In [20]:
import sys
import seaborn as sns
import random
sys.path.append("..")
%matplotlib inline
sns.set(rc={'image.cmap': 'Purples_r'})
In [21]:
import naminggamesal.ngstrat as ngstrat
import naminggamesal.ngvoc as ngvoc
Let's create a strategy. We will also need two vocabularies to work on (speaker and hearer). (more info on other strategy types: Design_newStrategy.ipynb)
In [210]:
M = 5
W = 10
voc_cfg = {
'voc_type':'matrix',
'M':M,
'W':W
}
nlink = 0
voctest_speaker = ngvoc.Vocabulary(**voc_cfg)
for i in range(0, nlink):
voctest_speaker.add(random.randint(0,M-1), random.randint(0,W-1), 0.2)
voctest_hearer=ngvoc.Vocabulary(**voc_cfg)
for i in range(0, nlink):
voctest_hearer.add(random.randint(0,M-1), random.randint(0,W-1), 0.2)
print("Speaker:")
print(voctest_speaker)
print(" ")
print("Hearer:")
print(voctest_hearer)
In [211]:
strat_cfg={"strat_type":"success_threshold_epirob",'vu_cfg':{'vu_type':'BLIS'},}
teststrat=ngstrat.Strategy(**strat_cfg)
teststrat
Out[211]:
Now that we have a strategy, we can test the different functions. Exec
!! Vocabularies are modified, but this way you can observe progressive growth of the number of links !!
In [262]:
memory_s=teststrat.init_memory(voctest_speaker) #Not important for the naive strategy, here it simply is {}
memory_h=teststrat.init_memory(voctest_hearer)
print("Initial vocabulary of the speaker:")
print(voctest_speaker)
print(" ")
print("Initial vocabulary of the hearer:")
print(voctest_hearer)
print(" ")
ms=teststrat.pick_m(voctest_speaker,memory_s,context=[])
print("Meaning chosen by speaker:")
print(ms)
print (" ")
w=teststrat.pick_w(voc=voctest_speaker,mem=memory_s,m=ms,context=[])
print("Word uttered by speaker:")
print(w)
print (" ")
mh=teststrat.guess_m(w,voctest_hearer,memory_h,context=[])
print("Meaning interpreted by hearer:")
print(mh)
print (" ")
if (ms==mh):
print("Success!")
bool_succ = 1
else:
bool_succ = 0
print("Failure!")
print(" ")
teststrat.update_speaker(ms,w,mh,voctest_speaker,memory_s,bool_succ)
teststrat.update_hearer(ms,w,mh,voctest_hearer,memory_h,bool_succ)
print("Updated vocabulary of the speaker:")
print(voctest_speaker)
print(" ")
print("Updated vocabulary of the hearer:")
print(voctest_hearer)
Here you can modify by hand the 2 vocabularies before re-executing the code:
In [19]:
#voctest_speaker.add(0,0,1)
#voctest_speaker.add(0,0,0)
#voctest_hearer.add(0,0,1)
#voctest_hearer.add(0,0,0)
print("Speaker:")
print(voctest_speaker)
print(" ")
print("Hearer:")
print(voctest_hearer)
Approximation of the probability density of the different procedures of the strategy:
In [42]:
voctest_speaker.visual()
teststrat.visual(voc=voctest_speaker,mem=memory_s,vtype="pick_m",iterr=500)
In [43]:
voctest_speaker.visual()
teststrat.visual(voc=voctest_speaker,mem=memory_s,vtype="pick_mw",iterr=500)
In [44]:
voctest_speaker.visual()
teststrat.visual(voc=voctest_speaker,mem=memory_s,vtype="pick_w",iterr=500)
In [17]:
voctest_hearer.visual()
teststrat.visual(voc=voctest_hearer,mem=memory_h,vtype="guess_m",iterr=500)
In [ ]:
In [ ]:
In [ ]:
In [16]:
dir(teststrat)
teststrat.voc_update
Out[16]:
In [ ]:
In [ ]: