diff --git a/eprop_testing/create_pops_for_incremental_learning.py b/eprop_testing/create_pops_for_incremental_learning.py index 84f7a64..0dabfe0 100644 --- a/eprop_testing/create_pops_for_incremental_learning.py +++ b/eprop_testing/create_pops_for_incremental_learning.py @@ -1,7 +1,7 @@ -import spynnaker8 as pynn +import pyNN.spiNNaker as pynn from spynnaker.pyNN.spynnaker_external_device_plugin_manager import SpynnakerExternalDevicePluginManager -from eprop_testing.plot_graph import draw_graph_from_list, plot_learning_curve -from eprop_testing.incremental_config import * +from plot_graph import draw_graph_from_list, plot_learning_curve +from incremental_config import * def load_connections(npy_label, pop_size, rec=True): in_conn = [list(ele) for ele in np.load(npy_label+' in.npy').tolist()] @@ -66,6 +66,7 @@ def range_connector(pre_min, pre_max, post_min, post_max, weight=1.5, delay_offs def first_create_pops(): pynn.setup(timestep=1) + pynn.set_number_of_neurons_per_core(pynn.extra_models.EPropAdaptive, 6) input_pop = pynn.Population(input_size, pynn.SpikeSourcePoisson(rate=rates), label='input_pop') @@ -81,7 +82,13 @@ def first_create_pops(): label="readout_pop" ) - SpynnakerExternalDevicePluginManager.add_edge(readout_pop._get_vertex, input_pop._get_vertex, "CONTROL") + # SpynnakerExternalDevicePluginManager.add_edge(readout_pop._get_vertex, input_pop._get_vertex, "CONTROL") + poisson_control_edge = SpynnakerExternalDevicePluginManager.add_edge( + readout_pop._vertex, input_pop._vertex, "CONTROL") + # pynn.external_devices.activate_live_output_to( + # readout_pop, input_pop, "CONTROL") + input_pop._vertex.set_live_poisson_control_edge(poisson_control_edge) + # pynn.external_devices.add_poisson_live_rate_control(input_pop) eprop_learning_neuron = pynn.STDPMechanism( timing_dependence=pynn.extra_models.TimingDependenceEprop(), @@ -179,7 +186,13 @@ def next_create_pops(from_list_in, from_list_rec, from_list_out): label="readout_pop" ) - SpynnakerExternalDevicePluginManager.add_edge(readout_pop._get_vertex, input_pop._get_vertex, "CONTROL") + # SpynnakerExternalDevicePluginManager.add_edge(readout_pop._get_vertex, input_pop._get_vertex, "CONTROL") + poisson_control_edge = SpynnakerExternalDevicePluginManager.add_edge( + readout_pop._vertex, input_pop._vertex, "CONTROL") + # pynn.external_devices.activate_live_output_to( + # readout_pop, input_pop, "CONTROL") + input_pop._vertex.set_live_poisson_control_edge(poisson_control_edge) + # pynn.external_devices.add_poisson_live_rate_control(input_pop) eprop_learning_neuron = pynn.STDPMechanism( timing_dependence=pynn.extra_models.TimingDependenceEprop(), @@ -290,14 +303,16 @@ def run_until(experiment_label, runtime, pynn, in_proj, recurrent_proj, out_proj pynn.run(window_size) # in_spikes = input_pop.get_data('spikes', clear=True) # neuron_res = neuron.get_data('all', clear=True) - readout_res = readout_pop.get_data('all', clear=True) + readout_res = readout_pop.get_data('all') #, clear=True) for cycle in range(window_cycles): cycle_error.append(0.0) correct_or_not.append([]) for time_index in range(cycle_time): instantaneous_error = np.abs(float( - readout_res.segments[0].filter(name='gsyn_inh')[0][time_index + ((cycle+current_iter) * cycle_time)][0])) + readout_res.segments[0].filter( + name='gsyn_inh')[0][time_index + ( + (cycle+current_iter) * cycle_time)][0])) cycle_error[-1] += instantaneous_error if cycle_error[-1] < 75: correct_or_not[-1] = 1 diff --git a/eprop_testing/incremental_config.py b/eprop_testing/incremental_config.py index 14cd4f1..6546a8e 100644 --- a/eprop_testing/incremental_config.py +++ b/eprop_testing/incremental_config.py @@ -29,7 +29,7 @@ readout_neuron_params = { "v": 0, "v_thresh": 30, # controls firing rate of error neurons - "poisson_pop_size": input_size / 4, + "poisson_pop_size": input_size // 4, "rate_on": 100, "rate_off": 0, "w_fb": [1, -1, 0], @@ -39,7 +39,7 @@ } rates = [] for i in range(input_size): - if i >= (3 * input_size) / 4: + if i >= (3 * input_size) // 4: rates.append(10) else: rates.append(0) @@ -49,7 +49,7 @@ ratio_of_LIF = 0.5 beta = [] for i in range(neuron_pop_size): - if i < neuron_pop_size / 2: + if i < neuron_pop_size // 2: beta.append(threshold_beta) else: beta.append(threshold_beta) diff --git a/eprop_testing/incremental_graph_drawing.py b/eprop_testing/incremental_graph_drawing.py index a5ed563..60881a8 100644 --- a/eprop_testing/incremental_graph_drawing.py +++ b/eprop_testing/incremental_graph_drawing.py @@ -1,11 +1,11 @@ import spynnaker8 as pynn import numpy as np import matplotlib.pyplot as plt -from PyNN8Examples.eprop_testing.frozen_poisson import build_input_spike_train, frozen_poisson_variable_hz +from frozen_poisson import build_input_spike_train, frozen_poisson_variable_hz from pyNN.random import NumpyRNG, RandomDistribution from pyNN.utility.plotting import Figure, Panel from spynnaker.pyNN.spynnaker_external_device_plugin_manager import SpynnakerExternalDevicePluginManager -from PyNN8Examples.eprop_testing.plot_graph import draw_graph_from_list, plot_learning_curve +from plot_graph import draw_graph_from_list, plot_learning_curve def load_connections(npy_label, pop_size, rec=True): in_conn = [list(ele) for ele in np.load(npy_label+' in.npy').tolist()] @@ -72,7 +72,7 @@ def range_connector(pre_min, pre_max, post_min, post_max, weight=1.5, delay_offs number_of_cues = 1 cycle_time = (number_of_cues*150)+1000+150 num_repeats = 300 -pynn.setup(1.0) +# pynn.setup(1.0) # setup called twice? reg_rate = 0.000 p_connect_in = 1. @@ -94,12 +94,13 @@ def range_connector(pre_min, pre_max, post_min, post_max, weight=1.5, delay_offs weight_string = "i{}-p{}-r{}-o{}".format(in_weight, prompt_weight, rec_weight, out_weight) pynn.setup(timestep=1) +pynn.set_number_of_neurons_per_core(pynn.extra_models.EPropAdaptive, 6) input_size = 40 readout_neuron_params = { "v": 0, "v_thresh": 30, # controls firing rate of error neurons - "poisson_pop_size": input_size / 4, + "poisson_pop_size": input_size // 4, "rate_on": 100, "rate_off": 0, # "tau_m": tau_a, @@ -109,7 +110,7 @@ def range_connector(pre_min, pre_max, post_min, post_max, weight=1.5, delay_offs } rates = [] for i in range(input_size): - if i >= (3*input_size) / 4: + if i >= (3*input_size) // 4: rates.append(10) else: rates.append(0) @@ -125,7 +126,7 @@ def range_connector(pre_min, pre_max, post_min, post_max, weight=1.5, delay_offs ratio_of_LIF = 0.5 beta = [] for i in range(neuron_pop_size): - if i < neuron_pop_size/2: + if i < neuron_pop_size//2: # if i % 2 == 0: beta.append(threshold_beta) else: @@ -158,7 +159,12 @@ def range_connector(pre_min, pre_max, post_min, post_max, weight=1.5, delay_offs label="readout_pop" ) -SpynnakerExternalDevicePluginManager.add_edge(readout_pop._get_vertex, input_pop._get_vertex, "CONTROL") +poisson_control_edge = SpynnakerExternalDevicePluginManager.add_edge( + readout_pop._vertex, input_pop._vertex, "CONTROL") +# pynn.external_devices.activate_live_output_to( +# readout_pop, input_pop, "CONTROL") +input_pop._vertex.set_live_poisson_control_edge(poisson_control_edge) +# pynn.external_devices.add_poisson_live_rate_control(input_pop) eprop_learning_neuron = pynn.STDPMechanism( timing_dependence=pynn.extra_models.TimingDependenceEprop(), @@ -232,7 +238,9 @@ def range_connector(pre_min, pre_max, post_min, post_max, weight=1.5, delay_offs input_pop.record('spikes') neuron.record('spikes') -neuron.record(['gsyn_exc', 'v', 'gsyn_inh'], indexes=[i for i in range(int((neuron_pop_size/2)-5), int((neuron_pop_size/2)+5))]) +# neuron.record(['gsyn_exc', 'v', 'gsyn_inh'], indexes=[i for i in range(int((neuron_pop_size/2)-5), int((neuron_pop_size/2)+5))]) +neuron[[i for i in range(int((neuron_pop_size/2)-5), + int((neuron_pop_size/2)+5))]].record(['gsyn_exc', 'v', 'gsyn_inh']) readout_pop.record('all') runtime = cycle_time * num_repeats @@ -246,7 +254,7 @@ def range_connector(pre_min, pre_max, post_min, post_max, weight=1.5, delay_offs pynn.run(window_size) in_spikes = input_pop.get_data('spikes', clear=True) neuron_res = neuron.get_data('all', clear=True) - readout_res = readout_pop.get_data('all', clear=True) + readout_res = readout_pop.get_data('all') #, clear=True) plot_start = (window_size*current_window) current_window += 1 plot_end = (window_size*current_window) @@ -315,7 +323,9 @@ def range_connector(pre_min, pre_max, post_min, post_max, weight=1.5, delay_offs graph_directory = './graphs/' draw_graph_from_list(new_connections_in, new_connections_rec, new_connections_out, graph_directory, experiment_label+' {}'.format(current_window), rec_flag=recurrent_connections, save_flag=True) - plot_learning_curve([correct_or_not, cycle_error], graph_directory, experiment_label+' {}'.format(current_window), save_flag=True) + plot_learning_curve(correct_or_not, cycle_error, graph_directory, + experiment_label+' {}'.format(current_window), + save_flag=True) total_error = 0.0 diff --git a/eprop_testing/incremental_learning.py b/eprop_testing/incremental_learning.py index cd14c98..632dae8 100644 --- a/eprop_testing/incremental_learning.py +++ b/eprop_testing/incremental_learning.py @@ -1,7 +1,7 @@ import numpy as np -from eprop_testing.plot_graph import draw_graph_from_list, plot_learning_curve -from eprop_testing.create_pops_for_incremental_learning import first_create_pops, next_create_pops, run_until -from eprop_testing.incremental_config import * +from plot_graph import draw_graph_from_list, plot_learning_curve +from create_pops_for_incremental_learning import first_create_pops, next_create_pops, run_until +from incremental_config import * np.random.seed(272727) diff --git a/eprop_testing/input_buffer_overflow_test.py b/eprop_testing/input_buffer_overflow_test.py index bd2fa93..4374f5a 100644 --- a/eprop_testing/input_buffer_overflow_test.py +++ b/eprop_testing/input_buffer_overflow_test.py @@ -130,9 +130,12 @@ def range_connector(pre_min, pre_max, post_min, post_max, weight=1.5, delay_offs label="readout_pop" ) -# SpynnakerExternalDevicePluginManager.add_edge(readout_pop._get_vertex, input_pop._get_vertex, "CONTROL") -pynn.external_devices.activate_live_output_to( - readout_pop, input_pop, "CONTROL") +poisson_control_edge = SpynnakerExternalDevicePluginManager.add_edge( + readout_pop._vertex, input_pop._vertex, "CONTROL") +# pynn.external_devices.activate_live_output_to( +# readout_pop, input_pop, "CONTROL") +input_pop._vertex.set_live_poisson_control_edge(poisson_control_edge) +# pynn.external_devices.add_poisson_live_rate_control(input_pop) start_w = [weight_distribution(neuron_pop_size*input_size) for i in range(input_size)] eprop_learning_neuron = pynn.STDPMechanism( diff --git a/eprop_testing/readout_input_test.py b/eprop_testing/readout_input_test.py index c6deec0..1033df4 100644 --- a/eprop_testing/readout_input_test.py +++ b/eprop_testing/readout_input_test.py @@ -1,4 +1,4 @@ -import spynnaker8 as pynn +import pyNN.spiNNaker as pynn import numpy as np import matplotlib.pyplot as plt from frozen_poisson import build_input_spike_train, frozen_poisson_variable_hz diff --git a/eprop_testing/test_left_right_readout.py b/eprop_testing/test_left_right_readout.py index e396f22..d43813a 100644 --- a/eprop_testing/test_left_right_readout.py +++ b/eprop_testing/test_left_right_readout.py @@ -126,10 +126,12 @@ def probability_connector(pre_pop_size, post_pop_size, prob, offset=0, added_wei label="readout_pop" ) -# SpynnakerExternalDevicePluginManager.add_edge( -# readout_pop._vertex, input_pop._vertex, "CONTROL") -pynn.external_devices.activate_live_output_to( - readout_pop, input_pop, "CONTROL") +poisson_control_edge = SpynnakerExternalDevicePluginManager.add_edge( + readout_pop._vertex, input_pop._vertex, "CONTROL") +# pynn.external_devices.activate_live_output_to( +# readout_pop, input_pop, "CONTROL") +input_pop._vertex.set_live_poisson_control_edge(poisson_control_edge) +# pynn.external_devices.add_poisson_live_rate_control(input_pop) # start_w = [weight_distribution(neuron_pop_size*input_size) for i in range(input_size)] eprop_learning_neuron = pynn.STDPMechanism( @@ -207,8 +209,10 @@ def probability_connector(pre_pop_size, post_pop_size, prob, offset=0, added_wei runtime = cycle_time * num_repeats -experiment_label = "eta:{}/{} - size:{}/{} - reg_rate:{} - p_conn:{}/{}/{} - rec:{} - cycle:{}/{}/{} noresetv 0d b:{} in+{}".format( - readout_neuron_params["eta"], neuron_params["eta"], input_size, neuron_pop_size, reg_rate, p_connect_in, p_connect_rec, p_connect_out, recurrent_connections, cycle_time, window_size, runtime, eprop_beta, added_input_weight) +experiment_label = "eta:{}/{} - size:{}/{} - reg_rate:{} - p_conn:{}/{}/{} - rec:{} - cycle:{}/{}/{} noresetv 0d b:{}".format( + readout_neuron_params["eta"], neuron_params["eta"], input_size, neuron_pop_size, + reg_rate, p_connect_in, p_connect_rec, p_connect_out, recurrent_connections, + cycle_time, window_size, runtime, eprop_beta) print("\n", experiment_label, "\n") pynn.run(runtime)