Skip to content

Commit

Permalink
Switch scripts to use pyNN.spiNNaker and minor tidying up
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgait committed May 25, 2023
1 parent e3aedfd commit 6055986
Show file tree
Hide file tree
Showing 17 changed files with 47 additions and 34 deletions.
20 changes: 15 additions & 5 deletions eprop_testing/create_pops_for_incremental_learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ 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)

print("Check rates: ", rates)

input_pop = pynn.Population(input_size,
pynn.SpikeSourcePoisson(rate=rates),
label='input_pop')
Expand Down Expand Up @@ -101,6 +104,9 @@ def first_create_pops():
weight=in_weight) # connect all 2 prompt
from_list_in += range_connector(ps * 2, ps * 4, 0, neuron_pop_size, delay_offset=0,
weight=prompt_weight) # connect all 2 prompt

print("length ", len(from_list_in))

in_proj = pynn.Projection(input_pop,
neuron,
pynn.FromListConnector(from_list_in),
Expand Down Expand Up @@ -303,7 +309,7 @@ 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)
Expand All @@ -312,7 +318,8 @@ def run_until(experiment_label, runtime, pynn, in_proj, recurrent_proj, out_proj
instantaneous_error = np.abs(float(
readout_res.segments[0].filter(
name='gsyn_inh')[0][time_index + (
(cycle+current_iter) * cycle_time)][0]))
cycle * cycle_time)][0]))
# (cycle+current_iter) * cycle_time)][0]))
cycle_error[-1] += instantaneous_error
if cycle_error[-1] < 75:
correct_or_not[-1] = 1
Expand Down Expand Up @@ -375,9 +382,12 @@ def run_until(experiment_label, runtime, pynn, in_proj, recurrent_proj, out_proj
print(experiment_label)

graph_directory = './big_with_labels/'
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)
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,
Expand Down
2 changes: 1 addition & 1 deletion eprop_testing/delta_synapse_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import spynnaker8 as pynn
import pyNN.spiNNaker as pynn
import numpy as np
import matplotlib.pyplot as plt
from pyNN.random import NumpyRNG, RandomDistribution
Expand Down
2 changes: 1 addition & 1 deletion eprop_testing/hand_crafted_left_right.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 7 additions & 4 deletions eprop_testing/incremental_graph_drawing.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -139,7 +139,9 @@ def range_connector(pre_min, pre_max, post_min, post_max, weight=1.5, delay_offs
# "w_fb": [(np.random.random() * 2) - 1. for i in range(neuron_pop_size)],
# "w_fb": [4*np.random.random() - 4*np.random.random() for i in range(neuron_pop_size)], ## for both feedback weights
# "w_fb": [-3]*(neuron_pop_size/2) + [3]*(neuron_pop_size/2),
"w_fb": [3]*int(neuron_pop_size/4) + [-3]*int(neuron_pop_size/4) + [3]*int(neuron_pop_size/4) + [-3]*int(neuron_pop_size/4),
"w_fb": [3.0]*int(neuron_pop_size/4) + [-3.0]*int(
neuron_pop_size/4) + [3.0]*int(neuron_pop_size/4) + [-3.0]*int(
neuron_pop_size/4),
# "B": 0.0,
"beta": beta,
"target_rate": 10,
Expand Down Expand Up @@ -254,15 +256,16 @@ 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)

total_error = 0.0
cycle_error = [0.0 for i in range(current_window*window_cycles)]
correct_or_not = [0 for i in range(current_window*window_cycles)]
for cycle in range(current_window*window_cycles):
# for cycle in range(current_window*window_cycles):
for cycle in range(window_cycles):
for time_index in range(cycle_time):
instantaneous_error = np.abs(float(
readout_res.segments[0].filter(name='gsyn_inh')[0][time_index+(cycle*cycle_time)][0]))
Expand Down
14 changes: 7 additions & 7 deletions eprop_testing/input_buffer_overflow_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
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
from pyNN.random import NumpyRNG, RandomDistribution
from pyNN.utility.plotting import Figure, Panel
# from spynnaker.pyNN.spynnaker_external_device_plugin_manager import SpynnakerExternalDevicePluginManager
from spynnaker.pyNN.spynnaker_external_device_plugin_manager import SpynnakerExternalDevicePluginManager

def weight_distribution(pop_size):
base_weight = np.random.randn() / np.sqrt(pop_size) #+ 0.5
Expand Down Expand Up @@ -75,7 +75,7 @@ def range_connector(pre_min, pre_max, post_min, post_max, weight=1.5, delay_offs
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": 40,
"rate_off": 0,
# "tau_m": tau_a,
Expand All @@ -85,7 +85,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)
Expand All @@ -99,7 +99,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(25.8)
else:
Expand Down Expand Up @@ -145,8 +145,8 @@ def range_connector(pre_min, pre_max, post_min, post_max, weight=1.5, delay_offs

# from_list_in, max_syn_per_input = probability_connector(input_size, neuron_pop_size, p_connect_in)
ps = readout_neuron_params["poisson_pop_size"]
from_list_in = range_connector(0, ps, 0, neuron_pop_size/2, weight=in_weight)
from_list_in += range_connector(ps, ps*2, neuron_pop_size/2, neuron_pop_size, weight=in_weight)
from_list_in = range_connector(0, ps, 0, neuron_pop_size//2, weight=in_weight)
from_list_in += range_connector(ps, ps*2, neuron_pop_size//2, neuron_pop_size, weight=in_weight)
from_list_in += range_connector(ps*2, ps*3, 0, neuron_pop_size, delay_offset=0, weight=prompt_weight)
in_proj = pynn.Projection(input_pop,
neuron,
Expand Down
2 changes: 1 addition & 1 deletion eprop_testing/learn_sinusoid_from_frozen_poisson.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion eprop_testing/learn_sinusoid_only_readout.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -95,7 +95,7 @@ def probability_connector(pre_pop_size, post_pop_size, prob, offset=0):
for i in range(num_repeats):
print('\nrepeat: {}\n'.format(i))
pynn.run(cycle_time)

in_spikes = input_pop.get_data('spikes')
readout_res = readout_pop.get_data('all')

Expand All @@ -117,7 +117,7 @@ def probability_connector(pre_pop_size, post_pop_size, prob, offset=0):
connection_diff_in = []
for i in range(len(from_list_in)):
connection_diff_in.append(new_connections_in[i][2] - from_list_in[i][2])

print("Input connections\noriginal\n", np.array(from_list_in))
print("new\n", np.array(new_connections_in))
print("diff\n", np.array(connection_diff_in))
Expand Down
2 changes: 1 addition & 1 deletion eprop_testing/one_neuron.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import spynnaker8 as pynn
import pyNN.spiNNaker as pynn
import numpy as np
import matplotlib.pyplot as plt
from pyNN.random import NumpyRNG, RandomDistribution
Expand Down
2 changes: 1 addition & 1 deletion eprop_testing/signed_weights_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import spynnaker8 as pynn
import pyNN.spiNNaker as pynn
import numpy as np
import matplotlib.pyplot as plt
from pyNN.random import NumpyRNG, RandomDistribution
Expand Down
2 changes: 1 addition & 1 deletion eprop_testing/test_8_neuron_regularisation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import spynnaker8 as pynn
import pyNN.spiNNaker as pynn
import numpy as np
import matplotlib.pyplot as plt
from pyNN.random import NumpyRNG, RandomDistribution
Expand Down
2 changes: 1 addition & 1 deletion eprop_testing/test_adaptive_threshold.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import spynnaker8 as pynn
import pyNN.spiNNaker as pynn
import numpy as np
import matplotlib.pyplot as plt
from pyNN.random import NumpyRNG, RandomDistribution
Expand Down
2 changes: 1 addition & 1 deletion eprop_testing/test_learning_signal_by_payload.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import spynnaker8 as pynn
import pyNN.spiNNaker as pynn
import numpy as np
import matplotlib.pyplot as plt
from pyNN.random import NumpyRNG, RandomDistribution
Expand Down
4 changes: 2 additions & 2 deletions eprop_testing/test_left_right_readout.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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
# 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
Expand Down
4 changes: 2 additions & 2 deletions eprop_testing/test_single_plastic_update.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import spynnaker8 as pynn
import pyNN.spiNNaker as pynn
import numpy as np
import matplotlib.pyplot as plt
from pyNN.random import NumpyRNG, RandomDistribution
Expand Down Expand Up @@ -29,7 +29,7 @@
eprop_learning = pynn.STDPMechanism(
timing_dependence=pynn.extra_models.TimingDependenceEprop(),
weight_dependence=pynn.extra_models.WeightDependenceEpropReg(
w_min=-2.0, w_max=2.0, reg_rate=1.5),
w_min=-2.0, w_max=2.0, reg_rate=1.5),
weight=start_w, delay=[0, 0])

proj = pynn.Projection(spike_source, neuron,
Expand Down
2 changes: 1 addition & 1 deletion eprop_testing/test_sinusoid_learning.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import spynnaker8 as pynn
import pyNN.spiNNaker as pynn
import numpy as np
import matplotlib.pyplot as plt
from pyNN.random import NumpyRNG, RandomDistribution
Expand Down
2 changes: 1 addition & 1 deletion eprop_testing/test_synapse_state_evol.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import spynnaker8 as pynn
import pyNN.spiNNaker as pynn
import numpy as np
import matplotlib.pyplot as plt
from pyNN.random import NumpyRNG, RandomDistribution
Expand Down

0 comments on commit 6055986

Please sign in to comment.