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_noise_function(self): np.random.seed(22) A = AccumulatorIntegrator(rate = 1.0, noise=NormalDist(standard_deviation=0.1)) A() A() A() val = A() assert np.allclose([[-0.06509346]], val)
def test_buffer_standalone_noise_function(self): np.random.seed(22) B = Buffer(history=3, rate = 1.0, noise=NormalDist(standard_deviation=0.1)) B.execute([1,2,3]) B.execute([4,5,6]) B.execute([7,8,9]) val = B.execute([10,11,12]) assert np.allclose(deque(np.atleast_1d([[ 3.8925223, 5.03957263, 6.00262384], [ 7.00288551, 7.97692328, 9.05877522], [10, 11, 12]])), 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.2480800486427607, 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_DDM_input_fn(): with pytest.raises(TypeError) as error_text: stim = NormalDist() T = DDM( name='DDM', function=DriftDiffusionIntegrator(noise=0.0, rate=1.0, time_step_size=1.0), ) float(T.execute(stim)) assert "not supported for the input types" in str(error_text.value)
def test_buffer_standalone_noise_function(self, benchmark): B = Buffer(history=3, rate = 1.0, noise=NormalDist(standard_deviation=0.1)) B.execute([1, 2, 3]) B.execute([4, 5, 6]) B.execute([7, 8, 9]) val = B.execute([10,11,12]) assert np.allclose(deque(np.atleast_1d([[4.02430687, 4.91927251, 5.95087965], [7.09586966, 7.91823773, 8.86077491], [10, 11, 12]])), val) if benchmark.enabled: benchmark(B.execute, [1, 2, 3])
def test_buffer_standalone_noise_function_in_array(self): B = Buffer(history=3, noise=[10, NormalDist(standard_deviation=0.1), 20]) np.random.seed(22) B.execute([1,2,3]) B.execute([4,5,6]) B.execute([7,8,9]) val = B.execute([10,11,12]) expected_val = [[24, 5.0800314416734444, 46], [17, 8.040015720836722, 29], [10, 11, 12]] 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_recurrent_mech_normal_fun(self): with pytest.raises(TransferError) as error_text: R = RecurrentTransferMechanism( name='R', default_variable=[0, 0, 0, 0], function=NormalDist(), integration_rate=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_accumulator_standalone_noise_function_in_array(self): A = AccumulatorIntegrator(noise=[10, NormalDist(standard_deviation=0.1), 20]) np.random.seed(22) A() A() A() val = A() expected_val = [[40.0, 0.16006288334688934, 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_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), ) float(T.execute(stim)[0]) assert "incompatible value" in str(error_text.value)
def test_DDM_noise_fn(): with pytest.raises(FunctionError) as error_text: stim = 10 T = DDM( name='DDM', function=DriftDiffusionIntegrator(noise=NormalDist(), rate=1.0, time_step_size=1.0), ) float(T.execute(stim)[0]) assert "DriftDiffusionIntegrator requires noise parameter to be a float" in str( error_text.value)
def test_buffer_standalone_noise_function_in_array(self, benchmark): B = Buffer(history=3) # Set noise parameter ouside of a constructor to avoid problems # with extra copying B.parameters.noise.set([10, NormalDist(standard_deviation=0.1), 20]) B.execute([1, 2, 3]) B.execute([4, 5, 6]) B.execute([7, 8, 9]) val = B.execute([10, 11, 12]) expected_val = [[24, 4.693117564500052, 46], [17, 7.744647273059847, 29], [10, 11, 12]] for v_v, v_e in zip(val, expected_val): for v, e in zip(v_v, v_e): assert np.allclose(v, e) if benchmark.enabled: benchmark(B.execute, [1, 2, 3])
assert np.allclose(val[0][0][0], 8.194383551861414) benchmark(ex, [10]) # ------------------------------------------------------------------------------------------------ # INVALID NOISE: # ------------------------------------------------------------------------------------------------ @pytest.mark.ddm_mechanism @pytest.mark.mechanism @pytest.mark.benchmark(group="DDM") @pytest.mark.parametrize("noise", [ 2, NormalDist(), ], ids=["int", "functions"]) def test_DDM_noise_invalid(noise): with pytest.raises(FunctionError) as error_text: stim = 10 T = DDM( name='DDM', function=DriftDiffusionIntegrator(noise=noise, rate=1.0, time_step_size=1.0), ) float(T.execute(stim)[0]) assert "DriftDiffusionIntegrator requires noise parameter to be a float" in str( error_text.value)
def target_function(): val_1 = NormalDist(mean=3.0)() val_2 = NormalDist(mean=3.0)() target_value = np.array([val_1, val_2]) return target_value
def target_function(): val_1 = NormalDist(mean=3.0)() val_2 = NormalDist(mean=3.0)() return [val_1, val_2]
def target_function(): val_1 = NormalDist(mean=3.0)() return val_1