lrnmap[0, 1] = 0 lrnmap[0, 2] = 1 cfg.core_cfgs[0].lrnmap = lrnmap # Synaptic weights W = np.zeros([N_UNITS, N_UNITS, N_STATES[0]], 'int') W[0, N_INPUTS[0], 2] = 100 W[1, N_INPUTS[0], 1] = 0 print(W) # Adjacent matrix CW = np.zeros(W.shape, dtype='int') CW[0, N_INPUTS[0], 2] = True CW[1, N_INPUTS[0], 1] = True wgt_table, ptr_table = gen_ptr_wgt_table_from_W_CW(W, CW, []) np.set_printoptions(threshold=np.nan) cfg.core_cfgs[0].wgt_table = wgt_table cfg.core_cfgs[0].ptr_table = ptr_table # Generate spike events (external events) # rates = np.random.randint(5, 20, (N_INPUTS,), dtype='i') # rates = np.hstack([np.random.randint(5, 10, (N_INPUTS[0]//2,), 'int'), # np.random.randint(10, 20, (N_INPUTS[0]//2,), 'int')]) # Build external spikes freqs = 5 SL = PeriodicPrePostSpikingStimulus(freqs, -5, sim_ticks) import copy spk0 = copy.deepcopy(SL) ext_evts_data = nsat.exportAER(SL)
def setup(): print('Begin %s:setup()' % (os.path.splitext(os.path.basename(__file__))[0])) pyST.STCreate.seed(100) N_CORES = 1 # Number of cores N_NEURONS = [17] # Number of neurons per core N_INPUTS = [16] # Number of inputes per core N_STATES = [8] # Number of states per core N_UNITS = N_INPUTS[0] + N_NEURONS[0] # Total number of units # Constants XMAX = nsat.XMAX XMIN = nsat.XMIN OFF = -16 MAX = nsat.MAX MIN = nsat.XMIN # Class instance cfg = nsat.ConfigurationNSAT(sim_ticks=sim_ticks, N_CORES=N_CORES, N_INPUTS=N_INPUTS, N_NEURONS=N_NEURONS, N_STATES=N_STATES, monitor_states=True, ben_clock=True) # Transition matrix group 0 cfg.core_cfgs[0].A[0] = [[-3, OFF, OFF, OFF, OFF, OFF, OFF, OFF], [2, -5, OFF, OFF, OFF, OFF, OFF, OFF], [OFF, OFF, -7, -5, OFF, OFF, OFF, OFF], [OFF, OFF, OFF, 0, OFF, OFF, OFF, OFF], [OFF, OFF, OFF, OFF, OFF, OFF, OFF, OFF], [OFF, OFF, OFF, OFF, OFF, OFF, OFF, OFF], [OFF, OFF, OFF, OFF, OFF, OFF, OFF, OFF], [OFF, OFF, OFF, OFF, OFF, OFF, OFF, OFF]] # Sign matrix group 0 cfg.core_cfgs[0].sA[0] = [[-1, 1, 1, 1, 1, 1, 1, 1], [1, -1, 1, 1, 1, 1, 1, 1], [1, 1, -1, -1, 1, 1, 1, 1], [1, 1, 1, -1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1]] # Transition matrix group 1 cfg.core_cfgs[0].A[1] = [[0, OFF, OFF, OFF, OFF, OFF, OFF, OFF], [0, -10, OFF, OFF, OFF, OFF, OFF, OFF], [0, OFF, -8, OFF, OFF, OFF, OFF, OFF], [OFF, OFF, OFF, OFF, OFF, OFF, OFF, OFF], [OFF, OFF, OFF, OFF, OFF, OFF, OFF, OFF], [OFF, OFF, OFF, OFF, OFF, OFF, OFF, OFF], [OFF, OFF, OFF, OFF, OFF, OFF, OFF, OFF], [OFF, OFF, OFF, OFF, OFF, OFF, OFF, OFF]] # Sign matrix group 1 cfg.core_cfgs[0].sA[1] = [[-1, 1, 1, 1, 1, 1, 1, 1], [+1, -1, 1, 1, 1, 1, 1, 1], [-1, 1, -1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1]] # Transition matrix group 2 cfg.core_cfgs[0].A[2] = [[0, OFF, OFF, OFF, OFF, OFF, OFF, OFF], [-3, OFF, OFF, OFF, OFF, OFF, OFF, OFF], [OFF, -13, -6, OFF, OFF, OFF, OFF, OFF], [OFF, -15, OFF, -8, OFF, OFF, OFF, OFF], [0, OFF, OFF, OFF, OFF, OFF, OFF, OFF], [OFF, OFF, OFF, OFF, -7, -8, OFF, OFF], [OFF, OFF, OFF, OFF, -7, OFF, -3, OFF], [OFF, OFF, OFF, OFF, OFF, OFF, OFF, OFF]] # Sign matrix group 2 cfg.core_cfgs[0].sA[2] = [[-1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1], [1, 1, -1, 1, 1, 1, 1, 1], [1, -1, 1, -1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, -1, 1, 1], [1, 1, 1, 1, -1, 1, -1, 1], [1, 1, 1, 1, 1, 1, 1, 1]] # Bias cfg.core_cfgs[0].b[0] = np.array([-12000, 0, -7, 0, 0, 0, 0, 0], 'int') cfg.core_cfgs[0].b[1] = np.array([-40, 0, 0, 0, 0, 0, 0, 0], dtype='int') cfg.core_cfgs[0].b[2] = np.array([-40, 0, 0, 0, 0, 0, 0, 0], dtype='int') # Threshold cfg.core_cfgs[0].t_ref[0] = 0 # cfg.core_cfgs[0].Xth[0] = 30 # Spike increment value cfg.core_cfgs[0].XspikeIncrVal[1] = np.array([-1000] + [0] * 7, 'int') # Additive noise variance cfg.core_cfgs[0].sigma[0] = np.array([15000] + [0] * 7, 'int') # refractory period cfg.core_cfgs[0].t_ref[0] = 0 # Reset value cfg.core_cfgs[0].Xreset[0] = np.array([0] + [XMAX] * 7, 'int') # Turn reset on cfg.core_cfgs[0].XresetOn[0] = np.array([True] + [False] * 7, 'bool') cfg.core_cfgs[0].XresetOn[1] = np.array([False] * 8, 'bool') cfg.core_cfgs[0].XresetOn[2] = np.array([False] * 8, 'bool') # Mapping function between neurons and NSAT parameters groups cfg.core_cfgs[0].nmap = np.zeros((N_NEURONS[0], ), dtype='int') cfg.core_cfgs[0].nmap[-2] = 1 cfg.core_cfgs[0].nmap[-1] = 2 # Synaptic strength from scipy.linalg import toeplitz col = np.zeros((N_INPUTS[0] - 1, )) col[0] = 1 row = np.zeros((N_NEURONS[0] - 2, )) row[0:3] = np.array([1, 2, 1]) T = toeplitz(col, row) W = np.zeros((N_UNITS, N_UNITS, N_STATES[0]), 'i') W[:N_INPUTS[0] - 1, N_INPUTS[0]:-2, 1] = T W[N_INPUTS[0]:, N_UNITS - 2, 1] = 100 W[N_INPUTS[0]:, N_UNITS - 2, 2] = 100 W[N_INPUTS[0]:, N_UNITS - 1, 2] = 1 W[N_INPUTS[0]:, N_UNITS - 1, 3] = 1 W[N_INPUTS[0] - 1, N_UNITS - 1, 5] = 100 W[N_INPUTS[0] - 1, N_UNITS - 1, 6] = 100 CW = W.astype('bool') # np.set_printoptions(threshold=np.nan) wgt_table, ptr_table = gen_ptr_wgt_table_from_W_CW(W, CW, []) np.set_printoptions(threshold=np.nan) cfg.core_cfgs[0].wgt_table = wgt_table cfg.core_cfgs[0].ptr_table = ptr_table # Generate external events firing rates from 5 to 50 inc by 5 freqs = np.random.randint(300, 400, (N_INPUTS[0], )) SL = RegularSpikingStimulus(freqs, sim_ticks) # SL.raster_plot() ext_evts_data = nsat.exportAER(SL) # Set external events cfg.set_ext_events(ext_evts_data) # Write C NSAT parameters binary files c_nsat_writer = nsat.C_NSATWriter(cfg, path='/tmp', prefix='test_td') c_nsat_writer.write() print('End %s:setup()' % (os.path.splitext(os.path.basename(__file__))[0]))
def setup(): print('Begin %s:setup()' % (os.path.splitext(os.path.basename(__file__))[0])) np.random.seed(30) # Numpy RNG seed sim_ticks = 5000 # Simulation ticks N_CORES = 1 # Number of cores N_NEURONS = [10] # Number of neurons N_INPUTS = [10] # Number of inputs N_STATES = [4] # Number of states N_UNITS = N_INPUTS[0] + N_NEURONS[0] # Total number of units # Constants XMAX = nsat.XMAX XMIN = nsat.XMIN OFF = -16 MAX = nsat.MAX MIN = nsat.XMIN # Main class instance cfg = nsat.ConfigurationNSAT(sim_ticks=sim_ticks, N_CORES=N_CORES, N_INPUTS=N_INPUTS, N_NEURONS=N_NEURONS, N_STATES=N_STATES, monitor_states=True, ben_clock=True) # Transition matrix cfg.core_cfgs[0].A[0] = [[-1, OFF, OFF, OFF], [OFF, OFF, OFF, OFF], [OFF, OFF, OFF, OFF], [OFF, OFF, OFF, OFF]] # Sign matrix cfg.core_cfgs[0].sA[0] = [[-1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]] # Bias cfg.core_cfgs[0].b[0] = np.array([30, 0, 0, 0], dtype='int') # Threshold cfg.core_cfgs[0].Xth[0] = 100 # Reset value cfg.core_cfgs[0].Xreset[0] = np.array([0, XMAX, XMAX, XMAX], 'int') # Turn reset on cfg.core_cfgs[0].XresetOn[0] = np.array([True, False, False, False], 'bool') # Synaptic strengths gain cfg.core_cfgs[0].Wgain[0] = 1 # Mapping neurons and NSAT parameters groups cfg.core_cfgs[0].nmap = np.zeros((N_NEURONS[0], ), dtype='int') # Synaptic strengths matrix W = np.zeros([N_UNITS, N_UNITS, 4], 'int') W[0, 10, 0] = 50 W[1, 11, 0] = 50 W[2, 12, 0] = 50 W[3, 13, 0] = 50 W[4, 14, 0] = 50 W[5, 15, 0] = 50 W[6, 16, 0] = 50 W[7, 17, 0] = 50 W[8, 18, 0] = 50 W[9, 19, 0] = 50 # Adjacent matrix CW = np.zeros(W.shape, dtype='int') CW[0, 10, 0] = 1 CW[1, 11, 0] = 1 CW[2, 12, 0] = 1 CW[3, 13, 0] = 1 CW[4, 14, 0] = 1 CW[5, 15, 0] = 1 CW[6, 16, 0] = 1 CW[7, 17, 0] = 1 CW[8, 18, 0] = 1 CW[9, 19, 0] = 1 wgt_table, ptr_table = gen_ptr_wgt_table_from_W_CW(W, CW, []) np.set_printoptions(threshold=np.nan) cfg.core_cfgs[0].wgt_table = wgt_table cfg.core_cfgs[0].ptr_table = ptr_table # Generate external events freqs = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50] ext_evts_data = RegularSpikingStimulus(freqs, sim_ticks) # Set external events cfg.set_ext_events(ext_evts_data) # Write C NSAT parameters files c_nsat_writer = nsat.C_NSATWriter(cfg, path='/tmp', prefix='test_ext_evts_wgain') c_nsat_writer.write() # Write Intel FPGA hex parameters files # intel_fpga_writer = nsat.IntelFPGAWriter(cfg, path='.', # prefix='test_ext_evts_wgain') # intel_fpga_writer.write() # intel_fpga_writer.write_globals() print('End %s:setup()' % (os.path.splitext(os.path.basename(__file__))[0])) return c_nsat_writer.fname
def setup(): print('Begin %s:setup()' % (os.path.splitext(os.path.basename(__file__))[0])) sim_ticks = 100 # Simulation time N_CORES = 2 # Number of cores N_NEURONS = [1, 1] # Number of neurons per core N_INPUTS = [5, 5] # Number of inputes per core N_STATES = [2, 2] # Number of states per core # Constants XMAX = nsat.XMAX OFF = -16 # Class instance cfg = nsat.ConfigurationNSAT(sim_ticks=sim_ticks, N_CORES=N_CORES, N_INPUTS=N_INPUTS, N_NEURONS=N_NEURONS, N_STATES=N_STATES, monitor_states=True, ben_clock=True) for i in range(N_CORES): # Transition matrix cfg.core_cfgs[i].A[0] = [[-1, 1], [-1, OFF]] # Sign matrix cfg.core_cfgs[i].sA[0] = [[-1, 1], [1, -1]] # Bias cfg.core_cfgs[i].b[0] = np.array([0, 0], dtype='int') # Threshold cfg.core_cfgs[i].Xth[0] = 100 # Reset value cfg.core_cfgs[i].Xreset[0] = np.array([0, XMAX], 'int') # Turn reset on cfg.core_cfgs[i].XresetOn[0] = np.array([True, False], 'bool') W = np.zeros((6, 6, 2), dtype='i') W[0, 5, 0] = 10 W[1, 5, 0] = 10 W[2, 5, 0] = 0 W[3, 5, 0] = 0 W[3, 5, 0] = 0 CW = np.zeros(W.shape, 'i') CW[0, 5, 0] = 1 CW[1, 5, 0] = 1 CW[2, 5, 0] = 1 CW[3, 5, 0] = 1 CW[3, 5, 0] = 1 wgt_table, ptr_table = gen_ptr_wgt_table_from_W_CW(W, CW, []) np.set_printoptions(threshold=np.nan) cfg.core_cfgs[i].wgt_table = wgt_table cfg.core_cfgs[i].ptr_table = ptr_table # Mapping function between neurons and NSAT parameters groups cfg.core_cfgs[i].nmap = np.zeros((N_NEURONS[0], ), dtype='int') cfg.ext_evts = True # Write C NSAT parameters binary files c_nsat_writer = nsat.C_NSATWriter(cfg, path='/tmp', prefix='test_davis') c_nsat_writer.write() build_davis_file("/tmp/test_davis_davis_events", num_ticks=sim_ticks) print('End %s:setup()' % (os.path.splitext(os.path.basename(__file__))[0])) return c_nsat_writer.fname
def setup(): print('Begin %s:setup()' % (os.path.splitext(os.path.basename(__file__))[0])) N_CORES = 1 # Number of cores N_NEURONS = [2] # Number of neurons per core N_INPUTS = [1] # Number of inputs per core N_STATES = [4] # Number of states per core N_UNITS = N_INPUTS[0] + N_NEURONS[0] # Total units # Constants XMAX = nsat.XMAX XMIN = nsat.XMIN OFF = -16 MAX = nsat.MAX MIN = nsat.XMIN # Configuration NSAT class instance cfg = nsat.ConfigurationNSAT(sim_ticks=sim_ticks, N_CORES=N_CORES, N_INPUTS=N_INPUTS, N_NEURONS=N_NEURONS, N_STATES=N_STATES, monitor_states=True, monitor_spikes=True, monitor_weights=True, plasticity_en=[True], ben_clock=True) # Transition matrix group 0 cfg.core_cfgs[0].A[0] = [[-5, OFF, OFF, OFF], [OFF, OFF, OFF, OFF], [OFF, OFF, OFF, OFF], [OFF, OFF, OFF, OFF]] # Transition matrix group 1 cfg.core_cfgs[0].A[1] = [[-2, OFF, OFF, OFF], [0, -5, OFF, OFF], [OFF, OFF, 0, OFF], [OFF, OFF, OFF, OFF]] # Sign matrix group 0 cfg.core_cfgs[0].sA[0] = [[-1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]] # Sign matrix group 1 cfg.core_cfgs[0].sA[1] = [[-1, 1, 1, 1], [1, -1, 1, 1], [1, 1, -1, 1], [1, 1, 1, -1]] # Threshold cfg.core_cfgs[0].Xth[0] = 100 cfg.core_cfgs[0].Xth[1] = 175 # Refractory period cfg.core_cfgs[0].t_ref[1] = 0 cfg.core_cfgs[0].t_ref[0] = 120 # Bias cfg.core_cfgs[0].b[0] = [5, 0, 0, 0] cfg.core_cfgs[0].b[1] = [5, 0, 5, 0] # Initial conditions cfg.core_cfgs[0].Xinit[0] = np.array([0, 0, 0, 0], 'int') # Reset value cfg.core_cfgs[0].Xreset[0] = [0, MAX, MAX, MAX] cfg.core_cfgs[0].Xreset[1] = [0, MAX, MAX, MAX] # Turn on reset cfg.core_cfgs[0].XresetOn[0] = [True, False, False, False] cfg.core_cfgs[0].XresetOn[1] = [True, False, False, False] # Enable plasticity per state cfg.core_cfgs[0].plastic[1] = True # Enable STDP per state group 0 cfg.core_cfgs[0].stdp_en[0] = True # Enable STDP per state group 1 cfg.core_cfgs[0].stdp_en[1] = True # Global modulator state group 1 cfg.core_cfgs[0].modstate[1] = 2 # Set NSAT parameters mapping function nmap = np.zeros((N_NEURONS[0], ), dtype='int') nmap[0] = 0 nmap[1] = 1 cfg.core_cfgs[0].nmap = nmap # Set learning parameters mapping function lrnmap = np.zeros((nsat.N_GROUPS, N_STATES[0]), dtype='int') lrnmap[nmap[0], 1] = 0 lrnmap[nmap[1], 1] = 1 cfg.core_cfgs[0].lrnmap = lrnmap # Synaptic weights W = np.zeros([N_UNITS, N_UNITS, N_STATES[0]], 'int') W[0, 1, 0] = 40 W[1, 2, 1] = 50 # Adjacent matrix CW = np.zeros(W.shape, dtype='int') CW[0, 1, 0] = True CW[1, 2, 1] = True wgt_table, ptr_table = gen_ptr_wgt_table_from_W_CW(W, CW, []) np.set_printoptions(threshold=np.nan) cfg.core_cfgs[0].wgt_table = wgt_table cfg.core_cfgs[0].ptr_table = ptr_table # Build external events (spikes) freqs = [5] ext_evts_data = RegularSpikingStimulus(freqs, sim_ticks) cfg.set_ext_events(ext_evts_data) # Write C NSAT parameters binary files c_nsat_writer = nsat.C_NSATWriter(cfg, path='/tmp', prefix='test_two_neurons_stdp') c_nsat_writer.write() # Write Intel FPGA parameters hex files ## intel_fpga_writer = nsat.IntelFPGAWriter(cfg, path='.', ## prefix='test_two_neurons_stdp') ## intel_fpga_writer.write() ## intel_fpga_writer.write_globals() print('End %s:setup()' % (os.path.splitext(os.path.basename(__file__))[0]))
def setup(): global SL print('Begin %s:setup()' % (os.path.splitext(os.path.basename(__file__))[0])) N_CORES = 1 # Number of cores N_NEURONS = [1] # Number of neurons per core (list) N_INPUTS = [1] # Number of inputs per core (list) N_STATES = [4] # Number of states per core (list) N_UNITS = N_INPUTS[0] + N_NEURONS[0] # Total number of units # Constants XMAX = nsat.XMAX XMIN = nsat.XMIN OFF = -16 MAX = nsat.MAX MIN = nsat.XMIN # Main class instance cfg = nsat.ConfigurationNSAT(sim_ticks=sim_ticks, N_CORES=N_CORES, N_INPUTS=N_INPUTS, N_NEURONS=N_NEURONS, N_STATES=N_STATES, monitor_states=True, monitor_weights=True, monitor_spikes=True, plasticity_en=[True], ben_clock=True) # Transition matrix A (parameters group 0) cfg.core_cfgs[0].A[0] = [[-5, OFF, OFF, OFF], [2, -5, OFF, OFF], [OFF, OFF, -7, OFF], [OFF, OFF, OFF, OFF]] # Transition matrix A (parameters group 1) cfg.core_cfgs[0].A[1] = [[OFF, OFF, OFF, OFF], [OFF, OFF, OFF, OFF], [OFF, OFF, OFF, OFF], [OFF, OFF, OFF, OFF]] # Sign matrix A (parameters group 0) cfg.core_cfgs[0].sA[0] = [[-1, 1, 1, 1], [1, -1, 1, 1], [1, 1, -1, 1], [1, 1, 1, -1]] # Bias cfg.core_cfgs[0].b[0] = [0, 0, 0, 0] # Threshold cfg.core_cfgs[0].Xth[0] = 25000 # Initial conditions cfg.core_cfgs[0].Xinit[0] = np.array([[0, 0, 0, 0] for _ in range(N_NEURONS[0])], 'int') # Reset value cfg.core_cfgs[0].Xreset[0] = np.array([0, MAX, MAX, MAX], 'int') # Turn reset on cfg.core_cfgs[0].XresetOn[0] = np.array([True, False, False, False], 'bool') # STDP kernel height of acausal part cfg.core_cfgs[0].hiac = [[-1, 4, 0] for _ in range(8)] cfg.core_cfgs[0].plastic[0] = True # Plastic states group 0 cfg.core_cfgs[0].stdp_en[0] = False # STDP enabled for group 0 cfg.core_cfgs[0].sigma[0] = [0, 0, 5, 0] # Additive noise cfg.core_cfgs[0].modstate[0] = 2 # Global modulator state cfg.core_cfgs[0].t_ref[0] = 40 # Refractory period # Mapping between neurons and parameter groups cfg.core_cfgs[0].nmap = np.zeros((N_NEURONS[0],), dtype='int') # Synaptic weights W = np.zeros([N_UNITS, N_UNITS, N_STATES[0]], 'int') W[0, 1, 1] = 100 # Adjacent matrix CW = np.zeros(W.shape, dtype='int') CW[0, 1, 1] = 1 wgt_table, ptr_table = gen_ptr_wgt_table_from_W_CW(W, CW, []) np.set_printoptions(threshold=np.nan) cfg.core_cfgs[0].wgt_table = wgt_table cfg.core_cfgs[0].ptr_table = ptr_table # Generate external event spikes (firing rate 50Hz) stim = [50] SL = SimSpikingStimulus(stim, t_sim=sim_ticks) ext_evts_data = nsat.exportAER(SL) # Set external events cfg.set_ext_events(ext_evts_data) # Write the C NSAT parameters binary files c_nsat_writer = nsat.C_NSATWriter(cfg, path='/tmp', prefix='test_modstate') c_nsat_writer.write() # Write Intel FPGA parameters hex files # intel_fpga_writer = nsat.IntelFPGAWriter(cfg, path='.', # prefix='test_modstate') # intel_fpga_writer.write() # intel_fpga_writer.write_globals() print('End %s:setup()' % (os.path.splitext(os.path.basename(__file__))[0]))
def setup(): global SL print('Begin %s:setup()' % (os.path.splitext(os.path.basename(__file__))[0])) N_CORES = 1 # Number of cores N_test = 2 # Number of tests Nv = 100 # Visible neurons Nh = 100 # Hidden neurons N_NEURONS = [Nh] # Total number of inputes per core N_INPUTS = [Nv] # Total number of inputs per core N_STATES = [4] # Number of states per core N_UNITS = N_INPUTS[0] + N_NEURONS[0] # Total number of units # Constants XMAX = nsat.XMAX XMIN = nsat.XMIN OFF = -16 MAX = nsat.MAX MIN = nsat.XMIN # Main class instance cfg = nsat.ConfigurationNSAT(sim_ticks=sim_ticks, N_CORES=N_CORES, N_INPUTS=N_INPUTS, N_NEURONS=N_NEURONS, N_STATES=N_STATES, monitor_states=True, ben_clock=True) # Transition matrix cfg.core_cfgs[0].A[0] = [[-3, OFF, OFF, OFF], [2, -5, OFF, OFF], [OFF, OFF, -7, -5], [OFF, OFF, OFF, 0]] # Sign matrix cfg.core_cfgs[0].sA[0] = [[-1, 1, 1, 1], [1, -1, 1, 1], [1, 1, -1, -1], [1, 1, 1, -1]] # Bias cfg.core_cfgs[0].b[0] = [-12000, 0, -7, 0] # Refractory period cfg.core_cfgs[0].t_ref[0] = 40 # Initial conditions cfg.core_cfgs[0].Xinit[0] = np.zeros((N_STATES[0], ), 'int') # Reset value cfg.core_cfgs[0].Xreset[0] = np.array([0, MAX, MAX, MAX], 'int') # Turn on reset cfg.core_cfgs[0].XresetOn[0] = np.array([True, False, False, False], 'bool') # Spike increment value cfg.core_cfgs[0].XspikeIncrVal[1] = np.array([-1000, 0, 0, 0], 'int') # Additive noise variance cfg.core_cfgs[0].sigma[0] = np.array([15000, 0, 0, 0], 'int') # Set parameters cfg.core_cfgs[0].nmap = np.zeros((N_NEURONS[0], ), dtype='int') # Set weight matrix extW = np.zeros([N_INPUTS[0], N_NEURONS[0], N_STATES[0]]) extCW = np.zeros([N_INPUTS[0], N_NEURONS[0], N_STATES[0]]) extW[:Nv, :Nh, 1] = np.eye(N_INPUTS[0]) * 127 extCW[:Nv, :Nh, 1] = np.eye(N_INPUTS[0]).astype('bool') W = np.zeros([N_UNITS, N_UNITS, N_STATES[0]], 'int') W[:N_INPUTS[0], N_INPUTS[0]:] = extW # Set adjacent matrix CW = np.zeros([N_UNITS, N_UNITS, N_STATES[0]], 'int') CW[:N_INPUTS[0], N_INPUTS[0]:] = extCW wgt_table, ptr_table = gen_ptr_wgt_table_from_W_CW(W, CW, []) np.set_printoptions(threshold=np.nan) cfg.core_cfgs[0].wgt_table = wgt_table cfg.core_cfgs[0].ptr_table = ptr_table # Set external events stim = np.linspace(1, 1000, N_NEURONS[0]) ext_evts_data = nsat.exportAER( SimSpikingStimulus(stim, sim_ticks, t_sim=sim_ticks)) cfg.set_ext_events(ext_evts_data) # Write C NSAT parameters binary files c_nsat_writer = nsat.C_NSATWriter(cfg, path='/tmp', prefix='test_sigmoid_ext') c_nsat_writer.write() print('End %s:setup()' % (os.path.splitext(os.path.basename(__file__))[0])) return c_nsat_writer.fname
def setup(): global SL print('Begin %s:setup()' % (os.path.splitext(os.path.basename(__file__))[0])) N_CORES = 1 # Number of cores N_NEURONS = [1] # Number of neurons per core (list) N_INPUTS = [1000] # Number of inputs per core (list) N_STATES = [4] # Number of states per core (list) N_UNITS = N_INPUTS[0] + N_NEURONS[0] # Total inputs # Constants XMAX = nsat.XMAX XMIN = nsat.XMIN OFF = -16 MAX = nsat.MAX MIN = nsat.XMIN # Main class instance cfg = nsat.ConfigurationNSAT(sim_ticks=sim_ticks, N_CORES=N_CORES, N_INPUTS=N_INPUTS, N_NEURONS=N_NEURONS, N_STATES=N_STATES, monitor_states=True, monitor_spikes=True, w_check=False, tstdpmax=[100], monitor_weights_final=True, plasticity_en=[True], ben_clock=True) # Transition matrix cfg.core_cfgs[0].A[0] = [[-1, OFF, OFF, OFF], [0, -2, OFF, OFF], [OFF, OFF, 0, OFF], [OFF, OFF, OFF, OFF]] # Sign matrix cfg.core_cfgs[0].sA[0] = [[-1, 1, 1, 1], [1, -1, 1, 1], [1, 1, -1, 1], [1, 1, 1, -1]] # Refractory period cfg.core_cfgs[0].t_ref[0] = 20 # Threshold cfg.core_cfgs[0].Xth[0] = 25 # Bias cfg.core_cfgs[0].b[0] = [0, 0, 1, 0] # Initial conditions cfg.core_cfgs[0].Xinit[0] = np.array([0, 0, 0, 0], 'int') # Reset value cfg.core_cfgs[0].Xreset[0] = [0, MAX, MAX, MAX] # Turn reset on cfg.core_cfgs[0].XresetOn[0] = [True, False, False, False] # Enable plasticity at states cfg.core_cfgs[0].plastic[0] = True # Enable STDP cfg.core_cfgs[0].stdp_en[0] = True # Global modulator state cfg.core_cfgs[0].modstate[0] = 2 # Parameters for the STDP kernel function # cfg.core_cfgs[0].tstdp = np.array([32 for _ in rNLRN_GROUPS], 'int') # cfg.core_cfgs[0].tca = np.array([[6, 15] for _ in rNLRN_GROUPS], 'int') # cfg.core_cfgs[0].hica = np.array([[2, 1, 0] for _ in rNLRN_GROUPS], 'int') # cfg.core_cfgs[0].sica = np.array([[1, 1, 1] for _ in rNLRN_GROUPS], 'int') # cfg.core_cfgs[0].tac = np.array([[6, 15] for _ in rNLRN_GROUPS], 'int') # cfg.core_cfgs[0].hiac = np.array([[-16, -16, 16] for _ in rNLRN_GROUPS], # 'int') # cfg.core_cfgs[0].siac = np.array([[-1, -1, -1] for _ in rNLRN_GROUPS], # 'int') # Set parameters mapping cfg.core_cfgs[0].nmap = np.zeros((N_NEURONS[0], ), dtype='int') # Synaptic weights W = np.zeros([N_UNITS, N_UNITS, N_STATES[0]], 'int') W[:N_INPUTS[0], N_INPUTS[0], 1] = 50 # Adjacent matrix CW = np.zeros(W.shape, dtype='int') CW[:N_INPUTS[0], N_INPUTS[0], 1] = True wgt_table, ptr_table = gen_ptr_wgt_table_from_W_CW(W, CW, []) np.set_printoptions(threshold=np.nan) cfg.core_cfgs[0].wgt_table = wgt_table cfg.core_cfgs[0].ptr_table = ptr_table # Generate spike events (external events) # rates = np.random.randint(5, 20, (N_INPUTS,), dtype='i') rates = np.hstack([ np.random.randint(5, 10, (N_INPUTS[0] // 2, ), 'int'), np.random.randint(10, 20, (N_INPUTS[0] // 2, ), 'int') ]) SL = SimSpikingStimulus(rates, t_sim=sim_ticks) ext_evts_data = nsat.exportAER(SL) cfg.set_ext_events(ext_evts_data) # Write the C NSAT parameters binary files c_nsat_writer = nsat.C_NSATWriter(cfg, path='/tmp', prefix='test_stdp') c_nsat_writer.write() print('End %s:setup()' % (os.path.splitext(os.path.basename(__file__))[0])) return c_nsat_writer.fname
def setup(): print('Begin %s:setup()' % (os.path.splitext(os.path.basename(__file__))[0])) np.random.seed(30) sim_ticks = 5000 N_CORES = 2 N_NEURONS = [100, 100] N_INPUTS = [100, 100] N_STATES = [4, 4] N_UNITS = [sum(i) for i in zip(N_INPUTS, N_NEURONS)] XMAX = nsat.XMAX XMIN = nsat.XMIN OFF = -16 MAX = nsat.MAX MIN = nsat.XMIN cfg = nsat.ConfigurationNSAT(sim_ticks=sim_ticks, N_CORES=N_CORES, N_INPUTS=N_INPUTS, N_NEURONS=N_NEURONS, N_STATES=N_STATES, monitor_states=True, ben_clock=True) for i in range(N_CORES): cfg.core_cfgs[i].A[0] = [[-1, OFF, OFF, OFF], [OFF, OFF, OFF, OFF], [OFF, OFF, OFF, OFF], [OFF, OFF, OFF, OFF]] cfg.core_cfgs[i].sA[0] = [[-1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]] # if i == 1: # cfg.core_cfgs[i].A[0] = [[-2, OFF, OFF, OFF], # [OFF, OFF, OFF, OFF], # [OFF, OFF, OFF, OFF], # [OFF, OFF, OFF, OFF]] cfg.core_cfgs[i].b[0] = np.array([30, 0, 0, 0], dtype='int') cfg.core_cfgs[i].Xth[0] = 100 cfg.core_cfgs[i].Xthup[0] = np.array([XMAX, XMAX, XMAX, XMAX], 'int') cfg.core_cfgs[i].Xthlo[0] = np.ones(4, 'int') * XMIN cfg.core_cfgs[i].Xreset[0] = np.array([0, XMAX, XMAX, XMAX], 'int') cfg.core_cfgs[i].XresetOn[0] = np.array([True, False, False, False], 'bool') for i in range(N_CORES): # Mapping NSAT parameters (per core) cfg.core_cfgs[i].nmap = np.zeros((N_NEURONS[0], ), dtype='int') # Assigning synaptic strength to each core W = np.zeros([N_UNITS[i], N_UNITS[i], 4], 'int') tmp = np.zeros((N_INPUTS[i], N_NEURONS[i])) np.fill_diagonal(tmp, 50) W[:N_INPUTS[i], N_INPUTS[i]:, 0] = tmp # Assigning adjacent matrix to each core CW = np.zeros(W.shape, dtype='bool') CW[:N_INPUTS[i], N_INPUTS[i]:, 0] = tmp.astype('bool') wgt_table, ptr_table = gen_ptr_wgt_table_from_W_CW(W, CW, []) cfg.core_cfgs[i].wgt_table = wgt_table cfg.core_cfgs[i].ptr_table = ptr_table cfg.set_L1_connectivity(({ (0, 102): ((1, 1), (1, 50), (1, 73)), (0, 103): ((1, 15), (1, 95), (1, 7)), (0, 105): ((1, 89), (1, 65), (1, 56)), (0, 143): ((1, 21), (1, 45), (1, 33)), (0, 113): ((1, 5), (1, 50), (1, 7)), (0, 133): ((1, 41), (1, 5), (1, 77)), (0, 123): ((1, 19), (1, 75), (1, 57)), (0, 104): ((1, 3), ) })) # Generate external events # freqs = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50] freqs = np.arange(5, 1000, 10) SL = [] for i in range(1): SL.append(RegularSpikingStimulus(freqs, sim_ticks)) ext_evts_data = nsat.exportAER(SL) # Set external events cfg.set_ext_events(ext_evts_data) # Generate all the CNSAT parameters files c_nsat_writer = nsat.C_NSATWriter(cfg, path='/tmp', prefix='test_routing') c_nsat_writer.write() c_nsat_writer.write_L1connectivity() print('End %s:setup()' % (os.path.splitext(os.path.basename(__file__))[0]))
def setup(): print('Begin %s:setup()' % (os.path.splitext(os.path.basename(__file__))[0])) sim_ticks = 100 # Simulation time N_CORES = 1 # Number of cores N_NEURONS = [2] # Number of neurons per core (list) N_INPUTS = [0] # Number of input units per core (list) N_STATES = [4] # Number of states per core (list) N_UNITS = N_INPUTS[0] + N_NEURONS[0] # Total units # Constants XMAX = nsat.XMAX XMIN = nsat.XMIN OFF = -16 MAX = nsat.MAX MIN = nsat.XMIN # Instance of main class cfg = nsat.ConfigurationNSAT(sim_ticks=sim_ticks, N_CORES=N_CORES, N_INPUTS=N_INPUTS, N_NEURONS=N_NEURONS, N_STATES=N_STATES, monitor_states=True, ben_clock=True) # Define transition matrices cfg.core_cfgs[0].A[0] = [[-1, OFF, OFF, OFF], [OFF, OFF, OFF, OFF], [OFF, OFF, OFF, OFF], [OFF, OFF, OFF, OFF]] cfg.core_cfgs[0].A[1] = [[-1, OFF, OFF, OFF], [OFF, OFF, OFF, OFF], [OFF, OFF, OFF, OFF], [OFF, OFF, OFF, OFF]] # Sign matrices cfg.core_cfgs[0].sA[0] = [[-1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]] cfg.core_cfgs[0].sA[1] = [[-1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]] # Bias cfg.core_cfgs[0].b[0] = np.array([50, 0, 0, 0], dtype='int') cfg.core_cfgs[0].b[1] = np.array([0, 0, 0, 0], dtype='int') # Thresholds cfg.core_cfgs[0].Xth[0] = 100 cfg.core_cfgs[0].Xth[1] = 100 # Set reset value cfg.core_cfgs[0].Xreset[0] = np.array([0, XMAX, XMAX, XMAX], 'int') cfg.core_cfgs[0].Xreset[1] = np.array([0, MAX, MAX, MAX], 'int') # Turn reset on cfg.core_cfgs[0].XresetOn[0] = np.array([True, False, False, False], 'bool') cfg.core_cfgs[0].XresetOn[1] = np.array([True, False, False, False], 'bool') # Synaptic weights W = np.zeros([N_UNITS, N_UNITS, N_STATES[0]], 'int') W[0, 1, 0] = 50 # Adjacent matrix CW = np.zeros(W.shape, dtype='int') CW[0, 1, 0] = 1 wgt_table, ptr_table = gen_ptr_wgt_table_from_W_CW(W, CW, []) np.set_printoptions(threshold=np.nan) cfg.core_cfgs[0].wgt_table = wgt_table cfg.core_cfgs[0].ptr_table = ptr_table # Tested value if len(sys.argv) != 2: print('Missing argument! Default value is used[prob=0]!') cfg.core_cfgs[0].prob_syn[1] = np.array([0, 0, 0, 0], dtype='int') else: p = int(sys.argv[1]) cfg.core_cfgs[0].prob_syn[1] = np.array([p, p, p, p], 'int') # NSAT parameters and neurons mapping function cfg.core_cfgs[0].nmap = np.array([0, 1], dtype='int') # Write C NSAT parameter files c_nsat_writer = nsat.C_NSATWriter(cfg, path='/tmp', prefix='test_prob') c_nsat_writer.write() # Write Intel FPGA parameters files # # intel_fpga_writer = nsat.IntelFPGAWriter(cfg, path='.', # # prefix='test_prob') # # intel_fpga_writer.write() # # intel_fpga_writer.write_globals() print('End %s:setup()' % (os.path.splitext(os.path.basename(__file__))[0]))
def setup(): global SL, t_start, t_stop print('Begin %s:setup()' % (os.path.splitext(os.path.basename(__file__))[0])) N_CORES = 1 # Number of cores N_NEURONS = [4] # Number of neurons per core N_INPUTS = [3] # Number of inputs per core N_STATES = [4] # Number of states per core N_UNITS = N_INPUTS[0] + N_NEURONS[0] # Total number of units # Constants XMAX = nsat.XMAX XMIN = nsat.XMIN OFF = -16 MAX = nsat.MAX MIN = nsat.XMIN # Configuration class instance cfg = nsat.ConfigurationNSAT(sim_ticks=sim_ticks, N_CORES=N_CORES, N_INPUTS=N_INPUTS, N_NEURONS=N_NEURONS, N_STATES=N_STATES, monitor_states=True, ben_clock=True) # Transition matrix group 0 cfg.core_cfgs[0].A[0] = [[-7, OFF, OFF, OFF], [0, -5, OFF, OFF], [OFF, OFF, OFF, OFF], [OFF, OFF, OFF, OFF]] # Transition matrix group 1 cfg.core_cfgs[0].A[1] = [[-7, OFF, OFF, OFF], [0, -7, OFF, OFF], [OFF, OFF, OFF, OFF], [OFF, OFF, OFF, OFF]] # Sign matrix group 0 cfg.core_cfgs[0].sA[0] = [[-1, 1, 1, 1], [+1, -1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]] # Sign matrix group 1 cfg.core_cfgs[0].sA[1] = cfg.core_cfgs[0].sA[0].copy() # Refractory period group 0 cfg.core_cfgs[0].t_ref[0] = 40 # Refractory period group 1 cfg.core_cfgs[0].t_ref[1] = 30 # Bias group 0 cfg.core_cfgs[0].b[0] = [0, 0, 0, 0] # Bias group 1 cfg.core_cfgs[0].b[1] = [0, 0, 0, 0] # Threshold group 0 cfg.core_cfgs[0].Xth[0] = 100 # Threshold group 1 cfg.core_cfgs[0].Xth[1] = 80 # Initial conditions cfg.core_cfgs[0].Xinit[0] = np.array([0, 0, 0, 0], 'int') # Reset value group 0 cfg.core_cfgs[0].Xreset[0] = [0, MAX, MAX, MAX] # Reset value group 1 cfg.core_cfgs[0].Xreset[1] = cfg.core_cfgs[0].Xreset[0].copy() # Turn reset on group 0 cfg.core_cfgs[0].XresetOn[0] = np.array([True, False, False, False], 'bool') # Turn reset on group 1 cfg.core_cfgs[0].XresetOn[1] = np.array([True, False, False, False], 'bool') # Global modulator state group 0 cfg.core_cfgs[0].modstate[0] = 3 # Global modulator state group 0 cfg.core_cfgs[0].modstate[1] = 3 # Parameters groups mapping function nmap = np.array([0, 0, 0, 1], dtype='int') cfg.core_cfgs[0].nmap = nmap # Synaptic weights and adjacent matrix W, CW = build_synaptic_w(N_INPUTS[0], N_NEURONS[0], N_STATES[0]) wgt_table, ptr_table = gen_ptr_wgt_table_from_W_CW(W, CW, []) np.set_printoptions(threshold=np.nan) cfg.core_cfgs[0].wgt_table = wgt_table cfg.core_cfgs[0].ptr_table = ptr_table # Set external events rates = [60, 30, 30] SL = SimSpikingStimulus(rates, t_start, t_stop) ext_evts_data = nsat.exportAER(SL) cfg.set_ext_events(ext_evts_data) # Write C NSAT parameters binary files c_nsat_writer = nsat.C_NSATWriter(cfg, path='/tmp', prefix='test_wta') c_nsat_writer.write() print('End %s:setup()' % (os.path.splitext(os.path.basename(__file__))[0])) return c_nsat_writer.fname
def setup(): print('Begin %s:setup()' % (os.path.splitext(os.path.basename(__file__))[0])) N_CORES = 1 N_NEURONS = [100] N_INPUTS = [100] N_STATES = [4] N_UNITS = N_INPUTS[0] + N_NEURONS[0] XMAX = nsat.XMAX XMIN = nsat.XMIN OFF = -16 MAX = nsat.MAX MIN = nsat.XMIN cfg = nsat.ConfigurationNSAT(sim_ticks=sim_ticks, N_CORES=N_CORES, N_INPUTS=N_INPUTS, N_NEURONS=N_NEURONS, N_STATES=N_STATES, monitor_states=True, monitor_spikes=True, ben_clock=True) cfg.core_cfgs[0].A[0] = [[-2, OFF, OFF, OFF], [OFF, OFF, OFF, OFF], [OFF, OFF, OFF, OFF], [OFF, OFF, OFF, OFF]] cfg.core_cfgs[0].sA[0] = [[-1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]] cfg.core_cfgs[0].b[0] = np.array([-5, 0, 0, 0], dtype='int') cfg.core_cfgs[0].Xth[0] = 20 cfg.core_cfgs[0].Xthup[0] = np.array([XMAX, XMAX, XMAX, XMAX], 'int') cfg.core_cfgs[0].Xthlo[0] = np.ones(4, 'int') * XMIN cfg.core_cfgs[0].Xreset[0] = np.array([0, XMAX, XMAX, XMAX], 'int') cfg.core_cfgs[0].XresetOn[0] = np.array([False, False, False, False], 'bool') # Synaptic weights # Bump tmp_w = kernel(N_NEURONS[0], amp=(7, 3), sigma=(0.1, 0.35)) # Selection # tmp_w = kernel(N_NEURONS, amp=(6, 3), sigma=(0.1, 1.0)) # Tracking # tmp_w = kernel(N_NEURONS, amp=(6, 3), sigma=(0.1, 1.0)) # tmp_w = kernel_(N_NEURONS, (3, 4), (0.01, 0.03)) W = np.zeros([N_UNITS, N_UNITS, N_STATES[0]], 'int') # W[:N_INPUTS, N_INPUTS+40:N_INPUTS+60, 0] = np.ones((20,)) * 30 np.fill_diagonal(W[:N_INPUTS[0], N_INPUTS[0]:, 0], 30) W[N_INPUTS[0]:, N_INPUTS[0]:, 0] = tmp_w # Adjacent matrix CW = np.zeros(W.shape, dtype='int') # CW[:N_INPUTS, N_INPUTS+40:N_INPUTS+60, 0] = 1 np.fill_diagonal(CW[:N_INPUTS[0], N_INPUTS[0]:, 0], 1) CW[N_INPUTS[0]:, N_INPUTS[0]:, 0] = 1 wgt_table, ptr_table = gen_ptr_wgt_table_from_W_CW(W, CW, []) np.set_printoptions(threshold=np.nan) cfg.core_cfgs[0].wgt_table = wgt_table cfg.core_cfgs[0].ptr_table = ptr_table # Parameters groups mapping function cfg.core_cfgs[0].nmap = np.zeros((N_NEURONS[0], ), dtype='int') # Set external events rates = [20] * N_INPUTS[0] ext_evts_data, sl = PoissonSpikingStimulus(rates, n_inputs=N_INPUTS[0]) events_i = sl.convert() mat = np.zeros((sim_ticks, N_INPUTS[0])) mat[events_i[0].astype('i'), events_i[1].astype('i')] = 1 # ext_evts_data = None # f = [i for i in np.random.randint(0, 15, (N_INPUTS,))] # ext_evts_data = RegularSpikingStimulus(f, 300) cfg.set_ext_events(ext_evts_data) cfg.core_cfgs[0].latex_print_parameters(1) # Write C NSAT parameters files c_nsat_writer = nsat.C_NSATWriter(cfg, path='/tmp', prefix='test_nf') c_nsat_writer.write() # Write FPGA NSAT parameters files # intel_fpga_writer = nsat.IntelFPGAWriter(cfg, path='.', # prefix='test_nf') # intel_fpga_writer.write() # intel_fpga_writer.write_globals() print('End %s:setup()' % (os.path.splitext(os.path.basename(__file__))[0])) return c_nsat_writer.fname
def setup(): print('Begin %s:setup()' % (os.path.splitext(os.path.basename(__file__))[0])) np.random.seed(30) # Numpy random number generator seed sim_ticks = 5000 # Total simulation time N_CORES = 2 # Number of cores N_NEURONS = [10, 10] # Number of neurons per core (list) N_INPUTS = [10, 10] # Number of inputs per core (list) N_STATES = [4, 4] # Number of states per core (list) N_UNITS = [sum(i) for i in zip(N_INPUTS, N_NEURONS)] # Constants XMAX = nsat.XMAX XMIN = nsat.XMIN OFF = -16 MAX = nsat.MAX MIN = nsat.XMIN # Main class instance cfg = nsat.ConfigurationNSAT(sim_ticks=sim_ticks, N_CORES=N_CORES, N_INPUTS=N_INPUTS, N_NEURONS=N_NEURONS, N_STATES=N_STATES, monitor_states=True, ben_clock=True) # Loop over the cores and set the parameters for i in range(N_CORES): # Transition matrix A cfg.core_cfgs[i].A[0] = [[-1, OFF, OFF, OFF], [OFF, OFF, OFF, OFF], [OFF, OFF, OFF, OFF], [OFF, OFF, OFF, OFF]] # Sign matrix sA cfg.core_cfgs[i].sA[0] = [[-1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]] # Bias cfg.core_cfgs[i].b[0] = np.array([30, 0, 0, 0], dtype='int') # Threshold cfg.core_cfgs[i].Xth[0] = 100 # Reset value cfg.core_cfgs[i].Xreset[0] = np.array([0, XMAX, XMAX, XMAX], 'int') # Turn reset on per state cfg.core_cfgs[i].XresetOn[0] = np.array([True, False, False, False], 'bool') for i in range(N_CORES): # Mapping NSAT parameters (per core) cfg.core_cfgs[i].nmap = np.zeros((N_NEURONS[0], ), dtype='int') if i == 0: # Assigning synaptic strength to each core W = np.zeros([N_UNITS[i], N_UNITS[i], 4], 'int') W[0, 10, 0] = 50 W[1, 11, 0] = 50 W[2, 12, 0] = 50 W[3, 13, 0] = 50 W[4, 14, 0] = 50 W[5, 15, 0] = 50 W[6, 16, 0] = 50 W[7, 17, 0] = 50 W[8, 18, 0] = 50 W[9, 19, 0] = 50 # Assigning adjacent matrix to each core CW = np.zeros(W.shape, dtype='int') CW[0, 10, 0] = 1 CW[1, 11, 0] = 1 CW[2, 12, 0] = 1 CW[3, 13, 0] = 1 CW[4, 14, 0] = 1 CW[5, 15, 0] = 1 CW[6, 16, 0] = 1 CW[7, 17, 0] = 1 CW[8, 18, 0] = 1 CW[9, 19, 0] = 1 wgt_table, ptr_table = gen_ptr_wgt_table_from_W_CW(W, CW, []) np.set_printoptions(threshold=np.nan) cfg.core_cfgs[i].wgt_table = wgt_table cfg.core_cfgs[i].ptr_table = ptr_table if i == 1: W = np.zeros([N_UNITS[i], N_UNITS[i], 4], 'int') CW = np.zeros(W.shape, dtype='int') W[1, 11, 0] = 50 W[5, 15, 0] = 50 CW[1, 11, 0] = 1 CW[5, 15, 0] = 1 wgt_table, ptr_table = gen_ptr_wgt_table_from_W_CW(W, CW, []) np.set_printoptions(threshold=np.nan) cfg.core_cfgs[i].wgt_table = wgt_table cfg.core_cfgs[i].ptr_table = ptr_table # Connect core 0 neuron 9 with core 1 neurons 1 and 5 cfg.set_L1_connectivity({(0, 9): ((1, 1), (1, 5))}) # Generate external events firing rates from 5 to 50 inc by 5 freqs = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50] SL = [] for i in range(N_CORES - 1): SL.append(RegularSpikingStimulus(freqs, sim_ticks)) ext_evts_data = nsat.exportAER(SL) # Set external events cfg.set_ext_events(ext_evts_data) # Generate all the CNSAT parameters files c_nsat_writer = nsat.C_NSATWriter(cfg, path='/tmp', prefix='test_external_evts') c_nsat_writer.write() print('End %s:setup()' % (os.path.splitext(os.path.basename(__file__))[0]))
def setup(): print('Begin %s:setup()' % (os.path.splitext(os.path.basename(__file__))[0])) N_CORES = 1 # Number of cores N_NEURONS = [4] # Number of neurons per core (list) N_INPUTS = [4] # Number of inputs per core (list) N_STATES = [4] # Number of states per core (list) N_UNITS = N_INPUTS[0] + N_NEURONS[0] # Total inputs # Constants XMAX = nsat.XMAX XMIN = nsat.XMIN OFF = -16 MAX = nsat.MAX MIN = nsat.XMIN # Main class instance cfg = nsat.ConfigurationNSAT(sim_ticks=sim_ticks, N_CORES=N_CORES, N_INPUTS=N_INPUTS, N_NEURONS=N_NEURONS, N_STATES=N_STATES, tstdpmax=[64], monitor_states=True, monitor_spikes=True, monitor_weights=True, monitor_weights_final=True, plasticity_en=[True], ben_clock=True) # Transition matrix cfg.core_cfgs[0].A[0] = [[-1, OFF, OFF, OFF], [0, -1, OFF, OFF], [OFF, OFF, 0, OFF], [OFF, OFF, OFF, OFF]] cfg.core_cfgs[0].A[1] = cfg.core_cfgs[0].A[0].copy() # Sign matrix cfg.core_cfgs[0].sA[0] = [[-1, 1, 1, 1], [1, -1, 1, 1], [1, 1, -1, 1], [1, 1, 1, 1]] cfg.core_cfgs[0].sA[1] = cfg.core_cfgs[0].sA[0].copy() # Refractory period cfg.core_cfgs[0].t_ref[0] = 0 cfg.core_cfgs[0].t_ref[1] = 2 # Threshold cfg.core_cfgs[0].Xth[0] = 100 cfg.core_cfgs[0].Xth[1] = 100 # Bias cfg.core_cfgs[0].b[0] = [30, 0, 5, 0] cfg.core_cfgs[0].b[1] = [30, 0, 5, 0] # Initial conditions cfg.core_cfgs[0].Xinit[0] = np.array([0, 0, 0, 0], 'int') cfg.core_cfgs[0].Xinit[1] = np.array([0, 0, 0, 0], 'int') # Reset value cfg.core_cfgs[0].Xreset[0] = [0, MAX, MAX, MAX] cfg.core_cfgs[0].Xreset[1] = [0, MAX, MAX, MAX] # Turn reset on cfg.core_cfgs[0].XresetOn[0] = [True, False, False, False] cfg.core_cfgs[0].XresetOn[1] = [True, False, False, False] # Enable plasticity at states cfg.core_cfgs[0].plastic[0] = True cfg.core_cfgs[0].plastic[1] = False # Enable STDP cfg.core_cfgs[0].stdp_en[0] = True cfg.core_cfgs[0].stdp_en[1] = False # Global modulator state cfg.core_cfgs[0].modstate[0] = 2 cfg.core_cfgs[0].modstate[1] = 2 # Parameters for the STDP kernel function rNLRN_GROUPS = list(range(8)) cfg.core_cfgs[0].tstdp = np.array([64 for _ in rNLRN_GROUPS], 'int') cfg.core_cfgs[0].tca = np.array([[16, 36] for _ in rNLRN_GROUPS], 'int') cfg.core_cfgs[0].hica = np.array([[1, 0, -1] for _ in rNLRN_GROUPS], 'int') cfg.core_cfgs[0].sica = np.array([[1, 1, 1] for _ in rNLRN_GROUPS], 'int') cfg.core_cfgs[0].tac = np.array([[-16, -36] for _ in rNLRN_GROUPS], 'int') cfg.core_cfgs[0].hiac = np.array([[1, 0, -1] for _ in rNLRN_GROUPS], 'int') cfg.core_cfgs[0].siac = np.array([[-1, -1, -1] for _ in rNLRN_GROUPS], 'int') # Set parameters mapping cfg.core_cfgs[0].nmap = np.zeros((N_NEURONS[0], ), dtype='int') cfg.core_cfgs[0].nmap[0] = 0 cfg.core_cfgs[0].nmap[1] = 1 cfg.core_cfgs[0].nmap[2] = 1 cfg.core_cfgs[0].nmap[3] = 1 # Learning parameters groups mapping lrnmap = np.zeros((nsat.N_GROUPS, N_STATES[0]), dtype='int') lrnmap[0, :] = 1 lrnmap[0, 1] = 0 lrnmap[1, 2] = 0 lrnmap[1, 0] = 0 # lrnmap[:] = 0 cfg.core_cfgs[0].lrnmap = lrnmap # Synaptic weights W = np.zeros([N_UNITS, N_UNITS, N_STATES[0]], 'int') W[0, 4, 1] = 50 W[1, 5, 1] = 50 W[2, 6, 1] = 50 W[3, 7, 1] = 50 W[4, 5, 1] = 5 W[4, 6, 1] = 5 W[4, 7, 1] = 5 # Adjacent matrix CW = W.astype('bool') wgt_table, ptr_table = gen_ptr_wgt_table_from_W_CW(W, CW, []) np.set_printoptions(threshold=np.nan) cfg.core_cfgs[0].wgt_table = wgt_table cfg.core_cfgs[0].ptr_table = ptr_table # Generate spike events (external events) # spk_train = np.array([0, 1, 2, 50, 60, 70, 100, 110, 120]) SL = SimSpikingStimulus(t_sim=sim_ticks) ext_evts_data = nsat.exportAER(SL) cfg.set_ext_events(ext_evts_data) # Write the C NSAT parameters binary files c_nsat_writer = nsat.C_NSATWriter(cfg, path='/tmp', prefix='test_stdp') c_nsat_writer.write() print('End %s:setup()' % (os.path.splitext(os.path.basename(__file__))[0])) return c_nsat_writer.fname
def setup(): print('Begin %s:setup()' % (os.path.splitext(os.path.basename(__file__))[0])) pyST.STCreate.seed(130) # pyNCSre random number generator np.random.seed(30) # Numpy random number generator N_CORES = 1 # Number of cores N_NEURONS = [1] # Number of neurons per core (list) N_INPUTS = [1] # Number of inputs per core (list) N_STATES = [8] # Number of states per core (list) N_UNITS = N_INPUTS[0] + N_NEURONS[0] # Total number of units # Number of states (8) rN_STATES = list(range(N_STATES[0])) # Number of parameters groups rN_GROUPS = list(range(nsat.N_GROUPS)) # Constants XMAX = nsat.XMAX XMIN = nsat.XMIN OFF = -16 MAX = nsat.MAX MIN = nsat.XMIN # Main class isntance cfg = nsat.ConfigurationNSAT(sim_ticks=sim_ticks, N_CORES=N_CORES, N_INPUTS=N_INPUTS, N_NEURONS=N_NEURONS, N_STATES=N_STATES, monitor_states=True, monitor_spikes=True, ben_clock=True) # Transition matrix A cfg.core_cfgs[0].A[0] = np.array([[-1, OFF, OFF, OFF, OFF, OFF, OFF, OFF], [-3, -1, OFF, OFF, OFF, OFF, OFF, OFF], [OFF, -2, -1, OFF, OFF, OFF, OFF, OFF], [OFF, OFF, -1, -1, OFF, OFF, OFF, OFF], [OFF, OFF, OFF, -1, -1, OFF, OFF, OFF], [OFF, OFF, OFF, OFF, -2, -1, OFF, OFF], [OFF, OFF, OFF, OFF, OFF, -3, -1, OFF], [OFF, OFF, OFF, OFF, OFF, OFF, 0, -1]], 'int') # Sign matrix sA cfg.core_cfgs[0].sA[0] = np.array( [[-1, 1, 1, 1, 1, 1, 1, 1], [1, -1, 1, 1, 1, 1, 1, 1], [1, 1, -1, 1, 1, 1, 1, 1], [1, 1, 1, -1, 1, 1, 1, 1], [1, 1, 1, 1, -1, 1, 1, 1], [1, 1, 1, 1, 1, -1, 1, 1], [1, 1, 1, 1, 1, 1, -1, 1], [1, 1, 1, 1, 1, 1, 1, -1]], 'int') # Bias cfg.core_cfgs[0].b[0] = np.array([0, 0, 0, 0, 0, 0, 0, 0], 'int') # Initiali conditions cfg.core_cfgs[0].Xinit[0] = np.array([[0] * 8 for _ in range(N_NEURONS[0])], 'int') # Reset value cfg.core_cfgs[0].Xreset[0] = np.array([0, 0, 0, 0, 0, 0, 0, 0], 'int') # Turn reset on cfg.core_cfgs[0].XresetOn[0] = np.array( [True, False, False, False, False, False, False, False], 'bool') # Synaptic probability cfg.core_cfgs[0].prob = np.ones(8, dtype='int') * 15 # Threshold cfg.core_cfgs[0].Xth[0] = 100 # Mapping between neurons and NSAT parameters groups cfg.core_cfgs[0].nmap = np.zeros((N_NEURONS[0], ), dtype='int') # Sunaptic weights W = np.zeros([N_UNITS, N_UNITS, 8], dtype='int') W[0, 1, 7] = 50 # Adjacent matrix CW = np.zeros(W.shape, dtype='bool') CW[0, 1, 7] = True wgt_table, ptr_table = gen_ptr_wgt_table_from_W_CW(W, CW, []) np.set_printoptions(threshold=np.nan) cfg.core_cfgs[0].wgt_table = wgt_table cfg.core_cfgs[0].ptr_table = ptr_table # Set external events (spikes) freqs = [15] ext_evts_data = RegularSpikingStimulus(freqs, ticks=sim_ticks) cfg.set_ext_events(ext_evts_data) # Write C NSAT parameters binary files c_nsat_writer = nsat.C_NSATWriter(cfg, path='/tmp', prefix='test_eight_states_neuron') c_nsat_writer.write() # Write Intel FPGA parameters hex files # intel_fpga_writer = nsat.IntelFPGAWriter(cfg, path='.', # prefix='test_eight_states_neuron') # intel_fpga_writer.write() # intel_fpga_writer.write_globals() print('End %s:setup()' % (os.path.splitext(os.path.basename(__file__))[0]))
def setup(): global SL print('Begin %s:setup()' % (os.path.splitext(os.path.basename(__file__))[0])) np.random.seed(100) # Numpy RNG seed pyST.STCreate.seed(130) # PyNCS RNG seed N_CORES = 1 # Number of cores N_NEURONS = [100] # Number of neurons per core N_INPUTS = [101] # Number of inputs per core N_STATES = [4] # Number of states pare core N_UNITS = N_INPUTS[0] + N_NEURONS[0] # Total units # Constants XMAX = nsat.XMAX XMIN = nsat.XMIN OFF = -16 MAX = nsat.MAX MIN = nsat.XMIN NLRN_GROUPS = 8 N_GROUPS = 8 # Main class instance cfg = nsat.ConfigurationNSAT(sim_ticks=sim_ticks, N_CORES=N_CORES, N_INPUTS=N_INPUTS, N_NEURONS=N_NEURONS, N_STATES=N_STATES, monitor_states=True, monitor_spikes=True, monitor_weights=True, w_check=False, plasticity_en=np.array([True], 'bool'), ben_clock=True) cfg.core_cfgs[core].sigma[0] = [0, 0, 10, 0] # Transition matrix group 0 cfg.core_cfgs[core].A[0] = [[-5, OFF, OFF, OFF], [3, -5, OFF, OFF], [OFF, OFF, -6, OFF], [OFF, OFF, OFF, OFF]] # Transition matrix group 1 cfg.core_cfgs[core].A[1] = [[OFF, OFF, OFF, OFF], [OFF, OFF, OFF, OFF], [OFF, OFF, OFF, OFF], [OFF, OFF, OFF, OFF]] # Sign matrix group 0 cfg.core_cfgs[core].sA[0] = [[-1, 1, 1, 1], [1, -1, 1, 1], [1, 1, -1, 1], [1, 1, 1, -1]] # Threshold cfg.core_cfgs[core].Xth[0] = 25000 # Refractory period cfg.core_cfgs[core].t_ref[0] = 40 # Bias cfg.core_cfgs[core].b[0] = [0, 0, 0, 0] # Initial conditions cfg.core_cfgs[core].Xinit = np.array([[0, 0, 0, 0] for _ in range(N_NEURONS[0])]) # Reset value cfg.core_cfgs[core].Xreset[0] = [0, MAX, MAX, MAX] # Turn reset on cfg.core_cfgs[core].XresetOn[0] = [True, False, False, False] # Turn plasticity per state on cfg.core_cfgs[core].plastic[0] = True # Turn stdp per state on cfg.core_cfgs[core].stdp_en[0] = True cfg.core_cfgs[core].is_stdp_exp_on[0] = True # Global modulator state cfg.core_cfgs[core].modstate[0] = 2 # Parameters groups mapping function cfg.core_cfgs[core].nmap = np.zeros((N_NEURONS[0], ), dtype='int') lrnmap = 1 + np.zeros((N_GROUPS, N_STATES[0]), dtype='int') lrnmap[0, 1] = 0 cfg.core_cfgs[core].lrnmap = lrnmap # Synaptic weights W = np.zeros([N_UNITS, N_UNITS, N_STATES[core]], 'int') W[0:100, N_INPUTS[core]:, 1] = np.eye(N_NEURONS[core]) * 100 W[100, N_INPUTS[core]:, 2] = 100 # Adjacent matrix CW = np.zeros(W.shape, dtype='int') CW[0:100, N_INPUTS[core]:, 1] = np.eye(N_NEURONS[core]) CW[100, N_INPUTS[core]:, 2] = 1 wgt_table, ptr_table = gen_ptr_wgt_table_from_W_CW(W, CW, []) np.set_printoptions(threshold=np.nan) cfg.core_cfgs[core].wgt_table = wgt_table cfg.core_cfgs[core].ptr_table = ptr_table # Learning STDP parameters cfg.core_cfgs[core].tca = [[24, 48] for _ in range(NLRN_GROUPS)] cfg.core_cfgs[core].hica = [[-3, -5, -6] for _ in range(NLRN_GROUPS)] cfg.core_cfgs[core].sica = [[1, 1, 1] for _ in range(NLRN_GROUPS)] cfg.core_cfgs[core].slca = [[16, 16, 16] for _ in range(NLRN_GROUPS)] cfg.core_cfgs[core].tac = [[-32, -64] for _ in range(NLRN_GROUPS)] cfg.core_cfgs[core].hiac = [[-6, -8, -9] for _ in range(NLRN_GROUPS)] cfg.core_cfgs[core].siac = [[-1, -1, -1] for _ in range(NLRN_GROUPS)] cfg.core_cfgs[core].slac = [[16, 16, 16] for _ in range(NLRN_GROUPS)] # Prepare external stimulus (spikes events) stim = [50] * N_NEURONS[core] SL = SimSpikingStimulus(stim, t_sim=sim_ticks) SLr = pyST.SpikeList(id_list=[100]) SLr[100] = pyST.STCreate.inh_poisson_generator(rate=np.array( [0., 100., 0.]), t=np.array([0, 400, 600]), t_stop=sim_ticks) SL = pyST.merge_spikelists(SL, SLr) ext_evts_data = nsat.exportAER(SL) cfg.set_ext_events(ext_evts_data) # Write C NSAT parameters binary file c_nsat_writer = nsat.C_NSATWriter(cfg, path='/tmp', prefix='test_rSTDP') c_nsat_writer.write() print('End %s:setup()' % (os.path.splitext(os.path.basename(__file__))[0]))
def setup(): print('Begin %s:setup()' % (os.path.splitext(os.path.basename(__file__))[0])) N_CORES = 1 # Number of cores N_NEURONS = [2] # Number of neurons per core N_INPUTS = [0] # Number of inputs per core N_STATES = [4] # Number of states per core N_UNITS = N_INPUTS[0] + N_NEURONS[0] # Total units # Constants XMAX = nsat.XMAX XMIN = nsat.XMIN OFF = -16 MAX = nsat.MAX MIN = nsat.XMIN # Main class instance cfg = nsat.ConfigurationNSAT(sim_ticks=sim_ticks, N_CORES=N_CORES, N_INPUTS=N_INPUTS, N_NEURONS=N_NEURONS, N_STATES=N_STATES, w_check=False, monitor_states=True, monitor_spikes=True, monitor_weights=True, plasticity_en=[True], ben_clock=True) # Transition matrix (group 0) cfg.core_cfgs[0].A[0] = [[-5, OFF, OFF, OFF], [OFF, OFF, OFF, OFF], [OFF, OFF, OFF, OFF], [OFF, OFF, OFF, OFF]] # Transition matrix (group 0) cfg.core_cfgs[0].A[1] = [[-2, OFF, OFF, OFF], [2, -5, OFF, OFF], [OFF, OFF, OFF, OFF], [OFF, OFF, OFF, OFF]] # Sign matrix (group 0) cfg.core_cfgs[0].sA[0] = [[-1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]] # Sign matrix (group 0) cfg.core_cfgs[0].sA[1] = [[-1, 1, 1, 1], [1, -1, 1, 1], [1, 1, -1, 1], [1, 1, 1, -1]] # Refractory period group 0 cfg.core_cfgs[0].t_ref[0] = 0 # Refractory period group 1 cfg.core_cfgs[0].t_ref[1] = 20 # Threshold group 0 cfg.core_cfgs[0].Xth[0] = 100 # Threshold group 1 cfg.core_cfgs[0].Xth[1] = 2500 # Bias group 0 cfg.core_cfgs[0].b[0] = np.array([5, 0, 0, 0], 'int') # Bias group 1 cfg.core_cfgs[0].b[1] = np.array([5, 0, 5, 0], 'int') # Initial conditions group 0 cfg.core_cfgs[0].Xinit[0] = np.array([0, 0, 0, 0], 'int') # Reset value group 0 cfg.core_cfgs[0].Xreset[0] = [0, MAX, MAX, MAX] # Reset value group 1 cfg.core_cfgs[0].Xreset[1] = [0, MAX, MAX, MAX] # Turn reset on group 0 cfg.core_cfgs[0].XresetOn[0] = np.array([True, False, False, False], 'bool') # Turn reset on group 1 cfg.core_cfgs[0].XresetOn[1] = np.array([True, False, False, False], 'bool') # Enable plastic states for group 1 cfg.core_cfgs[0].plastic[1] = True # Turn on STDP per state for group 0 cfg.core_cfgs[0].stdp_en[0] = True # Turn on STDP per state for group 1 cfg.core_cfgs[0].stdp_en[1] = True # Global modulator state group 0 cfg.core_cfgs[0].modstate[1] = 2 cfg.core_cfgs[0].modstate[0] = 2 # K = 40 # cfg.core_cfgs[0].tstdp[0] = K # cfg.core_cfgs[0].tca[0] = np.array([K, K]) # cfg.core_cfgs[0].hica[0] = np.array([0, 0, 0]) # cfg.core_cfgs[0].sica[0] = np.array([1, 1, 1]) # cfg.core_cfgs[0].tac[0] = np.array([-K, -K]) # cfg.core_cfgs[0].hiac[0] = np.array([0, 0, 0]) # cfg.core_cfgs[0].siac[0] = np.array([1, 1, 1]) # Parameters groups mapping function nmap = np.zeros((N_NEURONS[0], ), dtype='int') nmap[0] = 0 nmap[1] = 1 cfg.core_cfgs[0].nmap = nmap # Learning parameters groups mapping lrnmap = np.zeros((nsat.N_GROUPS, N_STATES[0]), dtype='int') lrnmap[nmap[0], 1] = 0 lrnmap[nmap[1], 1] = 1 lrnmap[:] = 0 cfg.core_cfgs[0].lrnmap = lrnmap # Synaptic weights W = np.zeros([N_UNITS, N_UNITS, N_STATES[0]], 'int') W[0, 1, 1] = 100 # W[1, 0, 1] = 100 # Adjacent matrix CW = np.zeros(W.shape, dtype='int') CW[0, 1, 1] = 1 # CW[1, 0, 1] = 1 wgt_table, ptr_table = gen_ptr_wgt_table_from_W_CW(W, CW, []) np.set_printoptions(threshold=np.nan) cfg.core_cfgs[0].wgt_table = wgt_table cfg.core_cfgs[0].ptr_table = ptr_table # Write C NSAT paramters binary files c_nsat_writer = nsat.C_NSATWriter(cfg, path='/tmp', prefix='test_iSTDP') c_nsat_writer.write() # Write Intel FPGA hex parameters files # intel_fpga_writer = nsat.IntelFPGAWriter(cfg, path='.', # prefix='test_iSTDP') # intel_fpga_writer.write() # intel_fpga_writer.write_globals() print('End %s:setup()' % (os.path.splitext(os.path.basename(__file__))[0])) return c_nsat_writer.fname
def setup(): print('Begin %s:setup()' % (os.path.splitext(os.path.basename(__file__))[0])) OFF = -16 MAX = nsat.MAX MIN = nsat.XMIN sim_ticks = 500 # Simulation ticks NUM_CORES = 1 # Number of cores N_INPUTS = [0] # Number of inputes per core N_NEURONS = [1] # Number of neurons per core N_STATES = [4] # Number of states per core per neuron # Class instance cfg = nsat.ConfigurationNSAT(sim_ticks=sim_ticks, N_CORES=NUM_CORES, N_INPUTS=N_INPUTS, N_NEURONS=N_NEURONS, N_STATES=N_STATES, monitor_states=True, ben_clock=True) # For every core set the parameters for i in range(NUM_CORES): # Transition matrix cfg.core_cfgs[i].A[0] = [[-4, -8, OFF, OFF], [OFF, -7, OFF, OFF], [0, OFF, -2, OFF], [0, OFF, OFF, -6]] # Sign matrix cfg.core_cfgs[i].sA[0] = [[-1, 1, 1, 1], [1, -1, 1, 1], [1, 1, -1, 1], [1, 1, 1, -1]] # Adaptive threshold enabled cfg.core_cfgs[i].flagXth[0] = True # Threshold cfg.core_cfgs[i].Xth[0] = MAX # Bias cfg.core_cfgs[i].b[0] = np.array([-250, -10, 0, 0], 'int') # Initial conditions cfg.core_cfgs[i].Xinit[0] = np.array([-7000, -5000, 100, 10], 'int') # Reset value cfg.core_cfgs[i].Xreset[0] = np.array([-7000, -6000, 0, 0], 'int') # Turn on reset cfg.core_cfgs[i].XresetOn[0] = np.array([True, False, True, False], 'bool') # For every core set the synaptic strengths for i in range(NUM_CORES): # Synaptic strength N_UNITS = N_INPUTS[i] + N_NEURONS[i] W = np.zeros([N_UNITS, N_UNITS, 4], 'int') W[0, 0, 1] = 5 W[0, 0, 3] = 0 # Adjacent matrix CW = np.zeros(W.shape, dtype='int') CW[0, 0, 1] = 1 CW[0, 0, 3] = 1 wgt_table, ptr_table = gen_ptr_wgt_table_from_W_CW(W, CW, []) np.set_printoptions(threshold=np.nan) cfg.core_cfgs[i].wgt_table = wgt_table cfg.core_cfgs[i].ptr_table = ptr_table # NSAT parameters mapping cfg.core_cfgs[i].nmap = np.zeros((N_NEURONS[i], ), dtype='int') # Write C NSAT parameters binary files c_nsat_writer = nsat.C_NSATWriter(cfg, path='/tmp', prefix='test_mn_neuron') c_nsat_writer.write() # Write Intel FPGA parameters hex files # # intel_fpga_writer = nsat.IntelFPGAWriter(cfg, path='.', # # prefix='test_mn_neuron') # # intel_fpga_writer.write() # # intel_fpga_writer.write_globals() cfg.core_cfgs[0].latex_print_parameters(1) print('End %s:setup()' % (os.path.splitext(os.path.basename(__file__))[0]))