def test_AGTUtility_valid(self): I = IntegratorMechanism(name="I", function=AGTUtilityIntegrator()) I.reinitialize_when = Never() assert np.allclose([[0.0]], I.function_object.previous_short_term_utility) assert np.allclose([[0.0]], I.function_object.previous_long_term_utility) I.function_object.reinitialize(0.2, 0.8) assert np.allclose([[0.2]], I.function_object.previous_short_term_utility) assert np.allclose([[0.8]], I.function_object.previous_long_term_utility) I.function_object.reinitialize() assert np.allclose([[0.0]], I.function_object.previous_short_term_utility) assert np.allclose([[0.0]], I.function_object.previous_long_term_utility) I.reinitialize(0.3, 0.7) assert np.allclose([[0.3]], I.function_object.previous_short_term_utility) assert np.allclose([[0.7]], I.function_object.previous_long_term_utility) print(I.value) print(I.function_object.combine_utilities(0.3, 0.7)) assert np.allclose(I.function_object.combine_utilities(0.3, 0.7), I.value) I.reinitialize() assert np.allclose([[0.0]], I.function_object.previous_short_term_utility) assert np.allclose([[0.0]], I.function_object.previous_long_term_utility) assert np.allclose(I.function_object.combine_utilities(0.0, 0.0), I.value)
def test_Simple_valid(self): I = IntegratorMechanism( name='IntegratorMechanism', function=SimpleIntegrator( ), ) I.reinitialize_when = Never() # returns previous_value + rate*variable + noise # so in this case, returns 10.0 I.execute(10) assert np.allclose(I.value, 10.0) assert np.allclose(I.output_state.value, 10.0) # reinitialize function I.function_object.reinitialize(5.0) assert np.allclose(I.function_object.value, 5.0) assert np.allclose(I.value, 10.0) assert np.allclose(I.output_states[0].value, 10.0) # reinitialize function without value spec I.function_object.reinitialize() assert np.allclose(I.function_object.value, 0.0) assert np.allclose(I.value, 10.0) assert np.allclose(I.output_states[0].value, 10.0) # reinitialize mechanism I.reinitialize(4.0) assert np.allclose(I.function_object.value, 4.0) assert np.allclose(I.value, 4.0) assert np.allclose(I.output_states[0].value, 4.0) I.execute(1) assert np.allclose(I.value, 5.0) assert np.allclose(I.output_states[0].value, 5.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)
def test_reinitialize_when(self): I1 = IntegratorMechanism() I2 = IntegratorMechanism() I2.reinitialize_when = AtTrial(2) P1 = Process(pathway=[I1]) P2 = Process(pathway=[I2]) S = System(processes=[P1, P2], reinitialize_mechanisms_when=AtTrial(3)) S.run(inputs={I1: [[1.0]], I2: [[1.0]]}, num_trials=7) expected_results = [[np.array([0.5]), np.array([0.5])], [np.array([0.75]), np.array([0.75])], [np.array([0.875]), np.array([0.5])], # I2 reinitializes at Trial 2 [np.array([0.5]), np.array([0.75])], # I1 reinitializes at Trial 3 [np.array([0.75]), np.array([0.875])], [np.array([0.875]), np.array([0.9375])], [np.array([0.9375]), np.array([0.96875])]] assert np.allclose(expected_results, S.results)
def test_FHN_valid(self): I = IntegratorMechanism(name="I", function=FHNIntegrator()) I.reinitialize_when = Never() I.execute(1.0) assert np.allclose([[0.05127053]], I.value[0]) assert np.allclose([[0.00279552]], I.value[1]) assert np.allclose([[0.05]], I.value[2]) I.function_object.reinitialize(0.01, 0.02, 0.03) assert np.allclose(0.01, I.function_object.value[0]) assert np.allclose(0.02, I.function_object.value[1]) assert np.allclose(0.03, I.function_object.value[2]) assert np.allclose([[0.05127053]], I.value[0]) assert np.allclose([[0.00279552]], I.value[1]) assert np.allclose([[0.05]], I.value[2]) assert np.allclose([[0.05127053]], I.output_states[0].value) I.execute(1.0) assert np.allclose([[0.06075727]], I.value[0]) assert np.allclose([[0.02277156]], I.value[1]) assert np.allclose([[0.08]], I.value[2]) assert np.allclose([[0.06075727]], I.output_states[0].value) # I.reinitialize(new_previous_v=0.01, new_previous_w=0.02, new_previous_time=0.03) I.reinitialize(0.01, 0.02, 0.03) assert np.allclose(0.01, I.value[0]) assert np.allclose(0.02, I.value[1]) assert np.allclose(0.03, I.value[2]) assert np.allclose(0.01, I.output_states[0].value)