def setupLayer_KC(): ''' ┌────── KC_cell_0001 ├────── KC_cell_0002 ┌──────> PN_cell_[i] KC ─────┼────── KC_cell_0003 <────┼──────> ... ├────── .... └──────> PN_cell_[k] └────── KC_cell_2000 1.Each KC neuron map to around ~20 PN_cells which was chosen randomly from 100 of all 2.By the property of SpiNNaker Board. Each core contains MAX 256 neurons. Hence 2000 KC_neurons will spreads to around ~10 cores ''' kc_population = spynnaker.Population(NUM_KC_CELLS, spynnaker.IF_curr_exp(), label='KC_population') return kc_population
import pyNN.utility.plotting as plot import matplotlib.pyplot as plt import threading from random import uniform from time import sleep from pykeyboard import PyKeyboard sim.setup(timestep=1.0) sim.set_number_of_neurons_per_core(sim.IF_curr_exp, 100) input1 = sim.Population(6, sim.external_devices.SpikeInjector(), label="stateSpikeInjector") pre_pop = sim.Population(6, sim.IF_curr_exp(tau_syn_E=100, tau_refrac=50), label="statePopulation") post_pop = sim.Population(1, sim.IF_curr_exp(), label="actorPopulation") sim.external_devices.activate_live_output_for(pre_pop, database_notify_host="localhost", database_notify_port_num=19996) sim.external_devices.activate_live_output_for(input1, database_notify_host="localhost", database_notify_port_num=19998) timing_rule = sim.SpikePairRule(tau_plus=20.0, tau_minus=20.0, A_plus=0.5, A_minus=0.5) weight_rule = sim.AdditiveWeightDependence(w_max=25.0, w_min=0.0)
try: import pyNN.spiNNaker as p except Exception as e: import spynnaker8 as p # set up the tools p.setup(timestep=1.0, min_delay=1.0, max_delay=32.0) # set up the virtual chip coordinates for the motor connected_chip_coords = {'x': 0, 'y': 0} link = 4 populations = list() projections = list() input_population = p.Population(6, p.SpikeSourcePoisson(rate=10)) control_population = p.Population(6, p.IF_curr_exp()) motor_device = p.Population( 6, p.external_devices.MunichMotorDevice(spinnaker_link_id=0)) p.Projection(input_population, control_population, p.OneToOneConnector(), synapse_type=p.StaticSynapse(weight=5.0)) p.external_devices.activate_live_output_to(control_population, motor_device) p.run(1000) p.end()
cell_params_lif = { 'cm': 0.25, 'i_offset': 0, 'tau_m': 20, 'tau_refrac': 2, 'tau_syn_E': 50, 'tau_syn_I': 5, 'v_reset': -70, 'v_rest': -65, 'v_thresh': -55 } sim.set_number_of_neurons_per_core(sim.IF_curr_exp, 100) G1_1= sim.Population(1,sim.IF_curr_exp(**cell_params_lif), label="G1_1") G2_2= sim.Population(10,sim.IF_curr_exp(**cell_params_lif), label="G2_2") GEN1_3= sim.Population(1,simSpikeSourceArray(spike_times=[0,8], label="GEN1_3") input_G1_1GEN1_3=sim.Projection(G1_1,GEN1_3, sim.OneToOneConnector(), synapse_type.StaticSynapse(weight=1.25, delay=0)) input_G1_1G2_2=sim.Projection(G1_1,G2_2, sim.OneToOneConnector(), synapse_type.StaticSynapse(weight=0.8, delay=0)) input_G2_2G1_1=sim.Projection(G2_2,G1_1, sim.OneToOneConnector(), synapse_type.StaticSynapse(weight=0.1, delay=0)) G1_1.record(["spikes","v","gsyn_exc"]) simtime =50 sim.run(simtime) neo = G1_1.get_data(variables=["spikes","v","gsync_exc"]) spikes = neo.segments[0].spiketrains print spikes
import pyNN.spiNNaker as p INJECTOR_LABEL = "injector" RECEIVER_LABEL = "receiver" # declare python code when received spikes for a timer tick def receive_spikes(label, time, neuron_ids): for neuron_id in neuron_ids: print("Received spike at time {} from {}-{}" "".format(time, label, neuron_id)) p.setup(timestep=1.0) p1 = p.Population(1, p.IF_curr_exp(), label="pop_1") input_injector = p.Population(1, p.external_devices.SpikeInjector(), label=INJECTOR_LABEL) # set up python live spike connection live_spikes_connection = p.external_devices.SpynnakerLiveSpikesConnection( receive_labels=[RECEIVER_LABEL]) # register python receiver with live spike connection live_spikes_connection.add_receive_callback(RECEIVER_LABEL, receive_spikes) input_proj = p.Projection(input, p1, p.OneToOneConnector(), p.StaticSynapse(weight=5, delay=3)) p1.record(["spikes", "v"]) p.run(50)
label=label) def get_outgoing_partition_constraints(self, partition): return [ FixedKeyAndMaskConstraint([BaseKeyAndMask(0x12340000, 0xFFFF0000)]) ] class MySpiNNakerLinkDeviceDataHolder(DataHolder): def __init__(self, spinnaker_link_id, label=None): DataHolder.__init__(self, { "spinnaker_link_id": spinnaker_link_id, "label": label }) @staticmethod def build_model(): return MySpiNNakerLinkDevice p.setup(1.0) pop = p.Population(1, p.IF_curr_exp()) device = p.Population(1, MySpiNNakerLinkDeviceDataHolder(spinnaker_link_id=0)) p.Projection(device, pop, p.OneToOneConnector(), p.StaticSynapse(weight=1.0)) p.run(100) p.end()
cell_params_lif = { 'cm': 0.25, 'i_offset': 0, 'tau_m': 20, 'tau_refrac': 2, 'tau_syn_E': 50, 'tau_syn_I': 5, 'v_reset': -70, 'v_rest': -65, 'v_thresh': -55 } sim.set_number_of_neurons_per_core(sim.IF_curr_exp, 100) G1_1= sim.Population(1,sim.IF_curr_exp(**cell_params_lif), label="G1_1") G2_2= sim.Population(10,sim.IF_curr_exp(**cell_params_lif), label="G2_2") GEN1_3= sim.Population(1,simSpikeSourceArray(spike_times=[0,8], label="GEN1_3") G4_4= sim.Population(1,sim.IF_curr_exp(**cell_params_lif), label="G4_4") Dani_5= sim.Population(1,sim.IF_curr_exp(**cell_params_lif), label="Dani_5") G5_6= sim.Population(1,sim.IF_curr_exp(**cell_params_lif), label="G5_6") G6_7= sim.Population(1,sim.IF_curr_exp(**cell_params_lif), label="G6_7") input_G1_1GEN1_3=sim.Projection(G1_1,GEN1_3, sim.OneToOneConnector(), synapse_type.StaticSynapse(weight=1.25, delay=1)) input_G1_1G2_2=sim.Projection(G1_1,G2_2, sim.OneToOneConnector(), synapse_type.StaticSynapse(weight=0.8, delay=1)) input_G1_1G4_4=sim.Projection(G1_1,G4_4, sim.OneToOneConnector(), synapse_type.StaticSynapse(weight=1.7, delay=1)) input_G1_1Dani_5=sim.Projection(G1_1,Dani_5, sim.OneToOneConnector(), synapse_type.StaticSynapse(weight=1.3, delay=1)) input_G1_1G5_6=sim.Projection(G1_1,G5_6, sim.OneToOneConnector(), synapse_type.StaticSynapse(weight=1, delay=1)) input_G2_2G1_1=sim.Projection(G2_2,G1_1, sim.OneToOneConnector(), synapse_type.StaticSynapse(weight=0.1, delay=1)) input_G4_4G4_4=sim.Projection(G4_4,G4_4, sim.OneToOneConnector(), synapse_type.StaticSynapse(weight=1, delay=1)) input_G6_7G1_1=sim.Projection(G6_7,G1_1, sim.OneToOneConnector(), synapse_type.StaticSynapse(weight=1, delay=1))
sim.setup(timestep=1.0) sim.set_number_of_neurons_per_core(sim.IF_curr_exp, 100) numberOfSteps = 12 numberOfActions = 4 input1 = sim.Population(numberOfSteps * 4, sim.external_devices.SpikeInjector(), label="stateSpikeInjector") input2 = sim.Population(numberOfSteps * 4, sim.external_devices.SpikeInjector(), label="actorSpikeInjector") pre_pop = sim.Population(numberOfSteps * 4, sim.IF_curr_exp(tau_syn_E=100, tau_refrac=50), label="statePopulation") post_pop = sim.Population(numberOfSteps * 4, sim.IF_curr_exp(tau_syn_E=25, tau_refrac=100), label="actorPopulation") sim.external_devices.activate_live_output_for(pre_pop, database_notify_host="localhost", database_notify_port_num=19996) sim.external_devices.activate_live_output_for(input1, database_notify_host="localhost", database_notify_port_num=19998) sim.external_devices.activate_live_output_for(post_pop, database_notify_host="localhost", database_notify_port_num=20000) sim.external_devices.activate_live_output_for(input2,
import cv2 import numpy as np import pyautogui from datetime import datetime from random import randint import sys sim.setup(timestep=1.0) sim.set_number_of_neurons_per_core(sim.IF_curr_exp, 100) numberOfSteps = 12 numberOfActions = 4 stateSpikeInjector = sim.Population(numberOfSteps * numberOfActions, sim.external_devices.SpikeInjector(), label="stateSpikeInjector") actorSpikeInjector = sim.Population(numberOfSteps * numberOfActions, sim.external_devices.SpikeInjector(), label="actorSpikeInjector") statePopulation = sim.Population(numberOfSteps * numberOfActions, sim.IF_curr_exp(tau_syn_E=100, tau_refrac=50), label="statePopulation") actorPopulation = sim.Population(numberOfSteps * numberOfActions, sim.IF_curr_exp(tau_syn_E=25, tau_refrac=100), label="actorPopulation") firstSpikeTrigger = sim.Population(numberOfSteps, sim.external_devices.SpikeInjector(), label="firstSpikeTrigger") sim.external_devices.activate_live_output_for(statePopulation, database_notify_host="localhost", database_notify_port_num=19996) sim.external_devices.activate_live_output_for(stateSpikeInjector, database_notify_host="localhost", database_notify_port_num=19998) sim.external_devices.activate_live_output_for(actorPopulation, database_notify_host="localhost", database_notify_port_num=20000) sim.external_devices.activate_live_output_for(actorSpikeInjector, database_notify_host="localhost", database_notify_port_num=20002) sim.external_devices.activate_live_output_for(firstSpikeTrigger, database_notify_host="localhost", database_notify_port_num=20004) timing_rule = sim.SpikePairRule(tau_plus=50.0, tau_minus=50.0, A_plus=0.001, A_minus=0.001) weight_rule = sim.AdditiveWeightDependence(w_max=5.0, w_min=-5.0) stdp_model = sim.STDPMechanism(timing_dependence=timing_rule, weight_dependence=weight_rule, weight=2, delay=1)
connected_chip_details = { "spinnaker_link_id": 0, } def get_updated_params(params): params.update(connected_chip_details) return params # Setup p.setup(timestep=1.0) # FPGA Retina - Down Polarity retina_pop = p.Population( None, p.external_devices.ExternalFPGARetinaDevice, get_updated_params({ 'retina_key': 0x5, 'mode': p.external_devices.ExternalFPGARetinaDevice.MODE_128, 'polarity': ( p.external_devices.ExternalFPGARetinaDevice.DOWN_POLARITY)}), label='External retina') population = p.Population(256, p.IF_curr_exp(), label='pop_1') p.Projection( retina_pop, population, p.FixedProbabilityConnector(0.1), synapse_type=p.StaticSynapse(weight=0.1)) # q.activate_live_output_for(population) p.run(1000) p.end()
# register python receiver with live spike connection live_spikes_connection.add_receive_callback(RECEIVER_LABEL1, receive_spikes) live_spikes_connection.add_receive_callback(RECEIVER_LABEL2, receive_spikes) # register python injector with injector connection live_spikes_connection.add_start_callback(INJECTOR_LABEL, send_spike) sim.setup(timestep=1.0) input = sim.Population(2, sim.external_devices.SpikeInjector(), label=INJECTOR_LABEL) synfire1 = sim.Population(n_neurons, sim.IF_curr_exp(tau_syn_E=5), label=RECEIVER_LABEL1) synfire2 = sim.Population(n_neurons, sim.IF_curr_exp(tau_syn_E=5), label=RECEIVER_LABEL2) sim.external_devices.activate_live_output_for(synfire1) sim.external_devices.activate_live_output_for(synfire2) loop_conns = list() for i in range(0, n_neurons - 1): single_connection = (i, i + 1, weight_to_spike, delay) loop_conns.append(single_connection) print(loop_conns) input_proj = sim.Projection(input, synfire1,
no_gaps=True, start_time=0, simtime=SIMTIME, eventframe_width=None) sim.setup(timestep=1.0) #first = [i for i in range(1000)] #spike_times = [[i] for i in range(NR)] #spike_times[0] = first input_pop = sim.Population( size=NR, cellclass=sim.SpikeSourceArray(spike_times=spike_times), label="spikes") pop_0 = sim.Population(size=NR, cellclass=sim.IF_curr_exp(), label="1_pre_input") pop_0.set(v_thresh=0.1) pop_1 = sim.Population(size=16, cellclass=sim.IF_curr_exp(), label="1_input") pop_1.set(v_thresh=0.05) #misc.set_cell_params(pop_1, cellparams) pop_2 = sim.Population(size=4, cellclass=sim.IF_curr_exp(), label="2_hidden") pop_2.set(v_thresh=0.1) #misc.set_cell_params(pop_2, cellparams) #pop_2.set(i_offset=s[label]['v_thresh']) # this projection / pop_0 is only used to monitor the input spikes (actually not needed for MLP network) input_proj = sim.Projection(input_pop, pop_0, sim.OneToOneConnector(), synapse_type=sim.StaticSynapse(weight=3, delay=1))
def lancement_sim(cellSourceSpikes, path, weight_input=0, weight_inter=0, max_time=800000, TIME_STEP=TIME_STEP, input_n=input_n, nb_neuron_int=nb_neuron_int, nb_neuron_out=nb_neuron_out, delay=delay, p_conn_in_int=p_conn_in_int, p_conn_int_out=p_conn_int_out, v_tresh=v_tresh): simulator = 'spinnaker' # le max_delay doit être inférieur à 14*time_step sim.setup(timestep=TIME_STEP, min_delay=delay, max_delay=delay * 2) randoms = np.random.rand(100, 1) #defining network topology lif_curr_exp_params = { 'cm': 1.0, # The capacitance of the LIF neuron in nano-Farads 'tau_m': 20.0, # The time-constant of the RC circuit, in milliseconds 'tau_refrac': 5.0, # The refractory period, in milliseconds 'v_reset': -65.0, # The voltage to set the neuron at immediately after a spike 'v_rest': -65.0, # The ambient rest voltage of the neuron 'v_thresh': -(v_tresh), # The threshold voltage at which the neuron will spike 'tau_syn_E': 5.0, # The excitatory input current decay time-constant 'tau_syn_I': 5.0, # The inhibitory input current decay time-constant 'i_offset': 0.0, # A base input current to add each timestep } # Population d'entrée avec comme source le SpikeSourceArray en paramètre Input = sim.Population(input_n, sim.SpikeSourceArray(spike_times=cellSourceSpikes), label="Input") Input.record("spikes") # Définition des types de neurones et des couches intermédiaire, de sortie, ainsi que celle contenant le neurone de l'attention LIF_Intermediate = sim.IF_curr_exp(**lif_curr_exp_params) Intermediate = sim.Population(nb_neuron_int, LIF_Intermediate, label="Intermediate") Intermediate.record(("spikes", "v")) LIF_Output = sim.IF_curr_exp(**lif_curr_exp_params) Output = sim.Population(nb_neuron_out, LIF_Output, label="Output") Output.record(("spikes", "v")) LIF_delayer = sim.IF_curr_exp(**lif_curr_exp_params) Delay_n = sim.Population(1, LIF_delayer, label="Delay") Delay_n.record(("spikes", "v")) # set the stdp mechanisim parameters, we are going to use stdp in both connections between (input-intermediate) adn (intermediate-output) python_rng = NumpyRNG(seed=98497627) delay = delay # (ms) synaptic time delay #A_minus # définition des connexions entre couches de neurones entrée <=> intermédiaire, intermédiaire <=> sortie # vérificatio pour savoir si on est dans le cas de la première simulation par défault ou si on doit injecter les poids if ((weight_input != 0) or (weight_inter != 0)): # cas ou l'on inject les poids Conn_input_inter = sim.Projection( Input, Intermediate, # Le fromListConnector pour injecter les poids connector=sim.FromListConnector(weight_input), receptor_type="excitatory", label="Connection input to intermediate", # des synapses static pour "suprimer" l'apprentissage synapse_type=sim.StaticSynapse()) Conn_inter_output = sim.Projection( Intermediate, Output, # pre and post population connector=sim.FromListConnector(weight_inter), receptor_type="excitatory", label="Connection intermediate to output", synapse_type=sim.StaticSynapse()) else: # cas par défault Conn_input_inter = sim.Projection( Input, Intermediate, connector=sim.FixedProbabilityConnector( p_conn_in_int, allow_self_connections=False), synapse_type=sim.StaticSynapse( weight=RandomDistribution('normal', (3, 2.9), rng=python_rng)), receptor_type="excitatory", label="Connection input to intermediate") Conn_inter_output = sim.Projection( Intermediate, Output, # pre and post population connector=sim.FixedProbabilityConnector( p_conn_int_out, allow_self_connections=False), synapse_type=sim.StaticSynapse( weight=RandomDistribution('normal', (3, 2.9), rng=python_rng)), receptor_type="excitatory", label="Connection intermediate to output") # définition des connexions inhibitrices des couches intermédiaire et de sortie FixedInhibitory_WTA = sim.StaticSynapse(weight=6) WTA_INT = sim.Projection( Intermediate, Intermediate, connector=sim.AllToAllConnector(allow_self_connections=False), synapse_type=FixedInhibitory_WTA, receptor_type="inhibitory", label="Connection WTA") WTA_OUT = sim.Projection( Output, Output, connector=sim.AllToAllConnector(allow_self_connections=False), synapse_type=FixedInhibitory_WTA, receptor_type="inhibitory", label="Connection WTA") # Connexion avec le neurone de l'attention FixedInhibitory_delayer = sim.StaticSynapse(weight=2) Delay_out = sim.Projection( Delay_n, Output, connector=sim.AllToAllConnector(allow_self_connections=False), synapse_type=FixedInhibitory_delayer, receptor_type="inhibitory", label="Connection WTA") Delay_inter = sim.Projection( Intermediate, Delay_n, connector=sim.AllToAllConnector(allow_self_connections=False), synapse_type=FixedInhibitory_delayer, receptor_type="inhibitory", label="Connection WTA") # On précise le nombre de neurone par coeurs au cas ou sim.set_number_of_neurons_per_core(sim.IF_curr_exp, 255) # on arrondie le temps de simulation, sinon avec les callbacks, on a une boucle infinie pour des temps d'arrêts plus précis que la fréquence des callbacks simtime = ceil(max_time) try: #lancement de la simulation sim.run(simtime) #récupération des infos sur les spike des trois couches neo = Output.get_data(variables=["spikes", "v"]) spikes = neo.segments[0].spiketrains #print(spikes) v = neo.segments[0].filter(name='v')[0] neo_in = Input.get_data(variables=["spikes"]) spikes_in = neo_in.segments[0].spiketrains #print(spikes_in) neo_intermediate = Intermediate.get_data(variables=["spikes", "v"]) spikes_intermediate = neo_intermediate.segments[0].spiketrains #print(spikes_intermediate) v_intermediate = neo_intermediate.segments[0].filter(name='v')[0] #print(v_intermediate) sim.reset() sim.end() except: # Si la simulation fail, on set ces deux variables à zéros pour gérer l'erreur dans le script principal v = 0 spikes = 0 # Création et sauvegarde des graphs des graphs si la simluation s'est bien passée, + envoie des sorties de la fonction if (isinstance(spikes, list) and isinstance(v, AnalogSignal)): plot.Figure( # plot voltage for first ([0]) neuron plot.Panel(v, ylabel="Membrane potential (mV)", data_labels=[Output.label], yticks=True, xlim=(0, simtime)), # plot spikes (or in this case spike) plot.Panel(spikes, yticks=True, markersize=5, xlim=(0, simtime)), title="Spiking activity of the output layer during test", annotations="Simulated with {}".format(sim.name())).save( "./Generated_data/tests/" + path + "/output_layer_membrane_voltage_and_spikes.png") plot.Figure( # plot voltage for first ([0]) neuron plot.Panel(v_intermediate, ylabel="Membrane potential (mV)", data_labels=[Output.label], yticks=True, xlim=(0, simtime)), # plot spikes (or in this case spike) plot.Panel(spikes_intermediate, yticks=True, markersize=5, xlim=(0, simtime)), title="Spiking activity of the intermediate layer during test", annotations="Simulated with {}".format(sim.name())).save( "./Generated_data/tests/" + path + "/intermediate_layer_membrane_voltage_and_spikes.png") return v, spikes else: print( "simulation failed with parameters : (l'affichage des paramètres ayant causés le disfonctionnement de la simulation sera traitée à une date ultérieur, merci!)" ) return 0, 0
import pyNN.spiNNaker as sim import pyNN.utility.plotting as plot import matplotlib.pyplot as plt sim.setup(timestep=1.0) sim.set_number_of_neurons_per_core(sim.IF_curr_exp, 100) # Define Input neuron input = sim.Population(1, sim.SpikeSourcePoisson(), label="Input") # Define output neuron pop_1 = sim.Population(1,sim.IF_curr_exp(),label="pop_1") # Connect Input Neuron with Output neuron input_proj=sim.Projection(input,pop_1,sim.OneToOneConnector(),synapse_type=sim.StaticSynapse(weight=5,delay=1)) pop_1.record(["spikes","v"]) input.record(["spikes"]) simtime = 30000 sim.run(simtime) # Input neuron neo_input=input.get_data(variables=["spikes"]) spikes_input=neo_input.segments[0].spiketrains print(spikes_input) print( len(spikes_input[0]) ) # Pop1 neuron neo_pop1=pop_1.get_data(variables=["spikes","v"])
def lancement_sim(cellSourceSpikes, max_time=800000, path="default", TIME_STEP=TIME_STEP, input_n=input_n, nb_neuron_int=nb_neuron_int, nb_neuron_out=nb_neuron_out, delay=delay, p_conn_in_int=p_conn_in_int, p_conn_int_out=p_conn_int_out, a_minus=0.6, a_plus=0.6, tau_minus=12.0, tau_plus=10.0, v_tresh=10.0): simulator = 'spinnaker' sim.setup(timestep=TIME_STEP, min_delay=delay, max_delay=delay * 2) randoms = np.random.rand(100, 1) lif_curr_exp_params = { 'cm': 1.0, # The capacitance of the LIF neuron in nano-Farads 'tau_m': 20.0, # The time-constant of the RC circuit, in milliseconds 'tau_refrac': 5.0, # The refractory period, in milliseconds 'v_reset': -65.0, # The voltage to set the neuron at immediately after a spike 'v_rest': -65.0, # The ambient rest voltage of the neuron 'v_thresh': -(v_tresh), # The threshold voltage at which the neuron will spike 'tau_syn_E': 5.0, # The excitatory input current decay time-constant 'tau_syn_I': 5.0, # The inhibitory input current decay time-constant 'i_offset': 0.0, # A base input current to add each timestep } Input = sim.Population(input_n, sim.SpikeSourceArray(spike_times=cellSourceSpikes), label="Input") Input.record("spikes") LIF_Intermediate = sim.IF_curr_exp(**lif_curr_exp_params) Intermediate = sim.Population(nb_neuron_int, LIF_Intermediate, label="Intermediate") Intermediate.record(("spikes", "v")) LIF_Output = sim.IF_curr_exp(**lif_curr_exp_params) Output = sim.Population(nb_neuron_out, LIF_Output, label="Output") Output.record(("spikes", "v")) LIF_delayer = sim.IF_curr_exp(**lif_curr_exp_params) Delay_n = sim.Population(1, LIF_delayer, label="Delay") Delay_n.record(("spikes", "v")) python_rng = NumpyRNG(seed=98497627) delay = delay # (ms) synaptic time delay # Définition du fonctionnement de la stdp stdp_proj = sim.STDPMechanism( timing_dependence=sim.SpikePairRule(tau_plus=tau_plus, tau_minus=tau_minus, A_plus=a_plus, A_minus=a_minus), weight_dependence=sim.AdditiveWeightDependence(w_min=0.1, w_max=6), weight=RandomDistribution('normal', (3, 2.9), rng=python_rng), delay=delay) Conn_input_inter = sim.Projection( Input, Intermediate, connector=sim.FixedProbabilityConnector(p_conn_in_int, allow_self_connections=False), # synapse type set avec la définition de la stdp pour l'aprentsissage synapse_type=stdp_proj, receptor_type="excitatory", label="Connection input to intermediate") # second projection with stdp Conn_inter_output = sim.Projection( Intermediate, Output, # pre and post population connector=sim.FixedProbabilityConnector(p_conn_int_out, allow_self_connections=False), synapse_type=stdp_proj, receptor_type="excitatory", label="Connection intermediate to output") FixedInhibitory_WTA = sim.StaticSynapse(weight=6) WTA_INT = sim.Projection( Intermediate, Intermediate, connector=sim.AllToAllConnector(allow_self_connections=False), synapse_type=FixedInhibitory_WTA, receptor_type="inhibitory", label="Connection WTA") WTA_OUT = sim.Projection( Output, Output, connector=sim.AllToAllConnector(allow_self_connections=False), synapse_type=FixedInhibitory_WTA, receptor_type="inhibitory", label="Connection WTA") FixedInhibitory_delayer = sim.StaticSynapse(weight=2) Delay_out = sim.Projection( Delay_n, Output, connector=sim.AllToAllConnector(allow_self_connections=False), synapse_type=FixedInhibitory_delayer, receptor_type="inhibitory", label="Connection WTA") Delay_inter = sim.Projection( Intermediate, Delay_n, connector=sim.AllToAllConnector(allow_self_connections=False), synapse_type=FixedInhibitory_delayer, receptor_type="inhibitory", label="Connection WTA") sim.set_number_of_neurons_per_core(sim.IF_curr_exp, 255) # Définition des callbacks pour la récupération de l'écart-type sur les connexions entrée-intermédiaire, intermédiaire-sortie weight_recorder1 = WeightRecorder(sampling_interval=1000.0, projection=Conn_input_inter) weight_recorder2 = WeightRecorder(sampling_interval=1000.0, projection=Conn_inter_output) simtime = ceil(max_time) # Initialisation des tableaux pour la récupération des poids weights_int = [] weights_out = [] try: sim.run(simtime, callbacks=[weight_recorder1, weight_recorder2]) neo = Output.get_data(variables=["spikes", "v"]) spikes = neo.segments[0].spiketrains #print(spikes) v = neo.segments[0].filter(name='v')[0] weights_int = Conn_input_inter.get(["weight"], format="list") neo_in = Input.get_data(variables=["spikes"]) spikes_in = neo_in.segments[0].spiketrains #print(spikes_in) neo_intermediate = Intermediate.get_data(variables=["spikes", "v"]) spikes_intermediate = neo_intermediate.segments[0].spiketrains #print(spikes_intermediate) v_intermediate = neo_intermediate.segments[0].filter(name='v')[0] #print(v_intermediate) weights_out = Conn_inter_output.get(["weight"], format="list") sim.reset() sim.end() except: v = 0 spikes = 0 if (isinstance(spikes, list) and isinstance(v, AnalogSignal)): # Récupération des écart-types standard_deviation_out = weight_recorder2.get_standard_deviations() standard_deviation_int = weight_recorder1.get_standard_deviations() t = np.arange(0., max_time, 1.) # Création et sauvegarde des graphs sur les spikes et écart-types savePath = "./Generated_data/training/" + path + "/intermediate_layer_standard_deviation.png" plt.plot(standard_deviation_int) plt.xlabel("callbacks tick (1s)") plt.ylabel("standard deviation of the weights( wmax=6, wmin=0.1 )") plt.savefig(savePath) plt.clf() savePath = "./Generated_data/training/" + path + "/output_layer_standard_deviation.png" plt.plot(standard_deviation_out) plt.xlabel("callbacks tick") plt.ylabel("standard deviation ( wmax=6, wmin=0.1 )") plt.savefig(savePath) plt.clf() savePath = "./Generated_data/training/" + path + "/output_layer_membrane_voltage_and_spikes.png" plot.Figure( # plot voltage for first ([0]) neuron plot.Panel(v, ylabel="Membrane potential (mV)", data_labels=[Output.label], yticks=True, xlim=(0, simtime)), # plot spikes (or in this case spike) plot.Panel(spikes, yticks=True, markersize=5, xlim=(0, simtime)), title="Spiking activity of the output layer during training", annotations="Simulated with {}".format(sim.name())).save(savePath) savePath = "./Generated_data/training/" + path + "/intermediate_layer_membrane_voltage_and_spikes.png" plot.Figure( # plot voltage for first ([0]) neuron plot.Panel(v_intermediate, ylabel="Membrane potential (mV)", data_labels=[Output.label], yticks=True, xlim=(0, simtime)), # plot spikes (or in this case spike) plot.Panel(spikes_intermediate, yticks=True, markersize=5, xlim=(0, simtime)), title="Spiking activity of the intermediate layer during training", annotations="Simulated with {}".format(sim.name())).save(savePath) return v, spikes, weights_int, weights_out else: print( "simulation failed with parmaters parameters : (l'affichage des paramètres ayant causés le disfonctionnement de la simulation sera traitée à une date ultérieur, merci!)" ) return 0, 0, 0, 0
cell_params_lif = { 'cm': 0.25, 'i_offset': 0, 'tau_m': 20, 'tau_refrac': 2, 'tau_syn_E': 50, 'tau_syn_I': 5, 'v_reset': -70, 'v_rest': -65, 'v_thresh': -55 } sim.set_number_of_neurons_per_core(sim.IF_curr_exp, 100) GEN1_1= sim.Population(1,simSpikeSourceArray(spike_times=[0,8], label="GEN1_1") G1_2= sim.Population(1,sim.IF_curr_exp(**cell_params_lif), label="G1_2") G3_4= sim.Population(1,sim.IF_curr_exp(**cell_params_lif), label="G3_4") G4_5= sim.Population(1,sim.IF_curr_exp(**cell_params_lif), label="G4_5") G2_6= sim.Population(1,sim.IF_curr_exp(**cell_params_lif), label="G2_6") input_GEN1_1G1_2=sim.Projection(GEN1_1,G1_2, sim.OneToOneConnector(), synapse_type=sim.StaticSynapse(weight=1.25, delay=0)) input_G4_5G1_2=sim.Projection(G4_5,G1_2, sim.OneToOneConnector(), synapse_type=sim.StaticSynapse(weight=0.8, delay=0)) input_G4_5G3_4=sim.Projection(G4_5,G3_4, sim.OneToOneConnector(), synapse_type=sim.StaticSynapse(weight=0.9, delay=0)) input_G2_6G4_5=sim.Projection(G2_6,G4_5, sim.OneToOneConnector(), synapse_type=sim.StaticSynapse(weight=1, delay=0)) input_G1_2G2_6=sim.Projection(G1_2,G2_6, sim.OneToOneConnector(), synapse_type=sim.StaticSynapse(weight=1.6, delay=0)) GEN1_1.record(["spikes","v","gsyn_exc"]) simtime =50 sim.run(simtime)