def main(): train, spikes = get_spike_train() # print("Stimulus:", spikes) ws0 = np.random.normal(loc=w0, scale=sigma0, size=(N)) ws1 = np.random.normal(loc=w1, scale=sigma1, size=(N)) current0 = get_cumulative_current(spikes, ws0) current1 = get_cumulative_current(spikes, ws1) model = Model.RS initU, initV = initalize_U_V(model, M, True) _, V0, _x0 = get_U_V(initU, initV, model, current0) _, V1, _x1 = get_U_V(initU, initV, model, current1) print("Spikes: %d, w_mean: %f, w_std: %f" % (len(_x0), w0, sigma0)) print("Spikes: %d, w_mean: %f, w_std: %f" % (len(_x1), w1, sigma1)) plot_curr_and_resp( current0, V0, "Q2.a.png" ) plot_curr_and_resp( current1, V1, "Q2.b.png" )
def main(): _, spikes1 = get_spike_train() _, spikes2 = get_spike_train() # print("S1:", spikes1) # print("S2:", spikes2) ws0 = np.random.normal(loc=w0, scale=sigma0, size=(N)) model = Model.RS initU, initV = initalize_U_V(model, M, True) print("Q5.a") currenti1 = get_cumulative_current(spikes1, ws0) _, V1, aspikes1 = get_U_V(initU, initV, model, currenti1) currenti2 = get_cumulative_current(spikes2, ws0) _, V2, aspikes2 = get_U_V(initU, initV, model, currenti2) plot_curr_and_resp(currenti1, V1, "Q5.a.1.png") plot_curr_and_resp(currenti2, V2, "Q5.a.2.png") print("Q5.b") print("Removing spikes for S2") wsn = ws0 while len(aspikes2) != 0: wsn, _, _ = train_d_synapses(wsn, spikes=spikes2, effect=aspikes2) currenti2 = get_cumulative_current(spikes2, wsn) _, V2, aspikes2 = get_U_V(initU, initV, model, currenti2) plot_curr_and_resp(currenti2, V2, "Q5.b.2.png") print("Q5.c") print("Causing spikes for S1 and removing spikes for S2") # main learning loop wsn = ws0 currenti1 = get_cumulative_current(spikes1, wsn) _, V1, aspikes1 = get_U_V(initU, initV, model, currenti1) currenti2 = get_cumulative_current(spikes2, wsn) _, V2, aspikes2 = get_U_V(initU, initV, model, currenti2) while len(aspikes1) == 0 or len(aspikes2) != 0: currenti1 = get_cumulative_current(spikes1, wsn) _, _, aspikes1 = get_U_V(initU, initV, model, currenti1) while len(aspikes1) == 0: wsn, _, _ = train_synapses(wsn, spikes=spikes1, effect=aspikes1) currenti1 = get_cumulative_current(spikes1, wsn) _, _, aspikes1 = get_U_V(initU, initV, model, currenti1) print("Causing spikes for S1") currenti2 = get_cumulative_current(spikes2, wsn) _, _, aspikes2 = get_U_V(initU, initV, model, currenti2) while len(aspikes2) != 0: wsn, _, _ = train_d_synapses(wsn, spikes=spikes2, effect=aspikes2) currenti2 = get_cumulative_current(spikes2, wsn) _, _, aspikes2 = get_U_V(initU, initV, model, currenti2) print("Removed spikes for S2") currenti1 = get_cumulative_current(spikes1, wsn) _, V1, aspikes1 = get_U_V(initU, initV, model, currenti1) currenti2 = get_cumulative_current(spikes2, wsn) _, V2, aspikes2 = get_U_V(initU, initV, model, currenti2) plot_curr_and_resp(currenti1, V1, "Q5.c.1.png") plot_curr_and_resp(currenti2, V2, "Q5.c.2.png") print("Q5.d") print("Removing spikes for S1 and causing spikes for S2") # main learning loop wsn = ws0 currenti1 = get_cumulative_current(spikes1, wsn) _, V1, aspikes1 = get_U_V(initU, initV, model, currenti1) currenti2 = get_cumulative_current(spikes2, wsn) _, V2, aspikes2 = get_U_V(initU, initV, model, currenti2) while len(aspikes1) != 0 or len(aspikes2) == 0: currenti1 = get_cumulative_current(spikes1, wsn) _, _, aspikes1 = get_U_V(initU, initV, model, currenti1) while len(aspikes1) != 0: wsn, _, _ = train_d_synapses(wsn, spikes=spikes1, effect=aspikes1) currenti1 = get_cumulative_current(spikes1, wsn) _, _, aspikes1 = get_U_V(initU, initV, model, currenti1) print("Removed spikes for S1") currenti2 = get_cumulative_current(spikes2, wsn) _, _, aspikes2 = get_U_V(initU, initV, model, currenti2) while len(aspikes2) == 0: wsn, _, _ = train_synapses(wsn, spikes=spikes2, effect=aspikes2) currenti2 = get_cumulative_current(spikes2, wsn) _, _, aspikes2 = get_U_V(initU, initV, model, currenti2) print("Caused spikes for S2") currenti1 = get_cumulative_current(spikes1, wsn) _, V1, aspikes1 = get_U_V(initU, initV, model, currenti1) currenti2 = get_cumulative_current(spikes2, wsn) _, V2, aspikes2 = get_U_V(initU, initV, model, currenti2) plot_curr_and_resp(currenti1, V1, "Q5.d.1.png") plot_curr_and_resp(currenti2, V2, "Q5.d.2.png")