In [1]:
import sys
import seaborn as sns
sys.path.append("..")
%matplotlib inline
sns.set(rc={'image.cmap': 'Purples_r'})

Experiment Database


In [3]:
import naminggamesal.ngdb as ngdb
import naminggamesal.ngsimu as ngsimu

Using ngdb instead of ngsimu, we create Experiments objects that are re-usable via a database. Execute the code below, and a second time for the graph().show() part, you will notice the difference between the 2 libs (testexp is ngdb.Experiment, testexp2 is ngsimu.Experiment).


In [35]:
xp_cfg={
    'pop_cfg':{
        'voc_cfg':{
            'voc_type':'pandas',
            #'voc_type':'sparse_matrix',
            #'M':5,
            #'W':10
            },
        'strat_cfg':{
            'strat_type':'naive',
            'voc_update':'minimal'
            },
        'interact_cfg':{
            'interact_type':'speakerschoice'
            },
        'env_cfg':{'env_type':'simple','M':5,'W':10},
        'nbagent':nbagent
        },
    'step':10
}

testexp=ngdb.Experiment(**xp_cfg)
testexp
testexp2=ngsimu.Experiment(**xp_cfg)
testexp2


Out[35]:
<naminggamesal.ngsimu.Experiment at 0x7f64401c1190>

In [46]:
testexp.continue_exp_until(0)
testexp2.continue_exp_until(3)

In [48]:
for i in range()
print testexp2._poplist.get_last()._agentlist[i]._vocabulary._content_m
print testexp2._poplist.get_last()._agentlist[i]._vocabulary._content_m.index
print testexp2._poplist.get_last()._agentlist[i]._vocabulary.get_accessible_words()


['T_last', '__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__getstate__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'append', 'compress', 'filepath', 'get', 'get_last', 'init_db', 'init_done', 'pop', 'priority']
Series([], dtype: float64)
MultiIndex(levels=[[], []],
           labels=[[], []],
           names=[u'Meaning', u'Word'])
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

In [ ]:
testexp2._poplist.get_last()._agentlist[0]._vocabulary.add()

In [7]:
testexp.graph("entropy").show()


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-7-b7c4bd7ffba1> in <module>()
----> 1 testexp.graph("entropy").show()

/home/wschuell/Boulot_Projets/naminggamesal/naminggamesal/ngdb.pyc in graph(self, method, X, tmin, tmax, autocommit, tempgraph)
    554                         if not self.compute:
    555                                 raise Exception('Computation needed')
--> 556                         tempgraph = super(Experiment, self).graph(method=method,tmin=tmin, tmax=tmax)
    557                 if autocommit:
    558                         if do_not_commit:

/home/wschuell/Boulot_Projets/naminggamesal/naminggamesal/ngsimu.pyc in graph(self, method, X, tmin, tmax)
    262                 if tempfun.level=="agent":
    263                         for j in range(indmin,len(self._T)+1+indmax):
--> 264                                 tempout=tempfun.apply(self._poplist.get(self._T[j]))
    265                                 tempoutmean.append(tempout[0])
    266                                 tempoutstd.append(tempout[1])

/home/wschuell/Boulot_Projets/naminggamesal/additional/custom_func.pyc in apply(self, data, **kwargs)
     39                 if "progress_info" in kwargs.keys():
     40                         return self.func(data,progress_info=kwargs["progress_info"])
---> 41                 return self.func(data)
     42 
     43         def modify_graph_config(self,**kwargs):

/home/wschuell/Boulot_Projets/naminggamesal/naminggamesal/ngmeth.pyc in out_func(pop, **kwargs)
     19                 agentlist=pop._agentlist
     20                 for i in range(0,len(agentlist)):
---> 21                         tempNlist.append(func(agentlist[i]))
     22                         mean=np.mean(tempNlist)
     23                         std=np.std(tempNlist)

/home/wschuell/Boulot_Projets/naminggamesal/naminggamesal/ngmeth.pyc in entropy(agent, **kwargs)
    848 
    849 def entropy(agent,**kwargs):
--> 850         m=len(agent._vocabulary.get_known_meanings())
    851         return tempentropy(agent._vocabulary.get_M()-m,agent._vocabulary.get_W()-m)
    852 

/home/wschuell/Boulot_Projets/naminggamesal/naminggamesal/ngvoc/pd_df.pyc in get_known_meanings(self, w, option)
    142         def get_known_meanings(self,w=None,option=None):
    143                 if w is None:
--> 144                         return list(self._content_m.index.levels[0])#PANDASREPLACENEEDED
    145                 else:
    146                         if option is None:

AttributeError: 'Int64Index' object has no attribute 'levels'

In [6]:
testexp2.graph("entropy").show()


Get back existing experiments, merge DBs, and plot with different abscisse


In [7]:
db=ngdb.NamingGamesDB("ng2.db")

In [8]:
testexp3=db.get_experiment(force_new=True,**xp_cfg)

In [9]:
testexp3.continue_exp_until(200)

In [10]:
db.merge("naminggames.db",remove=False)

In [11]:
testexp3=db.get_experiment(force_new=False,**xp_cfg)

In [12]:
testexp3.continue_exp_until(100)

In [13]:
testexp3.graph("srtheo").show()
testexp3.graph("entropy").show()



In [14]:
testexp3.graph("entropy",X="srtheo").show()



In [15]:
testexp3.graph("entropy",X="interactions_per_agent").show()



In [ ]: