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

Agents

Agents are objects having a strategy, a vocabulary, and an ID (this last attribute is not important for the moment).


In [2]:
import lib.ngagent as ngagent

Let's create an agent. Vocabulary and strategy are created at the same time.


In [3]:
ag_cfg = {
    'agent_id':'test',
    'voc_cfg':{
        'voc_type':'sparse_matrix',
        'M':5,
        'W':10
        },
    'strat_cfg':{
        'strat_type':'naive',
        'voc_update':'Minimal'
        }
    }

testagent=ngagent.Agent(**ag_cfg)
testagent


matrix
strat naive fin
<module 'lib.ngstrat.naive' from '../lib/ngstrat/naive.pyc'>
<module 'lib.ngstrat.voc_update_decorators' from '../lib/ngstrat/voc_update_decorators.pyc'>
Out[3]:
<lib.ngagent.agent.Agent at 0xb5580ecc>

In [4]:
print(testagent)


                          Words
        [[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
         [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
Meanings [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
         [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
         [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]]


In [5]:
import random
M=ag_cfg['voc_cfg']['M']
W=ag_cfg['voc_cfg']['W']
for i in range(0,15):
    k=random.randint(0,M-1)
    l=random.randint(0,W-1)
    testagent._vocabulary.add(k,l,1)
print(testagent)


                          Words
        [[ 1.  0.  0.  0.  0.  0.  0.  1.  0.  0.]
         [ 0.  1.  1.  0.  0.  0.  0.  0.  0.  0.]
Meanings [ 0.  1.  1.  0.  0.  0.  1.  0.  0.  1.]
         [ 0.  0.  0.  0.  1.  1.  0.  0.  0.  0.]
         [ 0.  0.  0.  1.  1.  0.  0.  0.  0.  0.]]

We can get visuals of agent objects from strategy and vocabulary visuals, with same syntax.


In [6]:
testagent.visual()
testagent.visual("hom")


                          Words
        [[ 1.  0.  0.  0.  0.  0.  0.  1.  0.  0.]
         [ 0.  1.  1.  0.  0.  0.  0.  0.  0.  0.]
Meanings [ 0.  1.  1.  0.  0.  0.  1.  0.  0.  1.]
         [ 0.  0.  0.  0.  1.  1.  0.  0.  0.  0.]
         [ 0.  0.  0.  1.  1.  0.  0.  0.  0.  0.]]


In [7]:
testagent.visual()
testagent.visual("syn")


                          Words
        [[ 1.  0.  0.  0.  0.  0.  0.  1.  0.  0.]
         [ 0.  1.  1.  0.  0.  0.  0.  0.  0.  0.]
Meanings [ 0.  1.  1.  0.  0.  0.  1.  0.  0.  1.]
         [ 0.  0.  0.  0.  1.  1.  0.  0.  0.  0.]
         [ 0.  0.  0.  1.  1.  0.  0.  0.  0.  0.]]


In [8]:
testagent.visual()
testagent.visual("pick_mw",iterr=500)


                          Words
        [[ 1.  0.  0.  0.  0.  0.  0.  1.  0.  0.]
         [ 0.  1.  1.  0.  0.  0.  0.  0.  0.  0.]
Meanings [ 0.  1.  1.  0.  0.  0.  1.  0.  0.  1.]
         [ 0.  0.  0.  0.  1.  1.  0.  0.  0.  0.]
         [ 0.  0.  0.  1.  1.  0.  0.  0.  0.  0.]]


In [9]:
testagent.visual()
testagent.visual("guess_m",iterr=500)


                          Words
        [[ 1.  0.  0.  0.  0.  0.  0.  1.  0.  0.]
         [ 0.  1.  1.  0.  0.  0.  0.  0.  0.  0.]
Meanings [ 0.  1.  1.  0.  0.  0.  1.  0.  0.  1.]
         [ 0.  0.  0.  0.  1.  1.  0.  0.  0.  0.]
         [ 0.  0.  0.  1.  1.  0.  0.  0.  0.  0.]]


In [10]:
testagent.visual()
testagent.visual("pick_w",iterr=500)


                          Words
        [[ 1.  0.  0.  0.  0.  0.  0.  1.  0.  0.]
         [ 0.  1.  1.  0.  0.  0.  0.  0.  0.  0.]
Meanings [ 0.  1.  1.  0.  0.  0.  1.  0.  0.  1.]
         [ 0.  0.  0.  0.  1.  1.  0.  0.  0.  0.]
         [ 0.  0.  0.  1.  1.  0.  0.  0.  0.  0.]]


In [ ]:


In [ ]:


In [ ]: