囚人のジレンマゲームの実験2

概要: README.md


In [35]:
#-*- encoding: utf-8 -*-
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
pd.set_option('display.precision', 4)
import sys
sys.path.append('./user_strategies')
import play as pl
from Iida_perfect_monitoring import Iida_pm
from Iida_imperfect_public import Iida_ipm
from Iida_imperfect_private import Iida_iprm
from kato import KatoStrategy
from ikegami_perfect import Self_Centered_perfect
from ikegami_imperfect_public import Self_Centered_public
from ikegami_imperfect_private import Self_Centered_private
from mhanami_Public_Strategy import PubStrategy
from mhanami_Imperfect_Public_Strategy import ImPubStrategy
from mhanami_Imperfect_Private_Strategy import ImPrivStrategy
from tsuyoshi import GrimTrigger
from gistfile1 import MyStrategy
from beeleb_Strategy import beeleb
from oyama import OyamaPerfectMonitoring, OyamaImperfectPublicMonitoring, OyamaImperfectPrivateMonitoring
from ogawa import ogawa
from yamagishi_impd import yamagishi

Test

各戦略のテスト


In [10]:
import unittest

class TestStrategies(unittest.TestCase):
    def setUp(self):
        self.Strategies = [Iida_pm, Iida_ipm, Iida_iprm, KatoStrategy, Self_Centered_perfect, \
                          Self_Centered_public, Self_Centered_private, PubStrategy, ImPubStrategy, ImPrivStrategy, \
                          MyStrategy, beeleb, OyamaPerfectMonitoring, \
                           OyamaImperfectPublicMonitoring, OyamaImperfectPrivateMonitoring, \
                          ogawa, yamagishi, GrimTrigger] # ここに自作のclassを入れる
        self.case1 = "Signal is empty(period 1)"
        self.case2 = [0, 1]
        self.case3 = [1, 0]
        self.case4 = [0, 1, 0, 1, 0, 0, 1]

        self.seed = 11451
        self.RandomState = np.random.RandomState(self.seed)


    # case1を引数に渡してテスト
    def test1(self):
        print("testcase:", self.case1)
        for Strategy in self.Strategies:
            rst = Strategy(self.RandomState).play()
            self.assertIsNotNone(rst, Strategy.__module__)
            self.assertIn(rst, (0, 1), Strategy.__module__)


    # case2を引数に渡してテスト
    def test2(self):
        print("testcase:", self.case2)
        for Strategy in self.Strategies:
            S = Strategy(self.RandomState)
            for signal in self.case2:
                S.get_signal(signal)
                rst = S.play()       
                self.assertIsNotNone(rst, Strategy.__module__)
                self.assertIn(rst, (0, 1), Strategy.__module__)


    # case3を引数に渡してテスト
    def test3(self):
        print("testcase:", self.case3)
        for Strategy in self.Strategies:
            S = Strategy(self.RandomState)
            for signal in self.case3:
                S.get_signal(signal)
            
            rst = S.play()
            self.assertIsNotNone(rst, S.__module__)
            self.assertIn(rst, (0, 1), S.__module__)


    # case4を引数に渡してテスト
    def test4(self):
        print("testcase:", self.case4)
        for Strategy in self.Strategies:
            S = Strategy(self.RandomState)
            for signal in self.case4:
                S.get_signal(signal)
                rst = S.play()
                self.assertIsNotNone(rst, S.__module__)
                self.assertIn(rst, (0, 1), S.__module__)

In [11]:
suite = unittest.TestLoader().loadTestsFromTestCase(TestStrategies)
unittest.TextTestRunner().run(suite)


....
testcase: Signal is empty(period 1)
testcase: [0, 1]
testcase: [1, 0]
testcase: [0, 1, 0, 1, 0, 0, 1]
----------------------------------------------------------------------
Ran 4 tests in 0.003s

OK
Out[11]:
<unittest.runner.TextTestResult run=4 errors=0 failures=0>

Test: OK

実験のセットアップ


In [12]:
payoff = np.array([[4, 0], [5, 2]])
seed = 20141019
rs = np.random.RandomState(seed)
discount_v = 0.97
repeat = 1000
ts_length = rs.geometric(p=1-discount_v, size=1000) + 1

Case1: perfect monitoring


In [13]:
strategies = [Iida_pm, PubStrategy, KatoStrategy, Self_Centered_perfect,
                       GrimTrigger, MyStrategy, beeleb, OyamaPerfectMonitoring, ogawa,
                       yamagishi]
game = pl.RepeatedMatrixGame(payoff, strategies, signal=None, ts_length=ts_length, repeat=1000)
game.play(mtype="perfect", random_seed=seed, record=False)


Start
The object has 10 strategy functions below
****************************************
Iida_perfect_monitoring.Iida_pm
mhanami_Public_Strategy.PubStrategy
kato.KatoStrategy
ikegami_perfect.Self_Centered_perfect
tsuyoshi.GrimTrigger
gistfile1.MyStrategy
beeleb_Strategy.beeleb
oyama.OyamaPerfectMonitoring
ogawa.ogawa
yamagishi_impd.yamagishi
****************************************
Repeats: 1000
Total time series length: 34333

Game 1: "Iida_perfect_monitoring.Iida_pm" vs "mhanami_Public_Strategy.PubStrategy"
total score of Iida_perfect_monitoring.Iida_pm: 96040.000, per stage: 2.797
total score of mhanami_Public_Strategy.PubStrategy: 104995.000, per stage: 3.058

Game 2: "Iida_perfect_monitoring.Iida_pm" vs "kato.KatoStrategy"
total score of Iida_perfect_monitoring.Iida_pm: 60464.000, per stage: 1.761
total score of kato.KatoStrategy: 85969.000, per stage: 2.504

Game 3: "Iida_perfect_monitoring.Iida_pm" vs "ikegami_perfect.Self_Centered_perfect"
total score of Iida_perfect_monitoring.Iida_pm: 147123.000, per stage: 4.285
total score of ikegami_perfect.Self_Centered_perfect: 98168.000, per stage: 2.859

Game 4: "Iida_perfect_monitoring.Iida_pm" vs "tsuyoshi.GrimTrigger"
total score of Iida_perfect_monitoring.Iida_pm: 124298.000, per stage: 3.620
total score of tsuyoshi.GrimTrigger: 88338.000, per stage: 2.573

Game 5: "Iida_perfect_monitoring.Iida_pm" vs "gistfile1.MyStrategy"
total score of Iida_perfect_monitoring.Iida_pm: 147123.000, per stage: 4.285
total score of gistfile1.MyStrategy: 98168.000, per stage: 2.859

Game 6: "Iida_perfect_monitoring.Iida_pm" vs "beeleb_Strategy.beeleb"
total score of Iida_perfect_monitoring.Iida_pm: 147123.000, per stage: 4.285
total score of beeleb_Strategy.beeleb: 98168.000, per stage: 2.859

Game 7: "Iida_perfect_monitoring.Iida_pm" vs "oyama.OyamaPerfectMonitoring"
total score of Iida_perfect_monitoring.Iida_pm: 95809.000, per stage: 2.791
total score of oyama.OyamaPerfectMonitoring: 104604.000, per stage: 3.047

Game 8: "Iida_perfect_monitoring.Iida_pm" vs "ogawa.ogawa"
total score of Iida_perfect_monitoring.Iida_pm: 106699.000, per stage: 3.108
total score of ogawa.ogawa: 96454.000, per stage: 2.809

Game 9: "Iida_perfect_monitoring.Iida_pm" vs "yamagishi_impd.yamagishi"
total score of Iida_perfect_monitoring.Iida_pm: 126331.000, per stage: 3.680
total score of yamagishi_impd.yamagishi: 125791.000, per stage: 3.664

Game 10: "mhanami_Public_Strategy.PubStrategy" vs "kato.KatoStrategy"
total score of mhanami_Public_Strategy.PubStrategy: 68666.000, per stage: 2.000
total score of kato.KatoStrategy: 73666.000, per stage: 2.146

Game 11: "mhanami_Public_Strategy.PubStrategy" vs "ikegami_perfect.Self_Centered_perfect"
total score of mhanami_Public_Strategy.PubStrategy: 137332.000, per stage: 4.000
total score of ikegami_perfect.Self_Centered_perfect: 137332.000, per stage: 4.000

Game 12: "mhanami_Public_Strategy.PubStrategy" vs "tsuyoshi.GrimTrigger"
total score of mhanami_Public_Strategy.PubStrategy: 137332.000, per stage: 4.000
total score of tsuyoshi.GrimTrigger: 137332.000, per stage: 4.000

Game 13: "mhanami_Public_Strategy.PubStrategy" vs "gistfile1.MyStrategy"
total score of mhanami_Public_Strategy.PubStrategy: 137332.000, per stage: 4.000
total score of gistfile1.MyStrategy: 137332.000, per stage: 4.000

Game 14: "mhanami_Public_Strategy.PubStrategy" vs "beeleb_Strategy.beeleb"
total score of mhanami_Public_Strategy.PubStrategy: 137332.000, per stage: 4.000
total score of beeleb_Strategy.beeleb: 137332.000, per stage: 4.000

Game 15: "mhanami_Public_Strategy.PubStrategy" vs "oyama.OyamaPerfectMonitoring"
total score of mhanami_Public_Strategy.PubStrategy: 137332.000, per stage: 4.000
total score of oyama.OyamaPerfectMonitoring: 137332.000, per stage: 4.000

Game 16: "mhanami_Public_Strategy.PubStrategy" vs "ogawa.ogawa"
total score of mhanami_Public_Strategy.PubStrategy: 97073.000, per stage: 2.827
total score of ogawa.ogawa: 95428.000, per stage: 2.779

Game 17: "mhanami_Public_Strategy.PubStrategy" vs "yamagishi_impd.yamagishi"
total score of mhanami_Public_Strategy.PubStrategy: 137332.000, per stage: 4.000
total score of yamagishi_impd.yamagishi: 137332.000, per stage: 4.000

Game 18: "kato.KatoStrategy" vs "ikegami_perfect.Self_Centered_perfect"
total score of kato.KatoStrategy: 170665.000, per stage: 4.971
total score of ikegami_perfect.Self_Centered_perfect: 4000.000, per stage: 0.117

Game 19: "kato.KatoStrategy" vs "tsuyoshi.GrimTrigger"
total score of kato.KatoStrategy: 122335.000, per stage: 3.563
total score of tsuyoshi.GrimTrigger: 36220.000, per stage: 1.055

Game 20: "kato.KatoStrategy" vs "gistfile1.MyStrategy"
total score of kato.KatoStrategy: 104554.000, per stage: 3.045
total score of gistfile1.MyStrategy: 48074.000, per stage: 1.400

Game 21: "kato.KatoStrategy" vs "beeleb_Strategy.beeleb"
total score of kato.KatoStrategy: 82174.000, per stage: 2.393
total score of beeleb_Strategy.beeleb: 62994.000, per stage: 1.835

Game 22: "kato.KatoStrategy" vs "oyama.OyamaPerfectMonitoring"
total score of kato.KatoStrategy: 73666.000, per stage: 2.146
total score of oyama.OyamaPerfectMonitoring: 68666.000, per stage: 2.000

Game 23: "kato.KatoStrategy" vs "ogawa.ogawa"
total score of kato.KatoStrategy: 76420.000, per stage: 2.226
total score of ogawa.ogawa: 66830.000, per stage: 1.947

Game 24: "kato.KatoStrategy" vs "yamagishi_impd.yamagishi"
total score of kato.KatoStrategy: 73666.000, per stage: 2.146
total score of yamagishi_impd.yamagishi: 68666.000, per stage: 2.000

Game 25: "ikegami_perfect.Self_Centered_perfect" vs "tsuyoshi.GrimTrigger"
total score of ikegami_perfect.Self_Centered_perfect: 137332.000, per stage: 4.000
total score of tsuyoshi.GrimTrigger: 137332.000, per stage: 4.000

Game 26: "ikegami_perfect.Self_Centered_perfect" vs "gistfile1.MyStrategy"
total score of ikegami_perfect.Self_Centered_perfect: 137332.000, per stage: 4.000
total score of gistfile1.MyStrategy: 137332.000, per stage: 4.000

Game 27: "ikegami_perfect.Self_Centered_perfect" vs "beeleb_Strategy.beeleb"
total score of ikegami_perfect.Self_Centered_perfect: 137332.000, per stage: 4.000
total score of beeleb_Strategy.beeleb: 137332.000, per stage: 4.000

Game 28: "ikegami_perfect.Self_Centered_perfect" vs "oyama.OyamaPerfectMonitoring"
total score of ikegami_perfect.Self_Centered_perfect: 137332.000, per stage: 4.000
total score of oyama.OyamaPerfectMonitoring: 137332.000, per stage: 4.000

Game 29: "ikegami_perfect.Self_Centered_perfect" vs "ogawa.ogawa"
total score of ikegami_perfect.Self_Centered_perfect: 83376.000, per stage: 2.428
total score of ogawa.ogawa: 150821.000, per stage: 4.393

Game 30: "ikegami_perfect.Self_Centered_perfect" vs "yamagishi_impd.yamagishi"
total score of ikegami_perfect.Self_Centered_perfect: 137332.000, per stage: 4.000
total score of yamagishi_impd.yamagishi: 137332.000, per stage: 4.000

Game 31: "tsuyoshi.GrimTrigger" vs "gistfile1.MyStrategy"
total score of tsuyoshi.GrimTrigger: 137332.000, per stage: 4.000
total score of gistfile1.MyStrategy: 137332.000, per stage: 4.000

Game 32: "tsuyoshi.GrimTrigger" vs "beeleb_Strategy.beeleb"
total score of tsuyoshi.GrimTrigger: 137332.000, per stage: 4.000
total score of beeleb_Strategy.beeleb: 137332.000, per stage: 4.000

Game 33: "tsuyoshi.GrimTrigger" vs "oyama.OyamaPerfectMonitoring"
total score of tsuyoshi.GrimTrigger: 137332.000, per stage: 4.000
total score of oyama.OyamaPerfectMonitoring: 137332.000, per stage: 4.000

Game 34: "tsuyoshi.GrimTrigger" vs "ogawa.ogawa"
total score of tsuyoshi.GrimTrigger: 93425.000, per stage: 2.721
total score of ogawa.ogawa: 126385.000, per stage: 3.681

Game 35: "tsuyoshi.GrimTrigger" vs "yamagishi_impd.yamagishi"
total score of tsuyoshi.GrimTrigger: 137332.000, per stage: 4.000
total score of yamagishi_impd.yamagishi: 137332.000, per stage: 4.000

Game 36: "gistfile1.MyStrategy" vs "beeleb_Strategy.beeleb"
total score of gistfile1.MyStrategy: 137332.000, per stage: 4.000
total score of beeleb_Strategy.beeleb: 137332.000, per stage: 4.000

Game 37: "gistfile1.MyStrategy" vs "oyama.OyamaPerfectMonitoring"
total score of gistfile1.MyStrategy: 137332.000, per stage: 4.000
total score of oyama.OyamaPerfectMonitoring: 137332.000, per stage: 4.000

Game 38: "gistfile1.MyStrategy" vs "ogawa.ogawa"
total score of gistfile1.MyStrategy: 99883.000, per stage: 2.909
total score of ogawa.ogawa: 125958.000, per stage: 3.669

Game 39: "gistfile1.MyStrategy" vs "yamagishi_impd.yamagishi"
total score of gistfile1.MyStrategy: 137332.000, per stage: 4.000
total score of yamagishi_impd.yamagishi: 137332.000, per stage: 4.000

Game 40: "beeleb_Strategy.beeleb" vs "oyama.OyamaPerfectMonitoring"
total score of beeleb_Strategy.beeleb: 137332.000, per stage: 4.000
total score of oyama.OyamaPerfectMonitoring: 137332.000, per stage: 4.000

Game 41: "beeleb_Strategy.beeleb" vs "ogawa.ogawa"
total score of beeleb_Strategy.beeleb: 105660.000, per stage: 3.078
total score of ogawa.ogawa: 117485.000, per stage: 3.422

Game 42: "beeleb_Strategy.beeleb" vs "yamagishi_impd.yamagishi"
total score of beeleb_Strategy.beeleb: 137332.000, per stage: 4.000
total score of yamagishi_impd.yamagishi: 137332.000, per stage: 4.000

Game 43: "oyama.OyamaPerfectMonitoring" vs "ogawa.ogawa"
total score of oyama.OyamaPerfectMonitoring: 96651.000, per stage: 2.815
total score of ogawa.ogawa: 94806.000, per stage: 2.761

Game 44: "oyama.OyamaPerfectMonitoring" vs "yamagishi_impd.yamagishi"
total score of oyama.OyamaPerfectMonitoring: 137332.000, per stage: 4.000
total score of yamagishi_impd.yamagishi: 137332.000, per stage: 4.000

Game 45: "ogawa.ogawa" vs "yamagishi_impd.yamagishi"
total score of ogawa.ogawa: 110390.000, per stage: 3.215
total score of yamagishi_impd.yamagishi: 108350.000, per stage: 3.156

Score table:
[[      0.   96040.   60464.  147123.  124298.  147123.  147123.   95809.
   106699.  126331.]
 [ 104995.       0.   68666.  137332.  137332.  137332.  137332.  137332.
    97073.  137332.]
 [  85969.   73666.       0.  170665.  122335.  104554.   82174.   73666.
    76420.   73666.]
 [  98168.  137332.    4000.       0.  137332.  137332.  137332.  137332.
    83376.  137332.]
 [  88338.  137332.   36220.  137332.       0.  137332.  137332.  137332.
    93425.  137332.]
 [  98168.  137332.   48074.  137332.  137332.       0.  137332.  137332.
    99883.  137332.]
 [  98168.  137332.   62994.  137332.  137332.  137332.       0.  137332.
   105660.  137332.]
 [ 104604.  137332.   68666.  137332.  137332.  137332.  137332.       0.
    96651.  137332.]
 [  96454.   95428.   66830.  150821.  126385.  125958.  117485.   94806.
        0.  110390.]
 [ 125791.  137332.   68666.  137332.  137332.  137332.  137332.  137332.
   108350.       0.]]

Ranking:
1. "yamagishi_impd.yamagishi"
total points: 1126799.000, average points per match: 125199.889, average points per stage: 3.647
2. "mhanami_Public_Strategy.PubStrategy"
total points: 1094726.000, average points per match: 121636.222, average points per stage: 3.543
3. "oyama.OyamaPerfectMonitoring"
total points: 1093913.000, average points per match: 121545.889, average points per stage: 3.540
4. "beeleb_Strategy.beeleb"
total points: 1090814.000, average points per match: 121201.556, average points per stage: 3.530
5. "gistfile1.MyStrategy"
total points: 1070117.000, average points per match: 118901.889, average points per stage: 3.463
6. "Iida_perfect_monitoring.Iida_pm"
total points: 1051010.000, average points per match: 116778.889, average points per stage: 3.401
7. "tsuyoshi.GrimTrigger"
total points: 1041975.000, average points per match: 115775.000, average points per stage: 3.372
8. "ikegami_perfect.Self_Centered_perfect"
total points: 1009536.000, average points per match: 112170.667, average points per stage: 3.267
9. "ogawa.ogawa"
total points: 984557.000, average points per match: 109395.222, average points per stage: 3.186
10. "kato.KatoStrategy"
total points: 863115.000, average points per match: 95901.667, average points per stage: 2.793

スコアテーブル

行: 利得を表示するプレイヤー 列: 対戦相手


In [37]:
score_perfect = np.array([[0, 96040, 60464, 147123, 124298, 147123, 147123, 95809, 106699, 126331],
[104995, 0, 68666, 137332, 137332, 137332, 137332, 137332, 97073, 137332],
[85969, 73666, 0, 170665, 122335, 104554, 82174, 73666, 76420, 73666],
[98168, 137332, 4000, 0, 137332, 137332, 137332, 137332, 83376, 137332],
[88338, 137332, 36220, 137332, 0, 137332, 137332, 137332, 93425, 137332],
[98168, 137332, 48074, 137332, 137332, 0, 137332, 137332, 99883, 137332],
[98168, 137332, 62994, 137332, 137332, 137332, 0, 137332, 105660, 137332],
[104604, 137332, 68666, 137332, 137332, 137332, 137332, 0, 96651, 137332],
[96454, 95428, 66830, 150821, 126385, 125958, 117485, 94806, 0, 110390],
[125791, 137332, 68666, 137332, 137332, 137332, 137332, 137332, 108350, 0]], dtype=float)

score_perfect /= 34333
score_perfect = pd.DataFrame(score_perfect)

print(score_perfect)


       0      1      2      3      4      5      6      7      8      9
0  0.000  2.797  1.761  4.285  3.620  4.285  4.285  2.791  3.108  3.680
1  3.058  0.000  2.000  4.000  4.000  4.000  4.000  4.000  2.827  4.000
2  2.504  2.146  0.000  4.971  3.563  3.045  2.393  2.146  2.226  2.146
3  2.859  4.000  0.117  0.000  4.000  4.000  4.000  4.000  2.428  4.000
4  2.573  4.000  1.055  4.000  0.000  4.000  4.000  4.000  2.721  4.000
5  2.859  4.000  1.400  4.000  4.000  0.000  4.000  4.000  2.909  4.000
6  2.859  4.000  1.835  4.000  4.000  4.000  0.000  4.000  3.078  4.000
7  3.047  4.000  2.000  4.000  4.000  4.000  4.000  0.000  2.815  4.000
8  2.809  2.779  1.947  4.393  3.681  3.669  3.422  2.761  0.000  3.215
9  3.664  4.000  2.000  4.000  4.000  4.000  4.000  4.000  3.156  0.000
Iida_pmPubStrategyKatoStrategySelf_Centered_perfectGrimTriggerMyStrategybeelebOyamaImperfectPerfectMonitoringogawayamagishi
Iida_pm0.0002.7971.7614.2853.6204.2854.2852.7913.1083.680
PubStrategy3.0580.0002.0004.0004.0004.0004.0004.0002.8274.000
KatoStrategy2.5042.1460.0004.9713.5633.0452.3932.1462.2262.146
Self_Centered_perfect2.8594.0000.1170.0004.0004.0004.0004.0002.4284.000
GrimTrigger2.5734.0001.0554.0000.0004.0004.0004.0002.7214.000
MyStrategy2.8594.0001.4004.0004.0000.0004.0004.0002.9094.000
beeleb2.8594.0001.8354.0004.0004.0000.0004.0003.0784.000
OyamaPerfectMonitoring3.0474.0002.0004.0004.0004.0004.0000.0002.8154.000
ogawa2.8092.7791.9474.3933.6813.6693.4222.7610.0003.215
yamagishi3.6644.0002.0004.0004.0004.0004.0004.0003.1560.000

グラフを出力

各対戦、各periodにおいて、それぞれのプレイヤーがCooperationをとっている割合


In [14]:
def normalize(array_2d):
    copy_array = np.array(array_2d, dtype=float)
    for v in copy_array:
        total = np.sum(v)
        v /= total
    return copy_array


def __plotC__(periods, action1, action2, **kwargs):
    period_max = kwargs.get('period_max', np.max(periods)+1)
    title = kwargs.get('title', None)
    
    fig, ax = plt.subplots(figsize=(20, 5))
    plt.xlim(-1, period_max)
    plt.ylim(-0.1, 1.1)
    plt.plot(periods, action1, color='c', label='player1 Cooperate %')
    plt.plot(periods, action2, color='r', label='player2 Cooperate %')
    if title:
        plt.title(title)
    
    plt.legend()
    plt.show()


# period毎にどの程度協力が行われているかをplot
def plotC(df):
    # 対戦組み合わせの数
    match_len = df['Match'].max() + 1

    # 1対戦のゲーム数
    round_len = df['Round'].max() + 1

    # 最長period
    period_max = df['Period'].max() + 1

    for m in range(match_len):
        df_match = df[df_perfect.Match == m].reset_index()
        str1 = df_match['Strategy1'][0]
        str2 = df_match['Strategy2'][0]
        df_match_s = df_match.loc[:, ["Round", "Period", "Action1", "Action2"]]
        df_match_np = df_match_s.as_matrix()

        periods = np.arange(period_max)
        action1 = np.zeros((period_max, 2), dtype=int)
        action2 = np.zeros((period_max, 2), dtype=int)

        for r in range(round_len):
            df_round = df_match_np[df_match_np[:, 0] == r]
            period_len = int(df_round[:, 1].max()+1)
            for p in range(period_len):
                stage_df = df_round[df_round[:, 1] == p]
                stage_action1 = stage_df[:, 2]
                stage_action2 = stage_df[:, 3]

                if stage_action1 == 0:
                    action1[p, 0]  += 1
                else:
                    action1[p, 1] += 1

                if stage_action2 == 0:
                    action2[p, 0]  += 1
                else:
                    action2[p, 1] += 1
                    
        action1 = normalize(action1)
        action2 = normalize(action2)
        __plotC__(periods, action1[:, 0], action2[:, 0], period_max=100, title='{0}  VS  {1}'.format(str1, str2))

        
# 結果の読み込み
df_perfect = pd.read_csv("record_perfect.csv")
plotC(df_perfect)


各対戦、ゲーム毎の平均利得分布


In [22]:
def __plotAve__(ts_length, ave_payoff1, ave_payoff2, **kwargs):
    title = kwargs.get('title', None)
    fig = plt.figure(figsize=(18, 5)) 
    
    weight1 = np.ones_like(ave_payoff1)/ts_length/100
    ax1 = plt.subplot(1, 2, 1)
    ax1.hist(ave_payoff1, bins=20, range=(0, 5), weights=weight1, normed=False, facecolor='g', alpha=0.8, label='player1')
    plt.legend()
    ax1.grid(True)
    
    weight2 = np.ones_like(ave_payoff2)/ts_length/100
    ax2 = plt.subplot(1, 2, 2, sharex=ax1, sharey=ax1)
    ax2.hist(ave_payoff2, bins=20, range=(0, 5), weights=weight2, normed=False, facecolor='g', alpha=0.8, label='player2')
    plt.legend()
    ax2.grid(True)
    
    mu1 = np.mean(ave_payoff1)
    mu2 = np.mean(ave_payoff2)
    ax1.axvline(x=mu1, linewidth=2, color='r')
    ax2.axvline(x=mu2, linewidth=2, color='r')
    plt.ylim(0, 1)
    ax1.text(0.1, 0.9, "average = {0:.2f}".format(mu1), size=12)
    ax2.text(0.1, 0.9, "average = {0:.2f}".format(mu2), size=12)

    if title:
        plt.suptitle(title, size=14)
    plt.show()


def plotAve(df):
    # 対戦組み合わせの数
    match_len = df['Match'].max() + 1

    # 1対戦のゲーム数
    round_len = df['Round'].max() + 1

    # 最長period
    period_max = df['Period'].max() + 1

    for m in range(match_len):
        df_match = df[df.Match == m].reset_index()
        str1 = df_match['Strategy1'][0]
        str2 = df_match['Strategy2'][0]
        df_match_s = df_match.loc[:, ["Round", "Period", "Payoff1", "Payoff2"]]
        df_match_np = df_match_s.as_matrix()

        periods = np.arange(period_max)
        ave_payoff1 = np.zeros(round_len, dtype=float)
        ave_payoff2 = np.zeros(round_len, dtype=float)

        for r in range(round_len):
            df_round = df_match_np[df_match_np[:, 0] == r]
            period_len = int(df_round[:, 1].max()+1)
            ave_payoff1[r] = df_round[:, 2].mean()
            ave_payoff2[r] = df_round[:, 3].mean()

        __plotAve__(ts_length, ave_payoff1, ave_payoff2, title='{0}  /  {1}  average payoff distribution'.format(str1, str2))
        

# 結果の読み込み
df_perfect = pd.read_csv("record_perfect.csv")
plotAve(df_perfect)


Case2: Imperfect public monitoring


In [16]:
# プロジェクトが成功か失敗かを返す
def public_signal(actions):
    prob = rs.uniform()
    if actions[0] == 0 and actions[1] == 0:
        return 0 if prob < 0.9 else 1

    elif (actions[0] == 0 and actions[1] == 1) or (actions[0] == 1 and actions[1] == 0):
        return 0 if prob < 0.5 else 1

    elif actions[0] == 1 and actions[1] == 1:
        return 0 if prob < 0.2 else 1

    else:
        raise ValueError
        
strategies = [Iida_ipm, KatoStrategy, Self_Centered_public,
              ImPubStrategy, GrimTrigger, MyStrategy, beeleb, OyamaImperfectPublicMonitoring, ogawa, yamagishi]
game = pl.RepeatedMatrixGame(payoff, strategies, signal=public_signal, ts_length=ts_length, repeat=1000)
game.play(mtype="public", random_seed=seed, record=False)


Start
The object has 10 strategy functions below
****************************************
Iida_imperfect_public.Iida_ipm
kato.KatoStrategy
ikegami_imperfect_public.Self_Centered_public
mhanami_Imperfect_Public_Strategy.ImPubStrategy
tsuyoshi.GrimTrigger
gistfile1.MyStrategy
beeleb_Strategy.beeleb
oyama.OyamaImperfectPublicMonitoring
ogawa.ogawa
yamagishi_impd.yamagishi
****************************************
Repeats: 1000
Total time series length: 34333

Game 1: "Iida_imperfect_public.Iida_ipm" vs "kato.KatoStrategy"
total score of Iida_imperfect_public.Iida_ipm: 54398.000, per stage: 1.584
total score of kato.KatoStrategy: 95068.000, per stage: 2.769

Game 2: "Iida_imperfect_public.Iida_ipm" vs "ikegami_imperfect_public.Self_Centered_public"
total score of Iida_imperfect_public.Iida_ipm: 157243.000, per stage: 4.580
total score of ikegami_imperfect_public.Self_Centered_public: 57688.000, per stage: 1.680

Game 3: "Iida_imperfect_public.Iida_ipm" vs "mhanami_Imperfect_Public_Strategy.ImPubStrategy"
total score of Iida_imperfect_public.Iida_ipm: 51002.000, per stage: 1.486
total score of mhanami_Imperfect_Public_Strategy.ImPubStrategy: 95162.000, per stage: 2.772

Game 4: "Iida_imperfect_public.Iida_ipm" vs "tsuyoshi.GrimTrigger"
total score of Iida_imperfect_public.Iida_ipm: 127446.000, per stage: 3.712
total score of tsuyoshi.GrimTrigger: 74731.000, per stage: 2.177

Game 5: "Iida_imperfect_public.Iida_ipm" vs "gistfile1.MyStrategy"
total score of Iida_imperfect_public.Iida_ipm: 142462.000, per stage: 4.149
total score of gistfile1.MyStrategy: 67987.000, per stage: 1.980

Game 6: "Iida_imperfect_public.Iida_ipm" vs "beeleb_Strategy.beeleb"
total score of Iida_imperfect_public.Iida_ipm: 138347.000, per stage: 4.030
total score of beeleb_Strategy.beeleb: 69502.000, per stage: 2.024

Game 7: "Iida_imperfect_public.Iida_ipm" vs "oyama.OyamaImperfectPublicMonitoring"
total score of Iida_imperfect_public.Iida_ipm: 87568.000, per stage: 2.551
total score of oyama.OyamaImperfectPublicMonitoring: 97498.000, per stage: 2.840

Game 8: "Iida_imperfect_public.Iida_ipm" vs "ogawa.ogawa"
total score of Iida_imperfect_public.Iida_ipm: 100961.000, per stage: 2.941
total score of ogawa.ogawa: 87296.000, per stage: 2.543

Game 9: "Iida_imperfect_public.Iida_ipm" vs "yamagishi_impd.yamagishi"
total score of Iida_imperfect_public.Iida_ipm: 106747.000, per stage: 3.109
total score of yamagishi_impd.yamagishi: 89082.000, per stage: 2.595

Game 10: "kato.KatoStrategy" vs "ikegami_imperfect_public.Self_Centered_public"
total score of kato.KatoStrategy: 170665.000, per stage: 4.971
total score of ikegami_imperfect_public.Self_Centered_public: 4000.000, per stage: 0.117

Game 11: "kato.KatoStrategy" vs "mhanami_Imperfect_Public_Strategy.ImPubStrategy"
total score of kato.KatoStrategy: 66666.000, per stage: 1.942
total score of mhanami_Imperfect_Public_Strategy.ImPubStrategy: 71666.000, per stage: 2.087

Game 12: "kato.KatoStrategy" vs "tsuyoshi.GrimTrigger"
total score of kato.KatoStrategy: 134419.000, per stage: 3.915
total score of tsuyoshi.GrimTrigger: 28164.000, per stage: 0.820

Game 13: "kato.KatoStrategy" vs "gistfile1.MyStrategy"
total score of kato.KatoStrategy: 147247.000, per stage: 4.289
total score of gistfile1.MyStrategy: 19612.000, per stage: 0.571

Game 14: "kato.KatoStrategy" vs "beeleb_Strategy.beeleb"
total score of kato.KatoStrategy: 134836.000, per stage: 3.927
total score of beeleb_Strategy.beeleb: 27886.000, per stage: 0.812

Game 15: "kato.KatoStrategy" vs "oyama.OyamaImperfectPublicMonitoring"
total score of kato.KatoStrategy: 87358.000, per stage: 2.544
total score of oyama.OyamaImperfectPublicMonitoring: 59538.000, per stage: 1.734

Game 16: "kato.KatoStrategy" vs "ogawa.ogawa"
total score of kato.KatoStrategy: 105889.000, per stage: 3.084
total score of ogawa.ogawa: 47184.000, per stage: 1.374

Game 17: "kato.KatoStrategy" vs "yamagishi_impd.yamagishi"
total score of kato.KatoStrategy: 101710.000, per stage: 2.962
total score of yamagishi_impd.yamagishi: 49970.000, per stage: 1.455

Game 18: "ikegami_imperfect_public.Self_Centered_public" vs "mhanami_Imperfect_Public_Strategy.ImPubStrategy"
total score of ikegami_imperfect_public.Self_Centered_public: 0.000, per stage: 0.000
total score of mhanami_Imperfect_Public_Strategy.ImPubStrategy: 171665.000, per stage: 5.000

