From 7a45b6cc7c0c355ec1700a80c2482bc62cb70d92 Mon Sep 17 00:00:00 2001 From: Andrew Gait Date: Thu, 18 Nov 2021 11:52:05 +0000 Subject: [PATCH 01/28] Move examples/tests from sPyNNaker8 to PyNN8Examples --- examples/icub_vor_examples/cerebellum.py | 445 +++++++++ examples/icub_vor_examples/cerebellum_tb.py | 504 +++++++++++ examples/icub_vor_examples/dataflow.py | 131 +++ examples/icub_vor_examples/icub_utilities.py | 224 +++++ .../icub_vor_examples/icub_vor_env_test.py | 133 +++ .../icub_vor_env_test_200_inputs.py | 95 ++ .../icub_vor_venv_test_perfect_motion.py | 107 +++ .../icub_vor_examples/pb_cerebellum_tb.py | 842 ++++++++++++++++++ ...e_cell_test.pysingle_purkinje_cell_test.py | 98 ++ examples/icub_vor_examples/readme.md | 13 + .../receptive_fields_for_motion.py | 423 +++++++++ .../single_purkinje_cell_pf_windowing.py | 105 +++ .../single_purkinje_cell_potentiation_test.py | 95 ++ .../single_purkinje_cell_test.py | 106 +++ .../single_vestibular_nuclei_mf_windowing.py | 110 +++ ...vestibular_nuclei_mf_windowing_3_spikes.py | 111 +++ ...gle_vestibular_nuclei_potentiation_test.py | 100 +++ examples/icub_vor_examples/test_mfvn_lut.py | 11 + examples/icub_vor_examples/test_pfpc_lut.py | 11 + 19 files changed, 3664 insertions(+) create mode 100644 examples/icub_vor_examples/cerebellum.py create mode 100644 examples/icub_vor_examples/cerebellum_tb.py create mode 100644 examples/icub_vor_examples/dataflow.py create mode 100644 examples/icub_vor_examples/icub_utilities.py create mode 100644 examples/icub_vor_examples/icub_vor_env_test.py create mode 100644 examples/icub_vor_examples/icub_vor_env_test_200_inputs.py create mode 100644 examples/icub_vor_examples/icub_vor_venv_test_perfect_motion.py create mode 100644 examples/icub_vor_examples/pb_cerebellum_tb.py create mode 100644 examples/icub_vor_examples/pb_single_purkinje_cell_test.pysingle_purkinje_cell_test.py create mode 100644 examples/icub_vor_examples/readme.md create mode 100644 examples/icub_vor_examples/receptive_fields_for_motion.py create mode 100644 examples/icub_vor_examples/single_purkinje_cell_pf_windowing.py create mode 100644 examples/icub_vor_examples/single_purkinje_cell_potentiation_test.py create mode 100644 examples/icub_vor_examples/single_purkinje_cell_test.py create mode 100644 examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing.py create mode 100644 examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing_3_spikes.py create mode 100644 examples/icub_vor_examples/single_vestibular_nuclei_potentiation_test.py create mode 100644 examples/icub_vor_examples/test_mfvn_lut.py create mode 100644 examples/icub_vor_examples/test_pfpc_lut.py diff --git a/examples/icub_vor_examples/cerebellum.py b/examples/icub_vor_examples/cerebellum.py new file mode 100644 index 00000000..2b7609ec --- /dev/null +++ b/examples/icub_vor_examples/cerebellum.py @@ -0,0 +1,445 @@ +import socket +import spynnaker8 as sim +import numpy as np +#import logging +import matplotlib.pyplot as plt + +#from spynnaker8.utilities import DataHolder +from pacman.model.constraints.key_allocator_constraints import FixedKeyAndMaskConstraint +from pacman.model.graphs.application import ApplicationSpiNNakerLinkVertex +from pacman.model.routing_info import BaseKeyAndMask +from spinn_front_end_common.abstract_models.abstract_provides_n_keys_for_partition import AbstractProvidesNKeysForPartition +from spinn_front_end_common.abstract_models.abstract_provides_outgoing_partition_constraints import AbstractProvidesOutgoingPartitionConstraints +from spinn_utilities.overrides import overrides +from pyNN.utility import Timer +from pyNN.utility.plotting import Figure, Panel +from pyNN.random import RandomDistribution, NumpyRNG + +from spynnaker.pyNN.models.neuron.plasticity.stdp.common \ + import plasticity_helpers + +# cerebellum with simulated input +RETINA_X_SIZE = 304 +RETINA_Y_SIZE = 240 +RETINA_BASE_KEY = 0x00000000 +RETINA_MASK = 0xFF000000 +RETINA_Y_BIT_SHIFT = 9 + +# class ICUBInputVertex( +# ApplicationSpiNNakerLinkVertex, +# # AbstractProvidesNKeysForPartition, +# AbstractProvidesOutgoingPartitionConstraints): +# +# def __init__(self, n_neurons, spinnaker_link_id, board_address=None, +# constraints=None, label=None): +# +# ApplicationSpiNNakerLinkVertex.__init__( +# self, n_neurons, spinnaker_link_id=spinnaker_link_id, +# board_address=board_address, label=label, constraints=constraints) +# #AbstractProvidesNKeysForPartition.__init__(self) +# AbstractProvidesOutgoingPartitionConstraints.__init__(self) +# +# # @overrides(AbstractProvidesNKeysForPartition.get_n_keys_for_partition) +# # def get_n_keys_for_partition(self, partition, graph_mapper): +# # return 1048576 +# +# @overrides(AbstractProvidesOutgoingPartitionConstraints. +# get_outgoing_partition_constraints) +# def get_outgoing_partition_constraints(self, partition): +# return [FixedKeyAndMaskConstraint( +# keys_and_masks=[BaseKeyAndMask( +# base_key=0, #upper part of the key +# mask=0xFFFFFC00)])] +# #keys, i.e. neuron addresses of the input population that sits in the ICUB vertex +# # this mask removes all spikes that have a "1" in the MSB and lets the spikes go only if the MSB are at "0" +# # it must have enough keys to host the input addressing space and the output (with the same keys) +# class ICUBInputVertexDataHolder(DataHolder): +# +# def __init__(self, spinnaker_link_id, board_address=None, +# constraints=None, label=None): +# DataHolder.__init__( +# self, {"spinnaker_link_id": spinnaker_link_id,"board_address": board_address, "label": label}) +# +# @staticmethod +# def build_model(): +# return ICUBInputVertex +# #logger = logging.getLogger(__name__) + +# Synapsis parameters +gc_pc_weights = 0.005 +mf_vn_weights = 0.001 +pc_vn_weights = -0.00002 +io_pc_weights = 0.0 +mf_gc_weights = 0.0006 +go_gc_weights = -0.0002 +input_weights = 0.00025 +mf_go_weights = 0.0006 + + +# Network parameters +num_MF_neurons = 100 +num_GC_neurons = 2000 +num_GOC_neurons = 100 +num_PC_neurons = 200 +num_VN_neurons = 200 +num_IO_neurons = 200 + +# Random distribution for synapses delays and weights (MF and GO) +delay_distr = RandomDistribution('uniform', (1.0, 10.0), rng=NumpyRNG(seed=85524)) +weight_distr_MF = RandomDistribution('uniform', (mf_gc_weights*0.8, mf_gc_weights*1.2), rng=NumpyRNG(seed=85524)) +weight_distr_GO = RandomDistribution('uniform', (go_gc_weights*0.8, go_gc_weights*1.2), rng=NumpyRNG(seed=24568)) + +# Post-synapse population +neuron_params = { + "v_thresh": -50, + "v_reset": -70, + "v_rest": -65, + "i_offset": 0 # DC input + } + +# Learning parameters cos rule (MF to VN) +min_weight_c = 0 +max_weight_c = 0.1 +pot_alpha_c = 0.01 # this is alpha in the paper +beta_c = 11 +sigma_c = 201 +initial_weight_c = 0.005 +initial_weight_c = 0.05 +plastic_delay_c = 4 + +# Learning parameters sin rule (GrC to PC) +min_weight_s = 0 +max_weight_s = 0.1 +pot_alpha_s =0.01 +t_peak_s =100 +initial_weight_s = 0.05 +plastic_delay_s = 4 + +sim.setup(timestep=1.) +#sim.set_number_of_neurons_per_core(sim.IF_curr_exp, 255) + +# set up input populations +# num_pxl = 304 * 240; +# retina_pop = sim.Population(1024, ICUBInputVertexDataHolder(spinnaker_link_id=0), label='pop_retina') + +# Sensorial Activity: input activity from vestibulus (will come from the head IMU, now it is a test bench) +def sensorial_activity(pt): + MAX_AMPLITUDE = 0.8 + RELATIVE_AMPLITUDE = 1.0 + _head_pos = [] + _head_vel = [] + + i = np.arange(0,2,0.01) + for t in i: + desired_speed=-np.cos(t*2*np.pi)*MAX_AMPLITUDE*RELATIVE_AMPLITUDE*2.0*np.pi + desired_pos=-np.sin(t*2*np.pi)*MAX_AMPLITUDE*RELATIVE_AMPLITUDE + _head_pos.append(desired_pos) + _head_vel.append(desired_speed) + + # single point over time + head_pos = _head_pos[pt] + head_vel = _head_vel[pt] + + head_pos = ((head_pos + 0.8) / 1.6) + head_vel = ((head_vel + 0.8 * 2 * np.pi) / (1.6 * 2 * np.pi)) + + if head_pos > 1.0: + head_pos = 1.0 + elif head_pos < 0.0: + head_pos = 0.0 + if head_vel > 1.0: + head_vel = 1.0 + elif head_vel < 0.0: + head_vel = 0.0 + + min_rate = 0.0 + max_rate = 600.0 + sigma = 0.02 + MF_pos_activity = np.zeros((50)) + MF_vel_activity = np.zeros((50)) + + for i in range(50): + mean = float(i) / 50.0 + 0.01 + gaussian = np.exp(-((head_pos - mean) * (head_pos - mean))/(2.0 * sigma * sigma)) + MF_pos_activity[i] = min_rate + gaussian * (max_rate - min_rate) + + for i in range(50): + mean = float(i) / 50.0 + 0.01 + gaussian = np.exp(-((head_vel - mean) * (head_vel - mean))/(2.0 * sigma * sigma)) + MF_vel_activity[i] = min_rate + gaussian * (max_rate - min_rate) + + #sa_mean_freq = np.arange(0,1000,10) + sa_mean_freq = np.concatenate((MF_pos_activity, MF_vel_activity)) + out = [sa_mean_freq,head_pos,head_vel] + return out + +# Error Activity: error from eye and head encoders +def error_activity(pt): + def compute_P_error(kp, head_position, eye_position): + error = kp * (head_position + eye_position) + return error + def compute_D_error(kd, head_velocity, eye_velocity): + error = kd * (head_velocity + eye_velocity) + return error + + MAX_AMPLITUDE = 0.8 + MAX_AMPLITUDE_EYE = 0.35 + RELATIVE_AMPLITUDE_EYE = 1.0 + phaseShift = 1.0*np.pi # simulated error between eye and head signals, error is zero if the waves are in opposite phase + _eye_pos = [] + _eye_vel = [] + ea_rate = [] + i = np.arange(0,2,0.01) + for t_eye in i: + desired_speed = -np.cos(t_eye*2*np.pi+phaseShift) * MAX_AMPLITUDE_EYE * RELATIVE_AMPLITUDE_EYE * 2.0 * np.pi + desired_pos = -np.sin(t_eye*2*np.pi+phaseShift) * MAX_AMPLITUDE_EYE * RELATIVE_AMPLITUDE_EYE + _eye_pos.append(desired_pos) + _eye_vel.append(desired_speed) + + # single point over time + eye_pos = _eye_pos[pt] + eye_vel = _eye_vel[pt] + #print 'eye_pos ea',eye_pos + + head = sensorial_activity(pt) + head_pos = head[1] + head_vel = head[2] + + #print head_pos, eye_pos + kp=15.0 + position_error = compute_P_error(kp, head_pos, eye_pos) + kd=15.0 + velocity_error = compute_D_error(kd, head_vel, eye_vel) + + error=(position_error * 0.1 + (velocity_error/(2.0*np.pi)) * 0.9)/(MAX_AMPLITUDE*5) + + #print position_error, velocity_error, error + + min_rate = 1.0 + max_rate = 25.0 + err = np.linspace(-2.0, 2.0, 20) +# err = [1] + for j in range(len(err)): + error_ = err[j] + #print error_ + low_neuron_ID_threshold = abs(error_) * 100.0 + up_neuron_ID_threshold = low_neuron_ID_threshold - 100.0 + IO_agonist = np.zeros((100)) + IO_antagonist = np.zeros((100)) + + rate = [] + for i in range (100): + if(i < up_neuron_ID_threshold): + rate.append(max_rate) + elif(i=0.0: + IO_agonist[0:100]=min_rate + IO_antagonist=rate + else: + IO_antagonist[0:100]=min_rate + IO_agonist=rate + + ea_rate = np.concatenate((IO_agonist,IO_antagonist)) + #print j +# plt.plot(np.linspace(up_neuron_ID_threshold,low_neuron_ID_threshold,200) ,ea_rate) +# plt.plot(ea_rate) +# plt.show() + + low_neuron_ID_threshold = abs(error) * 100.0 + up_neuron_ID_threshold = low_neuron_ID_threshold - 100.0 + IO_agonist = np.zeros((100)) + IO_antagonist = np.zeros((100)) + + rate = [] + for i in range (100): + if(i < up_neuron_ID_threshold): + rate.append(max_rate) + elif(i=0.0: + IO_agonist[0:100]=min_rate + IO_antagonist=rate + else: + IO_antagonist[0:100]=min_rate + IO_agonist=rate + + ea_rate = np.concatenate((IO_agonist,IO_antagonist)) + +# plt.plot(ea_rate) +# plt.show() + + return ea_rate + +#### + + +for j in range (200): + x = error_activity(j) + plt.plot(x) + +plt.show() + +SA_population = sim.Population(num_MF_neurons, # number of sources + sim.SpikeSourcePoisson, # source type + #{'rate': sa_mean_freq}, # source spike times + {'rate': sensorial_activity(10)[0]}, # source spike times + label="sa_population" # identifier + ) +# plt.plot(sensorial_activity()) +# plt.show() +# Create MF population +MF_population = sim.Population(num_MF_neurons, sim.IF_curr_exp(),label='MFLayer') + +# Create GOC population +GOC_population = sim.Population(num_GOC_neurons, sim.IF_cond_exp() ,label='GOCLayer') + +# Create MF-GO connections +mf_go_connections = sim.Projection(MF_population, + GOC_population, + sim.OneToOneConnector(), + sim.StaticSynapse(delay=1.0, weight=mf_go_weights)) + +# Create GrC population +GC_population = sim.Population(num_GC_neurons,sim.IF_curr_exp(),label='GCLayer') + +# create PC population +PC_population = sim.Population(num_PC_neurons, # number of neurons + sim.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model + label="Purkinje Cell" # identifier + ) + +# create VN population +VN_population = sim.Population(num_VN_neurons, # number of neurons + sim.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model + label="Vestibular Nuclei" # identifier + ) + +# Create IO population +IO_population = sim.Population(num_IO_neurons,sim.IF_curr_exp(),label='IOLayer') + +# Create connections + +# Create MF-GC and GO-GC connections +float_num_MF_neurons = float (num_MF_neurons) + +list_GOC_GC = [] +list_MF_GC = [] +list_GOC_GC_2 = [] +# projections to subpopulations https://github.com/SpiNNakerManchester/sPyNNaker8/issues/168) +for i in range (num_MF_neurons): + GC_medium_index = int(round((i / float_num_MF_neurons ) * num_GC_neurons)) + GC_lower_index = GC_medium_index - 40 + GC_upper_index = GC_medium_index + 60 + + if(GC_lower_index < 0): + GC_lower_index = 0 + + elif(GC_upper_index > num_GC_neurons): + GC_upper_index = num_GC_neurons + + for j in range (GC_medium_index - GC_lower_index): + list_GOC_GC.append((i, GC_lower_index + j)) + + for j in range(GC_medium_index + 20 - GC_medium_index): + list_MF_GC.append((i, GC_medium_index + j)) + + + for j in range(GC_upper_index - GC_medium_index - 20): + list_GOC_GC_2.append((i, GC_medium_index + 20 + j)) + +GO_GC_con1 = sim.Projection(GOC_population, + GC_population, + sim.FromListConnector(list_GOC_GC, weight_distr_GO, delay_distr)) + +MF_GC_con2 = sim.Projection(MF_population, + GC_population, + sim.FromListConnector(list_MF_GC, weight_distr_MF, delay_distr)) + +GO_GC_con3 = sim.Projection(GOC_population, + GC_population, + sim.FromListConnector(list_GOC_GC_2, weight_distr_GO, delay_distr)) + + +# Create PC-VN connections +pc_vn_connections = sim.Projection(PC_population, + VN_population, + sim.OneToOneConnector(), + #receptor_type='GABA', + synapse_type = sim.StaticSynapse(delay=1.0, weight=pc_vn_weights)) + +# Create MF-VN learning rule - cos +mfvn_plas = sim.STDPMechanism( + timing_dependence=sim.extra_models.TimingDependenceMFVN(beta=beta_c, + sigma=sigma_c), + weight_dependence=sim.extra_models.WeightDependenceMFVN(w_min=min_weight_c, + w_max=max_weight_c, + pot_alpha=pot_alpha_c), + weight=initial_weight_c, delay=plastic_delay_c) + +# Create MF to VN connections +mf_vn_connections = sim.Projection( + MF_population, VN_population, sim.AllToAllConnector(), + synapse_type=mfvn_plas, receptor_type="excitatory") + +# Create projection from PC to VN -- replaces "TEACHING SIGNAL" +pc_vn_connections = sim.Projection( + PC_population, VN_population, sim.OneToOneConnector(), + sim.StaticSynapse(weight=0.0, delay=1), receptor_type="excitatory") + +# create PF-PC learning rule - sin +pfpc_plas = sim.STDPMechanism( + timing_dependence=sim.extra_models.TimingDependencePFPC(t_peak=t_peak_s), + weight_dependence=sim.extra_models.WeightDependencePFPC(w_min=min_weight_s, + w_max=max_weight_s, + pot_alpha=pot_alpha_s), + weight=initial_weight_s, delay=plastic_delay_s) + +# Create PF-PC connections +pf_pc_connections = sim.Projection( + GC_population, PC_population, sim.AllToAllConnector(), + synapse_type=pfpc_plas, receptor_type="excitatory") + +# Create IO-PC connections. This synapse with "receptor_type=COMPLEX_SPIKE" propagates the learning signals that drive the plasticity mechanisms in GC-PC synapses +io_pc_connections = sim.Projection(IO_population, + PC_population, + sim.OneToOneConnector(), + #receptor_type='COMPLEX_SPIKE', + synapse_type = sim.StaticSynapse(delay=1.0, weight=io_pc_weights)) + + + +lif_pop = sim.Population(1024, sim.IF_curr_exp(), label='pop_lif') + +out_pop = sim.Population(128, sim.IF_curr_exp(), label='pop_out') + + + +# sim.Projection( +# lif_pop, out_pop, sim.OneToOneConnector(), +# synapse_type=sim.StaticSynapse(weight=0.1)) +# +# +# # live output of the input vertex (retina_pop) to the first pynn population (lif_pop) +# sim.external_devices.activate_live_output_to(out_pop,retina_pop) +# +# +# #recordings and simulations +# lif_pop.record(["spikes"]) +# +# out_pop.record(["spikes"]) +# +# +# +# sim.run(10) +# +# sim.end() + diff --git a/examples/icub_vor_examples/cerebellum_tb.py b/examples/icub_vor_examples/cerebellum_tb.py new file mode 100644 index 00000000..14bc2e1a --- /dev/null +++ b/examples/icub_vor_examples/cerebellum_tb.py @@ -0,0 +1,504 @@ +from __future__ import print_function # for python3 printing in python2 +import socket +import spynnaker8 as sim +import numpy as np +#import logging +import matplotlib.pyplot as plt + + +#from spynnaker8.utilities import DataHolder +from pacman.model.constraints.key_allocator_constraints import FixedKeyAndMaskConstraint +from pacman.model.graphs.application import ApplicationSpiNNakerLinkVertex +from pacman.model.routing_info import BaseKeyAndMask +from spinn_front_end_common.abstract_models.abstract_provides_n_keys_for_partition import AbstractProvidesNKeysForPartition +from spinn_front_end_common.abstract_models.abstract_provides_outgoing_partition_constraints import AbstractProvidesOutgoingPartitionConstraints +from spinn_utilities.overrides import overrides +from pyNN.utility import Timer +from pyNN.utility.plotting import Figure, Panel +from pyNN.random import RandomDistribution, NumpyRNG + +from spynnaker.pyNN.models.neuron.plasticity.stdp.common \ + import plasticity_helpers + +L_RATE = 2 +H_RATE = 20 + +# cerebellum test bench +runtime = 1000 + +# Synapsis parameters +gc_pc_weights = 0.005 +mf_vn_weights = 0.0005 +pc_vn_weights = 0.01 +cf_pc_weights = 0.0 +mf_gc_weights = 0.5 +go_gc_weights = 0.002 +input_weights = 0.0025 +mf_go_weights = 0.1 + +# Network parameters +num_MF_neurons = 100 +num_GC_neurons = 2000 +num_GOC_neurons = 100 +num_PC_neurons = 200 +num_VN_neurons = 200 +num_CF_neurons = 200 + +# Random distribution for synapses delays and weights (MF and GO) +delay_distr = RandomDistribution('uniform', (1.0, 10.0), rng=NumpyRNG(seed=85524)) +weight_distr_MF = RandomDistribution('uniform', (mf_gc_weights*0.8, mf_gc_weights*1.2), rng=NumpyRNG(seed=85524)) +weight_distr_GO = RandomDistribution('uniform', + (go_gc_weights*0.8, go_gc_weights*1.2), + rng=NumpyRNG(seed=24568)) + + +# Post-synapse population +neuron_params = { + "v_thresh": -50, + "v_reset": -70, + "v_rest": -65, + "i_offset": 0 # DC input + } + +# Learning parameters cos rule (MF to VN) +min_weight_c = 0 +max_weight_c = 0.005 +pot_alpha_c = 0.001 # this is alpha in the paper +beta_c = 11 +sigma_c = 201 +initial_weight_c = 0.001 # max_weight_c #0.0005 +# initial_weight_c = 0.05 +plastic_delay_c = 4 + +# Learning parameters sin rule (GrC to PC) +min_weight_s = 0 +max_weight_s = 0.01 +pot_alpha_s =0.01 +t_peak_s =100 +initial_weight_s = max_weight_s #0.0001 +plastic_delay_s = 4 +weight_dist_pfpc = RandomDistribution('uniform', + (initial_weight_s*0.8, + initial_weight_s*1.2), + rng=NumpyRNG(seed=24534)) + + +sim.setup(timestep=1.) + + + + +# Sensorial Activity: input activity from vestibulus (will come from the head IMU, now it is a test bench) +# We simulate the output of the head encoders with a sinusoidal function. Each "sensorial activity" value is derived from the +# head position and velocity. From that value, we generate the mean firing rate of the MF neurons (later this will be an input +# that will come from the robot, through the spinnLink) +# the neurons that are active depend on the value of the sensorial activity. For each a gaussian is created centered on a specific neuron + + +# Prepare variables once at beginning +MAX_AMPLITUDE = 0.8 +RELATIVE_AMPLITUDE = 1.0 +_head_pos = [] +_head_vel = [] + +i = np.arange(0,1000,0.001) +for t in i: + desired_speed=-np.cos(t*2*np.pi)*MAX_AMPLITUDE*RELATIVE_AMPLITUDE*2.0*np.pi + desired_pos=-np.sin(t*2*np.pi)*MAX_AMPLITUDE*RELATIVE_AMPLITUDE + _head_pos.append(desired_pos) + _head_vel.append(desired_speed) + + +def sensorial_activity(pt): # pt is a single point in time at which we measure the head encoder's output + + + # single point over time + head_pos = _head_pos[pt] + head_vel = _head_vel[pt] + + head_pos = ((head_pos + 0.8) / 1.6) + head_vel = ((head_vel + 0.8 * 2 * np.pi) / (1.6 * 2 * np.pi)) + + if head_pos > 1.0: + head_pos = 1.0 + elif head_pos < 0.0: + head_pos = 0.0 + if head_vel > 1.0: + head_vel = 1.0 + elif head_vel < 0.0: + head_vel = 0.0 + + min_rate = 0.0 + max_rate = 600.0 + sigma = 0.02 + MF_pos_activity = np.zeros((50)) + MF_vel_activity = np.zeros((50)) + + # generate gaussian distributions around the neuron tuned to a given sensorial activity + for i in range(50): + mean = float(i) / 50.0 + 0.01 + gaussian = np.exp(-((head_pos - mean) * (head_pos - mean))/(2.0 * sigma * sigma)) + MF_pos_activity[i] = min_rate + gaussian * (max_rate - min_rate) + + for i in range(50): + mean = float(i) / 50.0 + 0.01 + gaussian = np.exp(-((head_vel - mean) * (head_vel - mean))/(2.0 * sigma * sigma)) + MF_vel_activity[i] = min_rate + gaussian * (max_rate - min_rate) + + sa_mean_freq = np.concatenate((MF_pos_activity, MF_vel_activity)) + out = [sa_mean_freq,head_pos,head_vel] + return out + +# Error Activity: error from eye and head encoders +def error_activity(error_): + +# min_rate = 1.0 +# max_rate = 25.0 +# +# low_neuron_ID_threshold = abs(error_) * 100.0 +# up_neuron_ID_threshold = low_neuron_ID_threshold - 100.0 + IO_agonist = np.zeros((100)) + IO_antagonist = np.zeros((100)) +# +# rate = [] +# for i in range (100): +# if(i < up_neuron_ID_threshold): +# rate.append(max_rate) +# elif(i=0.0: +# IO_agonist[0:100]=min_rate +# IO_antagonist=rate +# else: +# IO_antagonist[0:100]=min_rate +# IO_agonist=rate + IO_agonist[:] = H_RATE + IO_antagonist[:] = L_RATE + + ea_rate = np.concatenate((IO_agonist,IO_antagonist)) + + return ea_rate + +def process_VN_spiketrains(VN_spikes, t_start): + total_spikes = 0 + for spiketrain in VN_spikes.segments[0].spiketrains: + s = spiketrain.as_array()[np.where(spiketrain.as_array() >= t_start)[0]] + total_spikes += len(s) + + return total_spikes + + +############################################################### +# Create Populations +############################################################### + +# Create MF population - fake input population that will be substituted by external input from robot + +MF_population = sim.Population(num_MF_neurons, # number of sources + sim.SpikeSourcePoisson, # source type + #{'rate': sa_mean_freq}, # source spike times + {'rate': sensorial_activity(0)[0]}, # source spike times + label="MFLayer" # identifier + ) + +# Create GOC population +GOC_population = sim.Population(num_GOC_neurons, sim.IF_cond_exp() ,label='GOCLayer') + +# create PC population +PC_population = sim.Population(num_PC_neurons, # number of neurons + sim.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model + label="Purkinje Cell" # identifier + ) + +# create VN population +VN_population = sim.Population(num_VN_neurons, # number of neurons + sim.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model + label="Vestibular Nuclei" # identifier + ) + + + + +# Create GrC population +GC_population = sim.Population(num_GC_neurons, sim.IF_curr_exp(), label='GCLayer') + + + +# generate fake error (it should be calculated from sensorial activity in error activity, but we skip it and just generate an error from -1.5 to 1.5) +err = -0.7 # other values to test: -0.3 0 0.3 0.7 + +# Create CF population - fake input population that will be substituted by external input from robot +CF_population = sim.Population(num_CF_neurons, # number of sources + sim.SpikeSourcePoisson, # source type + #{'rate': sa_mean_freq}, # source spike times + {'rate': error_activity(err)}, # source spike times + label="CFLayer" # identifier + ) + +############################################################### +# Create connections +############################################################### + +# Create MF-GO connections +mf_go_connections = sim.Projection(MF_population, + GOC_population, + sim.OneToOneConnector(), + sim.StaticSynapse(delay=delay_distr, weight=mf_go_weights), + receptor_type='excitatory') + + +# Create MF-GC and GO-GC connections +float_num_MF_neurons = float (num_MF_neurons) + +list_GOC_GC = [] +list_MF_GC = [] +list_GOC_GC_2 = [] +# projections to subpopulations https://github.com/SpiNNakerManchester/sPyNNaker8/issues/168) +for i in range (num_MF_neurons): + GC_medium_index = int(round((i / float_num_MF_neurons ) * num_GC_neurons)) + GC_lower_index = GC_medium_index - 40 + GC_upper_index = GC_medium_index + 60 + + if(GC_lower_index < 0): + GC_lower_index = 0 + + elif(GC_upper_index > num_GC_neurons): + GC_upper_index = num_GC_neurons + + for j in range (GC_medium_index - GC_lower_index): + list_GOC_GC.append( + (i, GC_lower_index + j, +# go_gc_weights, 1) + weight_distr_GO.next(), delay_distr.next()) + ) + + for j in range(GC_medium_index + 20 - GC_medium_index): + list_MF_GC.append( + (i, GC_medium_index + j, +# mf_gc_weights, 1) + weight_distr_MF.next(), delay_distr.next()) + ) + + + for j in range(GC_upper_index - GC_medium_index - 20): + list_GOC_GC_2.append( + (i, GC_medium_index + 20 + j, +# go_gc_weights, 1) + weight_distr_GO.next(), delay_distr.next()) + ) + +GO_GC_con1 = sim.Projection(GOC_population, + GC_population, + sim.FromListConnector(list_GOC_GC), + receptor_type='inhibitory') # this should be inhibitory + +MF_GC_con2 = sim.Projection(MF_population, + GC_population, + sim.FromListConnector(list_MF_GC), + receptor_type='excitatory') + +GO_GC_con3 = sim.Projection(GOC_population, + GC_population, + sim.FromListConnector(list_GOC_GC_2), + receptor_type='inhibitory') + + +# Create PC-VN connections +pc_vn_connections = sim.Projection(PC_population, + VN_population, + sim.OneToOneConnector(), + #receptor_type='GABA', # Should these be inhibitory? + synapse_type = sim.StaticSynapse(delay=delay_distr, weight=pc_vn_weights), + receptor_type='inhibitory') + +# Create MF-VN learning rule - cos +mfvn_plas = sim.STDPMechanism( + timing_dependence=sim.extra_models.TimingDependenceMFVN(beta=beta_c, + sigma=sigma_c), + weight_dependence=sim.extra_models.WeightDependenceMFVN(w_min=min_weight_c, + w_max=max_weight_c, + pot_alpha=pot_alpha_c), + weight=initial_weight_c, delay=delay_distr) + +# Create MF to VN connections +mf_vn_connections = sim.Projection( + MF_population, VN_population, sim.AllToAllConnector(), # Needs mapping as FromListConnector to make efficient + synapse_type=mfvn_plas, + receptor_type="excitatory") + +# Create projection from PC to VN -- replaces "TEACHING SIGNAL" +pc_vn_connections = sim.Projection( + PC_population, VN_population, sim.OneToOneConnector(), + sim.StaticSynapse(weight=0.0, delay=1.0), + receptor_type="excitatory") # "TEACHING SIGNAL" + +# create PF-PC learning rule - sin +pfpc_plas = sim.STDPMechanism( + timing_dependence=sim.extra_models.TimingDependencePFPC(t_peak=t_peak_s), + weight_dependence=sim.extra_models.WeightDependencePFPC(w_min=min_weight_s, + w_max=max_weight_s, + pot_alpha=pot_alpha_s), + weight=initial_weight_s, + delay=delay_distr + ) + +# Create PF-PC connections +pf_pc_connections = sim.Projection( + GC_population, PC_population, sim.AllToAllConnector(), + synapse_type=pfpc_plas, + receptor_type="excitatory") + +# Create IO-PC connections. This synapse with "receptor_type=COMPLEX_SPIKE" propagates the learning signals that drive the plasticity mechanisms in GC-PC synapses +cf_pc_connections = sim.Projection(CF_population, + PC_population, + sim.OneToOneConnector(), + #receptor_type='COMPLEX_SPIKE', + synapse_type = sim.StaticSynapse(delay=1.0, weight=cf_pc_weights), + receptor_type='excitatory') + +# lif_pop = sim.Population(1024, sim.IF_curr_exp(), label='pop_lif') +# +# out_pop = sim.Population(128, sim.IF_curr_exp(), label='pop_out') + +# sim.run(1000) + +# sim.Projection( +# lif_pop, out_pop, sim.OneToOneConnector(), +# synapse_type=sim.StaticSynapse(weight=0.1)) +# +# +# # live output of the input vertex (retina_pop) to the first pynn population (lif_pop) +# sim.external_devices.activate_live_output_to(out_pop,retina_pop) +# +# +#recordings and simulations +# lif_pop.record(["spikes"]) +# +# out_pop.record(["spikes"]) +# +# +# +#sim.run(10) +# +#sim.end() + +MF_population.record(['spikes']) +CF_population.record(['spikes']) +GC_population.record('all') +GOC_population.record(['spikes']) +VN_population.record('all') # VN_population.record(['spikes']) +PC_population.record(['spikes']) + +samples_in_repeat= 99 +sample_time = 10 +repeats = 1 +total_runtime = 0 +VN_transfer_func = [] + +for i in range(samples_in_repeat): + + sim.run(sample_time) + + VN_spikes = VN_population.get_data('spikes') + VN_transfer_func.append(process_VN_spiketrains(VN_spikes, total_runtime)) + + total_runtime +=sample_time + + print(total_runtime) + + MF_population.set(rate=sensorial_activity(total_runtime)[0]) + + + + + +# sim.run(runtime*0.4) +# +# CF_rates=[] +# lower_rate=100*[L_RATE] +# upper_rate=100*[H_RATE] +# CF_rates.extend(lower_rate) +# CF_rates.extend(upper_rate) +# CF_population.set(rate=CF_rates) +# +# sim.run(runtime*0.4) +# +# CF_rates=[] +# lower_rate=100*[H_RATE] +# upper_rate=100*[L_RATE] +# CF_rates.extend(lower_rate) +# CF_rates.extend(upper_rate) +# CF_population.set(rate=CF_rates) +# +# sim.run(runtime*0.2) +# +# CF_rates=[] +# lower_rate=100*[H_RATE] +# upper_rate=100*[L_RATE] +# CF_rates.extend(lower_rate) +# CF_rates.extend(upper_rate) +# CF_population.set(rate=CF_rates) + + + +total_runtime = runtime*repeats + +MF_spikes = MF_population.get_data('spikes') +CF_spikes = CF_population.get_data('spikes') +GC_spikes = GC_population.get_data('all') +GOC_spikes = GOC_population.get_data('spikes') +VN_spikes = VN_population.get_data('all') # VN_population.get_data('spikes') +PC_spikes = PC_population.get_data('spikes') + + +mfvn_weights = mf_vn_connections.get('weight', 'list', with_address=False) +pfpc_weights = pf_pc_connections.get('weight', 'list', with_address=False) + +# Plot +F = Figure( + Panel(MF_spikes.segments[0].spiketrains, + yticks=True, markersize=2, xlim=(0, total_runtime), + xlabel='MF_spikes'), + Panel(CF_spikes.segments[0].spiketrains, + yticks=True, markersize=2, xlim=(0, total_runtime), + xlabel='CF_spikes'), + Panel(GC_spikes.segments[0].spiketrains, + yticks=True, markersize=2, xlim=(0, total_runtime), + xlabel='GC_spikes'), + Panel(GOC_spikes.segments[0].spiketrains, + yticks=True, markersize=2, xlim=(0, total_runtime), + xlabel='GOC_spikes'), + Panel(PC_spikes.segments[0].spiketrains, + yticks=True, markersize=2, xlim=(0, total_runtime), + xlabel='PC_spikes'), + Panel(VN_spikes.segments[0].spiketrains, + yticks=True, markersize=2, xlim=(0, total_runtime), + xlabel='VN_spikes'), + Panel(VN_spikes.segments[0].filter(name='gsyn_inh')[0], + ylabel="Membrane potential (mV)", yticks=True, xlim=(0, total_runtime)) + ) +plt.show(block=False) + +plt.figure() +plt.plot(mfvn_weights, + label='mf-vn weights (init: {})'.format(initial_weight_c)) +plt.legend() + +plt.figure() +plt.plot(pfpc_weights, color='orange', + label='pf-pc weights (init: {})'.format(initial_weight_s)) +plt.legend() + +print(VN_transfer_func) + +plt.figure() +plt.plot(VN_transfer_func) + +plt.show() + +sim.end() +print("job done") \ No newline at end of file diff --git a/examples/icub_vor_examples/dataflow.py b/examples/icub_vor_examples/dataflow.py new file mode 100644 index 00000000..19645b60 --- /dev/null +++ b/examples/icub_vor_examples/dataflow.py @@ -0,0 +1,131 @@ +import socket +import spynnaker8 as sim +import numpy as np +#import logging +import matplotlib.pyplot as plt + +from pacman.model.constraints.key_allocator_constraints import FixedKeyAndMaskConstraint +from pacman.model.graphs.application import ApplicationSpiNNakerLinkVertex +from pacman.model.routing_info import BaseKeyAndMask +from spinn_front_end_common.abstract_models.abstract_provides_n_keys_for_partition import AbstractProvidesNKeysForPartition +from spinn_front_end_common.abstract_models.abstract_provides_outgoing_partition_constraints import AbstractProvidesOutgoingPartitionConstraints +from spinn_utilities.overrides import overrides +from spinn_front_end_common.abstract_models.abstract_provides_incoming_partition_constraints import AbstractProvidesIncomingPartitionConstraints +from pacman.executor.injection_decorator import inject_items +from pacman.operations.routing_info_allocator_algorithms.malloc_based_routing_allocator.utils import get_possible_masks +from spinn_front_end_common.utility_models.command_sender_machine_vertex import CommandSenderMachineVertex + +from spinn_front_end_common.abstract_models \ + import AbstractSendMeMulticastCommandsVertex +from spinn_front_end_common.utility_models.multi_cast_command \ + import MultiCastCommand + + +from pyNN.utility import Timer +from pyNN.utility.plotting import Figure, Panel +from pyNN.random import RandomDistribution, NumpyRNG + +from spynnaker.pyNN.models.neuron.plasticity.stdp.common import plasticity_helpers + +NUM_NEUR_IN = 1024 #1024 # 2x240x304 mask -> 0xFFFE0000 +MASK_IN = 0xFFFFFC00 #0xFFFFFC00 +NUM_NEUR_OUT = 1024 +#MASK_OUT =0xFFFFFC00 + +class ICUBInputVertex( + ApplicationSpiNNakerLinkVertex, + AbstractProvidesOutgoingPartitionConstraints, + AbstractProvidesIncomingPartitionConstraints, + AbstractSendMeMulticastCommandsVertex): + + def __init__(self, spinnaker_link_id, board_address=None, + constraints=None, label=None): + + ApplicationSpiNNakerLinkVertex.__init__( + self, n_atoms=NUM_NEUR_IN, spinnaker_link_id=spinnaker_link_id, + board_address=board_address, label=label) + + AbstractProvidesNKeysForPartition.__init__(self) + AbstractProvidesOutgoingPartitionConstraints.__init__(self) + AbstractSendMeMulticastCommandsVertex.__init__(self) + + @overrides(AbstractProvidesOutgoingPartitionConstraints. + get_outgoing_partition_constraints) + def get_outgoing_partition_constraints(self, partition): + return [FixedKeyAndMaskConstraint( + keys_and_masks=[BaseKeyAndMask( + base_key=0, #upper part of the key, + mask=MASK_IN)])] + #keys, i.e. neuron addresses of the input population that sits in the ICUB vertex, + + @inject_items({"graph_mapper": "MemoryGraphMapper"}) + @overrides(AbstractProvidesIncomingPartitionConstraints. + get_incoming_partition_constraints, + additional_arguments=["graph_mapper"]) + def get_incoming_partition_constraints(self, partition, graph_mapper): + if isinstance(partition.pre_vertex, CommandSenderMachineVertex): + return [] + index = graph_mapper.get_machine_vertex_index(partition.pre_vertex) + vertex_slice = graph_mapper.get_slice(partition.pre_vertex) + mask = get_possible_masks(vertex_slice.n_atoms)[0] + key = (0x1000 + index) << 16 + return [FixedKeyAndMaskConstraint( + keys_and_masks=[BaseKeyAndMask(key, mask)])] + + @property + @overrides(AbstractSendMeMulticastCommandsVertex.start_resume_commands) + def start_resume_commands(self): + return [MultiCastCommand( + key=0x80000000, payload=0, repeat=5, delay_between_repeats=100)] + + @property + @overrides(AbstractSendMeMulticastCommandsVertex.pause_stop_commands) + def pause_stop_commands(self): + return [MultiCastCommand( + key=0x40000000, payload=0, repeat=5, delay_between_repeats=100)] + + @property + @overrides(AbstractSendMeMulticastCommandsVertex.timed_commands) + def timed_commands(self): + return [] + + +sim.setup(timestep=1.0) +# sim.set_number_of_neurons_per_core(sim.IF_curr_exp, 32) + +# set up populations, +pop = sim.Population(None, ICUBInputVertex(spinnaker_link_id=0), label='pop_in') + +#neural population , +neuron_pop = sim.Population(NUM_NEUR_OUT, sim.IF_curr_exp(), label='neuron_pop') + +sim.Projection(pop, neuron_pop, sim.OneToOneConnector(), sim.StaticSynapse(weight=20.0)) + +#pop_out = sim.Population(None, ICUBOutputVertex(spinnaker_link_id=0), label='pop_out') + +sim.external_devices.activate_live_output_to(neuron_pop,pop) + +#recordings and simulations, +# neuron_pop.record("spikes") + +# simtime = 30000 #ms, +# sim.run(simtime) + +# continuous run until key press +# remember: do NOT record when running in this mode +sim.external_devices.run_forever() +raw_input('Press enter to stop') + +# exc_spikes = neuron_pop.get_data("spikes") +# +# Figure( +# # raster plot of the neuron_pop +# Panel(exc_spikes.segments[0].spiketrains, xlabel="Time/ms", xticks=True, +# yticks=True, markersize=0.2, xlim=(0, simtime)), +# title="neuron_pop: spikes" +# ) +# plt.show() + +sim.end() + +print("finished") diff --git a/examples/icub_vor_examples/icub_utilities.py b/examples/icub_vor_examples/icub_utilities.py new file mode 100644 index 00000000..20b21b39 --- /dev/null +++ b/examples/icub_vor_examples/icub_utilities.py @@ -0,0 +1,224 @@ +import numpy as np +import pylab as plt +import matplotlib as mlib +import copy + +# ensure we use viridis as the default cmap +plt.viridis() + +mlib.use('Agg') +# ensure we use the same rc parameters for all matplotlib outputs +mlib.rcParams.update({'font.size': 24}) +mlib.rcParams.update({'errorbar.capsize': 5}) +mlib.rcParams.update({'figure.autolayout': True}) +viridis_cmap = mlib.cm.get_cmap('viridis') + +ICUB_VOR_VENV_POP_SIZE = 2 +POS_TO_VEL = 2 * np.pi * 0.001 + + +# Examples of get functions for variables +def get_error(icub_vor_env_pop, simulator): + b_vertex = icub_vor_env_pop._vertex + error = b_vertex.get_data( + 'error', simulator.no_machine_time_steps, simulator.placements, + simulator.buffer_manager, simulator.machine_time_step) + return error.tolist() + + +def get_l_count(icub_vor_env_pop, simulator): + b_vertex = icub_vor_env_pop._vertex + left_count = b_vertex.get_data( + 'l_count', simulator.no_machine_time_steps, simulator.placements, + simulator.buffer_manager, simulator.machine_time_step) + return left_count.tolist() + + +def get_r_count(icub_vor_env_pop, simulator): + b_vertex = icub_vor_env_pop._vertex + right_count = b_vertex.get_data( + 'r_count', simulator.no_machine_time_steps, simulator.placements, + simulator.buffer_manager, simulator.machine_time_step) + return right_count.tolist() + + +def get_eye_pos(icub_vor_env_pop, simulator): + b_vertex = icub_vor_env_pop._vertex + eye_positions = b_vertex.get_data( + 'eye_pos', simulator.no_machine_time_steps, simulator.placements, + simulator.buffer_manager, simulator.machine_time_step) + return eye_positions.tolist() + + +def get_eye_vel(icub_vor_env_pop, simulator): + b_vertex = icub_vor_env_pop._vertex + eye_velocities = b_vertex.get_data( + 'eye_vel', simulator.no_machine_time_steps, simulator.placements, + simulator.buffer_manager, simulator.machine_time_step) + return eye_velocities.tolist() + + +def generate_head_position_and_velocity(time, dt=0.001): + i = np.arange(0, time, dt) + pos = -np.sin(i * 2 * np.pi) + vel = -np.cos(i * 2 * np.pi) + return pos, vel + + +def retrieve_and_package_results(icub_vor_env_pop, simulator): + # Get the data from the ICubVorEnv pop + errors = np.asarray(get_error(icub_vor_env_pop=icub_vor_env_pop, simulator=simulator)).ravel() + l_counts = get_l_count(icub_vor_env_pop=icub_vor_env_pop, simulator=simulator) + r_counts = get_r_count(icub_vor_env_pop=icub_vor_env_pop, simulator=simulator) + rec_eye_pos = np.asarray(get_eye_pos( + icub_vor_env_pop=icub_vor_env_pop, simulator=simulator)).ravel() + rec_eye_vel = np.asarray(get_eye_vel( + icub_vor_env_pop=icub_vor_env_pop, simulator=simulator)).ravel() + results = { + 'errors': errors, + 'l_counts': l_counts, + 'r_counts': r_counts, + 'rec_eye_pos': rec_eye_pos, + 'rec_eye_vel': rec_eye_vel, + } + return results + + +def highlight_area(ax, runtime, start_nid, stop_nid): + ax.fill_between( + [0, runtime], start_nid, stop_nid, + color='grey', alpha=0.1, + ) + + +def plot_results(results_dict, simulation_parameters, name): + # unpacking results + errors = results_dict['errors'] + l_counts = results_dict['l_counts'] + r_counts = results_dict['r_counts'] + rec_eye_pos = results_dict['rec_eye_pos'] + rec_eye_vel = results_dict['rec_eye_vel'] + + # unpacking simulation params + runtime = simulation_parameters['runtime'] + error_window_size = simulation_parameters['error_window_size'] + vn_spikes = simulation_parameters['vn_spikes'] + cf_spikes = simulation_parameters['cf_spikes'] + perfect_eye_pos = simulation_parameters['perfect_eye_pos'] + perfect_eye_vel = simulation_parameters['perfect_eye_vel'] + vn_size = simulation_parameters['vn_size'] + cf_size = simulation_parameters['cf_size'] + + # plot the data from the ICubVorEnv pop + x_plot = [(n) for n in range(0, runtime, error_window_size)] + fig = plt.figure(figsize=(15, 20), dpi=400) + # Spike raster plot + ax = plt.subplot(5, 1, 1) + highlight_area(ax, runtime, vn_size // 2, vn_size) + first_half_filter = vn_spikes[:, 0] < vn_size // 2 + second_half_filter = ~first_half_filter + plt.scatter( + vn_spikes[second_half_filter, 1], vn_spikes[second_half_filter, 0], + s=1, color=viridis_cmap(.75)) + plt.scatter( + vn_spikes[first_half_filter, 1], vn_spikes[first_half_filter, 0], + s=1, color=viridis_cmap(.25)) + + plt.xlim([0, runtime]) + plt.ylim([-0.1, vn_size+0.1]) + # L/R counts + plt.subplot(5, 1, 2) + plt.plot(x_plot, l_counts, 'o', color=viridis_cmap(.25), label="l_counts") + plt.plot(x_plot, r_counts, 'o', color=viridis_cmap(.75), label="r_counts") + plt.legend(loc="best") + plt.xlim([0, runtime]) + # Positions and velocities + plt.subplot(5, 1, 3) + plt.plot(x_plot, rec_eye_pos, label="rec. eye position") + plt.plot(x_plot, rec_eye_vel, label="rec. eye velocity") + plt.plot(np.tile(perfect_eye_pos, runtime // 1000), label="eye position", ls=':') + plt.plot(np.tile(perfect_eye_vel, runtime // 1000), label="eye velocity", ls=':') + plt.legend(loc="best") + plt.xlim([0, runtime]) + # Errors + plt.subplot(5, 1, 4) + plt.plot(x_plot, errors, label="recorded error") + + eye_pos_diff = np.tile(perfect_eye_pos[::error_window_size], runtime // 1000) - rec_eye_pos.ravel() + eye_vel_diff = np.tile(perfect_eye_vel[::error_window_size], runtime // 1000) - rec_eye_vel.ravel() + reconstructed_error = eye_pos_diff + eye_vel_diff + + plt.plot(x_plot, reconstructed_error, color='k', ls=":", label="reconstructed error") + plt.plot(x_plot, eye_pos_diff, + label="eye position diff") + plt.plot(x_plot, eye_vel_diff, + label="eye velocity diff") + plt.legend(loc="best") + plt.xlim([0, runtime]) + # Error spikes + ax2 = plt.subplot(5, 1, 5) + highlight_area(ax2, runtime, cf_size // 2, cf_size) + first_half_filter = cf_spikes[:, 0] < cf_size // 2 + second_half_filter = ~first_half_filter + plt.scatter( + cf_spikes[second_half_filter, 1], cf_spikes[second_half_filter, 0], + s=1, color=viridis_cmap(.75)) + plt.scatter( + cf_spikes[first_half_filter, 1], cf_spikes[first_half_filter, 0], + s=1, color=viridis_cmap(.25)) + # plt.legend(loc="best") + plt.xlim([0, runtime]) + plt.ylim([-0.1, cf_size+0.1]) + plt.xlabel("Time (ms)") + save_figure(plt, name, extensions=[".png", ]) + plt.close(fig) + + +def remap_odd_even(original_spikes, size): + remapped_spikes = copy.deepcopy(original_spikes) + mapping = np.arange(size) + mapping[::2] = np.arange(0, size, 2) // 2 + mapping[1::2] = size // 2 + np.arange(size - 1, 0, -2) // 2 + remapped_spikes[:, 0] = mapping[remapped_spikes[:, 0].astype(int)] + return remapped_spikes + + +def remap_second_half_descending(original_spikes, size): + remapped_spikes = copy.deepcopy(original_spikes) + mapping = np.arange(size) + mapping[:size // 2] = np.arange(0, size // 2, 1) + mapping[size // 2:] = np.arange(size, size // 2, -1) + remapped_spikes[:, 0] = mapping[remapped_spikes[:, 0].astype(int)] + return remapped_spikes + + +def color_for_index(index, size, cmap=viridis_cmap): + return cmap(index / (size + 1)) + + +def write_sep(): + print("=" * 80) + + +def write_line(): + print("-" * 80) + + +def write_header(msg): + write_sep() + print(msg) + write_line() + + +def write_short_msg(msg, value): + print("{:40}:{:39}".format(msg, str(value))) + + +def write_value(msg, value): + print("{:60}:{:19}".format(msg, str(value))) + + +def save_figure(plt, name, extensions=(".png",), **kwargs): + for ext in extensions: + write_short_msg("Plotting", name + ext) + plt.savefig(name + ext, **kwargs) diff --git a/examples/icub_vor_examples/icub_vor_env_test.py b/examples/icub_vor_examples/icub_vor_env_test.py new file mode 100644 index 00000000..212354dc --- /dev/null +++ b/examples/icub_vor_examples/icub_vor_env_test.py @@ -0,0 +1,133 @@ +import spynnaker8 as p +import spinn_gym as gym + +from pyNN.utility.plotting import Figure, Panel +import matplotlib.pyplot as plt +import numpy as np +import os +from spinn_front_end_common.utilities.globals_variables import get_simulator +from icub_utilities import * + +# Parameter definition +runtime = 10000 +# Build input SSP and output population +input_size = 2 # neurons +output_size = 200 # neurons +input_rate = 20 # Hz +# get head_positions and head_velocities from file (1000 samples) +base_dir = "./" +head_pos = np.loadtxt(os.path.join( + base_dir, "normalised_head_positions_1000.csv")) +head_vel = np.loadtxt(os.path.join( + base_dir, "normalised_head_velocities_1000.csv")) + +# The values in the files are [0,1] when we really want [-1,1]; obtain this +# by multiplying by 2 and subtracting 1 + +head_pos = (head_pos * 2.0) - 1.0 +head_vel = (head_vel * 2.0) - 1.0 + + +# perfect eye positions and velocities are exactly out of phase with head +perfect_eye_pos = np.concatenate((head_pos[500:], head_pos[:500])) +perfect_eye_vel = np.concatenate((head_vel[500:], head_vel[:500])) + +# TEST +# Report 4 points: +for i in [0, 250, 500, 750]: + print("At {}: head pos {:4.6f}, head vel {:4.6f}, eye pos {:4.6f}, eye vel {:4.6f}".format( + i, head_pos[i], head_vel[i], perfect_eye_pos[i], perfect_eye_vel[i])) + +# build ICubVorEnv model pop +error_window_size = 10 # ms + +# Setup +p.setup(timestep=1.0) + +input_pop = p.Population(input_size, p.SpikeSourcePoisson(rate=input_rate)) +output_pop = p.Population(output_size, p.SpikeSourcePoisson(rate=0)) + +# Instantiate venv +icub_vor_env_model = gym.ICubVorEnv( + head_pos, head_vel, perfect_eye_vel, perfect_eye_pos, error_window_size, + output_size) +icub_vor_env_pop = p.Population(input_size, icub_vor_env_model) + +# Set recording for input and output pop (env pop records by default) +input_pop.record('spikes') +output_pop.record('spikes') + +# Input -> ICubVorEnv projection +i2a = p.Projection(input_pop, icub_vor_env_pop, p.AllToAllConnector()) + +# ICubVorEnv -> output, setup live output to the SSP vertex +p.external_devices.activate_live_output_to( + icub_vor_env_pop, output_pop, "CONTROL") + +# Store simulator and run +simulator = get_simulator() +# Run the simulation +p.run(runtime) + +# Get the data from the ICubVorEnv pop +errors = get_error(icub_vor_env_pop=icub_vor_env_pop, simulator=simulator) +l_counts = get_l_count(icub_vor_env_pop=icub_vor_env_pop, simulator=simulator) +r_counts = get_r_count(icub_vor_env_pop=icub_vor_env_pop, simulator=simulator) +rec_head_pos = get_head_pos( + icub_vor_env_pop=icub_vor_env_pop, simulator=simulator) +rec_head_vel = get_head_vel( + icub_vor_env_pop=icub_vor_env_pop, simulator=simulator) + +# get the spike data from input and output and plot +# spikes_in = input_pop.get_data('spikes').segments[0].spiketrains +# spikes_out = output_pop.get_data('spikes').segments[0].spiketrains +# Figure( +# Panel(spikes_in, xlabel="Time (ms)", ylabel="nID", +# xticks=True, yticks=True), +# Panel(spikes_out, xlabel="Time (ms)", ylabel="nID", +# xticks=True, yticks=True) +# ) +# plt.show() + +spikes_in_spin = input_pop.spinnaker_get_data('spikes') +spikes_out_spin = output_pop.spinnaker_get_data('spikes') + +# end simulation +p.end() + +# plot the data from the ICubVorEnv pop +x_plot = [(n) for n in range(0, runtime, error_window_size)] +plt.figure(figsize=(15, 11), dpi=300) + +plt.subplot(5, 1, 1) +plt.scatter( + [i[1] for i in spikes_in_spin], [i[0] for i in spikes_in_spin], s=1) +plt.legend(loc="best") +plt.xlim([0, runtime]) + +plt.subplot(5, 1, 2) +plt.plot(x_plot, l_counts, 'bo', label="l_counts") +plt.plot(x_plot, r_counts, 'ro', label="r_counts") +plt.legend(loc="best") +plt.xlim([0, runtime]) + +plt.subplot(5, 1, 3) +plt.plot(x_plot, rec_head_pos, label="head position") +plt.plot(x_plot, rec_head_vel, label="head velocity") +# plt.plot(perfect_eye_pos, label="eye position", ls='--') +# plt.plot(perfect_eye_vel, label="eye velocity", ls='--') +plt.legend(loc="best") +plt.xlim([0, runtime]) + +plt.subplot(5, 1, 4) +plt.plot(x_plot, errors, label="errors") +plt.legend(loc="best") +plt.xlim([0, runtime]) + +plt.subplot(5, 1, 5) +plt.scatter( + [i[1] for i in spikes_out_spin], [i[0] for i in spikes_out_spin], s=1) +plt.legend(loc="best") +plt.xlim([0, runtime]) +plt.savefig("spinngym_icub_vor_test.png") +plt.show() diff --git a/examples/icub_vor_examples/icub_vor_env_test_200_inputs.py b/examples/icub_vor_examples/icub_vor_env_test_200_inputs.py new file mode 100644 index 00000000..03b8613b --- /dev/null +++ b/examples/icub_vor_examples/icub_vor_env_test_200_inputs.py @@ -0,0 +1,95 @@ +import spynnaker8 as p +import spinn_gym as gym + +from pyNN.utility.plotting import Figure, Panel +import matplotlib.pyplot as plt +import numpy as np +import os +from spinn_front_end_common.utilities.globals_variables import get_simulator +from icub_utilities import * + +# Parameter definition +runtime = 5000 +# Build input SSP and output population +input_size = 200 # neurons +output_size = 200 # neurons +gain = 20.0 + +head_pos, head_vel = generate_head_position_and_velocity(1) + +# perfect eye positions and velocities are exactly out of phase with head +perfect_eye_pos = np.concatenate((head_pos[500:], head_pos[:500])) +perfect_eye_vel = np.concatenate((head_vel[500:], head_vel[:500])) + +error_window_size = 10 # ms +npc_limit = 50 +input_spike_times = [[] for _ in range(input_size)] + +for i in range(5): + input_spike_times[i * 2] = [250 + (10 * 2 * i) for _ in range(1)] + input_spike_times[2 * i + 1] = [500 + (10 * (2 * i + 1)) for _ in range(1)] + input_spike_times[50 + i * 2] = [750 + (10 * 2 * i) for _ in range(10 + i)] + input_spike_times[100 + 2 * i + 1] = [1000 + (10 * (2 * i + 1)) for _ in range(10 + i)] + input_spike_times[150 + i * 2] = [1250 + (10 * 2 * i) for _ in range(100 + i)] + input_spike_times[150 + 2 * i + 1] = [1500 + (10 * (2 * i + 1)) for _ in range(100 + i)] + +# Setup +p.setup(timestep=1.0) +p.set_number_of_neurons_per_core(p.SpikeSourcePoisson, 50) +p.set_number_of_neurons_per_core(p.SpikeSourceArray, npc_limit) +input_pop = p.Population(input_size, p.SpikeSourceArray(spike_times=input_spike_times)) + +output_pop = p.Population(output_size, p.SpikeSourcePoisson(rate=0)) + +# Instantiate venv +icub_vor_env_model = gym.ICubVorEnv( + head_pos, head_vel, perfect_eye_vel, perfect_eye_pos, error_window_size, + output_size) +icub_vor_env_pop = p.Population(ICUB_VOR_VENV_POP_SIZE, icub_vor_env_model) + +# Set recording for input and output pop (env pop records by default) +input_pop.record('spikes') +output_pop.record('spikes') + +# Input -> ICubVorEnv projection +i2a = p.Projection(input_pop, icub_vor_env_pop, p.AllToAllConnector()) + +# ICubVorEnv -> output, setup live output to the SSP vertex +p.external_devices.activate_live_output_to( + icub_vor_env_pop, output_pop, "CONTROL") + +# Store simulator and run +simulator = get_simulator() +# Run the simulation +p.run(runtime) + +# Get the data from the ICubVorEnv pop +results = retrieve_and_package_results(icub_vor_env_pop, simulator) + +# get the spike data from input and output +spikes_in_spin = input_pop.spinnaker_get_data('spikes') +spikes_out_spin = output_pop.spinnaker_get_data('spikes') + +# end simulation +p.end() + +remapped_vn_spikes = remap_odd_even(spikes_in_spin, input_size) +remapped_cf_spikes = remap_second_half_descending(spikes_out_spin, output_size) + +simulation_parameters = { + 'runtime': runtime, + 'error_window_size': error_window_size, + 'vn_spikes': remapped_vn_spikes, + 'cf_spikes': remapped_cf_spikes, + 'perfect_eye_pos': perfect_eye_pos, + 'perfect_eye_vel': perfect_eye_vel, + 'vn_size': input_size, + 'cf_size': output_size, + 'gain': gain +} + +# plot the data from the ICubVorEnv pop +plot_results(results_dict=results, simulation_parameters=simulation_parameters, + name="spinngym_icub_vor_test_200_inputs") + +print("Done") diff --git a/examples/icub_vor_examples/icub_vor_venv_test_perfect_motion.py b/examples/icub_vor_examples/icub_vor_venv_test_perfect_motion.py new file mode 100644 index 00000000..403f7b2d --- /dev/null +++ b/examples/icub_vor_examples/icub_vor_venv_test_perfect_motion.py @@ -0,0 +1,107 @@ +import spynnaker8 as p +import spinn_gym as gym + +from pyNN.utility.plotting import Figure, Panel +import matplotlib.pyplot as plt +import numpy as np +import os +from spinn_front_end_common.utilities.globals_variables import get_simulator +from icub_utilities import * + +# Parameter definition +runtime = 3000 +# Build input SSP and output population +input_size = 200 # neurons +output_size = 200 # neurons +gain = 20.0 + +head_pos, head_vel = generate_head_position_and_velocity(1) + +# perfect eye positions and velocities are exactly out of phase with head +perfect_eye_pos = np.concatenate((head_pos[500:], head_pos[:500])) +perfect_eye_vel = np.concatenate((head_vel[500:], head_vel[:500])) + +input_spike_times = [[] for _ in range(input_size)] +# the constant number (0.000031) is the effect of a single spike on the head position +# assert (np.isclose(np.abs(np.diff(head_pos)[0]), no_required_spikes_per_chunk * 0.000031), 0.001) +sub_head_pos = np.diff(head_pos) +head_movement_per_spike = 2 ** (-15) * gain +sub_eye_pos = np.diff(np.concatenate((perfect_eye_pos, [perfect_eye_pos[0]]))) + +# no_required_spikes_per_chunk = 200 +no_required_spikes_per_chunk = np.ceil(np.abs(sub_head_pos[0]) / head_movement_per_spike) + +# build ICubVorEnv model +error_window_size = 10 # ms +npc_limit = 200 # 25 +no_input_cores = int(input_size / npc_limit) +input_spike_times = [[] for _ in range(input_size)] +for ts in range(runtime - 1): + # if 1000 <= ts < 2000: + # continue + sgn = np.sign(sub_eye_pos[ts % 1000]) + spikes_during_chunk = np.ceil(np.abs(sub_eye_pos[ts % 1000]) / head_movement_per_spike) + for i in range(int(spikes_during_chunk)): + x = int(sgn <= 0) + input_spike_times[(i % no_input_cores) * npc_limit + x].append(ts) + +# Setup +p.setup(timestep=1.0) +p.set_number_of_neurons_per_core(p.SpikeSourcePoisson, 50) +p.set_number_of_neurons_per_core(p.SpikeSourceArray, npc_limit) +input_pop = p.Population(input_size, p.SpikeSourceArray(spike_times=input_spike_times)) + +output_pop = p.Population(output_size, p.SpikeSourcePoisson(rate=0)) + +# Instantiate venv +icub_vor_env_model = gym.ICubVorEnv( + head_pos, head_vel, perfect_eye_vel, perfect_eye_pos, error_window_size, + output_size) +icub_vor_env_pop = p.Population(ICUB_VOR_VENV_POP_SIZE, icub_vor_env_model) + +# Set recording for input and output pop (env pop records by default) +input_pop.record('spikes') +output_pop.record('spikes') + +# Input -> ICubVorEnv projection +i2a = p.Projection(input_pop, icub_vor_env_pop, p.AllToAllConnector()) + +# ICubVorEnv -> output, setup live output to the SSP vertex +p.external_devices.activate_live_output_to( + icub_vor_env_pop, output_pop, "CONTROL") + +# Store simulator and run +simulator = get_simulator() +# Run the simulation +p.run(runtime) + +# Get the data from the ICubVorEnv pop +results = retrieve_and_package_results(icub_vor_env_pop, simulator) + +# get the spike data from input and output +spikes_in_spin = input_pop.spinnaker_get_data('spikes') +spikes_out_spin = output_pop.spinnaker_get_data('spikes') + +# end simulation +p.end() + +remapped_vn_spikes = remap_odd_even(spikes_in_spin, input_size) +remapped_cf_spikes = remap_second_half_descending(spikes_out_spin, output_size) + +simulation_parameters = { + 'runtime': runtime, + 'error_window_size': error_window_size, + 'vn_spikes': remapped_vn_spikes, + 'cf_spikes': remapped_cf_spikes, + 'perfect_eye_pos': perfect_eye_pos, + 'perfect_eye_vel': perfect_eye_vel, + 'vn_size': input_size, + 'cf_size': output_size, + 'gain': gain +} + +# plot the data from the ICubVorEnv pop +plot_results(results_dict=results, simulation_parameters=simulation_parameters, + name="spinngym_icub_vor_test_perfect") + +print("Done") diff --git a/examples/icub_vor_examples/pb_cerebellum_tb.py b/examples/icub_vor_examples/pb_cerebellum_tb.py new file mode 100644 index 00000000..5077e007 --- /dev/null +++ b/examples/icub_vor_examples/pb_cerebellum_tb.py @@ -0,0 +1,842 @@ +from __future__ import print_function +import spynnaker8 as sim +import numpy as np +# import logging +import pylab as plt +import matplotlib as mlib + + +from pyNN.utility.plotting import Figure, Panel +from pyNN.random import RandomDistribution, NumpyRNG + +# PAB imports +import traceback +import pandas as pd +import os +import neo +import copy + +# ============================ MAKING THINGS LOOK CONSISTENT ============================ +# ensure we use viridis as the default cmap +plt.viridis() + +# ensure we use the same rc parameters for all matplotlib outputs +mlib.rcParams.update({'font.size': 24}) +mlib.rcParams.update({'errorbar.capsize': 5}) +mlib.rcParams.update({'figure.autolayout': True}) +viridis_cmap = mlib.cm.get_cmap('viridis') + +PREFFERED_ORDER = [ + 'mossy_fibers', + 'climbing_fibers' + 'granule', + 'golgi', + 'purkinje', + 'vn' +] + + +# PAB UTILS +def get_plot_order(for_keys): + # Compute plot order + plot_order = [] + # only focus on keys for pops that have spikes + key_duplicate = list(for_keys) + key_duplicate.sort() + for pref in PREFFERED_ORDER: + for i, key in enumerate(key_duplicate): + if pref in key: + plot_order.append(key) + key_duplicate.pop(i) + + # add remaining keys to the end of plot order + plot_order += key_duplicate + print("Plot order:", plot_order) + return plot_order + + +def color_for_index(index, size, cmap=viridis_cmap): + return cmap(index / (size + 1)) + + +def convert_spiketrains(spiketrains): + """ Converts a list of spiketrains into spynakker7 format + + :param spiketrains: List of SpikeTrains + :rtype: nparray + """ + if len(spiketrains) == 0: + return np.empty(shape=(0, 2)) + + neurons = np.concatenate([ + np.repeat(x.annotations['source_index'], len(x)) + for x in spiketrains]) + spikes = np.concatenate([x.magnitude for x in spiketrains]) + return np.column_stack((neurons, spikes)) + + +def convert_spikes(neo, run=0): + """ Extracts the spikes for run one from a Neo Object + + :param neo: neo Object including Spike Data + :param run: Zero based index of the run to extract data for + :type run: int + :rtype: nparray + """ + if len(neo.segments) <= run: + raise ValueError( + "Data only contains {} so unable to run {}. Note run is the " + "zero based index.".format(len(neo.segments), run)) + return convert_spiketrains(neo.segments[run].spiketrains) + + +def write_short_msg(msg, value): + print("{:40}:{:39}".format(msg, str(value))) + + +def save_figure(plt, name, extensions=(".png",), **kwargs): + for ext in extensions: + write_short_msg("Plotting", name + ext) + plt.savefig(name + ext, **kwargs) + + +fig_folder = "figures/" +# Check if the folders exist +if not os.path.isdir(fig_folder) and not os.path.exists(fig_folder): + os.mkdir(fig_folder) + +# Record SCRIPT start time (wall clock) +start_time = plt.datetime.datetime.now() + +# Starting to record additional parameters + +L_RATE = 2 +H_RATE = 20 + +# cerebellum test bench +runtime = 1000 + +# Synapse parameters +gc_pc_weights = 0.005 +mf_vn_weights = 0.0005 +pc_vn_weights = 0.01 +cf_pc_weights = 0.0 +mf_gc_weights = 0.5 +go_gc_weights = 0.002 +input_weights = 0.0025 +mf_go_weights = 0.1 + +# Network parameters +num_MF_neurons = 100 +num_GC_neurons = 2000 +num_GOC_neurons = 100 +num_PC_neurons = 200 +num_VN_neurons = 200 +num_CF_neurons = 200 + +# Random distribution for synapses delays and weights (MF and GO) +delay_distr = RandomDistribution('uniform', (1.0, 10.0), rng=NumpyRNG(seed=85524)) +weight_distr_MF = RandomDistribution('uniform', (mf_gc_weights * 0.8, mf_gc_weights * 1.2), rng=NumpyRNG(seed=85524)) +weight_distr_GO = RandomDistribution('uniform', + (go_gc_weights * 0.8, go_gc_weights * 1.2), + rng=NumpyRNG(seed=24568)) + +# Post-synapse population +neuron_params = { + "v_thresh": -50, + "v_reset": -70, + "v_rest": -65, + "i_offset": 0 # DC input +} + +all_neurons = { + "mossy_fibers": num_MF_neurons, + "granule": num_GC_neurons, + "golgi": num_GOC_neurons, + "purkinje": num_PC_neurons, + "vn": num_VN_neurons, + "climbing_fibers": num_CF_neurons +} + +all_populations = { + +} + +initial_connectivity = { + +} + +final_connectivity = { + +} + +all_projections = { + +} + +# Learning parameters cos rule +# ==============(MF to VN)============== +min_weight_c = 0 +max_weight_c = 0.005 +pot_alpha_c = 0.001 # this is alpha in the paper +beta_c = 11 +sigma_c = 201 +initial_weight_c = 0.001 # max_weight_c #0.0005 +# initial_weight_c = 0.05 +plastic_delay_c = 4 + +# Learning parameters sin rule +# ==============(GrC to PC)============== +min_weight_s = 0 +max_weight_s = 0.01 +pot_alpha_s = 0.01 +t_peak_s = 100 +initial_weight_s = max_weight_s # 0.0001 +plastic_delay_s = 4 +weight_dist_pfpc = RandomDistribution('uniform', + (initial_weight_s * 0.8, + initial_weight_s * 1.2), + rng=NumpyRNG(seed=24534)) + +sim.setup(timestep=1., min_delay=1, max_delay=15) +global_n_neurons_per_core = 64 +sim.set_number_of_neurons_per_core(sim.SpikeSourcePoisson, global_n_neurons_per_core) +sim.set_number_of_neurons_per_core(sim.SpikeSourceArray, global_n_neurons_per_core) +sim.set_number_of_neurons_per_core(sim.IF_cond_exp, global_n_neurons_per_core) +sim.set_number_of_neurons_per_core(sim.extra_models.IFCondExpCerebellum, global_n_neurons_per_core) + +# Sensorial Activity: input activity from vestibulus (will come from the head IMU, now it is a test bench) +# We simulate the output of the head encoders with a sinusoidal function. Each "sensorial activity" value is derived from the +# head position and velocity. From that value, we generate the mean firing rate of the MF neurons (later this will be an input +# that will come from the robot, through the spinnLink) +# the neurons that are active depend on the value of the sensorial activity. For each a gaussian is created centered on a specific neuron + + +# Prepare variables once at beginning +MAX_AMPLITUDE = 0.8 +RELATIVE_AMPLITUDE = 1.0 +_head_pos = [] +_head_vel = [] + +i = np.arange(0, 1000, 0.001) +for t in i: + desired_speed = -np.cos(t * 2 * np.pi) * MAX_AMPLITUDE * RELATIVE_AMPLITUDE * 2.0 * np.pi + desired_pos = -np.sin(t * 2 * np.pi) * MAX_AMPLITUDE * RELATIVE_AMPLITUDE + _head_pos.append(desired_pos) + _head_vel.append(desired_speed) + +f = plt.figure(1, figsize=(9, 9), dpi=400) +plt.plot(_head_pos) +plt.xlim([0, 1000]) +plt.title("Pre-computed head positions") +plt.tight_layout() +save_figure(plt, os.path.join(fig_folder, "head_positions"), extensions=['.png', ]) +plt.close(f) + +f = plt.figure(1, figsize=(9, 9), dpi=400) +plt.plot(_head_vel) +plt.xlim([0, 1000]) +plt.title("Pre-computed head velocities") +plt.tight_layout() +save_figure(plt, os.path.join(fig_folder, "head_velocities"), extensions=['.png', ]) +plt.close(f) + +normalised_head_pos = (np.asarray(_head_pos) + 0.8) / 1.6 +normalised_head_vel = (np.asarray(_head_vel) + 0.8 * 2 * np.pi) / (1.6 * 2 * np.pi) + +f = plt.figure(1, figsize=(9, 9), dpi=400) +plt.plot(((np.asarray(_head_pos) + 0.8) / 1.6)) +plt.xlim([0, 1000]) +plt.title("Head positions") +plt.xlabel("Time (ms)") +plt.ylabel("Proportion of max") +plt.tight_layout() +save_figure(plt, os.path.join(fig_folder, "head_positions_processed"), extensions=['.png', '.pdf']) +plt.close(f) + +f = plt.figure(1, figsize=(9, 9), dpi=400) +plt.plot(((np.asarray(_head_vel) + 0.8 * 2 * np.pi) / (1.6 * 2 * np.pi))) +plt.xlim([0, 1000]) +plt.title("Head velocities") +plt.ylabel("Proportion of max") +plt.xlabel("Time (ms)") +plt.tight_layout() +save_figure(plt, os.path.join(fig_folder, "head_velocities_processed"), extensions=['.png', '.pdf']) +plt.close(f) + +np.savetxt("normalised_head_positions.csv", normalised_head_pos, delimiter=",") +np.savetxt("normalised_head_velocities.csv", normalised_head_vel, delimiter=",") + + +def sensorial_activity(pt): + """ + + :param pt: pt is a single point in time at which we measure the head encoder's output + :return: + """ + + # Head position and velocity seem to be retrieve from a look-up table then updated + # single point over time + head_pos = _head_pos[pt] + head_vel = _head_vel[pt] + + head_pos = ((head_pos + 0.8) / 1.6) + head_vel = ((head_vel + 0.8 * 2 * np.pi) / (1.6 * 2 * np.pi)) + + if head_pos > 1.0: + head_pos = 1.0 + elif head_pos < 0.0: + head_pos = 0.0 + if head_vel > 1.0: + head_vel = 1.0 + elif head_vel < 0.0: + head_vel = 0.0 + + min_rate = 0.0 + max_rate = 600.0 + sigma = 0.02 + MF_pos_activity = np.zeros((50)) + MF_vel_activity = np.zeros((50)) + + # generate gaussian distributions around the neuron tuned to a given sensorial activity + for i in range(50): + mean = float(i) / 50.0 + 0.01 + gaussian = np.exp(-((head_pos - mean) * (head_pos - mean)) / (2.0 * sigma * sigma)) + MF_pos_activity[i] = min_rate + gaussian * (max_rate - min_rate) + + for i in range(50): + mean = float(i) / 50.0 + 0.01 + gaussian = np.exp(-((head_vel - mean) * (head_vel - mean)) / (2.0 * sigma * sigma)) + MF_vel_activity[i] = min_rate + gaussian * (max_rate - min_rate) + + sa_mean_freq = np.concatenate((MF_pos_activity, MF_vel_activity)) + out = [sa_mean_freq, head_pos, head_vel] + return out + + +# Error Activity: error from eye and head encoders +def error_activity(error_): + # min_rate = 1.0 + # max_rate = 25.0 + # + # low_neuron_ID_threshold = abs(error_) * 100.0 + # up_neuron_ID_threshold = low_neuron_ID_threshold - 100.0 + IO_agonist = np.zeros((100)) + IO_antagonist = np.zeros((100)) + # + # rate = [] + # for i in range (100): + # if(i < up_neuron_ID_threshold): + # rate.append(max_rate) + # elif(i=0.0: + # IO_agonist[0:100]=min_rate + # IO_antagonist=rate + # else: + # IO_antagonist[0:100]=min_rate + # IO_agonist=rate + IO_agonist[:] = H_RATE + IO_antagonist[:] = L_RATE + + ea_rate = np.concatenate((IO_agonist, IO_antagonist)) + + return ea_rate + + +def process_VN_spiketrains(VN_spikes, t_start): + total_spikes = 0 + for spiketrain in VN_spikes.segments[0].spiketrains: + s = spiketrain.as_array()[np.where(spiketrain.as_array() >= t_start)[0]] + total_spikes += len(s) + + return total_spikes + + +############################################################################### +# ============================ Create populations ============================ +############################################################################## + +# Create MF population - fake input population that will be substituted by external input from robot + +MF_population = sim.Population(num_MF_neurons, # number of sources + sim.SpikeSourcePoisson, # source type + # {'rate': sa_mean_freq}, # source spike times + {'rate': sensorial_activity(0)[0]}, # source spike times + label="MFLayer" # identifier + ) + +all_populations["mossy_fibers"] = MF_population + +# Create GOC population +GOC_population = sim.Population(num_GOC_neurons, sim.IF_cond_exp(), label='GOCLayer') +all_populations["golgi"] = GOC_population + +# create PC population +PC_population = sim.Population(num_PC_neurons, # number of neurons + sim.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model + label="Purkinje Cell" # identifier + ) +all_populations["purkinje"] = PC_population + +# create VN population +VN_population = sim.Population(num_VN_neurons, # number of neurons + sim.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model + label="Vestibular Nuclei" # identifier + ) +all_populations["vn"] = VN_population + +# Create GrC population +GC_population = sim.Population(num_GC_neurons, sim.IF_curr_exp(), label='GCLayer') +all_populations["granule"] = GC_population + +# generate fake error (it should be calculated from sensorial activity in error activity, +# but we skip it and just generate an error from -1.5 to 1.5) +err = -0.7 # other values to test: -0.3 0 0.3 0.7 + +# Create CF population - fake input population that will be substituted by external input from robot +CF_population = sim.Population(num_CF_neurons, # number of sources + sim.SpikeSourcePoisson, # source type + # {'rate': sa_mean_freq}, # source spike times + {'rate': error_activity(err)}, # source spike times + label="CFLayer" # identifier + ) +all_populations["climbing_fibers"] = CF_population + +############################################################################### +# ============================ Create connections ============================ +############################################################################## + +# Create MF-GO connections +mf_go_connections = sim.Projection(MF_population, + GOC_population, + sim.OneToOneConnector(), + sim.StaticSynapse(delay=delay_distr, weight=mf_go_weights), + receptor_type='excitatory') +all_projections["mf_goc"] = mf_go_connections + +# Create MF-GC and GO-GC connections +float_num_MF_neurons = float(num_MF_neurons) + +list_GOC_GC = [] +list_MF_GC = [] +list_GOC_GC_2 = [] +# projections to subpopulations https://github.com/SpiNNakerManchester/sPyNNaker8/issues/168) +for i in range(num_MF_neurons): + GC_medium_index = int(round((i / float_num_MF_neurons) * num_GC_neurons)) + GC_lower_index = GC_medium_index - 40 + GC_upper_index = GC_medium_index + 60 + + if (GC_lower_index < 0): + GC_lower_index = 0 + + elif (GC_upper_index > num_GC_neurons): + GC_upper_index = num_GC_neurons + + for j in range(GC_medium_index - GC_lower_index): + list_GOC_GC.append( + (i, GC_lower_index + j, + # go_gc_weights, 1) + weight_distr_GO.next(), delay_distr.next()) + ) + + for j in range(GC_medium_index + 20 - GC_medium_index): + list_MF_GC.append( + (i, GC_medium_index + j, + # mf_gc_weights, 1) + weight_distr_MF.next(), delay_distr.next()) + ) + + for j in range(GC_upper_index - GC_medium_index - 20): + list_GOC_GC_2.append( + (i, GC_medium_index + 20 + j, + # go_gc_weights, 1) + weight_distr_GO.next(), delay_distr.next()) + ) + +GO_GC_con1 = sim.Projection(GOC_population, + GC_population, + sim.FromListConnector(list_GOC_GC), + receptor_type='inhibitory') # this should be inhibitory +all_projections["goc_grc_1"] = GO_GC_con1 + +MF_GC_con2 = sim.Projection(MF_population, + GC_population, + sim.FromListConnector(list_MF_GC), + receptor_type='excitatory') + +all_projections["mf_grc"] = MF_GC_con2 + +GO_GC_con3 = sim.Projection(GOC_population, + GC_population, + sim.FromListConnector(list_GOC_GC_2), + receptor_type='inhibitory') +all_projections["goc_grc_2"] = GO_GC_con3 + +# Create PC-VN connections +pc_vn_connections = sim.Projection(PC_population, + VN_population, + sim.OneToOneConnector(), + # receptor_type='GABA', # Should these be inhibitory? + synapse_type=sim.StaticSynapse(delay=delay_distr, weight=pc_vn_weights), + receptor_type='inhibitory') +all_projections["pc_vn"] = pc_vn_connections + +# Create MF-VN learning rule - cos +mfvn_plas = sim.STDPMechanism( + timing_dependence=sim.extra_models.TimingDependenceMFVN(beta=beta_c, + sigma=sigma_c), + weight_dependence=sim.extra_models.WeightDependenceMFVN(w_min=min_weight_c, + w_max=max_weight_c, + pot_alpha=pot_alpha_c), + weight=initial_weight_c, delay=delay_distr) + +# Create MF to VN connections +mf_vn_connections = sim.Projection( + MF_population, VN_population, sim.AllToAllConnector(), # Needs mapping as FromListConnector to make efficient + synapse_type=mfvn_plas, + receptor_type="excitatory") +all_projections["mf_vn"] = mf_vn_connections + +# Create projection from PC to VN -- replaces "TEACHING SIGNAL" +pc_vn_connections = sim.Projection( + PC_population, VN_population, sim.OneToOneConnector(), + sim.StaticSynapse(weight=0.0, delay=1.0), + receptor_type="excitatory") # "TEACHING SIGNAL" +all_projections["pc_vn_teaching"] = pc_vn_connections + +# create PF-PC learning rule - sin +pfpc_plas = sim.STDPMechanism( + timing_dependence=sim.extra_models.TimingDependencePFPC(t_peak=t_peak_s), + weight_dependence=sim.extra_models.WeightDependencePFPC(w_min=min_weight_s, + w_max=max_weight_s, + pot_alpha=pot_alpha_s), + weight=initial_weight_s, + delay=delay_distr +) + +# Create PF-PC connections +pf_pc_connections = sim.Projection( + GC_population, PC_population, sim.AllToAllConnector(), + synapse_type=pfpc_plas, + receptor_type="excitatory") +all_projections["pf_pc"] = pf_pc_connections + +# Create IO-PC connections. This synapse with "receptor_type=COMPLEX_SPIKE" propagates the learning signals that drive the plasticity mechanisms in GC-PC synapses +cf_pc_connections = sim.Projection(CF_population, + PC_population, + sim.OneToOneConnector(), + # receptor_type='COMPLEX_SPIKE', + synapse_type=sim.StaticSynapse(delay=1.0, weight=cf_pc_weights), + receptor_type='excitatory') +all_projections["cf_pc"] = cf_pc_connections + +# lif_pop = sim.Population(1024, sim.IF_curr_exp(), label='pop_lif') +# +# out_pop = sim.Population(128, sim.IF_curr_exp(), label='pop_out') + +# sim.run(1000) + +# sim.Projection( +# lif_pop, out_pop, sim.OneToOneConnector(), +# synapse_type=sim.StaticSynapse(weight=0.1)) +# +# +# # live output of the input vertex (retina_pop) to the first pynn population (lif_pop) +# sim.external_devices.activate_live_output_to(out_pop,retina_pop) +# +# +# recordings and simulations +# lif_pop.record(["spikes"]) +# +# out_pop.record(["spikes"]) +# +# +# +# sim.run(10) +# +# sim.end() + +# ============================ Set up recordings ============================ + +MF_population.record(['spikes']) +CF_population.record(['spikes']) +GC_population.record('all') +# GOC_population.record(['spikes']) +GOC_population.record('all') +VN_population.record('all') # VN_population.record(['spikes']) +# PC_population.record(['spikes']) +PC_population.record('all') + +# ============================ Run simulation ============================ + +samples_in_repeat = 99 +sample_time = 10 +repeats = 1 +total_runtime = 0 +VN_transfer_func = [] + +print("=" * 80) +print("Running simulation for", runtime, " ms split into", samples_in_repeat, "chunks.") +all_spikes_first_trial = {} +# Record simulation start time (wall clock) +sim_start_time = plt.datetime.datetime.now() +for i in range(samples_in_repeat): + sim.run(sample_time) + + VN_spikes = VN_population.get_data('spikes') + VN_transfer_func.append(process_VN_spiketrains(VN_spikes, total_runtime)) + + total_runtime += sample_time + + print(total_runtime) + + MF_population.set(rate=sensorial_activity(total_runtime)[0]) + +# sim.run(runtime*0.4) +# +# CF_rates=[] +# lower_rate=100*[L_RATE] +# upper_rate=100*[H_RATE] +# CF_rates.extend(lower_rate) +# CF_rates.extend(upper_rate) +# CF_population.set(rate=CF_rates) +# +# sim.run(runtime*0.4) +# +# CF_rates=[] +# lower_rate=100*[H_RATE] +# upper_rate=100*[L_RATE] +# CF_rates.extend(lower_rate) +# CF_rates.extend(upper_rate) +# CF_population.set(rate=CF_rates) +# +# sim.run(runtime*0.2) +# +# CF_rates=[] +# lower_rate=100*[H_RATE] +# upper_rate=100*[L_RATE] +# CF_rates.extend(lower_rate) +# CF_rates.extend(upper_rate) +# CF_population.set(rate=CF_rates) +end_time = plt.datetime.datetime.now() +total_time = end_time - start_time +sim_total_time = end_time - sim_start_time + +total_runtime = runtime * repeats + +# ============================ Retrieving data from simulation ============================ + +MF_spikes = MF_population.get_data('spikes') +CF_spikes = CF_population.get_data('spikes') +GC_spikes = GC_population.get_data('all') +GOC_spikes = GOC_population.get_data('spikes') +VN_spikes = VN_population.get_data('all') # VN_population.get_data('spikes') +PC_spikes = PC_population.get_data('spikes') + +mfvn_weights = mf_vn_connections.get('weight', 'list', with_address=False) +pfpc_weights = pf_pc_connections.get('weight', 'list', with_address=False) + +# Retrieve recordings +all_spikes = {} +for label, pop in all_populations.items(): + if pop is not None: + print("Retrieving recordings for ", label, "...") + all_spikes[label] = pop.get_data(['spikes']) +other_recordings = {} +for label, pop in all_populations.items(): + if label in ["mossy_fibers", "climbing_fibers"]: + continue + print("Retrieving recordings for ", label, "...") + other_recordings[label] = {} + + other_recordings[label]['current'] = np.array( + pop.get_data(['gsyn_inh']).filter(name='gsyn_inh'))[0].T + + other_recordings[label]['gsyn'] = np.array( + pop.get_data(['gsyn_exc']).filter(name='gsyn_exc'))[0].T + + other_recordings[label]['v'] = np.array( + pop.get_data(['v']).segments[0].filter(name='v'))[0].T + +# Retrieve final network connectivity +try: + final_connectivity = {} + for label, p in all_projections.items(): + if p is None: + print("Projection", label, "is not implemented!") + continue + print("Retrieving connectivity for projection ", label, "...") + try: + conn = \ + np.array(p.get(('weight', 'delay'), + format="list")._get_data_items()) + except Exception as e: + print("Careful! Something happened when retrieving the " + "connectivity:", e, "\nRetrying...") + conn = \ + np.array(p.get(('weight', 'delay'), format="list")) + + conn = np.array(conn.tolist()) + final_connectivity[label] = conn +except: + # This simulator might not support the way this is done + final_connectivity = [] + traceback.print_exc() + +sim.end() +print("job done") +# Report time taken +print("Total time elapsed -- " + str(total_time)) +# ============================ Plotting some stuff ============================ +# ============================ PAB ANALYSIS ============================ + +# Compute plot order +plot_order = get_plot_order(all_spikes.keys()) +n_plots = float(len(plot_order)) + +# Check if using neo blocks +neo_all_spikes = {} +for pop, potential_neo_block in all_spikes.items(): + if isinstance(potential_neo_block, neo.Block): + # make a copy of the spikes dict + neo_all_spikes[pop] = potential_neo_block + all_spikes[pop] = convert_spikes(potential_neo_block) + +# Report useful parameters +print("=" * 80) +print("Analysis report") +print("-" * 80) +print("Current time", + plt.datetime.datetime.now().strftime("%H:%M:%S on %d.%m.%Y")) +# Report number of neurons +print("=" * 80) +print("Number of neurons in each population") +print("-" * 80) +for pop in plot_order: + print("\t{:20} -> {:10} neurons".format(pop, all_neurons[pop])) + +# Report weights values +print("Average weight per projection") +print("-" * 80) +conn_dict = {} +for key in final_connectivity: + # Connection holder annoyance here: + conn = np.asarray(final_connectivity[key]) + if final_connectivity[key] is None or conn.size == 0: + print("Skipping analysing connection", key) + continue + conn_exists = True + if len(conn.shape) == 1 or conn.shape[1] != 4: + try: + x = np.concatenate(conn) + conn = x + except: + traceback.print_exc() + names = [('source', 'int_'), + ('target', 'int_'), + ('weight', 'float_'), + ('delay', 'float_')] + useful_conn = np.zeros((conn.shape[0], 4), dtype=np.float) + for i, (n, _) in enumerate(names): + useful_conn[:, i] = conn[n].astype(np.float) + final_connectivity[key] = useful_conn.astype(np.float) + conn = useful_conn.astype(np.float) + conn_dict[key] = conn + mean = np.mean(conn[:, 2]) + print("{:27} -> {:4.6f} uS".format( + key, mean)) + +print("Average Delay per projection") +print("-" * 80) +for key in final_connectivity: + conn = conn_dict[key] + mean = np.mean(conn[:, 3]) + print("{:27} -> {:4.2f} ms".format( + key, mean)) + +print("Plotting spiking raster plot for all populations") +f, axes = plt.subplots(len(all_spikes.keys()), 1, + figsize=(14, 20), sharex=True, dpi=400) +for index, pop in enumerate(plot_order): + curr_ax = axes[index] + # spike raster + _times = all_spikes[pop][:, 1] + _ids = all_spikes[pop][:, 0] + + curr_ax.scatter(_times, + _ids, + color=viridis_cmap(index / (n_plots + 1)), + s=.5, rasterized=True) + curr_ax.set_title(pop) +plt.xlabel("Time (ms)") +# plt.suptitle((use_display_name(simulator)+"\n") +f.tight_layout() +save_figure(plt, os.path.join(fig_folder, "raster_plots"), + extensions=['.png', '.pdf']) +plt.close(f) + +for proj, conn in final_connectivity.items(): + f = plt.figure(1, figsize=(9, 9), dpi=400) + plt.hist(conn[:, 2], bins=20) + plt.title(proj) + plt.xlabel("Weight") + plt.ylabel("Count") + save_figure(plt, os.path.join(fig_folder, "{}_weight_histogram".format(proj)), + extensions=['.png', ]) + plt.close(f) + +F = Figure( + Panel(MF_spikes.segments[0].spiketrains, + yticks=True, markersize=2, xlim=(0, total_runtime), + xlabel='MF_spikes'), + Panel(CF_spikes.segments[0].spiketrains, + yticks=True, markersize=2, xlim=(0, total_runtime), + xlabel='CF_spikes'), + Panel(GC_spikes.segments[0].spiketrains, + yticks=True, markersize=2, xlim=(0, total_runtime), + xlabel='GC_spikes'), + Panel(GOC_spikes.segments[0].spiketrains, + yticks=True, markersize=2, xlim=(0, total_runtime), + xlabel='GOC_spikes'), + Panel(PC_spikes.segments[0].spiketrains, + yticks=True, markersize=2, xlim=(0, total_runtime), + xlabel='PC_spikes'), + Panel(VN_spikes.segments[0].spiketrains, + yticks=True, markersize=2, xlim=(0, total_runtime), + xlabel='VN_spikes'), + Panel(VN_spikes.segments[0].filter(name='gsyn_inh')[0], + ylabel="Membrane potential (mV)", yticks=True, xlim=(0, total_runtime)) +) +save_figure(plt, os.path.join(fig_folder, "collections"), + extensions=['.png', ]) +# plt.show(block=False) + +plt.figure() +plt.plot(mfvn_weights, + label='mf-vn weights (init: {})'.format(initial_weight_c)) +plt.title("mfvn_weights") +plt.legend() +save_figure(plt, os.path.join(fig_folder, "mfvn_weights"), + extensions=['.png', ]) + +plt.figure() +plt.title("pfpc_weights") +plt.plot(pfpc_weights, color='orange', + label='pf-pc weights (init: {})'.format(initial_weight_s)) +plt.legend() +save_figure(plt, os.path.join(fig_folder, "pfpc_weights"), + extensions=['.png', ]) + +print(VN_transfer_func) +plt.figure() +plt.plot(VN_transfer_func) +plt.title("vn_transfer_function") +save_figure(plt, os.path.join(fig_folder, "VN_transfer_func"), + extensions=['.png', ]) + +# plt.show() diff --git a/examples/icub_vor_examples/pb_single_purkinje_cell_test.pysingle_purkinje_cell_test.py b/examples/icub_vor_examples/pb_single_purkinje_cell_test.pysingle_purkinje_cell_test.py new file mode 100644 index 00000000..ed832259 --- /dev/null +++ b/examples/icub_vor_examples/pb_single_purkinje_cell_test.pysingle_purkinje_cell_test.py @@ -0,0 +1,98 @@ +from __future__ import print_function +import spynnaker8 as p +import numpy +import math +import unittest +from pyNN.utility.plotting import Figure, Panel +import matplotlib.pyplot as plt + +p.setup(1, min_delay=1, max_delay=15) # simulation timestep (ms) +runtime = 500 + +# Post-synapse population +neuron_params = { + "v_thresh": -50, + "v_reset": -70, + "v_rest": -65, + "i_offset": 0 # DC input +} + +# Learning parameters +min_weight = 0 +max_weight = 0.1 +pot_alpha = 0.01 +t_peak = 100 +initial_weight = 0.05 +plastic_delay = 4 + +purkinje_cell = p.Population(1, # number of neurons + p.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model + label="Purkinje Cell" # identifier + ) + +# Spike source to send spike via synapse +spike_times = [50, 150, 270] + +granular_cell = p.Population(1, # number of sources + p.SpikeSourceArray, # source type + {'spike_times': spike_times}, # source spike times + label="src1" # identifier + ) + +# Spike source to send spike via synapse from climbing fibre +spike_times_2 = [100, 104, 107, 246] +climbing_fibre = p.Population(1, # number of sources + p.SpikeSourceArray, # source type + {'spike_times': spike_times_2}, # source spike times + label="src2" # identifier + ) + +# Create projection from GC to PC +pfpc_plas = p.STDPMechanism( + timing_dependence=p.extra_models.TimingDependencePFPC(t_peak=t_peak), + weight_dependence=p.extra_models.WeightDependencePFPC(w_min=min_weight, + w_max=max_weight, + pot_alpha=pot_alpha), + weight=initial_weight, delay=plastic_delay) + +synapse_pfpc = p.Projection( + granular_cell, purkinje_cell, p.AllToAllConnector(), + synapse_type=pfpc_plas, receptor_type="excitatory") + +# Create projection from CF to PC +synapse = p.Projection( + climbing_fibre, purkinje_cell, p.OneToOneConnector(), + p.StaticSynapse(weight=0.0, delay=1), receptor_type="excitatory") + +granular_cell.record('spikes') +climbing_fibre.record('spikes') +purkinje_cell.record("all") + +p.run(runtime) + +granluar_cell_spikes = granular_cell.get_data('spikes') +climbing_fibre_spikes = climbing_fibre.get_data('spikes') +purkinje_data = purkinje_cell.get_data() + +pf_weights = synapse_pfpc.get('weight', 'list', with_address=False) +print(pf_weights) + +# Plot +F = Figure( + # plot data for postsynaptic neuron + Panel(granluar_cell_spikes.segments[0].spiketrains, + yticks=True, markersize=2, xlim=(0, runtime)), + Panel(climbing_fibre_spikes.segments[0].spiketrains, + yticks=True, markersize=2, xlim=(0, runtime)), + Panel(purkinje_data.segments[0].filter(name='v')[0], + ylabel="Membrane potential (mV)", + data_labels=[purkinje_cell.label], yticks=True, xlim=(0, runtime)), + Panel(purkinje_data.segments[0].filter(name='gsyn_exc')[0], + ylabel="gsyn excitatory (mV)", + data_labels=[purkinje_cell.label], yticks=True, xlim=(0, runtime)), + Panel(purkinje_data.segments[0].spiketrains, + yticks=True, markersize=2, xlim=(0, runtime)), +) + +plt.show() +p.end() diff --git a/examples/icub_vor_examples/readme.md b/examples/icub_vor_examples/readme.md new file mode 100644 index 00000000..73c929b7 --- /dev/null +++ b/examples/icub_vor_examples/readme.md @@ -0,0 +1,13 @@ +# Project's resources: + +### Telluride implementation of STDP for cerebellar model on pyNN: + +https://github.com/neworderofjamie/jamie_telluride_2016/tree/master/cerebellum/cerebellum + +### Network model (NEST) + +https://github.com/EduardoRosLab/VOR_in_neurorobotics + +### Neurons and synapse models (NEST) + +https://github.com/jgarridoalcazar/SpikingCerebellum diff --git a/examples/icub_vor_examples/receptive_fields_for_motion.py b/examples/icub_vor_examples/receptive_fields_for_motion.py new file mode 100644 index 00000000..93170c0b --- /dev/null +++ b/examples/icub_vor_examples/receptive_fields_for_motion.py @@ -0,0 +1,423 @@ +#!usr/bin/python + +import socket +import spynnaker8 as sim +import numpy as np +#import logging +import matplotlib.pyplot as plt +from decode_events import* +from functions import* +import yarp + +from pacman.model.constraints.key_allocator_constraints import FixedKeyAndMaskConstraint +from pacman.model.graphs.application import ApplicationSpiNNakerLinkVertex +from pacman.model.routing_info import BaseKeyAndMask +from spinn_front_end_common.abstract_models.abstract_provides_n_keys_for_partition import AbstractProvidesNKeysForPartition +from spinn_front_end_common.abstract_models.abstract_provides_outgoing_partition_constraints import AbstractProvidesOutgoingPartitionConstraints +from spinn_utilities.overrides import overrides +from spinn_front_end_common.abstract_models.abstract_provides_incoming_partition_constraints import AbstractProvidesIncomingPartitionConstraints +from pacman.executor.injection_decorator import inject_items +from pacman.operations.routing_info_allocator_algorithms.malloc_based_routing_allocator.utils import get_possible_masks +from spinn_front_end_common.utility_models.command_sender_machine_vertex import CommandSenderMachineVertex + +from spinn_front_end_common.abstract_models \ + import AbstractSendMeMulticastCommandsVertex +from spinn_front_end_common.utility_models.multi_cast_command \ + import MultiCastCommand + + +from pyNN.utility import Timer +from pyNN.utility.plotting import Figure, Panel +from pyNN.random import RandomDistribution, NumpyRNG + +from spynnaker.pyNN.models.neuron.plasticity.stdp.common import plasticity_helpers + +# yarp.Network.init() + +NUM_NEUR_IN = 1024 #1024 # 2x240x304 mask -> 0xFFFE0000 +MASK_IN = 0xFFFFFC00 #0xFFFFFC00 +NUM_NEUR_OUT = 1024 +MASK_OUT =0xFFFFFFFC + +class ICUBInputVertex( + ApplicationSpiNNakerLinkVertex, + AbstractProvidesOutgoingPartitionConstraints, + AbstractProvidesIncomingPartitionConstraints, + AbstractSendMeMulticastCommandsVertex): + + def __init__(self, spinnaker_link_id, board_address=None, + constraints=None, label=None): + + ApplicationSpiNNakerLinkVertex.__init__( + self, n_atoms=NUM_NEUR_IN, spinnaker_link_id=spinnaker_link_id, + board_address=board_address, label=label) + + AbstractProvidesNKeysForPartition.__init__(self) + AbstractProvidesOutgoingPartitionConstraints.__init__(self) + AbstractSendMeMulticastCommandsVertex.__init__(self) + + @overrides(AbstractProvidesOutgoingPartitionConstraints. + get_outgoing_partition_constraints) + def get_outgoing_partition_constraints(self, partition): + return [FixedKeyAndMaskConstraint( + keys_and_masks=[BaseKeyAndMask( + base_key=0, #upper part of the key, + mask=MASK_IN)])] + #keys, i.e. neuron addresses of the input population that sits in the ICUB vertex, + + @inject_items({"graph_mapper": "MemoryGraphMapper"}) + @overrides(AbstractProvidesIncomingPartitionConstraints. + get_incoming_partition_constraints, + additional_arguments=["graph_mapper"]) + def get_incoming_partition_constraints(self, partition, graph_mapper): + if isinstance(partition.pre_vertex, CommandSenderMachineVertex): + return [] + index = graph_mapper.get_machine_vertex_index(partition.pre_vertex) + vertex_slice = graph_mapper.get_slice(partition.pre_vertex) + mask = get_possible_masks(vertex_slice.n_atoms)[0] + key = (0x1000 + index) << 16 + return [FixedKeyAndMaskConstraint( + keys_and_masks=[BaseKeyAndMask(key, mask)])] + + @property + @overrides(AbstractSendMeMulticastCommandsVertex.start_resume_commands) + def start_resume_commands(self): + return [MultiCastCommand( + key=0x80000000, payload=0, repeat=5, delay_between_repeats=100)] + + @property + @overrides(AbstractSendMeMulticastCommandsVertex.pause_stop_commands) + def pause_stop_commands(self): + return [MultiCastCommand( + key=0x40000000, payload=0, repeat=5, delay_between_repeats=100)] + + @property + @overrides(AbstractSendMeMulticastCommandsVertex.timed_commands) + def timed_commands(self): + return [] + +def convert_data_mapping(x, y, down_sample_x, down_sample_y): + if simulate: + x /= (304 / down_sample_x) + y /= (240 / down_sample_y) + address = (y * 304) + x + else: + address = (int(y) << 12) + (int(x) << 1) + 1 + return int(address) + +def convert_data(data): + converted_data = [[] for i in range(304*240)] + for item in data: + converted_data[convert_data_mapping(item[2], item[3], width, length)].append(item[0]*1000) + return converted_data + +def convert_pixel_mapping(pixel, down_sample_x, down_sample_y): + x = pixel % 304 + y = (pixel - x) / 304 + if simulate: + x /= (304 / down_sample_x) + y /= (240 / down_sample_y) + address = (y * down_sample_x) + x + else: + address = (y << 12) + (x << 1) + 1 + return address + +def map_neurons_to_field(length, x_segments, y_segments, scale_down, layers, x_size=304, y_size=240, central_x=304, + central_y=240): + # base-filter = width x (dimension / segments) + # Y*8 E*2 X*9 P*1 + # x_segments /= 2 + # y_segments /= 2 + field_size_x = [] + field_size_y = [] + # define the field size for each layer + for i in range(layers): + field_size_length_x = length * (scale_down ** layers) + field_size_width_x = (x_size / x_segments) * (scale_down ** layers) + field_size_x.append([field_size_length_x, field_size_width_x]) + field_size_length_y = length * (scale_down ** layers) + field_size_width_y = (y_size / y_segments) * (scale_down ** layers) + field_size_y.append([field_size_length_y, field_size_width_y]) + + # map the field size to real pixels + pixel_mapping = [[[[-1, -1] for x in range(y_size)] for y in range(x_size)] for i in range(layers + 1)] + field_size = [[[0 for i in range(y_segments)] for j in range(x_segments)] for k in range(layers+1)] + x_border = int(x_size - central_x) # / 2 + y_border = int(y_size - central_y) # / 2 + for x in range(central_x / 2): + for y in range(central_y / 2): + x_segment = int(x / ((x_size - (x_border)) / x_segments)) + y_segment = int(y / ((y_size - (y_border)) / y_segments)) + pixel_mapping[layers][(x_size - (x_border / 2)) - x -1][y + y_border] = [(x_segments - 1) - x_segment, y_segment] + pixel_mapping[layers][x + x_border][(y_size - (y_border / 2)) - y - 1] = [x_segment, (y_segments - 1) - y_segment] + pixel_mapping[layers][(x_size - (x_border / 2)) - x - 1][(y_size - (y_border / 2)) - y - 1] = [(x_segments - 1) - x_segment, (y_segments - 1) - y_segment] + pixel_mapping[layers][x + x_border][y + y_border] = [x_segment, y_segment] + # for layer in range(layers): + # x_border = int(x_size - (x_size * (scale_down ** layer))) # / 2 + # y_border = int(y_size - (y_size * (scale_down ** layer))) # / 2 + # if x_border < x_size / 2 or y_border < y_size / 2: + # for x in range(0, (x_size / 2) - x_border): + # for y in range(0, (y_size / 2) - y_border): + # if x < length * (scale_down ** layer) or y < length * (scale_down ** layer): + # x_segment = int(x / ((x_size - (x_border * 2)) / x_segments)) + # y_segment = int(y / ((y_size - (y_border * 2)) / y_segments)) + # pixel_mapping[layer][x + x_border][y + y_border] = \ + # [x_segment, y_segment] + # field_size[layer][x_segment][y_segment] += 1 + # pixel_mapping[layer][((x_size - 1) - x_border) - x][((y_size - 1) - y_border) - y] = \ + # [(x_segments - 1) - x_segment, (y_segments - 1) - y_segment] + # field_size[layer][(x_segments - 1) - x_segment][(y_segments - 1) - y_segment] += 1 + # pixel_mapping[layer][x + x_border][((y_size - 1) - y_border) - y] = \ + # [x_segment, (y_segments - 1) - y_segment] + # field_size[layer][x_segment][(y_segments - 1) - y_segment] += 1 + # pixel_mapping[layer][((x_size - 1) - x_border) - x][y + y_border] = \ + # [(x_segments - 1) - x_segment, y_segment] + # field_size[layer][(x_segments - 1) - x_segment][y_segment] += 1 + # # print x, x_segment, x_segments, y, y_segment, y_segments + # # print x, y + # print "finished layer", layer, "with border", x_border, y_border + + print "done mapping" + return pixel_mapping, field_size + +def convert_xy_field_to_id(field_x, field_y, width, length): + # receptive_fields = width * 2 + length * 2 - 2 + id = (field_y * width) + field_x + return id + +def map_to_from_list(mapping, width, length, scale_down, pixel_weight=5, x_size=304, y_size=240, motor_weight=1.5): + # motor_weight *= width * length + mapping, field_size = mapping + layers = len(mapping) + print "layer", layers, "width", width, "length", length + from_list_connections = [[] for i in range(layers)] + motor_conn = [] + for layer in range(layers): + motor_control_e = [] + motor_control_i = [] + for x in range(x_size): + for y in range(y_size): + if mapping[layer][x][y][0] != -1: + if layer < layers - 1: + weight = pixel_weight / float(field_size[layer][mapping[layer][x][y][0]][mapping[layer][x][y][1]]) + else: + weight = pixel_weight #/ 16. + connection = [convert_pixel_mapping(x + (304 * y), width, length), + convert_xy_field_to_id(mapping[layer][x][y][0], mapping[layer][x][y][1], width, length), + weight, + 1] + if connection not in from_list_connections: + from_list_connections[layer].append(connection) + print x, y, x + (304 * y), convert_pixel_mapping(x + (304 * y), width, length), convert_xy_field_to_id(mapping[layer][x][y][0], mapping[layer][x][y][1], width, length) + if convert_pixel_mapping(x + (304 * y), width, length) >= 304*240 or convert_xy_field_to_id(mapping[layer][x][y][0], mapping[layer][x][y][1], width, length) >= width*length: + print "fucked" + for connection in from_list_connections[layer]: + if connection[1] % width < width / 2: + if [connection[1], 0, motor_weight, 1] not in motor_control_e: + motor_control_e.append([connection[1], 0, motor_weight, 1]) + motor_control_i.append([connection[1], 1, motor_weight, 1]) + if connection[1] % width > width / 2: + if [connection[1], 1, motor_weight, 1] not in motor_control_e: + motor_control_e.append([connection[1], 1, motor_weight, 1]) + motor_control_i.append([connection[1], 0, motor_weight, 1]) + if connection[1] / width < length / 2: + if [connection[1], 2, motor_weight, 1] not in motor_control_e: + motor_control_e.append([connection[1], 2, motor_weight, 1]) + motor_control_i.append([connection[1], 3, motor_weight, 1]) + if connection[1] / width > length / 2: + if [connection[1], 3, motor_weight, 1] not in motor_control_e: + motor_control_e.append([connection[1], 3, motor_weight, 1]) + motor_control_i.append([connection[1], 2, motor_weight, 1]) + motor_conn.append([motor_control_e, motor_control_i]) + print "created connections" + return from_list_connections, motor_conn + +def split_the_from_list(input, output, from_list, receptor_type="excitatory", max_conn=255): + # from_list_segments = [from_list[x:x + max_conn] for x in xrange(0, len(from_list), max_conn)] + # file_name = "connections.txt" + # with open(file_name, 'w') as f: + # for segment in from_list_segments: + # connections_file = open(file_name, "w") + # for connection in segment: + # for item in connection: + # f.write("%s " % item) + # f.write("\n") + # connections_file.close() + # sim.Projection(input, output, sim.FromFileConnector(file_name), receptor_type=receptor_type) + + from_list_segments = [from_list[x:x + max_conn] for x in xrange(0, len(from_list), max_conn)] + for connection in from_list_segments: + sim.Projection(input, output, sim.FromListConnector(connection), receptor_type=receptor_type) + +def segment_hidden_pop(from_list, width, length, pre): + hidden_pops = [] + list_of_lists = [[] for i in range(width*length)] + for connection in from_list: + if pre: + list_of_lists[connection[0]].append([0, connection[1], connection[2], connection[3]]) + else: + list_of_lists[connection[1]].append([connection[0], 0, connection[2], connection[3]]) + return list_of_lists + +def connect_it_up(visual_input, motor_output, connections, width, length): + visual_connections, motor_conn = connections + layers = len(motor_conn) + all_pops = [] + hidden_pops = [] + for layer in range(layers): + motor_conn_e, motor_conn_i = motor_conn[layer] + # hidden_pop = sim.Population(width * length, sim.IF_curr_exp(), label="hidden_pop_{}".format(layer)) + # hidden_pops.append(hidden_pop) + for i in range(width*length): + hidden_pop = sim.Population(1, sim.IF_curr_exp(tau_refrac=3), label="hidden_pop_{}_{}".format(layer, i)) + if simulate: + hidden_pop.record(["spikes", "v"]) + hidden_pops.append(hidden_pop) + list_of_lists = segment_hidden_pop(visual_connections[layer], width, length, False) + for i in range(len(list_of_lists)): + split_the_from_list(visual_input, hidden_pops[i], list_of_lists[i]) + list_of_lists = segment_hidden_pop(motor_conn_e, width, length, True) + for i in range(len(list_of_lists)): + split_the_from_list(hidden_pops[i], motor_output, list_of_lists[i]) + list_of_lists = segment_hidden_pop(motor_conn_i, width, length, True) + for i in range(len(list_of_lists)): + split_the_from_list(hidden_pops[i], motor_output, list_of_lists[i], receptor_type="inhibitory") + # split_the_from_list(visual_input, hidden_pop, visual_connections[layer]) + # split_the_from_list(hidden_pop, motor_output, motor_conn_e) + # split_the_from_list(hidden_pops[layer], motor_output, motor_conn_i, receptor_type="inhibitory") + all_pops.append(hidden_pops) + print "finished connecting" + return all_pops + +simulate = True + +sim.setup(timestep=1.0) +# sim.set_number_of_neurons_per_core(sim.IF_curr_exp, 255) + +width = 2 +length = 2 + +# mapping_1 = map_neurons_to_field(64, 19, 15, 0.9, 5) +mapping_2 = map_neurons_to_field(20, width, length, 0.9, 0) +# mapping_3 = map_neurons_to_field(50, 19, 15, 0.9, 2) +# mapping_4 = map_neurons_to_field(128, 2, 2, 0.9, 5) +# mapping_5 = map_neurons_to_field(128, 2, 2, 0.9, 7) +print "created mapping" +# connections_1 = map_to_from_list(mapping_1, 19, 15, 0.9) +connections_2 = map_to_from_list(mapping_2, width, length, 0.9) +# connections_3 = map_to_from_list(mapping_3, 19, 15, 0.9) +# connections_4 = map_to_from_list(mapping_4, 2, 2, 0.9) +# connections_5 = map_to_from_list(mapping_5, 2, 2, 0.9) +print "created all connections" + + +sim.setup(timestep=1.0) +# sim.set_number_of_neurons_per_core(sim.IF_curr_exp, 32) + +# set up populations, +if simulate: + # Assuming channel 0 as left camera and channel 1 as right camera + # Import data.log and Decode events + dm = DataManager() + dm.load_AE_from_yarp('acquisitions10042019/circle10042019') + + # Loading decoded events; data(timestamp, channel, x, y, polarity) + stereo_data = np.loadtxt('acquisitions10042019/circle10042019/decoded_events.txt', delimiter=',') + [left_data, right_data] = split_stereo_data(stereo_data) + # left_data.tolist() + # right_data.tolist() + + new_left = convert_data(left_data) + new_right = convert_data(right_data) + + print('ATIS data processing ended') + + vis_pop = sim.Population(width*length, sim.SpikeSourceArray(new_left), label='pop_in') +else: + vis_pop = sim.Population(None, ICUBInputVertex(spinnaker_link_id=0), label='pop_in') + +pop_out = sim.Population(4, sim.IF_curr_exp(tau_refrac=3), label="motor_control") +if simulate: + pop_out.record(['spikes', 'v']) + +# pop_out = sim.Population(None, ICUBOutputVertex(spinnaker_link_id=0), label='pop_out') + +# hidden_pops = connect_it_up(vis_pop, pop_out, connections_1, 19, 15) +hidden_pops = connect_it_up(vis_pop, pop_out, connections_2, width, length) +# connect_it_up(vis_pop, pop_out, connections_3, 19, 15) +# connect_it_up(vis_pop, pop_out, connections_4, 2, 2) +# connect_it_up(vis_pop, pop_out, connections_5, 2, 2) + +# test_input = sim.Population(304*240, sim.IF_curr_exp(), label="readout") +# test_input.record(['spikes', 'v']) +# sim.Projection(vis_pop, test_input, sim.OneToOneConnector(), sim.StaticSynapse(weight=0.1)) + +# sim.Projection(pop, neuron_pop, sim.OneToOneConnector(), sim.StaticSynapse(weight=20.0)) + +sim.external_devices.activate_live_output_to(pop_out, vis_pop) + +# out_port = yarp.BufferedPortBottle() +# out_port.open('/spinn:o') +# # bottle = out_port.prepare() +# # bottle.clear() +# # bottle.addInt32(2) +# # out_port.write() +# # out_port +# # b.addString("thing") +# while True: +# bottle = out_port.prepare() +# bottle.clear() +# bottle.addInt32(2) +# out_port.write() + +#recordings and simulations, +#neuron_pop.record("spikes") + +simtime = 30000 #ms, +if simulate: + sim.run(simtime) +else: + sim.external_devices.run_forever() + raw_input('Press enter to stop') + +# continuous run until key press +# remember: do NOT record when running in this mode + +if simulate: + exc_spikes = pop_out.get_data("spikes") + exc_v = pop_out.get_data("v") + hidden_spikes = [] + hidden_v = [] + for i in range(len(hidden_pops[0])): + hidden_spikes.append(hidden_pops[0][i].get_data("spikes")) + hidden_v.append(hidden_pops[0][i].get_data("v")) + # input_spikes = test_input.get_data("spikes") + # input_v = test_input.get_data("v") + + Figure( + # raster plot of the neuron_pop + Panel(exc_spikes.segments[0].spiketrains, xlabel="Time/ms", xticks=True, + yticks=True, markersize=0.2, xlim=(0, simtime)), + Panel(exc_v.segments[0].filter(name='v')[0], ylabel="Membrane potential (mV)", yticks=True), + Panel(hidden_spikes[0].segments[0].spiketrains, xlabel="Time/ms", xticks=True, + yticks=True, markersize=0.2, xlim=(0, simtime)), + Panel(hidden_v[0].segments[0].filter(name='v')[0], ylabel="Membrane potential (mV)", yticks=True), + Panel(hidden_spikes[1].segments[0].spiketrains, xlabel="Time/ms", xticks=True, + yticks=True, markersize=0.2, xlim=(0, simtime)), + Panel(hidden_v[1].segments[0].filter(name='v')[0], ylabel="Membrane potential (mV)", yticks=True), + Panel(hidden_spikes[2].segments[0].spiketrains, xlabel="Time/ms", xticks=True, + yticks=True, markersize=0.2, xlim=(0, simtime)), + Panel(hidden_v[2].segments[0].filter(name='v')[0], ylabel="Membrane potential (mV)", yticks=True), + Panel(hidden_spikes[3].segments[0].spiketrains, xlabel="Time/ms", xticks=True, + yticks=True, markersize=0.2, xlim=(0, simtime)), + Panel(hidden_v[3].segments[0].filter(name='v')[0], ylabel="Membrane potential (mV)", yticks=True), + # Panel(input_spikes.segments[0].spiketrains, xlabel="Time/ms", xticks=True, + # yticks=True, markersize=0.2, xlim=(0, simtime)), + # Panel(input_v.segments[0].filter(name='v')[0], ylabel="Membrane potential (mV)", yticks=True), + title="neuron_pop: spikes" + ) + plt.show() + +sim.end() + +print("finished") diff --git a/examples/icub_vor_examples/single_purkinje_cell_pf_windowing.py b/examples/icub_vor_examples/single_purkinje_cell_pf_windowing.py new file mode 100644 index 00000000..158d4641 --- /dev/null +++ b/examples/icub_vor_examples/single_purkinje_cell_pf_windowing.py @@ -0,0 +1,105 @@ +from __future__ import print_function +import spynnaker8 as p +import numpy +import math +import unittest +from pyNN.utility.plotting import Figure, Panel +import matplotlib.pyplot as plt + +p.setup(1) # simulation timestep (ms) +runtime = 500 + +# Post-synapse population +neuron_params = { + "v_thresh": -50, + "v_reset": -70, + "v_rest": -65, + "i_offset": 0 # DC input + } + +# Learning parameters +min_weight = 0 +max_weight = 0.1 +pot_alpha=0.01 +t_peak=100 +initial_weight = 0.05 +plastic_delay = 4 + +purkinje_cell = p.Population(1, # number of neurons + p.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model + label="Purkinje Cell" # identifier + ) + + +# Spike source to send spike via synapse +pf_spike_times = [50, 60, 65, 85, 101, 400]#, 150, 175, 180, 190, 240, 250, 255, +# 270, 300, 345, 350, 360, 370, 400, 422, 425, 427, 429] + +granular_cell = p.Population(1, # number of sources + p.SpikeSourceArray, # source type + {'spike_times': pf_spike_times}, # source spike times + label="src1" # identifier + ) + +# Spike source to send spike via synapse from climbing fibre +cf_spike_times = [55, 80, 90, 95, 96, 201]#, 104, 107, 246] +climbing_fibre = p.Population(1, # number of sources + p.SpikeSourceArray, # source type + {'spike_times': cf_spike_times}, # source spike times + label="src2" # identifier + ) + +# Create projection from GC to PC +pfpc_plas = p.STDPMechanism( + timing_dependence=p.extra_models.TimingDependencePFPC(t_peak=t_peak), + weight_dependence=p.extra_models.WeightDependencePFPC(w_min=min_weight, + w_max=max_weight, + pot_alpha=pot_alpha), + weight=initial_weight, delay=plastic_delay) + +synapse_pfpc = p.Projection( + granular_cell, purkinje_cell, p.AllToAllConnector(), + synapse_type=pfpc_plas, receptor_type="excitatory") + + +# Create projection from CF to PC +synapse = p.Projection( + climbing_fibre, purkinje_cell, p.OneToOneConnector(), + p.StaticSynapse(weight=0.0, delay=1), receptor_type="excitatory") + + +granular_cell.record('spikes') +climbing_fibre.record('spikes') +purkinje_cell.record("all") + +p.run(runtime) + +granluar_cell_spikes = granular_cell.get_data('spikes') +climbing_fibre_spikes = climbing_fibre.get_data('spikes') +purkinje_data = purkinje_cell.get_data() + +pf_weights = synapse_pfpc.get('weight', 'list', with_address=False) +print(pf_weights) + +# Plot +F = Figure( + # plot data for postsynaptic neuron + Panel(granluar_cell_spikes.segments[0].spiketrains, + yticks=True, markersize=2, xlim=(0, runtime)), + Panel(climbing_fibre_spikes.segments[0].spiketrains, + yticks=True, markersize=2, xlim=(0, runtime)), + Panel(purkinje_data.segments[0].filter(name='v')[0], + ylabel="Membrane potential (mV)", + data_labels=[purkinje_cell.label], yticks=True, xlim=(0, runtime)), + Panel(purkinje_data.segments[0].filter(name='gsyn_exc')[0], + ylabel="gsyn excitatory (mV)", + data_labels=[purkinje_cell.label], yticks=True, xlim=(0, runtime)), + Panel(purkinje_data.segments[0].spiketrains, + yticks=True, markersize=2, xlim=(0, runtime)), + ) + + +plt.show() +p.end() + +print("Job Complete") diff --git a/examples/icub_vor_examples/single_purkinje_cell_potentiation_test.py b/examples/icub_vor_examples/single_purkinje_cell_potentiation_test.py new file mode 100644 index 00000000..8bb60c02 --- /dev/null +++ b/examples/icub_vor_examples/single_purkinje_cell_potentiation_test.py @@ -0,0 +1,95 @@ +from __future__ import print_function +import spynnaker8 as p +import numpy +import math +import unittest +from pyNN.utility.plotting import Figure, Panel +import matplotlib.pyplot as plt + +p.setup(1) # simulation timestep (ms) +runtime = 1000 + +# Post-synapse population +neuron_params = { + "v_thresh": -50, + "v_reset": -70, + "v_rest": -65, + "i_offset": 0 # DC input + } + +# Learning parameters +min_weight = 0 +max_weight = 0.1 +pot_alpha = 0.002 # this is alpha in the paper + +t_peak = 101 # ms + +initial_weight = 0.05 +plastic_delay = 4 + +purkinje_cell = p.Population(1, # number of neurons + p.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model + label="Purkinje Cell" # identifier + ) + + +# Spike source to send spike via synapse +spike_times = [101, 201, 301, 401, 501, 601, 701, 801, 901] + +granular_cell = p.Population(1, # number of sources + p.SpikeSourceArray, # source type + {'spike_times': spike_times}, # source spike times + label="src1" # identifier + ) + + +# Create projection from GC to PC +pfpc_plas = p.STDPMechanism( + timing_dependence=p.extra_models.TimingDependencePFPC(t_peak=t_peak), + weight_dependence=p.extra_models.WeightDependencePFPC(w_min=min_weight, + w_max=max_weight, + pot_alpha=pot_alpha), + weight=initial_weight, delay=plastic_delay) + +synapse_pfpc = p.Projection( + granular_cell, purkinje_cell, p.AllToAllConnector(), + synapse_type=pfpc_plas, receptor_type="excitatory") + + + + +granular_cell.record('spikes') +purkinje_cell.record("all") + + +pf_weights = [] +for i in range(len(spike_times)): + p.run(100) + pf_weights.append(synapse_pfpc.get('weight', 'list', with_address=False)) + +granluar_cell_spikes = granular_cell.get_data('spikes') +purkinje_data = purkinje_cell.get_data(['v', 'gsyn_exc', 'spikes']) + +for i in pf_weights: + print(i) +# Plot +F = Figure( + # plot data for postsynaptic neuron + Panel(granluar_cell_spikes.segments[0].spiketrains, + yticks=True, markersize=2, xlim=(0, runtime)), + Panel(purkinje_data.segments[0].filter(name='v')[0], + ylabel="Membrane potential (mV)", + data_labels=[purkinje_cell.label], yticks=True, xlim=(0, runtime)), + Panel(purkinje_data.segments[0].filter(name='gsyn_exc')[0], + ylabel="gsyn excitatory (mV)", + data_labels=[purkinje_cell.label], yticks=True, xlim=(0, runtime)), + Panel(purkinje_data.segments[0].spiketrains, + yticks=True, markersize=2, xlim=(0, runtime)), + ) + + +plt.show() +p.end() + +print("Job Complete") + diff --git a/examples/icub_vor_examples/single_purkinje_cell_test.py b/examples/icub_vor_examples/single_purkinje_cell_test.py new file mode 100644 index 00000000..6961858b --- /dev/null +++ b/examples/icub_vor_examples/single_purkinje_cell_test.py @@ -0,0 +1,106 @@ +from __future__ import print_function +import spynnaker8 as p +import numpy +import math +import unittest +from pyNN.utility.plotting import Figure, Panel +import matplotlib.pyplot as plt + +p.setup(1) # simulation timestep (ms) +runtime = 500 + +# Post-synapse population +neuron_params = { + "v_thresh": -50, + "v_reset": -70, + "v_rest": -65, + "i_offset": 0 # DC input + } + +# Learning parameters +min_weight = 0 +max_weight = 0.1 +pot_alpha=0.01 +t_peak=100 +initial_weight = 0.05 +plastic_delay = 4 + +purkinje_cell = p.Population(1, # number of neurons + p.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model + label="Purkinje Cell" # identifier + ) + + +# Spike source to send spike via synapse +spike_times = [50, 150, 270] + +granular_cell = p.Population(1, # number of sources + p.SpikeSourceArray, # source type + {'spike_times': spike_times}, # source spike times + label="src1" # identifier + ) + +# Spike source to send spike via synapse from climbing fibre +spike_times_2 = [100, 104, 107, 246] +climbing_fibre = p.Population(1, # number of sources + p.SpikeSourceArray, # source type + {'spike_times': spike_times_2}, # source spike times + label="src2" # identifier + ) + +# Create projection from GC to PC +pfpc_plas = p.STDPMechanism( + timing_dependence=p.extra_models.TimingDependencePFPC(t_peak=t_peak), + weight_dependence=p.extra_models.WeightDependencePFPC(w_min=min_weight, + w_max=max_weight, + pot_alpha=pot_alpha), + weight=initial_weight, delay=plastic_delay) + +synapse_pfpc = p.Projection( + granular_cell, purkinje_cell, p.AllToAllConnector(), + synapse_type=pfpc_plas, receptor_type="excitatory") + + +# Create projection from CF to PC +synapse = p.Projection( + climbing_fibre, purkinje_cell, p.OneToOneConnector(), + p.StaticSynapse(weight=0.0, delay=1), receptor_type="excitatory") + + +granular_cell.record('spikes') +climbing_fibre.record('spikes') +purkinje_cell.record("all") + +p.run(runtime) + +granluar_cell_spikes = granular_cell.get_data('spikes') +climbing_fibre_spikes = climbing_fibre.get_data('spikes') +purkinje_data = purkinje_cell.get_data(['v', 'gsyn_exc', 'spikes']) + +pf_weights = synapse_pfpc.get('weight', 'list', with_address=False) +print(pf_weights) + +# Plot +F = Figure( + # plot data for postsynaptic neuron + Panel(granluar_cell_spikes.segments[0].spiketrains, + yticks=True, markersize=2, xlim=(0, runtime)), + Panel(climbing_fibre_spikes.segments[0].spiketrains, + yticks=True, markersize=2, xlim=(0, runtime)), + Panel(purkinje_data.segments[0].filter(name='v')[0], + ylabel="PC membrane potential (mV)", + data_labels=[purkinje_cell.label], yticks=True, xlim=(0, runtime)), + Panel(purkinje_data.segments[0].filter(name='gsyn_exc')[0], + ylabel="PC excitatory current (mV)", + data_labels=[purkinje_cell.label], yticks=True, xlim=(0, runtime)), + Panel(purkinje_data.segments[0].spiketrains, + ylabel="PC spikes", + xlabel="Time (ms)", + yticks=True, markersize=2, xlim=(0, runtime)), + ) + +plt.savefig("single_pc_test.png", dpi=600) +plt.show() +p.end() + + diff --git a/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing.py b/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing.py new file mode 100644 index 00000000..04f85903 --- /dev/null +++ b/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing.py @@ -0,0 +1,110 @@ +from __future__ import print_function +import spynnaker8 as p +import numpy +import math +import unittest +from pyNN.utility.plotting import Figure, Panel +import matplotlib.pyplot as plt + +p.setup(1) # simulation timestep (ms) +runtime = 500 + +# Post-synapse population +neuron_params = { + "v_thresh": -50, + "v_reset": -70, + "v_rest": -65, + "i_offset": 0 # DC input + } + +# Learning parameters +min_weight = 0 +max_weight = 0.1 +pot_alpha = 0.01 # this is alpha in the paper + +beta = 11 +sigma = 201 +initial_weight = 0.005 + +initial_weight = 0.05 +plastic_delay = 4 + +vestibular_nuclei = p.Population(1, # number of neurons + p.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model + label="Vestibular Nuclei" # identifier + ) + + +# Spike source to send spike via synapse +mf_spike_times = [50, 60, 65, 85, 101, 400]#, 150, 175, 180, 190, 240, 250, 255, +# 270, 300, 345, 350, 360, 370, 400, 422, 425, 427, 429] + +mossy_fibre_src = p.Population(1, # number of sources + p.SpikeSourceArray, # source type + {'spike_times': mf_spike_times}, # source spike times + label="src1" # identifier + ) + +# Spike source to send spike via synapse from climbing fibre +pc_spike_times = [55, 80, 90, 95, 96, 201]#, 104, 107, 246] +purkinje_cell_src = p.Population(1, # number of sources + p.SpikeSourceArray, # source type + {'spike_times': pc_spike_times}, # source spike times + label="src2" # identifier + ) + +# Create projection from GC to PC +mfvn_plas = p.STDPMechanism( + timing_dependence=p.extra_models.TimingDependenceMFVN(beta=beta, + sigma=sigma), + weight_dependence=p.extra_models.WeightDependenceMFVN(w_min=min_weight, + w_max=max_weight, + pot_alpha=pot_alpha), + weight=initial_weight, delay=plastic_delay) + +synapse_mfvn = p.Projection( + mossy_fibre_src, vestibular_nuclei, p.AllToAllConnector(), + synapse_type=mfvn_plas, receptor_type="excitatory") + + +# Create projection from PC to VN +synapse = p.Projection( + purkinje_cell_src, vestibular_nuclei, p.OneToOneConnector(), + p.StaticSynapse(weight=0.0, delay=1), receptor_type="excitatory") + + +mossy_fibre_src.record('spikes') +purkinje_cell_src.record('spikes') +vestibular_nuclei.record("all") + +p.run(runtime) + +mossy_fibre_src_spikes = mossy_fibre_src.get_data('spikes') +purkinje_cell_src_spikes = purkinje_cell_src.get_data('spikes') +vestibular_nuclei_data = vestibular_nuclei.get_data() + +mf_weights = synapse_mfvn.get('weight', 'list', with_address=False) +print(mf_weights) + +# Plot +F = Figure( + # plot data for postsynaptic neuron + Panel(mossy_fibre_src_spikes.segments[0].spiketrains, + yticks=True, markersize=2, xlim=(0, runtime)), + Panel(purkinje_cell_src_spikes.segments[0].spiketrains, + yticks=True, markersize=2, xlim=(0, runtime)), + Panel(vestibular_nuclei_data.segments[0].filter(name='v')[0], + ylabel="Membrane potential (mV)", + data_labels=[vestibular_nuclei.label], yticks=True, xlim=(0, runtime)), + Panel(vestibular_nuclei_data.segments[0].filter(name='gsyn_exc')[0], + ylabel="gsyn excitatory (mV)", + data_labels=[vestibular_nuclei.label], yticks=True, xlim=(0, runtime)), + Panel(vestibular_nuclei_data.segments[0].spiketrains, + yticks=True, markersize=2, xlim=(0, runtime)), + ) + + +plt.show() +p.end() + +print("Job Complete") diff --git a/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing_3_spikes.py b/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing_3_spikes.py new file mode 100644 index 00000000..21c8dcbe --- /dev/null +++ b/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing_3_spikes.py @@ -0,0 +1,111 @@ +from __future__ import print_function +import spynnaker8 as p +import numpy +import math +import unittest +from pyNN.utility.plotting import Figure, Panel +import matplotlib.pyplot as plt + +p.setup(1) # simulation timestep (ms) +runtime = 500 + +# Post-synapse population +neuron_params = { + "v_thresh": -50, + "v_reset": -70, + "v_rest": -65, + "i_offset": 0 # DC input + } + +# Learning parameters +pot_alpha = 0.01 +beta = 11 +sigma = 201 + +pot_alpha = 0.01 +min_weight = 0 +max_weight = 0.1 + +initial_weight = 0.01 +plastic_delay = 4 + +vestibular_nuclei = p.Population(1, # number of neurons + p.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model + label="Vestibular Nuclei" # identifier + ) + + +# Spike source to send spike via synapse +mf_spike_times = [50, 60, 65]#, 150, 175, 180, 190, 240, 250, 255, +# 270, 300, 345, 350, 360, 370, 400, 422, 425, 427, 429] + +mossy_fibre_src = p.Population(1, # number of sources + p.SpikeSourceArray, # source type + {'spike_times': mf_spike_times}, # source spike times + label="src1" # identifier + ) + +# Spike source to send spike via synapse from climbing fibre +pc_spike_times = [60]#, 104, 107, 246] +purkinje_cell_src = p.Population(1, # number of sources + p.SpikeSourceArray, # source type + {'spike_times': pc_spike_times}, # source spike times + label="purkinje_cell_src" # identifier + ) + +# Create projection from GC to PC +mfvn_plas = p.STDPMechanism( + timing_dependence=p.extra_models.TimingDependenceMFVN(beta=beta, + sigma=sigma), + weight_dependence=p.extra_models.WeightDependenceMFVN(w_min=min_weight, + w_max=max_weight, + pot_alpha=pot_alpha), + weight=initial_weight, delay=plastic_delay) + +synapse_mfvn = p.Projection( + mossy_fibre_src, vestibular_nuclei, p.AllToAllConnector(), + synapse_type=mfvn_plas, receptor_type="excitatory") + + +# Create projection from PC to VN +synapse = p.Projection( + purkinje_cell_src, vestibular_nuclei, p.OneToOneConnector(), + p.StaticSynapse(weight=0.0, delay=1), receptor_type="excitatory") + + +mossy_fibre_src.record('spikes') +purkinje_cell_src.record('spikes') +vestibular_nuclei.record("all") + +p.run(runtime) + +mossy_fibre_src_spikes = mossy_fibre_src.get_data('spikes') +purkinje_cell_src_spikes = purkinje_cell_src.get_data('spikes') +vestibular_nuclei_data = vestibular_nuclei.get_data() + +mf_weights = synapse_mfvn.get('weight', 'list', with_address=False) +print("\n {}".format(mf_weights)) + +# Plot +F = Figure( + # plot data for postsynaptic neuron + Panel(mossy_fibre_src_spikes.segments[0].spiketrains, + yticks=True, markersize=2, xlim=(0, runtime)), + Panel(purkinje_cell_src_spikes.segments[0].spiketrains, + yticks=True, markersize=2, xlim=(0, runtime)), + Panel(vestibular_nuclei_data.segments[0].filter(name='v')[0], + ylabel="Membrane potential (mV)", + data_labels=[vestibular_nuclei.label], yticks=True, xlim=(0, runtime)), + Panel(vestibular_nuclei_data.segments[0].filter(name='gsyn_exc')[0], + ylabel="gsyn excitatory (mV)", + data_labels=[vestibular_nuclei.label], yticks=True, xlim=(0, runtime)), + Panel(vestibular_nuclei_data.segments[0].spiketrains, + yticks=True, markersize=2, xlim=(0, runtime)), + ) + + +plt.show() +p.end() +print("Job Complete") + + diff --git a/examples/icub_vor_examples/single_vestibular_nuclei_potentiation_test.py b/examples/icub_vor_examples/single_vestibular_nuclei_potentiation_test.py new file mode 100644 index 00000000..f863fb8b --- /dev/null +++ b/examples/icub_vor_examples/single_vestibular_nuclei_potentiation_test.py @@ -0,0 +1,100 @@ +from __future__ import print_function +import spynnaker8 as p +import numpy +import math +import unittest +from pyNN.utility.plotting import Figure, Panel +import matplotlib.pyplot as plt + + +p.setup(1) # simulation timestep (ms) +runtime = 1000 + +# Post-synapse population +neuron_params = { + "v_thresh": -50, + "v_reset": -70, + "v_rest": -65, + "i_offset": 0 # DC input + } + +# Learning parameters +min_weight = 0 +max_weight = 0.1 +pot_alpha = 0.01 # this is alpha in the paper + +beta = 11 +sigma = 201 +initial_weight = 0.005 + +plastic_delay = 4 + +vestibular_neuclei = p.Population(1, # number of neurons + p.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model + label="Vestibular Nuclei" # identifier + ) + + +# Spike source to send spike via synapse +spike_times = [1, 101, 201, 301, 401, 501, 601, 701, 801, 901] + +mossy_fibre_src = p.Population(1, # number of sources + p.SpikeSourceArray, # source type + {'spike_times': spike_times}, # source spike times + label="src1" # identifier + ) + + +# Create projection from MF to VN +mfvn_plas = p.STDPMechanism( + timing_dependence=p.extra_models.TimingDependenceMFVN(beta=beta, + sigma=sigma), + weight_dependence=p.extra_models.WeightDependenceMFVN(w_min=min_weight, + w_max=max_weight, + pot_alpha=pot_alpha), + weight=initial_weight, delay=plastic_delay) + +synapse_mfvn = p.Projection( + mossy_fibre_src, vestibular_neuclei, p.AllToAllConnector(), + synapse_type=mfvn_plas, receptor_type="excitatory") + + +mossy_fibre_src.record('spikes') +vestibular_neuclei.record("all") + + +mf_weights = [] +for i in range(len(spike_times)): + p.run(100) + mf_weights.append(synapse_mfvn.get('weight', 'list', with_address=False)) + +mossy_fibre_src_spikes = mossy_fibre_src.get_data('spikes') +vestibular_neuclei_data = vestibular_neuclei.get_data( + ['v', 'gsyn_exc', 'spikes']) + +# print weight history +for i in mf_weights: + print(i) + +# Plot +F = Figure( + # plot data for postsynaptic neuron + Panel(mossy_fibre_src_spikes.segments[0].spiketrains, + yticks=True, markersize=2, xlim=(0, runtime)), + Panel(vestibular_neuclei_data.segments[0].filter(name='v')[0], + ylabel="VN membrane potential (mV)", + data_labels=[vestibular_neuclei.label], yticks=True, xlim=(0, runtime)), + Panel(vestibular_neuclei_data.segments[0].filter(name='gsyn_exc')[0], + ylabel="VN excitatory current (mV)", + data_labels=[vestibular_neuclei.label], yticks=True, xlim=(0, runtime)), + Panel(vestibular_neuclei_data.segments[0].spiketrains, + xlabel="Time (ms)", + yticks=True, markersize=2, xlim=(0, runtime)), + ) + + +plt.savefig("single_vn_test.png", dpi=600) +plt.show() +p.end() + +print("Job Complete") diff --git a/examples/icub_vor_examples/test_mfvn_lut.py b/examples/icub_vor_examples/test_mfvn_lut.py new file mode 100644 index 00000000..0cc00a42 --- /dev/null +++ b/examples/icub_vor_examples/test_mfvn_lut.py @@ -0,0 +1,11 @@ +from spynnaker.pyNN.models.neuron.plasticity.stdp.common import write_mfvn_lut + +beta = 10 +sigma = 200 + +write_mfvn_lut(spec=None, + sigma=sigma, + beta=beta, + lut_size=256, + shift=0, + time_probe=22) diff --git a/examples/icub_vor_examples/test_pfpc_lut.py b/examples/icub_vor_examples/test_pfpc_lut.py new file mode 100644 index 00000000..a452596f --- /dev/null +++ b/examples/icub_vor_examples/test_pfpc_lut.py @@ -0,0 +1,11 @@ +from spynnaker.pyNN.models.neuron.plasticity.stdp.common import write_pfpc_lut +# import math + +# sin_power=20 +t_peak = 100 + +write_pfpc_lut(spec=None, + peak_time=t_peak, + lut_size=256, + shift=0, + time_probe=t_peak) From 84fbb8d37c9eaf5c03e193e3a4aa2f52a1d75a9b Mon Sep 17 00:00:00 2001 From: Andrew Gait Date: Thu, 18 Nov 2021 17:19:11 +0000 Subject: [PATCH 02/28] Minor fixes to script (note: packets-per-timestep recording broken?) --- examples/icub_vor_examples/cerebellum.py | 6 +++--- examples/icub_vor_examples/dataflow.py | 18 +++++++++--------- ...je_cell_test.pysingle_purkinje_cell_test.py | 2 +- .../single_purkinje_cell_pf_windowing.py | 2 +- .../single_vestibular_nuclei_mf_windowing.py | 2 +- ..._vestibular_nuclei_mf_windowing_3_spikes.py | 2 +- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/examples/icub_vor_examples/cerebellum.py b/examples/icub_vor_examples/cerebellum.py index 2b7609ec..7143cbf9 100644 --- a/examples/icub_vor_examples/cerebellum.py +++ b/examples/icub_vor_examples/cerebellum.py @@ -8,15 +8,15 @@ from pacman.model.constraints.key_allocator_constraints import FixedKeyAndMaskConstraint from pacman.model.graphs.application import ApplicationSpiNNakerLinkVertex from pacman.model.routing_info import BaseKeyAndMask -from spinn_front_end_common.abstract_models.abstract_provides_n_keys_for_partition import AbstractProvidesNKeysForPartition +# from spinn_front_end_common.abstract_models.abstract_provides_n_keys_for_partition import AbstractProvidesNKeysForPartition from spinn_front_end_common.abstract_models.abstract_provides_outgoing_partition_constraints import AbstractProvidesOutgoingPartitionConstraints from spinn_utilities.overrides import overrides from pyNN.utility import Timer from pyNN.utility.plotting import Figure, Panel from pyNN.random import RandomDistribution, NumpyRNG -from spynnaker.pyNN.models.neuron.plasticity.stdp.common \ - import plasticity_helpers +# from spynnaker.pyNN.models.neuron.plasticity.stdp.common \ +# import plasticity_helpers # cerebellum with simulated input RETINA_X_SIZE = 304 diff --git a/examples/icub_vor_examples/dataflow.py b/examples/icub_vor_examples/dataflow.py index 19645b60..9a79baa7 100644 --- a/examples/icub_vor_examples/dataflow.py +++ b/examples/icub_vor_examples/dataflow.py @@ -7,7 +7,7 @@ from pacman.model.constraints.key_allocator_constraints import FixedKeyAndMaskConstraint from pacman.model.graphs.application import ApplicationSpiNNakerLinkVertex from pacman.model.routing_info import BaseKeyAndMask -from spinn_front_end_common.abstract_models.abstract_provides_n_keys_for_partition import AbstractProvidesNKeysForPartition +# from spinn_front_end_common.abstract_models.abstract_provides_n_keys_for_partition import AbstractProvidesNKeysForPartition from spinn_front_end_common.abstract_models.abstract_provides_outgoing_partition_constraints import AbstractProvidesOutgoingPartitionConstraints from spinn_utilities.overrides import overrides from spinn_front_end_common.abstract_models.abstract_provides_incoming_partition_constraints import AbstractProvidesIncomingPartitionConstraints @@ -25,7 +25,7 @@ from pyNN.utility.plotting import Figure, Panel from pyNN.random import RandomDistribution, NumpyRNG -from spynnaker.pyNN.models.neuron.plasticity.stdp.common import plasticity_helpers +# from spynnaker.pyNN.models.neuron.plasticity.stdp.common import plasticity_helpers NUM_NEUR_IN = 1024 #1024 # 2x240x304 mask -> 0xFFFE0000 MASK_IN = 0xFFFFFC00 #0xFFFFFC00 @@ -45,7 +45,7 @@ def __init__(self, spinnaker_link_id, board_address=None, self, n_atoms=NUM_NEUR_IN, spinnaker_link_id=spinnaker_link_id, board_address=board_address, label=label) - AbstractProvidesNKeysForPartition.__init__(self) + # AbstractProvidesNKeysForPartition.__init__(self) AbstractProvidesOutgoingPartitionConstraints.__init__(self) AbstractSendMeMulticastCommandsVertex.__init__(self) @@ -58,15 +58,15 @@ def get_outgoing_partition_constraints(self, partition): mask=MASK_IN)])] #keys, i.e. neuron addresses of the input population that sits in the ICUB vertex, - @inject_items({"graph_mapper": "MemoryGraphMapper"}) @overrides(AbstractProvidesIncomingPartitionConstraints. - get_incoming_partition_constraints, - additional_arguments=["graph_mapper"]) - def get_incoming_partition_constraints(self, partition, graph_mapper): + get_incoming_partition_constraints) + def get_incoming_partition_constraints(self, partition): if isinstance(partition.pre_vertex, CommandSenderMachineVertex): return [] - index = graph_mapper.get_machine_vertex_index(partition.pre_vertex) - vertex_slice = graph_mapper.get_slice(partition.pre_vertex) + # index = graph_mapper.get_machine_vertex_index(partition.pre_vertex) + # vertex_slice = graph_mapper.get_slice(partition.pre_vertex) + index = partition.pre_vertex.index + vertex_slice = partition.pre_vertex.vertex_slice mask = get_possible_masks(vertex_slice.n_atoms)[0] key = (0x1000 + index) << 16 return [FixedKeyAndMaskConstraint( diff --git a/examples/icub_vor_examples/pb_single_purkinje_cell_test.pysingle_purkinje_cell_test.py b/examples/icub_vor_examples/pb_single_purkinje_cell_test.pysingle_purkinje_cell_test.py index ed832259..9dd81c25 100644 --- a/examples/icub_vor_examples/pb_single_purkinje_cell_test.pysingle_purkinje_cell_test.py +++ b/examples/icub_vor_examples/pb_single_purkinje_cell_test.pysingle_purkinje_cell_test.py @@ -72,7 +72,7 @@ granluar_cell_spikes = granular_cell.get_data('spikes') climbing_fibre_spikes = climbing_fibre.get_data('spikes') -purkinje_data = purkinje_cell.get_data() +purkinje_data = purkinje_cell.get_data(['v', 'gsyn_exc', 'spikes']) pf_weights = synapse_pfpc.get('weight', 'list', with_address=False) print(pf_weights) diff --git a/examples/icub_vor_examples/single_purkinje_cell_pf_windowing.py b/examples/icub_vor_examples/single_purkinje_cell_pf_windowing.py index 158d4641..f9e552c1 100644 --- a/examples/icub_vor_examples/single_purkinje_cell_pf_windowing.py +++ b/examples/icub_vor_examples/single_purkinje_cell_pf_windowing.py @@ -76,7 +76,7 @@ granluar_cell_spikes = granular_cell.get_data('spikes') climbing_fibre_spikes = climbing_fibre.get_data('spikes') -purkinje_data = purkinje_cell.get_data() +purkinje_data = purkinje_cell.get_data(['v', 'gsyn_exc', 'spikes']) pf_weights = synapse_pfpc.get('weight', 'list', with_address=False) print(pf_weights) diff --git a/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing.py b/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing.py index 04f85903..60b18378 100644 --- a/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing.py +++ b/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing.py @@ -81,7 +81,7 @@ mossy_fibre_src_spikes = mossy_fibre_src.get_data('spikes') purkinje_cell_src_spikes = purkinje_cell_src.get_data('spikes') -vestibular_nuclei_data = vestibular_nuclei.get_data() +vestibular_nuclei_data = vestibular_nuclei.get_data(['v', 'gsyn_exc', 'spikes']) mf_weights = synapse_mfvn.get('weight', 'list', with_address=False) print(mf_weights) diff --git a/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing_3_spikes.py b/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing_3_spikes.py index 21c8dcbe..666db0d9 100644 --- a/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing_3_spikes.py +++ b/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing_3_spikes.py @@ -81,7 +81,7 @@ mossy_fibre_src_spikes = mossy_fibre_src.get_data('spikes') purkinje_cell_src_spikes = purkinje_cell_src.get_data('spikes') -vestibular_nuclei_data = vestibular_nuclei.get_data() +vestibular_nuclei_data = vestibular_nuclei.get_data(['v', 'gsyn_exc', 'spikes']) mf_weights = synapse_mfvn.get('weight', 'list', with_address=False) print("\n {}".format(mf_weights)) From eda9e8eb60278637686c8c497a0803d4756305fb Mon Sep 17 00:00:00 2001 From: Andrew Gait Date: Fri, 19 Nov 2021 12:28:01 +0000 Subject: [PATCH 03/28] Update icub_vor and related examples --- examples/icub_vor_examples/cerebellum_tb.py | 6 +- .../icub_utilities.py | 10 +-- .../icub_vor_env_test.py | 90 +++++++++++++------ .../icub_vor_env_test_200_inputs.py | 0 .../icub_vor_venv_test_perfect_motion.py | 0 .../spinn_gym_examples/spynnaker.cfg | 4 + 6 files changed, 75 insertions(+), 35 deletions(-) rename examples/icub_vor_examples/{ => spinn_gym_examples}/icub_utilities.py (95%) rename examples/icub_vor_examples/{ => spinn_gym_examples}/icub_vor_env_test.py (67%) rename examples/icub_vor_examples/{ => spinn_gym_examples}/icub_vor_env_test_200_inputs.py (100%) rename examples/icub_vor_examples/{ => spinn_gym_examples}/icub_vor_venv_test_perfect_motion.py (100%) create mode 100644 examples/icub_vor_examples/spinn_gym_examples/spynnaker.cfg diff --git a/examples/icub_vor_examples/cerebellum_tb.py b/examples/icub_vor_examples/cerebellum_tb.py index 14bc2e1a..3730a8eb 100644 --- a/examples/icub_vor_examples/cerebellum_tb.py +++ b/examples/icub_vor_examples/cerebellum_tb.py @@ -10,15 +10,15 @@ from pacman.model.constraints.key_allocator_constraints import FixedKeyAndMaskConstraint from pacman.model.graphs.application import ApplicationSpiNNakerLinkVertex from pacman.model.routing_info import BaseKeyAndMask -from spinn_front_end_common.abstract_models.abstract_provides_n_keys_for_partition import AbstractProvidesNKeysForPartition +# from spinn_front_end_common.abstract_models.abstract_provides_n_keys_for_partition import AbstractProvidesNKeysForPartition from spinn_front_end_common.abstract_models.abstract_provides_outgoing_partition_constraints import AbstractProvidesOutgoingPartitionConstraints from spinn_utilities.overrides import overrides from pyNN.utility import Timer from pyNN.utility.plotting import Figure, Panel from pyNN.random import RandomDistribution, NumpyRNG -from spynnaker.pyNN.models.neuron.plasticity.stdp.common \ - import plasticity_helpers +# from spynnaker.pyNN.models.neuron.plasticity.stdp.common \ +# import plasticity_helpers L_RATE = 2 H_RATE = 20 diff --git a/examples/icub_vor_examples/icub_utilities.py b/examples/icub_vor_examples/spinn_gym_examples/icub_utilities.py similarity index 95% rename from examples/icub_vor_examples/icub_utilities.py rename to examples/icub_vor_examples/spinn_gym_examples/icub_utilities.py index 20b21b39..561cc6b4 100644 --- a/examples/icub_vor_examples/icub_utilities.py +++ b/examples/icub_vor_examples/spinn_gym_examples/icub_utilities.py @@ -22,7 +22,7 @@ def get_error(icub_vor_env_pop, simulator): b_vertex = icub_vor_env_pop._vertex error = b_vertex.get_data( 'error', simulator.no_machine_time_steps, simulator.placements, - simulator.buffer_manager, simulator.machine_time_step) + simulator.buffer_manager) return error.tolist() @@ -30,7 +30,7 @@ def get_l_count(icub_vor_env_pop, simulator): b_vertex = icub_vor_env_pop._vertex left_count = b_vertex.get_data( 'l_count', simulator.no_machine_time_steps, simulator.placements, - simulator.buffer_manager, simulator.machine_time_step) + simulator.buffer_manager) return left_count.tolist() @@ -38,7 +38,7 @@ def get_r_count(icub_vor_env_pop, simulator): b_vertex = icub_vor_env_pop._vertex right_count = b_vertex.get_data( 'r_count', simulator.no_machine_time_steps, simulator.placements, - simulator.buffer_manager, simulator.machine_time_step) + simulator.buffer_manager) return right_count.tolist() @@ -46,7 +46,7 @@ def get_eye_pos(icub_vor_env_pop, simulator): b_vertex = icub_vor_env_pop._vertex eye_positions = b_vertex.get_data( 'eye_pos', simulator.no_machine_time_steps, simulator.placements, - simulator.buffer_manager, simulator.machine_time_step) + simulator.buffer_manager) return eye_positions.tolist() @@ -54,7 +54,7 @@ def get_eye_vel(icub_vor_env_pop, simulator): b_vertex = icub_vor_env_pop._vertex eye_velocities = b_vertex.get_data( 'eye_vel', simulator.no_machine_time_steps, simulator.placements, - simulator.buffer_manager, simulator.machine_time_step) + simulator.buffer_manager) return eye_velocities.tolist() diff --git a/examples/icub_vor_examples/icub_vor_env_test.py b/examples/icub_vor_examples/spinn_gym_examples/icub_vor_env_test.py similarity index 67% rename from examples/icub_vor_examples/icub_vor_env_test.py rename to examples/icub_vor_examples/spinn_gym_examples/icub_vor_env_test.py index 212354dc..97989131 100644 --- a/examples/icub_vor_examples/icub_vor_env_test.py +++ b/examples/icub_vor_examples/spinn_gym_examples/icub_vor_env_test.py @@ -1,19 +1,67 @@ import spynnaker8 as p import spinn_gym as gym -from pyNN.utility.plotting import Figure, Panel import matplotlib.pyplot as plt import numpy as np import os from spinn_front_end_common.utilities.globals_variables import get_simulator -from icub_utilities import * -# Parameter definition -runtime = 10000 + +# Examples of get functions for variables +def get_error(icub_vor_env_pop, simulator): + b_vertex = icub_vor_env_pop._vertex + error = b_vertex.get_data( + 'error', simulator.no_machine_time_steps, simulator.placements, + simulator.buffer_manager) + return error.tolist() + + +def get_l_count(icub_vor_env_pop, simulator): + b_vertex = icub_vor_env_pop._vertex + left_count = b_vertex.get_data( + 'l_count', simulator.no_machine_time_steps, simulator.placements, + simulator.buffer_manager) + return left_count.tolist() + + +def get_r_count(icub_vor_env_pop, simulator): + b_vertex = icub_vor_env_pop._vertex + right_count = b_vertex.get_data( + 'r_count', simulator.no_machine_time_steps, simulator.placements, + simulator.buffer_manager) + return right_count.tolist() + + +def get_eye_pos(icub_vor_env_pop, simulator): + b_vertex = icub_vor_env_pop._vertex + eye_positions = b_vertex.get_data( + 'eye_pos', simulator.no_machine_time_steps, simulator.placements, + simulator.buffer_manager) + return eye_positions.tolist() + + +def get_eye_vel(icub_vor_env_pop, simulator): + b_vertex = icub_vor_env_pop._vertex + eye_velocities = b_vertex.get_data( + 'eye_vel', simulator.no_machine_time_steps, simulator.placements, + simulator.buffer_manager) + return eye_velocities.tolist() + + +# Setup +p.setup(timestep=1.0) +# p.set_number_of_neurons_per_core(p.SpikeSourcePoisson, 100) + # Build input SSP and output population -input_size = 2 # neurons -output_size = 200 # neurons -input_rate = 20 # Hz +input_size = 2 +output_size = 200 + +input_rate = 20 +input_pop = p.Population(input_size, p.SpikeSourcePoisson(rate=input_rate), + label='SSP_input') +output_pop = p.Population(output_size, p.SpikeSourcePoisson(rate=0), + label='SSP_output') + # get head_positions and head_velocities from file (1000 samples) base_dir = "./" head_pos = np.loadtxt(os.path.join( @@ -27,27 +75,17 @@ head_pos = (head_pos * 2.0) - 1.0 head_vel = (head_vel * 2.0) - 1.0 - # perfect eye positions and velocities are exactly out of phase with head perfect_eye_pos = np.concatenate((head_pos[500:], head_pos[:500])) perfect_eye_vel = np.concatenate((head_vel[500:], head_vel[:500])) -# TEST # Report 4 points: for i in [0, 250, 500, 750]: print("At {}: head pos {:4.6f}, head vel {:4.6f}, eye pos {:4.6f}, eye vel {:4.6f}".format( i, head_pos[i], head_vel[i], perfect_eye_pos[i], perfect_eye_vel[i])) # build ICubVorEnv model pop -error_window_size = 10 # ms - -# Setup -p.setup(timestep=1.0) - -input_pop = p.Population(input_size, p.SpikeSourcePoisson(rate=input_rate)) -output_pop = p.Population(output_size, p.SpikeSourcePoisson(rate=0)) - -# Instantiate venv +error_window_size = 10 icub_vor_env_model = gym.ICubVorEnv( head_pos, head_vel, perfect_eye_vel, perfect_eye_pos, error_window_size, output_size) @@ -66,16 +104,16 @@ # Store simulator and run simulator = get_simulator() -# Run the simulation +runtime = 10000 p.run(runtime) # Get the data from the ICubVorEnv pop errors = get_error(icub_vor_env_pop=icub_vor_env_pop, simulator=simulator) l_counts = get_l_count(icub_vor_env_pop=icub_vor_env_pop, simulator=simulator) r_counts = get_r_count(icub_vor_env_pop=icub_vor_env_pop, simulator=simulator) -rec_head_pos = get_head_pos( +rec_eye_pos = get_eye_pos( icub_vor_env_pop=icub_vor_env_pop, simulator=simulator) -rec_head_vel = get_head_vel( +rec_eye_vel = get_eye_vel( icub_vor_env_pop=icub_vor_env_pop, simulator=simulator) # get the spike data from input and output and plot @@ -97,12 +135,11 @@ # plot the data from the ICubVorEnv pop x_plot = [(n) for n in range(0, runtime, error_window_size)] -plt.figure(figsize=(15, 11), dpi=300) +plt.figure(figsize=(15, 11)) plt.subplot(5, 1, 1) plt.scatter( [i[1] for i in spikes_in_spin], [i[0] for i in spikes_in_spin], s=1) -plt.legend(loc="best") plt.xlim([0, runtime]) plt.subplot(5, 1, 2) @@ -112,8 +149,8 @@ plt.xlim([0, runtime]) plt.subplot(5, 1, 3) -plt.plot(x_plot, rec_head_pos, label="head position") -plt.plot(x_plot, rec_head_vel, label="head velocity") +plt.plot(x_plot, rec_eye_pos, label="eye position") +plt.plot(x_plot, rec_eye_vel, label="eye velocity") # plt.plot(perfect_eye_pos, label="eye position", ls='--') # plt.plot(perfect_eye_vel, label="eye velocity", ls='--') plt.legend(loc="best") @@ -127,7 +164,6 @@ plt.subplot(5, 1, 5) plt.scatter( [i[1] for i in spikes_out_spin], [i[0] for i in spikes_out_spin], s=1) -plt.legend(loc="best") plt.xlim([0, runtime]) -plt.savefig("spinngym_icub_vor_test.png") + plt.show() diff --git a/examples/icub_vor_examples/icub_vor_env_test_200_inputs.py b/examples/icub_vor_examples/spinn_gym_examples/icub_vor_env_test_200_inputs.py similarity index 100% rename from examples/icub_vor_examples/icub_vor_env_test_200_inputs.py rename to examples/icub_vor_examples/spinn_gym_examples/icub_vor_env_test_200_inputs.py diff --git a/examples/icub_vor_examples/icub_vor_venv_test_perfect_motion.py b/examples/icub_vor_examples/spinn_gym_examples/icub_vor_venv_test_perfect_motion.py similarity index 100% rename from examples/icub_vor_examples/icub_vor_venv_test_perfect_motion.py rename to examples/icub_vor_examples/spinn_gym_examples/icub_vor_venv_test_perfect_motion.py diff --git a/examples/icub_vor_examples/spinn_gym_examples/spynnaker.cfg b/examples/icub_vor_examples/spinn_gym_examples/spynnaker.cfg new file mode 100644 index 00000000..8bbf7d2f --- /dev/null +++ b/examples/icub_vor_examples/spinn_gym_examples/spynnaker.cfg @@ -0,0 +1,4 @@ +[Mapping] + +# Logic doesn't implement delay extensions, so avoid DelaySupportAdder +delay_support_adder = None \ No newline at end of file From a30ee9e6492119e537dcbf5b8680831752d80a7a Mon Sep 17 00:00:00 2001 From: Andrew Gait Date: Fri, 19 Nov 2021 15:05:07 +0000 Subject: [PATCH 04/28] Tidy up icub_vor-related scripts --- examples/icub_vor_examples/cerebellum.py | 202 ++++++----- examples/icub_vor_examples/cerebellum_tb.py | 284 ++++++++------- examples/icub_vor_examples/dataflow.py | 66 ++-- .../icub_vor_examples/pb_cerebellum_tb.py | 327 ++++++++++-------- ...e_cell_test.pysingle_purkinje_cell_test.py | 52 ++- .../receptive_fields_for_motion.py | 35 +- .../single_purkinje_cell_pf_windowing.py | 72 ++-- .../single_purkinje_cell_potentiation_test.py | 58 ++-- .../single_purkinje_cell_test.py | 65 ++-- .../single_vestibular_nuclei_mf_windowing.py | 80 +++-- ...vestibular_nuclei_mf_windowing_3_spikes.py | 79 +++-- ...gle_vestibular_nuclei_potentiation_test.py | 53 ++- .../spinn_gym_examples/icub_utilities.py | 41 ++- .../spinn_gym_examples/icub_vor_env_test.py | 21 +- .../icub_vor_env_test_200_inputs.py | 39 ++- .../icub_vor_venv_test_perfect_motion.py | 44 ++- examples/icub_vor_examples/test_mfvn_lut.py | 15 + examples/icub_vor_examples/test_pfpc_lut.py | 15 + 18 files changed, 956 insertions(+), 592 deletions(-) diff --git a/examples/icub_vor_examples/cerebellum.py b/examples/icub_vor_examples/cerebellum.py index 7143cbf9..29af7a82 100644 --- a/examples/icub_vor_examples/cerebellum.py +++ b/examples/icub_vor_examples/cerebellum.py @@ -1,23 +1,37 @@ -import socket +# Copyright (c) 2019-2021 The University of Manchester +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# import socket import spynnaker8 as sim import numpy as np -#import logging +# import logging import matplotlib.pyplot as plt #from spynnaker8.utilities import DataHolder -from pacman.model.constraints.key_allocator_constraints import FixedKeyAndMaskConstraint +from pacman.model.constraints.key_allocator_constraints import ( + FixedKeyAndMaskConstraint) from pacman.model.graphs.application import ApplicationSpiNNakerLinkVertex from pacman.model.routing_info import BaseKeyAndMask -# from spinn_front_end_common.abstract_models.abstract_provides_n_keys_for_partition import AbstractProvidesNKeysForPartition -from spinn_front_end_common.abstract_models.abstract_provides_outgoing_partition_constraints import AbstractProvidesOutgoingPartitionConstraints +from spinn_front_end_common.abstract_models.\ + abstract_provides_outgoing_partition_constraints import ( + AbstractProvidesOutgoingPartitionConstraints) from spinn_utilities.overrides import overrides from pyNN.utility import Timer from pyNN.utility.plotting import Figure, Panel from pyNN.random import RandomDistribution, NumpyRNG -# from spynnaker.pyNN.models.neuron.plasticity.stdp.common \ -# import plasticity_helpers - # cerebellum with simulated input RETINA_X_SIZE = 304 RETINA_Y_SIZE = 240 @@ -75,7 +89,6 @@ input_weights = 0.00025 mf_go_weights = 0.0006 - # Network parameters num_MF_neurons = 100 num_GC_neurons = 2000 @@ -85,22 +98,27 @@ num_IO_neurons = 200 # Random distribution for synapses delays and weights (MF and GO) -delay_distr = RandomDistribution('uniform', (1.0, 10.0), rng=NumpyRNG(seed=85524)) -weight_distr_MF = RandomDistribution('uniform', (mf_gc_weights*0.8, mf_gc_weights*1.2), rng=NumpyRNG(seed=85524)) -weight_distr_GO = RandomDistribution('uniform', (go_gc_weights*0.8, go_gc_weights*1.2), rng=NumpyRNG(seed=24568)) +delay_distr = RandomDistribution('uniform', (1.0, 10.0), + rng=NumpyRNG(seed=85524)) +weight_distr_MF = RandomDistribution( + 'uniform', (mf_gc_weights*0.8, mf_gc_weights*1.2), + rng=NumpyRNG(seed=85524)) +weight_distr_GO = RandomDistribution( + 'uniform', (go_gc_weights*0.8, go_gc_weights*1.2), + rng=NumpyRNG(seed=24568)) # Post-synapse population neuron_params = { "v_thresh": -50, "v_reset": -70, "v_rest": -65, - "i_offset": 0 # DC input - } + "i_offset": 0 # DC input +} # Learning parameters cos rule (MF to VN) min_weight_c = 0 max_weight_c = 0.1 -pot_alpha_c = 0.01 # this is alpha in the paper +pot_alpha_c = 0.01 # this is alpha in the paper beta_c = 11 sigma_c = 201 initial_weight_c = 0.005 @@ -120,9 +138,11 @@ # set up input populations # num_pxl = 304 * 240; -# retina_pop = sim.Population(1024, ICUBInputVertexDataHolder(spinnaker_link_id=0), label='pop_retina') +# retina_pop = sim.Population( +# 1024, ICUBInputVertexDataHolder(spinnaker_link_id=0), label='pop_retina') -# Sensorial Activity: input activity from vestibulus (will come from the head IMU, now it is a test bench) +# Sensorial Activity: input activity from vestibulus (will come from the head +# IMU, now it is a test bench) def sensorial_activity(pt): MAX_AMPLITUDE = 0.8 RELATIVE_AMPLITUDE = 1.0 @@ -131,7 +151,8 @@ def sensorial_activity(pt): i = np.arange(0,2,0.01) for t in i: - desired_speed=-np.cos(t*2*np.pi)*MAX_AMPLITUDE*RELATIVE_AMPLITUDE*2.0*np.pi + desired_speed=-np.cos( + t*2*np.pi)*MAX_AMPLITUDE*RELATIVE_AMPLITUDE*2.0*np.pi desired_pos=-np.sin(t*2*np.pi)*MAX_AMPLITUDE*RELATIVE_AMPLITUDE _head_pos.append(desired_pos) _head_vel.append(desired_speed) @@ -160,12 +181,14 @@ def sensorial_activity(pt): for i in range(50): mean = float(i) / 50.0 + 0.01 - gaussian = np.exp(-((head_pos - mean) * (head_pos - mean))/(2.0 * sigma * sigma)) + gaussian = np.exp( + -((head_pos - mean) * (head_pos - mean))/(2.0 * sigma * sigma)) MF_pos_activity[i] = min_rate + gaussian * (max_rate - min_rate) for i in range(50): mean = float(i) / 50.0 + 0.01 - gaussian = np.exp(-((head_vel - mean) * (head_vel - mean))/(2.0 * sigma * sigma)) + gaussian = np.exp( + -((head_vel - mean) * (head_vel - mean))/(2.0 * sigma * sigma)) MF_vel_activity[i] = min_rate + gaussian * (max_rate - min_rate) #sa_mean_freq = np.arange(0,1000,10) @@ -185,14 +208,20 @@ def compute_D_error(kd, head_velocity, eye_velocity): MAX_AMPLITUDE = 0.8 MAX_AMPLITUDE_EYE = 0.35 RELATIVE_AMPLITUDE_EYE = 1.0 - phaseShift = 1.0*np.pi # simulated error between eye and head signals, error is zero if the waves are in opposite phase + phaseShift = 1.0*np.pi + # simulated error between eye and head signals, error is zero if the waves + # are in opposite phase _eye_pos = [] _eye_vel = [] ea_rate = [] i = np.arange(0,2,0.01) for t_eye in i: - desired_speed = -np.cos(t_eye*2*np.pi+phaseShift) * MAX_AMPLITUDE_EYE * RELATIVE_AMPLITUDE_EYE * 2.0 * np.pi - desired_pos = -np.sin(t_eye*2*np.pi+phaseShift) * MAX_AMPLITUDE_EYE * RELATIVE_AMPLITUDE_EYE + desired_speed = -np.cos( + t_eye*2*np.pi+phaseShift) * MAX_AMPLITUDE_EYE * \ + RELATIVE_AMPLITUDE_EYE * 2.0 * np.pi + desired_pos = -np.sin( + t_eye*2*np.pi+phaseShift) * MAX_AMPLITUDE_EYE * \ + RELATIVE_AMPLITUDE_EYE _eye_pos.append(desired_pos) _eye_vel.append(desired_speed) @@ -205,15 +234,16 @@ def compute_D_error(kd, head_velocity, eye_velocity): head_pos = head[1] head_vel = head[2] - #print head_pos, eye_pos + # print(head_pos, eye_pos) kp=15.0 position_error = compute_P_error(kp, head_pos, eye_pos) kd=15.0 velocity_error = compute_D_error(kd, head_vel, eye_vel) - error=(position_error * 0.1 + (velocity_error/(2.0*np.pi)) * 0.9)/(MAX_AMPLITUDE*5) + error=(position_error * 0.1 + ( + velocity_error/(2.0*np.pi)) * 0.9)/(MAX_AMPLITUDE*5) - #print position_error, velocity_error, error + # print(position_error, velocity_error, error) min_rate = 1.0 max_rate = 25.0 @@ -221,7 +251,7 @@ def compute_D_error(kd, head_velocity, eye_velocity): # err = [1] for j in range(len(err)): error_ = err[j] - #print error_ + # print(error) low_neuron_ID_threshold = abs(error_) * 100.0 up_neuron_ID_threshold = low_neuron_ID_threshold - 100.0 IO_agonist = np.zeros((100)) @@ -232,7 +262,9 @@ def compute_D_error(kd, head_velocity, eye_velocity): if(i < up_neuron_ID_threshold): rate.append(max_rate) elif(i. + +from __future__ import print_function # for python3 printing in python2 +# import socket import spynnaker8 as sim import numpy as np -#import logging +# import logging import matplotlib.pyplot as plt - -#from spynnaker8.utilities import DataHolder -from pacman.model.constraints.key_allocator_constraints import FixedKeyAndMaskConstraint +# from spynnaker8.utilities import DataHolder +# from pacman.model.constraints.key_allocator_constraints import ( +# FixedKeyAndMaskConstraint) from pacman.model.graphs.application import ApplicationSpiNNakerLinkVertex -from pacman.model.routing_info import BaseKeyAndMask -# from spinn_front_end_common.abstract_models.abstract_provides_n_keys_for_partition import AbstractProvidesNKeysForPartition -from spinn_front_end_common.abstract_models.abstract_provides_outgoing_partition_constraints import AbstractProvidesOutgoingPartitionConstraints -from spinn_utilities.overrides import overrides -from pyNN.utility import Timer +# from pacman.model.routing_info import BaseKeyAndMask +# from spinn_front_end_common.abstract_models.\ +# abstract_provides_n_keys_for_partition import ( +# AbstractProvidesNKeysForPartition) +# from spinn_front_end_common.abstract_models.\ +# abstract_provides_outgoing_partition_constraints import ( +# AbstractProvidesOutgoingPartitionConstraints) +# from spinn_utilities.overrides import overrides +# from pyNN.utility import Timer from pyNN.utility.plotting import Figure, Panel from pyNN.random import RandomDistribution, NumpyRNG -# from spynnaker.pyNN.models.neuron.plasticity.stdp.common \ -# import plasticity_helpers - L_RATE = 2 H_RATE = 20 @@ -45,11 +61,14 @@ num_CF_neurons = 200 # Random distribution for synapses delays and weights (MF and GO) -delay_distr = RandomDistribution('uniform', (1.0, 10.0), rng=NumpyRNG(seed=85524)) -weight_distr_MF = RandomDistribution('uniform', (mf_gc_weights*0.8, mf_gc_weights*1.2), rng=NumpyRNG(seed=85524)) -weight_distr_GO = RandomDistribution('uniform', - (go_gc_weights*0.8, go_gc_weights*1.2), - rng=NumpyRNG(seed=24568)) +delay_distr = RandomDistribution('uniform', (1.0, 10.0), + rng=NumpyRNG(seed=85524)) +weight_distr_MF = RandomDistribution( + 'uniform', (mf_gc_weights*0.8, mf_gc_weights*1.2), + rng=NumpyRNG(seed=85524)) +weight_distr_GO = RandomDistribution( + 'uniform', (go_gc_weights*0.8, go_gc_weights*1.2), + rng=NumpyRNG(seed=24568)) # Post-synapse population @@ -57,16 +76,16 @@ "v_thresh": -50, "v_reset": -70, "v_rest": -65, - "i_offset": 0 # DC input - } + "i_offset": 0 # DC input +} # Learning parameters cos rule (MF to VN) min_weight_c = 0 max_weight_c = 0.005 -pot_alpha_c = 0.001 # this is alpha in the paper +pot_alpha_c = 0.001 # this is alpha in the paper beta_c = 11 sigma_c = 201 -initial_weight_c = 0.001 # max_weight_c #0.0005 +initial_weight_c = 0.001 # max_weight_c # 0.0005 # initial_weight_c = 0.05 plastic_delay_c = 4 @@ -75,25 +94,23 @@ max_weight_s = 0.01 pot_alpha_s =0.01 t_peak_s =100 -initial_weight_s = max_weight_s #0.0001 +initial_weight_s = max_weight_s # 0.0001 plastic_delay_s = 4 weight_dist_pfpc = RandomDistribution('uniform', (initial_weight_s*0.8, initial_weight_s*1.2), rng=NumpyRNG(seed=24534)) - sim.setup(timestep=1.) - - - -# Sensorial Activity: input activity from vestibulus (will come from the head IMU, now it is a test bench) -# We simulate the output of the head encoders with a sinusoidal function. Each "sensorial activity" value is derived from the -# head position and velocity. From that value, we generate the mean firing rate of the MF neurons (later this will be an input -# that will come from the robot, through the spinnLink) -# the neurons that are active depend on the value of the sensorial activity. For each a gaussian is created centered on a specific neuron - +# Sensorial Activity: input activity from vestibulus (will come from the head +# IMU, now it is a test bench) +# We simulate the output of the head encoders with a sinusoidal function. Each +# "sensorial activity" value is derived from the head position and velocity. +# From that value, we generate the mean firing rate of the MF neurons (later +# this will be an input that will come from the robot, through the spinnLink) +# the neurons that are active depend on the value of the sensorial activity. +# For each a gaussian is created centered on a specific neuron. # Prepare variables once at beginning MAX_AMPLITUDE = 0.8 @@ -109,9 +126,8 @@ _head_vel.append(desired_speed) -def sensorial_activity(pt): # pt is a single point in time at which we measure the head encoder's output - - +def sensorial_activity(pt): + # pt is a single time point at which we measure the head encoder's output # single point over time head_pos = _head_pos[pt] head_vel = _head_vel[pt] @@ -134,15 +150,18 @@ def sensorial_activity(pt): # pt is a single point in time at which we measure t MF_pos_activity = np.zeros((50)) MF_vel_activity = np.zeros((50)) - # generate gaussian distributions around the neuron tuned to a given sensorial activity + # generate gaussian distributions around the neuron tuned to a given + # sensorial activity for i in range(50): mean = float(i) / 50.0 + 0.01 - gaussian = np.exp(-((head_pos - mean) * (head_pos - mean))/(2.0 * sigma * sigma)) + gaussian = np.exp( + -((head_pos - mean) * (head_pos - mean))/(2.0 * sigma * sigma)) MF_pos_activity[i] = min_rate + gaussian * (max_rate - min_rate) for i in range(50): mean = float(i) / 50.0 + 0.01 - gaussian = np.exp(-((head_vel - mean) * (head_vel - mean))/(2.0 * sigma * sigma)) + gaussian = np.exp( + -((head_vel - mean) * (head_vel - mean))/(2.0 * sigma * sigma)) MF_vel_activity[i] = min_rate + gaussian * (max_rate - min_rate) sa_mean_freq = np.concatenate((MF_pos_activity, MF_vel_activity)) @@ -152,30 +171,32 @@ def sensorial_activity(pt): # pt is a single point in time at which we measure t # Error Activity: error from eye and head encoders def error_activity(error_): -# min_rate = 1.0 -# max_rate = 25.0 -# -# low_neuron_ID_threshold = abs(error_) * 100.0 -# up_neuron_ID_threshold = low_neuron_ID_threshold - 100.0 + # min_rate = 1.0 + # max_rate = 25.0 + # + # low_neuron_ID_threshold = abs(error_) * 100.0 + # up_neuron_ID_threshold = low_neuron_ID_threshold - 100.0 IO_agonist = np.zeros((100)) IO_antagonist = np.zeros((100)) -# -# rate = [] -# for i in range (100): -# if(i < up_neuron_ID_threshold): -# rate.append(max_rate) -# elif(i=0.0: -# IO_agonist[0:100]=min_rate -# IO_antagonist=rate -# else: -# IO_antagonist[0:100]=min_rate -# IO_agonist=rate + + # rate = [] + # for i in range (100): + # if(i < up_neuron_ID_threshold): + # rate.append(max_rate) + # elif(i=0.0: + # IO_agonist[0:100]=min_rate + # IO_antagonist=rate + # else: + # IO_antagonist[0:100]=min_rate + # IO_agonist=rate IO_agonist[:] = H_RATE IO_antagonist[:] = L_RATE @@ -186,7 +207,8 @@ def error_activity(error_): def process_VN_spiketrains(VN_spikes, t_start): total_spikes = 0 for spiketrain in VN_spikes.segments[0].spiketrains: - s = spiketrain.as_array()[np.where(spiketrain.as_array() >= t_start)[0]] + s = spiketrain.as_array()[ + np.where(spiketrain.as_array() >= t_start)[0]] total_spikes += len(s) return total_spikes @@ -196,48 +218,52 @@ def process_VN_spiketrains(VN_spikes, t_start): # Create Populations ############################################################### -# Create MF population - fake input population that will be substituted by external input from robot +# Create MF population - fake input population that will be substituted by +# external input from robot -MF_population = sim.Population(num_MF_neurons, # number of sources - sim.SpikeSourcePoisson, # source type - #{'rate': sa_mean_freq}, # source spike times - {'rate': sensorial_activity(0)[0]}, # source spike times - label="MFLayer" # identifier - ) +MF_population = sim.Population( + num_MF_neurons, # number of sources + sim.SpikeSourcePoisson, # source type + # {'rate': sa_mean_freq}, # source spike times + {'rate': sensorial_activity(0)[0]}, # source spike times + label="MFLayer" # identifier + ) # Create GOC population -GOC_population = sim.Population(num_GOC_neurons, sim.IF_cond_exp() ,label='GOCLayer') +GOC_population = sim.Population(num_GOC_neurons, sim.IF_cond_exp(), + label='GOCLayer') # create PC population -PC_population = sim.Population(num_PC_neurons, # number of neurons - sim.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model - label="Purkinje Cell" # identifier - ) +PC_population = sim.Population( + num_PC_neurons, # number of neurons + sim.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model + label="Purkinje Cell" # identifier + ) # create VN population -VN_population = sim.Population(num_VN_neurons, # number of neurons - sim.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model - label="Vestibular Nuclei" # identifier - ) - - - +VN_population = sim.Population( + num_VN_neurons, # number of neurons + sim.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model + label="Vestibular Nuclei" # identifier + ) # Create GrC population -GC_population = sim.Population(num_GC_neurons, sim.IF_curr_exp(), label='GCLayer') - - - -# generate fake error (it should be calculated from sensorial activity in error activity, but we skip it and just generate an error from -1.5 to 1.5) -err = -0.7 # other values to test: -0.3 0 0.3 0.7 - -# Create CF population - fake input population that will be substituted by external input from robot -CF_population = sim.Population(num_CF_neurons, # number of sources - sim.SpikeSourcePoisson, # source type - #{'rate': sa_mean_freq}, # source spike times - {'rate': error_activity(err)}, # source spike times - label="CFLayer" # identifier - ) +GC_population = sim.Population(num_GC_neurons, sim.IF_curr_exp(), + label='GCLayer') + +# generate fake error (it should be calculated from sensorial activity in error +# activity, but we skip it and just generate an error from -1.5 to 1.5) +err = -0.7 # other values to test: -0.3 0 0.3 0.7 + +# Create CF population - fake input population that will be substituted by +# external input from robot +CF_population = sim.Population( + num_CF_neurons, # number of sources + sim.SpikeSourcePoisson, # source type + # {'rate': sa_mean_freq}, # source spike times + {'rate': error_activity(err)}, # source spike times + label="CFLayer" # identifier + ) ############################################################### # Create connections @@ -247,19 +273,21 @@ def process_VN_spiketrains(VN_spikes, t_start): mf_go_connections = sim.Projection(MF_population, GOC_population, sim.OneToOneConnector(), - sim.StaticSynapse(delay=delay_distr, weight=mf_go_weights), + sim.StaticSynapse(delay=delay_distr, + weight=mf_go_weights), receptor_type='excitatory') - # Create MF-GC and GO-GC connections float_num_MF_neurons = float (num_MF_neurons) list_GOC_GC = [] list_MF_GC = [] list_GOC_GC_2 = [] -# projections to subpopulations https://github.com/SpiNNakerManchester/sPyNNaker8/issues/168) +# projections to subpopulations +# https://github.com/SpiNNakerManchester/sPyNNaker8/issues/168) for i in range (num_MF_neurons): - GC_medium_index = int(round((i / float_num_MF_neurons ) * num_GC_neurons)) + GC_medium_index = int( + round((i / float_num_MF_neurons ) * num_GC_neurons)) GC_lower_index = GC_medium_index - 40 GC_upper_index = GC_medium_index + 60 @@ -308,25 +336,24 @@ def process_VN_spiketrains(VN_spikes, t_start): # Create PC-VN connections -pc_vn_connections = sim.Projection(PC_population, - VN_population, - sim.OneToOneConnector(), - #receptor_type='GABA', # Should these be inhibitory? - synapse_type = sim.StaticSynapse(delay=delay_distr, weight=pc_vn_weights), - receptor_type='inhibitory') +pc_vn_connections = sim.Projection( + PC_population, VN_population, sim.OneToOneConnector(), + # receptor_type='GABA', # Should these be inhibitory? + synapse_type = sim.StaticSynapse(delay=delay_distr, weight=pc_vn_weights), + receptor_type='inhibitory') # Create MF-VN learning rule - cos mfvn_plas = sim.STDPMechanism( timing_dependence=sim.extra_models.TimingDependenceMFVN(beta=beta_c, - sigma=sigma_c), - weight_dependence=sim.extra_models.WeightDependenceMFVN(w_min=min_weight_c, - w_max=max_weight_c, - pot_alpha=pot_alpha_c), + sigma=sigma_c), + weight_dependence=sim.extra_models.WeightDependenceMFVN( + w_min=min_weight_c, w_max=max_weight_c, pot_alpha=pot_alpha_c), weight=initial_weight_c, delay=delay_distr) # Create MF to VN connections mf_vn_connections = sim.Projection( - MF_population, VN_population, sim.AllToAllConnector(), # Needs mapping as FromListConnector to make efficient + MF_population, VN_population, sim.AllToAllConnector(), + # Needs mapping as FromListConnector to make efficient synapse_type=mfvn_plas, receptor_type="excitatory") @@ -334,14 +361,13 @@ def process_VN_spiketrains(VN_spikes, t_start): pc_vn_connections = sim.Projection( PC_population, VN_population, sim.OneToOneConnector(), sim.StaticSynapse(weight=0.0, delay=1.0), - receptor_type="excitatory") # "TEACHING SIGNAL" + receptor_type="excitatory") # "TEACHING SIGNAL" # create PF-PC learning rule - sin pfpc_plas = sim.STDPMechanism( timing_dependence=sim.extra_models.TimingDependencePFPC(t_peak=t_peak_s), - weight_dependence=sim.extra_models.WeightDependencePFPC(w_min=min_weight_s, - w_max=max_weight_s, - pot_alpha=pot_alpha_s), + weight_dependence=sim.extra_models.WeightDependencePFPC( + w_min=min_weight_s, w_max=max_weight_s, pot_alpha=pot_alpha_s), weight=initial_weight_s, delay=delay_distr ) @@ -352,13 +378,14 @@ def process_VN_spiketrains(VN_spikes, t_start): synapse_type=pfpc_plas, receptor_type="excitatory") -# Create IO-PC connections. This synapse with "receptor_type=COMPLEX_SPIKE" propagates the learning signals that drive the plasticity mechanisms in GC-PC synapses -cf_pc_connections = sim.Projection(CF_population, - PC_population, - sim.OneToOneConnector(), - #receptor_type='COMPLEX_SPIKE', - synapse_type = sim.StaticSynapse(delay=1.0, weight=cf_pc_weights), - receptor_type='excitatory') +# Create IO-PC connections. This synapse with "receptor_type=COMPLEX_SPIKE" +# propagates the learning signals that drive the plasticity mechanisms in +# GC-PC synapses +cf_pc_connections = sim.Projection( + CF_population, PC_population, sim.OneToOneConnector(), + # receptor_type='COMPLEX_SPIKE', + synapse_type = sim.StaticSynapse(delay=1.0, weight=cf_pc_weights), + receptor_type='excitatory') # lif_pop = sim.Population(1024, sim.IF_curr_exp(), label='pop_lif') # @@ -371,7 +398,7 @@ def process_VN_spiketrains(VN_spikes, t_start): # synapse_type=sim.StaticSynapse(weight=0.1)) # # -# # live output of the input vertex (retina_pop) to the first pynn population (lif_pop) +# # live output of the input (retina_pop) to the first population (lif_pop) # sim.external_devices.activate_live_output_to(out_pop,retina_pop) # # @@ -412,10 +439,6 @@ def process_VN_spiketrains(VN_spikes, t_start): MF_population.set(rate=sensorial_activity(total_runtime)[0]) - - - - # sim.run(runtime*0.4) # # CF_rates=[] @@ -443,18 +466,15 @@ def process_VN_spiketrains(VN_spikes, t_start): # CF_rates.extend(upper_rate) # CF_population.set(rate=CF_rates) - - total_runtime = runtime*repeats MF_spikes = MF_population.get_data('spikes') CF_spikes = CF_population.get_data('spikes') GC_spikes = GC_population.get_data('all') GOC_spikes = GOC_population.get_data('spikes') -VN_spikes = VN_population.get_data('all') # VN_population.get_data('spikes') +VN_spikes = VN_population.get_data('all') # VN_population.get_data('spikes') PC_spikes = PC_population.get_data('spikes') - mfvn_weights = mf_vn_connections.get('weight', 'list', with_address=False) pfpc_weights = pf_pc_connections.get('weight', 'list', with_address=False) @@ -501,4 +521,4 @@ def process_VN_spiketrains(VN_spikes, t_start): plt.show() sim.end() -print("job done") \ No newline at end of file +print("job done") diff --git a/examples/icub_vor_examples/dataflow.py b/examples/icub_vor_examples/dataflow.py index 9a79baa7..cf2199ef 100644 --- a/examples/icub_vor_examples/dataflow.py +++ b/examples/icub_vor_examples/dataflow.py @@ -1,34 +1,51 @@ -import socket +# Copyright (c) 2019-2021 The University of Manchester +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# import socket import spynnaker8 as sim -import numpy as np -#import logging +# import numpy as np +# import logging import matplotlib.pyplot as plt -from pacman.model.constraints.key_allocator_constraints import FixedKeyAndMaskConstraint +from pacman.model.constraints.key_allocator_constraints import ( + FixedKeyAndMaskConstraint) from pacman.model.graphs.application import ApplicationSpiNNakerLinkVertex from pacman.model.routing_info import BaseKeyAndMask -# from spinn_front_end_common.abstract_models.abstract_provides_n_keys_for_partition import AbstractProvidesNKeysForPartition -from spinn_front_end_common.abstract_models.abstract_provides_outgoing_partition_constraints import AbstractProvidesOutgoingPartitionConstraints +from spinn_front_end_common.abstract_models.\ + abstract_provides_outgoing_partition_constraints import ( + AbstractProvidesOutgoingPartitionConstraints) from spinn_utilities.overrides import overrides -from spinn_front_end_common.abstract_models.abstract_provides_incoming_partition_constraints import AbstractProvidesIncomingPartitionConstraints -from pacman.executor.injection_decorator import inject_items -from pacman.operations.routing_info_allocator_algorithms.malloc_based_routing_allocator.utils import get_possible_masks -from spinn_front_end_common.utility_models.command_sender_machine_vertex import CommandSenderMachineVertex +from spinn_front_end_common.abstract_models.\ + abstract_provides_incoming_partition_constraints import ( + AbstractProvidesIncomingPartitionConstraints) +from pacman.operations.routing_info_allocator_algorithms.\ + malloc_based_routing_allocator.utils import get_possible_masks +from spinn_front_end_common.utility_models.command_sender_machine_vertex \ + import CommandSenderMachineVertex from spinn_front_end_common.abstract_models \ import AbstractSendMeMulticastCommandsVertex from spinn_front_end_common.utility_models.multi_cast_command \ import MultiCastCommand - from pyNN.utility import Timer from pyNN.utility.plotting import Figure, Panel from pyNN.random import RandomDistribution, NumpyRNG -# from spynnaker.pyNN.models.neuron.plasticity.stdp.common import plasticity_helpers - -NUM_NEUR_IN = 1024 #1024 # 2x240x304 mask -> 0xFFFE0000 -MASK_IN = 0xFFFFFC00 #0xFFFFFC00 +NUM_NEUR_IN = 1024 # 1024 # 2x240x304 mask -> 0xFFFE0000 +MASK_IN = 0xFFFFFC00 # 0xFFFFFC00 NUM_NEUR_OUT = 1024 #MASK_OUT =0xFFFFFC00 @@ -54,9 +71,8 @@ def __init__(self, spinnaker_link_id, board_address=None, def get_outgoing_partition_constraints(self, partition): return [FixedKeyAndMaskConstraint( keys_and_masks=[BaseKeyAndMask( - base_key=0, #upper part of the key, + base_key=0, # upper part of the key, mask=MASK_IN)])] - #keys, i.e. neuron addresses of the input population that sits in the ICUB vertex, @overrides(AbstractProvidesIncomingPartitionConstraints. get_incoming_partition_constraints) @@ -94,18 +110,22 @@ def timed_commands(self): # sim.set_number_of_neurons_per_core(sim.IF_curr_exp, 32) # set up populations, -pop = sim.Population(None, ICUBInputVertex(spinnaker_link_id=0), label='pop_in') +pop = sim.Population(None, ICUBInputVertex(spinnaker_link_id=0), + label='pop_in') #neural population , -neuron_pop = sim.Population(NUM_NEUR_OUT, sim.IF_curr_exp(), label='neuron_pop') +neuron_pop = sim.Population(NUM_NEUR_OUT, sim.IF_curr_exp(), + label='neuron_pop') -sim.Projection(pop, neuron_pop, sim.OneToOneConnector(), sim.StaticSynapse(weight=20.0)) +sim.Projection(pop, neuron_pop, sim.OneToOneConnector(), + sim.StaticSynapse(weight=20.0)) -#pop_out = sim.Population(None, ICUBOutputVertex(spinnaker_link_id=0), label='pop_out') +# pop_out = sim.Population(None, ICUBOutputVertex(spinnaker_link_id=0), +# label='pop_out') sim.external_devices.activate_live_output_to(neuron_pop,pop) -#recordings and simulations, +# recordings and simulations # neuron_pop.record("spikes") # simtime = 30000 #ms, @@ -114,7 +134,7 @@ def timed_commands(self): # continuous run until key press # remember: do NOT record when running in this mode sim.external_devices.run_forever() -raw_input('Press enter to stop') +input('Press enter to stop') # exc_spikes = neuron_pop.get_data("spikes") # diff --git a/examples/icub_vor_examples/pb_cerebellum_tb.py b/examples/icub_vor_examples/pb_cerebellum_tb.py index 5077e007..dcb74d11 100644 --- a/examples/icub_vor_examples/pb_cerebellum_tb.py +++ b/examples/icub_vor_examples/pb_cerebellum_tb.py @@ -1,3 +1,18 @@ +# Copyright (c) 2019-2021 The University of Manchester +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + from __future__ import print_function import spynnaker8 as sim import numpy as np @@ -11,12 +26,12 @@ # PAB imports import traceback -import pandas as pd +# import pandas as pd import os import neo -import copy +# import copy -# ============================ MAKING THINGS LOOK CONSISTENT ============================ +# ====================== MAKING THINGS LOOK CONSISTENT ======================== # ensure we use viridis as the default cmap plt.viridis() @@ -35,7 +50,6 @@ 'vn' ] - # PAB UTILS def get_plot_order(for_keys): # Compute plot order @@ -135,11 +149,14 @@ def save_figure(plt, name, extensions=(".png",), **kwargs): num_CF_neurons = 200 # Random distribution for synapses delays and weights (MF and GO) -delay_distr = RandomDistribution('uniform', (1.0, 10.0), rng=NumpyRNG(seed=85524)) -weight_distr_MF = RandomDistribution('uniform', (mf_gc_weights * 0.8, mf_gc_weights * 1.2), rng=NumpyRNG(seed=85524)) -weight_distr_GO = RandomDistribution('uniform', - (go_gc_weights * 0.8, go_gc_weights * 1.2), - rng=NumpyRNG(seed=24568)) +delay_distr = RandomDistribution( + 'uniform', (1.0, 10.0), rng=NumpyRNG(seed=85524)) +weight_distr_MF = RandomDistribution( + 'uniform', (mf_gc_weights * 0.8, mf_gc_weights * 1.2), + rng=NumpyRNG(seed=85524)) +weight_distr_GO = RandomDistribution( + 'uniform', (go_gc_weights * 0.8, go_gc_weights * 1.2), + rng=NumpyRNG(seed=24568)) # Post-synapse population neuron_params = { @@ -200,17 +217,22 @@ def save_figure(plt, name, extensions=(".png",), **kwargs): sim.setup(timestep=1., min_delay=1, max_delay=15) global_n_neurons_per_core = 64 -sim.set_number_of_neurons_per_core(sim.SpikeSourcePoisson, global_n_neurons_per_core) -sim.set_number_of_neurons_per_core(sim.SpikeSourceArray, global_n_neurons_per_core) +sim.set_number_of_neurons_per_core( + sim.SpikeSourcePoisson, global_n_neurons_per_core) +sim.set_number_of_neurons_per_core( + sim.SpikeSourceArray, global_n_neurons_per_core) sim.set_number_of_neurons_per_core(sim.IF_cond_exp, global_n_neurons_per_core) -sim.set_number_of_neurons_per_core(sim.extra_models.IFCondExpCerebellum, global_n_neurons_per_core) - -# Sensorial Activity: input activity from vestibulus (will come from the head IMU, now it is a test bench) -# We simulate the output of the head encoders with a sinusoidal function. Each "sensorial activity" value is derived from the -# head position and velocity. From that value, we generate the mean firing rate of the MF neurons (later this will be an input -# that will come from the robot, through the spinnLink) -# the neurons that are active depend on the value of the sensorial activity. For each a gaussian is created centered on a specific neuron - +sim.set_number_of_neurons_per_core( + sim.extra_models.IFCondExpCerebellum, global_n_neurons_per_core) + +# Sensorial Activity: input activity from vestibulus (will come from the head +# IMU, now it is a test bench) +# We simulate the output of the head encoders with a sinusoidal function. +# Each "sensorial activity" value is derived from the head position and +# velocity. From that value, we generate the mean firing rate of the MF neurons +# (later this will be an input that will come from the robot, through the +# spinnLink) the neurons that are active depend on the value of the sensorial +# activity. For each a gaussian is created centered on a specific neuron. # Prepare variables once at beginning MAX_AMPLITUDE = 0.8 @@ -220,8 +242,10 @@ def save_figure(plt, name, extensions=(".png",), **kwargs): i = np.arange(0, 1000, 0.001) for t in i: - desired_speed = -np.cos(t * 2 * np.pi) * MAX_AMPLITUDE * RELATIVE_AMPLITUDE * 2.0 * np.pi - desired_pos = -np.sin(t * 2 * np.pi) * MAX_AMPLITUDE * RELATIVE_AMPLITUDE + desired_speed = -np.cos( + t * 2 * np.pi) * MAX_AMPLITUDE * RELATIVE_AMPLITUDE * 2.0 * np.pi + desired_pos = -np.sin( + t * 2 * np.pi) * MAX_AMPLITUDE * RELATIVE_AMPLITUDE _head_pos.append(desired_pos) _head_vel.append(desired_speed) @@ -230,7 +254,8 @@ def save_figure(plt, name, extensions=(".png",), **kwargs): plt.xlim([0, 1000]) plt.title("Pre-computed head positions") plt.tight_layout() -save_figure(plt, os.path.join(fig_folder, "head_positions"), extensions=['.png', ]) +save_figure(plt, os.path.join(fig_folder, "head_positions"), + extensions=['.png', ]) plt.close(f) f = plt.figure(1, figsize=(9, 9), dpi=400) @@ -238,11 +263,13 @@ def save_figure(plt, name, extensions=(".png",), **kwargs): plt.xlim([0, 1000]) plt.title("Pre-computed head velocities") plt.tight_layout() -save_figure(plt, os.path.join(fig_folder, "head_velocities"), extensions=['.png', ]) +save_figure(plt, os.path.join(fig_folder, "head_velocities"), + extensions=['.png', ]) plt.close(f) normalised_head_pos = (np.asarray(_head_pos) + 0.8) / 1.6 -normalised_head_vel = (np.asarray(_head_vel) + 0.8 * 2 * np.pi) / (1.6 * 2 * np.pi) +normalised_head_vel = ( + np.asarray(_head_vel) + 0.8 * 2 * np.pi) / (1.6 * 2 * np.pi) f = plt.figure(1, figsize=(9, 9), dpi=400) plt.plot(((np.asarray(_head_pos) + 0.8) / 1.6)) @@ -251,7 +278,8 @@ def save_figure(plt, name, extensions=(".png",), **kwargs): plt.xlabel("Time (ms)") plt.ylabel("Proportion of max") plt.tight_layout() -save_figure(plt, os.path.join(fig_folder, "head_positions_processed"), extensions=['.png', '.pdf']) +save_figure(plt, os.path.join(fig_folder, "head_positions_processed"), + extensions=['.png', '.pdf']) plt.close(f) f = plt.figure(1, figsize=(9, 9), dpi=400) @@ -261,22 +289,23 @@ def save_figure(plt, name, extensions=(".png",), **kwargs): plt.ylabel("Proportion of max") plt.xlabel("Time (ms)") plt.tight_layout() -save_figure(plt, os.path.join(fig_folder, "head_velocities_processed"), extensions=['.png', '.pdf']) +save_figure(plt, os.path.join(fig_folder, "head_velocities_processed"), + extensions=['.png', '.pdf']) plt.close(f) np.savetxt("normalised_head_positions.csv", normalised_head_pos, delimiter=",") -np.savetxt("normalised_head_velocities.csv", normalised_head_vel, delimiter=",") +np.savetxt("normalised_head_velocities.csv", normalised_head_vel, + delimiter=",") def sensorial_activity(pt): """ - - :param pt: pt is a single point in time at which we measure the head encoder's output + :param pt: a single time point at which we measure head encoder's output :return: """ - # Head position and velocity seem to be retrieve from a look-up table then updated - # single point over time + # Head position and velocity seem to be retrieve from a look-up table then + # updated single point over time head_pos = _head_pos[pt] head_vel = _head_vel[pt] @@ -298,15 +327,18 @@ def sensorial_activity(pt): MF_pos_activity = np.zeros((50)) MF_vel_activity = np.zeros((50)) - # generate gaussian distributions around the neuron tuned to a given sensorial activity + # generate gaussian distributions around the neuron tuned to a given + # sensorial activity for i in range(50): mean = float(i) / 50.0 + 0.01 - gaussian = np.exp(-((head_pos - mean) * (head_pos - mean)) / (2.0 * sigma * sigma)) + gaussian = np.exp( + -((head_pos - mean) * (head_pos - mean)) / (2.0 * sigma * sigma)) MF_pos_activity[i] = min_rate + gaussian * (max_rate - min_rate) for i in range(50): mean = float(i) / 50.0 + 0.01 - gaussian = np.exp(-((head_vel - mean) * (head_vel - mean)) / (2.0 * sigma * sigma)) + gaussian = np.exp( + -((head_vel - mean) * (head_vel - mean)) / (2.0 * sigma * sigma)) MF_vel_activity[i] = min_rate + gaussian * (max_rate - min_rate) sa_mean_freq = np.concatenate((MF_pos_activity, MF_vel_activity)) @@ -316,30 +348,32 @@ def sensorial_activity(pt): # Error Activity: error from eye and head encoders def error_activity(error_): - # min_rate = 1.0 - # max_rate = 25.0 + # min_rate = 1.0 + # max_rate = 25.0 # - # low_neuron_ID_threshold = abs(error_) * 100.0 - # up_neuron_ID_threshold = low_neuron_ID_threshold - 100.0 + # low_neuron_ID_threshold = abs(error_) * 100.0 + # up_neuron_ID_threshold = low_neuron_ID_threshold - 100.0 IO_agonist = np.zeros((100)) IO_antagonist = np.zeros((100)) # - # rate = [] - # for i in range (100): - # if(i < up_neuron_ID_threshold): - # rate.append(max_rate) - # elif(i=0.0: - # IO_agonist[0:100]=min_rate - # IO_antagonist=rate + # rate = [] + # for i in range (100): + # if(i < up_neuron_ID_threshold): + # rate.append(max_rate) + # elif(i=0.0: + # IO_agonist[0:100]=min_rate + # IO_antagonist=rate + # else: + # IO_antagonist[0:100]=min_rate + # IO_agonist=rate IO_agonist[:] = H_RATE IO_antagonist[:] = L_RATE @@ -351,63 +385,72 @@ def error_activity(error_): def process_VN_spiketrains(VN_spikes, t_start): total_spikes = 0 for spiketrain in VN_spikes.segments[0].spiketrains: - s = spiketrain.as_array()[np.where(spiketrain.as_array() >= t_start)[0]] + s = spiketrain.as_array()[ + np.where(spiketrain.as_array() >= t_start)[0]] total_spikes += len(s) return total_spikes -############################################################################### +############################################################################## # ============================ Create populations ============================ ############################################################################## -# Create MF population - fake input population that will be substituted by external input from robot +# Create MF population - fake input population that will be substituted by +# external input from robot -MF_population = sim.Population(num_MF_neurons, # number of sources - sim.SpikeSourcePoisson, # source type - # {'rate': sa_mean_freq}, # source spike times - {'rate': sensorial_activity(0)[0]}, # source spike times - label="MFLayer" # identifier - ) +MF_population = sim.Population( + num_MF_neurons, # number of sources + sim.SpikeSourcePoisson, # source type + # {'rate': sa_mean_freq}, # source spike times + {'rate': sensorial_activity(0)[0]}, # source spike times + label="MFLayer" # identifier + ) all_populations["mossy_fibers"] = MF_population # Create GOC population -GOC_population = sim.Population(num_GOC_neurons, sim.IF_cond_exp(), label='GOCLayer') +GOC_population = sim.Population(num_GOC_neurons, sim.IF_cond_exp(), + label='GOCLayer') all_populations["golgi"] = GOC_population # create PC population -PC_population = sim.Population(num_PC_neurons, # number of neurons - sim.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model - label="Purkinje Cell" # identifier - ) +PC_population = sim.Population( + num_PC_neurons, # number of neurons + sim.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model + label="Purkinje Cell" # identifier + ) all_populations["purkinje"] = PC_population # create VN population -VN_population = sim.Population(num_VN_neurons, # number of neurons - sim.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model - label="Vestibular Nuclei" # identifier - ) +VN_population = sim.Population( + num_VN_neurons, # number of neurons + sim.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model + label="Vestibular Nuclei" # identifier + ) all_populations["vn"] = VN_population # Create GrC population -GC_population = sim.Population(num_GC_neurons, sim.IF_curr_exp(), label='GCLayer') +GC_population = sim.Population(num_GC_neurons, sim.IF_curr_exp(), + label='GCLayer') all_populations["granule"] = GC_population -# generate fake error (it should be calculated from sensorial activity in error activity, -# but we skip it and just generate an error from -1.5 to 1.5) +# generate fake error (it should be calculated from sensorial activity in error +# activity, but we skip it and just generate an error from -1.5 to 1.5) err = -0.7 # other values to test: -0.3 0 0.3 0.7 -# Create CF population - fake input population that will be substituted by external input from robot -CF_population = sim.Population(num_CF_neurons, # number of sources - sim.SpikeSourcePoisson, # source type - # {'rate': sa_mean_freq}, # source spike times - {'rate': error_activity(err)}, # source spike times - label="CFLayer" # identifier - ) +# Create CF population - fake input population that will be substituted by +# external input from robot +CF_population = sim.Population( + num_CF_neurons, # number of sources + sim.SpikeSourcePoisson, # source type + # {'rate': sa_mean_freq}, # source spike times + {'rate': error_activity(err)}, # source spike times + label="CFLayer" # identifier + ) all_populations["climbing_fibers"] = CF_population -############################################################################### +############################################################################## # ============================ Create connections ============================ ############################################################################## @@ -415,7 +458,8 @@ def process_VN_spiketrains(VN_spikes, t_start): mf_go_connections = sim.Projection(MF_population, GOC_population, sim.OneToOneConnector(), - sim.StaticSynapse(delay=delay_distr, weight=mf_go_weights), + sim.StaticSynapse(delay=delay_distr, + weight=mf_go_weights), receptor_type='excitatory') all_projections["mf_goc"] = mf_go_connections @@ -425,7 +469,8 @@ def process_VN_spiketrains(VN_spikes, t_start): list_GOC_GC = [] list_MF_GC = [] list_GOC_GC_2 = [] -# projections to subpopulations https://github.com/SpiNNakerManchester/sPyNNaker8/issues/168) +# projections to subpopulations +# https://github.com/SpiNNakerManchester/sPyNNaker8/issues/168) for i in range(num_MF_neurons): GC_medium_index = int(round((i / float_num_MF_neurons) * num_GC_neurons)) GC_lower_index = GC_medium_index - 40 @@ -440,35 +485,34 @@ def process_VN_spiketrains(VN_spikes, t_start): for j in range(GC_medium_index - GC_lower_index): list_GOC_GC.append( (i, GC_lower_index + j, - # go_gc_weights, 1) + # go_gc_weights, 1) weight_distr_GO.next(), delay_distr.next()) ) for j in range(GC_medium_index + 20 - GC_medium_index): list_MF_GC.append( (i, GC_medium_index + j, - # mf_gc_weights, 1) + # mf_gc_weights, 1) weight_distr_MF.next(), delay_distr.next()) ) for j in range(GC_upper_index - GC_medium_index - 20): list_GOC_GC_2.append( (i, GC_medium_index + 20 + j, - # go_gc_weights, 1) + # go_gc_weights, 1) weight_distr_GO.next(), delay_distr.next()) ) GO_GC_con1 = sim.Projection(GOC_population, GC_population, sim.FromListConnector(list_GOC_GC), - receptor_type='inhibitory') # this should be inhibitory + receptor_type='inhibitory') all_projections["goc_grc_1"] = GO_GC_con1 MF_GC_con2 = sim.Projection(MF_population, GC_population, sim.FromListConnector(list_MF_GC), receptor_type='excitatory') - all_projections["mf_grc"] = MF_GC_con2 GO_GC_con3 = sim.Projection(GOC_population, @@ -478,26 +522,25 @@ def process_VN_spiketrains(VN_spikes, t_start): all_projections["goc_grc_2"] = GO_GC_con3 # Create PC-VN connections -pc_vn_connections = sim.Projection(PC_population, - VN_population, - sim.OneToOneConnector(), - # receptor_type='GABA', # Should these be inhibitory? - synapse_type=sim.StaticSynapse(delay=delay_distr, weight=pc_vn_weights), - receptor_type='inhibitory') +pc_vn_connections = sim.Projection( + PC_population, VN_population, sim.OneToOneConnector(), + # receptor_type='GABA', # Should these be inhibitory? + synapse_type=sim.StaticSynapse(delay=delay_distr, weight=pc_vn_weights), + receptor_type='inhibitory') all_projections["pc_vn"] = pc_vn_connections # Create MF-VN learning rule - cos mfvn_plas = sim.STDPMechanism( timing_dependence=sim.extra_models.TimingDependenceMFVN(beta=beta_c, sigma=sigma_c), - weight_dependence=sim.extra_models.WeightDependenceMFVN(w_min=min_weight_c, - w_max=max_weight_c, - pot_alpha=pot_alpha_c), + weight_dependence=sim.extra_models.WeightDependenceMFVN( + w_min=min_weight_c, w_max=max_weight_c, pot_alpha=pot_alpha_c), weight=initial_weight_c, delay=delay_distr) # Create MF to VN connections mf_vn_connections = sim.Projection( - MF_population, VN_population, sim.AllToAllConnector(), # Needs mapping as FromListConnector to make efficient + MF_population, VN_population, sim.AllToAllConnector(), + # Needs mapping as FromListConnector to make efficient synapse_type=mfvn_plas, receptor_type="excitatory") all_projections["mf_vn"] = mf_vn_connections @@ -512,9 +555,8 @@ def process_VN_spiketrains(VN_spikes, t_start): # create PF-PC learning rule - sin pfpc_plas = sim.STDPMechanism( timing_dependence=sim.extra_models.TimingDependencePFPC(t_peak=t_peak_s), - weight_dependence=sim.extra_models.WeightDependencePFPC(w_min=min_weight_s, - w_max=max_weight_s, - pot_alpha=pot_alpha_s), + weight_dependence=sim.extra_models.WeightDependencePFPC( + w_min=min_weight_s, w_max=max_weight_s, pot_alpha=pot_alpha_s), weight=initial_weight_s, delay=delay_distr ) @@ -526,13 +568,14 @@ def process_VN_spiketrains(VN_spikes, t_start): receptor_type="excitatory") all_projections["pf_pc"] = pf_pc_connections -# Create IO-PC connections. This synapse with "receptor_type=COMPLEX_SPIKE" propagates the learning signals that drive the plasticity mechanisms in GC-PC synapses -cf_pc_connections = sim.Projection(CF_population, - PC_population, - sim.OneToOneConnector(), - # receptor_type='COMPLEX_SPIKE', - synapse_type=sim.StaticSynapse(delay=1.0, weight=cf_pc_weights), - receptor_type='excitatory') +# Create IO-PC connections. This synapse with "receptor_type=COMPLEX_SPIKE" +# propagates the learning signals that drive the plasticity mechanisms in +# GC-PC synapses +cf_pc_connections = sim.Projection( + CF_population, PC_population, sim.OneToOneConnector(), + # receptor_type='COMPLEX_SPIKE', + synapse_type=sim.StaticSynapse(delay=1.0, weight=cf_pc_weights), + receptor_type='excitatory') all_projections["cf_pc"] = cf_pc_connections # lif_pop = sim.Population(1024, sim.IF_curr_exp(), label='pop_lif') @@ -546,7 +589,7 @@ def process_VN_spiketrains(VN_spikes, t_start): # synapse_type=sim.StaticSynapse(weight=0.1)) # # -# # live output of the input vertex (retina_pop) to the first pynn population (lif_pop) +# # live output of the input (retina_pop) to the first population (lif_pop) # sim.external_devices.activate_live_output_to(out_pop,retina_pop) # # @@ -581,7 +624,8 @@ def process_VN_spiketrains(VN_spikes, t_start): VN_transfer_func = [] print("=" * 80) -print("Running simulation for", runtime, " ms split into", samples_in_repeat, "chunks.") +print("Running simulation for", runtime, " ms split into", samples_in_repeat, + "chunks.") all_spikes_first_trial = {} # Record simulation start time (wall clock) sim_start_time = plt.datetime.datetime.now() @@ -597,39 +641,40 @@ def process_VN_spiketrains(VN_spikes, t_start): MF_population.set(rate=sensorial_activity(total_runtime)[0]) -# sim.run(runtime*0.4) -# -# CF_rates=[] -# lower_rate=100*[L_RATE] -# upper_rate=100*[H_RATE] -# CF_rates.extend(lower_rate) -# CF_rates.extend(upper_rate) -# CF_population.set(rate=CF_rates) -# -# sim.run(runtime*0.4) -# -# CF_rates=[] -# lower_rate=100*[H_RATE] -# upper_rate=100*[L_RATE] -# CF_rates.extend(lower_rate) -# CF_rates.extend(upper_rate) -# CF_population.set(rate=CF_rates) -# -# sim.run(runtime*0.2) -# -# CF_rates=[] -# lower_rate=100*[H_RATE] -# upper_rate=100*[L_RATE] -# CF_rates.extend(lower_rate) -# CF_rates.extend(upper_rate) -# CF_population.set(rate=CF_rates) + # sim.run(runtime*0.4) + # + # CF_rates=[] + # lower_rate=100*[L_RATE] + # upper_rate=100*[H_RATE] + # CF_rates.extend(lower_rate) + # CF_rates.extend(upper_rate) + # CF_population.set(rate=CF_rates) + # + # sim.run(runtime*0.4) + # + # CF_rates=[] + # lower_rate=100*[H_RATE] + # upper_rate=100*[L_RATE] + # CF_rates.extend(lower_rate) + # CF_rates.extend(upper_rate) + # CF_population.set(rate=CF_rates) + # + # sim.run(runtime*0.2) + # + # CF_rates=[] + # lower_rate=100*[H_RATE] + # upper_rate=100*[L_RATE] + # CF_rates.extend(lower_rate) + # CF_rates.extend(upper_rate) + # CF_population.set(rate=CF_rates) + end_time = plt.datetime.datetime.now() total_time = end_time - start_time sim_total_time = end_time - sim_start_time total_runtime = runtime * repeats -# ============================ Retrieving data from simulation ============================ +# ==================== Retrieving data from simulation ======================= MF_spikes = MF_population.get_data('spikes') CF_spikes = CF_population.get_data('spikes') @@ -786,7 +831,8 @@ def process_VN_spiketrains(VN_spikes, t_start): plt.title(proj) plt.xlabel("Weight") plt.ylabel("Count") - save_figure(plt, os.path.join(fig_folder, "{}_weight_histogram".format(proj)), + save_figure(plt, os.path.join( + fig_folder, "{}_weight_histogram".format(proj)), extensions=['.png', ]) plt.close(f) @@ -810,7 +856,8 @@ def process_VN_spiketrains(VN_spikes, t_start): yticks=True, markersize=2, xlim=(0, total_runtime), xlabel='VN_spikes'), Panel(VN_spikes.segments[0].filter(name='gsyn_inh')[0], - ylabel="Membrane potential (mV)", yticks=True, xlim=(0, total_runtime)) + ylabel="Membrane potential (mV)", yticks=True, xlim=(0, + total_runtime)) ) save_figure(plt, os.path.join(fig_folder, "collections"), extensions=['.png', ]) diff --git a/examples/icub_vor_examples/pb_single_purkinje_cell_test.pysingle_purkinje_cell_test.py b/examples/icub_vor_examples/pb_single_purkinje_cell_test.pysingle_purkinje_cell_test.py index 9dd81c25..03247733 100644 --- a/examples/icub_vor_examples/pb_single_purkinje_cell_test.pysingle_purkinje_cell_test.py +++ b/examples/icub_vor_examples/pb_single_purkinje_cell_test.pysingle_purkinje_cell_test.py @@ -1,8 +1,23 @@ +# Copyright (c) 2019-2021 The University of Manchester +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + from __future__ import print_function import spynnaker8 as p -import numpy -import math -import unittest +# import numpy +# import math +# import unittest from pyNN.utility.plotting import Figure, Panel import matplotlib.pyplot as plt @@ -25,27 +40,30 @@ initial_weight = 0.05 plastic_delay = 4 -purkinje_cell = p.Population(1, # number of neurons - p.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model - label="Purkinje Cell" # identifier - ) +purkinje_cell = p.Population( + 1, # number of neurons + p.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model + label="Purkinje Cell" # identifier + ) # Spike source to send spike via synapse spike_times = [50, 150, 270] -granular_cell = p.Population(1, # number of sources - p.SpikeSourceArray, # source type - {'spike_times': spike_times}, # source spike times - label="src1" # identifier - ) +granular_cell = p.Population( + 1, # number of sources + p.SpikeSourceArray, # source type + {'spike_times': spike_times}, # source spike times + label="src1" # identifier + ) # Spike source to send spike via synapse from climbing fibre spike_times_2 = [100, 104, 107, 246] -climbing_fibre = p.Population(1, # number of sources - p.SpikeSourceArray, # source type - {'spike_times': spike_times_2}, # source spike times - label="src2" # identifier - ) +climbing_fibre = p.Population( + 1, # number of sources + p.SpikeSourceArray, # source type + {'spike_times': spike_times_2}, # source spike times + label="src2" # identifier + ) # Create projection from GC to PC pfpc_plas = p.STDPMechanism( diff --git a/examples/icub_vor_examples/receptive_fields_for_motion.py b/examples/icub_vor_examples/receptive_fields_for_motion.py index 93170c0b..c2afae05 100644 --- a/examples/icub_vor_examples/receptive_fields_for_motion.py +++ b/examples/icub_vor_examples/receptive_fields_for_motion.py @@ -1,12 +1,27 @@ #!usr/bin/python +# Copyright (c) 2019-2021 The University of Manchester +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + import socket import spynnaker8 as sim import numpy as np #import logging import matplotlib.pyplot as plt -from decode_events import* -from functions import* +from decode_events import * +from functions import * import yarp from pacman.model.constraints.key_allocator_constraints import FixedKeyAndMaskConstraint @@ -177,7 +192,7 @@ def map_neurons_to_field(length, x_segments, y_segments, scale_down, layers, x_s # # print x, y # print "finished layer", layer, "with border", x_border, y_border - print "done mapping" + print("done mapping") return pixel_mapping, field_size def convert_xy_field_to_id(field_x, field_y, width, length): @@ -189,7 +204,7 @@ def map_to_from_list(mapping, width, length, scale_down, pixel_weight=5, x_size= # motor_weight *= width * length mapping, field_size = mapping layers = len(mapping) - print "layer", layers, "width", width, "length", length + print("layer", layers, "width", width, "length", length) from_list_connections = [[] for i in range(layers)] motor_conn = [] for layer in range(layers): @@ -208,9 +223,9 @@ def map_to_from_list(mapping, width, length, scale_down, pixel_weight=5, x_size= 1] if connection not in from_list_connections: from_list_connections[layer].append(connection) - print x, y, x + (304 * y), convert_pixel_mapping(x + (304 * y), width, length), convert_xy_field_to_id(mapping[layer][x][y][0], mapping[layer][x][y][1], width, length) + print(x, y, x + (304 * y), convert_pixel_mapping(x + (304 * y), width, length), convert_xy_field_to_id(mapping[layer][x][y][0], mapping[layer][x][y][1], width, length)) if convert_pixel_mapping(x + (304 * y), width, length) >= 304*240 or convert_xy_field_to_id(mapping[layer][x][y][0], mapping[layer][x][y][1], width, length) >= width*length: - print "fucked" + print("oops") for connection in from_list_connections[layer]: if connection[1] % width < width / 2: if [connection[1], 0, motor_weight, 1] not in motor_control_e: @@ -229,7 +244,7 @@ def map_to_from_list(mapping, width, length, scale_down, pixel_weight=5, x_size= motor_control_e.append([connection[1], 3, motor_weight, 1]) motor_control_i.append([connection[1], 2, motor_weight, 1]) motor_conn.append([motor_control_e, motor_control_i]) - print "created connections" + print("created connections") return from_list_connections, motor_conn def split_the_from_list(input, output, from_list, receptor_type="excitatory", max_conn=255): @@ -286,7 +301,7 @@ def connect_it_up(visual_input, motor_output, connections, width, length): # split_the_from_list(hidden_pop, motor_output, motor_conn_e) # split_the_from_list(hidden_pops[layer], motor_output, motor_conn_i, receptor_type="inhibitory") all_pops.append(hidden_pops) - print "finished connecting" + print("finished connecting") return all_pops simulate = True @@ -302,13 +317,13 @@ def connect_it_up(visual_input, motor_output, connections, width, length): # mapping_3 = map_neurons_to_field(50, 19, 15, 0.9, 2) # mapping_4 = map_neurons_to_field(128, 2, 2, 0.9, 5) # mapping_5 = map_neurons_to_field(128, 2, 2, 0.9, 7) -print "created mapping" +print("created mapping") # connections_1 = map_to_from_list(mapping_1, 19, 15, 0.9) connections_2 = map_to_from_list(mapping_2, width, length, 0.9) # connections_3 = map_to_from_list(mapping_3, 19, 15, 0.9) # connections_4 = map_to_from_list(mapping_4, 2, 2, 0.9) # connections_5 = map_to_from_list(mapping_5, 2, 2, 0.9) -print "created all connections" +print("created all connections") sim.setup(timestep=1.0) diff --git a/examples/icub_vor_examples/single_purkinje_cell_pf_windowing.py b/examples/icub_vor_examples/single_purkinje_cell_pf_windowing.py index f9e552c1..5831df3a 100644 --- a/examples/icub_vor_examples/single_purkinje_cell_pf_windowing.py +++ b/examples/icub_vor_examples/single_purkinje_cell_pf_windowing.py @@ -1,8 +1,23 @@ +# Copyright (c) 2019-2021 The University of Manchester +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + from __future__ import print_function import spynnaker8 as p -import numpy -import math -import unittest +# import numpy +# import math +# import unittest from pyNN.utility.plotting import Figure, Panel import matplotlib.pyplot as plt @@ -14,40 +29,44 @@ "v_thresh": -50, "v_reset": -70, "v_rest": -65, - "i_offset": 0 # DC input - } + "i_offset": 0 # DC input +} # Learning parameters min_weight = 0 max_weight = 0.1 -pot_alpha=0.01 -t_peak=100 +pot_alpha = 0.01 +t_peak = 100 initial_weight = 0.05 plastic_delay = 4 -purkinje_cell = p.Population(1, # number of neurons - p.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model - label="Purkinje Cell" # identifier - ) +purkinje_cell = p.Population( + 1, # number of neurons + p.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model + label="Purkinje Cell" # identifier + ) # Spike source to send spike via synapse -pf_spike_times = [50, 60, 65, 85, 101, 400]#, 150, 175, 180, 190, 240, 250, 255, -# 270, 300, 345, 350, 360, 370, 400, 422, 425, 427, 429] - -granular_cell = p.Population(1, # number of sources - p.SpikeSourceArray, # source type - {'spike_times': pf_spike_times}, # source spike times - label="src1" # identifier - ) +pf_spike_times = [50, 60, 65, 85, 101, 400] +# 150, 175, 180, 190, 240, 250, 255, +# 270, 300, 345, 350, 360, 370, 400, 422, 425, 427, 429] + +granular_cell = p.Population( + 1, # number of sources + p.SpikeSourceArray, # source type + {'spike_times': pf_spike_times}, # source spike times + label="src1" # identifier + ) # Spike source to send spike via synapse from climbing fibre -cf_spike_times = [55, 80, 90, 95, 96, 201]#, 104, 107, 246] -climbing_fibre = p.Population(1, # number of sources - p.SpikeSourceArray, # source type - {'spike_times': cf_spike_times}, # source spike times - label="src2" # identifier - ) +cf_spike_times = [55, 80, 90, 95, 96, 201] # 104, 107, 246] +climbing_fibre = p.Population( + 1, # number of sources + p.SpikeSourceArray, # source type + {'spike_times': cf_spike_times}, # source spike times + label="src2" # identifier + ) # Create projection from GC to PC pfpc_plas = p.STDPMechanism( @@ -61,13 +80,11 @@ granular_cell, purkinje_cell, p.AllToAllConnector(), synapse_type=pfpc_plas, receptor_type="excitatory") - # Create projection from CF to PC synapse = p.Projection( climbing_fibre, purkinje_cell, p.OneToOneConnector(), p.StaticSynapse(weight=0.0, delay=1), receptor_type="excitatory") - granular_cell.record('spikes') climbing_fibre.record('spikes') purkinje_cell.record("all") @@ -98,7 +115,6 @@ yticks=True, markersize=2, xlim=(0, runtime)), ) - plt.show() p.end() diff --git a/examples/icub_vor_examples/single_purkinje_cell_potentiation_test.py b/examples/icub_vor_examples/single_purkinje_cell_potentiation_test.py index 8bb60c02..73409b93 100644 --- a/examples/icub_vor_examples/single_purkinje_cell_potentiation_test.py +++ b/examples/icub_vor_examples/single_purkinje_cell_potentiation_test.py @@ -1,12 +1,27 @@ +# Copyright (c) 2019-2021 The University of Manchester +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + from __future__ import print_function import spynnaker8 as p -import numpy -import math -import unittest +# import numpy +# import math +# import unittest from pyNN.utility.plotting import Figure, Panel import matplotlib.pyplot as plt -p.setup(1) # simulation timestep (ms) +p.setup(1) # simulation timestep (ms) runtime = 1000 # Post-synapse population @@ -14,34 +29,35 @@ "v_thresh": -50, "v_reset": -70, "v_rest": -65, - "i_offset": 0 # DC input - } + "i_offset": 0 # DC input +} # Learning parameters min_weight = 0 max_weight = 0.1 -pot_alpha = 0.002 # this is alpha in the paper +pot_alpha = 0.002 # this is alpha in the paper -t_peak = 101 # ms +t_peak = 101 # ms initial_weight = 0.05 plastic_delay = 4 -purkinje_cell = p.Population(1, # number of neurons - p.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model - label="Purkinje Cell" # identifier - ) +purkinje_cell = p.Population( + 1, # number of neurons + p.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model + label="Purkinje Cell" # identifier + ) # Spike source to send spike via synapse spike_times = [101, 201, 301, 401, 501, 601, 701, 801, 901] -granular_cell = p.Population(1, # number of sources - p.SpikeSourceArray, # source type - {'spike_times': spike_times}, # source spike times - label="src1" # identifier - ) - +granular_cell = p.Population( + 1, # number of sources + p.SpikeSourceArray, # source type + {'spike_times': spike_times}, # source spike times + label="src1" # identifier + ) # Create projection from GC to PC pfpc_plas = p.STDPMechanism( @@ -55,13 +71,9 @@ granular_cell, purkinje_cell, p.AllToAllConnector(), synapse_type=pfpc_plas, receptor_type="excitatory") - - - granular_cell.record('spikes') purkinje_cell.record("all") - pf_weights = [] for i in range(len(spike_times)): p.run(100) @@ -87,9 +99,7 @@ yticks=True, markersize=2, xlim=(0, runtime)), ) - plt.show() p.end() print("Job Complete") - diff --git a/examples/icub_vor_examples/single_purkinje_cell_test.py b/examples/icub_vor_examples/single_purkinje_cell_test.py index 6961858b..a69ffcda 100644 --- a/examples/icub_vor_examples/single_purkinje_cell_test.py +++ b/examples/icub_vor_examples/single_purkinje_cell_test.py @@ -1,12 +1,27 @@ +# Copyright (c) 2019-2021 The University of Manchester +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + from __future__ import print_function import spynnaker8 as p -import numpy -import math -import unittest +# import numpy +# import math +# import unittest from pyNN.utility.plotting import Figure, Panel import matplotlib.pyplot as plt -p.setup(1) # simulation timestep (ms) +p.setup(1) # simulation timestep (ms) runtime = 500 # Post-synapse population @@ -14,39 +29,41 @@ "v_thresh": -50, "v_reset": -70, "v_rest": -65, - "i_offset": 0 # DC input + "i_offset": 0 # DC input } # Learning parameters min_weight = 0 max_weight = 0.1 -pot_alpha=0.01 -t_peak=100 +pot_alpha = 0.01 +t_peak = 100 initial_weight = 0.05 plastic_delay = 4 -purkinje_cell = p.Population(1, # number of neurons - p.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model - label="Purkinje Cell" # identifier - ) - +purkinje_cell = p.Population( + 1, # number of neurons + p.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model + label="Purkinje Cell" # identifier + ) # Spike source to send spike via synapse spike_times = [50, 150, 270] -granular_cell = p.Population(1, # number of sources - p.SpikeSourceArray, # source type - {'spike_times': spike_times}, # source spike times - label="src1" # identifier - ) +granular_cell = p.Population( + 1, # number of sources + p.SpikeSourceArray, # source type + {'spike_times': spike_times}, # source spike times + label="src1" # identifier + ) # Spike source to send spike via synapse from climbing fibre spike_times_2 = [100, 104, 107, 246] -climbing_fibre = p.Population(1, # number of sources - p.SpikeSourceArray, # source type - {'spike_times': spike_times_2}, # source spike times - label="src2" # identifier - ) +climbing_fibre = p.Population( + 1, # number of sources + p.SpikeSourceArray, # source type + {'spike_times': spike_times_2}, # source spike times + label="src2" # identifier + ) # Create projection from GC to PC pfpc_plas = p.STDPMechanism( @@ -60,13 +77,11 @@ granular_cell, purkinje_cell, p.AllToAllConnector(), synapse_type=pfpc_plas, receptor_type="excitatory") - # Create projection from CF to PC synapse = p.Projection( climbing_fibre, purkinje_cell, p.OneToOneConnector(), p.StaticSynapse(weight=0.0, delay=1), receptor_type="excitatory") - granular_cell.record('spikes') climbing_fibre.record('spikes') purkinje_cell.record("all") @@ -102,5 +117,3 @@ plt.savefig("single_pc_test.png", dpi=600) plt.show() p.end() - - diff --git a/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing.py b/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing.py index 60b18378..aae438d3 100644 --- a/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing.py +++ b/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing.py @@ -1,12 +1,27 @@ +# Copyright (c) 2019-2021 The University of Manchester +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + from __future__ import print_function import spynnaker8 as p -import numpy -import math -import unittest +# import numpy +# import math +# import unittest from pyNN.utility.plotting import Figure, Panel import matplotlib.pyplot as plt -p.setup(1) # simulation timestep (ms) +p.setup(1) # simulation timestep (ms) runtime = 500 # Post-synapse population @@ -14,13 +29,13 @@ "v_thresh": -50, "v_reset": -70, "v_rest": -65, - "i_offset": 0 # DC input + "i_offset": 0 # DC input } # Learning parameters min_weight = 0 max_weight = 0.1 -pot_alpha = 0.01 # this is alpha in the paper +pot_alpha = 0.01 # this is alpha in the paper beta = 11 sigma = 201 @@ -29,29 +44,32 @@ initial_weight = 0.05 plastic_delay = 4 -vestibular_nuclei = p.Population(1, # number of neurons - p.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model - label="Vestibular Nuclei" # identifier - ) - +vestibular_nuclei = p.Population( + 1, # number of neurons + p.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model + label="Vestibular Nuclei" # identifier + ) # Spike source to send spike via synapse -mf_spike_times = [50, 60, 65, 85, 101, 400]#, 150, 175, 180, 190, 240, 250, 255, -# 270, 300, 345, 350, 360, 370, 400, 422, 425, 427, 429] - -mossy_fibre_src = p.Population(1, # number of sources - p.SpikeSourceArray, # source type - {'spike_times': mf_spike_times}, # source spike times - label="src1" # identifier - ) +mf_spike_times = [50, 60, 65, 85, 101, 400] +# 150, 175, 180, 190, 240, 250, 255, +# 270, 300, 345, 350, 360, 370, 400, 422, 425, 427, 429] + +mossy_fibre_src = p.Population( + 1, # number of sources + p.SpikeSourceArray, # source type + {'spike_times': mf_spike_times}, # source spike times + label="src1" # identifier + ) # Spike source to send spike via synapse from climbing fibre -pc_spike_times = [55, 80, 90, 95, 96, 201]#, 104, 107, 246] -purkinje_cell_src = p.Population(1, # number of sources - p.SpikeSourceArray, # source type - {'spike_times': pc_spike_times}, # source spike times - label="src2" # identifier - ) +pc_spike_times = [55, 80, 90, 95, 96, 201] #, 104, 107, 246] +purkinje_cell_src = p.Population( + 1, # number of sources + p.SpikeSourceArray, # source type + {'spike_times': pc_spike_times}, # source spike times + label="src2" # identifier + ) # Create projection from GC to PC mfvn_plas = p.STDPMechanism( @@ -66,13 +84,11 @@ mossy_fibre_src, vestibular_nuclei, p.AllToAllConnector(), synapse_type=mfvn_plas, receptor_type="excitatory") - # Create projection from PC to VN synapse = p.Projection( purkinje_cell_src, vestibular_nuclei, p.OneToOneConnector(), p.StaticSynapse(weight=0.0, delay=1), receptor_type="excitatory") - mossy_fibre_src.record('spikes') purkinje_cell_src.record('spikes') vestibular_nuclei.record("all") @@ -81,7 +97,8 @@ mossy_fibre_src_spikes = mossy_fibre_src.get_data('spikes') purkinje_cell_src_spikes = purkinje_cell_src.get_data('spikes') -vestibular_nuclei_data = vestibular_nuclei.get_data(['v', 'gsyn_exc', 'spikes']) +vestibular_nuclei_data = vestibular_nuclei.get_data( + ['v', 'gsyn_exc', 'spikes']) mf_weights = synapse_mfvn.get('weight', 'list', with_address=False) print(mf_weights) @@ -95,15 +112,16 @@ yticks=True, markersize=2, xlim=(0, runtime)), Panel(vestibular_nuclei_data.segments[0].filter(name='v')[0], ylabel="Membrane potential (mV)", - data_labels=[vestibular_nuclei.label], yticks=True, xlim=(0, runtime)), + data_labels=[vestibular_nuclei.label], yticks=True, xlim=(0, + runtime)), Panel(vestibular_nuclei_data.segments[0].filter(name='gsyn_exc')[0], ylabel="gsyn excitatory (mV)", - data_labels=[vestibular_nuclei.label], yticks=True, xlim=(0, runtime)), + data_labels=[vestibular_nuclei.label], yticks=True, xlim=(0, + runtime)), Panel(vestibular_nuclei_data.segments[0].spiketrains, yticks=True, markersize=2, xlim=(0, runtime)), ) - plt.show() p.end() diff --git a/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing_3_spikes.py b/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing_3_spikes.py index 666db0d9..786fe9dd 100644 --- a/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing_3_spikes.py +++ b/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing_3_spikes.py @@ -1,12 +1,27 @@ +# Copyright (c) 2019-2021 The University of Manchester +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + from __future__ import print_function import spynnaker8 as p -import numpy -import math -import unittest +# import numpy +# import math +# import unittest from pyNN.utility.plotting import Figure, Panel import matplotlib.pyplot as plt -p.setup(1) # simulation timestep (ms) +p.setup(1) # simulation timestep (ms) runtime = 500 # Post-synapse population @@ -14,7 +29,7 @@ "v_thresh": -50, "v_reset": -70, "v_rest": -65, - "i_offset": 0 # DC input + "i_offset": 0 # DC input } # Learning parameters @@ -29,29 +44,33 @@ initial_weight = 0.01 plastic_delay = 4 -vestibular_nuclei = p.Population(1, # number of neurons - p.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model - label="Vestibular Nuclei" # identifier - ) +vestibular_nuclei = p.Population( + 1, # number of neurons + p.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model + label="Vestibular Nuclei" # identifier + ) # Spike source to send spike via synapse -mf_spike_times = [50, 60, 65]#, 150, 175, 180, 190, 240, 250, 255, -# 270, 300, 345, 350, 360, 370, 400, 422, 425, 427, 429] - -mossy_fibre_src = p.Population(1, # number of sources - p.SpikeSourceArray, # source type - {'spike_times': mf_spike_times}, # source spike times - label="src1" # identifier - ) +mf_spike_times = [50, 60, 65] +# 150, 175, 180, 190, 240, 250, 255, +# 270, 300, 345, 350, 360, 370, 400, 422, 425, 427, 429] + +mossy_fibre_src = p.Population( + 1, # number of sources + p.SpikeSourceArray, # source type + {'spike_times': mf_spike_times}, # source spike times + label="src1" # identifier + ) # Spike source to send spike via synapse from climbing fibre -pc_spike_times = [60]#, 104, 107, 246] -purkinje_cell_src = p.Population(1, # number of sources - p.SpikeSourceArray, # source type - {'spike_times': pc_spike_times}, # source spike times - label="purkinje_cell_src" # identifier - ) +pc_spike_times = [60] # 104, 107, 246] +purkinje_cell_src = p.Population( + 1, # number of sources + p.SpikeSourceArray, # source type + {'spike_times': pc_spike_times}, # source spike times + label="purkinje_cell_src" # identifier + ) # Create projection from GC to PC mfvn_plas = p.STDPMechanism( @@ -66,13 +85,11 @@ mossy_fibre_src, vestibular_nuclei, p.AllToAllConnector(), synapse_type=mfvn_plas, receptor_type="excitatory") - # Create projection from PC to VN synapse = p.Projection( purkinje_cell_src, vestibular_nuclei, p.OneToOneConnector(), p.StaticSynapse(weight=0.0, delay=1), receptor_type="excitatory") - mossy_fibre_src.record('spikes') purkinje_cell_src.record('spikes') vestibular_nuclei.record("all") @@ -81,7 +98,8 @@ mossy_fibre_src_spikes = mossy_fibre_src.get_data('spikes') purkinje_cell_src_spikes = purkinje_cell_src.get_data('spikes') -vestibular_nuclei_data = vestibular_nuclei.get_data(['v', 'gsyn_exc', 'spikes']) +vestibular_nuclei_data = vestibular_nuclei.get_data( + ['v', 'gsyn_exc', 'spikes']) mf_weights = synapse_mfvn.get('weight', 'list', with_address=False) print("\n {}".format(mf_weights)) @@ -95,17 +113,16 @@ yticks=True, markersize=2, xlim=(0, runtime)), Panel(vestibular_nuclei_data.segments[0].filter(name='v')[0], ylabel="Membrane potential (mV)", - data_labels=[vestibular_nuclei.label], yticks=True, xlim=(0, runtime)), + data_labels=[vestibular_nuclei.label], yticks=True, xlim=(0, + runtime)), Panel(vestibular_nuclei_data.segments[0].filter(name='gsyn_exc')[0], ylabel="gsyn excitatory (mV)", - data_labels=[vestibular_nuclei.label], yticks=True, xlim=(0, runtime)), + data_labels=[vestibular_nuclei.label], yticks=True, xlim=(0, + runtime)), Panel(vestibular_nuclei_data.segments[0].spiketrains, yticks=True, markersize=2, xlim=(0, runtime)), ) - plt.show() p.end() print("Job Complete") - - diff --git a/examples/icub_vor_examples/single_vestibular_nuclei_potentiation_test.py b/examples/icub_vor_examples/single_vestibular_nuclei_potentiation_test.py index f863fb8b..a4df6e16 100644 --- a/examples/icub_vor_examples/single_vestibular_nuclei_potentiation_test.py +++ b/examples/icub_vor_examples/single_vestibular_nuclei_potentiation_test.py @@ -1,3 +1,18 @@ +# Copyright (c) 2019-2021 The University of Manchester +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + from __future__ import print_function import spynnaker8 as p import numpy @@ -7,7 +22,7 @@ import matplotlib.pyplot as plt -p.setup(1) # simulation timestep (ms) +p.setup(1) # simulation timestep (ms) runtime = 1000 # Post-synapse population @@ -15,13 +30,13 @@ "v_thresh": -50, "v_reset": -70, "v_rest": -65, - "i_offset": 0 # DC input - } + "i_offset": 0 # DC input +} # Learning parameters min_weight = 0 max_weight = 0.1 -pot_alpha = 0.01 # this is alpha in the paper +pot_alpha = 0.01 # this is alpha in the paper beta = 11 sigma = 201 @@ -29,21 +44,21 @@ plastic_delay = 4 -vestibular_neuclei = p.Population(1, # number of neurons - p.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model - label="Vestibular Nuclei" # identifier - ) - +vestibular_neuclei = p.Population( + 1, # number of neurons + p.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model + label="Vestibular Nuclei" # identifier + ) # Spike source to send spike via synapse spike_times = [1, 101, 201, 301, 401, 501, 601, 701, 801, 901] -mossy_fibre_src = p.Population(1, # number of sources - p.SpikeSourceArray, # source type - {'spike_times': spike_times}, # source spike times - label="src1" # identifier - ) - +mossy_fibre_src = p.Population( + 1, # number of sources + p.SpikeSourceArray, # source type + {'spike_times': spike_times}, # source spike times + label="src1" # identifier + ) # Create projection from MF to VN mfvn_plas = p.STDPMechanism( @@ -58,11 +73,9 @@ mossy_fibre_src, vestibular_neuclei, p.AllToAllConnector(), synapse_type=mfvn_plas, receptor_type="excitatory") - mossy_fibre_src.record('spikes') vestibular_neuclei.record("all") - mf_weights = [] for i in range(len(spike_times)): p.run(100) @@ -83,10 +96,12 @@ yticks=True, markersize=2, xlim=(0, runtime)), Panel(vestibular_neuclei_data.segments[0].filter(name='v')[0], ylabel="VN membrane potential (mV)", - data_labels=[vestibular_neuclei.label], yticks=True, xlim=(0, runtime)), + data_labels=[vestibular_neuclei.label], yticks=True, xlim=(0, + runtime)), Panel(vestibular_neuclei_data.segments[0].filter(name='gsyn_exc')[0], ylabel="VN excitatory current (mV)", - data_labels=[vestibular_neuclei.label], yticks=True, xlim=(0, runtime)), + data_labels=[vestibular_neuclei.label], yticks=True, xlim=(0, + runtime)), Panel(vestibular_neuclei_data.segments[0].spiketrains, xlabel="Time (ms)", yticks=True, markersize=2, xlim=(0, runtime)), diff --git a/examples/icub_vor_examples/spinn_gym_examples/icub_utilities.py b/examples/icub_vor_examples/spinn_gym_examples/icub_utilities.py index 561cc6b4..6648ac8f 100644 --- a/examples/icub_vor_examples/spinn_gym_examples/icub_utilities.py +++ b/examples/icub_vor_examples/spinn_gym_examples/icub_utilities.py @@ -1,3 +1,18 @@ +# Copyright (c) 2019-2021 The University of Manchester +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + import numpy as np import pylab as plt import matplotlib as mlib @@ -67,9 +82,12 @@ def generate_head_position_and_velocity(time, dt=0.001): def retrieve_and_package_results(icub_vor_env_pop, simulator): # Get the data from the ICubVorEnv pop - errors = np.asarray(get_error(icub_vor_env_pop=icub_vor_env_pop, simulator=simulator)).ravel() - l_counts = get_l_count(icub_vor_env_pop=icub_vor_env_pop, simulator=simulator) - r_counts = get_r_count(icub_vor_env_pop=icub_vor_env_pop, simulator=simulator) + errors = np.asarray(get_error( + icub_vor_env_pop=icub_vor_env_pop, simulator=simulator)).ravel() + l_counts = get_l_count(icub_vor_env_pop=icub_vor_env_pop, + simulator=simulator) + r_counts = get_r_count(icub_vor_env_pop=icub_vor_env_pop, + simulator=simulator) rec_eye_pos = np.asarray(get_eye_pos( icub_vor_env_pop=icub_vor_env_pop, simulator=simulator)).ravel() rec_eye_vel = np.asarray(get_eye_vel( @@ -136,19 +154,26 @@ def plot_results(results_dict, simulation_parameters, name): plt.subplot(5, 1, 3) plt.plot(x_plot, rec_eye_pos, label="rec. eye position") plt.plot(x_plot, rec_eye_vel, label="rec. eye velocity") - plt.plot(np.tile(perfect_eye_pos, runtime // 1000), label="eye position", ls=':') - plt.plot(np.tile(perfect_eye_vel, runtime // 1000), label="eye velocity", ls=':') + plt.plot(np.tile(perfect_eye_pos, runtime // 1000), label="eye position", + ls=':') + plt.plot(np.tile(perfect_eye_vel, runtime // 1000), label="eye velocity", + ls=':') plt.legend(loc="best") plt.xlim([0, runtime]) # Errors plt.subplot(5, 1, 4) plt.plot(x_plot, errors, label="recorded error") - eye_pos_diff = np.tile(perfect_eye_pos[::error_window_size], runtime // 1000) - rec_eye_pos.ravel() - eye_vel_diff = np.tile(perfect_eye_vel[::error_window_size], runtime // 1000) - rec_eye_vel.ravel() + eye_pos_diff = np.tile( + perfect_eye_pos[::error_window_size], + runtime // 1000) - rec_eye_pos.ravel() + eye_vel_diff = np.tile( + perfect_eye_vel[::error_window_size], + runtime // 1000) - rec_eye_vel.ravel() reconstructed_error = eye_pos_diff + eye_vel_diff - plt.plot(x_plot, reconstructed_error, color='k', ls=":", label="reconstructed error") + plt.plot(x_plot, reconstructed_error, color='k', ls=":", + label="reconstructed error") plt.plot(x_plot, eye_pos_diff, label="eye position diff") plt.plot(x_plot, eye_vel_diff, diff --git a/examples/icub_vor_examples/spinn_gym_examples/icub_vor_env_test.py b/examples/icub_vor_examples/spinn_gym_examples/icub_vor_env_test.py index 97989131..59371115 100644 --- a/examples/icub_vor_examples/spinn_gym_examples/icub_vor_env_test.py +++ b/examples/icub_vor_examples/spinn_gym_examples/icub_vor_env_test.py @@ -1,3 +1,18 @@ +# Copyright (c) 2019-2021 The University of Manchester +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + import spynnaker8 as p import spinn_gym as gym @@ -81,8 +96,10 @@ def get_eye_vel(icub_vor_env_pop, simulator): # Report 4 points: for i in [0, 250, 500, 750]: - print("At {}: head pos {:4.6f}, head vel {:4.6f}, eye pos {:4.6f}, eye vel {:4.6f}".format( - i, head_pos[i], head_vel[i], perfect_eye_pos[i], perfect_eye_vel[i])) + print("At {}: head pos {:4.6f}, head vel {:4.6f}, eye pos {:4.6f}, " + "eye vel {:4.6f}".format( + i, head_pos[i], head_vel[i], perfect_eye_pos[i], + perfect_eye_vel[i])) # build ICubVorEnv model pop error_window_size = 10 diff --git a/examples/icub_vor_examples/spinn_gym_examples/icub_vor_env_test_200_inputs.py b/examples/icub_vor_examples/spinn_gym_examples/icub_vor_env_test_200_inputs.py index 03b8613b..064a12f9 100644 --- a/examples/icub_vor_examples/spinn_gym_examples/icub_vor_env_test_200_inputs.py +++ b/examples/icub_vor_examples/spinn_gym_examples/icub_vor_env_test_200_inputs.py @@ -1,12 +1,31 @@ +# Copyright (c) 2019-2021 The University of Manchester +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + import spynnaker8 as p import spinn_gym as gym -from pyNN.utility.plotting import Figure, Panel -import matplotlib.pyplot as plt +# from pyNN.utility.plotting import Figure, Panel +# import matplotlib.pyplot as plt import numpy as np -import os +# import os from spinn_front_end_common.utilities.globals_variables import get_simulator -from icub_utilities import * +from icub_utilities import ( + generate_head_position_and_velocity, retrieve_and_package_results, + remap_odd_even, remap_second_half_descending, ICUB_VOR_VENV_POP_SIZE, + plot_results) + # Parameter definition runtime = 5000 @@ -29,15 +48,19 @@ input_spike_times[i * 2] = [250 + (10 * 2 * i) for _ in range(1)] input_spike_times[2 * i + 1] = [500 + (10 * (2 * i + 1)) for _ in range(1)] input_spike_times[50 + i * 2] = [750 + (10 * 2 * i) for _ in range(10 + i)] - input_spike_times[100 + 2 * i + 1] = [1000 + (10 * (2 * i + 1)) for _ in range(10 + i)] - input_spike_times[150 + i * 2] = [1250 + (10 * 2 * i) for _ in range(100 + i)] - input_spike_times[150 + 2 * i + 1] = [1500 + (10 * (2 * i + 1)) for _ in range(100 + i)] + input_spike_times[100 + 2 * i + 1] = [ + 1000 + (10 * (2 * i + 1)) for _ in range(10 + i)] + input_spike_times[150 + i * 2] = [ + 1250 + (10 * 2 * i) for _ in range(100 + i)] + input_spike_times[150 + 2 * i + 1] = [ + 1500 + (10 * (2 * i + 1)) for _ in range(100 + i)] # Setup p.setup(timestep=1.0) p.set_number_of_neurons_per_core(p.SpikeSourcePoisson, 50) p.set_number_of_neurons_per_core(p.SpikeSourceArray, npc_limit) -input_pop = p.Population(input_size, p.SpikeSourceArray(spike_times=input_spike_times)) +input_pop = p.Population(input_size, + p.SpikeSourceArray(spike_times=input_spike_times)) output_pop = p.Population(output_size, p.SpikeSourcePoisson(rate=0)) diff --git a/examples/icub_vor_examples/spinn_gym_examples/icub_vor_venv_test_perfect_motion.py b/examples/icub_vor_examples/spinn_gym_examples/icub_vor_venv_test_perfect_motion.py index 403f7b2d..bff484a3 100644 --- a/examples/icub_vor_examples/spinn_gym_examples/icub_vor_venv_test_perfect_motion.py +++ b/examples/icub_vor_examples/spinn_gym_examples/icub_vor_venv_test_perfect_motion.py @@ -1,12 +1,31 @@ +# Copyright (c) 2019-2021 The University of Manchester +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + import spynnaker8 as p import spinn_gym as gym -from pyNN.utility.plotting import Figure, Panel -import matplotlib.pyplot as plt +# from pyNN.utility.plotting import Figure, Panel +# import matplotlib.pyplot as plt import numpy as np -import os +# import os from spinn_front_end_common.utilities.globals_variables import get_simulator -from icub_utilities import * +from icub_utilities import ( + generate_head_position_and_velocity, retrieve_and_package_results, + remap_odd_even, remap_second_half_descending, ICUB_VOR_VENV_POP_SIZE, + plot_results) + # Parameter definition runtime = 3000 @@ -22,25 +41,29 @@ perfect_eye_vel = np.concatenate((head_vel[500:], head_vel[:500])) input_spike_times = [[] for _ in range(input_size)] -# the constant number (0.000031) is the effect of a single spike on the head position -# assert (np.isclose(np.abs(np.diff(head_pos)[0]), no_required_spikes_per_chunk * 0.000031), 0.001) +# the constant number (0.000031) is the effect of a single spike on the head +# position +# assert (np.isclose(np.abs(np.diff(head_pos)[0]), +# no_required_spikes_per_chunk * 0.000031), 0.001) sub_head_pos = np.diff(head_pos) head_movement_per_spike = 2 ** (-15) * gain sub_eye_pos = np.diff(np.concatenate((perfect_eye_pos, [perfect_eye_pos[0]]))) # no_required_spikes_per_chunk = 200 -no_required_spikes_per_chunk = np.ceil(np.abs(sub_head_pos[0]) / head_movement_per_spike) +no_required_spikes_per_chunk = np.ceil( + np.abs(sub_head_pos[0]) / head_movement_per_spike) # build ICubVorEnv model error_window_size = 10 # ms -npc_limit = 200 # 25 +npc_limit = 200 # 25 no_input_cores = int(input_size / npc_limit) input_spike_times = [[] for _ in range(input_size)] for ts in range(runtime - 1): # if 1000 <= ts < 2000: # continue sgn = np.sign(sub_eye_pos[ts % 1000]) - spikes_during_chunk = np.ceil(np.abs(sub_eye_pos[ts % 1000]) / head_movement_per_spike) + spikes_during_chunk = np.ceil( + np.abs(sub_eye_pos[ts % 1000]) / head_movement_per_spike) for i in range(int(spikes_during_chunk)): x = int(sgn <= 0) input_spike_times[(i % no_input_cores) * npc_limit + x].append(ts) @@ -49,7 +72,8 @@ p.setup(timestep=1.0) p.set_number_of_neurons_per_core(p.SpikeSourcePoisson, 50) p.set_number_of_neurons_per_core(p.SpikeSourceArray, npc_limit) -input_pop = p.Population(input_size, p.SpikeSourceArray(spike_times=input_spike_times)) +input_pop = p.Population(input_size, + p.SpikeSourceArray(spike_times=input_spike_times)) output_pop = p.Population(output_size, p.SpikeSourcePoisson(rate=0)) diff --git a/examples/icub_vor_examples/test_mfvn_lut.py b/examples/icub_vor_examples/test_mfvn_lut.py index 0cc00a42..fc30c9db 100644 --- a/examples/icub_vor_examples/test_mfvn_lut.py +++ b/examples/icub_vor_examples/test_mfvn_lut.py @@ -1,3 +1,18 @@ +# Copyright (c) 2019-2021 The University of Manchester +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + from spynnaker.pyNN.models.neuron.plasticity.stdp.common import write_mfvn_lut beta = 10 diff --git a/examples/icub_vor_examples/test_pfpc_lut.py b/examples/icub_vor_examples/test_pfpc_lut.py index a452596f..01e6a070 100644 --- a/examples/icub_vor_examples/test_pfpc_lut.py +++ b/examples/icub_vor_examples/test_pfpc_lut.py @@ -1,3 +1,18 @@ +# Copyright (c) 2019-2021 The University of Manchester +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + from spynnaker.pyNN.models.neuron.plasticity.stdp.common import write_pfpc_lut # import math From 661227add5dbf12446e32193ee2dc9a7888a3ad1 Mon Sep 17 00:00:00 2001 From: Andrew Gait Date: Fri, 19 Nov 2021 15:17:05 +0000 Subject: [PATCH 05/28] More tidying up of scripts --- examples/icub_vor_examples/cerebellum.py | 72 ++++++++++--------- examples/icub_vor_examples/dataflow.py | 15 ++-- .../single_purkinje_cell_pf_windowing.py | 2 +- .../single_purkinje_cell_test.py | 4 +- ...gle_vestibular_nuclei_potentiation_test.py | 6 +- 5 files changed, 53 insertions(+), 46 deletions(-) diff --git a/examples/icub_vor_examples/cerebellum.py b/examples/icub_vor_examples/cerebellum.py index 29af7a82..200edb27 100644 --- a/examples/icub_vor_examples/cerebellum.py +++ b/examples/icub_vor_examples/cerebellum.py @@ -19,18 +19,18 @@ # import logging import matplotlib.pyplot as plt -#from spynnaker8.utilities import DataHolder -from pacman.model.constraints.key_allocator_constraints import ( - FixedKeyAndMaskConstraint) -from pacman.model.graphs.application import ApplicationSpiNNakerLinkVertex -from pacman.model.routing_info import BaseKeyAndMask -from spinn_front_end_common.abstract_models.\ - abstract_provides_outgoing_partition_constraints import ( - AbstractProvidesOutgoingPartitionConstraints) -from spinn_utilities.overrides import overrides -from pyNN.utility import Timer -from pyNN.utility.plotting import Figure, Panel -from pyNN.random import RandomDistribution, NumpyRNG +# from spynnaker8.utilities import DataHolder +# from pacman.model.constraints.key_allocator_constraints import ( +# FixedKeyAndMaskConstraint) +# from pacman.model.graphs.application import ApplicationSpiNNakerLinkVertex +# from pacman.model.routing_info import BaseKeyAndMask +# from spinn_front_end_common.abstract_models.\ +# abstract_provides_outgoing_partition_constraints import ( +# AbstractProvidesOutgoingPartitionConstraints) +# from spinn_utilities.overrides import overrides +# from pyNN.utility import Timer +# from pyNN.utility.plotting import Figure, Panel +# from pyNN.random import RandomDistribution, NumpyRNG # cerebellum with simulated input RETINA_X_SIZE = 304 @@ -49,7 +49,8 @@ # # ApplicationSpiNNakerLinkVertex.__init__( # self, n_neurons, spinnaker_link_id=spinnaker_link_id, -# board_address=board_address, label=label, constraints=constraints) +# board_address=board_address, label=label, +# constraints=constraints) # #AbstractProvidesNKeysForPartition.__init__(self) # AbstractProvidesOutgoingPartitionConstraints.__init__(self) # @@ -64,15 +65,18 @@ # keys_and_masks=[BaseKeyAndMask( # base_key=0, #upper part of the key # mask=0xFFFFFC00)])] -# #keys, i.e. neuron addresses of the input population that sits in the ICUB vertex -# # this mask removes all spikes that have a "1" in the MSB and lets the spikes go only if the MSB are at "0" -# # it must have enough keys to host the input addressing space and the output (with the same keys) +# # keys, i.e. neuron addresses of the input population that sits in +# # the ICUB vertex: this mask removes all spikes that have a "1" in +# # the MSB and lets the spikes go only if the MSB are at "0" +# # it must have enough keys to host the input addressing space and +# # the output (with the same keys) # class ICUBInputVertexDataHolder(DataHolder): # # def __init__(self, spinnaker_link_id, board_address=None, # constraints=None, label=None): # DataHolder.__init__( -# self, {"spinnaker_link_id": spinnaker_link_id,"board_address": board_address, "label": label}) +# self, {"spinnaker_link_id": spinnaker_link_id, +# "board_address": board_address, "label": label}) # # @staticmethod # def build_model(): @@ -128,19 +132,20 @@ # Learning parameters sin rule (GrC to PC) min_weight_s = 0 max_weight_s = 0.1 -pot_alpha_s =0.01 -t_peak_s =100 +pot_alpha_s = 0.01 +t_peak_s = 100 initial_weight_s = 0.05 plastic_delay_s = 4 sim.setup(timestep=1.) -#sim.set_number_of_neurons_per_core(sim.IF_curr_exp, 255) +# sim.set_number_of_neurons_per_core(sim.IF_curr_exp, 255) # set up input populations # num_pxl = 304 * 240; # retina_pop = sim.Population( # 1024, ICUBInputVertexDataHolder(spinnaker_link_id=0), label='pop_retina') + # Sensorial Activity: input activity from vestibulus (will come from the head # IMU, now it is a test bench) def sensorial_activity(pt): @@ -149,11 +154,11 @@ def sensorial_activity(pt): _head_pos = [] _head_vel = [] - i = np.arange(0,2,0.01) + i = np.arange(0, 2, 0.01) for t in i: desired_speed=-np.cos( - t*2*np.pi)*MAX_AMPLITUDE*RELATIVE_AMPLITUDE*2.0*np.pi - desired_pos=-np.sin(t*2*np.pi)*MAX_AMPLITUDE*RELATIVE_AMPLITUDE + t * 2 * np.pi) * MAX_AMPLITUDE * RELATIVE_AMPLITUDE * 2.0 *np.pi + desired_pos=-np.sin(t * 2 * np.pi) * MAX_AMPLITUDE * RELATIVE_AMPLITUDE _head_pos.append(desired_pos) _head_vel.append(desired_speed) @@ -191,11 +196,12 @@ def sensorial_activity(pt): -((head_vel - mean) * (head_vel - mean))/(2.0 * sigma * sigma)) MF_vel_activity[i] = min_rate + gaussian * (max_rate - min_rate) - #sa_mean_freq = np.arange(0,1000,10) + # sa_mean_freq = np.arange(0,1000,10) sa_mean_freq = np.concatenate((MF_pos_activity, MF_vel_activity)) - out = [sa_mean_freq,head_pos,head_vel] + out = [sa_mean_freq, head_pos, head_vel] return out + # Error Activity: error from eye and head encoders def error_activity(pt): def compute_P_error(kp, head_position, eye_position): @@ -208,19 +214,19 @@ def compute_D_error(kd, head_velocity, eye_velocity): MAX_AMPLITUDE = 0.8 MAX_AMPLITUDE_EYE = 0.35 RELATIVE_AMPLITUDE_EYE = 1.0 - phaseShift = 1.0*np.pi + phaseShift = 1.0 * np.pi # simulated error between eye and head signals, error is zero if the waves # are in opposite phase _eye_pos = [] _eye_vel = [] ea_rate = [] - i = np.arange(0,2,0.01) + i = np.arange(0, 2, 0.01) for t_eye in i: desired_speed = -np.cos( - t_eye*2*np.pi+phaseShift) * MAX_AMPLITUDE_EYE * \ + t_eye * 2 * np.pi+phaseShift) * MAX_AMPLITUDE_EYE * \ RELATIVE_AMPLITUDE_EYE * 2.0 * np.pi desired_pos = -np.sin( - t_eye*2*np.pi+phaseShift) * MAX_AMPLITUDE_EYE * \ + t_eye * 2 * np.pi + phaseShift) * MAX_AMPLITUDE_EYE * \ RELATIVE_AMPLITUDE_EYE _eye_pos.append(desired_pos) _eye_vel.append(desired_speed) @@ -228,7 +234,7 @@ def compute_D_error(kd, head_velocity, eye_velocity): # single point over time eye_pos = _eye_pos[pt] eye_vel = _eye_vel[pt] - #print 'eye_pos ea',eye_pos + # print 'eye_pos ea',eye_pos head = sensorial_activity(pt) head_pos = head[1] @@ -241,7 +247,7 @@ def compute_D_error(kd, head_velocity, eye_velocity): velocity_error = compute_D_error(kd, head_vel, eye_vel) error=(position_error * 0.1 + ( - velocity_error/(2.0*np.pi)) * 0.9)/(MAX_AMPLITUDE*5) + velocity_error / (2.0 * np.pi)) * 0.9)/(MAX_AMPLITUDE * 5) # print(position_error, velocity_error, error) @@ -262,7 +268,7 @@ def compute_D_error(kd, head_velocity, eye_velocity): if(i < up_neuron_ID_threshold): rate.append(max_rate) elif(i 0xFFFE0000 MASK_IN = 0xFFFFFC00 # 0xFFFFFC00 NUM_NEUR_OUT = 1024 -#MASK_OUT =0xFFFFFC00 +# MASK_OUT =0xFFFFFC00 + class ICUBInputVertex( ApplicationSpiNNakerLinkVertex, @@ -113,7 +114,7 @@ def timed_commands(self): pop = sim.Population(None, ICUBInputVertex(spinnaker_link_id=0), label='pop_in') -#neural population , +# neural population , neuron_pop = sim.Population(NUM_NEUR_OUT, sim.IF_curr_exp(), label='neuron_pop') @@ -123,7 +124,7 @@ def timed_commands(self): # pop_out = sim.Population(None, ICUBOutputVertex(spinnaker_link_id=0), # label='pop_out') -sim.external_devices.activate_live_output_to(neuron_pop,pop) +sim.external_devices.activate_live_output_to(neuron_pop, pop) # recordings and simulations # neuron_pop.record("spikes") diff --git a/examples/icub_vor_examples/single_purkinje_cell_pf_windowing.py b/examples/icub_vor_examples/single_purkinje_cell_pf_windowing.py index 5831df3a..9b44cfdc 100644 --- a/examples/icub_vor_examples/single_purkinje_cell_pf_windowing.py +++ b/examples/icub_vor_examples/single_purkinje_cell_pf_windowing.py @@ -21,7 +21,7 @@ from pyNN.utility.plotting import Figure, Panel import matplotlib.pyplot as plt -p.setup(1) # simulation timestep (ms) +p.setup(1) # simulation timestep (ms) runtime = 500 # Post-synapse population diff --git a/examples/icub_vor_examples/single_purkinje_cell_test.py b/examples/icub_vor_examples/single_purkinje_cell_test.py index a69ffcda..c7bc54a0 100644 --- a/examples/icub_vor_examples/single_purkinje_cell_test.py +++ b/examples/icub_vor_examples/single_purkinje_cell_test.py @@ -43,7 +43,7 @@ purkinje_cell = p.Population( 1, # number of neurons p.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model - label="Purkinje Cell" # identifier + label="Purkinje Cell" # identifier ) # Spike source to send spike via synapse @@ -60,7 +60,7 @@ spike_times_2 = [100, 104, 107, 246] climbing_fibre = p.Population( 1, # number of sources - p.SpikeSourceArray, # source type + p.SpikeSourceArray, # source type {'spike_times': spike_times_2}, # source spike times label="src2" # identifier ) diff --git a/examples/icub_vor_examples/single_vestibular_nuclei_potentiation_test.py b/examples/icub_vor_examples/single_vestibular_nuclei_potentiation_test.py index a4df6e16..7f8121c8 100644 --- a/examples/icub_vor_examples/single_vestibular_nuclei_potentiation_test.py +++ b/examples/icub_vor_examples/single_vestibular_nuclei_potentiation_test.py @@ -15,9 +15,9 @@ from __future__ import print_function import spynnaker8 as p -import numpy -import math -import unittest +# import numpy +# import math +# import unittest from pyNN.utility.plotting import Figure, Panel import matplotlib.pyplot as plt From fc22bbbeff14f8eb2c3466e6590fe01ed8e4733c Mon Sep 17 00:00:00 2001 From: Andrew Gait Date: Mon, 22 Nov 2021 09:16:16 +0000 Subject: [PATCH 06/28] More tidying up of scripts --- examples/icub_vor_examples/cerebellum.py | 89 +- examples/icub_vor_examples/cerebellum_tb.py | 108 +- .../icub_vor_examples/pb_cerebellum_tb.py | 7 +- .../receptive_fields_for_motion.py | 268 +++-- .../single_vestibular_nuclei_mf_windowing.py | 2 +- .../normalised_head_positions_1000.csv | 1000 +++++++++++++++++ .../normalised_head_velocities_1000.csv | 1000 +++++++++++++++++ .../spinn_gym_examples/spynnaker.cfg | 2 +- 8 files changed, 2269 insertions(+), 207 deletions(-) create mode 100644 examples/icub_vor_examples/spinn_gym_examples/normalised_head_positions_1000.csv create mode 100644 examples/icub_vor_examples/spinn_gym_examples/normalised_head_velocities_1000.csv diff --git a/examples/icub_vor_examples/cerebellum.py b/examples/icub_vor_examples/cerebellum.py index 200edb27..854f5dbb 100644 --- a/examples/icub_vor_examples/cerebellum.py +++ b/examples/icub_vor_examples/cerebellum.py @@ -30,7 +30,7 @@ # from spinn_utilities.overrides import overrides # from pyNN.utility import Timer # from pyNN.utility.plotting import Figure, Panel -# from pyNN.random import RandomDistribution, NumpyRNG +from pyNN.random import RandomDistribution, NumpyRNG # cerebellum with simulated input RETINA_X_SIZE = 304 @@ -156,9 +156,10 @@ def sensorial_activity(pt): i = np.arange(0, 2, 0.01) for t in i: - desired_speed=-np.cos( - t * 2 * np.pi) * MAX_AMPLITUDE * RELATIVE_AMPLITUDE * 2.0 *np.pi - desired_pos=-np.sin(t * 2 * np.pi) * MAX_AMPLITUDE * RELATIVE_AMPLITUDE + desired_speed = -np.cos( + t * 2 * np.pi) * MAX_AMPLITUDE * RELATIVE_AMPLITUDE * 2.0 * np.pi + desired_pos = -np.sin( + t * 2 * np.pi) * MAX_AMPLITUDE * RELATIVE_AMPLITUDE _head_pos.append(desired_pos) _head_vel.append(desired_speed) @@ -207,6 +208,7 @@ def error_activity(pt): def compute_P_error(kp, head_position, eye_position): error = kp * (head_position + eye_position) return error + def compute_D_error(kd, head_velocity, eye_velocity): error = kd * (head_velocity + eye_velocity) return error @@ -214,7 +216,7 @@ def compute_D_error(kd, head_velocity, eye_velocity): MAX_AMPLITUDE = 0.8 MAX_AMPLITUDE_EYE = 0.35 RELATIVE_AMPLITUDE_EYE = 1.0 - phaseShift = 1.0 * np.pi + phaseShift = 1.0 * np.pi # simulated error between eye and head signals, error is zero if the waves # are in opposite phase _eye_pos = [] @@ -241,13 +243,13 @@ def compute_D_error(kd, head_velocity, eye_velocity): head_vel = head[2] # print(head_pos, eye_pos) - kp=15.0 + kp = 15.0 position_error = compute_P_error(kp, head_pos, eye_pos) - kd=15.0 + kd = 15.0 velocity_error = compute_D_error(kd, head_vel, eye_vel) - error=(position_error * 0.1 + ( - velocity_error / (2.0 * np.pi)) * 0.9)/(MAX_AMPLITUDE * 5) + error = (position_error * 0.1 + ( + velocity_error / (2.0 * np.pi)) * 0.9) / (MAX_AMPLITUDE * 5) # print(position_error, velocity_error, error) @@ -268,21 +270,21 @@ def compute_D_error(kd, head_velocity, eye_velocity): if(i < up_neuron_ID_threshold): rate.append(max_rate) elif(i=0.0: + if error_ >= 0.0: IO_agonist[0:100]=min_rate IO_antagonist=rate else: IO_antagonist[0:100]=min_rate IO_agonist=rate - ea_rate = np.concatenate((IO_agonist,IO_antagonist)) + ea_rate = np.concatenate((IO_agonist, IO_antagonist)) # print(j) # plt.plot(np.linspace(up_neuron_ID_threshold, # low_neuron_ID_threshold,200), ea_rate) @@ -295,11 +297,11 @@ def compute_D_error(kd, head_velocity, eye_velocity): IO_antagonist = np.zeros((100)) rate = [] - for i in range (100): + for i in range(100): if(i < up_neuron_ID_threshold): rate.append(max_rate) elif(i num_GC_neurons): - GC_upper_index = num_GC_neurons + GC_medium_index = int( + round((i / float_num_MF_neurons ) * num_GC_neurons)) + GC_lower_index = GC_medium_index - 40 + GC_upper_index = GC_medium_index + 60 - for j in range (GC_medium_index - GC_lower_index): - list_GOC_GC.append((i, GC_lower_index + j)) + if(GC_lower_index < 0): + GC_lower_index = 0 - for j in range(GC_medium_index + 20 - GC_medium_index): - list_MF_GC.append((i, GC_medium_index + j)) + elif(GC_upper_index > num_GC_neurons): + GC_upper_index = num_GC_neurons + for j in range (GC_medium_index - GC_lower_index): + list_GOC_GC.append((i, GC_lower_index + j)) - for j in range(GC_upper_index - GC_medium_index - 20): - list_GOC_GC_2.append((i, GC_medium_index + 20 + j)) + for j in range(GC_medium_index + 20 - GC_medium_index): + list_MF_GC.append((i, GC_medium_index + j)) -GO_GC_con1 = sim.Projection(GOC_population, - GC_population, - sim.FromListConnector(list_GOC_GC, weight_distr_GO, delay_distr)) + for j in range(GC_upper_index - GC_medium_index - 20): + list_GOC_GC_2.append((i, GC_medium_index + 20 + j)) -MF_GC_con2 = sim.Projection(MF_population, - GC_population, - sim.FromListConnector(list_MF_GC, weight_distr_MF, delay_distr)) +GO_GC_con1 = sim.Projection( + GOC_population,GC_population, + sim.FromListConnector(list_GOC_GC, weight_distr_GO, delay_distr)) -GO_GC_con3 = sim.Projection(GOC_population, - GC_population, - sim.FromListConnector( - list_GOC_GC_2, weight_distr_GO, delay_distr)) +MF_GC_con2 = sim.Projection( + MF_population, GC_population, + sim.FromListConnector(list_MF_GC, weight_distr_MF, delay_distr)) +GO_GC_con3 = sim.Projection( + GOC_population, GC_population, + sim.FromListConnector(list_GOC_GC_2, weight_distr_GO, delay_distr)) # Create PC-VN connections pc_vn_connections = sim.Projection( PC_population, VN_population, sim.OneToOneConnector(), #receptor_type='GABA', - synapse_type = sim.StaticSynapse(delay=1.0, weight=pc_vn_weights)) + synapse_type=sim.StaticSynapse(delay=1.0, weight=pc_vn_weights)) # Create MF-VN learning rule - cos mfvn_plas = sim.STDPMechanism( @@ -460,7 +457,7 @@ def compute_D_error(kd, head_velocity, eye_velocity): io_pc_connections = sim.Projection( IO_population, PC_population, sim.OneToOneConnector(), # receptor_type='COMPLEX_SPIKE', - synapse_type = sim.StaticSynapse(delay=1.0, weight=io_pc_weights)) + synapse_type=sim.StaticSynapse(delay=1.0, weight=io_pc_weights)) lif_pop = sim.Population(1024, sim.IF_curr_exp(), label='pop_lif') diff --git a/examples/icub_vor_examples/cerebellum_tb.py b/examples/icub_vor_examples/cerebellum_tb.py index 88e40f7a..691b4c92 100644 --- a/examples/icub_vor_examples/cerebellum_tb.py +++ b/examples/icub_vor_examples/cerebellum_tb.py @@ -23,7 +23,7 @@ # from spynnaker8.utilities import DataHolder # from pacman.model.constraints.key_allocator_constraints import ( # FixedKeyAndMaskConstraint) -from pacman.model.graphs.application import ApplicationSpiNNakerLinkVertex +# from pacman.model.graphs.application import ApplicationSpiNNakerLinkVertex # from pacman.model.routing_info import BaseKeyAndMask # from spinn_front_end_common.abstract_models.\ # abstract_provides_n_keys_for_partition import ( @@ -92,8 +92,8 @@ # Learning parameters sin rule (GrC to PC) min_weight_s = 0 max_weight_s = 0.01 -pot_alpha_s =0.01 -t_peak_s =100 +pot_alpha_s = 0.01 +t_peak_s = 100 initial_weight_s = max_weight_s # 0.0001 plastic_delay_s = 4 weight_dist_pfpc = RandomDistribution('uniform', @@ -118,10 +118,12 @@ _head_pos = [] _head_vel = [] -i = np.arange(0,1000,0.001) +i = np.arange(0, 1000, 0.001) for t in i: - desired_speed=-np.cos(t*2*np.pi)*MAX_AMPLITUDE*RELATIVE_AMPLITUDE*2.0*np.pi - desired_pos=-np.sin(t*2*np.pi)*MAX_AMPLITUDE*RELATIVE_AMPLITUDE + desired_speed = -np.cos( + t * 2 * np.pi) * MAX_AMPLITUDE * RELATIVE_AMPLITUDE * 2.0 * np.pi + desired_pos = -np.sin( + t * 2 * np.pi) * MAX_AMPLITUDE * RELATIVE_AMPLITUDE _head_pos.append(desired_pos) _head_vel.append(desired_speed) @@ -165,9 +167,10 @@ def sensorial_activity(pt): MF_vel_activity[i] = min_rate + gaussian * (max_rate - min_rate) sa_mean_freq = np.concatenate((MF_pos_activity, MF_vel_activity)) - out = [sa_mean_freq,head_pos,head_vel] + out = [sa_mean_freq, head_pos, head_vel] return out + # Error Activity: error from eye and head encoders def error_activity(error_): @@ -200,10 +203,11 @@ def error_activity(error_): IO_agonist[:] = H_RATE IO_antagonist[:] = L_RATE - ea_rate = np.concatenate((IO_agonist,IO_antagonist)) + ea_rate = np.concatenate((IO_agonist, IO_antagonist)) return ea_rate + def process_VN_spiketrains(VN_spikes, t_start): total_spikes = 0 for spiketrain in VN_spikes.segments[0].spiketrains: @@ -278,68 +282,61 @@ def process_VN_spiketrains(VN_spikes, t_start): receptor_type='excitatory') # Create MF-GC and GO-GC connections -float_num_MF_neurons = float (num_MF_neurons) +float_num_MF_neurons = float(num_MF_neurons) list_GOC_GC = [] list_MF_GC = [] list_GOC_GC_2 = [] # projections to subpopulations # https://github.com/SpiNNakerManchester/sPyNNaker8/issues/168) -for i in range (num_MF_neurons): - GC_medium_index = int( - round((i / float_num_MF_neurons ) * num_GC_neurons)) - GC_lower_index = GC_medium_index - 40 - GC_upper_index = GC_medium_index + 60 +for i in range(num_MF_neurons): + GC_medium_index = int( + round((i / float_num_MF_neurons) * num_GC_neurons)) + GC_lower_index = GC_medium_index - 40 + GC_upper_index = GC_medium_index + 60 - if(GC_lower_index < 0): - GC_lower_index = 0 + if(GC_lower_index < 0): + GC_lower_index = 0 - elif(GC_upper_index > num_GC_neurons): - GC_upper_index = num_GC_neurons + elif(GC_upper_index > num_GC_neurons): + GC_upper_index = num_GC_neurons - for j in range (GC_medium_index - GC_lower_index): - list_GOC_GC.append( - (i, GC_lower_index + j, + for j in range (GC_medium_index - GC_lower_index): + list_GOC_GC.append( + (i, GC_lower_index + j, # go_gc_weights, 1) - weight_distr_GO.next(), delay_distr.next()) - ) + weight_distr_GO.next(), delay_distr.next())) - for j in range(GC_medium_index + 20 - GC_medium_index): - list_MF_GC.append( - (i, GC_medium_index + j, + for j in range(GC_medium_index + 20 - GC_medium_index): + list_MF_GC.append( + (i, GC_medium_index + j, # mf_gc_weights, 1) - weight_distr_MF.next(), delay_distr.next()) - ) - + weight_distr_MF.next(), delay_distr.next())) - for j in range(GC_upper_index - GC_medium_index - 20): - list_GOC_GC_2.append( - (i, GC_medium_index + 20 + j, + for j in range(GC_upper_index - GC_medium_index - 20): + list_GOC_GC_2.append( + (i, GC_medium_index + 20 + j, # go_gc_weights, 1) - weight_distr_GO.next(), delay_distr.next()) - ) + weight_distr_GO.next(), delay_distr.next())) -GO_GC_con1 = sim.Projection(GOC_population, - GC_population, - sim.FromListConnector(list_GOC_GC), - receptor_type='inhibitory') # this should be inhibitory +GO_GC_con1 = sim.Projection( + GOC_population, GC_population, sim.FromListConnector(list_GOC_GC), + receptor_type='inhibitory') # this should be inhibitory -MF_GC_con2 = sim.Projection(MF_population, - GC_population, - sim.FromListConnector(list_MF_GC), - receptor_type='excitatory') +MF_GC_con2 = sim.Projection( + MF_population, GC_population, sim.FromListConnector(list_MF_GC), + receptor_type='excitatory') -GO_GC_con3 = sim.Projection(GOC_population, - GC_population, - sim.FromListConnector(list_GOC_GC_2), - receptor_type='inhibitory') +GO_GC_con3 = sim.Projection( + GOC_population, GC_population, sim.FromListConnector(list_GOC_GC_2), + receptor_type='inhibitory') # Create PC-VN connections pc_vn_connections = sim.Projection( PC_population, VN_population, sim.OneToOneConnector(), # receptor_type='GABA', # Should these be inhibitory? - synapse_type = sim.StaticSynapse(delay=delay_distr, weight=pc_vn_weights), + synapse_type=sim.StaticSynapse(delay=delay_distr, weight=pc_vn_weights), receptor_type='inhibitory') # Create MF-VN learning rule - cos @@ -354,8 +351,7 @@ def process_VN_spiketrains(VN_spikes, t_start): mf_vn_connections = sim.Projection( MF_population, VN_population, sim.AllToAllConnector(), # Needs mapping as FromListConnector to make efficient - synapse_type=mfvn_plas, - receptor_type="excitatory") + synapse_type=mfvn_plas, receptor_type="excitatory") # Create projection from PC to VN -- replaces "TEACHING SIGNAL" pc_vn_connections = sim.Projection( @@ -368,15 +364,13 @@ def process_VN_spiketrains(VN_spikes, t_start): timing_dependence=sim.extra_models.TimingDependencePFPC(t_peak=t_peak_s), weight_dependence=sim.extra_models.WeightDependencePFPC( w_min=min_weight_s, w_max=max_weight_s, pot_alpha=pot_alpha_s), - weight=initial_weight_s, - delay=delay_distr + weight=initial_weight_s, delay=delay_distr ) # Create PF-PC connections pf_pc_connections = sim.Projection( GC_population, PC_population, sim.AllToAllConnector(), - synapse_type=pfpc_plas, - receptor_type="excitatory") + synapse_type=pfpc_plas, receptor_type="excitatory") # Create IO-PC connections. This synapse with "receptor_type=COMPLEX_SPIKE" # propagates the learning signals that drive the plasticity mechanisms in @@ -384,7 +378,7 @@ def process_VN_spiketrains(VN_spikes, t_start): cf_pc_connections = sim.Projection( CF_population, PC_population, sim.OneToOneConnector(), # receptor_type='COMPLEX_SPIKE', - synapse_type = sim.StaticSynapse(delay=1.0, weight=cf_pc_weights), + synapse_type=sim.StaticSynapse(delay=1.0, weight=cf_pc_weights), receptor_type='excitatory') # lif_pop = sim.Population(1024, sim.IF_curr_exp(), label='pop_lif') @@ -427,13 +421,12 @@ def process_VN_spiketrains(VN_spikes, t_start): VN_transfer_func = [] for i in range(samples_in_repeat): - sim.run(sample_time) VN_spikes = VN_population.get_data('spikes') VN_transfer_func.append(process_VN_spiketrains(VN_spikes, total_runtime)) - total_runtime +=sample_time + total_runtime += sample_time print(total_runtime) @@ -499,7 +492,8 @@ def process_VN_spiketrains(VN_spikes, t_start): yticks=True, markersize=2, xlim=(0, total_runtime), xlabel='VN_spikes'), Panel(VN_spikes.segments[0].filter(name='gsyn_inh')[0], - ylabel="Membrane potential (mV)", yticks=True, xlim=(0, total_runtime)) + ylabel="Membrane potential (mV)", yticks=True, + xlim=(0,total_runtime)) ) plt.show(block=False) diff --git a/examples/icub_vor_examples/pb_cerebellum_tb.py b/examples/icub_vor_examples/pb_cerebellum_tb.py index dcb74d11..8845f4d8 100644 --- a/examples/icub_vor_examples/pb_cerebellum_tb.py +++ b/examples/icub_vor_examples/pb_cerebellum_tb.py @@ -50,6 +50,7 @@ 'vn' ] + # PAB UTILS def get_plot_order(for_keys): # Compute plot order @@ -728,7 +729,7 @@ def process_VN_spiketrains(VN_spikes, t_start): conn = np.array(conn.tolist()) final_connectivity[label] = conn -except: +except Exception as e: # This simulator might not support the way this is done final_connectivity = [] traceback.print_exc() @@ -737,7 +738,7 @@ def process_VN_spiketrains(VN_spikes, t_start): print("job done") # Report time taken print("Total time elapsed -- " + str(total_time)) -# ============================ Plotting some stuff ============================ +# ============================ Plotting some stuff =========================== # ============================ PAB ANALYSIS ============================ # Compute plot order @@ -780,7 +781,7 @@ def process_VN_spiketrains(VN_spikes, t_start): try: x = np.concatenate(conn) conn = x - except: + except Exception as e: traceback.print_exc() names = [('source', 'int_'), ('target', 'int_'), diff --git a/examples/icub_vor_examples/receptive_fields_for_motion.py b/examples/icub_vor_examples/receptive_fields_for_motion.py index c2afae05..aea8adfc 100644 --- a/examples/icub_vor_examples/receptive_fields_for_motion.py +++ b/examples/icub_vor_examples/receptive_fields_for_motion.py @@ -15,44 +15,46 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import socket +# import socket import spynnaker8 as sim import numpy as np -#import logging +# import logging import matplotlib.pyplot as plt from decode_events import * from functions import * -import yarp +# import yarp -from pacman.model.constraints.key_allocator_constraints import FixedKeyAndMaskConstraint +from pacman.model.constraints.key_allocator_constraints import ( + FixedKeyAndMaskConstraint) from pacman.model.graphs.application import ApplicationSpiNNakerLinkVertex from pacman.model.routing_info import BaseKeyAndMask -from spinn_front_end_common.abstract_models.abstract_provides_n_keys_for_partition import AbstractProvidesNKeysForPartition -from spinn_front_end_common.abstract_models.abstract_provides_outgoing_partition_constraints import AbstractProvidesOutgoingPartitionConstraints +from spinn_front_end_common.abstract_models.\ + abstract_provides_outgoing_partition_constraints import ( + AbstractProvidesOutgoingPartitionConstraints) from spinn_utilities.overrides import overrides -from spinn_front_end_common.abstract_models.abstract_provides_incoming_partition_constraints import AbstractProvidesIncomingPartitionConstraints +from spinn_front_end_common.abstract_models.\ + abstract_provides_incoming_partition_constraints import ( + AbstractProvidesIncomingPartitionConstraints) from pacman.executor.injection_decorator import inject_items -from pacman.operations.routing_info_allocator_algorithms.malloc_based_routing_allocator.utils import get_possible_masks -from spinn_front_end_common.utility_models.command_sender_machine_vertex import CommandSenderMachineVertex +from pacman.operations.routing_info_allocator_algorithms.\ + malloc_based_routing_allocator.utils import get_possible_masks +from spinn_front_end_common.utility_models.command_sender_machine_vertex \ + import CommandSenderMachineVertex from spinn_front_end_common.abstract_models \ import AbstractSendMeMulticastCommandsVertex from spinn_front_end_common.utility_models.multi_cast_command \ import MultiCastCommand - -from pyNN.utility import Timer from pyNN.utility.plotting import Figure, Panel -from pyNN.random import RandomDistribution, NumpyRNG - -from spynnaker.pyNN.models.neuron.plasticity.stdp.common import plasticity_helpers # yarp.Network.init() -NUM_NEUR_IN = 1024 #1024 # 2x240x304 mask -> 0xFFFE0000 -MASK_IN = 0xFFFFFC00 #0xFFFFFC00 +NUM_NEUR_IN = 1024 # 1024 # 2x240x304 mask -> 0xFFFE0000 +MASK_IN = 0xFFFFFC00 # 0xFFFFFC00 NUM_NEUR_OUT = 1024 -MASK_OUT =0xFFFFFFFC +MASK_OUT = 0xFFFFFFFC + class ICUBInputVertex( ApplicationSpiNNakerLinkVertex, @@ -67,7 +69,7 @@ def __init__(self, spinnaker_link_id, board_address=None, self, n_atoms=NUM_NEUR_IN, spinnaker_link_id=spinnaker_link_id, board_address=board_address, label=label) - AbstractProvidesNKeysForPartition.__init__(self) + # AbstractProvidesNKeysForPartition.__init__(self) AbstractProvidesOutgoingPartitionConstraints.__init__(self) AbstractSendMeMulticastCommandsVertex.__init__(self) @@ -76,19 +78,18 @@ def __init__(self, spinnaker_link_id, board_address=None, def get_outgoing_partition_constraints(self, partition): return [FixedKeyAndMaskConstraint( keys_and_masks=[BaseKeyAndMask( - base_key=0, #upper part of the key, + base_key=0, # upper part of the key, mask=MASK_IN)])] - #keys, i.e. neuron addresses of the input population that sits in the ICUB vertex, - @inject_items({"graph_mapper": "MemoryGraphMapper"}) @overrides(AbstractProvidesIncomingPartitionConstraints. - get_incoming_partition_constraints, - additional_arguments=["graph_mapper"]) - def get_incoming_partition_constraints(self, partition, graph_mapper): + get_incoming_partition_constraints) + def get_incoming_partition_constraints(self, partition): if isinstance(partition.pre_vertex, CommandSenderMachineVertex): return [] - index = graph_mapper.get_machine_vertex_index(partition.pre_vertex) - vertex_slice = graph_mapper.get_slice(partition.pre_vertex) + # index = graph_mapper.get_machine_vertex_index(partition.pre_vertex) + # vertex_slice = graph_mapper.get_slice(partition.pre_vertex) + index = partition.pre_vertex.index + vertex_slice = partition.pre_vertex.vertex_slice mask = get_possible_masks(vertex_slice.n_atoms)[0] key = (0x1000 + index) << 16 return [FixedKeyAndMaskConstraint( @@ -111,6 +112,7 @@ def pause_stop_commands(self): def timed_commands(self): return [] + def convert_data_mapping(x, y, down_sample_x, down_sample_y): if simulate: x /= (304 / down_sample_x) @@ -120,12 +122,15 @@ def convert_data_mapping(x, y, down_sample_x, down_sample_y): address = (int(y) << 12) + (int(x) << 1) + 1 return int(address) + def convert_data(data): converted_data = [[] for i in range(304*240)] for item in data: - converted_data[convert_data_mapping(item[2], item[3], width, length)].append(item[0]*1000) + converted_data[convert_data_mapping( + item[2], item[3], width, length)].append(item[0]*1000) return converted_data + def convert_pixel_mapping(pixel, down_sample_x, down_sample_y): x = pixel % 304 y = (pixel - x) / 304 @@ -137,8 +142,9 @@ def convert_pixel_mapping(pixel, down_sample_x, down_sample_y): address = (y << 12) + (x << 1) + 1 return address -def map_neurons_to_field(length, x_segments, y_segments, scale_down, layers, x_size=304, y_size=240, central_x=304, - central_y=240): +def map_neurons_to_field( + length, x_segments, y_segments, scale_down, layers, + x_size=304, y_size=240, central_x=304, central_y=240): # base-filter = width x (dimension / segments) # Y*8 E*2 X*9 P*1 # x_segments /= 2 @@ -155,52 +161,75 @@ def map_neurons_to_field(length, x_segments, y_segments, scale_down, layers, x_s field_size_y.append([field_size_length_y, field_size_width_y]) # map the field size to real pixels - pixel_mapping = [[[[-1, -1] for x in range(y_size)] for y in range(x_size)] for i in range(layers + 1)] - field_size = [[[0 for i in range(y_segments)] for j in range(x_segments)] for k in range(layers+1)] + pixel_mapping = [[[[-1, -1] for x in range(y_size)] for y in range(x_size)] + for i in range(layers + 1)] + field_size = [[[0 for i in range(y_segments)] for j in range(x_segments)] + for k in range(layers+1)] x_border = int(x_size - central_x) # / 2 y_border = int(y_size - central_y) # / 2 for x in range(central_x / 2): for y in range(central_y / 2): x_segment = int(x / ((x_size - (x_border)) / x_segments)) y_segment = int(y / ((y_size - (y_border)) / y_segments)) - pixel_mapping[layers][(x_size - (x_border / 2)) - x -1][y + y_border] = [(x_segments - 1) - x_segment, y_segment] - pixel_mapping[layers][x + x_border][(y_size - (y_border / 2)) - y - 1] = [x_segment, (y_segments - 1) - y_segment] - pixel_mapping[layers][(x_size - (x_border / 2)) - x - 1][(y_size - (y_border / 2)) - y - 1] = [(x_segments - 1) - x_segment, (y_segments - 1) - y_segment] - pixel_mapping[layers][x + x_border][y + y_border] = [x_segment, y_segment] + pixel_mapping[layers][(x_size - (x_border / 2)) - x -1][ + y + y_border] = [(x_segments - 1) - x_segment, y_segment] + pixel_mapping[layers][x + x_border][ + (y_size - (y_border / 2)) - y - 1] = [ + x_segment, (y_segments - 1) - y_segment] + pixel_mapping[layers][(x_size - (x_border / 2)) - x - 1][ + (y_size - (y_border / 2)) - y - 1] = [ + (x_segments - 1) - x_segment, (y_segments - 1) - y_segment] + pixel_mapping[layers][x + x_border][y + y_border] = [ + x_segment, y_segment] # for layer in range(layers): # x_border = int(x_size - (x_size * (scale_down ** layer))) # / 2 # y_border = int(y_size - (y_size * (scale_down ** layer))) # / 2 + # scale_val = scale_down ** layer # if x_border < x_size / 2 or y_border < y_size / 2: # for x in range(0, (x_size / 2) - x_border): # for y in range(0, (y_size / 2) - y_border): - # if x < length * (scale_down ** layer) or y < length * (scale_down ** layer): - # x_segment = int(x / ((x_size - (x_border * 2)) / x_segments)) - # y_segment = int(y / ((y_size - (y_border * 2)) / y_segments)) + # if x < length * (scale_val) or y < length * (scale_val): + # x_segment = int( + # x / ((x_size - (x_border * 2)) / x_segments)) + # y_segment = int( + # y / ((y_size - (y_border * 2)) / y_segments)) # pixel_mapping[layer][x + x_border][y + y_border] = \ # [x_segment, y_segment] # field_size[layer][x_segment][y_segment] += 1 - # pixel_mapping[layer][((x_size - 1) - x_border) - x][((y_size - 1) - y_border) - y] = \ - # [(x_segments - 1) - x_segment, (y_segments - 1) - y_segment] - # field_size[layer][(x_segments - 1) - x_segment][(y_segments - 1) - y_segment] += 1 - # pixel_mapping[layer][x + x_border][((y_size - 1) - y_border) - y] = \ - # [x_segment, (y_segments - 1) - y_segment] - # field_size[layer][x_segment][(y_segments - 1) - y_segment] += 1 - # pixel_mapping[layer][((x_size - 1) - x_border) - x][y + y_border] = \ - # [(x_segments - 1) - x_segment, y_segment] - # field_size[layer][(x_segments - 1) - x_segment][y_segment] += 1 - # # print x, x_segment, x_segments, y, y_segment, y_segments - # # print x, y - # print "finished layer", layer, "with border", x_border, y_border + # pixel_mapping[layer][((x_size - 1) - x_border) - x][ + # ((y_size - 1) - y_border) - y] = [ + # (x_segments - 1) - x_segment, + # (y_segments - 1) - y_segment] + # field_size[layer][(x_segments - 1) - x_segment][ + # (y_segments - 1) - y_segment] += 1 + # pixel_mapping[layer][x + x_border][ + # ((y_size - 1) - y_border) - y] = [ + # x_segment, (y_segments - 1) - y_segment] + # field_size[layer][x_segment][ + # (y_segments - 1) - y_segment] += 1 + # pixel_mapping[layer][((x_size - 1) - x_border) - x][ + # y + y_border] = [ + # (x_segments - 1) - x_segment, y_segment] + # field_size[layer][(x_segments - 1) - x_segment][ + # y_segment] += 1 + # # (print x, x_segment, x_segments, y, y_segment, + # # y_segments) + # # print(x, y) + # print("finished layer", layer, "with border", x_border, y_border) print("done mapping") return pixel_mapping, field_size + def convert_xy_field_to_id(field_x, field_y, width, length): # receptive_fields = width * 2 + length * 2 - 2 - id = (field_y * width) + field_x - return id + id_val = (field_y * width) + field_x + return id_val + -def map_to_from_list(mapping, width, length, scale_down, pixel_weight=5, x_size=304, y_size=240, motor_weight=1.5): +def map_to_from_list( + mapping, width, length, scale_down, pixel_weight=5, x_size=304, + y_size=240, motor_weight=1.5): # motor_weight *= width * length mapping, field_size = mapping layers = len(mapping) @@ -214,17 +243,28 @@ def map_to_from_list(mapping, width, length, scale_down, pixel_weight=5, x_size= for y in range(y_size): if mapping[layer][x][y][0] != -1: if layer < layers - 1: - weight = pixel_weight / float(field_size[layer][mapping[layer][x][y][0]][mapping[layer][x][y][1]]) + weight = pixel_weight / float( + field_size[layer][mapping[layer][x][y][0]][ + mapping[layer][x][y][1]]) else: weight = pixel_weight #/ 16. - connection = [convert_pixel_mapping(x + (304 * y), width, length), - convert_xy_field_to_id(mapping[layer][x][y][0], mapping[layer][x][y][1], width, length), - weight, - 1] + connection = [ + convert_pixel_mapping(x + (304 * y), width, length), + convert_xy_field_to_id( + mapping[layer][x][y][0], mapping[layer][x][y][1], + width, length), + weight, 1] if connection not in from_list_connections: from_list_connections[layer].append(connection) - print(x, y, x + (304 * y), convert_pixel_mapping(x + (304 * y), width, length), convert_xy_field_to_id(mapping[layer][x][y][0], mapping[layer][x][y][1], width, length)) - if convert_pixel_mapping(x + (304 * y), width, length) >= 304*240 or convert_xy_field_to_id(mapping[layer][x][y][0], mapping[layer][x][y][1], width, length) >= width*length: + print(x, y, x + (304 * y), convert_pixel_mapping( + x + (304 * y), width, length), convert_xy_field_to_id( + mapping[layer][x][y][0], mapping[layer][x][y][1], + width, length)) + if convert_pixel_mapping( + x + (304 * y), width, length) >= 304*240 or \ + convert_xy_field_to_id( + mapping[layer][x][y][0], mapping[layer][x][y][1], + width, length) >= width*length: print("oops") for connection in from_list_connections[layer]: if connection[1] % width < width / 2: @@ -247,8 +287,11 @@ def map_to_from_list(mapping, width, length, scale_down, pixel_weight=5, x_size= print("created connections") return from_list_connections, motor_conn -def split_the_from_list(input, output, from_list, receptor_type="excitatory", max_conn=255): - # from_list_segments = [from_list[x:x + max_conn] for x in xrange(0, len(from_list), max_conn)] + +def split_the_from_list( + input, output, from_list, receptor_type="excitatory", max_conn=255): + # from_list_segments = [from_list[x:x + max_conn] for x in xrange( + # 0, len(from_list), max_conn)] # file_name = "connections.txt" # with open(file_name, 'w') as f: # for segment in from_list_segments: @@ -258,22 +301,29 @@ def split_the_from_list(input, output, from_list, receptor_type="excitatory", ma # f.write("%s " % item) # f.write("\n") # connections_file.close() - # sim.Projection(input, output, sim.FromFileConnector(file_name), receptor_type=receptor_type) + # sim.Projection(input, output, sim.FromFileConnector(file_name), + # receptor_type=receptor_type) - from_list_segments = [from_list[x:x + max_conn] for x in xrange(0, len(from_list), max_conn)] + from_list_segments = [from_list[x:x + max_conn] for x in range( + 0, len(from_list), max_conn)] for connection in from_list_segments: - sim.Projection(input, output, sim.FromListConnector(connection), receptor_type=receptor_type) + sim.Projection(input, output, sim.FromListConnector(connection), + receptor_type=receptor_type) + def segment_hidden_pop(from_list, width, length, pre): hidden_pops = [] list_of_lists = [[] for i in range(width*length)] for connection in from_list: if pre: - list_of_lists[connection[0]].append([0, connection[1], connection[2], connection[3]]) + list_of_lists[connection[0]].append( + [0, connection[1], connection[2], connection[3]]) else: - list_of_lists[connection[1]].append([connection[0], 0, connection[2], connection[3]]) + list_of_lists[connection[1]].append( + [connection[0], 0, connection[2], connection[3]]) return list_of_lists + def connect_it_up(visual_input, motor_output, connections, width, length): visual_connections, motor_conn = connections layers = len(motor_conn) @@ -281,14 +331,18 @@ def connect_it_up(visual_input, motor_output, connections, width, length): hidden_pops = [] for layer in range(layers): motor_conn_e, motor_conn_i = motor_conn[layer] - # hidden_pop = sim.Population(width * length, sim.IF_curr_exp(), label="hidden_pop_{}".format(layer)) + # hidden_pop = sim.Population(width * length, sim.IF_curr_exp(), + # label="hidden_pop_{}".format(layer)) # hidden_pops.append(hidden_pop) for i in range(width*length): - hidden_pop = sim.Population(1, sim.IF_curr_exp(tau_refrac=3), label="hidden_pop_{}_{}".format(layer, i)) + hidden_pop = sim.Population( + 1, sim.IF_curr_exp(tau_refrac=3), + label="hidden_pop_{}_{}".format(layer, i)) if simulate: hidden_pop.record(["spikes", "v"]) hidden_pops.append(hidden_pop) - list_of_lists = segment_hidden_pop(visual_connections[layer], width, length, False) + list_of_lists = segment_hidden_pop( + visual_connections[layer], width, length, False) for i in range(len(list_of_lists)): split_the_from_list(visual_input, hidden_pops[i], list_of_lists[i]) list_of_lists = segment_hidden_pop(motor_conn_e, width, length, True) @@ -296,10 +350,13 @@ def connect_it_up(visual_input, motor_output, connections, width, length): split_the_from_list(hidden_pops[i], motor_output, list_of_lists[i]) list_of_lists = segment_hidden_pop(motor_conn_i, width, length, True) for i in range(len(list_of_lists)): - split_the_from_list(hidden_pops[i], motor_output, list_of_lists[i], receptor_type="inhibitory") - # split_the_from_list(visual_input, hidden_pop, visual_connections[layer]) + split_the_from_list(hidden_pops[i], motor_output, list_of_lists[i], + receptor_type="inhibitory") + # split_the_from_list(visual_input, hidden_pop, + # visual_connections[layer]) # split_the_from_list(hidden_pop, motor_output, motor_conn_e) - # split_the_from_list(hidden_pops[layer], motor_output, motor_conn_i, receptor_type="inhibitory") + # split_the_from_list(hidden_pops[layer], motor_output, motor_conn_i, + # receptor_type="inhibitory") all_pops.append(hidden_pops) print("finished connecting") return all_pops @@ -337,7 +394,9 @@ def connect_it_up(visual_input, motor_output, connections, width, length): dm.load_AE_from_yarp('acquisitions10042019/circle10042019') # Loading decoded events; data(timestamp, channel, x, y, polarity) - stereo_data = np.loadtxt('acquisitions10042019/circle10042019/decoded_events.txt', delimiter=',') + stereo_data = np.loadtxt( + 'acquisitions10042019/circle10042019/decoded_events.txt', + delimiter=',') [left_data, right_data] = split_stereo_data(stereo_data) # left_data.tolist() # right_data.tolist() @@ -347,15 +406,18 @@ def connect_it_up(visual_input, motor_output, connections, width, length): print('ATIS data processing ended') - vis_pop = sim.Population(width*length, sim.SpikeSourceArray(new_left), label='pop_in') + vis_pop = sim.Population(width*length, sim.SpikeSourceArray(new_left), + label='pop_in') else: - vis_pop = sim.Population(None, ICUBInputVertex(spinnaker_link_id=0), label='pop_in') + vis_pop = sim.Population(None, ICUBInputVertex(spinnaker_link_id=0), + label='pop_in') pop_out = sim.Population(4, sim.IF_curr_exp(tau_refrac=3), label="motor_control") if simulate: pop_out.record(['spikes', 'v']) -# pop_out = sim.Population(None, ICUBOutputVertex(spinnaker_link_id=0), label='pop_out') +# pop_out = sim.Population(None, ICUBOutputVertex(spinnaker_link_id=0), +# label='pop_out') # hidden_pops = connect_it_up(vis_pop, pop_out, connections_1, 19, 15) hidden_pops = connect_it_up(vis_pop, pop_out, connections_2, width, length) @@ -365,9 +427,11 @@ def connect_it_up(visual_input, motor_output, connections, width, length): # test_input = sim.Population(304*240, sim.IF_curr_exp(), label="readout") # test_input.record(['spikes', 'v']) -# sim.Projection(vis_pop, test_input, sim.OneToOneConnector(), sim.StaticSynapse(weight=0.1)) +# sim.Projection(vis_pop, test_input, sim.OneToOneConnector(), +# sim.StaticSynapse(weight=0.1)) -# sim.Projection(pop, neuron_pop, sim.OneToOneConnector(), sim.StaticSynapse(weight=20.0)) +# sim.Projection(pop, neuron_pop, sim.OneToOneConnector(), +# sim.StaticSynapse(weight=20.0)) sim.external_devices.activate_live_output_to(pop_out, vis_pop) @@ -388,12 +452,12 @@ def connect_it_up(visual_input, motor_output, connections, width, length): #recordings and simulations, #neuron_pop.record("spikes") -simtime = 30000 #ms, +simtime = 30000 # ms if simulate: sim.run(simtime) else: sim.external_devices.run_forever() - raw_input('Press enter to stop') + input('Press enter to stop') # continuous run until key press # remember: do NOT record when running in this mode @@ -411,24 +475,30 @@ def connect_it_up(visual_input, motor_output, connections, width, length): Figure( # raster plot of the neuron_pop - Panel(exc_spikes.segments[0].spiketrains, xlabel="Time/ms", xticks=True, - yticks=True, markersize=0.2, xlim=(0, simtime)), - Panel(exc_v.segments[0].filter(name='v')[0], ylabel="Membrane potential (mV)", yticks=True), - Panel(hidden_spikes[0].segments[0].spiketrains, xlabel="Time/ms", xticks=True, - yticks=True, markersize=0.2, xlim=(0, simtime)), - Panel(hidden_v[0].segments[0].filter(name='v')[0], ylabel="Membrane potential (mV)", yticks=True), - Panel(hidden_spikes[1].segments[0].spiketrains, xlabel="Time/ms", xticks=True, - yticks=True, markersize=0.2, xlim=(0, simtime)), - Panel(hidden_v[1].segments[0].filter(name='v')[0], ylabel="Membrane potential (mV)", yticks=True), - Panel(hidden_spikes[2].segments[0].spiketrains, xlabel="Time/ms", xticks=True, - yticks=True, markersize=0.2, xlim=(0, simtime)), - Panel(hidden_v[2].segments[0].filter(name='v')[0], ylabel="Membrane potential (mV)", yticks=True), - Panel(hidden_spikes[3].segments[0].spiketrains, xlabel="Time/ms", xticks=True, - yticks=True, markersize=0.2, xlim=(0, simtime)), - Panel(hidden_v[3].segments[0].filter(name='v')[0], ylabel="Membrane potential (mV)", yticks=True), - # Panel(input_spikes.segments[0].spiketrains, xlabel="Time/ms", xticks=True, - # yticks=True, markersize=0.2, xlim=(0, simtime)), - # Panel(input_v.segments[0].filter(name='v')[0], ylabel="Membrane potential (mV)", yticks=True), + Panel(exc_spikes.segments[0].spiketrains, xlabel="Time/ms", + xticks=True, yticks=True, markersize=0.2, xlim=(0, simtime)), + Panel(exc_v.segments[0].filter(name='v')[0], + ylabel="Membrane potential (mV)", yticks=True), + Panel(hidden_spikes[0].segments[0].spiketrains, xlabel="Time/ms", + xticks=True, yticks=True, markersize=0.2, xlim=(0, simtime)), + Panel(hidden_v[0].segments[0].filter(name='v')[0], + ylabel="Membrane potential (mV)", yticks=True), + Panel(hidden_spikes[1].segments[0].spiketrains, xlabel="Time/ms", + xticks=True, yticks=True, markersize=0.2, xlim=(0, simtime)), + Panel(hidden_v[1].segments[0].filter(name='v')[0], + ylabel="Membrane potential (mV)", yticks=True), + Panel(hidden_spikes[2].segments[0].spiketrains, xlabel="Time/ms", + xticks=True, yticks=True, markersize=0.2, xlim=(0, simtime)), + Panel(hidden_v[2].segments[0].filter(name='v')[0], + ylabel="Membrane potential (mV)", yticks=True), + Panel(hidden_spikes[3].segments[0].spiketrains, xlabel="Time/ms", + xticks=True, yticks=True, markersize=0.2, xlim=(0, simtime)), + Panel(hidden_v[3].segments[0].filter(name='v')[0], + ylabel="Membrane potential (mV)", yticks=True), + # Panel(input_spikes.segments[0].spiketrains, xlabel="Time/ms", + # xticks=True, yticks=True, markersize=0.2, xlim=(0, simtime)), + # Panel(input_v.segments[0].filter(name='v')[0], + # ylabel="Membrane potential (mV)", yticks=True), title="neuron_pop: spikes" ) plt.show() diff --git a/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing.py b/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing.py index aae438d3..887fa95d 100644 --- a/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing.py +++ b/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing.py @@ -63,7 +63,7 @@ ) # Spike source to send spike via synapse from climbing fibre -pc_spike_times = [55, 80, 90, 95, 96, 201] #, 104, 107, 246] +pc_spike_times = [55, 80, 90, 95, 96, 201] # 104, 107, 246] purkinje_cell_src = p.Population( 1, # number of sources p.SpikeSourceArray, # source type diff --git a/examples/icub_vor_examples/spinn_gym_examples/normalised_head_positions_1000.csv b/examples/icub_vor_examples/spinn_gym_examples/normalised_head_positions_1000.csv new file mode 100644 index 00000000..a66f167a --- /dev/null +++ b/examples/icub_vor_examples/spinn_gym_examples/normalised_head_positions_1000.csv @@ -0,0 +1,1000 @@ +5.000000000000000000e-01 +4.968584280172205769e-01 +4.937169800583237067e-01 +4.905757801422959141e-01 +4.874349522783312239e-01 +4.842946204609358540e-01 +4.811549086650327434e-01 +4.780159408410675770e-01 +4.748778409101152009e-01 +4.717407327589877020e-01 +4.686047402353433200e-01 +4.654699871427970814e-01 +4.623365972360336529e-01 +4.592046942159212497e-01 +4.560744017246283755e-01 +4.529458433407428375e-01 +4.498191425743925387e-01 +4.466944228623700996e-01 +4.435718075632591462e-01 +4.404514199525650930e-01 +4.373333832178478708e-01 +4.342178204538587050e-01 +4.311048546576810025e-01 +4.279946087238739594e-01 +4.248872054396214404e-01 +4.217827674798845239e-01 +4.186814174025581536e-01 +4.155832776436330644e-01 +4.124884705123619821e-01 +4.093971181864313191e-01 +4.063093427071376995e-01 +4.032252659745698686e-01 +4.001450097427964869e-01 +3.970686956150593638e-01 +3.939964450389726869e-01 +3.909283793017287456e-01 +3.878646195253094286e-01 +3.848052866617047152e-01 +3.817505014881376613e-01 +3.787003846022963249e-01 +3.756550564175726303e-01 +3.726146371583089478e-01 +3.695792468550515575e-01 +3.665490053398122172e-01 +3.635240322413374470e-01 +3.605044469803853624e-01 +3.574903687650119455e-01 +3.544819165858640875e-01 +3.514792092114825128e-01 +3.484823651836130298e-01 +3.454915028125263299e-01 +3.425067401723476124e-01 +3.395281950963952022e-01 +3.365559851725287155e-01 +3.335902277385066617e-01 +3.306310398773543158e-01 +3.276785384127414713e-01 +3.247328399043704628e-01 +3.217940606433745687e-01 +3.188623166477271287e-01 +3.159377236576610404e-01 +3.130203971310997479e-01 +3.101104522390994434e-01 +3.072080038613017594e-01 +3.043131665813987863e-01 +3.014260546826096898e-01 +2.985467821431686541e-01 +2.956754626318254808e-01 +2.928122095033579009e-01 +2.899571357940968763e-01 +2.871103542174636702e-01 +2.842719771595204614e-01 +2.814421166745335601e-01 +2.786208844805492801e-01 +2.758083919549839114e-01 +2.730047501302266255e-01 +2.702100696892560938e-01 +2.674244609612708157e-01 +2.646480339173337692e-01 +2.618808981660304402e-01 +2.591231629491423383e-01 +2.563749371373338914e-01 +2.536363292258542179e-01 +2.509074473302546071e-01 +2.481883991821196012e-01 +2.454792921248143411e-01 +2.427802331092467902e-01 +2.400913286896452226e-01 +2.374126850193521987e-01 +2.347444078466329742e-01 +2.320866025105016717e-01 +2.294393739365621077e-01 +2.268028266328654674e-01 +2.241770646857849103e-01 +2.215621917559060239e-01 +2.189583110739347360e-01 +2.163655254366217418e-01 +2.137839372027045548e-01 +2.112136482888661848e-01 +2.086547601657119666e-01 +2.061073738537634592e-01 +2.035715899194703860e-01 +2.010475084712405880e-01 +1.985352291554876580e-01 +1.960348511526972815e-01 +1.935464731735118127e-01 +1.910701934548328373e-01 +1.886061097559437183e-01 +1.861543193546497665e-01 +1.837149190434377577e-01 +1.812880051256551828e-01 +1.788736734117077898e-01 +1.764720192152779144e-01 +1.740831373495606293e-01 +1.717071221235217382e-01 +1.693440673381740869e-01 +1.669940662828741373e-01 +1.646572117316399964e-01 +1.623335959394877348e-01 +1.600233106387904114e-01 +1.577264470356556925e-01 +1.554430958063257595e-01 +1.531733470935975339e-01 +1.509172905032637180e-01 +1.486750151005754306e-01 +1.464466094067262691e-01 +1.442321613953573278e-01 +1.420317584890844753e-01 +1.398454875560465327e-01 +1.376734349064766827e-01 +1.355156862892942238e-01 +1.333723268887200553e-01 +1.312434413209130624e-01 +1.291291136306304266e-01 +1.270294272879089748e-01 +1.249444651847701759e-01 +1.228743096319481060e-01 +1.208190423556390614e-01 +1.187787444942760284e-01 +1.167534965953250653e-01 +1.147433786121053456e-01 +1.127484699006330721e-01 +1.107688492164882882e-01 +1.088045947117059764e-01 +1.068557839316905400e-01 +1.049224938121548489e-01 +1.030048006760823920e-01 +1.011027802307144785e-01 +9.921650756456172615e-02 +9.734605714443907154e-02 +9.549150281252624661e-02 +9.365291778345302687e-02 +9.183037464140800243e-02 +9.002394533727385573e-02 +8.823370118578630072e-02 +8.645971286271911249e-02 +8.470205040209372038e-02 +8.296078319341440577e-02 +8.123597997892917366e-02 +7.952770885091546560e-02 +7.783603724899244847e-02 +7.616103195745842214e-02 +7.450275910265410917e-02 +7.286128415035245109e-02 +7.123667190317387043e-02 +6.962898649802817808e-02 +6.803829140358236272e-02 +6.646464941775495627e-02 +6.490812266523718344e-02 +6.336877259503992388e-02 +6.184665997806815252e-02 +6.034184490472188633e-02 +5.885438678252336020e-02 +5.738434433377237465e-02 +5.593177559322773384e-02 +5.449673790581609223e-02 +5.307928792436814036e-02 +5.167948160738213004e-02 +5.029737421681453047e-02 +4.893302031589857881e-02 +4.758647376699023934e-02 +4.625778772944157125e-02 +4.494701465750219893e-02 +4.365420629824860732e-02 +4.237941368954126209e-02 +4.112268715800941610e-02 +3.988407631706485101e-02 +3.866363006494261123e-02 +3.746139658277095053e-02 +3.627742333266931185e-02 +3.511175705587434026e-02 +3.396444377089455346e-02 +3.283552877169401696e-02 +3.172505662590377473e-02 +3.063307117306297844e-02 +2.955961552288728644e-02 +2.850473205356779394e-02 +2.746846241009757994e-02 +2.645084750262781392e-02 +2.545192750485272826e-02 +2.447174185242324829e-02 +2.351032924139059843e-02 +2.256772762667849652e-02 +2.164397422058469966e-02 +2.073910549131210979e-02 +1.985315716152846743e-02 +1.898616420695706242e-02 +1.813816085499513064e-02 +1.730918058336305965e-02 +1.649925611878252929e-02 +1.570841943568448973e-02 +1.493670175494711538e-02 +1.418413354266304105e-02 +1.345074450893671281e-02 +1.273656360671143739e-02 +1.204161903062633820e-02 +1.136593821590328734e-02 +1.070954783726395243e-02 +1.007247380787654190e-02 +9.454741278332942644e-03 +8.856374635655694938e-03 +8.277397502335151480e-03 +7.717832735397306410e-03 +7.177702425500975814e-03 +6.657027896065995098e-03 +6.155829702431114825e-03 +5.674127631042982789e-03 +5.211940698674547012e-03 +4.769287151674406200e-03 +4.346184465246691331e-03 +3.942649342761062048e-03 +3.558697715093164793e-03 +3.194344739995830240e-03 +2.849604801500524309e-03 +2.524491509349885421e-03 +2.219017698460029608e-03 +1.933195428413733707e-03 +1.667035982985051734e-03 +1.420549869693005229e-03 +1.193746819387400682e-03 +9.866357858642066381e-04 +7.992249455125027824e-04 +6.315216969912662570e-04 +4.835326609376605633e-04 +3.552636797053698725e-04 +2.467198171342277480e-04 +1.579053583500300562e-04 +8.882380959550351118e-05 +3.947789809194413024e-05 +9.869571931456211367e-06 +0.000000000000000000e+00 +9.869571931456211367e-06 +3.947789809194413024e-05 +8.882380959550351118e-05 +1.579053583500300562e-04 +2.467198171342277480e-04 +3.552636797053698725e-04 +4.835326609376605633e-04 +6.315216969912662570e-04 +7.992249455125027824e-04 +9.866357858642066381e-04 +1.193746819387400682e-03 +1.420549869693005229e-03 +1.667035982985051734e-03 +1.933195428413733707e-03 +2.219017698460029608e-03 +2.524491509349885421e-03 +2.849604801500524309e-03 +3.194344739995830240e-03 +3.558697715093164793e-03 +3.942649342761131437e-03 +4.346184465246691331e-03 +4.769287151674406200e-03 +5.211940698674547012e-03 +5.674127631043052178e-03 +6.155829702431184214e-03 +6.657027896065995098e-03 +7.177702425500975814e-03 +7.717832735397306410e-03 +8.277397502335220869e-03 +8.856374635655694938e-03 +9.454741278332942644e-03 +1.007247380787654190e-02 +1.070954783726395243e-02 +1.136593821590328734e-02 +1.204161903062626882e-02 +1.273656360671143739e-02 +1.345074450893671281e-02 +1.418413354266304105e-02 +1.493670175494704599e-02 +1.570841943568442034e-02 +1.649925611878245990e-02 +1.730918058336299026e-02 +1.813816085499506126e-02 +1.898616420695706242e-02 +1.985315716152846743e-02 +2.073910549131204040e-02 +2.164397422058469966e-02 +2.256772762667849652e-02 +2.351032924139059843e-02 +2.447174185242317890e-02 +2.545192750485265887e-02 +2.645084750262781392e-02 +2.746846241009751055e-02 +2.850473205356772455e-02 +2.955961552288728644e-02 +3.063307117306290905e-02 +3.172505662590377473e-02 +3.283552877169394757e-02 +3.396444377089455346e-02 +3.511175705587434026e-02 +3.627742333266931185e-02 +3.746139658277095053e-02 +3.866363006494254184e-02 +3.988407631706478162e-02 +4.112268715800934671e-02 +4.237941368954119270e-02 +4.365420629824853793e-02 +4.494701465750219893e-02 +4.625778772944157125e-02 +4.758647376699023934e-02 +4.893302031589864820e-02 +5.029737421681439169e-02 +5.167948160738199126e-02 +5.307928792436807097e-02 +5.449673790581602284e-02 +5.593177559322773384e-02 +5.738434433377237465e-02 +5.885438678252336020e-02 +6.034184490472188633e-02 +6.184665997806829130e-02 +6.336877259503999327e-02 +6.490812266523718344e-02 +6.646464941775495627e-02 +6.803829140358229333e-02 +6.962898649802817808e-02 +7.123667190317387043e-02 +7.286128415035245109e-02 +7.450275910265410917e-02 +7.616103195745842214e-02 +7.783603724899251786e-02 +7.952770885091539621e-02 +8.123597997892910427e-02 +8.296078319341440577e-02 +8.470205040209365099e-02 +8.645971286271911249e-02 +8.823370118578630072e-02 +9.002394533727385573e-02 +9.183037464140807182e-02 +9.365291778345316565e-02 +9.549150281252624661e-02 +9.734605714443900215e-02 +9.921650756456158737e-02 +1.011027802307144091e-01 +1.030048006760822532e-01 +1.049224938121547102e-01 +1.068557839316904706e-01 +1.088045947117059070e-01 +1.107688492164882882e-01 +1.127484699006330721e-01 +1.147433786121053456e-01 +1.167534965953250653e-01 +1.187787444942759590e-01 +1.208190423556389920e-01 +1.228743096319480366e-01 +1.249444651847701759e-01 +1.270294272879088915e-01 +1.291291136306304266e-01 +1.312434413209130624e-01 +1.333723268887200553e-01 +1.355156862892942793e-01 +1.376734349064765439e-01 +1.398454875560464772e-01 +1.420317584890843365e-01 +1.442321613953572446e-01 +1.464466094067261859e-01 +1.486750151005754306e-01 +1.509172905032637180e-01 +1.531733470935975339e-01 +1.554430958063258150e-01 +1.577264470356556092e-01 +1.600233106387903559e-01 +1.623335959394877348e-01 +1.646572117316399131e-01 +1.669940662828741373e-01 +1.693440673381740869e-01 +1.717071221235218215e-01 +1.740831373495606849e-01 +1.764720192152779144e-01 +1.788736734117077343e-01 +1.812880051256550995e-01 +1.837149190434377577e-01 +1.861543193546497110e-01 +1.886061097559437183e-01 +1.910701934548328373e-01 +1.935464731735118127e-01 +1.960348511526973647e-01 +1.985352291554877413e-01 +2.010475084712406435e-01 +2.035715899194703304e-01 +2.061073738537633759e-01 +2.086547601657119666e-01 +2.112136482888661848e-01 +2.137839372027046381e-01 +2.163655254366217973e-01 +2.189583110739347638e-01 +2.215621917559060794e-01 +2.241770646857850491e-01 +2.268028266328653841e-01 +2.294393739365620521e-01 +2.320866025105016717e-01 +2.347444078466329742e-01 +2.374126850193521987e-01 +2.400913286896453336e-01 +2.427802331092468457e-01 +2.454792921248144522e-01 +2.481883991821197399e-01 +2.509074473302545516e-01 +2.536363292258542179e-01 +2.563749371373336694e-01 +2.591231629491422273e-01 +2.618808981660303292e-01 +2.646480339173336027e-01 +2.674244609612707047e-01 +2.702100696892560383e-01 +2.730047501302265700e-01 +2.758083919549838559e-01 +2.786208844805492246e-01 +2.814421166745335601e-01 +2.842719771595203504e-01 +2.871103542174635592e-01 +2.899571357940967653e-01 +2.928122095033578454e-01 +2.956754626318254253e-01 +2.985467821431686541e-01 +3.014260546826096898e-01 +3.043131665813987863e-01 +3.072080038613017594e-01 +3.101104522390993323e-01 +3.130203971310996369e-01 +3.159377236576608738e-01 +3.188623166477270732e-01 +3.217940606433745687e-01 +3.247328399043704628e-01 +3.276785384127414713e-01 +3.306310398773543158e-01 +3.335902277385067727e-01 +3.365559851725286045e-01 +3.395281950963952022e-01 +3.425067401723475013e-01 +3.454915028125262189e-01 +3.484823651836130298e-01 +3.514792092114825128e-01 +3.544819165858640875e-01 +3.574903687650120010e-01 +3.605044469803854179e-01 +3.635240322413375025e-01 +3.665490053398121617e-01 +3.695792468550514465e-01 +3.726146371583088923e-01 +3.756550564175725748e-01 +3.787003846022963249e-01 +3.817505014881376613e-01 +3.848052866617047707e-01 +3.878646195253094842e-01 +3.909283793017288566e-01 +3.939964450389725759e-01 +3.970686956150593083e-01 +4.001450097427964869e-01 +4.032252659745698686e-01 +4.063093427071376995e-01 +4.093971181864314302e-01 +4.124884705123620376e-01 +4.155832776436331755e-01 +4.186814174025583202e-01 +4.217827674798844684e-01 +4.248872054396214404e-01 +4.279946087238739594e-01 +4.311048546576810025e-01 +4.342178204538588160e-01 +4.373333832178477598e-01 +4.404514199525650375e-01 +4.435718075632590351e-01 +4.466944228623699331e-01 +4.498191425743925387e-01 +4.529458433407427820e-01 +4.560744017246284865e-01 +4.592046942159210277e-01 +4.623365972360335419e-01 +4.654699871427969704e-01 +4.686047402353432645e-01 +4.717407327589876465e-01 +4.748778409101152009e-01 +4.780159408410675215e-01 +4.811549086650327434e-01 +4.842946204609359095e-01 +4.874349522783311128e-01 +4.905757801422958031e-01 +4.937169800583235957e-01 +4.968584280172204104e-01 +4.999999999999999445e-01 +5.031415719827794231e-01 +5.062830199416762378e-01 +5.094242198577040304e-01 +5.125650477216687761e-01 +5.157053795390640349e-01 +5.188450913349671456e-01 +5.219840591589323120e-01 +5.251221590898846880e-01 +5.282592672410122425e-01 +5.313952597646567355e-01 +5.345300128572029186e-01 +5.376634027639664026e-01 +5.407953057840788613e-01 +5.439255982753714580e-01 +5.470541566592570515e-01 +5.501808574256074058e-01 +5.533055771376299559e-01 +5.564281924367407983e-01 +5.595485800474349070e-01 +5.626666167821521292e-01 +5.657821795461412950e-01 +5.688951453423191085e-01 +5.720053912761261516e-01 +5.751127945603784486e-01 +5.782172325201153651e-01 +5.813185825974417353e-01 +5.844167223563669911e-01 +5.875115294876379624e-01 +5.906028818135686809e-01 +5.936906572928624115e-01 +5.967747340254302424e-01 +5.998549902572036796e-01 +6.029313043849405807e-01 +6.060035549610273131e-01 +6.090716206982712544e-01 +6.121353804746906269e-01 +6.151947133382953403e-01 +6.182494985118623942e-01 +6.212996153977038416e-01 +6.243449435824275362e-01 +6.273853628416912187e-01 +6.304207531449484980e-01 +6.334509946601877273e-01 +6.364759677586625530e-01 +6.394955530196146931e-01 +6.425096312349881655e-01 +6.455180834141360791e-01 +6.485207907885176537e-01 +6.515176348163871367e-01 +6.545084971874738367e-01 +6.574932598276524987e-01 +6.604718049036047978e-01 +6.634440148274712845e-01 +6.664097722614933383e-01 +6.693689601226456842e-01 +6.723214615872585842e-01 +6.752671600956295928e-01 +6.782059393566255423e-01 +6.811376833522730934e-01 +6.840622763423390706e-01 +6.869796028689002521e-01 +6.898895477609005011e-01 +6.927919961386982406e-01 +6.956868334186012692e-01 +6.985739453173903657e-01 +7.014532178568314569e-01 +7.043245373681746857e-01 +7.071877904966422657e-01 +7.100428642059033457e-01 +7.128896457825363298e-01 +7.157280228404795386e-01 +7.185578833254665510e-01 +7.213791155194507754e-01 +7.241916080450162552e-01 +7.269952498697735965e-01 +7.297899303107441282e-01 +7.325755390387289623e-01 +7.353519660826660642e-01 +7.381191018339694487e-01 +7.408768370508574952e-01 +7.436250628626661641e-01 +7.463636707741456711e-01 +7.490925526697452819e-01 +7.518116008178801213e-01 +7.545207078751854368e-01 +7.572197668907529877e-01 +7.599086713103545554e-01 +7.625873149806478013e-01 +7.652555921533669148e-01 +7.679133974894982728e-01 +7.705606260634378923e-01 +7.731971733671345604e-01 +7.758229353142149787e-01 +7.784378082440938096e-01 +7.810416889260651807e-01 +7.836344745633780917e-01 +7.862160627972953897e-01 +7.887863517111337597e-01 +7.913452398342879501e-01 +7.938926261462365686e-01 +7.964284100805296696e-01 +7.989524915287593565e-01 +8.014647708445121754e-01 +8.039651488473026353e-01 +8.064535268264880763e-01 +8.089298065451669961e-01 +8.113938902440561707e-01 +8.138456806453501224e-01 +8.162850809565621590e-01 +8.187119948743448727e-01 +8.211263265882923212e-01 +8.235279807847220024e-01 +8.259168626504392874e-01 +8.282928778764780953e-01 +8.306559326618259131e-01 +8.330059337171258349e-01 +8.353427882683600592e-01 +8.376664040605121819e-01 +8.399766893612095053e-01 +8.422735529643443630e-01 +8.445569041936741295e-01 +8.468266529064023551e-01 +8.490827094967362543e-01 +8.513249848994244307e-01 +8.535533905932737309e-01 +8.557678386046426722e-01 +8.579682415109154414e-01 +8.601545124439535783e-01 +8.623265650935232340e-01 +8.644843137107056652e-01 +8.666276731112798615e-01 +8.687565586790868544e-01 +8.708708863693694902e-01 +8.729705727120909975e-01 +8.750555348152296853e-01 +8.771256903680518802e-01 +8.791809576443607721e-01 +8.812212555057239438e-01 +8.832465034046749208e-01 +8.852566213878946266e-01 +8.872515300993668586e-01 +8.892311507835117812e-01 +8.911954052882939958e-01 +8.931442160683092935e-01 +8.950775061878452066e-01 +8.969951993239174692e-01 +8.988972197692854937e-01 +9.007834924354382045e-01 +9.026539428555609978e-01 +9.045084971874736146e-01 +9.063470822165471397e-01 +9.081696253585920253e-01 +9.099760546627261304e-01 +9.117662988142136715e-01 +9.135402871372807487e-01 +9.152979495979064462e-01 +9.170392168065855110e-01 +9.187640200210709374e-01 +9.204722911490844650e-01 +9.221639627510076487e-01 +9.238389680425416195e-01 +9.254972408973460851e-01 +9.271387158496476877e-01 +9.287633280968260463e-01 +9.303710135019718219e-01 +9.319617085964176928e-01 +9.335353505822452380e-01 +9.350918773347628443e-01 +9.366312274049601871e-01 +9.381533400219318475e-01 +9.396581550952782802e-01 +9.411456132174766953e-01 +9.426156556662276254e-01 +9.440682244067722939e-01 +9.455032620941838939e-01 +9.469207120756319984e-01 +9.483205183926179949e-01 +9.497026257831855389e-01 +9.510669796841014767e-01 +9.524135262330098994e-01 +9.537422122705585537e-01 +9.550529853424978288e-01 +9.563457937017514343e-01 +9.576205863104587657e-01 +9.588773128419906255e-01 +9.601159236829351906e-01 +9.613363699350575553e-01 +9.625386034172290772e-01 +9.637225766673307437e-01 +9.648882429441257846e-01 +9.660355562291054188e-01 +9.671644712283061773e-01 +9.682749433740961420e-01 +9.693669288269370909e-01 +9.704403844771127829e-01 +9.714952679464323726e-01 +9.725315375899025172e-01 +9.735491524973722832e-01 +9.745480724951474105e-01 +9.755282581475768211e-01 +9.764896707586095959e-01 +9.774322723733215312e-01 +9.783560257794152726e-01 +9.792608945086878069e-01 +9.801468428384715326e-01 +9.810138357930427988e-01 +9.818618391450048000e-01 +9.826908194166369404e-01 +9.835007438812174430e-01 +9.842915805643155380e-01 +9.850632982450530095e-01 +9.858158664573369867e-01 +9.865492554910632039e-01 +9.872634363932886181e-01 +9.879583809693737173e-01 +9.886340617840967404e-01 +9.892904521627360337e-01 +9.899275261921234303e-01 +9.905452587216669880e-01 +9.911436253643443051e-01 +9.917226024976647514e-01 +9.922821672646027213e-01 +9.928222975744990242e-01 +9.933429721039339633e-01 +9.938441702975688852e-01 +9.943258723689569756e-01 +9.947880593013255224e-01 +9.952307128483256493e-01 +9.956538155347532948e-01 +9.960573506572389935e-01 +9.964413022849069046e-01 +9.968056552600041975e-01 +9.971503951984994618e-01 +9.974755084906501423e-01 +9.977809823015399981e-01 +9.980668045715862524e-01 +9.983329640170148789e-01 +9.985794501303070225e-01 +9.988062531806126687e-01 +9.990133642141357795e-01 +9.992007750544875666e-01 +9.993684783030087893e-01 +9.995164673390624088e-01 +9.996447363202946024e-01 +9.997532801828658000e-01 +9.998420946416499699e-01 +9.999111761904044826e-01 +9.999605221019081114e-01 +9.999901304280686132e-01 +1.000000000000000000e+00 +9.999901304280686132e-01 +9.999605221019081114e-01 +9.999111761904044826e-01 +9.998420946416499699e-01 +9.997532801828658000e-01 +9.996447363202946024e-01 +9.995164673390624088e-01 +9.993684783030087893e-01 +9.992007750544875666e-01 +9.990133642141357795e-01 +9.988062531806126687e-01 +9.985794501303070225e-01 +9.983329640170148789e-01 +9.980668045715862524e-01 +9.977809823015399981e-01 +9.974755084906501423e-01 +9.971503951984994618e-01 +9.968056552600041975e-01 +9.964413022849069046e-01 +9.960573506572389935e-01 +9.956538155347532948e-01 +9.952307128483256493e-01 +9.947880593013255224e-01 +9.943258723689569756e-01 +9.938441702975688852e-01 +9.933429721039340743e-01 +9.928222975744990242e-01 +9.922821672646027213e-01 +9.917226024976649734e-01 +9.911436253643443051e-01 +9.905452587216669880e-01 +9.899275261921234303e-01 +9.892904521627360337e-01 +9.886340617840967404e-01 +9.879583809693737173e-01 +9.872634363932886181e-01 +9.865492554910632039e-01 +9.858158664573369867e-01 +9.850632982450530095e-01 +9.842915805643155380e-01 +9.835007438812176650e-01 +9.826908194166369404e-01 +9.818618391450048000e-01 +9.810138357930429098e-01 +9.801468428384715326e-01 +9.792608945086879180e-01 +9.783560257794151616e-01 +9.774322723733215312e-01 +9.764896707586093738e-01 +9.755282581475768211e-01 +9.745480724951472995e-01 +9.735491524973721722e-01 +9.725315375899024062e-01 +9.714952679464322616e-01 +9.704403844771126719e-01 +9.693669288269370909e-01 +9.682749433740962530e-01 +9.671644712283059553e-01 +9.660355562291056408e-01 +9.648882429441255626e-01 +9.637225766673307437e-01 +9.625386034172289662e-01 +9.613363699350574443e-01 +9.601159236829350796e-01 +9.588773128419905145e-01 +9.576205863104588767e-01 +9.563457937017513233e-01 +9.550529853424979398e-01 +9.537422122705583316e-01 +9.524135262330097884e-01 +9.510669796841012547e-01 +9.497026257831855389e-01 +9.483205183926177728e-01 +9.469207120756318874e-01 +9.455032620941840049e-01 +9.440682244067721829e-01 +9.426156556662276254e-01 +9.411456132174764733e-01 +9.396581550952781692e-01 +9.381533400219317365e-01 +9.366312274049600761e-01 +9.350918773347627333e-01 +9.335353505822452380e-01 +9.319617085964176928e-01 +9.303710135019719329e-01 +9.287633280968261573e-01 +9.271387158496476877e-01 +9.254972408973461961e-01 +9.238389680425418415e-01 +9.221639627510077597e-01 +9.204722911490845760e-01 +9.187640200210711594e-01 +9.170392168065856220e-01 +9.152979495979064462e-01 +9.135402871372808598e-01 +9.117662988142138936e-01 +9.099760546627261304e-01 +9.081696253585921363e-01 +9.063470822165472507e-01 +9.045084971874737256e-01 +9.026539428555611089e-01 +9.007834924354383155e-01 +8.988972197692857158e-01 +8.969951993239175803e-01 +8.950775061878453176e-01 +8.931442160683095155e-01 +8.911954052882942179e-01 +8.892311507835118922e-01 +8.872515300993669696e-01 +8.852566213878948487e-01 +8.832465034046749208e-01 +8.812212555057241659e-01 +8.791809576443609942e-01 +8.771256903680521022e-01 +8.750555348152296853e-01 +8.729705727120912195e-01 +8.708708863693698232e-01 +8.687565586790870764e-01 +8.666276731112800835e-01 +8.644843137107057762e-01 +8.623265650935235671e-01 +8.601545124439533563e-01 +8.579682415109157745e-01 +8.557678386046426722e-01 +8.535533905932737309e-01 +8.513249848994247637e-01 +8.490827094967363653e-01 +8.468266529064027992e-01 +8.445569041936742405e-01 +8.422735529643444741e-01 +8.399766893612095053e-01 +8.376664040605122930e-01 +8.353427882683600592e-01 +8.330059337171258349e-01 +8.306559326618262462e-01 +8.282928778764783173e-01 +8.259168626504395094e-01 +8.235279807847221134e-01 +8.211263265882923212e-01 +8.187119948743448727e-01 +8.162850809565622701e-01 +8.138456806453500114e-01 +8.113938902440562817e-01 +8.089298065451674402e-01 +8.064535268264882983e-01 +8.039651488473028573e-01 +8.014647708445123975e-01 +7.989524915287595785e-01 +7.964284100805296696e-01 +7.938926261462366796e-01 +7.913452398342879501e-01 +7.887863517111338707e-01 +7.862160627972956117e-01 +7.836344745633783138e-01 +7.810416889260654028e-01 +7.784378082440940316e-01 +7.758229353142152007e-01 +7.731971733671344493e-01 +7.705606260634380034e-01 +7.679133974894981618e-01 +7.652555921533671368e-01 +7.625873149806478013e-01 +7.599086713103547774e-01 +7.572197668907534318e-01 +7.545207078751855478e-01 +7.518116008178805654e-01 +7.490925526697452819e-01 +7.463636707741457821e-01 +7.436250628626659420e-01 +7.408768370508576062e-01 +7.381191018339694487e-01 +7.353519660826662863e-01 +7.325755390387292953e-01 +7.297899303107437952e-01 +7.269952498697734855e-01 +7.241916080450159221e-01 +7.213791155194507754e-01 +7.185578833254663289e-01 +7.157280228404795386e-01 +7.128896457825362187e-01 +7.100428642059031237e-01 +7.071877904966422657e-01 +7.043245373681744637e-01 +7.014532178568313459e-01 +6.985739453173901437e-01 +6.956868334186012692e-01 +6.927919961386981296e-01 +6.898895477609005011e-01 +6.869796028688999190e-01 +6.840622763423389596e-01 +6.811376833522728713e-01 +6.782059393566253203e-01 +6.752671600956295928e-01 +6.723214615872583622e-01 +6.693689601226456842e-01 +6.664097722614931163e-01 +6.634440148274711735e-01 +6.604718049036045757e-01 +6.574932598276523876e-01 +6.545084971874738367e-01 +6.515176348163868036e-01 +6.485207907885174317e-01 +6.455180834141357460e-01 +6.425096312349881655e-01 +6.394955530196144711e-01 +6.364759677586625530e-01 +6.334509946601875052e-01 +6.304207531449484980e-01 +6.273853628416911077e-01 +6.243449435824276472e-01 +6.212996153977037306e-01 +6.182494985118626163e-01 +6.151947133382956734e-01 +6.121353804746907379e-01 +6.090716206982716985e-01 +6.060035549610274241e-01 +6.029313043849410247e-01 +5.998549902572035686e-01 +5.967747340254303534e-01 +5.936906572928624115e-01 +5.906028818135689029e-01 +5.875115294876379624e-01 +5.844167223563671021e-01 +5.813185825974421794e-01 +5.782172325201154761e-01 +5.751127945603787817e-01 +5.720053912761261516e-01 +5.688951453423193305e-01 +5.657821795461412950e-01 +5.626666167821523512e-01 +5.595485800474347959e-01 +5.564281924367410204e-01 +5.533055771376302889e-01 +5.501808574256075168e-01 +5.470541566592574956e-01 +5.439255982753715690e-01 +5.407953057840789723e-01 +5.376634027639662916e-01 +5.345300128572030296e-01 +5.313952597646566245e-01 +5.282592672410124646e-01 +5.251221590898850211e-01 +5.219840591589325340e-01 +5.188450913349675897e-01 +5.157053795390641460e-01 +5.125650477216689982e-01 +5.094242198577040304e-01 +5.062830199416764598e-01 +5.031415719827794231e-01 diff --git a/examples/icub_vor_examples/spinn_gym_examples/normalised_head_velocities_1000.csv b/examples/icub_vor_examples/spinn_gym_examples/normalised_head_velocities_1000.csv new file mode 100644 index 00000000..f215b6ad --- /dev/null +++ b/examples/icub_vor_examples/spinn_gym_examples/normalised_head_velocities_1000.csv @@ -0,0 +1,1000 @@ +0.000000000000000000e+00 +9.869571931439562087e-06 +3.947789809190699632e-05 +8.882380959548627237e-05 +1.579053583499612364e-04 +2.467198171342090997e-04 +3.552636797053673788e-04 +4.835326609376300430e-04 +6.315216969912583423e-04 +7.992249455125140581e-04 +9.866357858641615353e-04 +1.193746819387333461e-03 +1.420549869692992653e-03 +1.667035982985024412e-03 +1.933195428413718962e-03 +2.219017698460000985e-03 +2.524491509349872410e-03 +2.849604801500486579e-03 +3.194344739995816362e-03 +3.558697715093159155e-03 +3.942649342761002200e-03 +4.346184465246665310e-03 +4.769287151674420945e-03 +5.211940698674534002e-03 +5.674127631042969779e-03 +6.155829702431123499e-03 +6.657027896065956935e-03 +7.177702425500961068e-03 +7.717832735397246562e-03 +8.277397502335116786e-03 +8.856374635655587385e-03 +9.454741278332920093e-03 +1.007247380787648638e-02 +1.070954783726390906e-02 +1.136593821590326132e-02 +1.204161903062620463e-02 +1.273656360671141137e-02 +1.345074450893671801e-02 +1.418413354266298380e-02 +1.493670175494710324e-02 +1.570841943568445503e-02 +1.649925611878251541e-02 +1.730918058336302495e-02 +1.813816085499507860e-02 +1.898616420695698956e-02 +1.985315716152841886e-02 +2.073910549131204387e-02 +2.164397422058470313e-02 +2.256772762667843060e-02 +2.351032924139054292e-02 +2.447174185242324135e-02 +2.545192750485270050e-02 +2.645084750262781739e-02 +2.746846241009755912e-02 +2.850473205356769679e-02 +2.955961552288726563e-02 +3.063307117306297844e-02 +3.172505662590380943e-02 +3.283552877169400308e-02 +3.396444377089454653e-02 +3.511175705587420148e-02 +3.627742333266925634e-02 +3.746139658277095746e-02 +3.866363006494259735e-02 +3.988407631706478162e-02 +4.112268715800936753e-02 +4.237941368954127597e-02 +4.365420629824853793e-02 +4.494701465750217118e-02 +4.625778772944151573e-02 +4.758647376699020465e-02 +4.893302031589858575e-02 +5.029737421681453047e-02 +5.167948160738201208e-02 +5.307928792436815424e-02 +5.449673790581603672e-02 +5.593177559322771303e-02 +5.738434433377238159e-02 +5.885438678252330469e-02 +6.034184490472183082e-02 +6.184665997806816640e-02 +6.336877259503986837e-02 +6.490812266523718344e-02 +6.646464941775491464e-02 +6.803829140358234884e-02 +6.962898649802816420e-02 +7.123667190317387043e-02 +7.286128415035239558e-02 +7.450275910265402590e-02 +7.616103195745833887e-02 +7.783603724899246235e-02 +7.952770885091538233e-02 +8.123597997892911815e-02 +8.296078319341440577e-02 +8.470205040209359548e-02 +8.645971286271908474e-02 +8.823370118578624521e-02 +9.002394533727378634e-02 +9.183037464140793305e-02 +9.365291778345298523e-02 +9.549150281252624661e-02 +9.734605714443907154e-02 +9.921650756456158737e-02 +1.011027802307144785e-01 +1.030048006760823781e-01 +1.049224938121547657e-01 +1.068557839316905261e-01 +1.088045947117059348e-01 +1.107688492164882604e-01 +1.127484699006330582e-01 +1.147433786121053179e-01 +1.167534965953250237e-01 +1.187787444942760007e-01 +1.208190423556390197e-01 +1.228743096319480643e-01 +1.249444651847701482e-01 +1.270294272879089470e-01 +1.291291136306304266e-01 +1.312434413209131179e-01 +1.333723268887199720e-01 +1.355156862892941960e-01 +1.376734349064766549e-01 +1.398454875560465327e-01 +1.420317584890843643e-01 +1.442321613953572168e-01 +1.464466094067261859e-01 +1.486750151005754306e-01 +1.509172905032636069e-01 +1.531733470935975061e-01 +1.554430958063257318e-01 +1.577264470356556925e-01 +1.600233106387903836e-01 +1.623335959394877070e-01 +1.646572117316399408e-01 +1.669940662828741373e-01 +1.693440673381740591e-01 +1.717071221235217937e-01 +1.740831373495606849e-01 +1.764720192152778033e-01 +1.788736734117078453e-01 +1.812880051256551550e-01 +1.837149190434377577e-01 +1.861543193546498220e-01 +1.886061097559437738e-01 +1.910701934548328096e-01 +1.935464731735117017e-01 +1.960348511526972537e-01 +1.985352291554875470e-01 +2.010475084712405602e-01 +2.035715899194703027e-01 +2.061073738537634592e-01 +2.086547601657119388e-01 +2.112136482888661571e-01 +2.137839372027044993e-01 +2.163655254366217140e-01 +2.189583110739346805e-01 +2.215621917559059684e-01 +2.241770646857848825e-01 +2.268028266328654674e-01 +2.294393739365620244e-01 +2.320866025105016994e-01 +2.347444078466328909e-01 +2.374126850193520877e-01 +2.400913286896452226e-01 +2.427802331092467902e-01 +2.454792921248143966e-01 +2.481883991821195179e-01 +2.509074473302545516e-01 +2.536363292258542179e-01 +2.563749371373338359e-01 +2.591231629491423938e-01 +2.618808981660304402e-01 +2.646480339173337137e-01 +2.674244609612708712e-01 +2.702100696892560938e-01 +2.730047501302265700e-01 +2.758083919549837448e-01 +2.786208844805491691e-01 +2.814421166745335046e-01 +2.842719771595204614e-01 +2.871103542174636702e-01 +2.899571357940967653e-01 +2.928122095033578454e-01 +2.956754626318254253e-01 +2.985467821431686541e-01 +3.014260546826096898e-01 +3.043131665813987308e-01 +3.072080038613017039e-01 +3.101104522390994434e-01 +3.130203971310998035e-01 +3.159377236576609294e-01 +3.188623166477270732e-01 +3.217940606433746242e-01 +3.247328399043705183e-01 +3.276785384127414713e-01 +3.306310398773542603e-01 +3.335902277385066617e-01 +3.365559851725287710e-01 +3.395281950963952577e-01 +3.425067401723476124e-01 +3.454915028125262189e-01 +3.484823651836129743e-01 +3.514792092114825683e-01 +3.544819165858641430e-01 +3.574903687650118900e-01 +3.605044469803853624e-01 +3.635240322413374470e-01 +3.665490053398122727e-01 +3.695792468550516130e-01 +3.726146371583089478e-01 +3.756550564175725193e-01 +3.787003846022962139e-01 +3.817505014881376058e-01 +3.848052866617046597e-01 +3.878646195253094286e-01 +3.909283793017286346e-01 +3.939964450389726314e-01 +3.970686956150593083e-01 +4.001450097427964869e-01 +4.032252659745698131e-01 +4.063093427071376440e-01 +4.093971181864312636e-01 +4.124884705123619821e-01 +4.155832776436331200e-01 +4.186814174025580981e-01 +4.217827674798845239e-01 +4.248872054396214959e-01 +4.279946087238739594e-01 +4.311048546576810025e-01 +4.342178204538587050e-01 +4.373333832178479263e-01 +4.404514199525651486e-01 +4.435718075632592017e-01 +4.466944228623699886e-01 +4.498191425743925942e-01 +4.529458433407428375e-01 +4.560744017246284310e-01 +4.592046942159213052e-01 +4.623365972360336529e-01 +4.654699871427971369e-01 +4.686047402353432645e-01 +4.717407327589876465e-01 +4.748778409101152009e-01 +4.780159408410675770e-01 +4.811549086650326323e-01 +4.842946204609357985e-01 +4.874349522783312239e-01 +4.905757801422959141e-01 +4.937169800583236512e-01 +4.968584280172204659e-01 +5.000000000000000000e-01 +5.031415719827794231e-01 +5.062830199416763488e-01 +5.094242198577040304e-01 +5.125650477216686651e-01 +5.157053795390641460e-01 +5.188450913349672566e-01 +5.219840591589324230e-01 +5.251221590898846880e-01 +5.282592672410122425e-01 +5.313952597646566245e-01 +5.345300128572029186e-01 +5.376634027639662916e-01 +5.407953057840787503e-01 +5.439255982753716800e-01 +5.470541566592571625e-01 +5.501808574256075168e-01 +5.533055771376299559e-01 +5.564281924367407983e-01 +5.595485800474349070e-01 +5.626666167821522402e-01 +5.657821795461412950e-01 +5.688951453423189975e-01 +5.720053912761261516e-01 +5.751127945603785596e-01 +5.782172325201154761e-01 +5.813185825974417353e-01 +5.844167223563669911e-01 +5.875115294876380734e-01 +5.906028818135686809e-01 +5.936906572928624115e-01 +5.967747340254301314e-01 +5.998549902572035686e-01 +6.029313043849406917e-01 +6.060035549610274241e-01 +6.090716206982713654e-01 +6.121353804746906269e-01 +6.151947133382953403e-01 +6.182494985118623942e-01 +6.212996153977036196e-01 +6.243449435824273142e-01 +6.273853628416909967e-01 +6.304207531449482760e-01 +6.334509946601877273e-01 +6.364759677586625530e-01 +6.394955530196145821e-01 +6.425096312349880545e-01 +6.455180834141358570e-01 +6.485207907885174317e-01 +6.515176348163869147e-01 +6.545084971874736146e-01 +6.574932598276522766e-01 +6.604718049036046867e-01 +6.634440148274711735e-01 +6.664097722614933383e-01 +6.693689601226456842e-01 +6.723214615872584732e-01 +6.752671600956294817e-01 +6.782059393566253203e-01 +6.811376833522728713e-01 +6.840622763423389596e-01 +6.869796028689001410e-01 +6.898895477609005011e-01 +6.927919961386982406e-01 +6.956868334186012692e-01 +6.985739453173902547e-01 +7.014532178568313459e-01 +7.043245373681745747e-01 +7.071877904966421546e-01 +7.100428642059032347e-01 +7.128896457825364408e-01 +7.157280228404795386e-01 +7.185578833254663289e-01 +7.213791155194506644e-01 +7.241916080450160331e-01 +7.269952498697733745e-01 +7.297899303107439062e-01 +7.325755390387291843e-01 +7.353519660826662863e-01 +7.381191018339696708e-01 +7.408768370508577172e-01 +7.436250628626662751e-01 +7.463636707741457821e-01 +7.490925526697452819e-01 +7.518116008178803433e-01 +7.545207078751857699e-01 +7.572197668907533208e-01 +7.599086713103547774e-01 +7.625873149806479123e-01 +7.652555921533671368e-01 +7.679133974894983838e-01 +7.705606260634378923e-01 +7.731971733671345604e-01 +7.758229353142150897e-01 +7.784378082440940316e-01 +7.810416889260654028e-01 +7.836344745633783138e-01 +7.862160627972955007e-01 +7.887863517111338707e-01 +7.913452398342881722e-01 +7.938926261462365686e-01 +7.964284100805295585e-01 +7.989524915287592455e-01 +8.014647708445122865e-01 +8.039651488473026353e-01 +8.064535268264880763e-01 +8.089298065451671071e-01 +8.113938902440561707e-01 +8.138456806453501224e-01 +8.162850809565621590e-01 +8.187119948743448727e-01 +8.211263265882922102e-01 +8.235279807847220024e-01 +8.259168626504391764e-01 +8.282928778764780953e-01 +8.306559326618259131e-01 +8.330059337171259459e-01 +8.353427882683600592e-01 +8.376664040605122930e-01 +8.399766893612096164e-01 +8.422735529643444741e-01 +8.445569041936742405e-01 +8.468266529064024661e-01 +8.490827094967362543e-01 +8.513249848994244307e-01 +8.535533905932737309e-01 +8.557678386046427832e-01 +8.579682415109156635e-01 +8.601545124439534673e-01 +8.623265650935233451e-01 +8.644843137107056652e-01 +8.666276731112799725e-01 +8.687565586790869654e-01 +8.708708863693694902e-01 +8.729705727120909975e-01 +8.750555348152299073e-01 +8.771256903680519912e-01 +8.791809576443608831e-01 +8.812212555057239438e-01 +8.832465034046749208e-01 +8.852566213878946266e-01 +8.872515300993668586e-01 +8.892311507835116702e-01 +8.911954052882941069e-01 +8.931442160683095155e-01 +8.950775061878453176e-01 +8.969951993239176913e-01 +8.988972197692854937e-01 +9.007834924354383155e-01 +9.026539428555608868e-01 +9.045084971874738367e-01 +9.063470822165470286e-01 +9.081696253585921363e-01 +9.099760546627261304e-01 +9.117662988142137825e-01 +9.135402871372810818e-01 +9.152979495979065572e-01 +9.170392168065857330e-01 +9.187640200210708263e-01 +9.204722911490845760e-01 +9.221639627510074266e-01 +9.238389680425416195e-01 +9.254972408973460851e-01 +9.271387158496476877e-01 +9.287633280968261573e-01 +9.303710135019719329e-01 +9.319617085964179148e-01 +9.335353505822450160e-01 +9.350918773347628443e-01 +9.366312274049599651e-01 +9.381533400219316254e-01 +9.396581550952780582e-01 +9.411456132174766953e-01 +9.426156556662275143e-01 +9.440682244067721829e-01 +9.455032620941840049e-01 +9.469207120756318874e-01 +9.483205183926179949e-01 +9.497026257831856499e-01 +9.510669796841013657e-01 +9.524135262330096774e-01 +9.537422122705585537e-01 +9.550529853424978288e-01 +9.563457937017514343e-01 +9.576205863104587657e-01 +9.588773128419906255e-01 +9.601159236829353016e-01 +9.613363699350575553e-01 +9.625386034172290772e-01 +9.637225766673305216e-01 +9.648882429441256736e-01 +9.660355562291054188e-01 +9.671644712283059553e-01 +9.682749433740961420e-01 +9.693669288269369799e-01 +9.704403844771127829e-01 +9.714952679464322616e-01 +9.725315375899022952e-01 +9.735491524973720612e-01 +9.745480724951472995e-01 +9.755282581475767101e-01 +9.764896707586095959e-01 +9.774322723733215312e-01 +9.783560257794153836e-01 +9.792608945086879180e-01 +9.801468428384716436e-01 +9.810138357930430208e-01 +9.818618391450050220e-01 +9.826908194166369404e-01 +9.835007438812174430e-01 +9.842915805643155380e-01 +9.850632982450528985e-01 +9.858158664573368757e-01 +9.865492554910632039e-01 +9.872634363932887291e-01 +9.879583809693738283e-01 +9.886340617840968514e-01 +9.892904521627360337e-01 +9.899275261921235414e-01 +9.905452587216669880e-01 +9.911436253643443051e-01 +9.917226024976648624e-01 +9.922821672646028324e-01 +9.928222975744990242e-01 +9.933429721039341853e-01 +9.938441702975688852e-01 +9.943258723689569756e-01 +9.947880593013254114e-01 +9.952307128483255383e-01 +9.956538155347532948e-01 +9.960573506572389935e-01 +9.964413022849067936e-01 +9.968056552600040865e-01 +9.971503951984994618e-01 +9.974755084906502534e-01 +9.977809823015399981e-01 +9.980668045715863634e-01 +9.983329640170149899e-01 +9.985794501303070225e-01 +9.988062531806126687e-01 +9.990133642141358905e-01 +9.992007750544874556e-01 +9.993684783030087893e-01 +9.995164673390624088e-01 +9.996447363202946024e-01 +9.997532801828656890e-01 +9.998420946416499699e-01 +9.999111761904043716e-01 +9.999605221019081114e-01 +9.999901304280686132e-01 +1.000000000000000000e+00 +9.999901304280686132e-01 +9.999605221019081114e-01 +9.999111761904043716e-01 +9.998420946416499699e-01 +9.997532801828656890e-01 +9.996447363202946024e-01 +9.995164673390624088e-01 +9.993684783030087893e-01 +9.992007750544874556e-01 +9.990133642141358905e-01 +9.988062531806126687e-01 +9.985794501303070225e-01 +9.983329640170149899e-01 +9.980668045715863634e-01 +9.977809823015399981e-01 +9.974755084906502534e-01 +9.971503951984994618e-01 +9.968056552600040865e-01 +9.964413022849067936e-01 +9.960573506572389935e-01 +9.956538155347532948e-01 +9.952307128483255383e-01 +9.947880593013254114e-01 +9.943258723689569756e-01 +9.938441702975688852e-01 +9.933429721039340743e-01 +9.928222975744990242e-01 +9.922821672646028324e-01 +9.917226024976648624e-01 +9.911436253643443051e-01 +9.905452587216669880e-01 +9.899275261921235414e-01 +9.892904521627361447e-01 +9.886340617840968514e-01 +9.879583809693738283e-01 +9.872634363932885071e-01 +9.865492554910632039e-01 +9.858158664573368757e-01 +9.850632982450528985e-01 +9.842915805643155380e-01 +9.835007438812174430e-01 +9.826908194166369404e-01 +9.818618391450050220e-01 +9.810138357930430208e-01 +9.801468428384716436e-01 +9.792608945086879180e-01 +9.783560257794153836e-01 +9.774322723733215312e-01 +9.764896707586095959e-01 +9.755282581475767101e-01 +9.745480724951472995e-01 +9.735491524973720612e-01 +9.725315375899024062e-01 +9.714952679464321506e-01 +9.704403844771127829e-01 +9.693669288269369799e-01 +9.682749433740961420e-01 +9.671644712283059553e-01 +9.660355562291054188e-01 +9.648882429441256736e-01 +9.637225766673305216e-01 +9.625386034172290772e-01 +9.613363699350574443e-01 +9.601159236829353016e-01 +9.588773128419906255e-01 +9.576205863104587657e-01 +9.563457937017514343e-01 +9.550529853424978288e-01 +9.537422122705584426e-01 +9.524135262330098994e-01 +9.510669796841013657e-01 +9.497026257831854279e-01 +9.483205183926177728e-01 +9.469207120756318874e-01 +9.455032620941838939e-01 +9.440682244067721829e-01 +9.426156556662278474e-01 +9.411456132174766953e-01 +9.396581550952782802e-01 +9.381533400219318475e-01 +9.366312274049601871e-01 +9.350918773347629553e-01 +9.335353505822450160e-01 +9.319617085964179148e-01 +9.303710135019720440e-01 +9.287633280968262683e-01 +9.271387158496476877e-01 +9.254972408973460851e-01 +9.238389680425416195e-01 +9.221639627510076487e-01 +9.204722911490845760e-01 +9.187640200210708263e-01 +9.170392168065857330e-01 +9.152979495979065572e-01 +9.135402871372810818e-01 +9.117662988142137825e-01 +9.099760546627261304e-01 +9.081696253585921363e-01 +9.063470822165471397e-01 +9.045084971874738367e-01 +9.026539428555611089e-01 +9.007834924354383155e-01 +8.988972197692854937e-01 +8.969951993239178023e-01 +8.950775061878453176e-01 +8.931442160683095155e-01 +8.911954052882941069e-01 +8.892311507835118922e-01 +8.872515300993670806e-01 +8.852566213878947377e-01 +8.832465034046749208e-01 +8.812212555057239438e-01 +8.791809576443611052e-01 +8.771256903680519912e-01 +8.750555348152299073e-01 +8.729705727120912195e-01 +8.708708863693697122e-01 +8.687565586790869654e-01 +8.666276731112800835e-01 +8.644843137107058872e-01 +8.623265650935234561e-01 +8.601545124439534673e-01 +8.579682415109156635e-01 +8.557678386046427832e-01 +8.535533905932739529e-01 +8.513249848994246527e-01 +8.490827094967364763e-01 +8.468266529064025772e-01 +8.445569041936743515e-01 +8.422735529643444741e-01 +8.399766893612096164e-01 +8.376664040605122930e-01 +8.353427882683600592e-01 +8.330059337171259459e-01 +8.306559326618259131e-01 +8.282928778764783173e-01 +8.259168626504396205e-01 +8.235279807847220024e-01 +8.211263265882924323e-01 +8.187119948743448727e-01 +8.162850809565623811e-01 +8.138456806453501224e-01 +8.113938902440562817e-01 +8.089298065451674402e-01 +8.064535268264882983e-01 +8.039651488473028573e-01 +8.014647708445122865e-01 +7.989524915287594675e-01 +7.964284100805295585e-01 +7.938926261462365686e-01 +7.913452398342879501e-01 +7.887863517111338707e-01 +7.862160627972956117e-01 +7.836344745633782027e-01 +7.810416889260655138e-01 +7.784378082440939206e-01 +7.758229353142153117e-01 +7.731971733671344493e-01 +7.705606260634378923e-01 +7.679133974894981618e-01 +7.652555921533670258e-01 +7.625873149806475793e-01 +7.599086713103547774e-01 +7.572197668907533208e-01 +7.545207078751855478e-01 +7.518116008178805654e-01 +7.490925526697452819e-01 +7.463636707741457821e-01 +7.436250628626660530e-01 +7.408768370508576062e-01 +7.381191018339693377e-01 +7.353519660826662863e-01 +7.325755390387292953e-01 +7.297899303107437952e-01 +7.269952498697733745e-01 +7.241916080450160331e-01 +7.213791155194507754e-01 +7.185578833254663289e-01 +7.157280228404795386e-01 +7.128896457825361077e-01 +7.100428642059030127e-01 +7.071877904966422657e-01 +7.043245373681743526e-01 +7.014532178568313459e-01 +6.985739453173901437e-01 +6.956868334186012692e-01 +6.927919961386980185e-01 +6.898895477609005011e-01 +6.869796028689000300e-01 +6.840622763423388486e-01 +6.811376833522728713e-01 +6.782059393566252092e-01 +6.752671600956294817e-01 +6.723214615872583622e-01 +6.693689601226456842e-01 +6.664097722614931163e-01 +6.634440148274711735e-01 +6.604718049036044647e-01 +6.574932598276523876e-01 +6.545084971874737256e-01 +6.515176348163868036e-01 +6.485207907885174317e-01 +6.455180834141357460e-01 +6.425096312349884986e-01 +6.394955530196148041e-01 +6.364759677586629971e-01 +6.334509946601878383e-01 +6.304207531449488311e-01 +6.273853628416912187e-01 +6.243449435824276472e-01 +6.212996153977037306e-01 +6.182494985118625053e-01 +6.151947133382956734e-01 +6.121353804746907379e-01 +6.090716206982716985e-01 +6.060035549610274241e-01 +6.029313043849410247e-01 +5.998549902572035686e-01 +5.967747340254304644e-01 +5.936906572928623005e-01 +5.906028818135689029e-01 +5.875115294876379624e-01 +5.844167223563671021e-01 +5.813185825974421794e-01 +5.782172325201154761e-01 +5.751127945603787817e-01 +5.720053912761261516e-01 +5.688951453423192195e-01 +5.657821795461412950e-01 +5.626666167821522402e-01 +5.595485800474347959e-01 +5.564281924367410204e-01 +5.533055771376302889e-01 +5.501808574256075168e-01 +5.470541566592573846e-01 +5.439255982753716800e-01 +5.407953057840789723e-01 +5.376634027639664026e-01 +5.345300128572030296e-01 +5.313952597646566245e-01 +5.282592672410123535e-01 +5.251221590898850211e-01 +5.219840591589325340e-01 +5.188450913349674787e-01 +5.157053795390641460e-01 +5.125650477216689982e-01 +5.094242198577040304e-01 +5.062830199416764598e-01 +5.031415719827793120e-01 +5.000000000000001110e-01 +4.968584280172208545e-01 +4.937169800583237622e-01 +4.905757801422960807e-01 +4.874349522783312239e-01 +4.842946204609360206e-01 +4.811549086650326323e-01 +4.780159408410676880e-01 +4.748778409101150899e-01 +4.717407327589878685e-01 +4.686047402353435976e-01 +4.654699871427971369e-01 +4.623365972360338194e-01 +4.592046942159211942e-01 +4.560744017246285420e-01 +4.529458433407427265e-01 +4.498191425743926497e-01 +4.466944228623699331e-01 +4.435718075632592017e-01 +4.404514199525653706e-01 +4.373333832178479263e-01 +4.342178204538589270e-01 +4.311048546576808915e-01 +4.279946087238740704e-01 +4.248872054396213849e-01 +4.217827674798846904e-01 +4.186814174025580426e-01 +4.155832776436331200e-01 +4.124884705123622042e-01 +4.093971181864312636e-01 +4.063093427071379216e-01 +4.032252659745698131e-01 +4.001450097427966535e-01 +3.970686956150591973e-01 +3.939964450389727424e-01 +3.909283793017285236e-01 +3.878646195253094286e-01 +3.848052866617044376e-01 +3.817505014881376613e-01 +3.787003846022964360e-01 +3.756550564175725193e-01 +3.726146371583090033e-01 +3.695792468550513910e-01 +3.665490053398122727e-01 +3.635240322413371694e-01 +3.605044469803854179e-01 +3.574903687650116679e-01 +3.544819165858640320e-01 +3.514792092114826794e-01 +3.484823651836129188e-01 +3.454915028125263854e-01 +3.425067401723474458e-01 +3.395281950963952577e-01 +3.365559851725286045e-01 +3.335902277385066617e-01 +3.306310398773540937e-01 +3.276785384127414158e-01 +3.247328399043706293e-01 +3.217940606433745132e-01 +3.188623166477272397e-01 +3.159377236576608183e-01 +3.130203971310998035e-01 +3.101104522390992213e-01 +3.072080038613017039e-01 +3.043131665813985087e-01 +3.014260546826096343e-01 +2.985467821431687652e-01 +2.956754626318253698e-01 +2.928122095033579564e-01 +2.899571357940966543e-01 +2.871103542174636702e-01 +2.842719771595202394e-01 +2.814421166745335046e-01 +2.786208844805489471e-01 +2.758083919549838003e-01 +2.730047501302266810e-01 +2.702100696892559273e-01 +2.674244609612708712e-01 +2.646480339173335472e-01 +2.618808981660304402e-01 +2.591231629491421162e-01 +2.563749371373337804e-01 +2.536363292258538849e-01 +2.509074473302548292e-01 +2.481883991821196567e-01 +2.454792921248145632e-01 +2.427802331092467902e-01 +2.400913286896454168e-01 +2.374126850193525040e-01 +2.347444078466331130e-01 +2.320866025105019770e-01 +2.294393739365621077e-01 +2.268028266328657172e-01 +2.241770646857848825e-01 +2.215621917559061904e-01 +2.189583110739346805e-01 +2.163655254366218805e-01 +2.137839372027044993e-01 +2.112136482888663236e-01 +2.086547601657122442e-01 +2.061073738537635425e-01 +2.035715899194706080e-01 +2.010475084712405602e-01 +1.985352291554878246e-01 +1.960348511526973092e-01 +1.935464731735118959e-01 +1.910701934548327818e-01 +1.886061097559438571e-01 +1.861543193546500441e-01 +1.837149190434377855e-01 +1.812880051256553771e-01 +1.788736734117078453e-01 +1.764720192152779976e-01 +1.740831373495606016e-01 +1.717071221235218770e-01 +1.693440673381740036e-01 +1.669940662828742761e-01 +1.646572117316401629e-01 +1.623335959394878181e-01 +1.600233106387906057e-01 +1.577264470356556925e-01 +1.554430958063259538e-01 +1.531733470935974506e-01 +1.509172905032638012e-01 +1.486750151005753473e-01 +1.464466094067263247e-01 +1.442321613953575221e-01 +1.420317584890844753e-01 +1.398454875560466992e-01 +1.376734349064766549e-01 +1.355156862892944181e-01 +1.333723268887199720e-01 +1.312434413209131179e-01 +1.291291136306303433e-01 +1.270294272879090025e-01 +1.249444651847704119e-01 +1.228743096319480643e-01 +1.208190423556391585e-01 +1.187787444942760007e-01 +1.167534965953251902e-01 +1.147433786121053179e-01 +1.127484699006330998e-01 +1.107688492164881772e-01 +1.088045947117059348e-01 +1.068557839316906510e-01 +1.049224938121548073e-01 +1.030048006760824197e-01 +1.011027802307144785e-01 +9.921650756456176778e-02 +9.734605714443890501e-02 +9.549150281252624661e-02 +9.365291778345290197e-02 +9.183037464140793305e-02 +9.002394533727396675e-02 +8.823370118578624521e-02 +8.645971286271916800e-02 +8.470205040209359548e-02 +8.296078319341440577e-02 +8.123597997892903488e-02 +7.952770885091546560e-02 +7.783603724899237908e-02 +7.616103195745833887e-02 +7.450275910265394264e-02 +7.286128415035239558e-02 +7.123667190317387043e-02 +6.962898649802808093e-02 +6.803829140358244598e-02 +6.646464941775491464e-02 +6.490812266523718344e-02 +6.336877259503978510e-02 +6.184665997806816640e-02 +6.034184490472174062e-02 +5.885438678252330469e-02 +5.738434433377247179e-02 +5.593177559322771303e-02 +5.449673790581603672e-02 +5.307928792436806403e-02 +5.167948160738210228e-02 +5.029737421681435700e-02 +4.893302031589858575e-02 +4.758647376699011444e-02 +4.625778772944143247e-02 +4.494701465750217118e-02 +4.365420629824853793e-02 +4.237941368954127597e-02 +4.112268715800928426e-02 +3.988407631706478162e-02 +3.866363006494242388e-02 +3.746139658277095746e-02 +3.627742333266925634e-02 +3.511175705587420148e-02 +3.396444377089454653e-02 +3.283552877169391288e-02 +3.172505662590380943e-02 +3.063307117306288824e-02 +2.955961552288726563e-02 +2.850473205356760659e-02 +2.746846241009755912e-02 +2.645084750262772719e-02 +2.545192750485270050e-02 +2.447174185242324135e-02 +2.351032924139054292e-02 +2.256772762667843060e-02 +2.164397422058470313e-02 +2.073910549131204387e-02 +1.985315716152832866e-02 +1.898616420695698956e-02 +1.813816085499507860e-02 +1.730918058336302495e-02 +1.649925611878251541e-02 +1.570841943568445503e-02 +1.493670175494710324e-02 +1.418413354266298380e-02 +1.345074450893671801e-02 +1.273656360671149984e-02 +1.204161903062637984e-02 +1.136593821590326132e-02 +1.070954783726399753e-02 +1.007247380787648638e-02 +9.454741278333008564e-03 +8.856374635655587385e-03 +8.277397502335205257e-03 +7.717832735397246562e-03 +7.177702425501049539e-03 +6.657027896066045405e-03 +6.155829702431123499e-03 +5.674127631043058249e-03 +5.211940698674534002e-03 +4.769287151674420945e-03 +4.346184465246665310e-03 +3.942649342761090671e-03 +3.558697715093159155e-03 +3.194344739995816362e-03 +2.849604801500574616e-03 +2.524491509349872410e-03 +2.219017698460000985e-03 +1.933195428413718962e-03 +1.667035982985024412e-03 +1.420549869692992653e-03 +1.193746819387333461e-03 +9.866357858641615353e-04 +7.992249455125140581e-04 +6.315216969912583423e-04 +4.835326609376300430e-04 +3.552636797053673788e-04 +2.467198171342090997e-04 +1.579053583499612364e-04 +8.882380959548627237e-05 +3.947789809190699632e-05 +9.869571931439562087e-06 diff --git a/examples/icub_vor_examples/spinn_gym_examples/spynnaker.cfg b/examples/icub_vor_examples/spinn_gym_examples/spynnaker.cfg index 8bbf7d2f..ce534da0 100644 --- a/examples/icub_vor_examples/spinn_gym_examples/spynnaker.cfg +++ b/examples/icub_vor_examples/spinn_gym_examples/spynnaker.cfg @@ -1,4 +1,4 @@ [Mapping] -# Logic doesn't implement delay extensions, so avoid DelaySupportAdder +# ICubVor doesn't implement delay extensions, so avoid DelaySupportAdder delay_support_adder = None \ No newline at end of file From 460e69d51b6798b833657ff0cb651cc3fec302b0 Mon Sep 17 00:00:00 2001 From: Andrew Gait Date: Mon, 22 Nov 2021 09:34:00 +0000 Subject: [PATCH 07/28] And more tidying up --- examples/icub_vor_examples/cerebellum.py | 43 ++++++++++--------- examples/icub_vor_examples/cerebellum_tb.py | 31 ++++++------- .../icub_vor_examples/pb_cerebellum_tb.py | 4 +- .../receptive_fields_for_motion.py | 17 +++++--- 4 files changed, 48 insertions(+), 47 deletions(-) diff --git a/examples/icub_vor_examples/cerebellum.py b/examples/icub_vor_examples/cerebellum.py index 854f5dbb..f11091bc 100644 --- a/examples/icub_vor_examples/cerebellum.py +++ b/examples/icub_vor_examples/cerebellum.py @@ -266,10 +266,10 @@ def compute_D_error(kd, head_velocity, eye_velocity): IO_antagonist = np.zeros((100)) rate = [] - for i in range (100): - if(i < up_neuron_ID_threshold): + for i in range(100): + if (i < up_neuron_ID_threshold): rate.append(max_rate) - elif(i= 0.0: - IO_agonist[0:100]=min_rate - IO_antagonist=rate + IO_agonist[0:100] = min_rate + IO_antagonist = rate else: - IO_antagonist[0:100]=min_rate - IO_agonist=rate + IO_antagonist[0:100] = min_rate + IO_agonist = rate ea_rate = np.concatenate((IO_agonist, IO_antagonist)) # print(j) @@ -298,9 +298,9 @@ def compute_D_error(kd, head_velocity, eye_velocity): rate = [] for i in range(100): - if(i < up_neuron_ID_threshold): + if (i < up_neuron_ID_threshold): rate.append(max_rate) - elif(i=0.0: - IO_agonist[0:100]=min_rate - IO_antagonist=rate + if error >= 0.0: + IO_agonist[0:100] = min_rate + IO_antagonist = rate else: - IO_antagonist[0:100]=min_rate - IO_agonist=rate + IO_antagonist[0:100] = min_rate + IO_agonist = rate ea_rate = np.concatenate((IO_agonist, IO_antagonist)) @@ -322,6 +322,7 @@ def compute_D_error(kd, head_velocity, eye_velocity): return ea_rate + for j in range(200): x = error_activity(j) plt.plot(x) @@ -331,7 +332,7 @@ def compute_D_error(kd, head_velocity, eye_velocity): SA_population = sim.Population( num_MF_neurons, # number of sources sim.SpikeSourcePoisson, # source type - #{'rate': sa_mean_freq}, # source spike times + # {'rate': sa_mean_freq}, # source spike times {'rate': sensorial_activity(10)[0]}, # source spike times label="sa_population" # identifier ) @@ -351,7 +352,7 @@ def compute_D_error(kd, head_velocity, eye_velocity): sim.StaticSynapse(delay=1.0, weight=mf_go_weights)) # Create GrC population -GC_population = sim.Population(num_GC_neurons,sim.IF_curr_exp(), +GC_population = sim.Population(num_GC_neurons, sim.IF_curr_exp(), label='GCLayer') # create PC population @@ -382,9 +383,9 @@ def compute_D_error(kd, head_velocity, eye_velocity): list_GOC_GC_2 = [] # projections to subpopulations # https://github.com/SpiNNakerManchester/sPyNNaker8/issues/168) -for i in range (num_MF_neurons): +for i in range(num_MF_neurons): GC_medium_index = int( - round((i / float_num_MF_neurons ) * num_GC_neurons)) + round((i / float_num_MF_neurons) * num_GC_neurons)) GC_lower_index = GC_medium_index - 40 GC_upper_index = GC_medium_index + 60 @@ -394,7 +395,7 @@ def compute_D_error(kd, head_velocity, eye_velocity): elif(GC_upper_index > num_GC_neurons): GC_upper_index = num_GC_neurons - for j in range (GC_medium_index - GC_lower_index): + for j in range(GC_medium_index - GC_lower_index): list_GOC_GC.append((i, GC_lower_index + j)) for j in range(GC_medium_index + 20 - GC_medium_index): @@ -404,7 +405,7 @@ def compute_D_error(kd, head_velocity, eye_velocity): list_GOC_GC_2.append((i, GC_medium_index + 20 + j)) GO_GC_con1 = sim.Projection( - GOC_population,GC_population, + GOC_population, GC_population, sim.FromListConnector(list_GOC_GC, weight_distr_GO, delay_distr)) MF_GC_con2 = sim.Projection( @@ -418,7 +419,7 @@ def compute_D_error(kd, head_velocity, eye_velocity): # Create PC-VN connections pc_vn_connections = sim.Projection( PC_population, VN_population, sim.OneToOneConnector(), - #receptor_type='GABA', + # receptor_type='GABA', synapse_type=sim.StaticSynapse(delay=1.0, weight=pc_vn_weights)) # Create MF-VN learning rule - cos diff --git a/examples/icub_vor_examples/cerebellum_tb.py b/examples/icub_vor_examples/cerebellum_tb.py index 691b4c92..5699edb7 100644 --- a/examples/icub_vor_examples/cerebellum_tb.py +++ b/examples/icub_vor_examples/cerebellum_tb.py @@ -301,27 +301,24 @@ def process_VN_spiketrains(VN_spikes, t_start): elif(GC_upper_index > num_GC_neurons): GC_upper_index = num_GC_neurons - for j in range (GC_medium_index - GC_lower_index): + for j in range(GC_medium_index - GC_lower_index): list_GOC_GC.append( - (i, GC_lower_index + j, -# go_gc_weights, 1) - weight_distr_GO.next(), delay_distr.next())) + (i, GC_lower_index + j, # go_gc_weights, 1) + weight_distr_GO.next(), delay_distr.next())) for j in range(GC_medium_index + 20 - GC_medium_index): list_MF_GC.append( - (i, GC_medium_index + j, -# mf_gc_weights, 1) - weight_distr_MF.next(), delay_distr.next())) + (i, GC_medium_index + j, # mf_gc_weights, 1) + weight_distr_MF.next(), delay_distr.next())) for j in range(GC_upper_index - GC_medium_index - 20): list_GOC_GC_2.append( - (i, GC_medium_index + 20 + j, -# go_gc_weights, 1) - weight_distr_GO.next(), delay_distr.next())) + (i, GC_medium_index + 20 + j, # go_gc_weights, 1) + weight_distr_GO.next(), delay_distr.next())) GO_GC_con1 = sim.Projection( GOC_population, GC_population, sim.FromListConnector(list_GOC_GC), - receptor_type='inhibitory') # this should be inhibitory + receptor_type='inhibitory') # this should be inhibitory MF_GC_con2 = sim.Projection( MF_population, GC_population, sim.FromListConnector(list_MF_GC), @@ -396,25 +393,25 @@ def process_VN_spiketrains(VN_spikes, t_start): # sim.external_devices.activate_live_output_to(out_pop,retina_pop) # # -#recordings and simulations +# recordings and simulations # lif_pop.record(["spikes"]) # # out_pop.record(["spikes"]) # # # -#sim.run(10) +# sim.run(10) # -#sim.end() +# sim.end() MF_population.record(['spikes']) CF_population.record(['spikes']) GC_population.record('all') GOC_population.record(['spikes']) -VN_population.record('all') # VN_population.record(['spikes']) +VN_population.record('all') # VN_population.record(['spikes']) PC_population.record(['spikes']) -samples_in_repeat= 99 +samples_in_repeat = 99 sample_time = 10 repeats = 1 total_runtime = 0 @@ -493,7 +490,7 @@ def process_VN_spiketrains(VN_spikes, t_start): xlabel='VN_spikes'), Panel(VN_spikes.segments[0].filter(name='gsyn_inh')[0], ylabel="Membrane potential (mV)", yticks=True, - xlim=(0,total_runtime)) + xlim=(0, total_runtime)) ) plt.show(block=False) diff --git a/examples/icub_vor_examples/pb_cerebellum_tb.py b/examples/icub_vor_examples/pb_cerebellum_tb.py index 8845f4d8..ad42d8d9 100644 --- a/examples/icub_vor_examples/pb_cerebellum_tb.py +++ b/examples/icub_vor_examples/pb_cerebellum_tb.py @@ -729,7 +729,7 @@ def process_VN_spiketrains(VN_spikes, t_start): conn = np.array(conn.tolist()) final_connectivity[label] = conn -except Exception as e: +except Exception: # This simulator might not support the way this is done final_connectivity = [] traceback.print_exc() @@ -781,7 +781,7 @@ def process_VN_spiketrains(VN_spikes, t_start): try: x = np.concatenate(conn) conn = x - except Exception as e: + except Exception: traceback.print_exc() names = [('source', 'int_'), ('target', 'int_'), diff --git a/examples/icub_vor_examples/receptive_fields_for_motion.py b/examples/icub_vor_examples/receptive_fields_for_motion.py index aea8adfc..d7ccdfb0 100644 --- a/examples/icub_vor_examples/receptive_fields_for_motion.py +++ b/examples/icub_vor_examples/receptive_fields_for_motion.py @@ -142,6 +142,7 @@ def convert_pixel_mapping(pixel, down_sample_x, down_sample_y): address = (y << 12) + (x << 1) + 1 return address + def map_neurons_to_field( length, x_segments, y_segments, scale_down, layers, x_size=304, y_size=240, central_x=304, central_y=240): @@ -171,7 +172,7 @@ def map_neurons_to_field( for y in range(central_y / 2): x_segment = int(x / ((x_size - (x_border)) / x_segments)) y_segment = int(y / ((y_size - (y_border)) / y_segments)) - pixel_mapping[layers][(x_size - (x_border / 2)) - x -1][ + pixel_mapping[layers][(x_size - (x_border / 2)) - x - 1][ y + y_border] = [(x_segments - 1) - x_segment, y_segment] pixel_mapping[layers][x + x_border][ (y_size - (y_border / 2)) - y - 1] = [ @@ -247,7 +248,7 @@ def map_to_from_list( field_size[layer][mapping[layer][x][y][0]][ mapping[layer][x][y][1]]) else: - weight = pixel_weight #/ 16. + weight = pixel_weight # / 16. connection = [ convert_pixel_mapping(x + (304 * y), width, length), convert_xy_field_to_id( @@ -312,7 +313,7 @@ def split_the_from_list( def segment_hidden_pop(from_list, width, length, pre): - hidden_pops = [] + # hidden_pops = [] list_of_lists = [[] for i in range(width*length)] for connection in from_list: if pre: @@ -361,6 +362,7 @@ def connect_it_up(visual_input, motor_output, connections, width, length): print("finished connecting") return all_pops + simulate = True sim.setup(timestep=1.0) @@ -412,7 +414,8 @@ def connect_it_up(visual_input, motor_output, connections, width, length): vis_pop = sim.Population(None, ICUBInputVertex(spinnaker_link_id=0), label='pop_in') -pop_out = sim.Population(4, sim.IF_curr_exp(tau_refrac=3), label="motor_control") +pop_out = sim.Population(4, sim.IF_curr_exp(tau_refrac=3), + label="motor_control") if simulate: pop_out.record(['spikes', 'v']) @@ -449,10 +452,10 @@ def connect_it_up(visual_input, motor_output, connections, width, length): # bottle.addInt32(2) # out_port.write() -#recordings and simulations, -#neuron_pop.record("spikes") +# recordings and simulations, +# neuron_pop.record("spikes") -simtime = 30000 # ms +simtime = 30000 # ms if simulate: sim.run(simtime) else: From 3703efda9aa8714aa338106dddc03dfe1814b374 Mon Sep 17 00:00:00 2001 From: Andrew Gait Date: Mon, 22 Nov 2021 09:45:16 +0000 Subject: [PATCH 08/28] Commented out code relating to camera events which isn't available - code still crashes due to size mismatches but at least passes flake8 --- .../receptive_fields_for_motion.py | 41 +++++++++++-------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/examples/icub_vor_examples/receptive_fields_for_motion.py b/examples/icub_vor_examples/receptive_fields_for_motion.py index d7ccdfb0..d04136eb 100644 --- a/examples/icub_vor_examples/receptive_fields_for_motion.py +++ b/examples/icub_vor_examples/receptive_fields_for_motion.py @@ -17,11 +17,13 @@ # import socket import spynnaker8 as sim -import numpy as np +# import numpy as np # import logging import matplotlib.pyplot as plt -from decode_events import * -from functions import * + +# (the files for these imports don't appear to be on the icub_vor branch) +# from decode_events import * +# from functions import * # import yarp from pacman.model.constraints.key_allocator_constraints import ( @@ -35,7 +37,6 @@ from spinn_front_end_common.abstract_models.\ abstract_provides_incoming_partition_constraints import ( AbstractProvidesIncomingPartitionConstraints) -from pacman.executor.injection_decorator import inject_items from pacman.operations.routing_info_allocator_algorithms.\ malloc_based_routing_allocator.utils import get_possible_masks from spinn_front_end_common.utility_models.command_sender_machine_vertex \ @@ -168,17 +169,17 @@ def map_neurons_to_field( for k in range(layers+1)] x_border = int(x_size - central_x) # / 2 y_border = int(y_size - central_y) # / 2 - for x in range(central_x / 2): - for y in range(central_y / 2): + for x in range(int(central_x / 2)): + for y in range(int(central_y / 2)): x_segment = int(x / ((x_size - (x_border)) / x_segments)) y_segment = int(y / ((y_size - (y_border)) / y_segments)) - pixel_mapping[layers][(x_size - (x_border / 2)) - x - 1][ + pixel_mapping[layers][(x_size - (x_border // 2)) - x - 1][ y + y_border] = [(x_segments - 1) - x_segment, y_segment] pixel_mapping[layers][x + x_border][ - (y_size - (y_border / 2)) - y - 1] = [ + (y_size - (y_border // 2)) - y - 1] = [ x_segment, (y_segments - 1) - y_segment] - pixel_mapping[layers][(x_size - (x_border / 2)) - x - 1][ - (y_size - (y_border / 2)) - y - 1] = [ + pixel_mapping[layers][(x_size - (x_border // 2)) - x - 1][ + (y_size - (y_border // 2)) - y - 1] = [ (x_segments - 1) - x_segment, (y_segments - 1) - y_segment] pixel_mapping[layers][x + x_border][y + y_border] = [ x_segment, y_segment] @@ -392,14 +393,16 @@ def connect_it_up(visual_input, motor_output, connections, width, length): if simulate: # Assuming channel 0 as left camera and channel 1 as right camera # Import data.log and Decode events - dm = DataManager() - dm.load_AE_from_yarp('acquisitions10042019/circle10042019') - - # Loading decoded events; data(timestamp, channel, x, y, polarity) - stereo_data = np.loadtxt( - 'acquisitions10042019/circle10042019/decoded_events.txt', - delimiter=',') - [left_data, right_data] = split_stereo_data(stereo_data) + # (the files for these imports don't appear to be on the icub_vor branch) + # dm = DataManager() + # dm.load_AE_from_yarp('acquisitions10042019/circle10042019') + # + # # Loading decoded events; data(timestamp, channel, x, y, polarity) + # stereo_data = np.loadtxt( + # 'acquisitions10042019/circle10042019/decoded_events.txt', + # delimiter=',') + # [left_data, right_data] = split_stereo_data(stereo_data) + [left_data, right_data] = [[], []] # left_data.tolist() # right_data.tolist() @@ -408,6 +411,8 @@ def connect_it_up(visual_input, motor_output, connections, width, length): print('ATIS data processing ended') + # This currently crashes because width*length=4 is not the same as the + # value used in convert_data (304*240) vis_pop = sim.Population(width*length, sim.SpikeSourceArray(new_left), label='pop_in') else: From 9381562451ac6958528e14d01fd5d1edd7d50f43 Mon Sep 17 00:00:00 2001 From: Andrew Gait Date: Mon, 22 Nov 2021 09:50:37 +0000 Subject: [PATCH 09/28] Exclude csv --- .ratexcludes | 1 + 1 file changed, 1 insertion(+) diff --git a/.ratexcludes b/.ratexcludes index e3ce47c9..fd56a9a8 100644 --- a/.ratexcludes +++ b/.ratexcludes @@ -1,5 +1,6 @@ **/*.colour_map **/*.col +**/*.csv **/SpiNNUtils/** **/SpiNNMachine/** **/SpiNNMan/** From 02197623aa1c89148d400140b8fd4fa5f5b0501d Mon Sep 17 00:00:00 2001 From: Andrew Gait Date: Tue, 23 Nov 2021 12:44:50 +0000 Subject: [PATCH 10/28] packets-per-timestep appears to be broken on this branch; ignore for now --- examples/icub_vor_examples/cerebellum_tb.py | 6 ++++-- examples/icub_vor_examples/pb_cerebellum_tb.py | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/examples/icub_vor_examples/cerebellum_tb.py b/examples/icub_vor_examples/cerebellum_tb.py index 5699edb7..f91d1071 100644 --- a/examples/icub_vor_examples/cerebellum_tb.py +++ b/examples/icub_vor_examples/cerebellum_tb.py @@ -460,9 +460,11 @@ def process_VN_spiketrains(VN_spikes, t_start): MF_spikes = MF_population.get_data('spikes') CF_spikes = CF_population.get_data('spikes') -GC_spikes = GC_population.get_data('all') +# GC_spikes = GC_population.get_data('all') +GC_spikes = GC_population.get_data(['spikes', 'v', 'gsyn_exc', 'gsyn_inh']) GOC_spikes = GOC_population.get_data('spikes') -VN_spikes = VN_population.get_data('all') # VN_population.get_data('spikes') +# VN_spikes = VN_population.get_data('all') # VN_population.get_data('spikes') +VN_spikes = VN_population.get_data(['spikes', 'v', 'gsyn_exc', 'gsyn_inh']) PC_spikes = PC_population.get_data('spikes') mfvn_weights = mf_vn_connections.get('weight', 'list', with_address=False) diff --git a/examples/icub_vor_examples/pb_cerebellum_tb.py b/examples/icub_vor_examples/pb_cerebellum_tb.py index ad42d8d9..d22dac7e 100644 --- a/examples/icub_vor_examples/pb_cerebellum_tb.py +++ b/examples/icub_vor_examples/pb_cerebellum_tb.py @@ -679,9 +679,11 @@ def process_VN_spiketrains(VN_spikes, t_start): MF_spikes = MF_population.get_data('spikes') CF_spikes = CF_population.get_data('spikes') -GC_spikes = GC_population.get_data('all') +# GC_spikes = GC_population.get_data('all') +GC_spikes = GC_population.get_data(['spikes', 'v', 'gsyn_exc', 'gsyn_inh']) GOC_spikes = GOC_population.get_data('spikes') -VN_spikes = VN_population.get_data('all') # VN_population.get_data('spikes') +# VN_spikes = VN_population.get_data('all') # VN_population.get_data('spikes') +VN_spikes = VN_population.get_data(['spikes', 'v', 'gsyn_exc', 'gsyn_inh']) PC_spikes = PC_population.get_data('spikes') mfvn_weights = mf_vn_connections.get('weight', 'list', with_address=False) From f30017d667705539044935a3103ae0f70edf1799 Mon Sep 17 00:00:00 2001 From: Andrew Gait Date: Tue, 23 Nov 2021 17:18:39 +0000 Subject: [PATCH 11/28] Add various file extensions to gitignore --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 06205f55..1cd18b99 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,7 @@ __pycache__ *application_generated_data_files/ *reports/ .mypy_cache/ +**/*png +**/*pdf +**/*npz +**/*zip From e2b529ddcce9c11b6cf320dc221ba2ba9231ddd3 Mon Sep 17 00:00:00 2001 From: Andrew Gait Date: Mon, 29 Nov 2021 15:07:56 +0000 Subject: [PATCH 12/28] get_data('all') working properly again --- examples/icub_vor_examples/cerebellum_tb.py | 6 ++---- examples/icub_vor_examples/pb_cerebellum_tb.py | 6 ++---- ...single_purkinje_cell_test.pysingle_purkinje_cell_test.py | 2 +- .../icub_vor_examples/single_purkinje_cell_pf_windowing.py | 2 +- .../single_purkinje_cell_potentiation_test.py | 2 +- examples/icub_vor_examples/single_purkinje_cell_test.py | 2 +- .../single_vestibular_nuclei_mf_windowing.py | 3 +-- .../single_vestibular_nuclei_mf_windowing_3_spikes.py | 3 +-- .../single_vestibular_nuclei_potentiation_test.py | 3 +-- 9 files changed, 11 insertions(+), 18 deletions(-) diff --git a/examples/icub_vor_examples/cerebellum_tb.py b/examples/icub_vor_examples/cerebellum_tb.py index f91d1071..5699edb7 100644 --- a/examples/icub_vor_examples/cerebellum_tb.py +++ b/examples/icub_vor_examples/cerebellum_tb.py @@ -460,11 +460,9 @@ def process_VN_spiketrains(VN_spikes, t_start): MF_spikes = MF_population.get_data('spikes') CF_spikes = CF_population.get_data('spikes') -# GC_spikes = GC_population.get_data('all') -GC_spikes = GC_population.get_data(['spikes', 'v', 'gsyn_exc', 'gsyn_inh']) +GC_spikes = GC_population.get_data('all') GOC_spikes = GOC_population.get_data('spikes') -# VN_spikes = VN_population.get_data('all') # VN_population.get_data('spikes') -VN_spikes = VN_population.get_data(['spikes', 'v', 'gsyn_exc', 'gsyn_inh']) +VN_spikes = VN_population.get_data('all') # VN_population.get_data('spikes') PC_spikes = PC_population.get_data('spikes') mfvn_weights = mf_vn_connections.get('weight', 'list', with_address=False) diff --git a/examples/icub_vor_examples/pb_cerebellum_tb.py b/examples/icub_vor_examples/pb_cerebellum_tb.py index d22dac7e..ad42d8d9 100644 --- a/examples/icub_vor_examples/pb_cerebellum_tb.py +++ b/examples/icub_vor_examples/pb_cerebellum_tb.py @@ -679,11 +679,9 @@ def process_VN_spiketrains(VN_spikes, t_start): MF_spikes = MF_population.get_data('spikes') CF_spikes = CF_population.get_data('spikes') -# GC_spikes = GC_population.get_data('all') -GC_spikes = GC_population.get_data(['spikes', 'v', 'gsyn_exc', 'gsyn_inh']) +GC_spikes = GC_population.get_data('all') GOC_spikes = GOC_population.get_data('spikes') -# VN_spikes = VN_population.get_data('all') # VN_population.get_data('spikes') -VN_spikes = VN_population.get_data(['spikes', 'v', 'gsyn_exc', 'gsyn_inh']) +VN_spikes = VN_population.get_data('all') # VN_population.get_data('spikes') PC_spikes = PC_population.get_data('spikes') mfvn_weights = mf_vn_connections.get('weight', 'list', with_address=False) diff --git a/examples/icub_vor_examples/pb_single_purkinje_cell_test.pysingle_purkinje_cell_test.py b/examples/icub_vor_examples/pb_single_purkinje_cell_test.pysingle_purkinje_cell_test.py index 03247733..9a0bc4b1 100644 --- a/examples/icub_vor_examples/pb_single_purkinje_cell_test.pysingle_purkinje_cell_test.py +++ b/examples/icub_vor_examples/pb_single_purkinje_cell_test.pysingle_purkinje_cell_test.py @@ -90,7 +90,7 @@ granluar_cell_spikes = granular_cell.get_data('spikes') climbing_fibre_spikes = climbing_fibre.get_data('spikes') -purkinje_data = purkinje_cell.get_data(['v', 'gsyn_exc', 'spikes']) +purkinje_data = purkinje_cell.get_data() pf_weights = synapse_pfpc.get('weight', 'list', with_address=False) print(pf_weights) diff --git a/examples/icub_vor_examples/single_purkinje_cell_pf_windowing.py b/examples/icub_vor_examples/single_purkinje_cell_pf_windowing.py index 9b44cfdc..91c2b41e 100644 --- a/examples/icub_vor_examples/single_purkinje_cell_pf_windowing.py +++ b/examples/icub_vor_examples/single_purkinje_cell_pf_windowing.py @@ -93,7 +93,7 @@ granluar_cell_spikes = granular_cell.get_data('spikes') climbing_fibre_spikes = climbing_fibre.get_data('spikes') -purkinje_data = purkinje_cell.get_data(['v', 'gsyn_exc', 'spikes']) +purkinje_data = purkinje_cell.get_data() pf_weights = synapse_pfpc.get('weight', 'list', with_address=False) print(pf_weights) diff --git a/examples/icub_vor_examples/single_purkinje_cell_potentiation_test.py b/examples/icub_vor_examples/single_purkinje_cell_potentiation_test.py index 73409b93..809835fb 100644 --- a/examples/icub_vor_examples/single_purkinje_cell_potentiation_test.py +++ b/examples/icub_vor_examples/single_purkinje_cell_potentiation_test.py @@ -80,7 +80,7 @@ pf_weights.append(synapse_pfpc.get('weight', 'list', with_address=False)) granluar_cell_spikes = granular_cell.get_data('spikes') -purkinje_data = purkinje_cell.get_data(['v', 'gsyn_exc', 'spikes']) +purkinje_data = purkinje_cell.get_data() for i in pf_weights: print(i) diff --git a/examples/icub_vor_examples/single_purkinje_cell_test.py b/examples/icub_vor_examples/single_purkinje_cell_test.py index c7bc54a0..fa7c28d9 100644 --- a/examples/icub_vor_examples/single_purkinje_cell_test.py +++ b/examples/icub_vor_examples/single_purkinje_cell_test.py @@ -90,7 +90,7 @@ granluar_cell_spikes = granular_cell.get_data('spikes') climbing_fibre_spikes = climbing_fibre.get_data('spikes') -purkinje_data = purkinje_cell.get_data(['v', 'gsyn_exc', 'spikes']) +purkinje_data = purkinje_cell.get_data() pf_weights = synapse_pfpc.get('weight', 'list', with_address=False) print(pf_weights) diff --git a/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing.py b/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing.py index 887fa95d..26d1bf2b 100644 --- a/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing.py +++ b/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing.py @@ -97,8 +97,7 @@ mossy_fibre_src_spikes = mossy_fibre_src.get_data('spikes') purkinje_cell_src_spikes = purkinje_cell_src.get_data('spikes') -vestibular_nuclei_data = vestibular_nuclei.get_data( - ['v', 'gsyn_exc', 'spikes']) +vestibular_nuclei_data = vestibular_nuclei.get_data() mf_weights = synapse_mfvn.get('weight', 'list', with_address=False) print(mf_weights) diff --git a/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing_3_spikes.py b/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing_3_spikes.py index 786fe9dd..cc3c23ca 100644 --- a/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing_3_spikes.py +++ b/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing_3_spikes.py @@ -98,8 +98,7 @@ mossy_fibre_src_spikes = mossy_fibre_src.get_data('spikes') purkinje_cell_src_spikes = purkinje_cell_src.get_data('spikes') -vestibular_nuclei_data = vestibular_nuclei.get_data( - ['v', 'gsyn_exc', 'spikes']) +vestibular_nuclei_data = vestibular_nuclei.get_data() mf_weights = synapse_mfvn.get('weight', 'list', with_address=False) print("\n {}".format(mf_weights)) diff --git a/examples/icub_vor_examples/single_vestibular_nuclei_potentiation_test.py b/examples/icub_vor_examples/single_vestibular_nuclei_potentiation_test.py index 7f8121c8..000a1766 100644 --- a/examples/icub_vor_examples/single_vestibular_nuclei_potentiation_test.py +++ b/examples/icub_vor_examples/single_vestibular_nuclei_potentiation_test.py @@ -82,8 +82,7 @@ mf_weights.append(synapse_mfvn.get('weight', 'list', with_address=False)) mossy_fibre_src_spikes = mossy_fibre_src.get_data('spikes') -vestibular_neuclei_data = vestibular_neuclei.get_data( - ['v', 'gsyn_exc', 'spikes']) +vestibular_neuclei_data = vestibular_neuclei.get_data() # print weight history for i in mf_weights: From 104151e63d36d68dd57f488e80b74c172050f3df Mon Sep 17 00:00:00 2001 From: Andrew Gait Date: Mon, 28 Feb 2022 12:31:19 +0000 Subject: [PATCH 13/28] Use max_rate to prevent remapping --- examples/icub_vor_examples/cerebellum_tb.py | 9 ++++++--- examples/icub_vor_examples/pb_cerebellum_tb.py | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/examples/icub_vor_examples/cerebellum_tb.py b/examples/icub_vor_examples/cerebellum_tb.py index 5699edb7..0d301fb6 100644 --- a/examples/icub_vor_examples/cerebellum_tb.py +++ b/examples/icub_vor_examples/cerebellum_tb.py @@ -113,6 +113,7 @@ # For each a gaussian is created centered on a specific neuron. # Prepare variables once at beginning +MAX_RATE = 600.0 MAX_AMPLITUDE = 0.8 RELATIVE_AMPLITUDE = 1.0 _head_pos = [] @@ -147,7 +148,7 @@ def sensorial_activity(pt): head_vel = 0.0 min_rate = 0.0 - max_rate = 600.0 + max_rate = MAX_RATE sigma = 0.02 MF_pos_activity = np.zeros((50)) MF_vel_activity = np.zeros((50)) @@ -230,7 +231,8 @@ def process_VN_spiketrains(VN_spikes, t_start): sim.SpikeSourcePoisson, # source type # {'rate': sa_mean_freq}, # source spike times {'rate': sensorial_activity(0)[0]}, # source spike times - label="MFLayer" # identifier + label="MFLayer", # identifier + additional_parameters={"max_rate": MAX_RATE} ) # Create GOC population @@ -266,7 +268,8 @@ def process_VN_spiketrains(VN_spikes, t_start): sim.SpikeSourcePoisson, # source type # {'rate': sa_mean_freq}, # source spike times {'rate': error_activity(err)}, # source spike times - label="CFLayer" # identifier + label="CFLayer", # identifier + additional_parameters={"max_rate": MAX_RATE} ) ############################################################### diff --git a/examples/icub_vor_examples/pb_cerebellum_tb.py b/examples/icub_vor_examples/pb_cerebellum_tb.py index ad42d8d9..2656ac4a 100644 --- a/examples/icub_vor_examples/pb_cerebellum_tb.py +++ b/examples/icub_vor_examples/pb_cerebellum_tb.py @@ -236,6 +236,7 @@ def save_figure(plt, name, extensions=(".png",), **kwargs): # activity. For each a gaussian is created centered on a specific neuron. # Prepare variables once at beginning +MAX_RATE = 600.0 MAX_AMPLITUDE = 0.8 RELATIVE_AMPLITUDE = 1.0 _head_pos = [] @@ -323,7 +324,7 @@ def sensorial_activity(pt): head_vel = 0.0 min_rate = 0.0 - max_rate = 600.0 + max_rate = MAX_RATE sigma = 0.02 MF_pos_activity = np.zeros((50)) MF_vel_activity = np.zeros((50)) @@ -405,7 +406,8 @@ def process_VN_spiketrains(VN_spikes, t_start): sim.SpikeSourcePoisson, # source type # {'rate': sa_mean_freq}, # source spike times {'rate': sensorial_activity(0)[0]}, # source spike times - label="MFLayer" # identifier + label="MFLayer", # identifier + additional_parameters={"max_rate": MAX_RATE} ) all_populations["mossy_fibers"] = MF_population @@ -447,7 +449,8 @@ def process_VN_spiketrains(VN_spikes, t_start): sim.SpikeSourcePoisson, # source type # {'rate': sa_mean_freq}, # source spike times {'rate': error_activity(err)}, # source spike times - label="CFLayer" # identifier + label="CFLayer", # identifier + additional_parameters={"max_rate": MAX_RATE} ) all_populations["climbing_fibers"] = CF_population From a881df976b1c4b1320281132f65d274bbf7a57f8 Mon Sep 17 00:00:00 2001 From: Andrew Gait Date: Wed, 2 Mar 2022 11:50:25 +0000 Subject: [PATCH 14/28] Move SpiNNGym examples into SpiNNGym repository --- .../spinn_gym_examples/icub_utilities.py | 249 ---- .../spinn_gym_examples/icub_vor_env_test.py | 186 --- .../icub_vor_env_test_200_inputs.py | 118 -- .../icub_vor_venv_test_perfect_motion.py | 131 --- .../normalised_head_positions_1000.csv | 1000 ----------------- .../normalised_head_velocities_1000.csv | 1000 ----------------- .../spinn_gym_examples/spynnaker.cfg | 4 - 7 files changed, 2688 deletions(-) delete mode 100644 examples/icub_vor_examples/spinn_gym_examples/icub_utilities.py delete mode 100644 examples/icub_vor_examples/spinn_gym_examples/icub_vor_env_test.py delete mode 100644 examples/icub_vor_examples/spinn_gym_examples/icub_vor_env_test_200_inputs.py delete mode 100644 examples/icub_vor_examples/spinn_gym_examples/icub_vor_venv_test_perfect_motion.py delete mode 100644 examples/icub_vor_examples/spinn_gym_examples/normalised_head_positions_1000.csv delete mode 100644 examples/icub_vor_examples/spinn_gym_examples/normalised_head_velocities_1000.csv delete mode 100644 examples/icub_vor_examples/spinn_gym_examples/spynnaker.cfg diff --git a/examples/icub_vor_examples/spinn_gym_examples/icub_utilities.py b/examples/icub_vor_examples/spinn_gym_examples/icub_utilities.py deleted file mode 100644 index 6648ac8f..00000000 --- a/examples/icub_vor_examples/spinn_gym_examples/icub_utilities.py +++ /dev/null @@ -1,249 +0,0 @@ -# Copyright (c) 2019-2021 The University of Manchester -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -import numpy as np -import pylab as plt -import matplotlib as mlib -import copy - -# ensure we use viridis as the default cmap -plt.viridis() - -mlib.use('Agg') -# ensure we use the same rc parameters for all matplotlib outputs -mlib.rcParams.update({'font.size': 24}) -mlib.rcParams.update({'errorbar.capsize': 5}) -mlib.rcParams.update({'figure.autolayout': True}) -viridis_cmap = mlib.cm.get_cmap('viridis') - -ICUB_VOR_VENV_POP_SIZE = 2 -POS_TO_VEL = 2 * np.pi * 0.001 - - -# Examples of get functions for variables -def get_error(icub_vor_env_pop, simulator): - b_vertex = icub_vor_env_pop._vertex - error = b_vertex.get_data( - 'error', simulator.no_machine_time_steps, simulator.placements, - simulator.buffer_manager) - return error.tolist() - - -def get_l_count(icub_vor_env_pop, simulator): - b_vertex = icub_vor_env_pop._vertex - left_count = b_vertex.get_data( - 'l_count', simulator.no_machine_time_steps, simulator.placements, - simulator.buffer_manager) - return left_count.tolist() - - -def get_r_count(icub_vor_env_pop, simulator): - b_vertex = icub_vor_env_pop._vertex - right_count = b_vertex.get_data( - 'r_count', simulator.no_machine_time_steps, simulator.placements, - simulator.buffer_manager) - return right_count.tolist() - - -def get_eye_pos(icub_vor_env_pop, simulator): - b_vertex = icub_vor_env_pop._vertex - eye_positions = b_vertex.get_data( - 'eye_pos', simulator.no_machine_time_steps, simulator.placements, - simulator.buffer_manager) - return eye_positions.tolist() - - -def get_eye_vel(icub_vor_env_pop, simulator): - b_vertex = icub_vor_env_pop._vertex - eye_velocities = b_vertex.get_data( - 'eye_vel', simulator.no_machine_time_steps, simulator.placements, - simulator.buffer_manager) - return eye_velocities.tolist() - - -def generate_head_position_and_velocity(time, dt=0.001): - i = np.arange(0, time, dt) - pos = -np.sin(i * 2 * np.pi) - vel = -np.cos(i * 2 * np.pi) - return pos, vel - - -def retrieve_and_package_results(icub_vor_env_pop, simulator): - # Get the data from the ICubVorEnv pop - errors = np.asarray(get_error( - icub_vor_env_pop=icub_vor_env_pop, simulator=simulator)).ravel() - l_counts = get_l_count(icub_vor_env_pop=icub_vor_env_pop, - simulator=simulator) - r_counts = get_r_count(icub_vor_env_pop=icub_vor_env_pop, - simulator=simulator) - rec_eye_pos = np.asarray(get_eye_pos( - icub_vor_env_pop=icub_vor_env_pop, simulator=simulator)).ravel() - rec_eye_vel = np.asarray(get_eye_vel( - icub_vor_env_pop=icub_vor_env_pop, simulator=simulator)).ravel() - results = { - 'errors': errors, - 'l_counts': l_counts, - 'r_counts': r_counts, - 'rec_eye_pos': rec_eye_pos, - 'rec_eye_vel': rec_eye_vel, - } - return results - - -def highlight_area(ax, runtime, start_nid, stop_nid): - ax.fill_between( - [0, runtime], start_nid, stop_nid, - color='grey', alpha=0.1, - ) - - -def plot_results(results_dict, simulation_parameters, name): - # unpacking results - errors = results_dict['errors'] - l_counts = results_dict['l_counts'] - r_counts = results_dict['r_counts'] - rec_eye_pos = results_dict['rec_eye_pos'] - rec_eye_vel = results_dict['rec_eye_vel'] - - # unpacking simulation params - runtime = simulation_parameters['runtime'] - error_window_size = simulation_parameters['error_window_size'] - vn_spikes = simulation_parameters['vn_spikes'] - cf_spikes = simulation_parameters['cf_spikes'] - perfect_eye_pos = simulation_parameters['perfect_eye_pos'] - perfect_eye_vel = simulation_parameters['perfect_eye_vel'] - vn_size = simulation_parameters['vn_size'] - cf_size = simulation_parameters['cf_size'] - - # plot the data from the ICubVorEnv pop - x_plot = [(n) for n in range(0, runtime, error_window_size)] - fig = plt.figure(figsize=(15, 20), dpi=400) - # Spike raster plot - ax = plt.subplot(5, 1, 1) - highlight_area(ax, runtime, vn_size // 2, vn_size) - first_half_filter = vn_spikes[:, 0] < vn_size // 2 - second_half_filter = ~first_half_filter - plt.scatter( - vn_spikes[second_half_filter, 1], vn_spikes[second_half_filter, 0], - s=1, color=viridis_cmap(.75)) - plt.scatter( - vn_spikes[first_half_filter, 1], vn_spikes[first_half_filter, 0], - s=1, color=viridis_cmap(.25)) - - plt.xlim([0, runtime]) - plt.ylim([-0.1, vn_size+0.1]) - # L/R counts - plt.subplot(5, 1, 2) - plt.plot(x_plot, l_counts, 'o', color=viridis_cmap(.25), label="l_counts") - plt.plot(x_plot, r_counts, 'o', color=viridis_cmap(.75), label="r_counts") - plt.legend(loc="best") - plt.xlim([0, runtime]) - # Positions and velocities - plt.subplot(5, 1, 3) - plt.plot(x_plot, rec_eye_pos, label="rec. eye position") - plt.plot(x_plot, rec_eye_vel, label="rec. eye velocity") - plt.plot(np.tile(perfect_eye_pos, runtime // 1000), label="eye position", - ls=':') - plt.plot(np.tile(perfect_eye_vel, runtime // 1000), label="eye velocity", - ls=':') - plt.legend(loc="best") - plt.xlim([0, runtime]) - # Errors - plt.subplot(5, 1, 4) - plt.plot(x_plot, errors, label="recorded error") - - eye_pos_diff = np.tile( - perfect_eye_pos[::error_window_size], - runtime // 1000) - rec_eye_pos.ravel() - eye_vel_diff = np.tile( - perfect_eye_vel[::error_window_size], - runtime // 1000) - rec_eye_vel.ravel() - reconstructed_error = eye_pos_diff + eye_vel_diff - - plt.plot(x_plot, reconstructed_error, color='k', ls=":", - label="reconstructed error") - plt.plot(x_plot, eye_pos_diff, - label="eye position diff") - plt.plot(x_plot, eye_vel_diff, - label="eye velocity diff") - plt.legend(loc="best") - plt.xlim([0, runtime]) - # Error spikes - ax2 = plt.subplot(5, 1, 5) - highlight_area(ax2, runtime, cf_size // 2, cf_size) - first_half_filter = cf_spikes[:, 0] < cf_size // 2 - second_half_filter = ~first_half_filter - plt.scatter( - cf_spikes[second_half_filter, 1], cf_spikes[second_half_filter, 0], - s=1, color=viridis_cmap(.75)) - plt.scatter( - cf_spikes[first_half_filter, 1], cf_spikes[first_half_filter, 0], - s=1, color=viridis_cmap(.25)) - # plt.legend(loc="best") - plt.xlim([0, runtime]) - plt.ylim([-0.1, cf_size+0.1]) - plt.xlabel("Time (ms)") - save_figure(plt, name, extensions=[".png", ]) - plt.close(fig) - - -def remap_odd_even(original_spikes, size): - remapped_spikes = copy.deepcopy(original_spikes) - mapping = np.arange(size) - mapping[::2] = np.arange(0, size, 2) // 2 - mapping[1::2] = size // 2 + np.arange(size - 1, 0, -2) // 2 - remapped_spikes[:, 0] = mapping[remapped_spikes[:, 0].astype(int)] - return remapped_spikes - - -def remap_second_half_descending(original_spikes, size): - remapped_spikes = copy.deepcopy(original_spikes) - mapping = np.arange(size) - mapping[:size // 2] = np.arange(0, size // 2, 1) - mapping[size // 2:] = np.arange(size, size // 2, -1) - remapped_spikes[:, 0] = mapping[remapped_spikes[:, 0].astype(int)] - return remapped_spikes - - -def color_for_index(index, size, cmap=viridis_cmap): - return cmap(index / (size + 1)) - - -def write_sep(): - print("=" * 80) - - -def write_line(): - print("-" * 80) - - -def write_header(msg): - write_sep() - print(msg) - write_line() - - -def write_short_msg(msg, value): - print("{:40}:{:39}".format(msg, str(value))) - - -def write_value(msg, value): - print("{:60}:{:19}".format(msg, str(value))) - - -def save_figure(plt, name, extensions=(".png",), **kwargs): - for ext in extensions: - write_short_msg("Plotting", name + ext) - plt.savefig(name + ext, **kwargs) diff --git a/examples/icub_vor_examples/spinn_gym_examples/icub_vor_env_test.py b/examples/icub_vor_examples/spinn_gym_examples/icub_vor_env_test.py deleted file mode 100644 index 59371115..00000000 --- a/examples/icub_vor_examples/spinn_gym_examples/icub_vor_env_test.py +++ /dev/null @@ -1,186 +0,0 @@ -# Copyright (c) 2019-2021 The University of Manchester -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -import spynnaker8 as p -import spinn_gym as gym - -import matplotlib.pyplot as plt -import numpy as np -import os -from spinn_front_end_common.utilities.globals_variables import get_simulator - - -# Examples of get functions for variables -def get_error(icub_vor_env_pop, simulator): - b_vertex = icub_vor_env_pop._vertex - error = b_vertex.get_data( - 'error', simulator.no_machine_time_steps, simulator.placements, - simulator.buffer_manager) - return error.tolist() - - -def get_l_count(icub_vor_env_pop, simulator): - b_vertex = icub_vor_env_pop._vertex - left_count = b_vertex.get_data( - 'l_count', simulator.no_machine_time_steps, simulator.placements, - simulator.buffer_manager) - return left_count.tolist() - - -def get_r_count(icub_vor_env_pop, simulator): - b_vertex = icub_vor_env_pop._vertex - right_count = b_vertex.get_data( - 'r_count', simulator.no_machine_time_steps, simulator.placements, - simulator.buffer_manager) - return right_count.tolist() - - -def get_eye_pos(icub_vor_env_pop, simulator): - b_vertex = icub_vor_env_pop._vertex - eye_positions = b_vertex.get_data( - 'eye_pos', simulator.no_machine_time_steps, simulator.placements, - simulator.buffer_manager) - return eye_positions.tolist() - - -def get_eye_vel(icub_vor_env_pop, simulator): - b_vertex = icub_vor_env_pop._vertex - eye_velocities = b_vertex.get_data( - 'eye_vel', simulator.no_machine_time_steps, simulator.placements, - simulator.buffer_manager) - return eye_velocities.tolist() - - -# Setup -p.setup(timestep=1.0) -# p.set_number_of_neurons_per_core(p.SpikeSourcePoisson, 100) - -# Build input SSP and output population -input_size = 2 -output_size = 200 - -input_rate = 20 -input_pop = p.Population(input_size, p.SpikeSourcePoisson(rate=input_rate), - label='SSP_input') -output_pop = p.Population(output_size, p.SpikeSourcePoisson(rate=0), - label='SSP_output') - -# get head_positions and head_velocities from file (1000 samples) -base_dir = "./" -head_pos = np.loadtxt(os.path.join( - base_dir, "normalised_head_positions_1000.csv")) -head_vel = np.loadtxt(os.path.join( - base_dir, "normalised_head_velocities_1000.csv")) - -# The values in the files are [0,1] when we really want [-1,1]; obtain this -# by multiplying by 2 and subtracting 1 - -head_pos = (head_pos * 2.0) - 1.0 -head_vel = (head_vel * 2.0) - 1.0 - -# perfect eye positions and velocities are exactly out of phase with head -perfect_eye_pos = np.concatenate((head_pos[500:], head_pos[:500])) -perfect_eye_vel = np.concatenate((head_vel[500:], head_vel[:500])) - -# Report 4 points: -for i in [0, 250, 500, 750]: - print("At {}: head pos {:4.6f}, head vel {:4.6f}, eye pos {:4.6f}, " - "eye vel {:4.6f}".format( - i, head_pos[i], head_vel[i], perfect_eye_pos[i], - perfect_eye_vel[i])) - -# build ICubVorEnv model pop -error_window_size = 10 -icub_vor_env_model = gym.ICubVorEnv( - head_pos, head_vel, perfect_eye_vel, perfect_eye_pos, error_window_size, - output_size) -icub_vor_env_pop = p.Population(input_size, icub_vor_env_model) - -# Set recording for input and output pop (env pop records by default) -input_pop.record('spikes') -output_pop.record('spikes') - -# Input -> ICubVorEnv projection -i2a = p.Projection(input_pop, icub_vor_env_pop, p.AllToAllConnector()) - -# ICubVorEnv -> output, setup live output to the SSP vertex -p.external_devices.activate_live_output_to( - icub_vor_env_pop, output_pop, "CONTROL") - -# Store simulator and run -simulator = get_simulator() -runtime = 10000 -p.run(runtime) - -# Get the data from the ICubVorEnv pop -errors = get_error(icub_vor_env_pop=icub_vor_env_pop, simulator=simulator) -l_counts = get_l_count(icub_vor_env_pop=icub_vor_env_pop, simulator=simulator) -r_counts = get_r_count(icub_vor_env_pop=icub_vor_env_pop, simulator=simulator) -rec_eye_pos = get_eye_pos( - icub_vor_env_pop=icub_vor_env_pop, simulator=simulator) -rec_eye_vel = get_eye_vel( - icub_vor_env_pop=icub_vor_env_pop, simulator=simulator) - -# get the spike data from input and output and plot -# spikes_in = input_pop.get_data('spikes').segments[0].spiketrains -# spikes_out = output_pop.get_data('spikes').segments[0].spiketrains -# Figure( -# Panel(spikes_in, xlabel="Time (ms)", ylabel="nID", -# xticks=True, yticks=True), -# Panel(spikes_out, xlabel="Time (ms)", ylabel="nID", -# xticks=True, yticks=True) -# ) -# plt.show() - -spikes_in_spin = input_pop.spinnaker_get_data('spikes') -spikes_out_spin = output_pop.spinnaker_get_data('spikes') - -# end simulation -p.end() - -# plot the data from the ICubVorEnv pop -x_plot = [(n) for n in range(0, runtime, error_window_size)] -plt.figure(figsize=(15, 11)) - -plt.subplot(5, 1, 1) -plt.scatter( - [i[1] for i in spikes_in_spin], [i[0] for i in spikes_in_spin], s=1) -plt.xlim([0, runtime]) - -plt.subplot(5, 1, 2) -plt.plot(x_plot, l_counts, 'bo', label="l_counts") -plt.plot(x_plot, r_counts, 'ro', label="r_counts") -plt.legend(loc="best") -plt.xlim([0, runtime]) - -plt.subplot(5, 1, 3) -plt.plot(x_plot, rec_eye_pos, label="eye position") -plt.plot(x_plot, rec_eye_vel, label="eye velocity") -# plt.plot(perfect_eye_pos, label="eye position", ls='--') -# plt.plot(perfect_eye_vel, label="eye velocity", ls='--') -plt.legend(loc="best") -plt.xlim([0, runtime]) - -plt.subplot(5, 1, 4) -plt.plot(x_plot, errors, label="errors") -plt.legend(loc="best") -plt.xlim([0, runtime]) - -plt.subplot(5, 1, 5) -plt.scatter( - [i[1] for i in spikes_out_spin], [i[0] for i in spikes_out_spin], s=1) -plt.xlim([0, runtime]) - -plt.show() diff --git a/examples/icub_vor_examples/spinn_gym_examples/icub_vor_env_test_200_inputs.py b/examples/icub_vor_examples/spinn_gym_examples/icub_vor_env_test_200_inputs.py deleted file mode 100644 index 064a12f9..00000000 --- a/examples/icub_vor_examples/spinn_gym_examples/icub_vor_env_test_200_inputs.py +++ /dev/null @@ -1,118 +0,0 @@ -# Copyright (c) 2019-2021 The University of Manchester -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -import spynnaker8 as p -import spinn_gym as gym - -# from pyNN.utility.plotting import Figure, Panel -# import matplotlib.pyplot as plt -import numpy as np -# import os -from spinn_front_end_common.utilities.globals_variables import get_simulator -from icub_utilities import ( - generate_head_position_and_velocity, retrieve_and_package_results, - remap_odd_even, remap_second_half_descending, ICUB_VOR_VENV_POP_SIZE, - plot_results) - - -# Parameter definition -runtime = 5000 -# Build input SSP and output population -input_size = 200 # neurons -output_size = 200 # neurons -gain = 20.0 - -head_pos, head_vel = generate_head_position_and_velocity(1) - -# perfect eye positions and velocities are exactly out of phase with head -perfect_eye_pos = np.concatenate((head_pos[500:], head_pos[:500])) -perfect_eye_vel = np.concatenate((head_vel[500:], head_vel[:500])) - -error_window_size = 10 # ms -npc_limit = 50 -input_spike_times = [[] for _ in range(input_size)] - -for i in range(5): - input_spike_times[i * 2] = [250 + (10 * 2 * i) for _ in range(1)] - input_spike_times[2 * i + 1] = [500 + (10 * (2 * i + 1)) for _ in range(1)] - input_spike_times[50 + i * 2] = [750 + (10 * 2 * i) for _ in range(10 + i)] - input_spike_times[100 + 2 * i + 1] = [ - 1000 + (10 * (2 * i + 1)) for _ in range(10 + i)] - input_spike_times[150 + i * 2] = [ - 1250 + (10 * 2 * i) for _ in range(100 + i)] - input_spike_times[150 + 2 * i + 1] = [ - 1500 + (10 * (2 * i + 1)) for _ in range(100 + i)] - -# Setup -p.setup(timestep=1.0) -p.set_number_of_neurons_per_core(p.SpikeSourcePoisson, 50) -p.set_number_of_neurons_per_core(p.SpikeSourceArray, npc_limit) -input_pop = p.Population(input_size, - p.SpikeSourceArray(spike_times=input_spike_times)) - -output_pop = p.Population(output_size, p.SpikeSourcePoisson(rate=0)) - -# Instantiate venv -icub_vor_env_model = gym.ICubVorEnv( - head_pos, head_vel, perfect_eye_vel, perfect_eye_pos, error_window_size, - output_size) -icub_vor_env_pop = p.Population(ICUB_VOR_VENV_POP_SIZE, icub_vor_env_model) - -# Set recording for input and output pop (env pop records by default) -input_pop.record('spikes') -output_pop.record('spikes') - -# Input -> ICubVorEnv projection -i2a = p.Projection(input_pop, icub_vor_env_pop, p.AllToAllConnector()) - -# ICubVorEnv -> output, setup live output to the SSP vertex -p.external_devices.activate_live_output_to( - icub_vor_env_pop, output_pop, "CONTROL") - -# Store simulator and run -simulator = get_simulator() -# Run the simulation -p.run(runtime) - -# Get the data from the ICubVorEnv pop -results = retrieve_and_package_results(icub_vor_env_pop, simulator) - -# get the spike data from input and output -spikes_in_spin = input_pop.spinnaker_get_data('spikes') -spikes_out_spin = output_pop.spinnaker_get_data('spikes') - -# end simulation -p.end() - -remapped_vn_spikes = remap_odd_even(spikes_in_spin, input_size) -remapped_cf_spikes = remap_second_half_descending(spikes_out_spin, output_size) - -simulation_parameters = { - 'runtime': runtime, - 'error_window_size': error_window_size, - 'vn_spikes': remapped_vn_spikes, - 'cf_spikes': remapped_cf_spikes, - 'perfect_eye_pos': perfect_eye_pos, - 'perfect_eye_vel': perfect_eye_vel, - 'vn_size': input_size, - 'cf_size': output_size, - 'gain': gain -} - -# plot the data from the ICubVorEnv pop -plot_results(results_dict=results, simulation_parameters=simulation_parameters, - name="spinngym_icub_vor_test_200_inputs") - -print("Done") diff --git a/examples/icub_vor_examples/spinn_gym_examples/icub_vor_venv_test_perfect_motion.py b/examples/icub_vor_examples/spinn_gym_examples/icub_vor_venv_test_perfect_motion.py deleted file mode 100644 index bff484a3..00000000 --- a/examples/icub_vor_examples/spinn_gym_examples/icub_vor_venv_test_perfect_motion.py +++ /dev/null @@ -1,131 +0,0 @@ -# Copyright (c) 2019-2021 The University of Manchester -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -import spynnaker8 as p -import spinn_gym as gym - -# from pyNN.utility.plotting import Figure, Panel -# import matplotlib.pyplot as plt -import numpy as np -# import os -from spinn_front_end_common.utilities.globals_variables import get_simulator -from icub_utilities import ( - generate_head_position_and_velocity, retrieve_and_package_results, - remap_odd_even, remap_second_half_descending, ICUB_VOR_VENV_POP_SIZE, - plot_results) - - -# Parameter definition -runtime = 3000 -# Build input SSP and output population -input_size = 200 # neurons -output_size = 200 # neurons -gain = 20.0 - -head_pos, head_vel = generate_head_position_and_velocity(1) - -# perfect eye positions and velocities are exactly out of phase with head -perfect_eye_pos = np.concatenate((head_pos[500:], head_pos[:500])) -perfect_eye_vel = np.concatenate((head_vel[500:], head_vel[:500])) - -input_spike_times = [[] for _ in range(input_size)] -# the constant number (0.000031) is the effect of a single spike on the head -# position -# assert (np.isclose(np.abs(np.diff(head_pos)[0]), -# no_required_spikes_per_chunk * 0.000031), 0.001) -sub_head_pos = np.diff(head_pos) -head_movement_per_spike = 2 ** (-15) * gain -sub_eye_pos = np.diff(np.concatenate((perfect_eye_pos, [perfect_eye_pos[0]]))) - -# no_required_spikes_per_chunk = 200 -no_required_spikes_per_chunk = np.ceil( - np.abs(sub_head_pos[0]) / head_movement_per_spike) - -# build ICubVorEnv model -error_window_size = 10 # ms -npc_limit = 200 # 25 -no_input_cores = int(input_size / npc_limit) -input_spike_times = [[] for _ in range(input_size)] -for ts in range(runtime - 1): - # if 1000 <= ts < 2000: - # continue - sgn = np.sign(sub_eye_pos[ts % 1000]) - spikes_during_chunk = np.ceil( - np.abs(sub_eye_pos[ts % 1000]) / head_movement_per_spike) - for i in range(int(spikes_during_chunk)): - x = int(sgn <= 0) - input_spike_times[(i % no_input_cores) * npc_limit + x].append(ts) - -# Setup -p.setup(timestep=1.0) -p.set_number_of_neurons_per_core(p.SpikeSourcePoisson, 50) -p.set_number_of_neurons_per_core(p.SpikeSourceArray, npc_limit) -input_pop = p.Population(input_size, - p.SpikeSourceArray(spike_times=input_spike_times)) - -output_pop = p.Population(output_size, p.SpikeSourcePoisson(rate=0)) - -# Instantiate venv -icub_vor_env_model = gym.ICubVorEnv( - head_pos, head_vel, perfect_eye_vel, perfect_eye_pos, error_window_size, - output_size) -icub_vor_env_pop = p.Population(ICUB_VOR_VENV_POP_SIZE, icub_vor_env_model) - -# Set recording for input and output pop (env pop records by default) -input_pop.record('spikes') -output_pop.record('spikes') - -# Input -> ICubVorEnv projection -i2a = p.Projection(input_pop, icub_vor_env_pop, p.AllToAllConnector()) - -# ICubVorEnv -> output, setup live output to the SSP vertex -p.external_devices.activate_live_output_to( - icub_vor_env_pop, output_pop, "CONTROL") - -# Store simulator and run -simulator = get_simulator() -# Run the simulation -p.run(runtime) - -# Get the data from the ICubVorEnv pop -results = retrieve_and_package_results(icub_vor_env_pop, simulator) - -# get the spike data from input and output -spikes_in_spin = input_pop.spinnaker_get_data('spikes') -spikes_out_spin = output_pop.spinnaker_get_data('spikes') - -# end simulation -p.end() - -remapped_vn_spikes = remap_odd_even(spikes_in_spin, input_size) -remapped_cf_spikes = remap_second_half_descending(spikes_out_spin, output_size) - -simulation_parameters = { - 'runtime': runtime, - 'error_window_size': error_window_size, - 'vn_spikes': remapped_vn_spikes, - 'cf_spikes': remapped_cf_spikes, - 'perfect_eye_pos': perfect_eye_pos, - 'perfect_eye_vel': perfect_eye_vel, - 'vn_size': input_size, - 'cf_size': output_size, - 'gain': gain -} - -# plot the data from the ICubVorEnv pop -plot_results(results_dict=results, simulation_parameters=simulation_parameters, - name="spinngym_icub_vor_test_perfect") - -print("Done") diff --git a/examples/icub_vor_examples/spinn_gym_examples/normalised_head_positions_1000.csv b/examples/icub_vor_examples/spinn_gym_examples/normalised_head_positions_1000.csv deleted file mode 100644 index a66f167a..00000000 --- a/examples/icub_vor_examples/spinn_gym_examples/normalised_head_positions_1000.csv +++ /dev/null @@ -1,1000 +0,0 @@ -5.000000000000000000e-01 -4.968584280172205769e-01 -4.937169800583237067e-01 -4.905757801422959141e-01 -4.874349522783312239e-01 -4.842946204609358540e-01 -4.811549086650327434e-01 -4.780159408410675770e-01 -4.748778409101152009e-01 -4.717407327589877020e-01 -4.686047402353433200e-01 -4.654699871427970814e-01 -4.623365972360336529e-01 -4.592046942159212497e-01 -4.560744017246283755e-01 -4.529458433407428375e-01 -4.498191425743925387e-01 -4.466944228623700996e-01 -4.435718075632591462e-01 -4.404514199525650930e-01 -4.373333832178478708e-01 -4.342178204538587050e-01 -4.311048546576810025e-01 -4.279946087238739594e-01 -4.248872054396214404e-01 -4.217827674798845239e-01 -4.186814174025581536e-01 -4.155832776436330644e-01 -4.124884705123619821e-01 -4.093971181864313191e-01 -4.063093427071376995e-01 -4.032252659745698686e-01 -4.001450097427964869e-01 -3.970686956150593638e-01 -3.939964450389726869e-01 -3.909283793017287456e-01 -3.878646195253094286e-01 -3.848052866617047152e-01 -3.817505014881376613e-01 -3.787003846022963249e-01 -3.756550564175726303e-01 -3.726146371583089478e-01 -3.695792468550515575e-01 -3.665490053398122172e-01 -3.635240322413374470e-01 -3.605044469803853624e-01 -3.574903687650119455e-01 -3.544819165858640875e-01 -3.514792092114825128e-01 -3.484823651836130298e-01 -3.454915028125263299e-01 -3.425067401723476124e-01 -3.395281950963952022e-01 -3.365559851725287155e-01 -3.335902277385066617e-01 -3.306310398773543158e-01 -3.276785384127414713e-01 -3.247328399043704628e-01 -3.217940606433745687e-01 -3.188623166477271287e-01 -3.159377236576610404e-01 -3.130203971310997479e-01 -3.101104522390994434e-01 -3.072080038613017594e-01 -3.043131665813987863e-01 -3.014260546826096898e-01 -2.985467821431686541e-01 -2.956754626318254808e-01 -2.928122095033579009e-01 -2.899571357940968763e-01 -2.871103542174636702e-01 -2.842719771595204614e-01 -2.814421166745335601e-01 -2.786208844805492801e-01 -2.758083919549839114e-01 -2.730047501302266255e-01 -2.702100696892560938e-01 -2.674244609612708157e-01 -2.646480339173337692e-01 -2.618808981660304402e-01 -2.591231629491423383e-01 -2.563749371373338914e-01 -2.536363292258542179e-01 -2.509074473302546071e-01 -2.481883991821196012e-01 -2.454792921248143411e-01 -2.427802331092467902e-01 -2.400913286896452226e-01 -2.374126850193521987e-01 -2.347444078466329742e-01 -2.320866025105016717e-01 -2.294393739365621077e-01 -2.268028266328654674e-01 -2.241770646857849103e-01 -2.215621917559060239e-01 -2.189583110739347360e-01 -2.163655254366217418e-01 -2.137839372027045548e-01 -2.112136482888661848e-01 -2.086547601657119666e-01 -2.061073738537634592e-01 -2.035715899194703860e-01 -2.010475084712405880e-01 -1.985352291554876580e-01 -1.960348511526972815e-01 -1.935464731735118127e-01 -1.910701934548328373e-01 -1.886061097559437183e-01 -1.861543193546497665e-01 -1.837149190434377577e-01 -1.812880051256551828e-01 -1.788736734117077898e-01 -1.764720192152779144e-01 -1.740831373495606293e-01 -1.717071221235217382e-01 -1.693440673381740869e-01 -1.669940662828741373e-01 -1.646572117316399964e-01 -1.623335959394877348e-01 -1.600233106387904114e-01 -1.577264470356556925e-01 -1.554430958063257595e-01 -1.531733470935975339e-01 -1.509172905032637180e-01 -1.486750151005754306e-01 -1.464466094067262691e-01 -1.442321613953573278e-01 -1.420317584890844753e-01 -1.398454875560465327e-01 -1.376734349064766827e-01 -1.355156862892942238e-01 -1.333723268887200553e-01 -1.312434413209130624e-01 -1.291291136306304266e-01 -1.270294272879089748e-01 -1.249444651847701759e-01 -1.228743096319481060e-01 -1.208190423556390614e-01 -1.187787444942760284e-01 -1.167534965953250653e-01 -1.147433786121053456e-01 -1.127484699006330721e-01 -1.107688492164882882e-01 -1.088045947117059764e-01 -1.068557839316905400e-01 -1.049224938121548489e-01 -1.030048006760823920e-01 -1.011027802307144785e-01 -9.921650756456172615e-02 -9.734605714443907154e-02 -9.549150281252624661e-02 -9.365291778345302687e-02 -9.183037464140800243e-02 -9.002394533727385573e-02 -8.823370118578630072e-02 -8.645971286271911249e-02 -8.470205040209372038e-02 -8.296078319341440577e-02 -8.123597997892917366e-02 -7.952770885091546560e-02 -7.783603724899244847e-02 -7.616103195745842214e-02 -7.450275910265410917e-02 -7.286128415035245109e-02 -7.123667190317387043e-02 -6.962898649802817808e-02 -6.803829140358236272e-02 -6.646464941775495627e-02 -6.490812266523718344e-02 -6.336877259503992388e-02 -6.184665997806815252e-02 -6.034184490472188633e-02 -5.885438678252336020e-02 -5.738434433377237465e-02 -5.593177559322773384e-02 -5.449673790581609223e-02 -5.307928792436814036e-02 -5.167948160738213004e-02 -5.029737421681453047e-02 -4.893302031589857881e-02 -4.758647376699023934e-02 -4.625778772944157125e-02 -4.494701465750219893e-02 -4.365420629824860732e-02 -4.237941368954126209e-02 -4.112268715800941610e-02 -3.988407631706485101e-02 -3.866363006494261123e-02 -3.746139658277095053e-02 -3.627742333266931185e-02 -3.511175705587434026e-02 -3.396444377089455346e-02 -3.283552877169401696e-02 -3.172505662590377473e-02 -3.063307117306297844e-02 -2.955961552288728644e-02 -2.850473205356779394e-02 -2.746846241009757994e-02 -2.645084750262781392e-02 -2.545192750485272826e-02 -2.447174185242324829e-02 -2.351032924139059843e-02 -2.256772762667849652e-02 -2.164397422058469966e-02 -2.073910549131210979e-02 -1.985315716152846743e-02 -1.898616420695706242e-02 -1.813816085499513064e-02 -1.730918058336305965e-02 -1.649925611878252929e-02 -1.570841943568448973e-02 -1.493670175494711538e-02 -1.418413354266304105e-02 -1.345074450893671281e-02 -1.273656360671143739e-02 -1.204161903062633820e-02 -1.136593821590328734e-02 -1.070954783726395243e-02 -1.007247380787654190e-02 -9.454741278332942644e-03 -8.856374635655694938e-03 -8.277397502335151480e-03 -7.717832735397306410e-03 -7.177702425500975814e-03 -6.657027896065995098e-03 -6.155829702431114825e-03 -5.674127631042982789e-03 -5.211940698674547012e-03 -4.769287151674406200e-03 -4.346184465246691331e-03 -3.942649342761062048e-03 -3.558697715093164793e-03 -3.194344739995830240e-03 -2.849604801500524309e-03 -2.524491509349885421e-03 -2.219017698460029608e-03 -1.933195428413733707e-03 -1.667035982985051734e-03 -1.420549869693005229e-03 -1.193746819387400682e-03 -9.866357858642066381e-04 -7.992249455125027824e-04 -6.315216969912662570e-04 -4.835326609376605633e-04 -3.552636797053698725e-04 -2.467198171342277480e-04 -1.579053583500300562e-04 -8.882380959550351118e-05 -3.947789809194413024e-05 -9.869571931456211367e-06 -0.000000000000000000e+00 -9.869571931456211367e-06 -3.947789809194413024e-05 -8.882380959550351118e-05 -1.579053583500300562e-04 -2.467198171342277480e-04 -3.552636797053698725e-04 -4.835326609376605633e-04 -6.315216969912662570e-04 -7.992249455125027824e-04 -9.866357858642066381e-04 -1.193746819387400682e-03 -1.420549869693005229e-03 -1.667035982985051734e-03 -1.933195428413733707e-03 -2.219017698460029608e-03 -2.524491509349885421e-03 -2.849604801500524309e-03 -3.194344739995830240e-03 -3.558697715093164793e-03 -3.942649342761131437e-03 -4.346184465246691331e-03 -4.769287151674406200e-03 -5.211940698674547012e-03 -5.674127631043052178e-03 -6.155829702431184214e-03 -6.657027896065995098e-03 -7.177702425500975814e-03 -7.717832735397306410e-03 -8.277397502335220869e-03 -8.856374635655694938e-03 -9.454741278332942644e-03 -1.007247380787654190e-02 -1.070954783726395243e-02 -1.136593821590328734e-02 -1.204161903062626882e-02 -1.273656360671143739e-02 -1.345074450893671281e-02 -1.418413354266304105e-02 -1.493670175494704599e-02 -1.570841943568442034e-02 -1.649925611878245990e-02 -1.730918058336299026e-02 -1.813816085499506126e-02 -1.898616420695706242e-02 -1.985315716152846743e-02 -2.073910549131204040e-02 -2.164397422058469966e-02 -2.256772762667849652e-02 -2.351032924139059843e-02 -2.447174185242317890e-02 -2.545192750485265887e-02 -2.645084750262781392e-02 -2.746846241009751055e-02 -2.850473205356772455e-02 -2.955961552288728644e-02 -3.063307117306290905e-02 -3.172505662590377473e-02 -3.283552877169394757e-02 -3.396444377089455346e-02 -3.511175705587434026e-02 -3.627742333266931185e-02 -3.746139658277095053e-02 -3.866363006494254184e-02 -3.988407631706478162e-02 -4.112268715800934671e-02 -4.237941368954119270e-02 -4.365420629824853793e-02 -4.494701465750219893e-02 -4.625778772944157125e-02 -4.758647376699023934e-02 -4.893302031589864820e-02 -5.029737421681439169e-02 -5.167948160738199126e-02 -5.307928792436807097e-02 -5.449673790581602284e-02 -5.593177559322773384e-02 -5.738434433377237465e-02 -5.885438678252336020e-02 -6.034184490472188633e-02 -6.184665997806829130e-02 -6.336877259503999327e-02 -6.490812266523718344e-02 -6.646464941775495627e-02 -6.803829140358229333e-02 -6.962898649802817808e-02 -7.123667190317387043e-02 -7.286128415035245109e-02 -7.450275910265410917e-02 -7.616103195745842214e-02 -7.783603724899251786e-02 -7.952770885091539621e-02 -8.123597997892910427e-02 -8.296078319341440577e-02 -8.470205040209365099e-02 -8.645971286271911249e-02 -8.823370118578630072e-02 -9.002394533727385573e-02 -9.183037464140807182e-02 -9.365291778345316565e-02 -9.549150281252624661e-02 -9.734605714443900215e-02 -9.921650756456158737e-02 -1.011027802307144091e-01 -1.030048006760822532e-01 -1.049224938121547102e-01 -1.068557839316904706e-01 -1.088045947117059070e-01 -1.107688492164882882e-01 -1.127484699006330721e-01 -1.147433786121053456e-01 -1.167534965953250653e-01 -1.187787444942759590e-01 -1.208190423556389920e-01 -1.228743096319480366e-01 -1.249444651847701759e-01 -1.270294272879088915e-01 -1.291291136306304266e-01 -1.312434413209130624e-01 -1.333723268887200553e-01 -1.355156862892942793e-01 -1.376734349064765439e-01 -1.398454875560464772e-01 -1.420317584890843365e-01 -1.442321613953572446e-01 -1.464466094067261859e-01 -1.486750151005754306e-01 -1.509172905032637180e-01 -1.531733470935975339e-01 -1.554430958063258150e-01 -1.577264470356556092e-01 -1.600233106387903559e-01 -1.623335959394877348e-01 -1.646572117316399131e-01 -1.669940662828741373e-01 -1.693440673381740869e-01 -1.717071221235218215e-01 -1.740831373495606849e-01 -1.764720192152779144e-01 -1.788736734117077343e-01 -1.812880051256550995e-01 -1.837149190434377577e-01 -1.861543193546497110e-01 -1.886061097559437183e-01 -1.910701934548328373e-01 -1.935464731735118127e-01 -1.960348511526973647e-01 -1.985352291554877413e-01 -2.010475084712406435e-01 -2.035715899194703304e-01 -2.061073738537633759e-01 -2.086547601657119666e-01 -2.112136482888661848e-01 -2.137839372027046381e-01 -2.163655254366217973e-01 -2.189583110739347638e-01 -2.215621917559060794e-01 -2.241770646857850491e-01 -2.268028266328653841e-01 -2.294393739365620521e-01 -2.320866025105016717e-01 -2.347444078466329742e-01 -2.374126850193521987e-01 -2.400913286896453336e-01 -2.427802331092468457e-01 -2.454792921248144522e-01 -2.481883991821197399e-01 -2.509074473302545516e-01 -2.536363292258542179e-01 -2.563749371373336694e-01 -2.591231629491422273e-01 -2.618808981660303292e-01 -2.646480339173336027e-01 -2.674244609612707047e-01 -2.702100696892560383e-01 -2.730047501302265700e-01 -2.758083919549838559e-01 -2.786208844805492246e-01 -2.814421166745335601e-01 -2.842719771595203504e-01 -2.871103542174635592e-01 -2.899571357940967653e-01 -2.928122095033578454e-01 -2.956754626318254253e-01 -2.985467821431686541e-01 -3.014260546826096898e-01 -3.043131665813987863e-01 -3.072080038613017594e-01 -3.101104522390993323e-01 -3.130203971310996369e-01 -3.159377236576608738e-01 -3.188623166477270732e-01 -3.217940606433745687e-01 -3.247328399043704628e-01 -3.276785384127414713e-01 -3.306310398773543158e-01 -3.335902277385067727e-01 -3.365559851725286045e-01 -3.395281950963952022e-01 -3.425067401723475013e-01 -3.454915028125262189e-01 -3.484823651836130298e-01 -3.514792092114825128e-01 -3.544819165858640875e-01 -3.574903687650120010e-01 -3.605044469803854179e-01 -3.635240322413375025e-01 -3.665490053398121617e-01 -3.695792468550514465e-01 -3.726146371583088923e-01 -3.756550564175725748e-01 -3.787003846022963249e-01 -3.817505014881376613e-01 -3.848052866617047707e-01 -3.878646195253094842e-01 -3.909283793017288566e-01 -3.939964450389725759e-01 -3.970686956150593083e-01 -4.001450097427964869e-01 -4.032252659745698686e-01 -4.063093427071376995e-01 -4.093971181864314302e-01 -4.124884705123620376e-01 -4.155832776436331755e-01 -4.186814174025583202e-01 -4.217827674798844684e-01 -4.248872054396214404e-01 -4.279946087238739594e-01 -4.311048546576810025e-01 -4.342178204538588160e-01 -4.373333832178477598e-01 -4.404514199525650375e-01 -4.435718075632590351e-01 -4.466944228623699331e-01 -4.498191425743925387e-01 -4.529458433407427820e-01 -4.560744017246284865e-01 -4.592046942159210277e-01 -4.623365972360335419e-01 -4.654699871427969704e-01 -4.686047402353432645e-01 -4.717407327589876465e-01 -4.748778409101152009e-01 -4.780159408410675215e-01 -4.811549086650327434e-01 -4.842946204609359095e-01 -4.874349522783311128e-01 -4.905757801422958031e-01 -4.937169800583235957e-01 -4.968584280172204104e-01 -4.999999999999999445e-01 -5.031415719827794231e-01 -5.062830199416762378e-01 -5.094242198577040304e-01 -5.125650477216687761e-01 -5.157053795390640349e-01 -5.188450913349671456e-01 -5.219840591589323120e-01 -5.251221590898846880e-01 -5.282592672410122425e-01 -5.313952597646567355e-01 -5.345300128572029186e-01 -5.376634027639664026e-01 -5.407953057840788613e-01 -5.439255982753714580e-01 -5.470541566592570515e-01 -5.501808574256074058e-01 -5.533055771376299559e-01 -5.564281924367407983e-01 -5.595485800474349070e-01 -5.626666167821521292e-01 -5.657821795461412950e-01 -5.688951453423191085e-01 -5.720053912761261516e-01 -5.751127945603784486e-01 -5.782172325201153651e-01 -5.813185825974417353e-01 -5.844167223563669911e-01 -5.875115294876379624e-01 -5.906028818135686809e-01 -5.936906572928624115e-01 -5.967747340254302424e-01 -5.998549902572036796e-01 -6.029313043849405807e-01 -6.060035549610273131e-01 -6.090716206982712544e-01 -6.121353804746906269e-01 -6.151947133382953403e-01 -6.182494985118623942e-01 -6.212996153977038416e-01 -6.243449435824275362e-01 -6.273853628416912187e-01 -6.304207531449484980e-01 -6.334509946601877273e-01 -6.364759677586625530e-01 -6.394955530196146931e-01 -6.425096312349881655e-01 -6.455180834141360791e-01 -6.485207907885176537e-01 -6.515176348163871367e-01 -6.545084971874738367e-01 -6.574932598276524987e-01 -6.604718049036047978e-01 -6.634440148274712845e-01 -6.664097722614933383e-01 -6.693689601226456842e-01 -6.723214615872585842e-01 -6.752671600956295928e-01 -6.782059393566255423e-01 -6.811376833522730934e-01 -6.840622763423390706e-01 -6.869796028689002521e-01 -6.898895477609005011e-01 -6.927919961386982406e-01 -6.956868334186012692e-01 -6.985739453173903657e-01 -7.014532178568314569e-01 -7.043245373681746857e-01 -7.071877904966422657e-01 -7.100428642059033457e-01 -7.128896457825363298e-01 -7.157280228404795386e-01 -7.185578833254665510e-01 -7.213791155194507754e-01 -7.241916080450162552e-01 -7.269952498697735965e-01 -7.297899303107441282e-01 -7.325755390387289623e-01 -7.353519660826660642e-01 -7.381191018339694487e-01 -7.408768370508574952e-01 -7.436250628626661641e-01 -7.463636707741456711e-01 -7.490925526697452819e-01 -7.518116008178801213e-01 -7.545207078751854368e-01 -7.572197668907529877e-01 -7.599086713103545554e-01 -7.625873149806478013e-01 -7.652555921533669148e-01 -7.679133974894982728e-01 -7.705606260634378923e-01 -7.731971733671345604e-01 -7.758229353142149787e-01 -7.784378082440938096e-01 -7.810416889260651807e-01 -7.836344745633780917e-01 -7.862160627972953897e-01 -7.887863517111337597e-01 -7.913452398342879501e-01 -7.938926261462365686e-01 -7.964284100805296696e-01 -7.989524915287593565e-01 -8.014647708445121754e-01 -8.039651488473026353e-01 -8.064535268264880763e-01 -8.089298065451669961e-01 -8.113938902440561707e-01 -8.138456806453501224e-01 -8.162850809565621590e-01 -8.187119948743448727e-01 -8.211263265882923212e-01 -8.235279807847220024e-01 -8.259168626504392874e-01 -8.282928778764780953e-01 -8.306559326618259131e-01 -8.330059337171258349e-01 -8.353427882683600592e-01 -8.376664040605121819e-01 -8.399766893612095053e-01 -8.422735529643443630e-01 -8.445569041936741295e-01 -8.468266529064023551e-01 -8.490827094967362543e-01 -8.513249848994244307e-01 -8.535533905932737309e-01 -8.557678386046426722e-01 -8.579682415109154414e-01 -8.601545124439535783e-01 -8.623265650935232340e-01 -8.644843137107056652e-01 -8.666276731112798615e-01 -8.687565586790868544e-01 -8.708708863693694902e-01 -8.729705727120909975e-01 -8.750555348152296853e-01 -8.771256903680518802e-01 -8.791809576443607721e-01 -8.812212555057239438e-01 -8.832465034046749208e-01 -8.852566213878946266e-01 -8.872515300993668586e-01 -8.892311507835117812e-01 -8.911954052882939958e-01 -8.931442160683092935e-01 -8.950775061878452066e-01 -8.969951993239174692e-01 -8.988972197692854937e-01 -9.007834924354382045e-01 -9.026539428555609978e-01 -9.045084971874736146e-01 -9.063470822165471397e-01 -9.081696253585920253e-01 -9.099760546627261304e-01 -9.117662988142136715e-01 -9.135402871372807487e-01 -9.152979495979064462e-01 -9.170392168065855110e-01 -9.187640200210709374e-01 -9.204722911490844650e-01 -9.221639627510076487e-01 -9.238389680425416195e-01 -9.254972408973460851e-01 -9.271387158496476877e-01 -9.287633280968260463e-01 -9.303710135019718219e-01 -9.319617085964176928e-01 -9.335353505822452380e-01 -9.350918773347628443e-01 -9.366312274049601871e-01 -9.381533400219318475e-01 -9.396581550952782802e-01 -9.411456132174766953e-01 -9.426156556662276254e-01 -9.440682244067722939e-01 -9.455032620941838939e-01 -9.469207120756319984e-01 -9.483205183926179949e-01 -9.497026257831855389e-01 -9.510669796841014767e-01 -9.524135262330098994e-01 -9.537422122705585537e-01 -9.550529853424978288e-01 -9.563457937017514343e-01 -9.576205863104587657e-01 -9.588773128419906255e-01 -9.601159236829351906e-01 -9.613363699350575553e-01 -9.625386034172290772e-01 -9.637225766673307437e-01 -9.648882429441257846e-01 -9.660355562291054188e-01 -9.671644712283061773e-01 -9.682749433740961420e-01 -9.693669288269370909e-01 -9.704403844771127829e-01 -9.714952679464323726e-01 -9.725315375899025172e-01 -9.735491524973722832e-01 -9.745480724951474105e-01 -9.755282581475768211e-01 -9.764896707586095959e-01 -9.774322723733215312e-01 -9.783560257794152726e-01 -9.792608945086878069e-01 -9.801468428384715326e-01 -9.810138357930427988e-01 -9.818618391450048000e-01 -9.826908194166369404e-01 -9.835007438812174430e-01 -9.842915805643155380e-01 -9.850632982450530095e-01 -9.858158664573369867e-01 -9.865492554910632039e-01 -9.872634363932886181e-01 -9.879583809693737173e-01 -9.886340617840967404e-01 -9.892904521627360337e-01 -9.899275261921234303e-01 -9.905452587216669880e-01 -9.911436253643443051e-01 -9.917226024976647514e-01 -9.922821672646027213e-01 -9.928222975744990242e-01 -9.933429721039339633e-01 -9.938441702975688852e-01 -9.943258723689569756e-01 -9.947880593013255224e-01 -9.952307128483256493e-01 -9.956538155347532948e-01 -9.960573506572389935e-01 -9.964413022849069046e-01 -9.968056552600041975e-01 -9.971503951984994618e-01 -9.974755084906501423e-01 -9.977809823015399981e-01 -9.980668045715862524e-01 -9.983329640170148789e-01 -9.985794501303070225e-01 -9.988062531806126687e-01 -9.990133642141357795e-01 -9.992007750544875666e-01 -9.993684783030087893e-01 -9.995164673390624088e-01 -9.996447363202946024e-01 -9.997532801828658000e-01 -9.998420946416499699e-01 -9.999111761904044826e-01 -9.999605221019081114e-01 -9.999901304280686132e-01 -1.000000000000000000e+00 -9.999901304280686132e-01 -9.999605221019081114e-01 -9.999111761904044826e-01 -9.998420946416499699e-01 -9.997532801828658000e-01 -9.996447363202946024e-01 -9.995164673390624088e-01 -9.993684783030087893e-01 -9.992007750544875666e-01 -9.990133642141357795e-01 -9.988062531806126687e-01 -9.985794501303070225e-01 -9.983329640170148789e-01 -9.980668045715862524e-01 -9.977809823015399981e-01 -9.974755084906501423e-01 -9.971503951984994618e-01 -9.968056552600041975e-01 -9.964413022849069046e-01 -9.960573506572389935e-01 -9.956538155347532948e-01 -9.952307128483256493e-01 -9.947880593013255224e-01 -9.943258723689569756e-01 -9.938441702975688852e-01 -9.933429721039340743e-01 -9.928222975744990242e-01 -9.922821672646027213e-01 -9.917226024976649734e-01 -9.911436253643443051e-01 -9.905452587216669880e-01 -9.899275261921234303e-01 -9.892904521627360337e-01 -9.886340617840967404e-01 -9.879583809693737173e-01 -9.872634363932886181e-01 -9.865492554910632039e-01 -9.858158664573369867e-01 -9.850632982450530095e-01 -9.842915805643155380e-01 -9.835007438812176650e-01 -9.826908194166369404e-01 -9.818618391450048000e-01 -9.810138357930429098e-01 -9.801468428384715326e-01 -9.792608945086879180e-01 -9.783560257794151616e-01 -9.774322723733215312e-01 -9.764896707586093738e-01 -9.755282581475768211e-01 -9.745480724951472995e-01 -9.735491524973721722e-01 -9.725315375899024062e-01 -9.714952679464322616e-01 -9.704403844771126719e-01 -9.693669288269370909e-01 -9.682749433740962530e-01 -9.671644712283059553e-01 -9.660355562291056408e-01 -9.648882429441255626e-01 -9.637225766673307437e-01 -9.625386034172289662e-01 -9.613363699350574443e-01 -9.601159236829350796e-01 -9.588773128419905145e-01 -9.576205863104588767e-01 -9.563457937017513233e-01 -9.550529853424979398e-01 -9.537422122705583316e-01 -9.524135262330097884e-01 -9.510669796841012547e-01 -9.497026257831855389e-01 -9.483205183926177728e-01 -9.469207120756318874e-01 -9.455032620941840049e-01 -9.440682244067721829e-01 -9.426156556662276254e-01 -9.411456132174764733e-01 -9.396581550952781692e-01 -9.381533400219317365e-01 -9.366312274049600761e-01 -9.350918773347627333e-01 -9.335353505822452380e-01 -9.319617085964176928e-01 -9.303710135019719329e-01 -9.287633280968261573e-01 -9.271387158496476877e-01 -9.254972408973461961e-01 -9.238389680425418415e-01 -9.221639627510077597e-01 -9.204722911490845760e-01 -9.187640200210711594e-01 -9.170392168065856220e-01 -9.152979495979064462e-01 -9.135402871372808598e-01 -9.117662988142138936e-01 -9.099760546627261304e-01 -9.081696253585921363e-01 -9.063470822165472507e-01 -9.045084971874737256e-01 -9.026539428555611089e-01 -9.007834924354383155e-01 -8.988972197692857158e-01 -8.969951993239175803e-01 -8.950775061878453176e-01 -8.931442160683095155e-01 -8.911954052882942179e-01 -8.892311507835118922e-01 -8.872515300993669696e-01 -8.852566213878948487e-01 -8.832465034046749208e-01 -8.812212555057241659e-01 -8.791809576443609942e-01 -8.771256903680521022e-01 -8.750555348152296853e-01 -8.729705727120912195e-01 -8.708708863693698232e-01 -8.687565586790870764e-01 -8.666276731112800835e-01 -8.644843137107057762e-01 -8.623265650935235671e-01 -8.601545124439533563e-01 -8.579682415109157745e-01 -8.557678386046426722e-01 -8.535533905932737309e-01 -8.513249848994247637e-01 -8.490827094967363653e-01 -8.468266529064027992e-01 -8.445569041936742405e-01 -8.422735529643444741e-01 -8.399766893612095053e-01 -8.376664040605122930e-01 -8.353427882683600592e-01 -8.330059337171258349e-01 -8.306559326618262462e-01 -8.282928778764783173e-01 -8.259168626504395094e-01 -8.235279807847221134e-01 -8.211263265882923212e-01 -8.187119948743448727e-01 -8.162850809565622701e-01 -8.138456806453500114e-01 -8.113938902440562817e-01 -8.089298065451674402e-01 -8.064535268264882983e-01 -8.039651488473028573e-01 -8.014647708445123975e-01 -7.989524915287595785e-01 -7.964284100805296696e-01 -7.938926261462366796e-01 -7.913452398342879501e-01 -7.887863517111338707e-01 -7.862160627972956117e-01 -7.836344745633783138e-01 -7.810416889260654028e-01 -7.784378082440940316e-01 -7.758229353142152007e-01 -7.731971733671344493e-01 -7.705606260634380034e-01 -7.679133974894981618e-01 -7.652555921533671368e-01 -7.625873149806478013e-01 -7.599086713103547774e-01 -7.572197668907534318e-01 -7.545207078751855478e-01 -7.518116008178805654e-01 -7.490925526697452819e-01 -7.463636707741457821e-01 -7.436250628626659420e-01 -7.408768370508576062e-01 -7.381191018339694487e-01 -7.353519660826662863e-01 -7.325755390387292953e-01 -7.297899303107437952e-01 -7.269952498697734855e-01 -7.241916080450159221e-01 -7.213791155194507754e-01 -7.185578833254663289e-01 -7.157280228404795386e-01 -7.128896457825362187e-01 -7.100428642059031237e-01 -7.071877904966422657e-01 -7.043245373681744637e-01 -7.014532178568313459e-01 -6.985739453173901437e-01 -6.956868334186012692e-01 -6.927919961386981296e-01 -6.898895477609005011e-01 -6.869796028688999190e-01 -6.840622763423389596e-01 -6.811376833522728713e-01 -6.782059393566253203e-01 -6.752671600956295928e-01 -6.723214615872583622e-01 -6.693689601226456842e-01 -6.664097722614931163e-01 -6.634440148274711735e-01 -6.604718049036045757e-01 -6.574932598276523876e-01 -6.545084971874738367e-01 -6.515176348163868036e-01 -6.485207907885174317e-01 -6.455180834141357460e-01 -6.425096312349881655e-01 -6.394955530196144711e-01 -6.364759677586625530e-01 -6.334509946601875052e-01 -6.304207531449484980e-01 -6.273853628416911077e-01 -6.243449435824276472e-01 -6.212996153977037306e-01 -6.182494985118626163e-01 -6.151947133382956734e-01 -6.121353804746907379e-01 -6.090716206982716985e-01 -6.060035549610274241e-01 -6.029313043849410247e-01 -5.998549902572035686e-01 -5.967747340254303534e-01 -5.936906572928624115e-01 -5.906028818135689029e-01 -5.875115294876379624e-01 -5.844167223563671021e-01 -5.813185825974421794e-01 -5.782172325201154761e-01 -5.751127945603787817e-01 -5.720053912761261516e-01 -5.688951453423193305e-01 -5.657821795461412950e-01 -5.626666167821523512e-01 -5.595485800474347959e-01 -5.564281924367410204e-01 -5.533055771376302889e-01 -5.501808574256075168e-01 -5.470541566592574956e-01 -5.439255982753715690e-01 -5.407953057840789723e-01 -5.376634027639662916e-01 -5.345300128572030296e-01 -5.313952597646566245e-01 -5.282592672410124646e-01 -5.251221590898850211e-01 -5.219840591589325340e-01 -5.188450913349675897e-01 -5.157053795390641460e-01 -5.125650477216689982e-01 -5.094242198577040304e-01 -5.062830199416764598e-01 -5.031415719827794231e-01 diff --git a/examples/icub_vor_examples/spinn_gym_examples/normalised_head_velocities_1000.csv b/examples/icub_vor_examples/spinn_gym_examples/normalised_head_velocities_1000.csv deleted file mode 100644 index f215b6ad..00000000 --- a/examples/icub_vor_examples/spinn_gym_examples/normalised_head_velocities_1000.csv +++ /dev/null @@ -1,1000 +0,0 @@ -0.000000000000000000e+00 -9.869571931439562087e-06 -3.947789809190699632e-05 -8.882380959548627237e-05 -1.579053583499612364e-04 -2.467198171342090997e-04 -3.552636797053673788e-04 -4.835326609376300430e-04 -6.315216969912583423e-04 -7.992249455125140581e-04 -9.866357858641615353e-04 -1.193746819387333461e-03 -1.420549869692992653e-03 -1.667035982985024412e-03 -1.933195428413718962e-03 -2.219017698460000985e-03 -2.524491509349872410e-03 -2.849604801500486579e-03 -3.194344739995816362e-03 -3.558697715093159155e-03 -3.942649342761002200e-03 -4.346184465246665310e-03 -4.769287151674420945e-03 -5.211940698674534002e-03 -5.674127631042969779e-03 -6.155829702431123499e-03 -6.657027896065956935e-03 -7.177702425500961068e-03 -7.717832735397246562e-03 -8.277397502335116786e-03 -8.856374635655587385e-03 -9.454741278332920093e-03 -1.007247380787648638e-02 -1.070954783726390906e-02 -1.136593821590326132e-02 -1.204161903062620463e-02 -1.273656360671141137e-02 -1.345074450893671801e-02 -1.418413354266298380e-02 -1.493670175494710324e-02 -1.570841943568445503e-02 -1.649925611878251541e-02 -1.730918058336302495e-02 -1.813816085499507860e-02 -1.898616420695698956e-02 -1.985315716152841886e-02 -2.073910549131204387e-02 -2.164397422058470313e-02 -2.256772762667843060e-02 -2.351032924139054292e-02 -2.447174185242324135e-02 -2.545192750485270050e-02 -2.645084750262781739e-02 -2.746846241009755912e-02 -2.850473205356769679e-02 -2.955961552288726563e-02 -3.063307117306297844e-02 -3.172505662590380943e-02 -3.283552877169400308e-02 -3.396444377089454653e-02 -3.511175705587420148e-02 -3.627742333266925634e-02 -3.746139658277095746e-02 -3.866363006494259735e-02 -3.988407631706478162e-02 -4.112268715800936753e-02 -4.237941368954127597e-02 -4.365420629824853793e-02 -4.494701465750217118e-02 -4.625778772944151573e-02 -4.758647376699020465e-02 -4.893302031589858575e-02 -5.029737421681453047e-02 -5.167948160738201208e-02 -5.307928792436815424e-02 -5.449673790581603672e-02 -5.593177559322771303e-02 -5.738434433377238159e-02 -5.885438678252330469e-02 -6.034184490472183082e-02 -6.184665997806816640e-02 -6.336877259503986837e-02 -6.490812266523718344e-02 -6.646464941775491464e-02 -6.803829140358234884e-02 -6.962898649802816420e-02 -7.123667190317387043e-02 -7.286128415035239558e-02 -7.450275910265402590e-02 -7.616103195745833887e-02 -7.783603724899246235e-02 -7.952770885091538233e-02 -8.123597997892911815e-02 -8.296078319341440577e-02 -8.470205040209359548e-02 -8.645971286271908474e-02 -8.823370118578624521e-02 -9.002394533727378634e-02 -9.183037464140793305e-02 -9.365291778345298523e-02 -9.549150281252624661e-02 -9.734605714443907154e-02 -9.921650756456158737e-02 -1.011027802307144785e-01 -1.030048006760823781e-01 -1.049224938121547657e-01 -1.068557839316905261e-01 -1.088045947117059348e-01 -1.107688492164882604e-01 -1.127484699006330582e-01 -1.147433786121053179e-01 -1.167534965953250237e-01 -1.187787444942760007e-01 -1.208190423556390197e-01 -1.228743096319480643e-01 -1.249444651847701482e-01 -1.270294272879089470e-01 -1.291291136306304266e-01 -1.312434413209131179e-01 -1.333723268887199720e-01 -1.355156862892941960e-01 -1.376734349064766549e-01 -1.398454875560465327e-01 -1.420317584890843643e-01 -1.442321613953572168e-01 -1.464466094067261859e-01 -1.486750151005754306e-01 -1.509172905032636069e-01 -1.531733470935975061e-01 -1.554430958063257318e-01 -1.577264470356556925e-01 -1.600233106387903836e-01 -1.623335959394877070e-01 -1.646572117316399408e-01 -1.669940662828741373e-01 -1.693440673381740591e-01 -1.717071221235217937e-01 -1.740831373495606849e-01 -1.764720192152778033e-01 -1.788736734117078453e-01 -1.812880051256551550e-01 -1.837149190434377577e-01 -1.861543193546498220e-01 -1.886061097559437738e-01 -1.910701934548328096e-01 -1.935464731735117017e-01 -1.960348511526972537e-01 -1.985352291554875470e-01 -2.010475084712405602e-01 -2.035715899194703027e-01 -2.061073738537634592e-01 -2.086547601657119388e-01 -2.112136482888661571e-01 -2.137839372027044993e-01 -2.163655254366217140e-01 -2.189583110739346805e-01 -2.215621917559059684e-01 -2.241770646857848825e-01 -2.268028266328654674e-01 -2.294393739365620244e-01 -2.320866025105016994e-01 -2.347444078466328909e-01 -2.374126850193520877e-01 -2.400913286896452226e-01 -2.427802331092467902e-01 -2.454792921248143966e-01 -2.481883991821195179e-01 -2.509074473302545516e-01 -2.536363292258542179e-01 -2.563749371373338359e-01 -2.591231629491423938e-01 -2.618808981660304402e-01 -2.646480339173337137e-01 -2.674244609612708712e-01 -2.702100696892560938e-01 -2.730047501302265700e-01 -2.758083919549837448e-01 -2.786208844805491691e-01 -2.814421166745335046e-01 -2.842719771595204614e-01 -2.871103542174636702e-01 -2.899571357940967653e-01 -2.928122095033578454e-01 -2.956754626318254253e-01 -2.985467821431686541e-01 -3.014260546826096898e-01 -3.043131665813987308e-01 -3.072080038613017039e-01 -3.101104522390994434e-01 -3.130203971310998035e-01 -3.159377236576609294e-01 -3.188623166477270732e-01 -3.217940606433746242e-01 -3.247328399043705183e-01 -3.276785384127414713e-01 -3.306310398773542603e-01 -3.335902277385066617e-01 -3.365559851725287710e-01 -3.395281950963952577e-01 -3.425067401723476124e-01 -3.454915028125262189e-01 -3.484823651836129743e-01 -3.514792092114825683e-01 -3.544819165858641430e-01 -3.574903687650118900e-01 -3.605044469803853624e-01 -3.635240322413374470e-01 -3.665490053398122727e-01 -3.695792468550516130e-01 -3.726146371583089478e-01 -3.756550564175725193e-01 -3.787003846022962139e-01 -3.817505014881376058e-01 -3.848052866617046597e-01 -3.878646195253094286e-01 -3.909283793017286346e-01 -3.939964450389726314e-01 -3.970686956150593083e-01 -4.001450097427964869e-01 -4.032252659745698131e-01 -4.063093427071376440e-01 -4.093971181864312636e-01 -4.124884705123619821e-01 -4.155832776436331200e-01 -4.186814174025580981e-01 -4.217827674798845239e-01 -4.248872054396214959e-01 -4.279946087238739594e-01 -4.311048546576810025e-01 -4.342178204538587050e-01 -4.373333832178479263e-01 -4.404514199525651486e-01 -4.435718075632592017e-01 -4.466944228623699886e-01 -4.498191425743925942e-01 -4.529458433407428375e-01 -4.560744017246284310e-01 -4.592046942159213052e-01 -4.623365972360336529e-01 -4.654699871427971369e-01 -4.686047402353432645e-01 -4.717407327589876465e-01 -4.748778409101152009e-01 -4.780159408410675770e-01 -4.811549086650326323e-01 -4.842946204609357985e-01 -4.874349522783312239e-01 -4.905757801422959141e-01 -4.937169800583236512e-01 -4.968584280172204659e-01 -5.000000000000000000e-01 -5.031415719827794231e-01 -5.062830199416763488e-01 -5.094242198577040304e-01 -5.125650477216686651e-01 -5.157053795390641460e-01 -5.188450913349672566e-01 -5.219840591589324230e-01 -5.251221590898846880e-01 -5.282592672410122425e-01 -5.313952597646566245e-01 -5.345300128572029186e-01 -5.376634027639662916e-01 -5.407953057840787503e-01 -5.439255982753716800e-01 -5.470541566592571625e-01 -5.501808574256075168e-01 -5.533055771376299559e-01 -5.564281924367407983e-01 -5.595485800474349070e-01 -5.626666167821522402e-01 -5.657821795461412950e-01 -5.688951453423189975e-01 -5.720053912761261516e-01 -5.751127945603785596e-01 -5.782172325201154761e-01 -5.813185825974417353e-01 -5.844167223563669911e-01 -5.875115294876380734e-01 -5.906028818135686809e-01 -5.936906572928624115e-01 -5.967747340254301314e-01 -5.998549902572035686e-01 -6.029313043849406917e-01 -6.060035549610274241e-01 -6.090716206982713654e-01 -6.121353804746906269e-01 -6.151947133382953403e-01 -6.182494985118623942e-01 -6.212996153977036196e-01 -6.243449435824273142e-01 -6.273853628416909967e-01 -6.304207531449482760e-01 -6.334509946601877273e-01 -6.364759677586625530e-01 -6.394955530196145821e-01 -6.425096312349880545e-01 -6.455180834141358570e-01 -6.485207907885174317e-01 -6.515176348163869147e-01 -6.545084971874736146e-01 -6.574932598276522766e-01 -6.604718049036046867e-01 -6.634440148274711735e-01 -6.664097722614933383e-01 -6.693689601226456842e-01 -6.723214615872584732e-01 -6.752671600956294817e-01 -6.782059393566253203e-01 -6.811376833522728713e-01 -6.840622763423389596e-01 -6.869796028689001410e-01 -6.898895477609005011e-01 -6.927919961386982406e-01 -6.956868334186012692e-01 -6.985739453173902547e-01 -7.014532178568313459e-01 -7.043245373681745747e-01 -7.071877904966421546e-01 -7.100428642059032347e-01 -7.128896457825364408e-01 -7.157280228404795386e-01 -7.185578833254663289e-01 -7.213791155194506644e-01 -7.241916080450160331e-01 -7.269952498697733745e-01 -7.297899303107439062e-01 -7.325755390387291843e-01 -7.353519660826662863e-01 -7.381191018339696708e-01 -7.408768370508577172e-01 -7.436250628626662751e-01 -7.463636707741457821e-01 -7.490925526697452819e-01 -7.518116008178803433e-01 -7.545207078751857699e-01 -7.572197668907533208e-01 -7.599086713103547774e-01 -7.625873149806479123e-01 -7.652555921533671368e-01 -7.679133974894983838e-01 -7.705606260634378923e-01 -7.731971733671345604e-01 -7.758229353142150897e-01 -7.784378082440940316e-01 -7.810416889260654028e-01 -7.836344745633783138e-01 -7.862160627972955007e-01 -7.887863517111338707e-01 -7.913452398342881722e-01 -7.938926261462365686e-01 -7.964284100805295585e-01 -7.989524915287592455e-01 -8.014647708445122865e-01 -8.039651488473026353e-01 -8.064535268264880763e-01 -8.089298065451671071e-01 -8.113938902440561707e-01 -8.138456806453501224e-01 -8.162850809565621590e-01 -8.187119948743448727e-01 -8.211263265882922102e-01 -8.235279807847220024e-01 -8.259168626504391764e-01 -8.282928778764780953e-01 -8.306559326618259131e-01 -8.330059337171259459e-01 -8.353427882683600592e-01 -8.376664040605122930e-01 -8.399766893612096164e-01 -8.422735529643444741e-01 -8.445569041936742405e-01 -8.468266529064024661e-01 -8.490827094967362543e-01 -8.513249848994244307e-01 -8.535533905932737309e-01 -8.557678386046427832e-01 -8.579682415109156635e-01 -8.601545124439534673e-01 -8.623265650935233451e-01 -8.644843137107056652e-01 -8.666276731112799725e-01 -8.687565586790869654e-01 -8.708708863693694902e-01 -8.729705727120909975e-01 -8.750555348152299073e-01 -8.771256903680519912e-01 -8.791809576443608831e-01 -8.812212555057239438e-01 -8.832465034046749208e-01 -8.852566213878946266e-01 -8.872515300993668586e-01 -8.892311507835116702e-01 -8.911954052882941069e-01 -8.931442160683095155e-01 -8.950775061878453176e-01 -8.969951993239176913e-01 -8.988972197692854937e-01 -9.007834924354383155e-01 -9.026539428555608868e-01 -9.045084971874738367e-01 -9.063470822165470286e-01 -9.081696253585921363e-01 -9.099760546627261304e-01 -9.117662988142137825e-01 -9.135402871372810818e-01 -9.152979495979065572e-01 -9.170392168065857330e-01 -9.187640200210708263e-01 -9.204722911490845760e-01 -9.221639627510074266e-01 -9.238389680425416195e-01 -9.254972408973460851e-01 -9.271387158496476877e-01 -9.287633280968261573e-01 -9.303710135019719329e-01 -9.319617085964179148e-01 -9.335353505822450160e-01 -9.350918773347628443e-01 -9.366312274049599651e-01 -9.381533400219316254e-01 -9.396581550952780582e-01 -9.411456132174766953e-01 -9.426156556662275143e-01 -9.440682244067721829e-01 -9.455032620941840049e-01 -9.469207120756318874e-01 -9.483205183926179949e-01 -9.497026257831856499e-01 -9.510669796841013657e-01 -9.524135262330096774e-01 -9.537422122705585537e-01 -9.550529853424978288e-01 -9.563457937017514343e-01 -9.576205863104587657e-01 -9.588773128419906255e-01 -9.601159236829353016e-01 -9.613363699350575553e-01 -9.625386034172290772e-01 -9.637225766673305216e-01 -9.648882429441256736e-01 -9.660355562291054188e-01 -9.671644712283059553e-01 -9.682749433740961420e-01 -9.693669288269369799e-01 -9.704403844771127829e-01 -9.714952679464322616e-01 -9.725315375899022952e-01 -9.735491524973720612e-01 -9.745480724951472995e-01 -9.755282581475767101e-01 -9.764896707586095959e-01 -9.774322723733215312e-01 -9.783560257794153836e-01 -9.792608945086879180e-01 -9.801468428384716436e-01 -9.810138357930430208e-01 -9.818618391450050220e-01 -9.826908194166369404e-01 -9.835007438812174430e-01 -9.842915805643155380e-01 -9.850632982450528985e-01 -9.858158664573368757e-01 -9.865492554910632039e-01 -9.872634363932887291e-01 -9.879583809693738283e-01 -9.886340617840968514e-01 -9.892904521627360337e-01 -9.899275261921235414e-01 -9.905452587216669880e-01 -9.911436253643443051e-01 -9.917226024976648624e-01 -9.922821672646028324e-01 -9.928222975744990242e-01 -9.933429721039341853e-01 -9.938441702975688852e-01 -9.943258723689569756e-01 -9.947880593013254114e-01 -9.952307128483255383e-01 -9.956538155347532948e-01 -9.960573506572389935e-01 -9.964413022849067936e-01 -9.968056552600040865e-01 -9.971503951984994618e-01 -9.974755084906502534e-01 -9.977809823015399981e-01 -9.980668045715863634e-01 -9.983329640170149899e-01 -9.985794501303070225e-01 -9.988062531806126687e-01 -9.990133642141358905e-01 -9.992007750544874556e-01 -9.993684783030087893e-01 -9.995164673390624088e-01 -9.996447363202946024e-01 -9.997532801828656890e-01 -9.998420946416499699e-01 -9.999111761904043716e-01 -9.999605221019081114e-01 -9.999901304280686132e-01 -1.000000000000000000e+00 -9.999901304280686132e-01 -9.999605221019081114e-01 -9.999111761904043716e-01 -9.998420946416499699e-01 -9.997532801828656890e-01 -9.996447363202946024e-01 -9.995164673390624088e-01 -9.993684783030087893e-01 -9.992007750544874556e-01 -9.990133642141358905e-01 -9.988062531806126687e-01 -9.985794501303070225e-01 -9.983329640170149899e-01 -9.980668045715863634e-01 -9.977809823015399981e-01 -9.974755084906502534e-01 -9.971503951984994618e-01 -9.968056552600040865e-01 -9.964413022849067936e-01 -9.960573506572389935e-01 -9.956538155347532948e-01 -9.952307128483255383e-01 -9.947880593013254114e-01 -9.943258723689569756e-01 -9.938441702975688852e-01 -9.933429721039340743e-01 -9.928222975744990242e-01 -9.922821672646028324e-01 -9.917226024976648624e-01 -9.911436253643443051e-01 -9.905452587216669880e-01 -9.899275261921235414e-01 -9.892904521627361447e-01 -9.886340617840968514e-01 -9.879583809693738283e-01 -9.872634363932885071e-01 -9.865492554910632039e-01 -9.858158664573368757e-01 -9.850632982450528985e-01 -9.842915805643155380e-01 -9.835007438812174430e-01 -9.826908194166369404e-01 -9.818618391450050220e-01 -9.810138357930430208e-01 -9.801468428384716436e-01 -9.792608945086879180e-01 -9.783560257794153836e-01 -9.774322723733215312e-01 -9.764896707586095959e-01 -9.755282581475767101e-01 -9.745480724951472995e-01 -9.735491524973720612e-01 -9.725315375899024062e-01 -9.714952679464321506e-01 -9.704403844771127829e-01 -9.693669288269369799e-01 -9.682749433740961420e-01 -9.671644712283059553e-01 -9.660355562291054188e-01 -9.648882429441256736e-01 -9.637225766673305216e-01 -9.625386034172290772e-01 -9.613363699350574443e-01 -9.601159236829353016e-01 -9.588773128419906255e-01 -9.576205863104587657e-01 -9.563457937017514343e-01 -9.550529853424978288e-01 -9.537422122705584426e-01 -9.524135262330098994e-01 -9.510669796841013657e-01 -9.497026257831854279e-01 -9.483205183926177728e-01 -9.469207120756318874e-01 -9.455032620941838939e-01 -9.440682244067721829e-01 -9.426156556662278474e-01 -9.411456132174766953e-01 -9.396581550952782802e-01 -9.381533400219318475e-01 -9.366312274049601871e-01 -9.350918773347629553e-01 -9.335353505822450160e-01 -9.319617085964179148e-01 -9.303710135019720440e-01 -9.287633280968262683e-01 -9.271387158496476877e-01 -9.254972408973460851e-01 -9.238389680425416195e-01 -9.221639627510076487e-01 -9.204722911490845760e-01 -9.187640200210708263e-01 -9.170392168065857330e-01 -9.152979495979065572e-01 -9.135402871372810818e-01 -9.117662988142137825e-01 -9.099760546627261304e-01 -9.081696253585921363e-01 -9.063470822165471397e-01 -9.045084971874738367e-01 -9.026539428555611089e-01 -9.007834924354383155e-01 -8.988972197692854937e-01 -8.969951993239178023e-01 -8.950775061878453176e-01 -8.931442160683095155e-01 -8.911954052882941069e-01 -8.892311507835118922e-01 -8.872515300993670806e-01 -8.852566213878947377e-01 -8.832465034046749208e-01 -8.812212555057239438e-01 -8.791809576443611052e-01 -8.771256903680519912e-01 -8.750555348152299073e-01 -8.729705727120912195e-01 -8.708708863693697122e-01 -8.687565586790869654e-01 -8.666276731112800835e-01 -8.644843137107058872e-01 -8.623265650935234561e-01 -8.601545124439534673e-01 -8.579682415109156635e-01 -8.557678386046427832e-01 -8.535533905932739529e-01 -8.513249848994246527e-01 -8.490827094967364763e-01 -8.468266529064025772e-01 -8.445569041936743515e-01 -8.422735529643444741e-01 -8.399766893612096164e-01 -8.376664040605122930e-01 -8.353427882683600592e-01 -8.330059337171259459e-01 -8.306559326618259131e-01 -8.282928778764783173e-01 -8.259168626504396205e-01 -8.235279807847220024e-01 -8.211263265882924323e-01 -8.187119948743448727e-01 -8.162850809565623811e-01 -8.138456806453501224e-01 -8.113938902440562817e-01 -8.089298065451674402e-01 -8.064535268264882983e-01 -8.039651488473028573e-01 -8.014647708445122865e-01 -7.989524915287594675e-01 -7.964284100805295585e-01 -7.938926261462365686e-01 -7.913452398342879501e-01 -7.887863517111338707e-01 -7.862160627972956117e-01 -7.836344745633782027e-01 -7.810416889260655138e-01 -7.784378082440939206e-01 -7.758229353142153117e-01 -7.731971733671344493e-01 -7.705606260634378923e-01 -7.679133974894981618e-01 -7.652555921533670258e-01 -7.625873149806475793e-01 -7.599086713103547774e-01 -7.572197668907533208e-01 -7.545207078751855478e-01 -7.518116008178805654e-01 -7.490925526697452819e-01 -7.463636707741457821e-01 -7.436250628626660530e-01 -7.408768370508576062e-01 -7.381191018339693377e-01 -7.353519660826662863e-01 -7.325755390387292953e-01 -7.297899303107437952e-01 -7.269952498697733745e-01 -7.241916080450160331e-01 -7.213791155194507754e-01 -7.185578833254663289e-01 -7.157280228404795386e-01 -7.128896457825361077e-01 -7.100428642059030127e-01 -7.071877904966422657e-01 -7.043245373681743526e-01 -7.014532178568313459e-01 -6.985739453173901437e-01 -6.956868334186012692e-01 -6.927919961386980185e-01 -6.898895477609005011e-01 -6.869796028689000300e-01 -6.840622763423388486e-01 -6.811376833522728713e-01 -6.782059393566252092e-01 -6.752671600956294817e-01 -6.723214615872583622e-01 -6.693689601226456842e-01 -6.664097722614931163e-01 -6.634440148274711735e-01 -6.604718049036044647e-01 -6.574932598276523876e-01 -6.545084971874737256e-01 -6.515176348163868036e-01 -6.485207907885174317e-01 -6.455180834141357460e-01 -6.425096312349884986e-01 -6.394955530196148041e-01 -6.364759677586629971e-01 -6.334509946601878383e-01 -6.304207531449488311e-01 -6.273853628416912187e-01 -6.243449435824276472e-01 -6.212996153977037306e-01 -6.182494985118625053e-01 -6.151947133382956734e-01 -6.121353804746907379e-01 -6.090716206982716985e-01 -6.060035549610274241e-01 -6.029313043849410247e-01 -5.998549902572035686e-01 -5.967747340254304644e-01 -5.936906572928623005e-01 -5.906028818135689029e-01 -5.875115294876379624e-01 -5.844167223563671021e-01 -5.813185825974421794e-01 -5.782172325201154761e-01 -5.751127945603787817e-01 -5.720053912761261516e-01 -5.688951453423192195e-01 -5.657821795461412950e-01 -5.626666167821522402e-01 -5.595485800474347959e-01 -5.564281924367410204e-01 -5.533055771376302889e-01 -5.501808574256075168e-01 -5.470541566592573846e-01 -5.439255982753716800e-01 -5.407953057840789723e-01 -5.376634027639664026e-01 -5.345300128572030296e-01 -5.313952597646566245e-01 -5.282592672410123535e-01 -5.251221590898850211e-01 -5.219840591589325340e-01 -5.188450913349674787e-01 -5.157053795390641460e-01 -5.125650477216689982e-01 -5.094242198577040304e-01 -5.062830199416764598e-01 -5.031415719827793120e-01 -5.000000000000001110e-01 -4.968584280172208545e-01 -4.937169800583237622e-01 -4.905757801422960807e-01 -4.874349522783312239e-01 -4.842946204609360206e-01 -4.811549086650326323e-01 -4.780159408410676880e-01 -4.748778409101150899e-01 -4.717407327589878685e-01 -4.686047402353435976e-01 -4.654699871427971369e-01 -4.623365972360338194e-01 -4.592046942159211942e-01 -4.560744017246285420e-01 -4.529458433407427265e-01 -4.498191425743926497e-01 -4.466944228623699331e-01 -4.435718075632592017e-01 -4.404514199525653706e-01 -4.373333832178479263e-01 -4.342178204538589270e-01 -4.311048546576808915e-01 -4.279946087238740704e-01 -4.248872054396213849e-01 -4.217827674798846904e-01 -4.186814174025580426e-01 -4.155832776436331200e-01 -4.124884705123622042e-01 -4.093971181864312636e-01 -4.063093427071379216e-01 -4.032252659745698131e-01 -4.001450097427966535e-01 -3.970686956150591973e-01 -3.939964450389727424e-01 -3.909283793017285236e-01 -3.878646195253094286e-01 -3.848052866617044376e-01 -3.817505014881376613e-01 -3.787003846022964360e-01 -3.756550564175725193e-01 -3.726146371583090033e-01 -3.695792468550513910e-01 -3.665490053398122727e-01 -3.635240322413371694e-01 -3.605044469803854179e-01 -3.574903687650116679e-01 -3.544819165858640320e-01 -3.514792092114826794e-01 -3.484823651836129188e-01 -3.454915028125263854e-01 -3.425067401723474458e-01 -3.395281950963952577e-01 -3.365559851725286045e-01 -3.335902277385066617e-01 -3.306310398773540937e-01 -3.276785384127414158e-01 -3.247328399043706293e-01 -3.217940606433745132e-01 -3.188623166477272397e-01 -3.159377236576608183e-01 -3.130203971310998035e-01 -3.101104522390992213e-01 -3.072080038613017039e-01 -3.043131665813985087e-01 -3.014260546826096343e-01 -2.985467821431687652e-01 -2.956754626318253698e-01 -2.928122095033579564e-01 -2.899571357940966543e-01 -2.871103542174636702e-01 -2.842719771595202394e-01 -2.814421166745335046e-01 -2.786208844805489471e-01 -2.758083919549838003e-01 -2.730047501302266810e-01 -2.702100696892559273e-01 -2.674244609612708712e-01 -2.646480339173335472e-01 -2.618808981660304402e-01 -2.591231629491421162e-01 -2.563749371373337804e-01 -2.536363292258538849e-01 -2.509074473302548292e-01 -2.481883991821196567e-01 -2.454792921248145632e-01 -2.427802331092467902e-01 -2.400913286896454168e-01 -2.374126850193525040e-01 -2.347444078466331130e-01 -2.320866025105019770e-01 -2.294393739365621077e-01 -2.268028266328657172e-01 -2.241770646857848825e-01 -2.215621917559061904e-01 -2.189583110739346805e-01 -2.163655254366218805e-01 -2.137839372027044993e-01 -2.112136482888663236e-01 -2.086547601657122442e-01 -2.061073738537635425e-01 -2.035715899194706080e-01 -2.010475084712405602e-01 -1.985352291554878246e-01 -1.960348511526973092e-01 -1.935464731735118959e-01 -1.910701934548327818e-01 -1.886061097559438571e-01 -1.861543193546500441e-01 -1.837149190434377855e-01 -1.812880051256553771e-01 -1.788736734117078453e-01 -1.764720192152779976e-01 -1.740831373495606016e-01 -1.717071221235218770e-01 -1.693440673381740036e-01 -1.669940662828742761e-01 -1.646572117316401629e-01 -1.623335959394878181e-01 -1.600233106387906057e-01 -1.577264470356556925e-01 -1.554430958063259538e-01 -1.531733470935974506e-01 -1.509172905032638012e-01 -1.486750151005753473e-01 -1.464466094067263247e-01 -1.442321613953575221e-01 -1.420317584890844753e-01 -1.398454875560466992e-01 -1.376734349064766549e-01 -1.355156862892944181e-01 -1.333723268887199720e-01 -1.312434413209131179e-01 -1.291291136306303433e-01 -1.270294272879090025e-01 -1.249444651847704119e-01 -1.228743096319480643e-01 -1.208190423556391585e-01 -1.187787444942760007e-01 -1.167534965953251902e-01 -1.147433786121053179e-01 -1.127484699006330998e-01 -1.107688492164881772e-01 -1.088045947117059348e-01 -1.068557839316906510e-01 -1.049224938121548073e-01 -1.030048006760824197e-01 -1.011027802307144785e-01 -9.921650756456176778e-02 -9.734605714443890501e-02 -9.549150281252624661e-02 -9.365291778345290197e-02 -9.183037464140793305e-02 -9.002394533727396675e-02 -8.823370118578624521e-02 -8.645971286271916800e-02 -8.470205040209359548e-02 -8.296078319341440577e-02 -8.123597997892903488e-02 -7.952770885091546560e-02 -7.783603724899237908e-02 -7.616103195745833887e-02 -7.450275910265394264e-02 -7.286128415035239558e-02 -7.123667190317387043e-02 -6.962898649802808093e-02 -6.803829140358244598e-02 -6.646464941775491464e-02 -6.490812266523718344e-02 -6.336877259503978510e-02 -6.184665997806816640e-02 -6.034184490472174062e-02 -5.885438678252330469e-02 -5.738434433377247179e-02 -5.593177559322771303e-02 -5.449673790581603672e-02 -5.307928792436806403e-02 -5.167948160738210228e-02 -5.029737421681435700e-02 -4.893302031589858575e-02 -4.758647376699011444e-02 -4.625778772944143247e-02 -4.494701465750217118e-02 -4.365420629824853793e-02 -4.237941368954127597e-02 -4.112268715800928426e-02 -3.988407631706478162e-02 -3.866363006494242388e-02 -3.746139658277095746e-02 -3.627742333266925634e-02 -3.511175705587420148e-02 -3.396444377089454653e-02 -3.283552877169391288e-02 -3.172505662590380943e-02 -3.063307117306288824e-02 -2.955961552288726563e-02 -2.850473205356760659e-02 -2.746846241009755912e-02 -2.645084750262772719e-02 -2.545192750485270050e-02 -2.447174185242324135e-02 -2.351032924139054292e-02 -2.256772762667843060e-02 -2.164397422058470313e-02 -2.073910549131204387e-02 -1.985315716152832866e-02 -1.898616420695698956e-02 -1.813816085499507860e-02 -1.730918058336302495e-02 -1.649925611878251541e-02 -1.570841943568445503e-02 -1.493670175494710324e-02 -1.418413354266298380e-02 -1.345074450893671801e-02 -1.273656360671149984e-02 -1.204161903062637984e-02 -1.136593821590326132e-02 -1.070954783726399753e-02 -1.007247380787648638e-02 -9.454741278333008564e-03 -8.856374635655587385e-03 -8.277397502335205257e-03 -7.717832735397246562e-03 -7.177702425501049539e-03 -6.657027896066045405e-03 -6.155829702431123499e-03 -5.674127631043058249e-03 -5.211940698674534002e-03 -4.769287151674420945e-03 -4.346184465246665310e-03 -3.942649342761090671e-03 -3.558697715093159155e-03 -3.194344739995816362e-03 -2.849604801500574616e-03 -2.524491509349872410e-03 -2.219017698460000985e-03 -1.933195428413718962e-03 -1.667035982985024412e-03 -1.420549869692992653e-03 -1.193746819387333461e-03 -9.866357858641615353e-04 -7.992249455125140581e-04 -6.315216969912583423e-04 -4.835326609376300430e-04 -3.552636797053673788e-04 -2.467198171342090997e-04 -1.579053583499612364e-04 -8.882380959548627237e-05 -3.947789809190699632e-05 -9.869571931439562087e-06 diff --git a/examples/icub_vor_examples/spinn_gym_examples/spynnaker.cfg b/examples/icub_vor_examples/spinn_gym_examples/spynnaker.cfg deleted file mode 100644 index ce534da0..00000000 --- a/examples/icub_vor_examples/spinn_gym_examples/spynnaker.cfg +++ /dev/null @@ -1,4 +0,0 @@ -[Mapping] - -# ICubVor doesn't implement delay extensions, so avoid DelaySupportAdder -delay_support_adder = None \ No newline at end of file From 8027dfc1ff0b34179ef2c38bf8fbe5b4fca7c280 Mon Sep 17 00:00:00 2001 From: Andrew Gait Date: Fri, 4 Mar 2022 12:34:03 +0000 Subject: [PATCH 15/28] Remove duplicated example --- ...e_cell_test.pysingle_purkinje_cell_test.py | 116 ------------------ 1 file changed, 116 deletions(-) delete mode 100644 examples/icub_vor_examples/pb_single_purkinje_cell_test.pysingle_purkinje_cell_test.py diff --git a/examples/icub_vor_examples/pb_single_purkinje_cell_test.pysingle_purkinje_cell_test.py b/examples/icub_vor_examples/pb_single_purkinje_cell_test.pysingle_purkinje_cell_test.py deleted file mode 100644 index 9a0bc4b1..00000000 --- a/examples/icub_vor_examples/pb_single_purkinje_cell_test.pysingle_purkinje_cell_test.py +++ /dev/null @@ -1,116 +0,0 @@ -# Copyright (c) 2019-2021 The University of Manchester -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -from __future__ import print_function -import spynnaker8 as p -# import numpy -# import math -# import unittest -from pyNN.utility.plotting import Figure, Panel -import matplotlib.pyplot as plt - -p.setup(1, min_delay=1, max_delay=15) # simulation timestep (ms) -runtime = 500 - -# Post-synapse population -neuron_params = { - "v_thresh": -50, - "v_reset": -70, - "v_rest": -65, - "i_offset": 0 # DC input -} - -# Learning parameters -min_weight = 0 -max_weight = 0.1 -pot_alpha = 0.01 -t_peak = 100 -initial_weight = 0.05 -plastic_delay = 4 - -purkinje_cell = p.Population( - 1, # number of neurons - p.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model - label="Purkinje Cell" # identifier - ) - -# Spike source to send spike via synapse -spike_times = [50, 150, 270] - -granular_cell = p.Population( - 1, # number of sources - p.SpikeSourceArray, # source type - {'spike_times': spike_times}, # source spike times - label="src1" # identifier - ) - -# Spike source to send spike via synapse from climbing fibre -spike_times_2 = [100, 104, 107, 246] -climbing_fibre = p.Population( - 1, # number of sources - p.SpikeSourceArray, # source type - {'spike_times': spike_times_2}, # source spike times - label="src2" # identifier - ) - -# Create projection from GC to PC -pfpc_plas = p.STDPMechanism( - timing_dependence=p.extra_models.TimingDependencePFPC(t_peak=t_peak), - weight_dependence=p.extra_models.WeightDependencePFPC(w_min=min_weight, - w_max=max_weight, - pot_alpha=pot_alpha), - weight=initial_weight, delay=plastic_delay) - -synapse_pfpc = p.Projection( - granular_cell, purkinje_cell, p.AllToAllConnector(), - synapse_type=pfpc_plas, receptor_type="excitatory") - -# Create projection from CF to PC -synapse = p.Projection( - climbing_fibre, purkinje_cell, p.OneToOneConnector(), - p.StaticSynapse(weight=0.0, delay=1), receptor_type="excitatory") - -granular_cell.record('spikes') -climbing_fibre.record('spikes') -purkinje_cell.record("all") - -p.run(runtime) - -granluar_cell_spikes = granular_cell.get_data('spikes') -climbing_fibre_spikes = climbing_fibre.get_data('spikes') -purkinje_data = purkinje_cell.get_data() - -pf_weights = synapse_pfpc.get('weight', 'list', with_address=False) -print(pf_weights) - -# Plot -F = Figure( - # plot data for postsynaptic neuron - Panel(granluar_cell_spikes.segments[0].spiketrains, - yticks=True, markersize=2, xlim=(0, runtime)), - Panel(climbing_fibre_spikes.segments[0].spiketrains, - yticks=True, markersize=2, xlim=(0, runtime)), - Panel(purkinje_data.segments[0].filter(name='v')[0], - ylabel="Membrane potential (mV)", - data_labels=[purkinje_cell.label], yticks=True, xlim=(0, runtime)), - Panel(purkinje_data.segments[0].filter(name='gsyn_exc')[0], - ylabel="gsyn excitatory (mV)", - data_labels=[purkinje_cell.label], yticks=True, xlim=(0, runtime)), - Panel(purkinje_data.segments[0].spiketrains, - yticks=True, markersize=2, xlim=(0, runtime)), -) - -plt.show() -p.end() From 94e2efa7cb3b875169e1cf2c78c261946b28da0f Mon Sep 17 00:00:00 2001 From: Andrew Gait Date: Fri, 4 Mar 2022 14:34:04 +0000 Subject: [PATCH 16/28] Skip a few more scripts for now --- integration_tests/script_builder.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/integration_tests/script_builder.py b/integration_tests/script_builder.py index 7be948f9..24d3107e 100644 --- a/integration_tests/script_builder.py +++ b/integration_tests/script_builder.py @@ -27,6 +27,9 @@ def build_scripts(self): # These scripts raise a SkipTest with the reasons given exceptions = {} exceptions["pushbot_ethernet_example.py"] = "Needs a physical pushbot" + exceptions["dataflow.py"] = "Vertex tested elsewhere" + exceptions["receptive_fields_for_motion.py"] = "Duplication" + exceptions["cerebellum.py"] = "Script has no run stage" # For branches these raise a SkipTest quoting the time given # For cron and manual runs these just and a warning From ece220d53100d67fcd087165703162ce68d01c64 Mon Sep 17 00:00:00 2001 From: Andrew Gait Date: Fri, 4 Mar 2022 16:36:08 +0000 Subject: [PATCH 17/28] Take out block=False --- examples/icub_vor_examples/cerebellum_tb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/icub_vor_examples/cerebellum_tb.py b/examples/icub_vor_examples/cerebellum_tb.py index 0d301fb6..f840caae 100644 --- a/examples/icub_vor_examples/cerebellum_tb.py +++ b/examples/icub_vor_examples/cerebellum_tb.py @@ -495,7 +495,7 @@ def process_VN_spiketrains(VN_spikes, t_start): ylabel="Membrane potential (mV)", yticks=True, xlim=(0, total_runtime)) ) -plt.show(block=False) +plt.show() plt.figure() plt.plot(mfvn_weights, From ada0dfd9c2499b1a4fbac992027a51575174ce71 Mon Sep 17 00:00:00 2001 From: Andrew Gait Date: Mon, 7 Mar 2022 10:59:18 +0000 Subject: [PATCH 18/28] Exclude more "examples" --- integration_tests/script_builder.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/integration_tests/script_builder.py b/integration_tests/script_builder.py index 24d3107e..9cb2b26c 100644 --- a/integration_tests/script_builder.py +++ b/integration_tests/script_builder.py @@ -30,6 +30,8 @@ def build_scripts(self): exceptions["dataflow.py"] = "Vertex tested elsewhere" exceptions["receptive_fields_for_motion.py"] = "Duplication" exceptions["cerebellum.py"] = "Script has no run stage" + exceptions["test_mfvn_lut.py"] = "Only a test (no machine needed)" + exceptions["test_pfpc_lut.py"] = "Only a test (no machine needed)" # For branches these raise a SkipTest quoting the time given # For cron and manual runs these just and a warning From 2a3c2870bdb7c20857263a30a6f1a56c86632870 Mon Sep 17 00:00:00 2001 From: Andrew Gait Date: Fri, 17 Jun 2022 14:01:21 +0100 Subject: [PATCH 19/28] Replace spynnaker8 with pynn.spinnaker --- examples/icub_vor_examples/cerebellum.py | 2 +- examples/icub_vor_examples/cerebellum_tb.py | 2 +- examples/icub_vor_examples/dataflow.py | 2 +- examples/icub_vor_examples/pb_cerebellum_tb.py | 2 +- examples/icub_vor_examples/receptive_fields_for_motion.py | 2 +- examples/icub_vor_examples/single_purkinje_cell_pf_windowing.py | 2 +- .../icub_vor_examples/single_purkinje_cell_potentiation_test.py | 2 +- examples/icub_vor_examples/single_purkinje_cell_test.py | 2 +- .../icub_vor_examples/single_vestibular_nuclei_mf_windowing.py | 2 +- .../single_vestibular_nuclei_mf_windowing_3_spikes.py | 2 +- .../single_vestibular_nuclei_potentiation_test.py | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/examples/icub_vor_examples/cerebellum.py b/examples/icub_vor_examples/cerebellum.py index f11091bc..7197bb3d 100644 --- a/examples/icub_vor_examples/cerebellum.py +++ b/examples/icub_vor_examples/cerebellum.py @@ -14,7 +14,7 @@ # along with this program. If not, see . # import socket -import spynnaker8 as sim +import pyNN.spiNNaker as sim import numpy as np # import logging import matplotlib.pyplot as plt diff --git a/examples/icub_vor_examples/cerebellum_tb.py b/examples/icub_vor_examples/cerebellum_tb.py index f840caae..d2dbf2be 100644 --- a/examples/icub_vor_examples/cerebellum_tb.py +++ b/examples/icub_vor_examples/cerebellum_tb.py @@ -15,7 +15,7 @@ from __future__ import print_function # for python3 printing in python2 # import socket -import spynnaker8 as sim +import pyNN.spiNNaker as sim import numpy as np # import logging import matplotlib.pyplot as plt diff --git a/examples/icub_vor_examples/dataflow.py b/examples/icub_vor_examples/dataflow.py index 1a78274e..d91a77e7 100644 --- a/examples/icub_vor_examples/dataflow.py +++ b/examples/icub_vor_examples/dataflow.py @@ -14,7 +14,7 @@ # along with this program. If not, see . # import socket -import spynnaker8 as sim +import pyNN.spiNNaker as sim # import numpy as np # import logging # import matplotlib.pyplot as plt diff --git a/examples/icub_vor_examples/pb_cerebellum_tb.py b/examples/icub_vor_examples/pb_cerebellum_tb.py index 2656ac4a..05177c07 100644 --- a/examples/icub_vor_examples/pb_cerebellum_tb.py +++ b/examples/icub_vor_examples/pb_cerebellum_tb.py @@ -14,7 +14,7 @@ # along with this program. If not, see . from __future__ import print_function -import spynnaker8 as sim +import pyNN.spiNNaker as sim import numpy as np # import logging import pylab as plt diff --git a/examples/icub_vor_examples/receptive_fields_for_motion.py b/examples/icub_vor_examples/receptive_fields_for_motion.py index d04136eb..c813dc95 100644 --- a/examples/icub_vor_examples/receptive_fields_for_motion.py +++ b/examples/icub_vor_examples/receptive_fields_for_motion.py @@ -16,7 +16,7 @@ # along with this program. If not, see . # import socket -import spynnaker8 as sim +import pyNN.spiNNaker as sim # import numpy as np # import logging import matplotlib.pyplot as plt diff --git a/examples/icub_vor_examples/single_purkinje_cell_pf_windowing.py b/examples/icub_vor_examples/single_purkinje_cell_pf_windowing.py index 91c2b41e..0491fed3 100644 --- a/examples/icub_vor_examples/single_purkinje_cell_pf_windowing.py +++ b/examples/icub_vor_examples/single_purkinje_cell_pf_windowing.py @@ -14,7 +14,7 @@ # along with this program. If not, see . from __future__ import print_function -import spynnaker8 as p +import pyNN.spiNNaker as p # import numpy # import math # import unittest diff --git a/examples/icub_vor_examples/single_purkinje_cell_potentiation_test.py b/examples/icub_vor_examples/single_purkinje_cell_potentiation_test.py index 809835fb..cd6ec141 100644 --- a/examples/icub_vor_examples/single_purkinje_cell_potentiation_test.py +++ b/examples/icub_vor_examples/single_purkinje_cell_potentiation_test.py @@ -14,7 +14,7 @@ # along with this program. If not, see . from __future__ import print_function -import spynnaker8 as p +import pyNN.spiNNaker as p # import numpy # import math # import unittest diff --git a/examples/icub_vor_examples/single_purkinje_cell_test.py b/examples/icub_vor_examples/single_purkinje_cell_test.py index fa7c28d9..c9078056 100644 --- a/examples/icub_vor_examples/single_purkinje_cell_test.py +++ b/examples/icub_vor_examples/single_purkinje_cell_test.py @@ -14,7 +14,7 @@ # along with this program. If not, see . from __future__ import print_function -import spynnaker8 as p +import pyNN.spiNNaker as p # import numpy # import math # import unittest diff --git a/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing.py b/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing.py index 26d1bf2b..4f6c7dc2 100644 --- a/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing.py +++ b/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing.py @@ -14,7 +14,7 @@ # along with this program. If not, see . from __future__ import print_function -import spynnaker8 as p +import pyNN.spiNNaker as p # import numpy # import math # import unittest diff --git a/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing_3_spikes.py b/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing_3_spikes.py index cc3c23ca..cc4778a3 100644 --- a/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing_3_spikes.py +++ b/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing_3_spikes.py @@ -14,7 +14,7 @@ # along with this program. If not, see . from __future__ import print_function -import spynnaker8 as p +import pyNN.spiNNaker as p # import numpy # import math # import unittest diff --git a/examples/icub_vor_examples/single_vestibular_nuclei_potentiation_test.py b/examples/icub_vor_examples/single_vestibular_nuclei_potentiation_test.py index 000a1766..759b5ba7 100644 --- a/examples/icub_vor_examples/single_vestibular_nuclei_potentiation_test.py +++ b/examples/icub_vor_examples/single_vestibular_nuclei_potentiation_test.py @@ -14,7 +14,7 @@ # along with this program. If not, see . from __future__ import print_function -import spynnaker8 as p +import pyNN.spiNNaker as p # import numpy # import math # import unittest From 0b9aa1de636b5db87e8fab450c17c074d806465f Mon Sep 17 00:00:00 2001 From: Andrew Gait Date: Wed, 14 Sep 2022 15:11:45 +0100 Subject: [PATCH 20/28] flake8 --- examples/icub_vor_examples/cerebellum.py | 4 ++-- examples/icub_vor_examples/cerebellum_tb.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/icub_vor_examples/cerebellum.py b/examples/icub_vor_examples/cerebellum.py index 7197bb3d..b8e15561 100644 --- a/examples/icub_vor_examples/cerebellum.py +++ b/examples/icub_vor_examples/cerebellum.py @@ -389,10 +389,10 @@ def compute_D_error(kd, head_velocity, eye_velocity): GC_lower_index = GC_medium_index - 40 GC_upper_index = GC_medium_index + 60 - if(GC_lower_index < 0): + if (GC_lower_index < 0): GC_lower_index = 0 - elif(GC_upper_index > num_GC_neurons): + elif (GC_upper_index > num_GC_neurons): GC_upper_index = num_GC_neurons for j in range(GC_medium_index - GC_lower_index): diff --git a/examples/icub_vor_examples/cerebellum_tb.py b/examples/icub_vor_examples/cerebellum_tb.py index d2dbf2be..23486ee4 100644 --- a/examples/icub_vor_examples/cerebellum_tb.py +++ b/examples/icub_vor_examples/cerebellum_tb.py @@ -298,10 +298,10 @@ def process_VN_spiketrains(VN_spikes, t_start): GC_lower_index = GC_medium_index - 40 GC_upper_index = GC_medium_index + 60 - if(GC_lower_index < 0): + if (GC_lower_index < 0): GC_lower_index = 0 - elif(GC_upper_index > num_GC_neurons): + elif (GC_upper_index > num_GC_neurons): GC_upper_index = num_GC_neurons for j in range(GC_medium_index - GC_lower_index): From a93a280b28da68334f345fe1034ca58e656b5cfa Mon Sep 17 00:00:00 2001 From: Andrew Gait Date: Mon, 26 Sep 2022 09:25:11 +0100 Subject: [PATCH 21/28] Update exceptions in integration tests --- integration_tests/script_builder.py | 1 + 1 file changed, 1 insertion(+) diff --git a/integration_tests/script_builder.py b/integration_tests/script_builder.py index 9cb2b26c..31af53e7 100644 --- a/integration_tests/script_builder.py +++ b/integration_tests/script_builder.py @@ -30,6 +30,7 @@ def build_scripts(self): exceptions["dataflow.py"] = "Vertex tested elsewhere" exceptions["receptive_fields_for_motion.py"] = "Duplication" exceptions["cerebellum.py"] = "Script has no run stage" + exceptions["cerebellum_tb.py"] = "Old version of pb_cerebellum_tb.py" exceptions["test_mfvn_lut.py"] = "Only a test (no machine needed)" exceptions["test_pfpc_lut.py"] = "Only a test (no machine needed)" From 2a8646fa47c73ee432b0f4d15123da618856a5ce Mon Sep 17 00:00:00 2001 From: Andrew Gait Date: Wed, 28 Sep 2022 09:26:55 +0100 Subject: [PATCH 22/28] Move plotting into examples --- examples/icub_vor_examples/test_mfvn_lut.py | 21 ++++++++++------- examples/icub_vor_examples/test_pfpc_lut.py | 26 ++++++++++++++------- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/examples/icub_vor_examples/test_mfvn_lut.py b/examples/icub_vor_examples/test_mfvn_lut.py index fc30c9db..9d2f235d 100644 --- a/examples/icub_vor_examples/test_mfvn_lut.py +++ b/examples/icub_vor_examples/test_mfvn_lut.py @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2021 The University of Manchester +# Copyright (c) 2019-2022 The University of Manchester # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -13,14 +13,19 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from spynnaker.pyNN.models.neuron.plasticity.stdp.common import write_mfvn_lut +import matplotlib.pyplot as plt +from spynnaker.pyNN.models.neuron.plasticity.stdp.common \ + import write_mfvn_lut beta = 10 sigma = 200 -write_mfvn_lut(spec=None, - sigma=sigma, - beta=beta, - lut_size=256, - shift=0, - time_probe=22) +_comp_times, out_float, plot_times = write_mfvn_lut( + spec=None, sigma=sigma, beta=beta, lut_size=256, shift=0, time_probe=22, + kernel_scaling=0.8) + +plt.plot(plot_times, out_float, label='float') +# plt.plot(t,out_fixed, label='fixed') +plt.legend() +plt.title("mf-VN LUT") +plt.savefig("figures/write_mfvn_lut.png") diff --git a/examples/icub_vor_examples/test_pfpc_lut.py b/examples/icub_vor_examples/test_pfpc_lut.py index 01e6a070..8796d867 100644 --- a/examples/icub_vor_examples/test_pfpc_lut.py +++ b/examples/icub_vor_examples/test_pfpc_lut.py @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2021 The University of Manchester +# Copyright (c) 2019-2022 The University of Manchester # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -13,14 +13,22 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from spynnaker.pyNN.models.neuron.plasticity.stdp.common import write_pfpc_lut -# import math +import matplotlib.pyplot as plt +from spynnaker.pyNN.models.neuron.plasticity.stdp.common \ + import write_pfpc_lut -# sin_power=20 t_peak = 100 -write_pfpc_lut(spec=None, - peak_time=t_peak, - lut_size=256, - shift=0, - time_probe=t_peak) +_comp_times, out_float, out_fixed, t = write_pfpc_lut( + spec=None, peak_time=t_peak, lut_size=256, shift=0, time_probe=t_peak, + kernel_scaling=0.8) + +plt.plot(t, out_float, label='float') +plt.legend() +plt.title("pf-PC LUT") +plt.savefig("figures/write_pfpc_lut.png") + +plt.plot(t, out_fixed, label='fixed int16') +plt.legend() +plt.title("pf-PC LUT") +plt.savefig("figures/write_pfpc_lut_final_exp_fix.png") From 47ca784b689f941f163876b645906b262baf562a Mon Sep 17 00:00:00 2001 From: Andrew Gait Date: Mon, 15 May 2023 17:04:37 +0100 Subject: [PATCH 23/28] Update license --- examples/icub_vor_examples/cerebellum.py | 21 +++++++++---------- examples/icub_vor_examples/cerebellum_tb.py | 21 +++++++++---------- examples/icub_vor_examples/dataflow.py | 21 +++++++++---------- .../icub_vor_examples/pb_cerebellum_tb.py | 21 +++++++++---------- .../receptive_fields_for_motion.py | 21 +++++++++---------- .../single_purkinje_cell_pf_windowing.py | 21 +++++++++---------- .../single_purkinje_cell_potentiation_test.py | 21 +++++++++---------- .../single_purkinje_cell_test.py | 21 +++++++++---------- .../single_vestibular_nuclei_mf_windowing.py | 21 +++++++++---------- ...vestibular_nuclei_mf_windowing_3_spikes.py | 21 +++++++++---------- ...gle_vestibular_nuclei_potentiation_test.py | 21 +++++++++---------- examples/icub_vor_examples/test_mfvn_lut.py | 21 +++++++++---------- examples/icub_vor_examples/test_pfpc_lut.py | 21 +++++++++---------- 13 files changed, 130 insertions(+), 143 deletions(-) diff --git a/examples/icub_vor_examples/cerebellum.py b/examples/icub_vor_examples/cerebellum.py index b8e15561..3090001a 100644 --- a/examples/icub_vor_examples/cerebellum.py +++ b/examples/icub_vor_examples/cerebellum.py @@ -1,17 +1,16 @@ -# Copyright (c) 2019-2021 The University of Manchester +# Copyright (c) 2021 The University of Manchester # -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# https://www.apache.org/licenses/LICENSE-2.0 # -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. # import socket import pyNN.spiNNaker as sim diff --git a/examples/icub_vor_examples/cerebellum_tb.py b/examples/icub_vor_examples/cerebellum_tb.py index 23486ee4..6ecc0377 100644 --- a/examples/icub_vor_examples/cerebellum_tb.py +++ b/examples/icub_vor_examples/cerebellum_tb.py @@ -1,17 +1,16 @@ -# Copyright (c) 2019-2021 The University of Manchester +# Copyright (c) 2021 The University of Manchester # -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# https://www.apache.org/licenses/LICENSE-2.0 # -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. from __future__ import print_function # for python3 printing in python2 # import socket diff --git a/examples/icub_vor_examples/dataflow.py b/examples/icub_vor_examples/dataflow.py index d91a77e7..9088c037 100644 --- a/examples/icub_vor_examples/dataflow.py +++ b/examples/icub_vor_examples/dataflow.py @@ -1,17 +1,16 @@ -# Copyright (c) 2019-2021 The University of Manchester +# Copyright (c) 2021 The University of Manchester # -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# https://www.apache.org/licenses/LICENSE-2.0 # -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. # import socket import pyNN.spiNNaker as sim diff --git a/examples/icub_vor_examples/pb_cerebellum_tb.py b/examples/icub_vor_examples/pb_cerebellum_tb.py index 05177c07..608b99a1 100644 --- a/examples/icub_vor_examples/pb_cerebellum_tb.py +++ b/examples/icub_vor_examples/pb_cerebellum_tb.py @@ -1,17 +1,16 @@ -# Copyright (c) 2019-2021 The University of Manchester +# Copyright (c) 2021 The University of Manchester # -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# https://www.apache.org/licenses/LICENSE-2.0 # -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. from __future__ import print_function import pyNN.spiNNaker as sim diff --git a/examples/icub_vor_examples/receptive_fields_for_motion.py b/examples/icub_vor_examples/receptive_fields_for_motion.py index c813dc95..4b6fade0 100644 --- a/examples/icub_vor_examples/receptive_fields_for_motion.py +++ b/examples/icub_vor_examples/receptive_fields_for_motion.py @@ -1,19 +1,18 @@ #!usr/bin/python -# Copyright (c) 2019-2021 The University of Manchester +# Copyright (c) 2021 The University of Manchester # -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# https://www.apache.org/licenses/LICENSE-2.0 # -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. # import socket import pyNN.spiNNaker as sim diff --git a/examples/icub_vor_examples/single_purkinje_cell_pf_windowing.py b/examples/icub_vor_examples/single_purkinje_cell_pf_windowing.py index 0491fed3..666da87f 100644 --- a/examples/icub_vor_examples/single_purkinje_cell_pf_windowing.py +++ b/examples/icub_vor_examples/single_purkinje_cell_pf_windowing.py @@ -1,17 +1,16 @@ -# Copyright (c) 2019-2021 The University of Manchester +# Copyright (c) 2021 The University of Manchester # -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# https://www.apache.org/licenses/LICENSE-2.0 # -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. from __future__ import print_function import pyNN.spiNNaker as p diff --git a/examples/icub_vor_examples/single_purkinje_cell_potentiation_test.py b/examples/icub_vor_examples/single_purkinje_cell_potentiation_test.py index cd6ec141..372708a7 100644 --- a/examples/icub_vor_examples/single_purkinje_cell_potentiation_test.py +++ b/examples/icub_vor_examples/single_purkinje_cell_potentiation_test.py @@ -1,17 +1,16 @@ -# Copyright (c) 2019-2021 The University of Manchester +# Copyright (c) 2021 The University of Manchester # -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# https://www.apache.org/licenses/LICENSE-2.0 # -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. from __future__ import print_function import pyNN.spiNNaker as p diff --git a/examples/icub_vor_examples/single_purkinje_cell_test.py b/examples/icub_vor_examples/single_purkinje_cell_test.py index c9078056..973802b8 100644 --- a/examples/icub_vor_examples/single_purkinje_cell_test.py +++ b/examples/icub_vor_examples/single_purkinje_cell_test.py @@ -1,17 +1,16 @@ -# Copyright (c) 2019-2021 The University of Manchester +# Copyright (c) 2021 The University of Manchester # -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# https://www.apache.org/licenses/LICENSE-2.0 # -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. from __future__ import print_function import pyNN.spiNNaker as p diff --git a/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing.py b/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing.py index 4f6c7dc2..734c9cd9 100644 --- a/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing.py +++ b/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing.py @@ -1,17 +1,16 @@ -# Copyright (c) 2019-2021 The University of Manchester +# Copyright (c) 2021 The University of Manchester # -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# https://www.apache.org/licenses/LICENSE-2.0 # -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. from __future__ import print_function import pyNN.spiNNaker as p diff --git a/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing_3_spikes.py b/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing_3_spikes.py index cc4778a3..5bd82df8 100644 --- a/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing_3_spikes.py +++ b/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing_3_spikes.py @@ -1,17 +1,16 @@ -# Copyright (c) 2019-2021 The University of Manchester +# Copyright (c) 2021 The University of Manchester # -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# https://www.apache.org/licenses/LICENSE-2.0 # -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. from __future__ import print_function import pyNN.spiNNaker as p diff --git a/examples/icub_vor_examples/single_vestibular_nuclei_potentiation_test.py b/examples/icub_vor_examples/single_vestibular_nuclei_potentiation_test.py index 759b5ba7..df01793b 100644 --- a/examples/icub_vor_examples/single_vestibular_nuclei_potentiation_test.py +++ b/examples/icub_vor_examples/single_vestibular_nuclei_potentiation_test.py @@ -1,17 +1,16 @@ -# Copyright (c) 2019-2021 The University of Manchester +# Copyright (c) 2021 The University of Manchester # -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# https://www.apache.org/licenses/LICENSE-2.0 # -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. from __future__ import print_function import pyNN.spiNNaker as p diff --git a/examples/icub_vor_examples/test_mfvn_lut.py b/examples/icub_vor_examples/test_mfvn_lut.py index 9d2f235d..48b27287 100644 --- a/examples/icub_vor_examples/test_mfvn_lut.py +++ b/examples/icub_vor_examples/test_mfvn_lut.py @@ -1,17 +1,16 @@ -# Copyright (c) 2019-2022 The University of Manchester +# Copyright (c) 2021 The University of Manchester # -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# https://www.apache.org/licenses/LICENSE-2.0 # -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. import matplotlib.pyplot as plt from spynnaker.pyNN.models.neuron.plasticity.stdp.common \ diff --git a/examples/icub_vor_examples/test_pfpc_lut.py b/examples/icub_vor_examples/test_pfpc_lut.py index 8796d867..9e244410 100644 --- a/examples/icub_vor_examples/test_pfpc_lut.py +++ b/examples/icub_vor_examples/test_pfpc_lut.py @@ -1,17 +1,16 @@ -# Copyright (c) 2019-2022 The University of Manchester +# Copyright (c) 2021 The University of Manchester # -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# https://www.apache.org/licenses/LICENSE-2.0 # -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. import matplotlib.pyplot as plt from spynnaker.pyNN.models.neuron.plasticity.stdp.common \ From 6111356154fe8bc1c85661ffa41dd4e384aab6c7 Mon Sep 17 00:00:00 2001 From: Andrew Gait Date: Fri, 30 Jun 2023 14:40:56 +0100 Subject: [PATCH 24/28] Move rng seed to Population --- .../icub_vor_examples/pb_cerebellum_tb.py | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/examples/icub_vor_examples/pb_cerebellum_tb.py b/examples/icub_vor_examples/pb_cerebellum_tb.py index 608b99a1..b1144e6b 100644 --- a/examples/icub_vor_examples/pb_cerebellum_tb.py +++ b/examples/icub_vor_examples/pb_cerebellum_tb.py @@ -21,7 +21,7 @@ from pyNN.utility.plotting import Figure, Panel -from pyNN.random import RandomDistribution, NumpyRNG +from pyNN.random import RandomDistribution # PAB imports import traceback @@ -150,13 +150,11 @@ def save_figure(plt, name, extensions=(".png",), **kwargs): # Random distribution for synapses delays and weights (MF and GO) delay_distr = RandomDistribution( - 'uniform', (1.0, 10.0), rng=NumpyRNG(seed=85524)) + 'uniform', (1.0, 10.0)) weight_distr_MF = RandomDistribution( - 'uniform', (mf_gc_weights * 0.8, mf_gc_weights * 1.2), - rng=NumpyRNG(seed=85524)) + 'uniform', (mf_gc_weights * 0.8, mf_gc_weights * 1.2)) weight_distr_GO = RandomDistribution( - 'uniform', (go_gc_weights * 0.8, go_gc_weights * 1.2), - rng=NumpyRNG(seed=24568)) + 'uniform', (go_gc_weights * 0.8, go_gc_weights * 1.2)) # Post-synapse population neuron_params = { @@ -212,8 +210,7 @@ def save_figure(plt, name, extensions=(".png",), **kwargs): plastic_delay_s = 4 weight_dist_pfpc = RandomDistribution('uniform', (initial_weight_s * 0.8, - initial_weight_s * 1.2), - rng=NumpyRNG(seed=24534)) + initial_weight_s * 1.2)) sim.setup(timestep=1., min_delay=1, max_delay=15) global_n_neurons_per_core = 64 @@ -406,35 +403,37 @@ def process_VN_spiketrains(VN_spikes, t_start): # {'rate': sa_mean_freq}, # source spike times {'rate': sensorial_activity(0)[0]}, # source spike times label="MFLayer", # identifier - additional_parameters={"max_rate": MAX_RATE} + additional_parameters={"max_rate": MAX_RATE, 'seed': 24534} ) all_populations["mossy_fibers"] = MF_population # Create GOC population GOC_population = sim.Population(num_GOC_neurons, sim.IF_cond_exp(), - label='GOCLayer') + label='GOCLayer', + additional_parameters={'seed': 24534}) all_populations["golgi"] = GOC_population # create PC population PC_population = sim.Population( num_PC_neurons, # number of neurons sim.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model - label="Purkinje Cell" # identifier - ) + label="Purkinje Cell", # identifier + additional_parameters={'seed': 24534}) all_populations["purkinje"] = PC_population # create VN population VN_population = sim.Population( num_VN_neurons, # number of neurons sim.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model - label="Vestibular Nuclei" # identifier - ) + label="Vestibular Nuclei", # identifier + additional_parameters={'seed': 24534}) all_populations["vn"] = VN_population # Create GrC population GC_population = sim.Population(num_GC_neurons, sim.IF_curr_exp(), - label='GCLayer') + label='GCLayer', + additional_parameters={'seed': 24534}) all_populations["granule"] = GC_population # generate fake error (it should be calculated from sensorial activity in error @@ -449,7 +448,7 @@ def process_VN_spiketrains(VN_spikes, t_start): # {'rate': sa_mean_freq}, # source spike times {'rate': error_activity(err)}, # source spike times label="CFLayer", # identifier - additional_parameters={"max_rate": MAX_RATE} + additional_parameters={"max_rate": MAX_RATE, 'seed': 24534} ) all_populations["climbing_fibers"] = CF_population From 5b7eb9477b7b2dc7919d2849a4fc28a6b8c4e4c3 Mon Sep 17 00:00:00 2001 From: Andrew Gait Date: Fri, 28 Jul 2023 11:43:14 +0100 Subject: [PATCH 25/28] Minor updates to pb_cerebellum script --- .../icub_vor_examples/pb_cerebellum_tb.py | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/examples/icub_vor_examples/pb_cerebellum_tb.py b/examples/icub_vor_examples/pb_cerebellum_tb.py index b1144e6b..3c635b95 100644 --- a/examples/icub_vor_examples/pb_cerebellum_tb.py +++ b/examples/icub_vor_examples/pb_cerebellum_tb.py @@ -682,7 +682,8 @@ def process_VN_spiketrains(VN_spikes, t_start): CF_spikes = CF_population.get_data('spikes') GC_spikes = GC_population.get_data('all') GOC_spikes = GOC_population.get_data('spikes') -VN_spikes = VN_population.get_data('all') # VN_population.get_data('spikes') +VN_spikes = VN_population.get_data('spikes') +VN_gsyninh = VN_population.get_data('gsyn_inh') PC_spikes = PC_population.get_data('spikes') mfvn_weights = mf_vn_connections.get('weight', 'list', with_address=False) @@ -827,16 +828,17 @@ def process_VN_spiketrains(VN_spikes, t_start): extensions=['.png', '.pdf']) plt.close(f) -for proj, conn in final_connectivity.items(): - f = plt.figure(1, figsize=(9, 9), dpi=400) - plt.hist(conn[:, 2], bins=20) - plt.title(proj) - plt.xlabel("Weight") - plt.ylabel("Count") - save_figure(plt, os.path.join( - fig_folder, "{}_weight_histogram".format(proj)), - extensions=['.png', ]) - plt.close(f) +if not isinstance(final_connectivity, list): + for proj, conn in final_connectivity.items(): + f = plt.figure(1, figsize=(9, 9), dpi=400) + plt.hist(conn[:, 2], bins=20) + plt.title(proj) + plt.xlabel("Weight") + plt.ylabel("Count") + save_figure(plt, os.path.join( + fig_folder, "{}_weight_histogram".format(proj)), + extensions=['.png', ]) + plt.close(f) F = Figure( Panel(MF_spikes.segments[0].spiketrains, @@ -857,8 +859,8 @@ def process_VN_spiketrains(VN_spikes, t_start): Panel(VN_spikes.segments[0].spiketrains, yticks=True, markersize=2, xlim=(0, total_runtime), xlabel='VN_spikes'), - Panel(VN_spikes.segments[0].filter(name='gsyn_inh')[0], - ylabel="Membrane potential (mV)", yticks=True, xlim=(0, + Panel(VN_gsyninh.segments[0].filter(name='gsyn_inh')[0], + ylabel="gsyn_inh", yticks=True, xlim=(0, total_runtime)) ) save_figure(plt, os.path.join(fig_folder, "collections"), From fcfde65759dd73c7d8e327b9138248d2cda98421 Mon Sep 17 00:00:00 2001 From: Andrew Gait Date: Fri, 28 Jul 2023 12:21:42 +0100 Subject: [PATCH 26/28] flake8 oops --- examples/icub_vor_examples/pb_cerebellum_tb.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/icub_vor_examples/pb_cerebellum_tb.py b/examples/icub_vor_examples/pb_cerebellum_tb.py index 3c635b95..54aef633 100644 --- a/examples/icub_vor_examples/pb_cerebellum_tb.py +++ b/examples/icub_vor_examples/pb_cerebellum_tb.py @@ -860,8 +860,7 @@ def process_VN_spiketrains(VN_spikes, t_start): yticks=True, markersize=2, xlim=(0, total_runtime), xlabel='VN_spikes'), Panel(VN_gsyninh.segments[0].filter(name='gsyn_inh')[0], - ylabel="gsyn_inh", yticks=True, xlim=(0, - total_runtime)) + ylabel="gsyn_inh", yticks=True, xlim=(0, total_runtime)) ) save_figure(plt, os.path.join(fig_folder, "collections"), extensions=['.png', ]) From 4d7acfffa95767fe4a879714e8b2b71d2e66cdba Mon Sep 17 00:00:00 2001 From: Andrew Gait Date: Tue, 19 Sep 2023 17:01:06 +0100 Subject: [PATCH 27/28] Update scripts to replace unneeded model --- examples/icub_vor_examples/cerebellum.py | 97 +------------- examples/icub_vor_examples/cerebellum_tb.py | 125 +++--------------- .../icub_vor_examples/pb_cerebellum_tb.py | 90 +------------ .../single_purkinje_cell_pf_windowing.py | 6 +- .../single_purkinje_cell_potentiation_test.py | 6 +- .../single_purkinje_cell_test.py | 6 +- .../single_vestibular_nuclei_mf_windowing.py | 6 +- ...vestibular_nuclei_mf_windowing_3_spikes.py | 6 +- ...gle_vestibular_nuclei_potentiation_test.py | 6 +- 9 files changed, 31 insertions(+), 317 deletions(-) diff --git a/examples/icub_vor_examples/cerebellum.py b/examples/icub_vor_examples/cerebellum.py index 3090001a..93f26fbf 100644 --- a/examples/icub_vor_examples/cerebellum.py +++ b/examples/icub_vor_examples/cerebellum.py @@ -15,20 +15,8 @@ # import socket import pyNN.spiNNaker as sim import numpy as np -# import logging import matplotlib.pyplot as plt -# from spynnaker8.utilities import DataHolder -# from pacman.model.constraints.key_allocator_constraints import ( -# FixedKeyAndMaskConstraint) -# from pacman.model.graphs.application import ApplicationSpiNNakerLinkVertex -# from pacman.model.routing_info import BaseKeyAndMask -# from spinn_front_end_common.abstract_models.\ -# abstract_provides_outgoing_partition_constraints import ( -# AbstractProvidesOutgoingPartitionConstraints) -# from spinn_utilities.overrides import overrides -# from pyNN.utility import Timer -# from pyNN.utility.plotting import Figure, Panel from pyNN.random import RandomDistribution, NumpyRNG # cerebellum with simulated input @@ -38,50 +26,6 @@ RETINA_MASK = 0xFF000000 RETINA_Y_BIT_SHIFT = 9 -# class ICUBInputVertex( -# ApplicationSpiNNakerLinkVertex, -# # AbstractProvidesNKeysForPartition, -# AbstractProvidesOutgoingPartitionConstraints): -# -# def __init__(self, n_neurons, spinnaker_link_id, board_address=None, -# constraints=None, label=None): -# -# ApplicationSpiNNakerLinkVertex.__init__( -# self, n_neurons, spinnaker_link_id=spinnaker_link_id, -# board_address=board_address, label=label, -# constraints=constraints) -# #AbstractProvidesNKeysForPartition.__init__(self) -# AbstractProvidesOutgoingPartitionConstraints.__init__(self) -# -# # @overrides(AbstractProvidesNKeysForPartition.get_n_keys_for_partition) -# # def get_n_keys_for_partition(self, partition, graph_mapper): -# # return 1048576 -# -# @overrides(AbstractProvidesOutgoingPartitionConstraints. -# get_outgoing_partition_constraints) -# def get_outgoing_partition_constraints(self, partition): -# return [FixedKeyAndMaskConstraint( -# keys_and_masks=[BaseKeyAndMask( -# base_key=0, #upper part of the key -# mask=0xFFFFFC00)])] -# # keys, i.e. neuron addresses of the input population that sits in -# # the ICUB vertex: this mask removes all spikes that have a "1" in -# # the MSB and lets the spikes go only if the MSB are at "0" -# # it must have enough keys to host the input addressing space and -# # the output (with the same keys) -# class ICUBInputVertexDataHolder(DataHolder): -# -# def __init__(self, spinnaker_link_id, board_address=None, -# constraints=None, label=None): -# DataHolder.__init__( -# self, {"spinnaker_link_id": spinnaker_link_id, -# "board_address": board_address, "label": label}) -# -# @staticmethod -# def build_model(): -# return ICUBInputVertex -# #logger = logging.getLogger(__name__) - # Synapsis parameters gc_pc_weights = 0.005 mf_vn_weights = 0.001 @@ -137,13 +81,6 @@ plastic_delay_s = 4 sim.setup(timestep=1.) -# sim.set_number_of_neurons_per_core(sim.IF_curr_exp, 255) - -# set up input populations -# num_pxl = 304 * 240; -# retina_pop = sim.Population( -# 1024, ICUBInputVertexDataHolder(spinnaker_link_id=0), label='pop_retina') - # Sensorial Activity: input activity from vestibulus (will come from the head # IMU, now it is a test bench) @@ -284,11 +221,6 @@ def compute_D_error(kd, head_velocity, eye_velocity): IO_agonist = rate ea_rate = np.concatenate((IO_agonist, IO_antagonist)) - # print(j) - # plt.plot(np.linspace(up_neuron_ID_threshold, - # low_neuron_ID_threshold,200), ea_rate) - # plt.plot(ea_rate) -# plt.show() low_neuron_ID_threshold = abs(error) * 100.0 up_neuron_ID_threshold = low_neuron_ID_threshold - 100.0 @@ -316,9 +248,6 @@ def compute_D_error(kd, head_velocity, eye_velocity): ea_rate = np.concatenate((IO_agonist, IO_antagonist)) -# plt.plot(ea_rate) -# plt.show() - return ea_rate @@ -335,8 +264,7 @@ def compute_D_error(kd, head_velocity, eye_velocity): {'rate': sensorial_activity(10)[0]}, # source spike times label="sa_population" # identifier ) -# plt.plot(sensorial_activity()) -# plt.show() + # Create MF population MF_population = sim.Population(num_MF_neurons, sim.IF_curr_exp(), label='MFLayer') @@ -357,14 +285,14 @@ def compute_D_error(kd, head_velocity, eye_velocity): # create PC population PC_population = sim.Population( num_PC_neurons, # number of neurons - sim.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model + sim.IF_cond_exp(**neuron_params), # Neuron model label="Purkinje Cell" # identifier ) # create VN population VN_population = sim.Population( num_VN_neurons, # number of neurons - sim.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model + sim.IF_cond_exp(**neuron_params), # Neuron model label="Vestibular Nuclei" # identifier ) @@ -463,22 +391,3 @@ def compute_D_error(kd, head_velocity, eye_velocity): out_pop = sim.Population(128, sim.IF_curr_exp(), label='pop_out') -# sim.Projection( -# lif_pop, out_pop, sim.OneToOneConnector(), -# synapse_type=sim.StaticSynapse(weight=0.1)) -# -# -# # live output of the input (retina_pop) to the first population (lif_pop) -# sim.external_devices.activate_live_output_to(out_pop,retina_pop) -# -# -# #recordings and simulations -# lif_pop.record(["spikes"]) -# -# out_pop.record(["spikes"]) -# -# -# -# sim.run(10) -# -# sim.end() diff --git a/examples/icub_vor_examples/cerebellum_tb.py b/examples/icub_vor_examples/cerebellum_tb.py index 6ecc0377..2852d4b2 100644 --- a/examples/icub_vor_examples/cerebellum_tb.py +++ b/examples/icub_vor_examples/cerebellum_tb.py @@ -12,26 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function # for python3 printing in python2 -# import socket import pyNN.spiNNaker as sim import numpy as np -# import logging import matplotlib.pyplot as plt -# from spynnaker8.utilities import DataHolder -# from pacman.model.constraints.key_allocator_constraints import ( -# FixedKeyAndMaskConstraint) -# from pacman.model.graphs.application import ApplicationSpiNNakerLinkVertex -# from pacman.model.routing_info import BaseKeyAndMask -# from spinn_front_end_common.abstract_models.\ -# abstract_provides_n_keys_for_partition import ( -# AbstractProvidesNKeysForPartition) -# from spinn_front_end_common.abstract_models.\ -# abstract_provides_outgoing_partition_constraints import ( -# AbstractProvidesOutgoingPartitionConstraints) -# from spinn_utilities.overrides import overrides -# from pyNN.utility import Timer from pyNN.utility.plotting import Figure, Panel from pyNN.random import RandomDistribution, NumpyRNG @@ -60,14 +44,13 @@ num_CF_neurons = 200 # Random distribution for synapses delays and weights (MF and GO) -delay_distr = RandomDistribution('uniform', (1.0, 10.0), - rng=NumpyRNG(seed=85524)) +delay_distr = RandomDistribution('uniform', (1.0, 10.0)) weight_distr_MF = RandomDistribution( - 'uniform', (mf_gc_weights*0.8, mf_gc_weights*1.2), - rng=NumpyRNG(seed=85524)) + 'uniform', (mf_gc_weights*0.8, mf_gc_weights*1.2)) +seed_MF = 85524 weight_distr_GO = RandomDistribution( - 'uniform', (go_gc_weights*0.8, go_gc_weights*1.2), - rng=NumpyRNG(seed=24568)) + 'uniform', (go_gc_weights*0.8, go_gc_weights*1.2)) +seed_GO = 24568 # Post-synapse population @@ -97,8 +80,8 @@ plastic_delay_s = 4 weight_dist_pfpc = RandomDistribution('uniform', (initial_weight_s*0.8, - initial_weight_s*1.2), - rng=NumpyRNG(seed=24534)) + initial_weight_s*1.2)) +seed_PFPC = 24534 sim.setup(timestep=1.) @@ -174,32 +157,9 @@ def sensorial_activity(pt): # Error Activity: error from eye and head encoders def error_activity(error_): - # min_rate = 1.0 - # max_rate = 25.0 - # - # low_neuron_ID_threshold = abs(error_) * 100.0 - # up_neuron_ID_threshold = low_neuron_ID_threshold - 100.0 IO_agonist = np.zeros((100)) IO_antagonist = np.zeros((100)) - # rate = [] - # for i in range (100): - # if(i < up_neuron_ID_threshold): - # rate.append(max_rate) - # elif(i=0.0: - # IO_agonist[0:100]=min_rate - # IO_antagonist=rate - # else: - # IO_antagonist[0:100]=min_rate - # IO_agonist=rate IO_agonist[:] = H_RATE IO_antagonist[:] = L_RATE @@ -231,30 +191,34 @@ def process_VN_spiketrains(VN_spikes, t_start): # {'rate': sa_mean_freq}, # source spike times {'rate': sensorial_activity(0)[0]}, # source spike times label="MFLayer", # identifier - additional_parameters={"max_rate": MAX_RATE} + additional_parameters={"max_rate": MAX_RATE, "seed": seed_MF} ) # Create GOC population GOC_population = sim.Population(num_GOC_neurons, sim.IF_cond_exp(), - label='GOCLayer') + label='GOCLayer', + additional_parameters={"seed": seed_GO}) # create PC population PC_population = sim.Population( num_PC_neurons, # number of neurons - sim.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model - label="Purkinje Cell" # identifier + sim.IF_cond_exp(**neuron_params), # Neuron model + label="Purkinje Cell", # identifier + additional_parameters={"seed": seed_PFPC} ) # create VN population VN_population = sim.Population( num_VN_neurons, # number of neurons - sim.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model - label="Vestibular Nuclei" # identifier + sim.IF_cond_exp(**neuron_params), # Neuron model + label="Vestibular Nuclei", # identifier + additional_parameters={"seed": seed_PFPC} ) # Create GrC population GC_population = sim.Population(num_GC_neurons, sim.IF_curr_exp(), - label='GCLayer') + label='GCLayer', + additional_parameters={"seed": seed_GO}) # generate fake error (it should be calculated from sensorial activity in error # activity, but we skip it and just generate an error from -1.5 to 1.5) @@ -380,32 +344,6 @@ def process_VN_spiketrains(VN_spikes, t_start): synapse_type=sim.StaticSynapse(delay=1.0, weight=cf_pc_weights), receptor_type='excitatory') -# lif_pop = sim.Population(1024, sim.IF_curr_exp(), label='pop_lif') -# -# out_pop = sim.Population(128, sim.IF_curr_exp(), label='pop_out') - -# sim.run(1000) - -# sim.Projection( -# lif_pop, out_pop, sim.OneToOneConnector(), -# synapse_type=sim.StaticSynapse(weight=0.1)) -# -# -# # live output of the input (retina_pop) to the first population (lif_pop) -# sim.external_devices.activate_live_output_to(out_pop,retina_pop) -# -# -# recordings and simulations -# lif_pop.record(["spikes"]) -# -# out_pop.record(["spikes"]) -# -# -# -# sim.run(10) -# -# sim.end() - MF_population.record(['spikes']) CF_population.record(['spikes']) GC_population.record('all') @@ -431,33 +369,6 @@ def process_VN_spiketrains(VN_spikes, t_start): MF_population.set(rate=sensorial_activity(total_runtime)[0]) -# sim.run(runtime*0.4) -# -# CF_rates=[] -# lower_rate=100*[L_RATE] -# upper_rate=100*[H_RATE] -# CF_rates.extend(lower_rate) -# CF_rates.extend(upper_rate) -# CF_population.set(rate=CF_rates) -# -# sim.run(runtime*0.4) -# -# CF_rates=[] -# lower_rate=100*[H_RATE] -# upper_rate=100*[L_RATE] -# CF_rates.extend(lower_rate) -# CF_rates.extend(upper_rate) -# CF_population.set(rate=CF_rates) -# -# sim.run(runtime*0.2) -# -# CF_rates=[] -# lower_rate=100*[H_RATE] -# upper_rate=100*[L_RATE] -# CF_rates.extend(lower_rate) -# CF_rates.extend(upper_rate) -# CF_population.set(rate=CF_rates) - total_runtime = runtime*repeats MF_spikes = MF_population.get_data('spikes') diff --git a/examples/icub_vor_examples/pb_cerebellum_tb.py b/examples/icub_vor_examples/pb_cerebellum_tb.py index 54aef633..56f1bf08 100644 --- a/examples/icub_vor_examples/pb_cerebellum_tb.py +++ b/examples/icub_vor_examples/pb_cerebellum_tb.py @@ -12,23 +12,18 @@ # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function import pyNN.spiNNaker as sim import numpy as np -# import logging import pylab as plt import matplotlib as mlib - from pyNN.utility.plotting import Figure, Panel from pyNN.random import RandomDistribution # PAB imports import traceback -# import pandas as pd import os import neo -# import copy # ====================== MAKING THINGS LOOK CONSISTENT ======================== # ensure we use viridis as the default cmap @@ -197,7 +192,6 @@ def save_figure(plt, name, extensions=(".png",), **kwargs): beta_c = 11 sigma_c = 201 initial_weight_c = 0.001 # max_weight_c #0.0005 -# initial_weight_c = 0.05 plastic_delay_c = 4 # Learning parameters sin rule @@ -220,7 +214,7 @@ def save_figure(plt, name, extensions=(".png",), **kwargs): sim.SpikeSourceArray, global_n_neurons_per_core) sim.set_number_of_neurons_per_core(sim.IF_cond_exp, global_n_neurons_per_core) sim.set_number_of_neurons_per_core( - sim.extra_models.IFCondExpCerebellum, global_n_neurons_per_core) + sim.IF_cond_exp, global_n_neurons_per_core) # Sensorial Activity: input activity from vestibulus (will come from the head # IMU, now it is a test bench) @@ -346,32 +340,9 @@ def sensorial_activity(pt): # Error Activity: error from eye and head encoders def error_activity(error_): - # min_rate = 1.0 - # max_rate = 25.0 - # - # low_neuron_ID_threshold = abs(error_) * 100.0 - # up_neuron_ID_threshold = low_neuron_ID_threshold - 100.0 IO_agonist = np.zeros((100)) IO_antagonist = np.zeros((100)) - # - # rate = [] - # for i in range (100): - # if(i < up_neuron_ID_threshold): - # rate.append(max_rate) - # elif(i=0.0: - # IO_agonist[0:100]=min_rate - # IO_antagonist=rate - # else: - # IO_antagonist[0:100]=min_rate - # IO_agonist=rate + IO_agonist[:] = H_RATE IO_antagonist[:] = L_RATE @@ -417,7 +388,7 @@ def process_VN_spiketrains(VN_spikes, t_start): # create PC population PC_population = sim.Population( num_PC_neurons, # number of neurons - sim.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model + sim.IF_cond_exp(**neuron_params), # Neuron model label="Purkinje Cell", # identifier additional_parameters={'seed': 24534}) all_populations["purkinje"] = PC_population @@ -425,7 +396,7 @@ def process_VN_spiketrains(VN_spikes, t_start): # create VN population VN_population = sim.Population( num_VN_neurons, # number of neurons - sim.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model + sim.IF_cond_exp(**neuron_params), # Neuron model label="Vestibular Nuclei", # identifier additional_parameters={'seed': 24534}) all_populations["vn"] = VN_population @@ -580,32 +551,6 @@ def process_VN_spiketrains(VN_spikes, t_start): receptor_type='excitatory') all_projections["cf_pc"] = cf_pc_connections -# lif_pop = sim.Population(1024, sim.IF_curr_exp(), label='pop_lif') -# -# out_pop = sim.Population(128, sim.IF_curr_exp(), label='pop_out') - -# sim.run(1000) - -# sim.Projection( -# lif_pop, out_pop, sim.OneToOneConnector(), -# synapse_type=sim.StaticSynapse(weight=0.1)) -# -# -# # live output of the input (retina_pop) to the first population (lif_pop) -# sim.external_devices.activate_live_output_to(out_pop,retina_pop) -# -# -# recordings and simulations -# lif_pop.record(["spikes"]) -# -# out_pop.record(["spikes"]) -# -# -# -# sim.run(10) -# -# sim.end() - # ============================ Set up recordings ============================ MF_population.record(['spikes']) @@ -643,33 +588,6 @@ def process_VN_spiketrains(VN_spikes, t_start): MF_population.set(rate=sensorial_activity(total_runtime)[0]) - # sim.run(runtime*0.4) - # - # CF_rates=[] - # lower_rate=100*[L_RATE] - # upper_rate=100*[H_RATE] - # CF_rates.extend(lower_rate) - # CF_rates.extend(upper_rate) - # CF_population.set(rate=CF_rates) - # - # sim.run(runtime*0.4) - # - # CF_rates=[] - # lower_rate=100*[H_RATE] - # upper_rate=100*[L_RATE] - # CF_rates.extend(lower_rate) - # CF_rates.extend(upper_rate) - # CF_population.set(rate=CF_rates) - # - # sim.run(runtime*0.2) - # - # CF_rates=[] - # lower_rate=100*[H_RATE] - # upper_rate=100*[L_RATE] - # CF_rates.extend(lower_rate) - # CF_rates.extend(upper_rate) - # CF_population.set(rate=CF_rates) - end_time = plt.datetime.datetime.now() total_time = end_time - start_time sim_total_time = end_time - sim_start_time diff --git a/examples/icub_vor_examples/single_purkinje_cell_pf_windowing.py b/examples/icub_vor_examples/single_purkinje_cell_pf_windowing.py index 666da87f..99ad32cc 100644 --- a/examples/icub_vor_examples/single_purkinje_cell_pf_windowing.py +++ b/examples/icub_vor_examples/single_purkinje_cell_pf_windowing.py @@ -12,11 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function import pyNN.spiNNaker as p -# import numpy -# import math -# import unittest from pyNN.utility.plotting import Figure, Panel import matplotlib.pyplot as plt @@ -41,7 +37,7 @@ purkinje_cell = p.Population( 1, # number of neurons - p.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model + p.IF_cond_exp(**neuron_params), # Neuron model label="Purkinje Cell" # identifier ) diff --git a/examples/icub_vor_examples/single_purkinje_cell_potentiation_test.py b/examples/icub_vor_examples/single_purkinje_cell_potentiation_test.py index 372708a7..8c901430 100644 --- a/examples/icub_vor_examples/single_purkinje_cell_potentiation_test.py +++ b/examples/icub_vor_examples/single_purkinje_cell_potentiation_test.py @@ -12,11 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function import pyNN.spiNNaker as p -# import numpy -# import math -# import unittest from pyNN.utility.plotting import Figure, Panel import matplotlib.pyplot as plt @@ -43,7 +39,7 @@ purkinje_cell = p.Population( 1, # number of neurons - p.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model + p.IF_cond_exp(**neuron_params), # Neuron model label="Purkinje Cell" # identifier ) diff --git a/examples/icub_vor_examples/single_purkinje_cell_test.py b/examples/icub_vor_examples/single_purkinje_cell_test.py index 973802b8..22cf9328 100644 --- a/examples/icub_vor_examples/single_purkinje_cell_test.py +++ b/examples/icub_vor_examples/single_purkinje_cell_test.py @@ -12,11 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function import pyNN.spiNNaker as p -# import numpy -# import math -# import unittest from pyNN.utility.plotting import Figure, Panel import matplotlib.pyplot as plt @@ -41,7 +37,7 @@ purkinje_cell = p.Population( 1, # number of neurons - p.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model + p.IF_cond_exp(**neuron_params), # Neuron model label="Purkinje Cell" # identifier ) diff --git a/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing.py b/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing.py index 734c9cd9..feefc24c 100644 --- a/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing.py +++ b/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing.py @@ -12,11 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function import pyNN.spiNNaker as p -# import numpy -# import math -# import unittest from pyNN.utility.plotting import Figure, Panel import matplotlib.pyplot as plt @@ -45,7 +41,7 @@ vestibular_nuclei = p.Population( 1, # number of neurons - p.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model + p.IF_cond_exp(**neuron_params), # Neuron model label="Vestibular Nuclei" # identifier ) diff --git a/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing_3_spikes.py b/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing_3_spikes.py index 5bd82df8..947a104c 100644 --- a/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing_3_spikes.py +++ b/examples/icub_vor_examples/single_vestibular_nuclei_mf_windowing_3_spikes.py @@ -12,11 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function import pyNN.spiNNaker as p -# import numpy -# import math -# import unittest from pyNN.utility.plotting import Figure, Panel import matplotlib.pyplot as plt @@ -45,7 +41,7 @@ vestibular_nuclei = p.Population( 1, # number of neurons - p.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model + p.IF_cond_exp(**neuron_params), # Neuron model label="Vestibular Nuclei" # identifier ) diff --git a/examples/icub_vor_examples/single_vestibular_nuclei_potentiation_test.py b/examples/icub_vor_examples/single_vestibular_nuclei_potentiation_test.py index df01793b..a527ff92 100644 --- a/examples/icub_vor_examples/single_vestibular_nuclei_potentiation_test.py +++ b/examples/icub_vor_examples/single_vestibular_nuclei_potentiation_test.py @@ -12,11 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function import pyNN.spiNNaker as p -# import numpy -# import math -# import unittest from pyNN.utility.plotting import Figure, Panel import matplotlib.pyplot as plt @@ -45,7 +41,7 @@ vestibular_neuclei = p.Population( 1, # number of neurons - p.extra_models.IFCondExpCerebellum(**neuron_params), # Neuron model + p.IF_cond_exp(**neuron_params), # Neuron model label="Vestibular Nuclei" # identifier ) From d7d61aef860c71f5188f0a83cde92ef42ad637b7 Mon Sep 17 00:00:00 2001 From: Andrew Gait Date: Tue, 19 Sep 2023 17:07:07 +0100 Subject: [PATCH 28/28] flake8 tidy up --- examples/icub_vor_examples/cerebellum.py | 2 +- examples/icub_vor_examples/cerebellum_tb.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/icub_vor_examples/cerebellum.py b/examples/icub_vor_examples/cerebellum.py index 93f26fbf..d4cd779a 100644 --- a/examples/icub_vor_examples/cerebellum.py +++ b/examples/icub_vor_examples/cerebellum.py @@ -82,6 +82,7 @@ sim.setup(timestep=1.) + # Sensorial Activity: input activity from vestibulus (will come from the head # IMU, now it is a test bench) def sensorial_activity(pt): @@ -390,4 +391,3 @@ def compute_D_error(kd, head_velocity, eye_velocity): lif_pop = sim.Population(1024, sim.IF_curr_exp(), label='pop_lif') out_pop = sim.Population(128, sim.IF_curr_exp(), label='pop_out') - diff --git a/examples/icub_vor_examples/cerebellum_tb.py b/examples/icub_vor_examples/cerebellum_tb.py index 2852d4b2..993b87b8 100644 --- a/examples/icub_vor_examples/cerebellum_tb.py +++ b/examples/icub_vor_examples/cerebellum_tb.py @@ -17,7 +17,7 @@ import matplotlib.pyplot as plt from pyNN.utility.plotting import Figure, Panel -from pyNN.random import RandomDistribution, NumpyRNG +from pyNN.random import RandomDistribution L_RATE = 2 H_RATE = 20