def test_fitzHughNagumo_gilzenrat_figure_2(self): # Isolate the FitzHughNagumo mechanism for testing and recreate figure 2 from the gilzenrat paper initial_v = 0.2 initial_w = 0.0 F = IntegratorMechanism(name='IntegratorMech-FitzHughNagumoFunction', function=FitzHughNagumoIntegrator( initial_v=initial_v, initial_w=initial_w, time_step_size=0.01, time_constant_w=1.0, time_constant_v=0.01, a_v=-1.0, b_v=1.0, c_v=1.0, d_v=0.0, e_v=-1.0, f_v=1.0, threshold=0.5, mode=1.0, uncorrelated_activity=0.0, a_w=1.0, b_w=-1.0, c_w=0.0)) plot_v_list = [initial_v] plot_w_list = [initial_w] # found this stimulus by guess and check b/c one was not provided with Figure 2 params stimulus = 0.073 # increase range to 200 to match Figure 2 in Gilzenrat for i in range(10): results = F.execute(stimulus) plot_v_list.append(results[0][0][0]) plot_w_list.append(results[1][0][0]) # ** uncomment the lines below if you want to view the plot: # from matplotlib import pyplot as plt # plt.plot(plot_v_list) # plt.plot(plot_w_list) # plt.show() np.testing.assert_allclose(plot_v_list, [ 0.2, 0.22493312915681499, 0.24840327807265583, 0.27101619694032797, 0.29325863380332173, 0.31556552465130933, 0.33836727470568129, 0.36212868305470697, 0.38738542852040492, 0.41478016676749552, 0.44509530539552955 ]) print(plot_w_list) np.testing.assert_allclose(plot_w_list, [ 0.0, 0.0019900332500000003, 0.0042083541185625045, 0.0066381342093118408, 0.009268739886338381, 0.012094486544132229, 0.015114073825358726, 0.018330496914962583, 0.021751346023501487, 0.025389465931011893, 0.029263968140538919 ])
def test_reset_state_integrator_mechanism(self): A = IntegratorMechanism(name='A', function=DriftDiffusionIntegrator()) # Execute A twice # [0] saves decision variable only (not time) original_output = [A.execute(1.0)[0], A.execute(1.0)[0]] # SAVING STATE - - - - - - - - - - - - - - - - - - - - - - - - - reinitialize_values = [] for attr in A.function.stateful_attributes: reinitialize_values.append(getattr(A.function, attr)) # Execute A twice AFTER saving the state so that it continues accumulating. # We expect the next two outputs to repeat once we reset the state b/c we will return it to the current state output_after_saving_state = [A.execute(1.0)[0], A.execute(1.0)[0]] # RESETTING STATE - - - - - - - - - - - - - - - - - - - - - - - - A.reinitialize(*reinitialize_values) # We expect these results to match the results from immediately after saving the state output_after_reinitialization = [A.execute(1.0)[0], A.execute(1.0)[0]] assert np.allclose(output_after_saving_state, output_after_reinitialization) assert np.allclose( original_output, [np.array([[1.0]]), np.array([[2.0]])]) assert np.allclose( output_after_reinitialization, [np.array([[3.0]]), np.array([[4.0]])])