Game 19: "ikegami_imperfect_public.Self_Centered_public" vs "tsuyoshi.GrimTrigger"
total score of ikegami_imperfect_public.Self_Centered_public: 117668.000, per stage: 3.427
total score of tsuyoshi.GrimTrigger: 142248.000, per stage: 4.143

Game 20: "ikegami_imperfect_public.Self_Centered_public" vs "gistfile1.MyStrategy"
total score of ikegami_imperfect_public.Self_Centered_public: 136032.000, per stage: 3.962
total score of gistfile1.MyStrategy: 137657.000, per stage: 4.009

Game 21: "ikegami_imperfect_public.Self_Centered_public" vs "beeleb_Strategy.beeleb"
total score of ikegami_imperfect_public.Self_Centered_public: 137264.000, per stage: 3.998
total score of beeleb_Strategy.beeleb: 137349.000, per stage: 4.000

Game 22: "ikegami_imperfect_public.Self_Centered_public" vs "oyama.OyamaImperfectPublicMonitoring"
total score of ikegami_imperfect_public.Self_Centered_public: 70068.000, per stage: 2.041
total score of oyama.OyamaImperfectPublicMonitoring: 154148.000, per stage: 4.490

Game 23: "ikegami_imperfect_public.Self_Centered_public" vs "ogawa.ogawa"
total score of ikegami_imperfect_public.Self_Centered_public: 81900.000, per stage: 2.385
total score of ogawa.ogawa: 151190.000, per stage: 4.404

Game 24: "ikegami_imperfect_public.Self_Centered_public" vs "yamagishi_impd.yamagishi"
total score of ikegami_imperfect_public.Self_Centered_public: 115748.000, per stage: 3.371
total score of yamagishi_impd.yamagishi: 142728.000, per stage: 4.157

Game 25: "mhanami_Imperfect_Public_Strategy.ImPubStrategy" vs "tsuyoshi.GrimTrigger"
total score of mhanami_Imperfect_Public_Strategy.ImPubStrategy: 134240.000, per stage: 3.910
total score of tsuyoshi.GrimTrigger: 24950.000, per stage: 0.727

Game 26: "mhanami_Imperfect_Public_Strategy.ImPubStrategy" vs "gistfile1.MyStrategy"
total score of mhanami_Imperfect_Public_Strategy.ImPubStrategy: 147719.000, per stage: 4.303
total score of gistfile1.MyStrategy: 15964.000, per stage: 0.465

Game 27: "mhanami_Imperfect_Public_Strategy.ImPubStrategy" vs "beeleb_Strategy.beeleb"
total score of mhanami_Imperfect_Public_Strategy.ImPubStrategy: 135476.000, per stage: 3.946
total score of beeleb_Strategy.beeleb: 24126.000, per stage: 0.703

Game 28: "mhanami_Imperfect_Public_Strategy.ImPubStrategy" vs "oyama.OyamaImperfectPublicMonitoring"
total score of mhanami_Imperfect_Public_Strategy.ImPubStrategy: 86936.000, per stage: 2.532
total score of oyama.OyamaImperfectPublicMonitoring: 56486.000, per stage: 1.645

Game 29: "mhanami_Imperfect_Public_Strategy.ImPubStrategy" vs "ogawa.ogawa"
total score of mhanami_Imperfect_Public_Strategy.ImPubStrategy: 106589.000, per stage: 3.105
total score of ogawa.ogawa: 43384.000, per stage: 1.264

Game 30: "mhanami_Imperfect_Public_Strategy.ImPubStrategy" vs "yamagishi_impd.yamagishi"
total score of mhanami_Imperfect_Public_Strategy.ImPubStrategy: 100757.000, per stage: 2.935
total score of yamagishi_impd.yamagishi: 47272.000, per stage: 1.377

Game 31: "tsuyoshi.GrimTrigger" vs "gistfile1.MyStrategy"
total score of tsuyoshi.GrimTrigger: 137083.000, per stage: 3.993
total score of gistfile1.MyStrategy: 117708.000, per stage: 3.428

Game 32: "tsuyoshi.GrimTrigger" vs "beeleb_Strategy.beeleb"
total score of tsuyoshi.GrimTrigger: 138749.000, per stage: 4.041
total score of beeleb_Strategy.beeleb: 117904.000, per stage: 3.434

Game 33: "tsuyoshi.GrimTrigger" vs "oyama.OyamaImperfectPublicMonitoring"
total score of tsuyoshi.GrimTrigger: 75810.000, per stage: 2.208
total score of oyama.OyamaImperfectPublicMonitoring: 129200.000, per stage: 3.763

Game 34: "tsuyoshi.GrimTrigger" vs "ogawa.ogawa"
total score of tsuyoshi.GrimTrigger: 90198.000, per stage: 2.627
total score of ogawa.ogawa: 125223.000, per stage: 3.647

Game 35: "tsuyoshi.GrimTrigger" vs "yamagishi_impd.yamagishi"
total score of tsuyoshi.GrimTrigger: 114085.000, per stage: 3.323
total score of yamagishi_impd.yamagishi: 127345.000, per stage: 3.709

Game 36: "gistfile1.MyStrategy" vs "beeleb_Strategy.beeleb"
total score of gistfile1.MyStrategy: 136851.000, per stage: 3.986
total score of beeleb_Strategy.beeleb: 136161.000, per stage: 3.966

Game 37: "gistfile1.MyStrategy" vs "oyama.OyamaImperfectPublicMonitoring"
total score of gistfile1.MyStrategy: 75450.000, per stage: 2.198
total score of oyama.OyamaImperfectPublicMonitoring: 141190.000, per stage: 4.112

Game 38: "gistfile1.MyStrategy" vs "ogawa.ogawa"
total score of gistfile1.MyStrategy: 87852.000, per stage: 2.559
total score of ogawa.ogawa: 140727.000, per stage: 4.099

Game 39: "gistfile1.MyStrategy" vs "yamagishi_impd.yamagishi"
total score of gistfile1.MyStrategy: 116362.000, per stage: 3.389
total score of yamagishi_impd.yamagishi: 135922.000, per stage: 3.959

Game 40: "beeleb_Strategy.beeleb" vs "oyama.OyamaImperfectPublicMonitoring"
total score of beeleb_Strategy.beeleb: 82602.000, per stage: 2.406
total score of oyama.OyamaImperfectPublicMonitoring: 134897.000, per stage: 3.929

Game 41: "beeleb_Strategy.beeleb" vs "ogawa.ogawa"
total score of beeleb_Strategy.beeleb: 90045.000, per stage: 2.623
total score of ogawa.ogawa: 137015.000, per stage: 3.991

Game 42: "beeleb_Strategy.beeleb" vs "yamagishi_impd.yamagishi"
total score of beeleb_Strategy.beeleb: 115409.000, per stage: 3.361
total score of yamagishi_impd.yamagishi: 135634.000, per stage: 3.951

Game 43: "oyama.OyamaImperfectPublicMonitoring" vs "ogawa.ogawa"
total score of oyama.OyamaImperfectPublicMonitoring: 104634.000, per stage: 3.048
total score of ogawa.ogawa: 92504.000, per stage: 2.694

Game 44: "oyama.OyamaImperfectPublicMonitoring" vs "yamagishi_impd.yamagishi"
total score of oyama.OyamaImperfectPublicMonitoring: 109458.000, per stage: 3.188
total score of yamagishi_impd.yamagishi: 89598.000, per stage: 2.610

Game 45: "ogawa.ogawa" vs "yamagishi_impd.yamagishi"
total score of ogawa.ogawa: 110338.000, per stage: 3.214
total score of yamagishi_impd.yamagishi: 96163.000, per stage: 2.801

Score table:
[[      0.   54398.  157243.   51002.  127446.  142462.  138347.   87568.
   100961.  106747.]
 [  95068.       0.  170665.   66666.  134419.  147247.  134836.   87358.
   105889.  101710.]
 [  57688.    4000.       0.       0.  117668.  136032.  137264.   70068.
    81900.  115748.]
 [  95162.   71666.  171665.       0.  134240.  147719.  135476.   86936.
   106589.  100757.]
 [  74731.   28164.  142248.   24950.       0.  137083.  138749.   75810.
    90198.  114085.]
 [  67987.   19612.  137657.   15964.  117708.       0.  136851.   75450.
    87852.  116362.]
 [  69502.   27886.  137349.   24126.  117904.  136161.       0.   82602.
    90045.  115409.]
 [  97498.   59538.  154148.   56486.  129200.  141190.  134897.       0.
   104634.  109458.]
 [  87296.   47184.  151190.   43384.  125223.  140727.  137015.   92504.
        0.  110338.]
 [  89082.   49970.  142728.   47272.  127345.  135922.  135634.   89598.
    96163.       0.]]

