示例#1
0
def setup():
    print('Begin %s:setup()' %
          (os.path.splitext(os.path.basename(__file__))[0]))

    sim_ticks = 100  # Total simulation time
    N_CORES = 1  # Number of cores
    N_NEURONS = [1]  # Number of neurons per core (list)
    N_INPUTS = [0]  # 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,
                                 ben_clock=True)

    # Transition matrix A
    cfg.core_cfgs[0].A[0] = [[-15, OFF, OFF, OFF], [OFF, 0, OFF, OFF],
                             [OFF, OFF, 0, OFF], [OFF, OFF, OFF, 0]]

    # Sign matrix A
    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([10, 0, 0, 0], dtype='int')
    # Threshold
    cfg.core_cfgs[0].Xth[0] = 100
    # Reset value
    cfg.core_cfgs[0].Xreset[0] = np.array([0, 0, 0, 0], 'int')
    # Turn reset on
    cfg.core_cfgs[0].XresetOn[0] = np.array([False, False, False, False],
                                            'bool')

    # Mapping between neurons and NSAT parameters groups
    cfg.core_cfgs[0].nmap = np.zeros((N_NEURONS[0], ), dtype='int')

    # Write C NSAT parameters binary files
    c_nsat_writer = nsat.C_NSATWriter(cfg,
                                      path='/tmp',
                                      prefix='test_coupling_leak')
    c_nsat_writer.write()

    # Write Intel FPGA parameters hex files
    #    intel_fpga_writer = nsat.IntelFPGAWriter(cfg, path='.',
    #                                             prefix='test_coupling_leak')
    #    intel_fpga_writer.write()
    #    intel_fpga_writer.write_globals()
    print('End %s:setup()' % (os.path.splitext(os.path.basename(__file__))[0]))
W = np.zeros([N_NEURONS + N_INPUTS, N_NEURONS + N_INPUTS, N_STATES], 'int')
W[:N_INPUTS, N_INPUTS:] = extW
W[N_INPUTS:, N_INPUTS:] = recW

CW = np.zeros([N_NEURONS + N_INPUTS, N_NEURONS + N_INPUTS, N_STATES], 'int')
CW[:N_INPUTS, N_INPUTS:] = extCW
CW[N_INPUTS:, N_INPUTS:] = recCW

W = np.array(W)

cfg_train = nsat.ConfigurationNSAT(sim_ticks=sim_ticks,
                                   N_CORES=N_CORES,
                                   N_NEURONS=[N_NEURONS],
                                   N_INPUTS=[N_INPUTS],
                                   N_STATES=[N_STATES],
                                   bm_rng=True,
                                   monitor_spikes=True,
                                   monitor_states=False,
                                   gated_learning=[True],
                                   plasticity_en=[True])

# Parameters groups mapping function
core0_cfg = cfg_train.core_cfgs[0]
core0_cfg.nmap = np.zeros(N_NEURONS, dtype='int')
core0_cfg.lrnmap = np.zeros((N_GROUPS, N_STATES), dtype='int')
core0_cfg.nmap[sP:sP + Np] = OUTNRN
core0_cfg.nmap[sH:sH + Np] = HIDNRN
core0_cfg.nmap[sg1:] = ERRNRN
core0_cfg.lrnmap = np.zeros((N_GROUPS, N_STATES), dtype='int')
core0_cfg.lrnmap[core0_cfg.nmap[:sP + Np], 0] = 1
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]))
示例#4
0
    # 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,
                                 monitor_weights=True,
                                 w_check=False,
                                 tstdpmax=[50],
                                 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],
                             [0, OFF, -2, OFF], [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]]
示例#5
0
                                    data & (ADDR_MASK)))
                    fe.write(pack(data, 'i'))


def read_from_file(fname):
    import struct as st
    with open(fname, "rb") as f:
        cont = f.read()
    size = int(len(cont) / 4)
    return np.array(st.unpack('i' * size, cont))


