Example #1
0
A = pnl.TransferMechanism(name="A")
B = pnl.TransferMechanism(name="B")
C = pnl.TransferMechanism(name="C")
D = pnl.TransferMechanism(name="D")

comp.add_linear_processing_pathway([A, B, C])
comp.add_linear_processing_pathway([A, B, D])

# TimeInterval is not yet implemented in PsyNeuLink
comp.scheduler.add_condition_set({
    A:
    pnl.TimeInterval(repeat=7, unit="ms"),
    B:
    pnl.All(
        pnl.TimeInterval(start=1, repeat=1, unit="ms"),
        pnl.Not(pnl.TimeInterval(start=6, repeat=7, unit="ms")),
        pnl.Not(pnl.TimeInterval(start=7, repeat=7, unit="ms")),
    ),
    C:
    pnl.TimeInterval(start=6, repeat=7, unit="ms"),
    D:
    pnl.TimeInterval(start=13, repeat=7, unit="ms"),
})

comp.run(inputs={A: 1}, scheduling_mode=pnl.SchedulingMode.EXACT_TIME)

print("\n".join([
    "{:~}: {}".format(
        comp.scheduler.execution_timestamps[comp.default_execution_id]
        [i].absolute,
        {node.name
Example #2
0
      (simtime, fhn))

fn = pnl.IntegratorMechanism(name='fn', function=fhn)

comp = pnl.Composition(name='comp')

im = pnl.IntegratorMechanism(name='im')  # only used to demonstrate conditions

comp.add_linear_processing_pathway([fn, im])
comp.scheduler.add_condition_set({
    fn:
    pnl.Always(),  # default
    im:
    pnl.All(  # run when both conditions are met
        pnl.EveryNCalls(fn, 1 / dt),  # every 1ms, based on fn frequency
        pnl.AfterNCalls(fn,
                        .8 * simtime / dt)  # after 80ms, based on fn frequency
    )
})

comp.termination_processing = {
    pnl.TimeScale.RUN: pnl.Never(
    ),  # default, "Never" for early termination - ends when all trials finished
    pnl.TimeScale.TRIAL: pnl.AfterNCalls(fn, int(simtime / dt))
}

print('Running the SimpleFN model...')

comp.run(inputs={fn: 0}, log=True)

print('Finished running the SimpleFN model')
                             function=pnl.FitzHughNagumoIntegrator(
                                 name='FitzHughNagumoIntegrator Function-0',
                                 d_v=1,
                                 initial_v=-1,
                                 initializer=[[0]],
                                 default_variable=[[0]]))
im = pnl.IntegratorMechanism(name='im',
                             function=pnl.AdaptiveIntegrator(
                                 initializer=[[0]],
                                 rate=0.5,
                                 default_variable=[[0]]))

comp.add_node(fn)
comp.add_node(im)

comp.add_projection(projection=pnl.MappingProjection(
    name='MappingProjection from fn[OutputPort-0] to im[InputPort-0]',
    function=pnl.LinearMatrix(matrix=[[1.0]], default_variable=[-1.0])),
                    sender=fn,
                    receiver=im)

comp.scheduler.add_condition(fn, pnl.Always())
comp.scheduler.add_condition(
    im, pnl.All(pnl.EveryNCalls(fn, 20.0), pnl.AfterNCalls(fn, 1600.0)))

comp.scheduler.termination_conds = {
    pnl.TimeScale.RUN: pnl.Never(),
    pnl.TimeScale.TRIAL: pnl.AfterNCalls(fn, 2000)
}
comp.show_graph()
Stroop_model.add_linear_processing_pathway(task_color_pathway)
Stroop_model.add_linear_processing_pathway(task_word_pathway)
Stroop_model.add_linear_processing_pathway(decision_pathway)
Stroop_model.add_controller(control)

# Assign conditions:
settling_time = 10
Stroop_model.scheduler.add_condition(
    color_hidden, pnl.EveryNCalls(task, settling_time)
)
Stroop_model.scheduler.add_condition(
    word_hidden, pnl.EveryNCalls(task, settling_time)
)
Stroop_model.scheduler.add_condition(
    output,
    pnl.All(pnl.EveryNCalls(color_hidden, 1), pnl.EveryNCalls(word_hidden, 1)),
)
Stroop_model.scheduler.add_condition(decision, pnl.EveryNCalls(output, 1))


#Stroop_model.show_graph(show_controller=True)
#Stroop_model.run(animate={"show_controller":True})

red =   [1,0]
green = [0,1]
word =  [0,1]
color = [1,0]
                                   # Trial 1  Trial 2
Stroop_model.run(inputs={color_input:[red,     red   ],
                         word_input: [red,     green ],
                         task_input: [color,   color ]},
)
Stroop_model.add_projection(
    projection=pnl.MappingProjection(
        name="MappingProjection_from_TASK_RESULT__to_word_hidden_InputPort_0",
        function=pnl.LinearMatrix(default_variable=[0.5, 0.5],
                                  matrix=[[0.0, 0.0], [4.0, 4.0]]),
    ),
    sender=TASK,
    receiver=word_hidden,
)
Stroop_model.add_controller(CONTROL)

Stroop_model.scheduler.add_condition(word_hidden,
                                     pnl.EveryNCalls(dependency=TASK, n=10))
Stroop_model.scheduler.add_condition(color_hidden,
                                     pnl.EveryNCalls(dependency=TASK, n=10))
Stroop_model.scheduler.add_condition(
    OUTPUT,
    pnl.All(
        pnl.EveryNCalls(dependency=color_hidden, n=1),
        pnl.EveryNCalls(dependency=word_hidden, n=1),
    ),
)
Stroop_model.scheduler.add_condition(DECISION,
                                     pnl.EveryNCalls(dependency=OUTPUT, n=1))

Stroop_model.scheduler.termination_conds = {
    pnl.TimeScale.ENVIRONMENT_SEQUENCE: pnl.Never(),
    pnl.TimeScale.ENVIRONMENT_STATE_UPDATE: pnl.AllHaveRun(),
}
    B,
    pnl.All(
        pnl.TimeInterval(
            repeat="1 millisecond",
            start="1 millisecond",
            end=None,
            unit="ms",
            start_inclusive=True,
            end_inclusive=True,
        ),
        pnl.Not(
            condition=pnl.TimeInterval(
                repeat="7 millisecond",
                start="6 millisecond",
                end=None,
                unit="ms",
                start_inclusive=True,
                end_inclusive=True,
            )
        ),
        pnl.Not(
            condition=pnl.TimeInterval(
                repeat="7 millisecond",
                start="7 millisecond",
                end=None,
                unit="ms",
                start_inclusive=True,
                end_inclusive=True,
            )
        ),
    ),
)
Example #7
0
import psyneulink as pnl

comp = pnl.Composition(name='comp')
A = pnl.TransferMechanism(name='A')
B = pnl.TransferMechanism(name='B')
C = pnl.TransferMechanism(name='C')

comp.add_linear_processing_pathway([A, B, C])

comp.scheduler.add_condition_set({
    A:
    pnl.TimeInterval(interval=7, unit='ms'),
    B:
    pnl.All(pnl.TimeInterval(start=1, interval=1, unit='ms'),
            pnl.Not(pnl.TimeInterval(start=6, interval=7, unit='ms')),
            pnl.Not(pnl.TimeInterval(start=7, interval=7, unit='ms'))),
    C:
    pnl.TimeInterval(start=6, interval=7, unit='ms')
})

#  0   1   2   3   4   5   6   7   8   9   10  11  12  13
#  A   B   B   B   B   B   C   A   B   B   B   B   B   C
Example #8
0
)
ABCD.add_projection(
    projection=pnl.MappingProjection(
        name="MappingProjection_from_A_RESULT__to_C_InputPort_0_",
        function=pnl.LinearMatrix(default_variable=[2.0], matrix=[[1.0]]),
    ),
    sender=A,
    receiver=C,
)
ABCD.add_projection(
    projection=pnl.MappingProjection(
        name="MappingProjection_from_C_RESULT__to_D_InputPort_0_",
        function=pnl.LinearMatrix(default_variable=[1.0], matrix=[[1.0]]),
    ),
    sender=C,
    receiver=D,
)

ABCD.scheduler.add_condition(A, pnl.Always())
ABCD.scheduler.add_condition(C, pnl.EveryNCalls(dependency=A, n=1))
ABCD.scheduler.add_condition(B, pnl.EveryNCalls(dependency=A, n=1))
ABCD.scheduler.add_condition(
    D,
    pnl.All(pnl.EveryNCalls(dependency=C, n=1),
            pnl.EveryNCalls(dependency=B, n=1)))

ABCD.scheduler.termination_conds = {
    pnl.TimeScale.ENVIRONMENT_SEQUENCE: pnl.Never(),
    pnl.TimeScale.ENVIRONMENT_STATE_UPDATE: pnl.AllHaveRun(),
}
Example #9
0
    name='MappingProjection from A[RESULT] to B[InputPort-0]',
    function=pnl.LinearMatrix(matrix=[[1.0]], default_variable=[2.0])),
                    sender=A,
                    receiver=B)
ABCD.add_projection(projection=pnl.MappingProjection(
    name='MappingProjection from A[RESULT] to C[InputPort-0]',
    function=pnl.LinearMatrix(matrix=[[1.0]], default_variable=[2.0])),
                    sender=A,
                    receiver=C)
ABCD.add_projection(projection=pnl.MappingProjection(
    name='MappingProjection from B[RESULT] to D[InputPort-0]',
    function=pnl.LinearMatrix(matrix=[[1.0]], default_variable=[0.5])),
                    sender=B,
                    receiver=D)
ABCD.add_projection(projection=pnl.MappingProjection(
    name='MappingProjection from C[RESULT] to D[InputPort-0]',
    function=pnl.LinearMatrix(matrix=[[1.0]], default_variable=[1.0])),
                    sender=C,
                    receiver=D)

ABCD.scheduler.add_condition(A, pnl.Always())
ABCD.scheduler.add_condition(B, pnl.EveryNCalls(A, 1))
ABCD.scheduler.add_condition(C, pnl.EveryNCalls(A, 1))
ABCD.scheduler.add_condition(
    D, pnl.All(pnl.EveryNCalls(C, 1), pnl.EveryNCalls(B, 1)))

ABCD.scheduler.termination_conds = {
    pnl.TimeScale.RUN: pnl.Never(),
    pnl.TimeScale.TRIAL: pnl.AllHaveRun()
}
comp.show_graph()
Example #10
0
comp.add_node(im)

comp.add_projection(
    projection=pnl.MappingProjection(
        name="MappingProjection_from_fn_OutputPort_0__to_im_InputPort_0_",
        function=pnl.LinearMatrix(default_variable=[-1.0], matrix=[[1.0]]),
    ),
    sender=fn,
    receiver=im,
)

comp.scheduler.add_condition(fn, pnl.Always())
comp.scheduler.add_condition(
    im,
    pnl.All(
        pnl.EveryNCalls(dependency=fn, n=20.0),
        pnl.AfterNCalls(dependency=fn,
                        n=1600.0,
                        time_scale=pnl.TimeScale.ENVIRONMENT_STATE_UPDATE),
    ),
)

comp.scheduler.termination_conds = {
    pnl.TimeScale.ENVIRONMENT_SEQUENCE:
    pnl.Never(),
    pnl.TimeScale.ENVIRONMENT_STATE_UPDATE:
    pnl.AfterNCalls(dependency=fn,
                    n=2000,
                    time_scale=pnl.TimeScale.ENVIRONMENT_STATE_UPDATE),
}