Ranking:
1. "mhanami_Imperfect_Public_Strategy.ImPubStrategy"
total points: 1050210.000, average points per match: 116690.000, average points per stage: 3.399
2. "kato.KatoStrategy"
total points: 1043858.000, average points per match: 115984.222, average points per stage: 3.378
3. "oyama.OyamaImperfectPublicMonitoring"
total points: 987049.000, average points per match: 109672.111, average points per stage: 3.194
4. "Iida_imperfect_public.Iida_ipm"
total points: 966174.000, average points per match: 107352.667, average points per stage: 3.127
5. "ogawa.ogawa"
total points: 934861.000, average points per match: 103873.444, average points per stage: 3.025
6. "yamagishi_impd.yamagishi"
total points: 913714.000, average points per match: 101523.778, average points per stage: 2.957
7. "tsuyoshi.GrimTrigger"
total points: 826018.000, average points per match: 91779.778, average points per stage: 2.673
8. "beeleb_Strategy.beeleb"
total points: 800984.000, average points per match: 88998.222, average points per stage: 2.592
9. "gistfile1.MyStrategy"
total points: 775443.000, average points per match: 86160.333, average points per stage: 2.510
10. "ikegami_imperfect_public.Self_Centered_public"
total points: 720368.000, average points per match: 80040.889, average points per stage: 2.331

スコアテーブル

行: 利得を表示するプレイヤー 列: 対戦相手


In [43]:
score_public = np.array([[0, 54398, 157243, 51002, 127446, 142462, 138347, 87568, 100961, 106747], 
 [95068, 0, 170665, 66666, 134419, 147247, 134836, 87358, 105889, 101710], 
 [57688, 4000, 0, 0, 117668, 136032, 137264, 70068, 81900, 115748], 
 [95162, 71666, 171665, 0, 134240, 147719, 135476, 86936, 106589, 100757], 
 [74731, 28164, 142248, 24950, 0, 137083, 138749, 75810, 90198, 114085], 
 [67987, 19612, 137657, 15964, 117708, 0,136851, 75450, 87852, 116362], 
 [69502, 27886, 137349, 24126, 117904, 136161, 0, 82602, 90045, 115409], 
 [97498, 59538, 154148, 56486, 129200, 141190, 134897, 0, 104634, 109458], 
 [87296, 47184, 151190, 43384, 125223, 140727, 137015, 92504, 0, 110338], 
 [89082, 49970, 142728, 47272, 127345, 135922, 135634, 89598, 96163, 0]], dtype=float)

score_public /= 34333
score_public = pd.DataFrame(score_public)

print(score_public)


       0      1      2      3      4      5      6      7      8      9
0  0.000  1.584  4.580  1.486  3.712  4.149  4.030  2.551  2.941  3.109
1  2.769  0.000  4.971  1.942  3.915  4.289  3.927  2.544  3.084  2.962
2  1.680  0.117  0.000  0.000  3.427  3.962  3.998  2.041  2.385  3.371
3  2.772  2.087  5.000  0.000  3.910  4.303  3.946  2.532  3.105  2.935
4  2.177  0.820  4.143  0.727  0.000  3.993  4.041  2.208  2.627  3.323
5  1.980  0.571  4.009  0.465  3.428  0.000  3.986  2.198  2.559  3.389
6  2.024  0.812  4.000  0.703  3.434  3.966  0.000  2.406  2.623  3.361
7  2.840  1.734  4.490  1.645  3.763  4.112  3.929  0.000  3.048  3.188
8  2.543  1.374  4.404  1.264  3.647  4.099  3.991  2.694  0.000  3.214
9  2.595  1.455  4.157  1.377  3.709  3.959  3.951  2.610  2.801  0.000
Iida_ipmKatoStrategySelf_Centered_publicImPubStrategyGrimTriggerMyStrategybeelebOyamaImperfectPublicogawayamagishi
Iida_ipm0.0001.5844.5801.4863.7124.1494.0302.5512.9413.109
KatoStrategy2.7690.0004.9711.9423.9154.2893.9272.5443.0842.962
Self_Centered_public1.6800.1170.0000.0003.4273.9623.9982.0412.3853.371
ImPubStrategy2.7722.0875.0000.0003.9104.3033.9462.5323.1052.935
GrimTrigger2.1770.8204.1430.7270.0003.9934.0412.2082.6273.323
MyStrategy1.9800.5714.0090.4653.4280.0003.9862.1982.5593.389
beeleb2.0240.8124.0000.7033.4343.9660.0002.4062.6233.361
OyamaImperfectPublic2.8401.7344.4901.6453.7634.1123.9290.0003.0483.188
ogawa2.5431.3744.4041.2643.6474.0993.9912.6940.0003.214
yamagishi2.5951.4554.1571.3773.7093.9593.9512.6102.8010.000

グラフを出力

Cooperationの割合


In [17]:
# 結果の読み込み
df_public = pd.read_csv("record_imperfect_public.csv")
plotC(df_public)


平均利得分布


In [23]:
# 結果の読み込み
df_public = pd.read_csv("record_imperfect_public.csv")
plotAve(df_public)


Case3: Imperfect private monitoring


In [19]:
# 「相手の」シグナルが協調か攻撃かを(ノイズ付きで)返す
def private_signal(actions):
    pattern = [[0, 0], [0, 1], [1, 0], [1, 1]]
    # 例えば実際の行動が(0, 1)なら、シグナルは(1, 0)である可能性が最も高い
    signal_probs = [[.9, .02, .02, .06], [.02, .06, .9, .02], [.02, .9, .06, .02], [.06, .02, .02, .9]]
    prob = rs.uniform()
    if actions[0] == 0 and actions[1] == 0:
        choice = rs.choice(4, p=signal_probs[0])
        return pattern[choice]

    elif actions[0] == 0 and actions[1] == 1:
        choice = rs.choice(4, p=signal_probs[1])
        return pattern[choice]

    elif actions[0] == 1 and actions[1] == 0:
        choice = rs.choice(4, p=signal_probs[2])
        return pattern[choice]

    elif actions[0] == 1 and actions[1] == 1:
        choice = rs.choice(4, p=signal_probs[3])
        return pattern[choice]

    else:
        raise ValueError

strategies = [Iida_iprm, KatoStrategy, Self_Centered_private,
              ImPrivStrategy, GrimTrigger, MyStrategy, beeleb, OyamaImperfectPrivateMonitoring, ogawa, yamagishi]
game = pl.RepeatedMatrixGame(payoff, strategies, signal=private_signal, ts_length=ts_length, repeat=1000)
game.play(mtype="private", random_seed=seed, record=False)


Start
The object has 10 strategy functions below
****************************************
Iida_imperfect_private.Iida_iprm
kato.KatoStrategy
ikegami_imperfect_private.Self_Centered_private
mhanami_Imperfect_Private_Strategy.ImPrivStrategy
tsuyoshi.GrimTrigger
gistfile1.MyStrategy
beeleb_Strategy.beeleb
oyama.OyamaImperfectPrivateMonitoring
ogawa.ogawa
yamagishi_impd.yamagishi
****************************************
Repeats: 1000
Total time series length: 34333

Game 1: "Iida_imperfect_private.Iida_iprm" vs "kato.KatoStrategy"
total score of Iida_imperfect_private.Iida_iprm: 55822.000, per stage: 1.626
total score of kato.KatoStrategy: 92932.000, per stage: 2.707

Game 2: "Iida_imperfect_private.Iida_iprm" vs "ikegami_imperfect_private.Self_Centered_private"
total score of Iida_imperfect_private.Iida_iprm: 152891.000, per stage: 4.453
total score of ikegami_imperfect_private.Self_Centered_private: 75096.000, per stage: 2.187

Game 3: "Iida_imperfect_private.Iida_iprm" vs "mhanami_Imperfect_Private_Strategy.ImPrivStrategy"
total score of Iida_imperfect_private.Iida_iprm: 108216.000, per stage: 3.152
total score of mhanami_Imperfect_Private_Strategy.ImPrivStrategy: 99106.000, per stage: 2.887

Game 4: "Iida_imperfect_private.Iida_iprm" vs "tsuyoshi.GrimTrigger"
total score of Iida_imperfect_private.Iida_iprm: 116865.000, per stage: 3.404
total score of tsuyoshi.GrimTrigger: 83055.000, per stage: 2.419

Game 5: "Iida_imperfect_private.Iida_iprm" vs "gistfile1.MyStrategy"
total score of Iida_imperfect_private.Iida_iprm: 137151.000, per stage: 3.995
total score of gistfile1.MyStrategy: 90136.000, per stage: 2.625