if __name__ == '__main__':
    cfg = pyNSATlib.ConfigurationNSAT(N_CORES=2,
                                      N_INPUTS=[10, 10],
                                      N_NEURONS=[512, 100],
                                      N_STATES=[4, 2],
                                      bm_rng=True,
                                      ben_clock=True)

    cfg.core_cfgs[0].W[:cfg.core_cfgs[0].n_inputs,
                       cfg.core_cfgs[0].n_inputs:] = 1
    cfg.core_cfgs[0].CW[:cfg.core_cfgs[0].n_inputs,
                        cfg.core_cfgs[0].n_inputs:] = 1
    cfg.core_cfgs[1].W[:cfg.core_cfgs[1].n_inputs,
                       cfg.core_cfgs[1].n_inputs:] = 1
    cfg.core_cfgs[1].CW[:cfg.core_cfgs[1].n_inputs,
                        cfg.core_cfgs[1].n_inputs:] = 1
    cfg.set_L1_connectivity({(0, 1): ((1, 0), (1, 1))})

    SL1 = pyNSATlib.build_SpikeList(evs_time=[1, 2, 3], evs_addr=[5, 6, 7])
    SL2 = pyNSATlib.build_SpikeList(evs_time=[2, 5, 1], evs_addr=[3, 9, 5])
示例#6
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
示例#7
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 = [1]  # Number of neurons per core
    N_INPUTS = [0]  # Number of inputes 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

    # 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([50, 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')

    # Tested value
    if len(sys.argv) != 2:
        print('Missing argument! Default value is used[Xreset=0]!')
        cfg.core_cfgs[0].Xreset[0] = np.array([0, MAX, MAX, MAX], 'int')
    else:
        cfg.core_cfgs[0].Xreset[0] = np.array([sys.argv[1], MAX, MAX, MAX],
                                              'int')

    # Mapping function between neurons and NSAT parameters groups
    cfg.core_cfgs[0].nmap = np.zeros((N_NEURONS[0], ), dtype='int')

    # Write C NSAT parameters binary files
    c_nsat_writer = nsat.C_NSATWriter(cfg, path='/tmp', prefix='test_reset')
    c_nsat_writer.write()

    print('End %s:setup()' % (os.path.splitext(os.path.basename(__file__))[0]))
    return c_nsat_writer.fname
