def test_transfer_mech_array_var_normal_array_noise(self):

        T = TransferMechanism(
            name='T',
            default_variable=[0, 0, 0, 0],
            function=Linear(),
            noise=[NormalDist(), NormalDist(), NormalDist(), NormalDist()],
            integration_rate=1.0,
            integrator_mode=True
        )
        T.reinitialize_when = Never()
        val = T.execute([0, 0, 0, 0])
        expected = [0.7610377251469934, 0.12167501649282841, 0.44386323274542566, 0.33367432737426683]
        for i in range(len(val[0])):
            assert val[0][i] ==  expected[i]
 def test_transfer_mech_2d_variable_noise(self):
     T = TransferMechanism(
         name='T',
         function=Linear(slope=2.0, intercept=1.0),
         noise=NormalDist(),
         default_variable=[[0.0, 0.0], [0.0, 0.0]]
     )
     val = T.execute([[1.0, 2.0], [3.0, 4.0]])
    def test_integrator_adaptive_noise_fn(self):
        I = IntegratorMechanism(
            name='IntegratorMechanism',
            function=AdaptiveIntegrator(noise=NormalDist().function),
            time_scale=TimeScale.TIME_STEP)

        val = float(I.execute(10))

        np.testing.assert_allclose(val, 11.86755799)
    def test_integrator_adaptive_noise_fn(self):
        I = IntegratorMechanism(
            name='IntegratorMechanism',
            function=AdaptiveIntegrator(noise=NormalDist()),
        )

        val = float(I.execute(10))

        np.testing.assert_allclose(val, 12.240893199201459)
 def test_transfer_mech_normal_fun(self):
     with pytest.raises(TransferError) as error_text:
         T = TransferMechanism(name='T',
                               default_variable=[0, 0, 0, 0],
                               function=NormalDist(),
                               time_constant=1.0,
                               integrator_mode=True)
         T.execute([0, 0, 0, 0])
     assert "must be a TRANSFER FUNCTION TYPE" in str(error_text.value)
 def test_recurrent_mech_normal_fun(self):
     with pytest.raises(TransferError) as error_text:
         R = RecurrentTransferMechanism(name='R',
                                        default_variable=[0, 0, 0, 0],
                                        function=NormalDist(),
                                        smoothing_factor=1.0,
                                        integrator_mode=True)
         R.execute([0, 0, 0, 0])
     assert "must be a TRANSFER FUNCTION TYPE" in str(error_text.value)
    def test_integrator_constant_noise_fn(self):
        I = IntegratorMechanism(
            name='IntegratorMechanism',
            function=ConstantIntegrator(noise=NormalDist()),
        )

        val = float(I.execute(10))

        np.testing.assert_allclose(val, 1.8675579901499675)
    def test_integrator_accumulator_noise_fn_var_list(self):
        I = IntegratorMechanism(
            name='IntegratorMechanism',
            default_variable=[0, 0, 0, 0],
            function=AccumulatorIntegrator(noise=NormalDist(), ),
        )

        val = I.execute([10, 10, 10, 10])[0]
        np.testing.assert_allclose(
            val, [0.95008842, -0.15135721, -0.10321885, 0.4105985])
Пример #9
0
def test_DDM_input_fn():
    with pytest.raises(TypeError) as error_text:
        stim = NormalDist().function
        T = DDM(name='DDM',
                function=DriftDiffusionIntegrator(noise=0.0,
                                                  rate=1.0,
                                                  time_step_size=1.0),
                time_scale=TimeScale.TIME_STEP)
        float(T.execute(stim))
    assert "not supported for the input types" in str(error_text.value)
    def test_integrator_constant_noise_fn_var_list(self):
        I = IntegratorMechanism(
            name='IntegratorMechanism',
            default_variable=[0, 0, 0, 0],
            function=ConstantIntegrator(noise=NormalDist(), ),
        )

        val = I.execute([10, 10, 10, 10])[0]

        np.testing.assert_allclose(
            val, [-0.15135721, -0.10321885, 0.4105985, 0.14404357])
    def test_integrator_accumulator_noise_fn_var_list(self):
        I = IntegratorMechanism(name='IntegratorMechanism',
                                default_variable=[0, 0, 0, 0],
                                function=AccumulatorIntegrator(
                                    noise=NormalDist().function,
                                    default_variable=[0, 0, 0, 0]),
                                time_scale=TimeScale.TIME_STEP)

        val = I.execute([10, 10, 10, 10])[0]
        np.testing.assert_allclose(
            val, [0.12167502, 0.44386323, 0.33367433, 1.49407907])
