def test_constant_integrator(self):
        I = IntegratorMechanism(
            function=ConstantIntegrator(
                initializer=10.0,
                rate=5.0,
                offset=10
            )
        )
        # P = Process(pathway=[I])
        # constant integrator does not use input value (variable)

        # step 1:
        val = I.execute(20000)
        # value = 10 + 5
        # adjusted_value = 15 + 10
        # previous_value = 25
        # RETURN 25

        # step 2:
        val2 = I.execute(70000)
        # value = 25 + 5
        # adjusted_value = 30 + 10
        # previous_value = 30
        # RETURN 40
        assert (val, val2) == (25, 40)
 def test_integrator_type_constant_rate_list(self):
     I = IntegratorMechanism(
         default_variable=[0, 0, 0],
         name='IntegratorMechanism',
         function=ConstantIntegrator(rate=[5.0, 5.0, 5.0]))
     # P = Process(pathway=[I])
     val = list(I.execute([10.0, 10.0, 10.0])[0])
     assert val == [5.0, 5.0, 5.0]
 def test_transfer_mech_integrator_fun(self):
     with pytest.raises(TransferError) as error_text:
         T = TransferMechanism(name='T',
                               default_variable=[0, 0, 0, 0],
                               function=ConstantIntegrator(),
                               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_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_type_constant_rate_list_input_float(self):
     with pytest.raises(ComponentError) as error_text:
         I = IntegratorMechanism(
             name='IntegratorMechanism',
             function=ConstantIntegrator(rate=[5.0, 5.0, 5.0]))
         # P = Process(pathway=[I])
         float(I.execute(10.0))
     assert ("is not compatible with the variable format" in str(error_text)
             and "to which it is being assigned" in str(error_text))
 def test_recurrent_mech_integrator_fun(self):
     with pytest.raises(TransferError) as error_text:
         R = RecurrentTransferMechanism(name='R',
                                        default_variable=[0, 0, 0, 0],
                                        function=ConstantIntegrator(),
                                        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_type_constant_rate_list_input_float(self):
     with pytest.raises(FunctionError) as error_text:
         I = IntegratorMechanism(
             name='IntegratorMechanism',
             function=ConstantIntegrator(rate=[5.0, 5.0, 5.0]))
         # P = Process(pathway=[I])
         float(I.execute(10.0))
     assert ("array specified for the rate parameter" in str(error_text)
             and "must match the length" in str(error_text)
             and "of the default input" in str(error_text))
 def test_integrator_type_constant_rate_float(self):
     I = IntegratorMechanism(
         name='IntegratorMechanism',
         function=ConstantIntegrator(
             rate=5.0
         )
     )
     # P = Process(pathway=[I])
     val = float(I.execute(10.0))
     assert val == 5.0
    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_constant_noise_fn_var_list(self):
        I = IntegratorMechanism(name='IntegratorMechanism',
                                default_variable=[0, 0, 0, 0],
                                function=ConstantIntegrator(
                                    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])
    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])
    def test_integrator_constant_with_reset_intializer(self):
        I = IntegratorMechanism(name='IntegratorMechanism',
                                function=ConstantIntegrator(rate=1.0),
                                time_scale=TimeScale.TIME_STEP)
        # val = float(I.execute(10)[0])
        # P = Process(pathway=[I])
        val = float(I.execute())
        # returns previous_value + rate + noise
        # rate = 1.0, noise = 0, so in this case returns 1.0

        # testing initializer
        I.function_object.reset_initializer = 10.0
        val2 = float(I.execute())

        assert [val, val2] == [1.0, 11.0]
    def test_Constant_valid(self):
        I = IntegratorMechanism(
            name='IntegratorMechanism',
            function=ConstantIntegrator(
                rate=1.0
            ),
        )

        #  returns previous_value + rate + noise
        # so in this case, returns 0.0 + 1.0
        I.execute(1000)
        assert np.allclose(I.value, 1.0)
        assert np.allclose(I.output_state.value, 1.0)

        # reinitialize function
        I.function_object.reinitialize(2.0)
        assert np.allclose(I.function_object.value, 2.0)
        assert np.allclose(I.value, 1.0)
        assert np.allclose(I.output_states[0].value, 1.0)

        # reinitialize function without value spec
        I.function_object.reinitialize()
        assert np.allclose(I.function_object.value, 0.0)
        assert np.allclose(I.value, 1.0)
        assert np.allclose(I.output_states[0].value, 1.0)

        # reinitialize mechanism
        I.reinitialize(2.0)
        assert np.allclose(I.function_object.value, 2.0)
        assert np.allclose(I.value, 2.0)
        assert np.allclose(I.output_states[0].value, 2.0)

        I.execute(1.0)
        #  2.0 + 1.0 = 3.0
        assert np.allclose(I.value, 3.0)
        assert np.allclose(I.output_states[0].value, 3.0)

        # reinitialize mechanism without value spec
        I.reinitialize()
        assert np.allclose(I.function_object.value, 0.0)
        assert np.allclose(I.value, 0.0)
        assert np.allclose(I.output_states[0].value, 0.0)