示例#8
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 = [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]))
示例#9
0
def setup():
    sim_ticks = 500  # Total simulation time
    N_CORES = 1  # Number of cores
    N_NEURONS = [51]  # Number of neurons per core
    N_INPUTS = [0]  # Number of inputs per core
    N_STATES = [4]  # Number of states per neuron 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 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,
                                 plasticity_en=np.array([True], 'bool'),
                                 ben_clock=True)

    # Parameters group 0
    # Transition matrix A
    cfg.core_cfgs[0].A[0] = [[-1, OFF, OFF, OFF], [OFF, OFF, OFF, OFF],
                             [OFF, OFF, OFF, OFF], [OFF, OFF, OFF, OFF]]

    # Sign matrix A
    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([50, 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')

    # Parameters group 0
    # Transition matrix
    cfg.core_cfgs[0].A[1] = [[-1, OFF, OFF, OFF], [OFF, OFF, OFF, OFF],
                             [OFF, OFF, OFF, OFF], [OFF, OFF, OFF, OFF]]

    # Sign matrix
    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[1] = np.array([0, 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')
    # Enable plasticity per state
    cfg.core_cfgs[0].plastic[1] = True
    # Enable STDP per state
    cfg.core_cfgs[0].stdp_en[1] = True

    # Mapping function between NSAT parameters groups and neurons
    cfg.core_cfgs[0].nmap = np.zeros((N_NEURONS[0], ), dtype='int')
    cfg.core_cfgs[0].nmap[0] = 1

    # Mapping function between learning parameters groups and neurons
    lrnmap = np.zeros((nsat.N_GROUPS, N_STATES[0]), dtype='int')
    lrnmap[1] = 1
    cfg.core_cfgs[0].lrnmap = lrnmap

    # Synaptic strength matrix
    W = np.zeros((N_UNITS, N_UNITS, N_STATES[0]))
    W[1:, 0, 0] = 1
    cfg.core_cfgs[0].W = W

    # Adjacent matrix
    CW = np.zeros((N_UNITS, N_UNITS, N_STATES[0]))
    CW[1:, 0, 0] = 1
    cfg.core_cfgs[0].CW = CW

    # Write C NSAT parameters binary files
    c_nsat_writer = nsat.C_NSATWriter(cfg,
                                      path='/tmp',
                                      prefix='test_accumulator')
    c_nsat_writer.write()

    # Write Intel FPGA parameters hex files
    #    intel_fpga_writer = nsat.IntelFPGAWriter(cfg, path='.',
    #                                             prefix='test_accumulator')
    #    intel_fpga_writer.write()
    #
    #    # Call the C NSAT
    #    print("Running C NSAT!")
    #    nsat.run_c_nsat(nsat.fname)
    #
    #    # Load the results (read binary files)
    #    c_nsat_reader = nsat.C_NSATReader(cfg, nsat.fname)
    #    states = c_nsat_reader.read_c_nsat_states()
    #    time_core0, states_core0 = states[0][0], states[0][1]
    #
    #    # Plot the results
    #    fig = plt.figure(figsize=(10, 10))
    #    for i in range(1, 5):
    #        ax = fig.add_subplot(4, 1, i)
    #        ax.plot(states_core0[:-1, 0, i-1], 'b', lw=3)
    #
    #     import os
    #     plt.savefig('/tmp/%s.png' % (os.path.splitext(os.path.basename(__file__))[0]))
    #     plt.close()
    print('End %s:setup()' % (os.path.splitext(os.path.basename(__file__))[0]))
示例#10
0
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
示例#11
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]))
示例#12
0
def setup():
    print('Begin %s:setup()' %
          (os.path.splitext(os.path.basename(__file__))[0]))

    # sim_ticks = 10000             # Simulation time
    sim_ticks = 1000  # Simulation time
    N_CORES = 5  # Number of cores
    N_NEURONS = [300, 300, 300, 300, 300]  # Number of neurons per core
    N_INPUTS = [100, 100, 100, 100, 100]  # Number of inputes per core
    N_STATES = [4, 4, 4, 4, 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

    # 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, OFF, OFF, OFF], [OFF, OFF, OFF, OFF],
                                 [OFF, OFF, OFF, OFF], [OFF, OFF, OFF, OFF]]

        # Sign matrix
        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([50, 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
        cfg.core_cfgs[i].XresetOn[0] = np.array([True, False, False, False],
                                                'bool')

        # Mapping function between neurons and NSAT parameters groups
        cfg.core_cfgs[i].nmap = np.zeros((N_NEURONS[0], ), dtype='int')

    cfg.set_L1_connectivity(({
        (0, 102): ((1, 1), (1, 50), (1, 73)),
        (1, 103): ((1, 15), (1, 95), (1, 7)),
        (2, 105): ((1, 89), (3, 65), (3, 56)),
        (3, 143): ((2, 21), (4, 45), (4, 33)),
        (4, 113): ((1, 5), (1, 50), (1, 7)),
        (2, 133): ((3, 41), (3, 5), (4, 77)),
        (4, 123): ((3, 19), (1, 75), (2, 57)),
        (0, 104): ((2, 3), )
    }))

    # Write C NSAT parameters binary files
    c_nsat_writer = nsat.C_NSATWriter(cfg,
                                      path='/tmp',
                                      prefix='test_multithread')
    c_nsat_writer.write()

    print('End %s:setup()' % (os.path.splitext(os.path.basename(__file__))[0]))
    return c_nsat_writer.fname
示例#13
0
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]))
示例#14
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
示例#15
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
示例#16
0
文件: test_wta.py 项目: nmi-lab/NSAT
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
示例#17
0
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
示例#18
0
    N_INPUTS = [0]  # Number of inputs per core
    N_STATES = [4]  # Number of states per neuron 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 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,
                                 plasticity_en=np.array([True], 'bool'),
                                 ben_clock=True)

    # Parameters group 0
    # Transition matrix A
    cfg.core_cfgs[0].A[0] = [[-1, OFF, OFF, OFF], [OFF, OFF, OFF, OFF],
                             [OFF, OFF, OFF, OFF], [OFF, OFF, OFF, OFF]]

    # Sign matrix A
    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([50, 0, 0, 0], dtype='int')
