In [1]:
import numpy as np
import networkx as nx
import matplotlib.pyplot as plt
from __future__ import division
from localint import LocalInteraction

%matplotlib inline

In [2]:
payoff_matrix = np.asarray([[6, 0, 0], [5, 7, 5], [0, 5, 8]])

In [3]:
G1 = nx.complete_graph(8)

In [4]:
li1 = LocalInteraction(payoff_matrix, nx.adjacency_matrix(G1))

In [11]:
li1.simulate(ts_length=10000000,epsilon=0.01, init_actions=[0,0,0,0,0,0,0,0], revision='sequential')


Out[11]:
array([[0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       ..., 
       [2, 2, 2, ..., 2, 2, 2],
       [2, 2, 2, ..., 2, 2, 2],
       [2, 2, 2, ..., 2, 2, 2]])

In [13]:
for i in range(100):
    print li1.simulate(ts_length=10000,epsilon=0.01, init_actions=[0,0,0,0,0,0,0,0], revision='sequential')[9999]


[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-13-32c69ecaac77> in <module>()
      1 for i in range(100):
----> 2     print li1.simulate(ts_length=10000,epsilon=0.01, init_actions=[0,0,0,0,0,0,0,0], revision='sequential')[9999]

C:\Users\Atsushi Yamagishi\Documents\game_theory_models\localint.py in simulate(self, ts_length, epsilon, init_actions, revision)
    118                 init_actions=init_actions, revision=revision)
    119 
--> 120         for t, actions in enumerate(actions_sequence_iter):
    121             actions_sequence[t] = actions
    122 

C:\Users\Atsushi Yamagishi\Documents\game_theory_models\localint.py in simulate_iter(self, ts_length, epsilon, revision, init_actions)
    140         for t in range(ts_length):
    141             yield self.current_actions
--> 142             self.play(player_ind=player_ind_sequence[t])
    143             if revision == 'sequential':
    144                 mutation = np.random.random(1)

C:\Users\Atsushi Yamagishi\Documents\game_theory_models\localint.py in play(self, player_ind)
     96 
     97         opponent_act_dists = \
---> 98             self.adj_matrix[player_ind].dot(self.current_actions_mixed).toarray()
     99 
    100         best_responses = np.empty(len(player_ind), dtype=int)

C:\Users\Atsushi Yamagishi\AppData\Local\Continuum\Anaconda\lib\site-packages\scipy\sparse\csr.pyc in __getitem__(self, key)
    271             # [[1,2],??]
    272             if isintlike(col) or isinstance(col,slice):
--> 273                 P = extractor(row, self.shape[0])     # [[1,2],j] or [[1,2],1:2]
    274                 return (P*self)[:,col]
    275 

C:\Users\Atsushi Yamagishi\AppData\Local\Continuum\Anaconda\lib\site-packages\scipy\sparse\csr.pyc in extractor(indices, N)
    239             shape = (len(indices),N)
    240 
--> 241             return csr_matrix((data,indices,indptr), shape=shape)
    242 
    243         row, col = self._unpack_index(key)

C:\Users\Atsushi Yamagishi\AppData\Local\Continuum\Anaconda\lib\site-packages\scipy\sparse\compressed.pyc in __init__(self, arg1, shape, dtype, copy)
     86             self.data = self.data.astype(dtype)
     87 
---> 88         self.check_format(full_check=False)
     89 
     90     def getnnz(self, axis=None):

C:\Users\Atsushi Yamagishi\AppData\Local\Continuum\Anaconda\lib\site-packages\scipy\sparse\compressed.pyc in check_format(self, full_check)
    164 
    165         # check index and data arrays
--> 166         if (len(self.indices) != len(self.data)):
    167             raise ValueError("indices and data should have the same size")
    168         if (self.indptr[-1] > len(self.indices)):

KeyboardInterrupt: 

In [15]:
for i in range(30):
    print li1.simulate(ts_length=10000,epsilon=0.1, init_actions=[2,2,2,2,2,2,2,2], revision='sequential')[9999]


[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 2 1 1 1 1]
[1 1 1 1 1 1 2 1]
[2 2 0 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[1 1 1 1 1 1 1 1]
[1 1 0 1 1 1 1 1]
[1 1 1 1 2 1 1 1]
[0 1 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 0 2]
[1 1 1 1 1 0 1 1]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[1 1 2 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 2 1]
[1 1 1 1 2 0 1 2]
[1 0 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[2 2 1 2 2 2 2 2]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 0 1 1 1]
[1 1 1 1 1 1 2 1]
[1 1 1 1 2 1 1 1]
[2 2 2 2 2 2 2 2]

In [16]:
for i in range(30):
    print li1.simulate(ts_length=10000,epsilon=0.01, init_actions=[1,1,1,1,1,1,1,1], revision='sequential')[9999]


[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 2 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1]

In [17]:
G2 = nx.cycle_graph(8)
li2 = LocalInteraction(payoff_matrix, nx.adjacency_matrix(G2))

In [18]:
for i in range(30):
    print li2.simulate(ts_length=10000,epsilon=0.01, init_actions=[0,0,0,0,0,0,0,0], revision='sequential')[9999]


[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 1 2 2 2 2]
[2 2 2 2 2 2 2 2]

In [19]:
for i in range(30):
    print li2.simulate(ts_length=10000,epsilon=0.01, init_actions=[1,1,1,1,1,1,1,1], revision='sequential')[9999]


[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[1 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[0 1 2 2 2 2 2 1]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[1 2 2 2 2 2 2 0]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]

In [20]:
for i in range(30):
    print li2.simulate(ts_length=10000,epsilon=0.01, init_actions=[2,2,2,2,2,2,2,2], revision='sequential')[9999]


[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 0 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 2 2 2 2 2 2 2]
[2 1 1 1 2 2 2 2]

In [ ]: