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))