示例#19
0
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]))
示例#20
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 = [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
示例#21
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 = [1]  # Number of neurons per core (list)
    N_INPUTS = [0]  # Number of inputs per core (list)
    N_STATES = [4]  # Number of states (list)
    N_UNITS = N_INPUTS[0] + N_NEURONS[0]  # Total number of units

    # Basic 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)

    # Transistion matrix A
    cfg.core_cfgs[0].A[0] = [[-1, OFF, OFF, OFF], [OFF, OFF, OFF, OFF],
                             [OFF, OFF, OFF, OFF], [OFF, OFF, OFF, OFF]]

    # Sign matrix sA
    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([50, 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')

    # Tested value
    cfg.core_cfgs[0].Xinit[0] = np.zeros((N_NEURONS[0], N_STATES[0]), 'int')
    if len(sys.argv) != 2:
        print('Missing argument! Default value is used [xinit=0]!')
        cfg.core_cfgs[0].Xinit[0, 0] = 0
        cfg.core_cfgs[0].Xinit[0, 1] = 0
        cfg.core_cfgs[0].Xinit[0, 2] = 0
        cfg.core_cfgs[0].Xinit[0, 3] = 0
    else:
        tmp = int(sys.argv[1])
        print(tmp)
        cfg.core_cfgs[0].Xinit[0, 0] = tmp
        cfg.core_cfgs[0].Xinit[0, 1] = 0
        cfg.core_cfgs[0].Xinit[0, 2] = 0
        cfg.core_cfgs[0].Xinit[0, 3] = 0

    # Write C NSAT parameters files
    cfg.core_cfgs[0].nmap = np.zeros((N_NEURONS[0], ), dtype='int')

    c_nsat_writer = nsat.C_NSATWriter(cfg,
                                      path='/tmp',
                                      prefix='test_initial_cond')
    c_nsat_writer.write()

    # Write Intel FPGA parameters files
    #    intel_fpga_writer = nsat.IntelFPGAWriter(cfg, path='.',
    #                                             prefix='test_initial_cond')
    #    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
示例#22
0
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]))
示例#23
0
    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],
示例#24
0
W = np.zeros([N_NEURONS+N_INPUTS, N_NEURONS+N_INPUTS, N_STATES], 'int')
W[:N_INPUTS,N_INPUTS:] = extW
W[N_INPUTS:,N_INPUTS:] = recW

CW = np.zeros([N_NEURONS+N_INPUTS, N_NEURONS+N_INPUTS, N_STATES], 'int')
CW[:N_INPUTS,N_INPUTS:] = extCW
CW[N_INPUTS:,N_INPUTS:] = recCW

W = np.array(W)

cfg_train = nsat.ConfigurationNSAT(
                   sim_ticks = sim_ticks,
                   N_CORES = N_CORES,
                   N_NEURONS=[N_NEURONS], 
                   N_INPUTS=[N_INPUTS],
                   N_STATES=[N_STATES],
                   bm_rng=True,
                   monitor_spikes = True,
                   gated_learning = [True],
                   plasticity_en = [True])

# Parameters groups mapping function
core0_cfg = cfg_train.core_cfgs[0]
core0_cfg.nmap = np.zeros(N_NEURONS, dtype='int')
core0_cfg.lrnmap = np.zeros((N_GROUPS, N_STATES), dtype='int')
core0_cfg.nmap[sP:sP+Np] = 2
core0_cfg.nmap[sH:sH+Np] = 0
core0_cfg.nmap[sg1:] = 1
core0_cfg.lrnmap = np.zeros((N_GROUPS, N_STATES), dtype='int')
core0_cfg.lrnmap[core0_cfg.nmap[:sP+Np],1] = 1
 
    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')