Game 6: "Iida_imperfect_private.Iida_iprm" vs "beeleb_Strategy.beeleb"
total score of Iida_imperfect_private.Iida_iprm: 133439.000, per stage: 3.887
total score of beeleb_Strategy.beeleb: 93934.000, per stage: 2.736

Game 7: "Iida_imperfect_private.Iida_iprm" vs "oyama.OyamaImperfectPrivateMonitoring"
total score of Iida_imperfect_private.Iida_iprm: 105215.000, per stage: 3.065
total score of oyama.OyamaImperfectPrivateMonitoring: 98425.000, per stage: 2.867

Game 8: "Iida_imperfect_private.Iida_iprm" vs "ogawa.ogawa"
total score of Iida_imperfect_private.Iida_iprm: 101208.000, per stage: 2.948
total score of ogawa.ogawa: 95663.000, per stage: 2.786

Game 9: "Iida_imperfect_private.Iida_iprm" vs "yamagishi_impd.yamagishi"
total score of Iida_imperfect_private.Iida_iprm: 107322.000, per stage: 3.126
total score of yamagishi_impd.yamagishi: 109662.000, per stage: 3.194

Game 10: "kato.KatoStrategy" vs "ikegami_imperfect_private.Self_Centered_private"
total score of kato.KatoStrategy: 170665.000, per stage: 4.971
total score of ikegami_imperfect_private.Self_Centered_private: 4000.000, per stage: 0.117

Game 11: "kato.KatoStrategy" vs "mhanami_Imperfect_Private_Strategy.ImPrivStrategy"
total score of kato.KatoStrategy: 78496.000, per stage: 2.286
total score of mhanami_Imperfect_Private_Strategy.ImPrivStrategy: 65446.000, per stage: 1.906

Game 12: "kato.KatoStrategy" vs "tsuyoshi.GrimTrigger"
total score of kato.KatoStrategy: 122635.000, per stage: 3.572
total score of tsuyoshi.GrimTrigger: 36020.000, per stage: 1.049

Game 13: "kato.KatoStrategy" vs "gistfile1.MyStrategy"
total score of kato.KatoStrategy: 114811.000, per stage: 3.344
total score of gistfile1.MyStrategy: 41236.000, per stage: 1.201

Game 14: "kato.KatoStrategy" vs "beeleb_Strategy.beeleb"
total score of kato.KatoStrategy: 87871.000, per stage: 2.559
total score of beeleb_Strategy.beeleb: 59196.000, per stage: 1.724

Game 15: "kato.KatoStrategy" vs "oyama.OyamaImperfectPrivateMonitoring"
total score of kato.KatoStrategy: 87640.000, per stage: 2.553
total score of oyama.OyamaImperfectPrivateMonitoring: 59350.000, per stage: 1.729

Game 16: "kato.KatoStrategy" vs "ogawa.ogawa"
total score of kato.KatoStrategy: 84607.000, per stage: 2.464
total score of ogawa.ogawa: 61372.000, per stage: 1.788

Game 17: "kato.KatoStrategy" vs "yamagishi_impd.yamagishi"
total score of kato.KatoStrategy: 81208.000, per stage: 2.365
total score of yamagishi_impd.yamagishi: 63638.000, per stage: 1.854

Game 18: "ikegami_imperfect_private.Self_Centered_private" vs "mhanami_Imperfect_Private_Strategy.ImPrivStrategy"
total score of ikegami_imperfect_private.Self_Centered_private: 135640.000, per stage: 3.951
total score of mhanami_Imperfect_Private_Strategy.ImPrivStrategy: 137755.000, per stage: 4.012

Game 19: "ikegami_imperfect_private.Self_Centered_private" vs "tsuyoshi.GrimTrigger"
total score of ikegami_imperfect_private.Self_Centered_private: 88368.000, per stage: 2.574
total score of tsuyoshi.GrimTrigger: 149573.000, per stage: 4.357

Game 20: "ikegami_imperfect_private.Self_Centered_private" vs "gistfile1.MyStrategy"
total score of ikegami_imperfect_private.Self_Centered_private: 136708.000, per stage: 3.982
total score of gistfile1.MyStrategy: 137488.000, per stage: 4.005

Game 21: "ikegami_imperfect_private.Self_Centered_private" vs "beeleb_Strategy.beeleb"
total score of ikegami_imperfect_private.Self_Centered_private: 137312.000, per stage: 3.999
total score of beeleb_Strategy.beeleb: 137337.000, per stage: 4.000

Game 22: "ikegami_imperfect_private.Self_Centered_private" vs "oyama.OyamaImperfectPrivateMonitoring"
total score of ikegami_imperfect_private.Self_Centered_private: 126700.000, per stage: 3.690
total score of oyama.OyamaImperfectPrivateMonitoring: 139990.000, per stage: 4.077

Game 23: "ikegami_imperfect_private.Self_Centered_private" vs "ogawa.ogawa"
total score of ikegami_imperfect_private.Self_Centered_private: 83064.000, per stage: 2.419
total score of ogawa.ogawa: 150899.000, per stage: 4.395

Game 24: "ikegami_imperfect_private.Self_Centered_private" vs "yamagishi_impd.yamagishi"
total score of ikegami_imperfect_private.Self_Centered_private: 126792.000, per stage: 3.693
total score of yamagishi_impd.yamagishi: 139967.000, per stage: 4.077

Game 25: "mhanami_Imperfect_Private_Strategy.ImPrivStrategy" vs "tsuyoshi.GrimTrigger"
total score of mhanami_Imperfect_Private_Strategy.ImPrivStrategy: 121657.000, per stage: 3.543
total score of tsuyoshi.GrimTrigger: 115547.000, per stage: 3.365

Game 26: "mhanami_Imperfect_Private_Strategy.ImPrivStrategy" vs "gistfile1.MyStrategy"
total score of mhanami_Imperfect_Private_Strategy.ImPrivStrategy: 136005.000, per stage: 3.961
total score of gistfile1.MyStrategy: 134235.000, per stage: 3.910

Game 27: "mhanami_Imperfect_Private_Strategy.ImPrivStrategy" vs "beeleb_Strategy.beeleb"
total score of mhanami_Imperfect_Private_Strategy.ImPrivStrategy: 136391.000, per stage: 3.973
total score of beeleb_Strategy.beeleb: 134561.000, per stage: 3.919

Game 28: "mhanami_Imperfect_Private_Strategy.ImPrivStrategy" vs "oyama.OyamaImperfectPrivateMonitoring"
total score of mhanami_Imperfect_Private_Strategy.ImPrivStrategy: 116939.000, per stage: 3.406
total score of oyama.OyamaImperfectPrivateMonitoring: 118219.000, per stage: 3.443

Game 29: "mhanami_Imperfect_Private_Strategy.ImPrivStrategy" vs "ogawa.ogawa"
total score of mhanami_Imperfect_Private_Strategy.ImPrivStrategy: 104786.000, per stage: 3.052
total score of ogawa.ogawa: 112576.000, per stage: 3.279

Game 30: "mhanami_Imperfect_Private_Strategy.ImPrivStrategy" vs "yamagishi_impd.yamagishi"
total score of mhanami_Imperfect_Private_Strategy.ImPrivStrategy: 108554.000, per stage: 3.162
total score of yamagishi_impd.yamagishi: 109739.000, per stage: 3.196

Game 31: "tsuyoshi.GrimTrigger" vs "gistfile1.MyStrategy"
total score of tsuyoshi.GrimTrigger: 132336.000, per stage: 3.854
total score of gistfile1.MyStrategy: 118051.000, per stage: 3.438

Game 32: "tsuyoshi.GrimTrigger" vs "beeleb_Strategy.beeleb"
total score of tsuyoshi.GrimTrigger: 127460.000, per stage: 3.712
total score of beeleb_Strategy.beeleb: 115260.000, per stage: 3.357

Game 33: "tsuyoshi.GrimTrigger" vs "oyama.OyamaImperfectPrivateMonitoring"
total score of tsuyoshi.GrimTrigger: 115756.000, per stage: 3.372
total score of oyama.OyamaImperfectPrivateMonitoring: 116946.000, per stage: 3.406

Game 34: "tsuyoshi.GrimTrigger" vs "ogawa.ogawa"
total score of tsuyoshi.GrimTrigger: 90031.000, per stage: 2.622
total score of ogawa.ogawa: 118676.000, per stage: 3.457

Game 35: "tsuyoshi.GrimTrigger" vs "yamagishi_impd.yamagishi"
total score of tsuyoshi.GrimTrigger: 114610.000, per stage: 3.338
total score of yamagishi_impd.yamagishi: 121220.000, per stage: 3.531

