def test_accumulator_standalone_rate_list_incement_float(self):
     A = AccumulatorIntegrator(rate=[2.0, 2.5, -3.0], increment=-1.4)
     A()
     A()
     A()
     val = A()
     assert np.allclose([[-21., -35.525, 28.]], val)
 def test_accumulator_standalone_rate_float_incement_float(self):
     A = AccumulatorIntegrator(rate=2.0, increment=3.0)
     A()
     A()
     A()
     val = A()
     assert np.allclose([[45]], val)
 def test_accumulator_standalone_rate_float_incement_list(self):
     A = AccumulatorIntegrator(rate=2.0, increment=[3.5, 4.0, 5.0])
     A()
     A()
     A()
     val = A()
     assert np.allclose([[52.5, 60., 75.]], val)
 def test_accumulator_standalone_increment_float(self):
     A = AccumulatorIntegrator(increment=0.1)
     A()
     A()
     A()
     val = A()
     assert np.allclose([[0.4]], val)
 def test_accumulator_standalone_increment_ndarray(self):
     A = AccumulatorIntegrator(increment=np.array([0.1, 0.5, 0.9]))
     A()
     A()
     A()
     val = A()
     assert np.allclose([[0.4, 2., 3.6]], val)
 def test_accumulator_standalone_rate_float(self):
     A = AccumulatorIntegrator(rate=0.1, increment=1)
     A()
     A()
     A()
     val = A()
     assert np.allclose([[1.111]], val)
 def test_accumulator_standalone_rate_ndarray(self):
     A = AccumulatorIntegrator(rate=[0.1, 0.5, 0.9], increment=1)
     A()
     A()
     A()
     val = A()
     assert np.allclose([[1.111, 1.875, 3.439]], val)
 def test_accumulator_standalone_noise_ndarray(self):
     A = AccumulatorIntegrator(rate=1.0, noise=[10.0, 20.0, 30.0])
     A()
     A()
     A()
     val = A()
     assert np.allclose([[40., 80., 120.]], val)
 def test_accumulator_initializer_len_3(self):
     A = AccumulatorIntegrator(default_variable=[[0.0], [1.0], [2.0]],
                               initializer=[[0.0], [1.0], [2.0]],
                               increment=1)
     assert np.allclose(A(), [[1], [2], [3]])
     assert np.allclose(A(), [[2], [3], [4]])
     assert np.allclose(A(), [[3], [4], [5]])
 def test_accumulator_standalone_noise_float(self):
     A = AccumulatorIntegrator(rate=1.0, noise=10.0)
     A()
     A()
     A()
     val = A()
     assert np.allclose([[40]], val)
Esempio n. 11
0
    def _instantiate_parameter_ports(self, function=None, context=None):

        super()._instantiate_parameter_ports(function=function,
                                             context=context)

        # FIX: UPDATE FOR LEARNING
        # FIX: UPDATE WITH MODULATION_MODS
        # FIX: MOVE THIS TO MappingProjection.__init__;
        # FIX: AS IT IS, OVER-WRITES USER ASSIGNMENT OF FUNCTION IN params dict FOR MappingProjection
        # TODO: why is this using the value not the variable? if there isn't a
        # specific reason, it should be variable, but this affects the values
        # tests/mechanisms/test_gating_mechanism.py::test_gating_with_composition
        new_variable = copy.deepcopy(
            self._parameter_ports[MATRIX].defaults.value)
        initial_rate = new_variable * 0.0

        # KDM 7/11/19: instead of simply setting the function, we need to reinstantiate to ensure
        # new defaults get set properly
        self._parameter_ports[MATRIX]._instantiate_function(
            function=AccumulatorIntegrator(
                owner=self._parameter_ports[MATRIX],
                default_variable=new_variable,
                initializer=new_variable,
                # rate=initial_rate
            ),
            context=context)
        self._parameter_ports[MATRIX]._instantiate_value(context)
        self._parameter_ports[MATRIX]._update_parameter_components(context)
    def test_accumulator_as_function_of_processing_mech(self):

        P = ProcessingMechanism(function=AccumulatorIntegrator(
            initializer=[0.0], rate=.02, increment=1))
        P.execute(1.0)
        P.execute(1.0)
        val = P.execute(1.0)
        assert np.allclose(val, [[1.0204]])
 def test_accumulator_standalone_noise_function(self):
     A = AccumulatorIntegrator(rate=1.0,
                               noise=NormalDist(standard_deviation=0.1))
     A()
     A()
     A()
     val = A()
     assert np.allclose([[-0.34591555]], val)
 def test_accumulator_standalone_rate_list_incement_list(self):
     A = AccumulatorIntegrator(rate=[-.5, 2.0, -3.5],
                               increment=[-1.0, .5, -2.0])
     A()
     A()
     A()
     val = A()
     assert np.allclose([[-0.625, 7.5, 66.25]], val)
 def test_accumulator_standalone_noise_function_in_array(self):
     A = AccumulatorIntegrator(
         noise=[10, NormalDist(standard_deviation=0.1), 20])
     A()
     A()
     A()
     val = A()
     expected_val = [[40.0, -0.43300219, 80.0]]
     for i in range(len(val)):
         for j in range(len(val[i])):
             assert np.allclose(expected_val[i][j], val[i][j])
 def test_accumulator_standalone(self):
     A = AccumulatorIntegrator()
     val = A()
     assert np.allclose([[0]], val)