示例#26
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]))
示例#27
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 = [8]  # Number of neurons
    N_INPUTS = [0]  # 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 per group
    cfg.core_cfgs[0].A[0, 0, 0] = -1
    cfg.core_cfgs[0].A[1, 0, 0] = -2
    cfg.core_cfgs[0].A[2, 0, 0] = -3
    cfg.core_cfgs[0].A[3, 0, 0] = -4
    cfg.core_cfgs[0].A[4, 0, 0] = -5
    cfg.core_cfgs[0].A[5, 0, 0] = -12
    cfg.core_cfgs[0].A[6, 0, 0] = -7
    cfg.core_cfgs[0].A[7, 0, 0] = -3

    # Sign matrix per group
    cfg.core_cfgs[0].sA[0, 0, 0] = -1
    cfg.core_cfgs[0].sA[1, 0, 0] = -1
    cfg.core_cfgs[0].sA[2, 0, 0] = -1
    cfg.core_cfgs[0].sA[3, 0, 0] = -1
    cfg.core_cfgs[0].sA[4, 0, 0] = -1
    cfg.core_cfgs[0].sA[5, 0, 0] = -1
    cfg.core_cfgs[0].sA[6, 0, 0] = -1
    cfg.core_cfgs[0].sA[7, 0, 0] = -1

    # Bias matrix per group
    cfg.core_cfgs[0].b[0, 0] = 50
    cfg.core_cfgs[0].b[1, 0] = 80
    cfg.core_cfgs[0].b[2, 0] = 50
    cfg.core_cfgs[0].b[3, 0] = 20
    cfg.core_cfgs[0].b[4, 0] = 50
    cfg.core_cfgs[0].b[5, 0] = 60
    cfg.core_cfgs[0].b[6, 0] = 50
    cfg.core_cfgs[0].b[7, 0] = 5

    # Threshold
    cfg.core_cfgs[0].Xth = np.ones((nsat.N_GROUPS, )) * 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')

    # Mapping between neurons and NSAT parameters groups
    nmap = np.arange(N_NEURONS[0], dtype='int')
    cfg.core_cfgs[0].nmap = nmap

    # Write C NSAT parameters binary files
    c_nsat_writer = nsat.C_NSATWriter(cfg,
                                      path='/tmp',
                                      prefix='test_params_groups')
    c_nsat_writer.write()

    # Write Intel FPGA parameters hex files
    #    intel_fpga_writer = nsat.IntelFPGAWriter(cfg, path='.',
    #                                             prefix='test_parameters_groups')
    #    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
示例#28
0
def setup():
    print('Begin %s:setup()' %
          (os.path.splitext(os.path.basename(__file__))[0]))
    sim_ticks = 5000  # Simulation time
    N_CORES = 1  # Number of cores
    N_NEURONS = [2]  # Number of neurons per core (list)
    N_INPUTS = [0]  # Number of inputs per core (list)
    N_STATES = [4]  # Number of states per core (list)

    # 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 A
    cfg.core_cfgs[0].A[0] = [[-6, OFF, OFF, OFF], [0, -11, OFF, OFF],
                             [0, OFF, -8, OFF], [OFF, OFF, OFF, OFF]]

    # Sign matrix sA
    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([600, 0, 0, 1], dtype='int')
    # Threshold
    cfg.core_cfgs[0].Xth[0] = XMAX
    # 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')
    # Global modulator state (e.g. Dopamine)
    cfg.core_cfgs[0].modstate[0] = 3

    # Synaptic weights
    N_UNITS = N_INPUTS[0] + N_NEURONS[0]  # Total number of units
    W = np.zeros([N_UNITS, N_UNITS, N_STATES[0]], 'int')
    W[0, 0, 1] = 115
    W[0, 1, 2] = 125
    W[1, 1, 1] = 115
    W[1, 0, 2] = 125
    cfg.core_cfgs[0].W = W

    # Adjacent matrix
    CW = np.zeros(W.shape, dtype='int')
    CW[0, 0, 1] = 1
    CW[0, 1, 2] = 1
    CW[1, 1, 1] = 1
    CW[1, 0, 2] = 1
    cfg.core_cfgs[0].CW = CW

    # Mapping between neurons and NSAT parameters groups
    cfg.core_cfgs[0].nmap = np.zeros((N_NEURONS[0], ), dtype='int')

    # Write C NSAT parameters binary files
    c_nsat_writer = nsat.C_NSATWriter(cfg, path='/tmp', prefix='test_adapting')
    c_nsat_writer.write()

    # Write Intel FPGA parameters hex files
    #    intel_fpga_writer = nsat.IntelFPGAWriter(cfg, path='.',
    #                                             prefix='test_adapting')
    #    intel_fpga_writer.write()
    #    intel_fpga_writer.write_globals()
    print('End %s:setup()' % (os.path.splitext(os.path.basename(__file__))[0]))
示例#29
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
示例#30
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]))