コード例 #1
0
    def test_6(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_mechanism(m)
        comp.add_projection(A, MappingProjection(), B)
        comp.add_projection(B, MappingProjection(), C)

        sched = Scheduler(composition=comp)

        sched.add_condition(A, BeforePass(5))
        sched.add_condition(B, AfterNCalls(A, 5))
        sched.add_condition(C, AfterNCalls(B, 1))

        termination_conds = {}
        termination_conds[TimeScale.RUN] = AfterNTrials(1)
        termination_conds[TimeScale.TRIAL] = AfterNCalls(C, 3)
        output = list(sched.run(termination_conds=termination_conds))

        expected_output = [A, A, A, A, A, B, C, B, C, B, C]
        # pprint.pprint(output)
        assert output == pytest.helpers.setify_expected_output(expected_output)
コード例 #2
0
    def test_termination_conditions_reset(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')
        for m in [A, B]:
            comp.add_mechanism(m)
        comp.add_projection(A, MappingProjection(), B)

        sched = Scheduler(composition=comp)

        sched.add_condition(B, EveryNCalls(A, 2))

        termination_conds = {}
        termination_conds[TimeScale.RUN] = AfterNTrials(1)
        termination_conds[TimeScale.TRIAL] = AfterNCalls(B, 2)

        output = list(sched.run(termination_conds=termination_conds))

        expected_output = [A, A, B, A, A, B]
        assert output == pytest.helpers.setify_expected_output(expected_output)

        # reset the RUN because schedulers run TRIALs
        sched.clock._increment_time(TimeScale.RUN)
        sched._reset_counts_total(TimeScale.RUN)

        output = list(sched.run())

        expected_output = [A, A, B]
        assert output == pytest.helpers.setify_expected_output(expected_output)
コード例 #3
0
ファイル: test_scheduler.py プロジェクト: jdcpni/PsyNeuLink-1
    def test_checkmark2_1(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')
        D = TransferMechanism(function=Linear(intercept=.5), name='D')
        for m in [A, B, C, D]:
            comp.add_mechanism(m)
        comp.add_projection(A, MappingProjection(), B)
        comp.add_projection(A, MappingProjection(), D)
        comp.add_projection(B, MappingProjection(), D)
        comp.add_projection(C, MappingProjection(), D)

        sched = Scheduler(composition=comp)

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

        termination_conds = {}
        termination_conds[TimeScale.RUN] = AfterNTrials(1)
        termination_conds[TimeScale.TRIAL] = AfterNCalls(
            D, 1, time_scale=TimeScale.TRIAL)
        output = list(sched.run(termination_conds=termination_conds))

        expected_output = [A, set([A, C]), B, A, set([A, C]), B, D]
        assert output == pytest.helpers.setify_expected_output(expected_output)
コード例 #4
0
    def test_save_state_before_simulations(self):

        A = TransferMechanism(name='A',
                              integrator_mode=True,
                              integration_rate=0.2)

        B = IntegratorMechanism(name='B',
                                function=DriftDiffusionIntegrator(rate=0.1))
        C = TransferMechanism(name='C')

        P = Process(pathway=[A, B, C])
        S = System(processes=[P], reinitialize_mechanisms_when=Never())

        S.run(inputs={A: [[1.0], [1.0]]})

        run_1_values = [A.value, B.value[0], C.value]

        # "Save state" code from EVCaux

        # Get any values that need to be reinitialized for each run
        reinitialization_values = {}
        for mechanism in S.stateful_mechanisms:
            # "save" the current state of each stateful mechanism by storing the values of each of its stateful
            # attributes in the reinitialization_values dictionary; this gets passed into run and used to call
            # the reinitialize method on each stateful mechanism.
            reinitialization_value = []

            if isinstance(mechanism.function_object, Integrator):
                for attr in mechanism.function_object.stateful_attributes:
                    reinitialization_value.append(
                        getattr(mechanism.function_object, attr))
            elif hasattr(mechanism, "integrator_function"):
                if isinstance(mechanism.integrator_function, Integrator):
                    for attr in mechanism.integrator_function.stateful_attributes:
                        reinitialization_value.append(
                            getattr(mechanism.integrator_function, attr))

            reinitialization_values[mechanism] = reinitialization_value

        # Allow values to continue accumulating so that we can set them back to the saved state
        S.run(inputs={A: [[1.0], [1.0]]})

        run_2_values = [A.value, B.value[0], C.value]

        S.run(inputs={A: [[1.0], [1.0]]},
              reinitialize_values=reinitialization_values)

        run_3_values = [A.value, B.value[0], C.value]

        assert np.allclose(run_2_values, run_3_values)
        assert np.allclose(
            run_1_values,
            [np.array([[0.36]]),
             np.array([[0.056]]),
             np.array([[0.056]])])
        assert np.allclose(run_2_values, [
            np.array([[0.5904]]),
            np.array([[0.16384]]),
            np.array([[0.16384]])
        ])
コード例 #5
0
    def test_2_target_mechanisms_fn_spec(self):
        A = TransferMechanism(name="learning-process-mech-A")
        B = TransferMechanism(name="learning-process-mech-B")
        C = TransferMechanism(name="learning-process-mech-C")

        LP = Process(name="learning-process", pathway=[A, B], learning=ENABLED)
        LP2 = Process(name="learning-process2",
                      pathway=[A, C],
                      learning=ENABLED)

        S = System(
            name="learning-system",
            processes=[LP, LP2],
        )

        def target_function():
            val_1 = NormalDist(mean=3.0).function()
            val_2 = NormalDist(mean=3.0).function()
            return [val_1, val_2]

        with pytest.raises(RunError) as error_text:

            S.run(inputs={A: [[[1.0]]]}, targets=target_function)

        assert 'Target values for' in str(error_text.value) and \
               'must be specified in a dictionary' in str(error_text.value)
コード例 #6
0
    def test_dict_list_and_function(self):
        A = TransferMechanism(name="diverging-learning-pathways-mech-A")
        B = TransferMechanism(name="diverging-learning-pathways-mech-B")
        C = TransferMechanism(name="diverging-learning-pathways-mech-C")
        D = TransferMechanism(name="diverging-learning-pathways-mech-D")
        E = TransferMechanism(name="diverging-learning-pathways-mech-E")

        P1 = Process(name="learning-pathway-1",
                     pathway=[A, B, C],
                     learning=ENABLED)
        P2 = Process(name="learning-pathway-2",
                     pathway=[A, D, E],
                     learning=ENABLED)

        S = System(name="learning-system", processes=[P1, P2])

        def target_function():
            val_1 = NormalDist(mean=3.0).function()
            return val_1

        S.run(inputs={A: 1.0}, targets={C: 2.0, E: target_function})

        S.run(inputs={A: 1.0}, targets={C: [2.0], E: target_function})

        S.run(inputs={A: 1.0}, targets={C: [[2.0]], E: target_function})
コード例 #7
0
    def test_initial_values_softmax(self):
        T = TransferMechanism(default_variable=[[0.0, 0.0], [0.0, 0.0]],
                              function=SoftMax(),
                              integrator_mode=True,
                              integration_rate=0.5,
                              initial_value=[[1.0, 2.0], [3.0, 4.0]])
        T2 = TransferMechanism()
        P = Process(pathway=[T, T2])
        S = System(processes=[P])

        S.run(inputs={T: [[1.5, 2.5], [3.5, 4.5]]})

        result = T.value
        # Expected results
        # integrator function:
        # input = [[1.5, 2.5], [3.5, 4.5]]  |  output = [[1.25, 2.25]], [3.25, 4.25]]
        integrator_fn = AdaptiveIntegrator(rate=0.5,
                                           default_variable=[[0.0, 0.0], [0.0, 0.0]],
                                           initializer=[[1.0, 2.0], [3.0, 4.0]])
        expected_result_integrator = integrator_fn.function([[1.5, 2.5], [3.5, 4.5]])

        S1 = SoftMax()
        expected_result_s1 = S1.function([[1.25, 2.25]])

        S2 = SoftMax()
        expected_result_s2 = S2.function([[3.25, 4.25]])

        assert np.allclose(expected_result_integrator, T.integrator_function_value)
        assert np.allclose(expected_result_s1, result[0])
        assert np.allclose(expected_result_s2, result[1])
コード例 #8
0
ファイル: test_scheduler.py プロジェクト: jdcpni/PsyNeuLink-1
    def test_9(self):
        comp = Composition()
        A = TransferMechanism(function=Linear(slope=5.0, intercept=2.0),
                              name='A')
        B = TransferMechanism(function=Linear(intercept=4.0), name='B')
        for m in [A, B]:
            comp.add_mechanism(m)
        comp.add_projection(A, MappingProjection(), B)

        sched = Scheduler(composition=comp)

        sched.add_condition(A, EveryNPasses(1))
        sched.add_condition(B, WhenFinished(A))

        termination_conds = {}
        termination_conds[TimeScale.RUN] = AfterNTrials(1)
        termination_conds[TimeScale.TRIAL] = AfterNCalls(B, 2)

        output = []
        i = 0
        for step in sched.run(termination_conds=termination_conds):
            if i == 3:
                A.is_finished = True
            output.append(step)
            i += 1

        expected_output = [A, A, A, A, B, A, B]
        assert output == pytest.helpers.setify_expected_output(expected_output)
コード例 #9
0
ファイル: test_condition.py プロジェクト: jdcpni/PsyNeuLink-1
    def test_WhenFinishedAll_2(self):
        comp = Composition()
        A = TransferMechanism(function=Linear(slope=5.0, intercept=2.0),
                              name='A')
        A.is_finished = False
        B = TransferMechanism(function=Linear(intercept=4.0), name='B')
        B.is_finished = True
        C = TransferMechanism(function=Linear(intercept=1.5), name='C')
        for m in [A, B, C]:
            comp.add_mechanism(m)
        comp.add_projection(A, MappingProjection(), C)
        comp.add_projection(B, MappingProjection(), C)
        sched = Scheduler(composition=comp)

        sched.add_condition(A, EveryNPasses(1))
        sched.add_condition(B, EveryNPasses(1))
        sched.add_condition(C, WhenFinishedAll(A, B))

        termination_conds = {}
        termination_conds[TimeScale.RUN] = AfterNTrials(1)
        termination_conds[TimeScale.TRIAL] = AfterNCalls(A, 5)
        output = list(sched.run(termination_conds=termination_conds))
        expected_output = [
            set([A, B]),
            set([A, B]),
            set([A, B]),
            set([A, B]),
            set([A, B]),
        ]
        assert output == pytest.helpers.setify_expected_output(expected_output)
コード例 #10
0
ファイル: test_scheduler.py プロジェクト: jdcpni/PsyNeuLink-1
    def test_no_termination_conds(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_mechanism(m)
        comp.add_projection(A, MappingProjection(), B)
        comp.add_projection(B, MappingProjection(), C)

        sched = Scheduler(composition=comp)

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

        output = list(sched.run())

        expected_output = [
            A,
            A,
            B,
            A,
            A,
            B,
            A,
            A,
            B,
            C,
        ]
        # pprint.pprint(output)
        assert output == pytest.helpers.setify_expected_output(expected_output)
コード例 #11
0
ファイル: test_scheduler.py プロジェクト: jdcpni/PsyNeuLink-1
    def test_triangle_4b(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_mechanism(m)
        comp.add_projection(A, MappingProjection(), B)
        comp.add_projection(A, MappingProjection(), C)

        sched = Scheduler(composition=comp)

        sched.add_condition(A, EveryNPasses(1))
        sched.add_condition(B, EveryNCalls(A, 2))
        sched.add_condition(C, All(WhenFinished(A), AfterNCalls(B, 3)))

        termination_conds = {}
        termination_conds[TimeScale.RUN] = AfterNTrials(1)
        termination_conds[TimeScale.TRIAL] = AfterNCalls(C, 1)
        output = []
        i = 0
        for step in sched.run(termination_conds=termination_conds):
            if i == 10:
                A.is_finished = True
            output.append(step)
            i += 1

        expected_output = [A, A, B, A, A, B, A, A, B, A, A, set([B, C])]
        # pprint.pprint(output)
        assert output == pytest.helpers.setify_expected_output(expected_output)
コード例 #12
0
ファイル: test_scheduler.py プロジェクト: jdcpni/PsyNeuLink-1
    def test_invtriangle_1(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_mechanism(m)
        comp.add_projection(A, MappingProjection(), C)
        comp.add_projection(B, MappingProjection(), C)

        sched = Scheduler(composition=comp)

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

        termination_conds = {}
        termination_conds[TimeScale.RUN] = AfterNTrials(1)
        termination_conds[TimeScale.TRIAL] = AfterNCalls(
            C, 4, time_scale=TimeScale.TRIAL)
        output = list(sched.run(termination_conds=termination_conds))

        expected_output = [
            A, set([A, B]), A, C,
            set([A, B]), C, A, C,
            set([A, B]), C
        ]
        # pprint.pprint(output)
        assert output == pytest.helpers.setify_expected_output(expected_output)
コード例 #13
0
 def test_add_input_state_with_projection_by_assigning_owner_error(self):
     with pytest.raises(StateError) as error_text:
         S1 = TransferMechanism()
         S2 = TransferMechanism()
         TransferMechanism(name='T',
                           input_states=[{'MY INPUT 1':[S1],
                                          'MY INPUT 2':[S2]}])
コード例 #14
0
ファイル: test_scheduler.py プロジェクト: jdcpni/PsyNeuLink-1
    def test_linear_ABBCC(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_mechanism(m)
        comp.add_projection(A, MappingProjection(), B)
        comp.add_projection(B, MappingProjection(), C)

        sched = Scheduler(composition=comp)

        sched.add_condition(A, Any(AtPass(0), EveryNCalls(C, 2)))
        sched.add_condition(B, Any(JustRan(A), JustRan(B)))
        sched.add_condition(C, Any(EveryNCalls(B, 2), JustRan(C)))

        termination_conds = {}
        termination_conds[TimeScale.RUN] = AfterNTrials(1)
        termination_conds[TimeScale.TRIAL] = AfterNCalls(
            C, 4, time_scale=TimeScale.TRIAL)
        output = list(sched.run(termination_conds=termination_conds))

        expected_output = [A, B, B, C, C, A, B, B, C, C]
        assert output == pytest.helpers.setify_expected_output(expected_output)
コード例 #15
0
    def test_projection_with_matrix_and_sender(self):
        m = TransferMechanism(size=2)
        p = MappingProjection(sender=m, matrix=[[0, 0, 0], [0, 0, 0]])
        T = TransferMechanism(input_states=[p])

        np.testing.assert_array_equal(T.instance_defaults.variable, np.array([[0, 0, 0]]))
        assert len(T.input_states) == 1
コード例 #16
0
    def test_five_ABABCDE(self):
        A = TransferMechanism(
            name='A',
            default_variable=[0],
            function=Linear(slope=2.0),
        )

        B = TransferMechanism(
            name='B',
            default_variable=[0],
            function=Linear(slope=2.0),
        )

        C = IntegratorMechanism(name='C',
                                default_variable=[0],
                                function=SimpleIntegrator(rate=.5))

        D = TransferMechanism(
            name='D',
            default_variable=[0],
            function=Linear(slope=1.0),
        )

        E = TransferMechanism(
            name='E',
            default_variable=[0],
            function=Linear(slope=2.0),
        )

        p = Process(default_variable=[0], pathway=[A, C, D], name='p')

        q = Process(default_variable=[0], pathway=[B, C, E], name='q')

        s = System(processes=[p, q], name='s')

        term_conds = {TimeScale.TRIAL: AfterNCalls(E, 1)}
        stim_list = {A: [[1]], B: [[2]]}

        sched = Scheduler(system=s)
        sched.add_condition(C, Any(EveryNCalls(A, 1), EveryNCalls(B, 1)))
        sched.add_condition(D, EveryNCalls(C, 1))
        sched.add_condition(E, EveryNCalls(C, 1))
        s.scheduler_processing = sched

        s.run(inputs=stim_list, termination_processing=term_conds)

        terminal_mechs = [D, E]
        expected_output = [
            [
                numpy.array([3.]),
            ],
            [
                numpy.array([6.]),
            ],
        ]

        for m in range(len(terminal_mechs)):
            for i in range(len(expected_output[m])):
                numpy.testing.assert_allclose(
                    expected_output[m][i], terminal_mechs[m].output_values[i])
コード例 #17
0
ファイル: test_scheduler.py プロジェクト: jdcpni/PsyNeuLink-1
    def test_6_two_trials(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_mechanism(m)
        comp.add_projection(A, MappingProjection(), B)
        comp.add_projection(B, MappingProjection(), C)

        sched = Scheduler(composition=comp)

        sched.add_condition(A, BeforePass(5))
        sched.add_condition(B, AfterNCalls(A, 5))
        sched.add_condition(C, AfterNCalls(B, 1))

        termination_conds = {}
        termination_conds[TimeScale.RUN] = AfterNTrials(2)
        termination_conds[TimeScale.TRIAL] = AfterNCalls(C, 3)
        comp.run(inputs={A: range(6)},
                 scheduler_processing=sched,
                 termination_processing=termination_conds)
        output = sched.execution_list

        expected_output = [
            A, A, A, A, A, B, C, B, C, B, C, A, A, A, A, A, B, C, B, C, B, C
        ]
        # pprint.pprint(output)
        assert output == pytest.helpers.setify_expected_output(expected_output)
コード例 #18
0
    def test_initialize_mechanisms(self):
        A = TransferMechanism(name='A')
        B = TransferMechanism(name='B')
        C = RecurrentTransferMechanism(name='C',
                                       auto=1.0)

        abc_process = Process(pathway=[A, B, C])

        abc_system = System(processes=[abc_process])

        C.log.set_log_conditions('value')

        abc_system.run(inputs={A: [1.0, 2.0, 3.0]},
                       initial_values={A: 1.0,
                                       B: 1.5,
                                       C: 2.0},
                       initialize=True)

        abc_system.run(inputs={A: [1.0, 2.0, 3.0]},
                       initial_values={A: 1.0,
                                       B: 1.5,
                                       C: 2.0},
                       initialize=False)

        # Run 1 --> Execution 1: 1 + 2 = 3    |    Execution 2: 3 + 2 = 5    |    Execution 3: 5 + 3 = 8
        # Run 2 --> Execution 1: 8 + 1 = 9    |    Execution 2: 9 + 2 = 11    |    Execution 3: 11 + 3 = 14
        assert np.allclose(C.log.nparray_dictionary('value')['value'], [[[3]], [[5]], [[8]], [[9]], [[11]], [[14]]])
コード例 #19
0
    def test_chain(self):
        a = TransferMechanism(name='a', default_variable=[0, 0, 0])
        b = TransferMechanism(name='b')
        c = TransferMechanism(name='c')
        d = TransferMechanism(name='d')
        e = TransferMechanism(name='e')

        p1 = Process(pathway=[a, b, c], name='p1')
        p2 = Process(pathway=[c, d, e], name='p2')

        s = System(
            processes=[p1, p2],
            name='Chain System',
            initial_values={a: [1, 1, 1]},
        )

        inputs = {a: [[2, 2, 2], [0, 0, 0]]}
        s.run(inputs=inputs)

        assert [a] == s.origin_mechanisms.mechanisms
        assert [e] == s.terminal_mechanisms.mechanisms

        assert a.systems[s] == ORIGIN
        assert b.systems[s] == INTERNAL
        assert c.systems[s] == INTERNAL
        assert d.systems[s] == INTERNAL
        assert e.systems[s] == TERMINAL
コード例 #20
0
 def test_default_name_and_projections_listing_for_input_state_in_constructor(
         self):
     T1 = TransferMechanism()
     my_input_state = InputState(projections=[T1])
     T2 = TransferMechanism(input_states=[my_input_state])
     assert T2.input_states[0].name == 'InputState-0'
     assert T2.input_states[0].projections[0].sender.name == 'RESULTS'
コード例 #21
0
ファイル: test_condition.py プロジェクト: jdcpni/PsyNeuLink-1
    def test_change_scheduler(self):
        comp = Composition()
        A = TransferMechanism(function=Linear(slope=5.0, intercept=2.0),
                              name='A')
        B = TransferMechanism(function=Linear(slope=5.0, intercept=2.0),
                              name='B')
        for m in [A, B]:
            comp.add_mechanism(m)

        s1 = Scheduler(composition=comp)
        s2 = Scheduler(composition=comp)

        cs = ConditionSet(s1)
        cs.add_condition(A, Always())
        cs.add_condition(B, Always())

        assert cs.scheduler is s1
        for owner, cond in cs.conditions.items():
            assert cond.scheduler is s1

        cs.scheduler = s2

        assert cs.scheduler is s2
        for owner, cond in cs.conditions.items():
            assert cond.scheduler is s2
コード例 #22
0
    def test_projection_with_sender_and_default(self):
        t = TransferMechanism(size=3)
        p = MappingProjection(sender=t)
        T = TransferMechanism(default_variable=[[0, 0]], input_states=[p])

        np.testing.assert_array_equal(T.instance_defaults.variable, np.array([[0, 0]]))
        assert len(T.input_states) == 1
コード例 #23
0
ファイル: test_gilzenrat.py プロジェクト: karoara/PsyNeuLink
    def test_default_lc_control_mechanism(self):
        G = 1.0
        k = 0.5
        starting_value_LC = 2.0
        user_specified_gain = 1.0

        A = TransferMechanism(function=Logistic(gain=user_specified_gain))

        B = TransferMechanism(function=Logistic(gain=user_specified_gain))
        # B.output_states[0].value *= 0.0  # Reset after init | Doesn't matter here b/c default var = zero, no intercept

        P = Process(pathway=[A, B])

        LC = LCControlMechanism(modulated_mechanisms=[A, B],
                                base_level_gain=G,
                                scaling_factor_gain=k,
                                objective_mechanism=ObjectiveMechanism(
                                    function=Linear,
                                    monitored_output_states=[B],
                                    name='LC ObjectiveMechanism'))
        for output_state in LC.output_states:
            output_state.value *= starting_value_LC

        S = System(processes=[P])

        gain_created_by_LC_output_state_1 = []
        gain_created_by_LC_output_state_2 = []
        mod_gain_assigned_to_A = []
        base_gain_assigned_to_A = []
        mod_gain_assigned_to_B = []
        base_gain_assigned_to_B = []

        def report_trial():
            gain_created_by_LC_output_state_1.append(LC.output_states[0].value)
            gain_created_by_LC_output_state_2.append(LC.output_states[1].value)
            mod_gain_assigned_to_A.append(A.mod_gain[0])
            mod_gain_assigned_to_B.append(B.mod_gain[0])
            base_gain_assigned_to_A.append(A.function_object.gain)
            base_gain_assigned_to_B.append(B.function_object.gain)

        S.run(inputs={A: [[1.0], [1.0], [1.0], [1.0], [1.0]]},
              call_after_trial=report_trial)

        # (1) First value of gain in mechanisms A and B must be whatever we hardcoded for LC starting value
        assert mod_gain_assigned_to_A[0] == starting_value_LC

        # (2) _gain should always be set to user-specified value
        for i in range(5):
            assert base_gain_assigned_to_A[i] == user_specified_gain
            assert base_gain_assigned_to_B[i] == user_specified_gain

        # (3) LC output on trial n becomes gain of A and B on trial n + 1
        assert np.allclose(mod_gain_assigned_to_A[1:],
                           gain_created_by_LC_output_state_1[0:-1])
        assert np.allclose(mod_gain_assigned_to_B[1:],
                           gain_created_by_LC_output_state_2[0:-1])

        # (4) mechanisms A and B should always have the same gain values (b/c they are identical)
        assert np.allclose(mod_gain_assigned_to_A, mod_gain_assigned_to_B)
コード例 #24
0
 def test_2_item_tuple_value_for_first_item(self):
     R2 = TransferMechanism(size=3)
     T = TransferMechanism(input_states=[([0,0], R2)])
     np.testing.assert_array_equal(T.instance_defaults.variable, np.array([[0, 0]]))
     assert len(T.input_states) == 1
     assert len(T.input_state.path_afferents[0].sender.instance_defaults.variable) == 3
     assert len(T.input_state.instance_defaults.variable) == 2
     T.execute()
コード例 #25
0
 def test_mech_spec_list(self):
     R1 = TransferMechanism(output_states=['FIRST', 'SECOND'])
     T = TransferMechanism(default_variable=[[0]], input_states=[R1])
     np.testing.assert_array_equal(T.instance_defaults.variable,
                                   np.array([[0]]))
     assert len(T.input_states) == 1
     assert T.input_state.path_afferents[0].sender == R1.output_state
     T.execute()
コード例 #26
0
 def test_use_set_to_specify_projections_for_input_state_error(self):
     with pytest.raises(ProjectionError) as error_text:
         T1 = TransferMechanism()
         T2 = TransferMechanism()
         TransferMechanism(input_states=[{'MY STATE':{T1, T2}}])
     assert ('Connection specification for InputState of' in str(error_text.value)
             and 'is a set' in str(error_text.value)
             and 'it should be a list' in str(error_text.value))
コード例 #27
0
 def test_projection_tuple_with_matrix_spec(self):
     R2 = TransferMechanism(size=3)
     T = TransferMechanism(size=2, input_states=[(R2, None, None, np.zeros((3, 2)))])
     np.testing.assert_array_equal(T.instance_defaults.variable, np.array([[0, 0]]))
     assert len(T.input_states) == 1
     assert len(T.input_state.path_afferents[0].sender.instance_defaults.variable) == 3
     assert len(T.input_state.instance_defaults.variable) == 2
     T.execute()
コード例 #28
0
 def test_2_item_tuple_spec(self):
     R2 = TransferMechanism(size=3)
     T = TransferMechanism(size=2, input_states=[(R2, np.zeros((3, 2)))])
     np.testing.assert_array_equal(T.instance_defaults.variable, np.array([[0, 0]]))
     assert len(T.input_states) == 1
     assert len(T.input_state.path_afferents[0].sender.instance_defaults.variable) == 3
     assert T.input_state.socket_width == 2
     T.execute()
コード例 #29
0
 def test_name_assigned_before_error(self):
     name = 'target'
     with pytest.raises(StateError) as error_text:
         m = TransferMechanism(default_variable=[0, 0, 0])
         i = InputState(owner=m, name=name, variable=[0, 0, 0])
         TransferMechanism(input_states=[i])
     assert (belongs_to_another_mechanism_error_text in str(
         error_text.value) and 'Attempt to assign a State ({})'.format(name)
             in str(error_text.value))
コード例 #30
0
    def test_list_of_mechanisms_with_gating_mechanism(self):

        T1 = TransferMechanism(name='T6')
        G = GatingMechanism(gating_signals=['a','b'])
        T2 = TransferMechanism(input_states=[[T1, G]],
                               output_states=[G.gating_signals['b']])
        assert T2.input_states[0].path_afferents[0].sender.owner.name=='T6'
        assert T2.input_states[0].mod_afferents[0].sender.name=='a'
        assert T2.output_states[0].mod_afferents[0].sender.name=='b'