Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
word_response_weights,
response_layer], name='WORDS_PROCESS')
# Colors pathway
colors_process = pnl.Process(pathway=[colors_input_layer,
color_weights,
colors_hidden_layer,
color_response_weights,
response_layer], name='COLORS_PROCESS')
# Task representation pathway
task_CN_process = pnl.Process(pathway=[task_layer,
task_CN_weights,
colors_hidden_layer],
name='TASK_CN_PROCESS')
task_WR_process = pnl.Process(pathway=[task_layer,
task_WR_weights,
words_hidden_layer],
name='TASK_WR_PROCESS')
# Evidence accumulation pathway
respond_red_process = pnl.Process(pathway=[response_layer,
respond_red_differencing_weights,
respond_red_accumulator],
name='RESPOND_RED_PROCESS')
respond_green_process = pnl.Process(pathway=[response_layer,
respond_green_differencing_weights,
respond_green_accumulator],
name='RESPOND_GREEN_PROCESS')
# CREATE SYSTEM
my_Stroop = pnl.System(processes=[colors_process,
rel_in = pnl.TransferMechanism(size=11, name='REL_IN')
rep_hidden = pnl.TransferMechanism(size=4, function=psyneulink.core.components.functions.transferfunctions.Logistic, name='REP_HIDDEN')
rel_hidden = pnl.TransferMechanism(size=5, function=psyneulink.core.components.functions.transferfunctions.Logistic, name='REL_HIDDEN')
rep_out = pnl.TransferMechanism(size=10, function=psyneulink.core.components.functions.transferfunctions.Logistic, name='REP_OUT')
prop_out = pnl.TransferMechanism(size=12, function=psyneulink.core.components.functions.transferfunctions.Logistic, name='PROP_OUT')
qual_out = pnl.TransferMechanism(size=13, function=psyneulink.core.components.functions.transferfunctions.Logistic, name='QUAL_OUT')
act_out = pnl.TransferMechanism(size=14, function=psyneulink.core.components.functions.transferfunctions.Logistic, name='ACT_OUT')
r_step = pnl.ProcessingMechanism(size=10, function=step, name='REP_STEP')
p_step = pnl.ProcessingMechanism(size=12, function=step, name='PROP_STEP')
q_step = pnl.ProcessingMechanism(size=13, function=step, name='QUAL_STEP')
a_step = pnl.ProcessingMechanism(size=14, function=step, name='ACT_STEP')
#Processes that comprise the System:
# NOTE: this is one of several configuration of processes that can be used to construct the full network
# (see Test/learning/test_rumelhart_semantic_network.py for other configurations)
rep_hidden_proc = pnl.Process(pathway=[rep_in, rep_hidden, rel_hidden],
learning=pnl.LEARNING,
name='REP_HIDDEN_PROC')
rel_hidden_proc = pnl.Process(pathway=[rel_in, rel_hidden],
learning=pnl.LEARNING,
name='REL_HIDDEN_PROC')
rel_rep_proc = pnl.Process(pathway=[rel_hidden, rep_out],
learning=pnl.LEARNING,
name='REL_REP_PROC')
rel_prop_proc = pnl.Process(pathway=[rel_hidden, prop_out],
learning=pnl.LEARNING,
name='REL_PROP_PROC')
rel_qual_proc = pnl.Process(pathway=[rel_hidden, qual_out],
learning=pnl.LEARNING,
name='REL_QUAL_PROC')
rel_act_proc = pnl.Process(pathway=[rel_hidden, act_out],
learning=pnl.LEARNING,
#Next, we specify our output layer. This is where we do our sigmoid transformation, by simply applying the Logistic function.
#The size we specify for this layer is the number of output nodes we want. In this case, we want the network to return a scalar
#for each example (either a 1 or a zero), so our size is 1
output_layer=pnl.TransferMechanism(size=1, function=psyneulink.core.components.functions.transferfunctions.Logistic, name='OUTPUT LAYER')
#Now, we put them together into a process.
#Notice, that we did not need to specify a weighting matrix. One will automatically be generated by psyneulink when we create our
#process.
# JDC ADDED:
# Normally, for learning to occur in a process, we would just specify that learning=pnl.ENABLED.
# However, if we want to specify a specific learning function or error_function to be used, then we must
# specify it by construction a default LearningProjection and giving it the parameters we want. In this
# case it is the error_function, that we will set to CROSS_ENTROPY (using PsyNeulink's Distance Function):
net2l=pnl.Process(pathway=[input_layer,output_layer],
learning=pnl.LearningProjection(error_function=psyneulink.core.components.functions
.objectivefunctions.Distance(metric=pnl.CROSS_ENTROPY))
)
#The pathway argument specifies in which order to execute the layers. THis way, the output of one will be mapped to the input of
#the next.
#To run the process, we will put it into a system.
sys2l=pnl.System(processes=[net2l],learning_rate=4)
sys2l.show_graph(show_learning=pnl.ALL)
task_CN_process = pnl.Process(pathway=[task_layer,
task_CN_weights,
colors_hidden_layer],
name='TASK_CN_PROCESS')
task_WR_process = pnl.Process(pathway=[task_layer,
task_WR_weights,
words_hidden_layer],
name='TASK_WR_PROCESS')
# Evidence accumulation pathway
respond_red_process = pnl.Process(pathway=[response_layer,
respond_red_differencing_weights,
respond_red_accumulator],
name='RESPOND_RED_PROCESS')
respond_green_process = pnl.Process(pathway=[response_layer,
respond_green_differencing_weights,
respond_green_accumulator],
name='RESPOND_GREEN_PROCESS')
# CREATE SYSTEM
my_Stroop = pnl.System(processes=[colors_process,
words_process,
task_CN_process,
task_WR_process,
respond_red_process,
respond_green_process],
name='FEEDFORWARD_STROOP_SYSTEM')
my_Stroop.show()
# my_Stroop.show_graph(show_dimensions=pnl.ALL)
name='TASK_CN_WEIGHTS')
# column 0: task_CN to hidden_'RED', hidden_'GREEN'
# column 1: task_WR to hidden_'RED', hidden_'GREEN'
task_WR_weights = pnl.MappingProjection(matrix=np.matrix([[0, 0.0],
[4.0, 4.0]]),
name='TASK_WR_WEIGHTS')
# In[ ]:
# CREATE PATHWAYS
# Words pathway
words_process = pnl.Process(pathway=[words_input_layer,
word_weights,
words_hidden_layer,
word_response_weights,
response_layer], name='WORDS_PROCESS')
# Colors pathway
colors_process = pnl.Process(pathway=[colors_input_layer,
color_weights,
colors_hidden_layer,
color_response_weights,
response_layer], name='COLORS_PROCESS')
# Task representation pathway
task_CN_process = pnl.Process(pathway=[task_layer,
task_CN_weights,
colors_hidden_layer],
color_response_weights,
response_layer,
response_color_weights,
colors_hidden_layer],
name='COLORS_RESPONSE_PROCESS')
word_response_process = pnl.Process(pathway=[words_input_layer,
word_input_weights,
words_hidden_layer,
word_response_weights,
response_layer,
response_word_weights,
words_hidden_layer],
name='WORDS_RESPONSE_PROCESS')
task_color_response_process = pnl.Process(pathway=[task_input_layer,
task_input_weights,
task_layer,
task_color_weights,
colors_hidden_layer,
color_task_weights,
task_layer])
task_word_response_process = pnl.Process(pathway=[task_input_layer,
task_layer,
task_word_weights,
words_hidden_layer,
word_task_weights,
task_layer])
# CREATE SYSTEM -------------------------------------------------------------------------------------------------------
System_Conflict_Monitoring = pnl.System(processes=[color_response_process,
words_hidden_layer,
word_response_weights,
response_layer,
response_word_weights,
words_hidden_layer],
name='WORDS_RESPONSE_PROCESS')
task_color_response_process = pnl.Process(pathway=[task_input_layer,
task_input_weights,
task_layer,
task_color_weights,
colors_hidden_layer,
color_task_weights,
task_layer])
task_word_response_process = pnl.Process(pathway=[task_input_layer,
task_layer,
task_word_weights,
words_hidden_layer,
word_task_weights,
task_layer])
# Create system -------------------------------------------------------------------------------------------------------
Bidirectional_Stroop = pnl.System(processes=[color_response_process,
word_response_process,
task_color_response_process,
task_word_response_process],
reinitialize_mechanisms_when=pnl.Never(),
name='FEEDFORWARD_STROOP_SYSTEM')
# LOGGING:
# row 0: response_'red' to respond_green_accumulator
# row 1: response_'green' to respond_green_accumulator
respond_green_differencing_weights = pnl.MappingProjection(matrix=np.matrix([[-1.0], [1.0]]),
name='RESPOND_GREEN_WEIGHTS')
# Create pathways as processes
# Words pathway
words_process = pnl.Process(pathway=[words_input_layer,
word_weights,
words_hidden_layer,
word_response_weights,
response_layer], name='WORDS_PROCESS')
# Colors pathway
colors_process = pnl.Process(pathway=[colors_input_layer,
color_weights,
colors_hidden_layer,
color_response_weights,
response_layer], name='COLORS_PROCESS')
# Task representation pathway
task_CN_process = pnl.Process(pathway=[task_layer,
task_CN_weights,
colors_hidden_layer],
name='TASK_CN_PROCESS')
task_WR_process = pnl.Process(pathway=[task_layer,
task_WR_weights,
words_hidden_layer],
name='TASK_WR_PROCESS')
myHiddenLayer = pnl.TransferMechanism(
name='Hidden Layer 1',
function=psyneulink.core.components.functions.transferfunctions.Logistic(gain=1.0, x_0=0),
default_variable=np.zeros((5,))
)
myDDM = pnl.DDM(
name='My_DDM',
function=psyneulink.core.components.functions.distributionfunctions.DriftDiffusionAnalytical(
drift_rate=0.5,
threshold=1,
starting_point=0.0
)
)
myProcess = pnl.Process(
name='Neural Network DDM Process',
default_variable=[0, 0],
pathway=[
myInputLayer,
psyneulink.core.components.functions.transferfunctions.get_matrix(pnl.RANDOM_CONNECTIVITY_MATRIX, 2, 5),
myHiddenLayer,
pnl.FULL_CONNECTIVITY_MATRIX,
myDDM
]
)
myProcess.reportOutputPref = True
myInputLayer.reportOutputPref = True
myHiddenLayer.reportOutputPref = True
myDDM.reportOutputPref = pnl.PreferenceEntry(True, pnl.PreferenceLevel.INSTANCE)
task_CN_process = pnl.Process(pathway=[task_layer,
task_CN_weights,
colors_hidden_layer],
name='TASK_CN_PROCESS')
task_WR_process = pnl.Process(pathway=[task_layer,
task_WR_weights,
words_hidden_layer],
name='TASK_WR_PROCESS')
# evidence accumulation pathway
respond_red_process = pnl.Process(pathway=[response_layer,
respond_red_differencing_weights,
respond_red_accumulator],
name='RESPOND_RED_PROCESS')
respond_green_process = pnl.Process(pathway=[response_layer,
respond_green_differencing_weights,
respond_green_accumulator],
name='RESPOND_GREEN_PROCESS')
# In[ ]:
# CREATE SYSTEM
my_Stroop = pnl.System(processes=[colors_process,
words_process,
task_CN_process,
task_WR_process,
respond_red_process,
respond_green_process],
name='FEEDFORWARD_STROOP_SYSTEM')