-
Notifications
You must be signed in to change notification settings - Fork 4
/
stroop_model.py
102 lines (99 loc) · 3.77 KB
/
stroop_model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
"""replicate the stroop model from cohen et al (1990)
clr = color, wrd = word
i = input, h = hidden, o = output
tc/tw = mapping from taks input to color naming / word reading
"""
import psyneulink as pnl
# CONSTANTS
N_UNITS = 2
def get_stroop_model(unit_noise_std=.01, dec_noise_std=.1):
# model params
# TODO bad practice, to be moved
hidden_func = pnl.Logistic(gain=1.0, x_0=4.0)
integration_rate = .2
leak = 0
competition = 1
# input layer, color and word
inp_clr = pnl.TransferMechanism(
size=N_UNITS, function=pnl.Linear, name='COLOR INPUT'
)
inp_wrd = pnl.TransferMechanism(
size=N_UNITS, function=pnl.Linear, name='WORD INPUT'
)
# task layer, represent the task instruction; color naming / word reading
inp_task = pnl.TransferMechanism(
size=N_UNITS, function=pnl.Linear, name='TASK'
)
# hidden layer for color and word
hid_clr = pnl.TransferMechanism(
size=N_UNITS,
function=hidden_func,
integrator_mode=True,
integration_rate=integration_rate,
noise=pnl.NormalDist(standard_deviation=unit_noise_std).function,
name='COLORS HIDDEN'
)
hid_wrd = pnl.TransferMechanism(
size=N_UNITS,
function=hidden_func,
integrator_mode=True,
integration_rate=integration_rate,
noise=pnl.NormalDist(standard_deviation=unit_noise_std).function,
name='WORDS HIDDEN'
)
# output layer
output = pnl.TransferMechanism(
size=N_UNITS,
function=pnl.Logistic,
integrator_mode=True,
integration_rate=integration_rate,
noise=pnl.NormalDist(standard_deviation=unit_noise_std).function,
name='OUTPUT'
)
# decision layer, some accumulator
decision = pnl.LCAMechanism(
size=N_UNITS,
leak=leak,
competition=competition,
# MAX_VS_NEXT=lca_mvn,
noise=pnl.UniformToNormalDist(
standard_deviation=dec_noise_std).function,
name='DECISION'
)
# PROJECTIONS, weights copied from cohen et al (1990)
wts_clr_ih = pnl.MappingProjection(
matrix=[[2.2, -2.2], [-2.2, 2.2]], name='COLOR INPUT TO HIDDEN')
wts_wrd_ih = pnl.MappingProjection(
matrix=[[2.6, -2.6], [-2.6, 2.6]], name='WORD INPUT TO HIDDEN')
wts_clr_ho = pnl.MappingProjection(
matrix=[[1.3, -1.3], [-1.3, 1.3]], name='COLOR HIDDEN TO OUTPUT')
wts_wrd_ho = pnl.MappingProjection(
matrix=[[2.5, -2.5], [-2.5, 2.5]], name='WORD HIDDEN TO OUTPUT')
wts_tc = pnl.MappingProjection(
matrix=[[4.0, 4.0], [0, 0]], name='COLOR NAMING')
wts_tw = pnl.MappingProjection(
matrix=[[0, 0], [4.0, 4.0]], name='WORD READING')
# build the model
model = pnl.Composition(name='STROOP model')
model.add_node(inp_clr)
model.add_node(inp_wrd)
model.add_node(hid_clr)
model.add_node(hid_wrd)
model.add_node(inp_task)
model.add_node(output)
model.add_node(decision)
model.add_linear_processing_pathway([inp_clr, wts_clr_ih, hid_clr])
model.add_linear_processing_pathway([inp_wrd, wts_wrd_ih, hid_wrd])
model.add_linear_processing_pathway([hid_clr, wts_clr_ho, output])
model.add_linear_processing_pathway([hid_wrd, wts_wrd_ho, output])
model.add_linear_processing_pathway([inp_task, wts_tc, hid_clr])
model.add_linear_processing_pathway([inp_task, wts_tw, hid_wrd])
model.add_linear_processing_pathway([output, pnl.IDENTITY_MATRIX, decision])
# # LOGGING
# hid_clr.set_log_conditions('value')
# hid_wrd.set_log_conditions('value')
# output.set_log_conditions('value')
# collect the node handles
nodes = [inp_clr, inp_wrd, inp_task, hid_clr, hid_wrd, output, decision]
metadata = [integration_rate, dec_noise_std, unit_noise_std]
return model, nodes, metadata