def test_DDM_Integrator(): stim = 10 T = DDM(name='DDM', function=DriftDiffusionIntegrator(initializer=20.0), time_scale=TimeScale.TIME_STEP) val = float(T.execute(stim)[0]) T.function_object.initializer = 30.0 val2 = float(T.execute(stim)[0])
def test_DDM_noise_2_0(): stim = 10 T = DDM(name='DDM', function=DriftDiffusionIntegrator(noise=2.0, rate=1.0, time_step_size=1.0)) val = float(T.execute(stim)[0]) assert val == 12.641125838188323
def test_DDM_time(): D = DDM(name='DDM', function=DriftDiffusionIntegrator(noise=0.0, rate=-5.0, time_step_size=0.2, t0=0.5)) time_0 = D.function_object.previous_time # t_0 = 0.5 np.testing.assert_allclose(time_0, [0.5], atol=1e-08) time_1 = D.execute(10)[1][0] # t_1 = 0.5 + 0.2 = 0.7 np.testing.assert_allclose(time_1, [0.7], atol=1e-08) for i in range(10): # t_11 = 0.7 + 10*0.2 = 2.7 D.execute(10) time_12 = D.execute(10)[1][0] # t_12 = 2.7 + 0.2 = 2.9 np.testing.assert_allclose(time_12, [2.9], atol=1e-08)
def test_DDM_size_int_inputs_(): T = DDM(name='DDM', size=1.0, function=DriftDiffusionIntegrator(noise=0.0, rate=-5.0, time_step_size=1.0), time_scale=TimeScale.TIME_STEP) val = T.execute([.4]).tolist() assert val == [[-2.0], [1.0]]
def test_DDM_zero_noise(): stim = 10 T = DDM(name='DDM', function=DriftDiffusionIntegrator(noise=0.0, rate=1.0, time_step_size=1.0), time_scale=TimeScale.TIME_STEP) val = float(T.execute(stim)[0]) assert val == 10
def test_DDM_noise_0_5(): stim = 10 T = DDM(name='DDM', function=DriftDiffusionIntegrator(noise=0.5, rate=1.0, time_step_size=1.0)) val = float(T.execute(stim)[0]) assert val == 11.320562919094161
def test_DDM_input_list_len_1(): stim = [10] T = DDM( name='DDM', function=DriftDiffusionIntegrator(noise=0.0, rate=1.0, time_step_size=1.0), ) val = float(T.execute(stim)[0]) assert val == 10
def test_DDM_rate_float(): stim = 10 T = DDM( name='DDM', function=DriftDiffusionIntegrator(noise=0.0, rate=5, time_step_size=1.0), ) val = float(T.execute(stim)[0]) assert val == 50
def test_DDM_input_rate_negative(): stim = [10] T = DDM(name='DDM', default_variable=[0], function=DriftDiffusionIntegrator(noise=0.0, rate=-5.0, time_step_size=1.0), time_scale=TimeScale.TIME_STEP) val = float(T.execute(stim)[0]) assert val == -50
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_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_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)
def test_DDM_input_list_len_2(): with pytest.raises(DDMError) as error_text: stim = [10, 10] T = DDM(name='DDM', default_variable=[0, 0], function=DriftDiffusionIntegrator(noise=0.0, rate=1.0, time_step_size=1.0), time_scale=TimeScale.TIME_STEP) float(T.execute(stim)[0]) assert "must have only a single numeric item" in str(error_text.value)
def test_DDM_noise_int(): with pytest.raises(FunctionError) as error_text: stim = 10 T = DDM( name='DDM', function=DriftDiffusionIntegrator(noise=2, 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_DDM_size_int_inputs(): T = DDM( name='DDM', size=1, function=DriftDiffusionIntegrator(noise=0.0, rate=-5.0, time_step_size=1.0), ) val = T.execute([.4]) decision_variable = val[0][0] time = val[1][0] assert decision_variable == -2.0 assert time == 1.0
def test_threshold_stops_accumulation(self): D = DDM(name='DDM', function=DriftDiffusionIntegrator(threshold=5.0)) decision_variables = [] time_points = [] for i in range(5): output = D.execute(2.0) decision_variables.append(output[0][0][0]) time_points.append(output[1][0][0]) # decision variable accumulation stops assert np.allclose(decision_variables, [2.0, 4.0, 5.0, 5.0, 5.0]) # time accumulation does not stop assert np.allclose(time_points, [1.0, 2.0, 3.0, 4.0, 5.0])
def test_threshold_sets_is_finished(self): D = DDM(name='DDM', function=DriftDiffusionIntegrator(threshold=5.0)) D.execute(2.0) # 2.0 < 5.0 assert not D.is_finished D.execute(2.0) # 4.0 < 5.0 assert not D.is_finished D.execute(2.0) # 5.0 = threshold assert D.is_finished
def test_DDM_Integrator_Bogacz(): stim = 10 T = DDM(name='DDM', function=BogaczEtAl()) val = float(T.execute(stim)[0]) assert val == 1.0
def test_valid(self): D = DDM( name='DDM', function=DriftDiffusionIntegrator(), ) # returns previous_value + rate * variable * time_step_size + noise # 0.0 + 1.0 * 1.0 * 1.0 + 0.0 D.execute(1.0) assert np.allclose(D.value, [[1.0], [1.0]]) assert np.allclose(D.output_states[0].value, 1.0) assert np.allclose(D.output_states[1].value, 1.0) # reinitialize function D.function_object.reinitialize(2.0, 0.1) assert np.allclose(D.function_object.value, 2.0) assert np.allclose(D.function_object.previous_value, 2.0) assert np.allclose(D.function_object.previous_time, 0.1) assert np.allclose(D.value, [[1.0], [1.0]]) assert np.allclose(D.output_states[0].value, 1.0) assert np.allclose(D.output_states[1].value, 1.0) # reinitialize function without value spec D.function_object.reinitialize() assert np.allclose(D.function_object.value, 0.0) assert np.allclose(D.function_object.previous_value, 0.0) assert np.allclose(D.function_object.previous_time, 0.0) assert np.allclose(D.value, [[1.0], [1.0]]) assert np.allclose(D.output_states[0].value, 1.0) assert np.allclose(D.output_states[1].value, 1.0) # reinitialize mechanism D.reinitialize(2.0, 0.1) assert np.allclose(D.function_object.value, 2.0) assert np.allclose(D.function_object.previous_value, 2.0) assert np.allclose(D.function_object.previous_time, 0.1) assert np.allclose(D.value, [[2.0], [0.1]]) assert np.allclose(D.output_states[0].value, 2.0) assert np.allclose(D.output_states[1].value, 0.1) D.execute(1.0) # 2.0 + 1.0 = 3.0 ; 0.1 + 1.0 = 1.1 assert np.allclose(D.value, [[[3.0]], [[1.1]]]) assert np.allclose(D.output_states[0].value, 3.0) assert np.allclose(D.output_states[1].value, 1.1) # reinitialize mechanism without value spec D.reinitialize() assert np.allclose(D.function_object.value, 0.0) assert np.allclose(D.function_object.previous_value, 0.0) assert np.allclose(D.function_object.previous_time, 0.0) assert np.allclose(D.output_states[0].value[0], 0.0) assert np.allclose(D.output_states[1].value[0], 0.0) # reinitialize only decision variable D.reinitialize(1.0) assert np.allclose(D.function_object.value, 1.0) assert np.allclose(D.function_object.previous_value, 1.0) assert np.allclose(D.function_object.previous_time, 0.0) assert np.allclose(D.output_states[0].value[0], 1.0) assert np.allclose(D.output_states[1].value[0], 0.0)
def test_selected_input_array(self): action_selection = DDM(input_format=ARRAY, function=BogaczEtAl(), output_states=[SELECTED_INPUT_ARRAY], name='DDM') action_selection.execute([1.0])