How to use the psyneulink.System function in psyneulink

To help you get started, we’ve selected a few psyneulink examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PrincetonUniversity / PsyNeuLink / tests / naming / test_naming.py View on Github external
def test_process_and_system_default_names_2(self):

        T = pnl.TransferMechanism(name='T0')
        P1 = pnl.Process(name='MY PROCESS', pathway=[T])
        P2 = pnl.Process(name='MY PROCESS', pathway=[T])
        assert P1.name == 'MY PROCESS'
        assert P2.name == 'MY PROCESS-1'
        S1 = pnl.System(name='MY SYSTEM', processes=[P1])
        S2 = pnl.System(name='MY SYSTEM', processes=[P1])
        assert S1.name == 'MY SYSTEM'
        assert S2.name == 'MY SYSTEM-1'
github PrincetonUniversity / PsyNeuLink / Scripts / Misc / Laura Stroop w EVC.py View on Github external
import numpy as np
import matplotlib.pyplot as plt
import psyneulink as pnl
import psyneulink.core.components.functions.transferfunctions

ci = pnl.TransferMechanism(size=2, name='COLORS INPUT')
wi = pnl.TransferMechanism(size=2, name='WORDS INPUT')
ch = pnl.TransferMechanism(size=2, function=psyneulink.core.components.functions.transferfunctions.Logistic, name='COLORS HIDDEN')
wh = pnl.TransferMechanism(size=2, function=psyneulink.core.components.functions.transferfunctions.Logistic, name='WORDS HIDDEN')
tl = pnl.TransferMechanism(size=2, function=psyneulink.core.components.functions.transferfunctions.Logistic(gain=pnl.CONTROL), name='TASK CONTROL')
rl = pnl.LCAMechanism(size=2, function=psyneulink.core.components.functions.transferfunctions.Logistic, name='RESPONSE')
cp = pnl.Process(pathway=[ci, ch, rl])
wp = pnl.Process(pathway=[wi, wh, rl])
tc = pnl.Process(pathway=[tl, ch])
tw = pnl.Process(pathway=[tl,wh])
s = pnl.System(processes=[tc, tw, cp, wp],
               controller=pnl.EVCControlMechanism(name='EVC Mechanimsm'),
               monitor_for_control=[rl])
s.show_graph()
github PrincetonUniversity / PsyNeuLink / Scripts / Examples / System / Multilayer-Learning.py View on Github external
def show_target(system):
    i = system.input
    t = system.target_input_states[0].parameters.value.get(system)
    print('\nOLD WEIGHTS: \n')
    print('- Input Weights: \n', Input_Weights.parameters.matrix.get(system))
    print('- Middle Weights: \n', Middle_Weights.parameters.matrix.get(system))
    print('- Output Weights: \n', Output_Weights.parameters.matrix.get(system))

    print('\nSTIMULI:\n\n- Input: {}\n- Target: {}\n'.format(i, t))
    print('ACTIVITY FROM OLD WEIGHTS: \n')
    print('- Middle 1: \n', Hidden_Layer_1.parameters.value.get(system))
    print('- Middle 2: \n', Hidden_Layer_2.parameters.value.get(system))
    print('- Output:\n', Output_Layer.parameters.value.get(system))


mySystem = pnl.System(
        name='Multilayer-Learning',
        processes=[z],
        targets=[0, 0, 1],
        learning_rate=2.0
)

# Log Middle_Weights of MappingProjection to Hidden_Layer_2
# Hidden_Layer_2.set_log_conditions('Middle Weights')
Middle_Weights.set_log_conditions('mod_matrix')

mySystem.reportOutputPref = True
# Shows graph will full information:
mySystem.show_graph(show_dimensions=pnl.ALL)
mySystem.show_graph(show_learning=pnl.ALL)
# mySystem.show_graph(show_learning=pnl.ALL, show_processes=True)
# mySystem.show_graph(show_learning=pnl.ALL, show_dimensions=pnl.ALL, show_mechanism_structure=True)
github PrincetonUniversity / PsyNeuLink / Scripts / Markus_conflict_monitoring.py View on Github external
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')

#   CREATE SYSTEM
System_Conflict_Monitoring = pnl.System(processes=[colors_process,
                                  words_process,
                                  task_CN_process,
                                  task_WR_process],
                      controller=pnl.ControlMechanism,
                       monitor_for_control=[response_layer.output_states['DECISION_ENERGY']],
                       enable_controller=True,
                       name='FEEDFORWARD_Conflict_Monitoring_SYSTEM')

# System_Conflict_Monitoring.show_graph(show_control=pnl.ALL, show_dimensions=pnl.ALL)


# System_Conflict_Monitoring.controller.set_log_conditions('TASK[gain] ControlSignal', pnl.LogCondition.EXECUTION)
# System_Conflict_Monitoring.controller.set_log_conditions('value')
# System_Conflict_Monitoring.controller.set_log_conditions('slope')
# System_Conflict_Monitoring.controller.set_log_conditions('intercept')
github PrincetonUniversity / PsyNeuLink / Scripts / Examples / System / Gating-Mechanism. with UDF.py View on Github external
def print_header(system):
    print("\n\n**** Time: ", system.scheduler.get_clock(system).simple_time)


def show_target(context=None):
    print('Gated: ',
          Gating_Mechanism.gating_signals[0].efferents[0].receiver.owner.name,
          Gating_Mechanism.gating_signals[0].efferents[0].receiver.name)
    print('- Input_Layer.value:                  ', Input_Layer.parameters.value.get(context))
    print('- Output_Layer.value:                 ', Output_Layer.parameters.value.get(context))
    print('- Output_Layer.output_port.variable: ', Output_Layer.output_port.parameters.variable.get(context))
    print('- Output_Layer.output_port.value:    ', Output_Layer.output_port.parameters.value.get(context))

mySystem = pnl.System(processes=[p, g])

mySystem.reportOutputPref = False
# mySystem.show_graph(show_learning=True)

results = mySystem.run(
    num_trials=4,
    inputs=stim_list,
    call_before_trial=functools.partial(print_header, mySystem),
    call_after_trial=show_target,
)
github PrincetonUniversity / PsyNeuLink / Scripts / Misc / multitasking_nn_model.py View on Github external
def _generate_system(self):
        self.system = pnl.System(
            processes=self.input_output_processes + self.task_hidden_processes + \
                      self.task_output_processes + self.output_bias_processes + [self.hidden_bias_process],
            learning_rate=self.learning_rate
github PrincetonUniversity / PsyNeuLink / Scripts / Examples / System / Reinforcement-Learning.py View on Github external
learn_mech.output_ports[pnl.ERROR_SIGNAL].parameters.value.get(system),
            learn_mech.output_ports[pnl.LEARNING_SIGNAL].parameters.value.get(system),
            action_selection.output_port.parameters.value.get(system)[np.nonzero(action_selection.output_port.parameters.value.get(system))][0]
        )
    )

p.run(
    num_trials=10,
    inputs=[[[1, 1, 1]]],
    targets=reward,
    call_after_trial=functools.partial(show_weights, p)
)

input_list = {input_layer: [[1, 1, 1]]}

s = pnl.System(
    processes=[p],
    targets=[0]
)

s.show_graph(show_learning=pnl.ALL)

s.run(
    num_trials=10,
    inputs=input_list,
    targets=reward,
    call_before_trial=functools.partial(print_header, s),
    call_after_trial=functools.partial(show_weights, s)
)
github PrincetonUniversity / PsyNeuLink / psyneulink / library / models / Cohen_Huston1994_horse_race.py View on Github external
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:
colors_hidden_layer.set_log_conditions('value')
words_hidden_layer.set_log_conditions('value')

Bidirectional_Stroop.show()
# Bidirectional_Stroop.show_graph(show_dimensions=pnl.ALL)#,show_mechanism_structure=pnl.VALUES) # Uncomment to show graph of the system

# Create threshold function -------------------------------------------------------------------------------------------
# execution_context is automatically passed into Conditions, and references the execution context in which they are being run,
github PrincetonUniversity / PsyNeuLink / Scripts / Misc / Lena XOR.py View on Github external
)

proj=pnl.MappingProjection(matrix=(np.random.rand(2,2)),name="proj 1")
proj_h=pnl.MappingProjection(matrix=(np.random.rand(2,1)),name="proj 2")

#p_b=pnl.MappingProjection(matrix=.1*(np.random.rand(2,2)),name="proj bias 1")
#p_b_o=pnl.MappingProjection(matrix=.1*(np.random.rand(1,1)),name="proj bias 2")

output_layer=pnl.TransferMechanism(size=1, function=psyneulink.core.components.functions.transferfunctions.Logistic, name="output layer")

#bias_h=pnl.Process(pathway=[bias_mech_h,p_b,hidden_layer],learning=pnl.ENABLED)
#bias_out=pnl.Process(pathway=[bias_mech_out,p_b_o,output_layer],learning=pnl.ENABLED)

net3l=pnl.Process(pathway=[input_layer,proj,hidden_layer,proj_h,output_layer],learning=pnl.ENABLED)

sys3l=pnl.System(processes=[
    #bias_h,
    #bias_out,
    net3l],learning_rate=8)
#### AFTER THIS PART IS FINE #####

sys3l.show_graph(output_fmt = 'jupyter')

trials=4000
X=np.array([[1,1],[1,0],[0,1],[0,0]])
#X=[[1,1,1],[1,0,1],[0,1,1],[0,0,1]]
b_h_ins=[[1,1],[1,1],[1,1],[1,1]]
b_o_ins=[[1],[1],[1],[1]]
AND_labels_pnl=[[1],[0],[0],[0]]
OR_labels_pnl= [[1],[1],[1],[0]]
XOR_labels_pnl=[[0],[1],[1],[0]]