Пример #12
0
def test_DDM_rate_fn():
    with pytest.raises(typecheck.framework.InputParameterError) as error_text:
        stim = [10]
        T = DDM(name='DDM',
                default_variable=[0],
                function=DriftDiffusionIntegrator(noise=0.0,
                                                  rate=NormalDist().function,
                                                  time_step_size=1.0),
                time_scale=TimeScale.TIME_STEP)
        float(T.execute(stim)[0])
    assert "incompatible value" in str(error_text.value)
Пример #13
0
def test_DDM_noise_fn():
    with pytest.raises(FunctionError) as error_text:
        stim = 10
        T = DDM(name='DDM',
                function=DriftDiffusionIntegrator(noise=NormalDist().function,
                                                  rate=1.0,
                                                  time_step_size=1.0),
                time_scale=TimeScale.TIME_STEP)
        float(T.execute(stim)[0])
    assert "DriftDiffusionIntegrator requires noise parameter to be a float" in str(
        error_text.value)
    def test_integrator_adaptive_noise_fn_var_list(self):
        I = IntegratorMechanism(
            name='IntegratorMechanism',
            default_variable=[0, 0, 0, 0],
            function=AdaptiveIntegrator(noise=NormalDist(), ),
        )

        val = I.execute([10, 10, 10, 10])[0]

        np.testing.assert_allclose(
            val, [10.95008842, 9.84864279, 9.89678115, 10.4105985])
    def test_integrator_accumulator_noise_fn_var_list(self):
        I = IntegratorMechanism(
            name='IntegratorMechanism',
            default_variable=[0, 0, 0, 0],
            function=AccumulatorIntegrator(
                noise=NormalDist(),
            ),
        )

        val = I.execute([10, 10, 10, 10])[0]
        np.testing.assert_allclose(val, [0.14404357, 1.45427351, 0.76103773, 0.12167502])
    def test_integrator_constant_noise_fn_var_list(self):
        I = IntegratorMechanism(
            name='IntegratorMechanism',
            default_variable=[0, 0, 0, 0],
            function=ConstantIntegrator(
                noise=NormalDist(),
            ),
        )

        val = I.execute([10, 10, 10, 10])[0]

        np.testing.assert_allclose(val, [1.45427351, 0.76103773, 0.12167502, 0.44386323])
Пример #17
0
    def test_transfer_mech_array_var_normal_len_1_noise(self):

        T = TransferMechanism(name='T',
                              default_variable=[0, 0, 0, 0],
                              function=Linear(),
                              noise=NormalDist().function,
                              time_constant=1.0,
                              integrator_mode=True)
        val = T.execute([0, 0, 0, 0])
        assert np.allclose(val, [[
            0.41059850193837233, 0.144043571160878, 1.454273506962975,
            0.7610377251469934
        ]])
Пример #18
0
    def test_transfer_mech_normal_noise_standard_dev_error(self):
        with pytest.raises(FunctionError) as error_text:
            standard_deviation = -2.0
            T = TransferMechanism(
                name="T",
                default_variable=[0, 0, 0, 0],
                function=Linear(),
                noise=NormalDist(standard_dev=standard_deviation).function,
                time_constant=1.0,
                integrator_mode=True)

        assert "The standard_dev parameter" in str(
            error_text) and "must be greater than zero" in str(error_text)
    def test_integrator_simple_noise_fn(self):
        I = IntegratorMechanism(
            name='IntegratorMechanism',
            function=SimpleIntegrator(noise=NormalDist().function),
            time_scale=TimeScale.TIME_STEP)

        val = float(I.execute(10))

        I.function_object.reset_initializer = 5.0

        val2 = float(I.execute(0))

        np.testing.assert_allclose(val, 11.86755799)
        np.testing.assert_allclose(val2, 4.022722120123589)
    def test_integrator_simple_noise_fn(self):
        I = IntegratorMechanism(
            name='IntegratorMechanism',
            function=SimpleIntegrator(noise=NormalDist()),
        )

        val = float(I.execute(10))

        I.function_object.reinitialize(5.0)

        val2 = float(I.execute(0))

        np.testing.assert_allclose(val, 12.240893199201459)
        np.testing.assert_allclose(val2, 6.867557990149967)
Пример #21
0
 def target_function():
     val_1 = NormalDist(mean=3.0).function()
     return val_1
Пример #22
0
 def target_function():
     val_1 = NormalDist(mean=3.0).function()
     val_2 = NormalDist(mean=3.0).function()
     return [val_1, val_2]
Пример #23
0
 def target_function():
     val_1 = NormalDist(mean=3.0).function()
     val_2 = NormalDist(mean=3.0).function()
     target_value = np.array([val_1, val_2])
     return target_value