Try out R-W learning of various number marking systems using data from Ramscar, et al. (2011).


In [1]:
import pandas as pd
import pandas.rpy.common as com
import numpy as np
from sklearn.feature_extraction import DictVectorizer

import ndl

%load_ext autoreload
%autoreload 2

%load_ext rmagic

%matplotlib inline

%precision 2
pd.set_option('display.precision', 2)

In [2]:
%%R
library(ndl)


This is ndl version 0.2.16. 
For an overview of the package, type 'help("ndl.package")'.

In [3]:
data = com.load_data('numbers')
data['Cues'] = [x.split('_') for x in data['Cues']]
data['Number'] = data['Outcomes']
data


Out[3]:
Cues Outcomes Frequency Number
1 [size, shape, color, 1, exactly1] 1 455 1
2 [size, shape, color, 1, 2, exactly2] 2 205 2
3 [size, shape, color, 1, 2, 3, exactly3] 3 107 3
4 [size, shape, color, 1, 2, 3, 4, exactly4] 4 60 4
5 [size, shape, color, 1, 2, 3, 4, 5, exactly5] 5 50 5
6 [size, shape, color, 1, 2, 3, 4, 5, 6, exactly6] 6 36 6
7 [size, shape, color, 1, 2, 3, 4, 5, 6, 7, exac... 7 21 7
8 [size, shape, color, 1, 2, 3, 4, 5, 6, 7, 8, e... 8 20 8
9 [size, shape, color, 1, 2, 3, 4, 5, 6, 7, 8, 9... 9 13 9
10 [size, shape, color, 1, 2, 3, 4, 5, 6, 7, 8, 9... 10 16 10
11 [size, shape, color, 1, 2, 3, 4, 5, 6, 7, 8, 9... 11 3 11
12 [size, shape, color, 1, 2, 3, 4, 5, 6, 7, 8, 9... 12 4 12
13 [size, shape, color, 1, 2, 3, 4, 5, 6, 7, 8, 9... 13 2 13
14 [size, shape, color, 1, 2, 3, 4, 5, 6, 7, 8, 9... 14 2 14
15 [size, shape, color, 1, 2, 3, 4, 5, 6, 7, 8, 9... 15 4 15

15 rows × 4 columns


Singular, plural


In [4]:
data['Outcomes'] = 'plural'
data['Outcomes'][1] = 'singular'
data


Out[4]:
Cues Outcomes Frequency Number
1 [size, shape, color, 1, exactly1] singular 455 1
2 [size, shape, color, 1, 2, exactly2] plural 205 2
3 [size, shape, color, 1, 2, 3, exactly3] plural 107 3
4 [size, shape, color, 1, 2, 3, 4, exactly4] plural 60 4
5 [size, shape, color, 1, 2, 3, 4, 5, exactly5] plural 50 5
6 [size, shape, color, 1, 2, 3, 4, 5, 6, exactly6] plural 36 6
7 [size, shape, color, 1, 2, 3, 4, 5, 6, 7, exac... plural 21 7
8 [size, shape, color, 1, 2, 3, 4, 5, 6, 7, 8, e... plural 20 8
9 [size, shape, color, 1, 2, 3, 4, 5, 6, 7, 8, 9... plural 13 9
10 [size, shape, color, 1, 2, 3, 4, 5, 6, 7, 8, 9... plural 16 10
11 [size, shape, color, 1, 2, 3, 4, 5, 6, 7, 8, 9... plural 3 11
12 [size, shape, color, 1, 2, 3, 4, 5, 6, 7, 8, 9... plural 4 12
13 [size, shape, color, 1, 2, 3, 4, 5, 6, 7, 8, 9... plural 2 13
14 [size, shape, color, 1, 2, 3, 4, 5, 6, 7, 8, 9... plural 2 14
15 [size, shape, color, 1, 2, 3, 4, 5, 6, 7, 8, 9... plural 4 15

15 rows × 4 columns


In [7]:
W = ndl.rw(data,M=100)
W


Out[7]:
plural singular
1 9.3e-02 1.2e-01
10 2.0e-03 -2.8e-03
11 2.0e-03 -2.8e-03
12 2.0e-03 -2.8e-03
13 0.0e+00 0.0e+00
14 0.0e+00 0.0e+00
15 0.0e+00 0.0e+00
2 2.2e-01 -1.2e-01
3 1.3e-01 -7.4e-02
4 7.9e-02 -5.2e-02
5 4.7e-02 -3.1e-02
6 4.5e-02 -2.9e-02
7 4.0e-02 -2.3e-02
8 2.4e-02 -1.4e-02
9 5.3e-03 -6.0e-03
color 9.3e-02 1.2e-01
exactly1 -1.3e-01 2.4e-01
exactly10 0.0e+00 0.0e+00
exactly11 0.0e+00 0.0e+00
exactly12 2.0e-03 -2.8e-03
exactly13 0.0e+00 0.0e+00
exactly14 0.0e+00 0.0e+00
exactly15 0.0e+00 0.0e+00
exactly2 9.5e-02 -5.0e-02
exactly3 4.6e-02 -2.2e-02
exactly4 3.2e-02 -2.1e-02
exactly5 1.8e-03 -2.0e-03
exactly6 4.9e-03 -5.6e-03
exactly7 1.6e-02 -9.0e-03
exactly8 1.9e-02 -8.0e-03
exactly9 3.4e-03 -3.2e-03
shape 9.3e-02 1.2e-01
size 9.3e-02 1.2e-01

33 rows × 2 columns


In [8]:
def activation(W):
    return pd.DataFrame([ndl.activation(c,W) for c in data.Cues],index=data.index)

In [9]:
activation(W)


Out[9]:
plural singular
1 0.2 0.7
2 0.7 0.3
3 0.8 0.3
4 0.8 0.2
5 0.8 0.2
6 0.9 0.2
7 0.9 0.1
8 1.0 0.1
9 1.0 0.1
10 1.0 0.1
11 1.0 0.1
12 1.0 0.1
13 1.0 0.1
14 1.0 0.1
15 1.0 0.1

15 rows × 2 columns


Singular, dual, plural


In [10]:
data['Outcomes'] = 'plural'
data['Outcomes'][1] = 'singular'
data['Outcomes'][2] = 'dual'
W = ndl.rw(data,M=100)
activation(W)


Out[10]:
dual plural singular
1 0.1 0.1 0.8
2 0.4 0.3 0.3
3 0.2 0.5 0.3
4 0.2 0.6 0.3
5 0.1 0.7 0.2
6 0.1 0.7 0.2
7 0.1 0.7 0.2
8 0.1 0.8 0.2
9 0.1 0.8 0.2
10 0.1 0.8 0.2
11 0.1 0.8 0.2
12 0.1 0.8 0.2
13 0.1 0.8 0.2
14 0.1 0.8 0.2
15 0.1 0.8 0.2

15 rows × 3 columns


Singular, dual, trial, plural


In [12]:
data['Outcomes'] = 'plural'
data['Outcomes'][1] = 'singular'
data['Outcomes'][2] = 'dual'
data['Outcomes'][3] = 'trial'
W = ndl.rw(data,M=100)
activation(W)


Out[12]:
dual plural singular trial
1 0.2 0.0 0.7 0.1
2 0.5 0.1 0.3 0.1
3 0.3 0.2 0.2 0.3
4 0.2 0.4 0.2 0.2
5 0.2 0.5 0.2 0.2
6 0.2 0.5 0.2 0.2
7 0.2 0.6 0.2 0.2
8 0.2 0.6 0.2 0.2
9 0.2 0.7 0.2 0.2
10 0.2 0.7 0.1 0.1
11 0.2 0.7 0.2 0.1
12 0.2 0.8 0.2 0.1
13 0.2 0.8 0.2 0.1
14 0.2 0.8 0.2 0.1
15 0.2 0.8 0.2 0.1

15 rows × 4 columns


Singular, dual, trial, quadral, plural


In [13]:
data['Outcomes'] = 'plural'
data['Outcomes'][1] = 'singular'
data['Outcomes'][2] = 'dual'
data['Outcomes'][3] = 'trial'
data['Outcomes'][4] = '4ial'
W = ndl.rw(data,M=100)
activation(W)


Out[13]:
4ial dual plural singular trial
1 0.1 0.1 0.0 0.8 0.0
2 0.1 0.4 0.1 0.3 0.1
3 0.1 0.2 0.2 0.3 0.2
4 0.3 0.1 0.3 0.2 0.1
5 0.2 0.1 0.4 0.2 0.1
6 0.2 0.1 0.4 0.2 0.1
7 0.2 0.1 0.5 0.2 0.1
8 0.2 0.1 0.5 0.2 0.1
9 0.2 0.1 0.5 0.2 0.1
10 0.2 0.1 0.5 0.2 0.1
11 0.2 0.1 0.5 0.2 0.1
12 0.2 0.1 0.5 0.2 0.1
13 0.2 0.1 0.5 0.2 0.1
14 0.2 0.1 0.5 0.2 0.1
15 0.2 0.1 0.5 0.2 0.1

15 rows × 5 columns


Dual, non-dual


In [16]:
data['Outcomes'] = 'notdual'
data['Outcomes'][1] = 'notdual'
data['Outcomes'][2] = 'dual'
W = ndl.rw(data,M=100)
activation(W)


Out[16]:
dual notdual
1 0.1 0.9
2 0.3 0.7
3 0.1 0.9
4 0.1 0.9
5 0.1 0.9
6 0.1 0.9
7 0.1 1.0
8 0.1 1.0
9 0.1 1.0
10 0.1 1.0
11 0.1 1.0
12 0.1 1.0
13 0.1 1.0
14 0.1 1.0
15 0.1 1.0

15 rows × 2 columns


In [ ]: