How to use the psyneulink.core.components.mechanisms.processing.transfermechanism.TransferMechanism 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 / system / test_system.py View on Github external
def test_system_run_with_sticky_condition(self):

        # Construction
        T = TransferMechanism()
        P = Process(pathway=[T])
        S = System(processes=[P])
        assert T.noise == 0.0
        assert T.parameter_ports['noise'].value == 0.0

        # Runtime param used for noise
        # ONLY mechanism value should reflect runtime param -- attr should be changed back by the time we inspect it
        S.run(inputs={T: 2.0},
              runtime_params={T: {"noise": (10.0, AfterTrial(1))}},
              num_trials=4)

        # Runtime param NOT used for noise
        S.run(inputs={T: 2.0})

        assert np.allclose(S.results, [[np.array([2.])],      # Trial 0 - condition not satisfied yet
                                       [np.array([2.])],      # Trial 1 - condition not satisfied yet
github PrincetonUniversity / PsyNeuLink / tests / composition / test_interfaces.py View on Github external
def test_parameter_CIM_routing_from_ControlMechanism(self):
        # Inner Composition
        ia = TransferMechanism(name='ia')
        ib = TransferMechanism(name='ib')
        icomp = Composition(name='icomp', pathways=[ia])
        # Outer Composition
        ocomp = Composition(name='ocomp', pathways=[icomp])
        cm = ControlMechanism(
            name='control_mechanism',
            control_signals=
            ControlSignal(projections=[(SLOPE, ib)])
        )
        icomp.add_linear_processing_pathway([ia, ib])
        ocomp.add_linear_processing_pathway([cm, icomp])
        res = ocomp.run([[2], [2], [2]])
        assert np.allclose(res, [[4], [4], [4]])
        assert len(ib.mod_afferents) == 1
        assert ib.mod_afferents[0].sender == icomp.parameter_CIM.output_port
        assert icomp.parameter_CIM_ports[ib.parameter_ports['slope']][0].path_afferents[0].sender == cm.output_port
github PrincetonUniversity / PsyNeuLink / tests / system / test_system.py View on Github external
def test_system_run_with_combined_condition(self):

        # Construction
        T = TransferMechanism()
        P = Process(pathway=[T])
        S = System(processes=[P])

        # Runtime param used for noise
        # ONLY mechanism value should reflect runtime param -- attr should be changed back by the time we inspect it
        S.run(inputs={T: 2.0},
              runtime_params={T: {"noise": (10.0, Any(AtTrial(1), AfterTrial(2)))}},
              num_trials=5)

        # Runtime param NOT used for noise
        S.run(inputs={T: 2.0})

        assert np.allclose(S.results, [[np.array([2.])],      # Trial 0 - NOT condition 0, NOT condition 1
                                       [np.array([12.])],     # Trial 1 - condition 0, NOT condition 1
                                       [np.array([2.])],      # Trial 2 - NOT condition 0, NOT condition 1
                                       [np.array([12.])],     # Trial 3 - NOT condition 0, condition 1
github PrincetonUniversity / PsyNeuLink / tests / mechanisms / test_recurrent_transfer_mechanism.py View on Github external
def test_recurrent_mech_process_matrix_change(self):
        R = RecurrentTransferMechanism(
            size=4,
            auto=1,
            hetero=-1)
        T = TransferMechanism(
            size=4,
            function=Linear)
        p = Process(size=4, pathway=[T, R], prefs=TestRecurrentTransferMechanismInSystem.simple_prefs)
        R.matrix = [[2, 0, 1, 3]] * 4

        p.run(inputs={T: [[1, 2, 3, 4]]})
        np.testing.assert_allclose(T.parameters.value.get(p), [[1, 2, 3, 4]])
        np.testing.assert_allclose(R.parameters.value.get(p), [[1, 2, 3, 4]])
        p.run(inputs={T: [[1, 3, 2, 5]]})
        np.testing.assert_allclose(R.recurrent_projection.matrix, [[2, 0, 1, 3]] * 4)
        np.testing.assert_allclose(T.parameters.value.get(p), [[1, 3, 2, 5]])
        np.testing.assert_allclose(R.parameters.value.get(p), [[21, 3, 12, 35]])
github PrincetonUniversity / PsyNeuLink / tests / composition / test_show_graph.py View on Github external
def test_converging_pathways(self):
        a = TransferMechanism(name="a", default_variable=[0, 0, 0])
        b = TransferMechanism(name="b")
        c = TransferMechanism(name="c", default_variable=[0, 0, 0, 0, 0])
        LC = LCControlMechanism(
            modulated_mechanisms=[a, b],
            objective_mechanism=ObjectiveMechanism(
                function=Linear, monitor=[b], name="lc_om"
            ),
            name="lc",
        )
        comp = Composition()
        comp.add_linear_processing_pathway([a, c])
        comp.add_linear_processing_pathway([b, c])

        a_label = comp._show_graph._get_graph_node_label(comp, a, show_dimensions=ALL)
        b_label = comp._show_graph._get_graph_node_label(comp, b, show_dimensions=ALL)
        c_label = comp._show_graph._get_graph_node_label(comp, c, show_dimensions=ALL)
github PrincetonUniversity / PsyNeuLink / tests / learning / test_multilayer.py View on Github external
def test_multilayer_log():
    Input_Layer = TransferMechanism(
        name='Input Layer',
        function=Logistic,
        default_variable=np.zeros((2,)),
    )

    Hidden_Layer_1 = TransferMechanism(
        name='Hidden Layer_1',
        function=Logistic(),
        # default_variable=np.zeros((5,)),
        size=5
    )

    Hidden_Layer_2 = TransferMechanism(
        name='Hidden Layer_2',
        function=Logistic(),
        default_variable=[0, 0, 0, 0],
github PrincetonUniversity / PsyNeuLink / tests / mechanisms / test_recurrent_transfer_mechanism.py View on Github external
def test_transfer_mech_process_matrix_change(self):
        from psyneulink.core.components.projections.pathway.mappingprojection import MappingProjection
        T1 = TransferMechanism(
            size=4,
            function=Linear)
        proj = MappingProjection(matrix=[[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]])
        T2 = TransferMechanism(
            size=4,
            function=Linear)

        p = Process(size=4, pathway=[T1, proj, T2])

        p.run(inputs={T1: [[1, 2, 3, 4]]})
        proj.matrix = [[2, 2, 2, 2], [2, 2, 2, 2], [2, 2, 2, 2], [2, 2, 2, 2]]
        assert np.allclose(proj.matrix, [[2, 2, 2, 2], [2, 2, 2, 2], [2, 2, 2, 2], [2, 2, 2, 2]])
        # p.run(inputs={T1: [[1, 2, 3, 4]]})
        T1.execute([[1, 2, 3, 4]])
        proj.execute()
        # removed this assert, because before the changes of most_recent_execution_id -> most_recent_context
github PrincetonUniversity / PsyNeuLink / tests / scheduling / test_scheduler.py View on Github external
def test_triangle_2(self):
        comp = Composition()
        A = TransferMechanism(function=Linear(slope=5.0, intercept=2.0), name='scheduler-pytests-A')
        B = TransferMechanism(function=Linear(intercept=4.0), name='scheduler-pytests-B')
        C = TransferMechanism(function=Linear(intercept=1.5), name='scheduler-pytests-C')
        for m in [A, B, C]:
            comp.add_node(m)
        comp.add_projection(MappingProjection(), A, B)
        comp.add_projection(MappingProjection(), A, C)

        sched = Scheduler(composition=comp)

        sched.add_condition(A, EveryNPasses(1))
        sched.add_condition(B, EveryNCalls(A, 1))
        sched.add_condition(C, EveryNCalls(A, 2))

        termination_conds = {}
        termination_conds[TimeScale.RUN] = AfterNTrials(1)
        termination_conds[TimeScale.TRIAL] = AfterNCalls(C, 3, time_scale=TimeScale.TRIAL)
        output = list(sched.run(termination_conds=termination_conds))
github PrincetonUniversity / PsyNeuLink / tests / mechanisms / test_transfer_mechanism.py View on Github external
def test_transfer_mech_size_var_incompatible1(self):
        T = TransferMechanism(
            name='T',
            size=2,
            default_variable=[[1, 2], [3, 4, 5]]
        )
        assert (T.defaults.variable[0] == [1, 2]).all() and (T.defaults.variable[1] == [3, 4, 5]).all() and len(T.defaults.variable) == 2
github PrincetonUniversity / PsyNeuLink / tests / scheduling / test_condition.py View on Github external
def test_WhenFinishedAll_noargs(self):
        comp = Composition()
        A = TransferMechanism(function=Linear(slope=5.0, intercept=2.0), name='A')
        B = TransferMechanism(function=Linear(intercept=4.0), name='B')
        C = TransferMechanism(function=Linear(intercept=1.5), name='C')
        for m in [A, B, C]:
            comp.add_node(m)
            m.is_finished_flag = False
        comp.add_projection(MappingProjection(), A, C)
        comp.add_projection(MappingProjection(), B, C)
        sched = Scheduler(composition=comp)

        sched.add_condition(A, Always())
        sched.add_condition(B, Always())
        sched.add_condition(C, Always())

        termination_conds = {}
        termination_conds[TimeScale.RUN] = AfterNTrials(1)
        termination_conds[TimeScale.TRIAL] = WhenFinishedAll()
        output = []
        i = 0