def q2_full_full(): duration = 60 dt = 0.1 current_list1 = current_generator(duration, dt, [(7, 8), (1, 2)]) current_list2 = current_generator(duration, dt, [(1, 2), (7, 8)]) current_list3 = current_generator(duration, dt, [(1, 2), (1, 2)]) neuron_params_exc1 = { 'r': 5, 'tau': 8, 'threshold': -60, 'current': current_list1 } neuron_params_exc2 = { 'r': 5, 'tau': 8, 'threshold': -60, 'current': current_list2 } neuron_params_inh = { 'r': 8, 'tau': 5, 'threshold': -62, 'is_inh': True, 'current': current_list3 } pop1 = Population(400, LIF, exc_ratio=1, **neuron_params_exc1) pop2 = Population(200, LIF, exc_ratio=0, **neuron_params_inh) pop3 = Population(400, LIF, exc_ratio=1, **neuron_params_exc2) conn1 = Connection(pop1, pop1).apply("full", mu=0.2, sigma=0.1) conn2 = Connection(pop2, pop2).apply("full", mu=0.2, sigma=0.1) conn3 = Connection(pop3, pop3).apply("full", mu=0.2, sigma=0.1) conn4 = Connection(pop1, pop2).apply("full", mu=0.2, sigma=0.1) conn5 = Connection(pop2, pop3).apply("full", mu=0.2, sigma=0.1) conn6 = Connection(pop2, pop1).apply("full", mu=0.2, sigma=0.1) conn7 = Connection(pop3, pop2).apply("full", mu=0.2, sigma=0.1) # conn8 = Connection(pop2, pop1).apply("full", mu=0.2, sigma=0.1) # conn9 = Connection(pop3, pop2).apply("full", mu=0.2, sigma=0.1) conn8 = Connection(pop3, pop1).apply("fixed_prob", p=0.001, mu=0.2, sigma=0.1) conn9 = Connection(pop1, pop3).apply("fixed_prob", p=0.001, mu=0.2, sigma=0.1) sim = Network(populations=[pop1, pop2, pop3], connections=[ conn1, conn2, conn3, conn4, conn5, conn6, conn7, conn8, conn9 ], time_step=dt) sim.run(duration) print(pop1.spikes_per_neuron.shape) print(pop2.spikes_per_neuron.shape) print(pop3.spikes_per_neuron.shape) spikes = aggregate_population_spikes([pop1, pop2, pop3]) print(spikes.shape) decision_plot(pop1.activity, pop3.activity)
def random_current_test(Neuron, current_range, time_window, dt, **neuron_params): plot_name = f"./tests/phase1/{neuron_params}_{time_window}_randomCurrent.png" lif = Neuron(current=current_generator(time_window, dt, current_range), **neuron_params) simulate = Network(lif, dt) current_list, time_list = simulate.run(time_window) plot_firing_pattern(lif.potential_list, current_list, time_list, lif.u_rest, lif.threshold, save_to=plot_name)
def q1_full(): duration = 20 dt = 0.1 neuron_params = { 'r': 5, 'tau': 8, 'threshold': -60, 'current': current_generator(duration, dt, [(4, 5), (4, 5)]) } pop = Population(1000, LIF, exc_ratio=0.8, **neuron_params) conn = Connection(pop, pop).apply("full", mu=0.2, sigma=0.1) sim = Network(populations=[pop], connections=[conn], time_step=dt) sim.run(duration) print(pop.spikes_per_neuron.shape) colors = [ 'inh' if pop.neurons[int(p[0])].is_inh else 'exc' for p in pop.spikes_per_neuron ] raster_plot(pop.spikes_per_neuron, colors=colors)
def constant_current_test(Neuron, current_values, time_window, dt, **neuron_params): firing_patterns = [] f_i_curve_name = f"./tests/phase1/gain_function_{neuron_params}.png" for current_value in current_values: plot_name = f"./tests/phase1/{neuron_params}_{time_window}_{current_value}.png" lif = Neuron(current=current_generator(time_window, dt, current_value), **neuron_params) simulate = Network(lif, dt) current_list, time_list = simulate.run(time_window) firing_patterns.append(lif.spike_times) plot_firing_pattern(lif.potential_list, current_list, time_list, lif.u_rest, lif.threshold, save_to=plot_name) plot_f_i_curve(firing_patterns, time_window, current_values, save_to=f_i_curve_name)
def main(duration, dt, src_size, dest_size, interval, initial_dopamine, func_da, input_pattern, n_params, s_params, trace_alpha=0.1, regularize=None, plot_change=False): src = InputPopulation(src_size, LIF, **n_params) src.encode(input_pattern, duration, interval) n_params["current"] = list(np.zeros(duration // dt)) n_params["regularize"] = regularize dest = Population(dest_size, LIF, trace_alpha=trace_alpha, **n_params) conn = Connection(src, dest).apply(**s_params) net = Network(populations=[src, dest], connections=[conn], time_step=dt) net.set_dopamine(initial_dopamine, func_da) net.run(duration, learning_rule="rstdp") # raster_plot(src.spikes_per_neuron) # raster_plot(dest.spikes_per_neuron) print(conn.weight_in_time[-1]) plot_weight_matrix(conn.weight_in_time[-1]) if plot_change: plot_weight_change(conn.weight_in_time)
def main(trial_no, duration, dt, population_size, n, input_size, output_size, interval, initial_dopamine, func_da, neuron_params, rstdp_params, output_current=None): inp = InputPopulation(input_size, LIF, **neuron_params) input_pattern = [] for i in range(n): input_pattern.append(np.random.randint(0, 5, input_size)) inp.encode(input_pattern, duration, interval, dt) if output_current is not None: neuron_params["current"] = output_current * np.ones(duration // dt) outs = [] # neuron_params["regularize"] = True for i in range(n): outs.append( Population(output_size, LIF, trace_alpha=0, **neuron_params)) pop = Population(population_size, LIF, input_part=inp, output_part=outs, exc_ratio=0.8, trace_alpha=0, **neuron_params) conn = Connection(pop, pop, weight_change=False).apply(**rstdp_params) net = Network(populations=[pop], connections=[conn], time_step=dt) net.set_dopamine(initial_dopamine, func_da) net.run(duration, learning_rule="rstdp") inp.compute_spike_history() raster_plot(np.array(inp.spikes_per_neuron)) activity_plot([out.activity for out in outs], save_to="./q2trial{}.png".format(trial_no))
output_pop.add(1, LIF, **inh_params) conn.add(list(range(input_pop.size)), [-1], mu=1.25, sigma=0.1, delay=0, **stdp_params) conn.add([-1], [0, 1], mu=0.8, sigma=0.1, delay=0, **stdp_params) weight_matrix = np.zeros((input_pop.size, output_pop.size)) for syn in conn.synapses: weight_matrix[input_pop.neurons.index(syn.pre), output_pop.neurons.index(syn.post)] = syn.w print(weight_matrix) sim = Network(populations=[input_pop, output_pop], connections=[conn], time_step=dt) sim.run(duration, learning_rule="stdp") for syn in conn.synapses: weight_matrix[input_pop.neurons.index(syn.pre), output_pop.neurons.index(syn.post)] = syn.w # print(syn.pre.name, "--{}-->".format(syn.w), syn.post.name) print(weight_matrix) # for neuron in input_pop.neurons: # print(neuron.current_list) # # for i in range(0, 10): # print(