Game 36: "gistfile1.MyStrategy" vs "beeleb_Strategy.beeleb"
total score of gistfile1.MyStrategy: 137327.000, per stage: 4.000
total score of beeleb_Strategy.beeleb: 136762.000, per stage: 3.983

Game 37: "gistfile1.MyStrategy" vs "oyama.OyamaImperfectPrivateMonitoring"
total score of gistfile1.MyStrategy: 124673.000, per stage: 3.631
total score of oyama.OyamaImperfectPrivateMonitoring: 133903.000, per stage: 3.900

Game 38: "gistfile1.MyStrategy" vs "ogawa.ogawa"
total score of gistfile1.MyStrategy: 96889.000, per stage: 2.822
total score of ogawa.ogawa: 129054.000, per stage: 3.759

Game 39: "gistfile1.MyStrategy" vs "yamagishi_impd.yamagishi"
total score of gistfile1.MyStrategy: 123940.000, per stage: 3.610
total score of yamagishi_impd.yamagishi: 135800.000, per stage: 3.955

Game 40: "beeleb_Strategy.beeleb" vs "oyama.OyamaImperfectPrivateMonitoring"
total score of beeleb_Strategy.beeleb: 123787.000, per stage: 3.605
total score of oyama.OyamaImperfectPrivateMonitoring: 130852.000, per stage: 3.811

Game 41: "beeleb_Strategy.beeleb" vs "ogawa.ogawa"
total score of beeleb_Strategy.beeleb: 103640.000, per stage: 3.019
total score of ogawa.ogawa: 119305.000, per stage: 3.475

Game 42: "beeleb_Strategy.beeleb" vs "yamagishi_impd.yamagishi"
total score of beeleb_Strategy.beeleb: 124666.000, per stage: 3.631
total score of yamagishi_impd.yamagishi: 136946.000, per stage: 3.989

Game 43: "oyama.OyamaImperfectPrivateMonitoring" vs "ogawa.ogawa"
total score of oyama.OyamaImperfectPrivateMonitoring: 99584.000, per stage: 2.901
total score of ogawa.ogawa: 107074.000, per stage: 3.119

Game 44: "oyama.OyamaImperfectPrivateMonitoring" vs "yamagishi_impd.yamagishi"
total score of oyama.OyamaImperfectPrivateMonitoring: 110336.000, per stage: 3.214
total score of yamagishi_impd.yamagishi: 112346.000, per stage: 3.272

Game 45: "ogawa.ogawa" vs "yamagishi_impd.yamagishi"
total score of ogawa.ogawa: 104186.000, per stage: 3.035
total score of yamagishi_impd.yamagishi: 103511.000, per stage: 3.015

Score table:
[[      0.   55822.  152891.  108216.  116865.  137151.  133439.  105215.
   101208.  107322.]
 [  92932.       0.  170665.   78496.  122635.  114811.   87871.   87640.
    84607.   81208.]
 [  75096.    4000.       0.  135640.   88368.  136708.  137312.  126700.
    83064.  126792.]
 [  99106.   65446.  137755.       0.  121657.  136005.  136391.  116939.
   104786.  108554.]
 [  83055.   36020.  149573.  115547.       0.  132336.  127460.  115756.
    90031.  114610.]
 [  90136.   41236.  137488.  134235.  118051.       0.  137327.  124673.
    96889.  123940.]
 [  93934.   59196.  137337.  134561.  115260.  136762.       0.  123787.
   103640.  124666.]
 [  98425.   59350.  139990.  118219.  116946.  133903.  130852.       0.
    99584.  110336.]
 [  95663.   61372.  150899.  112576.  118676.  129054.  119305.  107074.
        0.  104186.]
 [ 109662.   63638.  139967.  109739.  121220.  135800.  136946.  112346.
   103511.       0.]]

Ranking:
1. "yamagishi_impd.yamagishi"
total points: 1032829.000, average points per match: 114758.778, average points per stage: 3.343
2. "beeleb_Strategy.beeleb"
total points: 1029143.000, average points per match: 114349.222, average points per stage: 3.331
3. "mhanami_Imperfect_Private_Strategy.ImPrivStrategy"
total points: 1026639.000, average points per match: 114071.000, average points per stage: 3.322
4. "Iida_imperfect_private.Iida_iprm"
total points: 1018129.000, average points per match: 113125.444, average points per stage: 3.295
5. "oyama.OyamaImperfectPrivateMonitoring"
total points: 1007605.000, average points per match: 111956.111, average points per stage: 3.261
6. "gistfile1.MyStrategy"
total points: 1003975.000, average points per match: 111552.778, average points per stage: 3.249
7. "ogawa.ogawa"
total points: 998805.000, average points per match: 110978.333, average points per stage: 3.232
8. "tsuyoshi.GrimTrigger"
total points: 964388.000, average points per match: 107154.222, average points per stage: 3.121
9. "kato.KatoStrategy"
total points: 920865.000, average points per match: 102318.333, average points per stage: 2.980
10. "ikegami_imperfect_private.Self_Centered_private"
total points: 913680.000, average points per match: 101520.000, average points per stage: 2.957

スコアテーブル

行: 利得を表示するプレイヤー 列: 対戦相手


In [39]:
score_private = np.array([[0, 55822, 152891, 108216, 116865, 137151, 133439, 105215, 101208, 107322], 
[92932, 0, 170665, 78496, 122635, 114811, 87871, 87640, 84607, 81208], 
[75096, 4000, 0, 135640, 88368, 136708, 137312, 126700, 83064, 126792], 
[99106, 65446, 137755, 0, 121657, 136005, 136391, 116939, 104786, 108554], 
[83055, 36020, 149573, 115547, 0, 132336, 127460, 115756, 90031, 114610], 
[90136, 41236, 137488, 134235, 118051, 0, 137327, 124673, 96889, 123940], 
[93934, 59196, 137337, 134561, 115260, 136762, 0, 123787, 103640, 124666], 
[98425, 59350, 139990, 118219, 116946, 133903, 130852, 0, 99584, 110336], 
[95663, 61372, 150899, 112576, 118676, 129054, 119305, 107074, 0, 104186], 
[109662, 63638, 139967, 109739, 121220, 135800, 136946, 112346, 103511, 0]], dtype=float)

score_private /= 34333
score_private = pd.DataFrame(score_private)

print(score_private)


       0      1      2      3      4      5      6      7      8      9
0  0.000  1.626  4.453  3.152  3.404  3.995  3.887  3.065  2.948  3.126
1  2.707  0.000  4.971  2.286  3.572  3.344  2.559  2.553  2.464  2.365
2  2.187  0.117  0.000  3.951  2.574  3.982  3.999  3.690  2.419  3.693
3  2.887  1.906  4.012  0.000  3.543  3.961  3.973  3.406  3.052  3.162
4  2.419  1.049  4.357  3.365  0.000  3.854  3.712  3.372  2.622  3.338
5  2.625  1.201  4.005  3.910  3.438  0.000  4.000  3.631  2.822  3.610
6  2.736  1.724  4.000  3.919  3.357  3.983  0.000  3.605  3.019  3.631
7  2.867  1.729  4.077  3.443  3.406  3.900  3.811  0.000  2.901  3.214
8  2.786  1.788  4.395  3.279  3.457  3.759  3.475  3.119  0.000  3.035
9  3.194  1.854  4.077  3.196  3.531  3.955  3.989  3.272  3.015  0.000
Iida_iprmKatoStrategySelf_Centered_privateImPrivStrategyGrimTriggerMyStrategybeelebOyamaImperfectPrivateogawayamagishi
Iida_iprm0.0001.6264.4533.1523.4043.9953.8873.0652.9483.126
KatoStrategy2.7070.0004.9712.2863.5723.3442.5592.5532.4642.365
Self_Centered_private2.1870.1170.0003.9512.5743.9823.9993.6902.4193.693
ImPrivStrategy2.8871.9064.0120.0003.5433.9613.9733.4063.0523.162
GrimTrigger2.4191.0494.3573.3650.0003.8543.7123.3722.6223.338
MyStrategy2.6251.2014.0053.9103.4380.0004.0003.6312.8223.610
beeleb2.7361.7244.0003.9193.3573.9830.0003.6053.0193.631
OyamaImperfectPrivate2.8671.7294.0773.4433.4063.9003.8110.0002.9013.214
ogawa2.7861.7884.3953.2793.4573.7593.4753.1190.0003.035
yamagishi3.1941.8544.0773.1963.5313.9553.9893.2723.0150.000

グラフを出力

Cooperationの割合


In [20]:
# 結果の読み込み
df_private = pd.read_csv("record_imperfect_private.csv")
plotC(df_private)


平均利得分布


In [24]:
# 結果の読み込み
df_private = pd.read_csv("record_imperfect_private.csv")
plotAve(df_private)



In [ ]: