def __init__(self, input_neurons_theta_size, input_neurons_theta_dot_size, liquid_neurons_size, readout_neurons_tau1_size, readout_neurons_tau2_size, output_layer_weight=100.0, thread_num=-1): # Don't make any nest nodes or connections before this line! nest.SetKernelStatus({ "local_num_threads": thread_num if thread_num > 0 else multiprocessing.cpu_count() }) nest.set_verbosity("M_ERROR") # suppress trivial messages self.total_sim_time = 0.0 self.tau1 = np.zeros(readout_neurons_tau1_size) self.tau2 = np.zeros(readout_neurons_tau2_size) self.output_layer_weight = output_layer_weight self.lsm = lsm.Lsm(input_neurons_theta_size, input_neurons_theta_dot_size, liquid_neurons_size, readout_neurons_tau1_size, readout_neurons_tau2_size, output_layer_weight=self.output_layer_weight)
setuptype = '../setupfiles/mc_final_mn256r1.xml' setupfile = '../setupfiles/final_mn256r1_retina_monster.xml' nsetup = pyNCS.NeuroSetup(setuptype, setupfile, prefix=prefix) nsetup.mapper._init_fpga_mapper() chip = nsetup.chips['mn256r1'] chip.configurator._set_multiplexer(0) #populate neurons rcnpop = pyNCS.Population('neurons', 'for fun') rcnpop.populate_by_id(nsetup, 'mn256r1', 'excitatory', neuron_ids) #init liquid state machine print "################# init onchip recurrent connections... [reservoir] " liquid = L.Lsm(rcnpop, cee=0.7, cii=0.3) #c = 0.2 #dim = np.round(np.sqrt(len(liquid.rcn.synapses['virtual_exc'].addr)*c)) use_retina_projections = (liquid.matrix_programmable_rec != 1) liquid.matrix_programmable_exc_inh[ use_retina_projections] = np.random.choice( [0, 1], size=np.sum(use_retina_projections)) liquid.matrix_programmable_w[use_retina_projections] = np.random.choice( [0, 1, 2, 3], size=np.sum(use_retina_projections)) liquid.program_config() ###### configure retina inputpop = pyNCS.Population('', '') inputpop.populate_by_id(nsetup, 'mn256r1', 'excitatory',
# [email protected] # Juan Pablo Carbajal # [email protected] # # Liquid State Machine class mn256r1 # =============================== ### ========================= import packages =============================== import random import numpy as np import time import pyNCS import sys import lsm as L liquid = L.Lsm() #init liquid state machine prob_n_itter = 0.8 t = np.linspace(0, 1, 1e3)[:, None] M = np.random.randn(1, 256) x = t.dot(M) bias = 0.05 * np.random.randn(1, 256) expo = [([1] * 11 + range(5)) * 16] zeros = np.where(np.random.rand(256, 1) > prob_n_itter)[0] def sys(x, bias, expo, zeros): y = x**expo + bias y[:, 1:10] = np.sin(2 * np.pi * 3 * y[:, 1:10]) for i in zeros: y[:, i] = 0 return y
setuptype = '../setupfiles/mc_final_mn256r1.xml' setupfile = '../setupfiles/final_mn256r1_retina_monster.xml' nsetup = pyNCS.NeuroSetup(setuptype, setupfile, prefix=prefix) nsetup.mapper._init_fpga_mapper() chip = nsetup.chips['mn256r1'] chip.configurator._set_multiplexer(0) #populate neurons rcnpop = pyNCS.Population('neurons', 'for fun') rcnpop.populate_by_id(nsetup, 'mn256r1', 'excitatory', neuron_ids) #init liquid state machine print "################# init onchip recurrent connections... [reservoir] " liquid = L.Lsm(rcnpop, cee=0.55, cii=0.25) #c = 0.2 #dim = np.round(np.sqrt(len(liquid.rcn.synapses['virtual_exc'].addr)*c)) if (use_retina): use_retina_projections = (liquid.matrix_programmable_rec != 1) liquid.matrix_programmable_exc_inh[ use_retina_projections] = np.random.choice( [0, 1], size=np.sum(use_retina_projections)) liquid.matrix_programmable_w[ use_retina_projections] = np.random.choice( [0, 1, 2, 3], size=np.sum(use_retina_projections)) liquid.program_config() ###### configure retina inputpop = pyNCS.Population('', '')
setuptype = '../setupfiles/mc_final_mn256r1.xml' setupfile = '../setupfiles/final_mn256r1_retina_monster.xml' nsetup = pyNCS.NeuroSetup(setuptype, setupfile, prefix=prefix) nsetup.mapper._init_fpga_mapper() chip = nsetup.chips['mn256r1'] chip.configurator._set_multiplexer(0) #populate neurons rcnpop = pyNCS.Population('neurons', 'for fun') rcnpop.populate_by_id(nsetup, 'mn256r1', 'excitatory', neuron_ids) #init liquid state machine print "################# init onchip recurrent connections... [reservoir] " liquid = L.Lsm(rcnpop, cee=0.8, cii=0.2) #c = 0.2 #dim = np.round(np.sqrt(len(liquid.rcn.synapses['virtual_exc'].addr)*c)) use_retina_projections = (liquid.matrix_programmable_rec != 1) liquid.matrix_programmable_exc_inh[ use_retina_projections] = np.random.choice( [0, 1], size=np.sum(use_retina_projections)) liquid.matrix_programmable_w[use_retina_projections] = np.random.choice( [0, 1, 2, 3], size=np.sum(use_retina_projections)) liquid.program_config() ###### configure retina inputpop = pyNCS.Population('', '') inputpop.populate_by_id(nsetup, 'mn256r1', 'excitatory',
do_figs_encoding = False #populations divisible by 2 for encoders neuron_ids = np.linspace(0, 255, 256) npops = len(neuron_ids) #setup prefix = '../' setuptype = '../setupfiles/mc_final_mn256r1.xml' setupfile = '../setupfiles/final_mn256r1_retina_monster.xml' nsetup = pyNCS.NeuroSetup(setuptype, setupfile, prefix=prefix) chip = nsetup.chips['mn256r1'] nsetup.mapper._init_fpga_mapper() chip.configurator._set_multiplexer(0) #populate neurons rcnpop = pyNCS.Population('neurons', 'for fun') rcnpop.populate_by_id(nsetup, 'mn256r1', 'excitatory', neuron_ids) #init nef on neuromorphic chips import lsm liquid = lsm.Lsm(rcnpop) #init liquid state machine ntrials = 150 #same projection stimulus, but regenerated poisson trains inputs, outputs = liquid.stimulate_reservoir(trials=ntrials) for trial in range(ntrials): np.savetxt("lsm/inputs_correlated_trial_" + str(trial) + ".txt", inputs[trial]) np.savetxt("lsm/outputs_correlated_trial_" + str(trial) + ".txt", outputs[trial])