Пример #1
0
def run(fnames):
    # Call the C NSAT
    print('Begin %s:run()' % (os.path.splitext(os.path.basename(__file__))[0]))
    cfg = nsat.ConfigurationNSAT.readfileb(fnames.pickled)
    nsat.run_c_nsat(fnames)

    # Load the results (read binary files)
    c_nsat_reader = nsat.C_NSATReader(cfg, fnames)
    states = c_nsat_reader.read_c_nsat_states()
    states_core0 = states[0][1]
    # np.save('states', states_core0)

    in_spikelist = SL
    ifname = fnames.events + '_core_0.dat'
    out_spikelist = nsat.importAER(nsat.read_from_file(ifname),
                                   sim_ticks=sim_ticks,
                                   id_list=[0])

    # Plot the results
    fig = plt.figure(figsize=(10, 10))
    for i in range(1, 9):
        ax = fig.add_subplot(8, 1, i)
        ax.plot(states_core0[:-1, 15, i - 1], 'b', lw=1.5)

    # fig = plt.figure(figsize=(10, 10))
    # for i in range(1, 9):
    #     ax = fig.add_subplot(8, 1, i)
    #     ax.plot(states_core0[:-1, 16, i-1], 'b', lw=1.5)

    # out_spikelist.raster_plot()

    plt.savefig('/tmp/%s.png' %
                (os.path.splitext(os.path.basename(__file__))[0]))
    plt.close()
    print('End %s:run()' % (os.path.splitext(os.path.basename(__file__))[0]))
Пример #2
0
def run():
    # Call the C NSAT
    print('Begin %s:run()' % (os.path.splitext(os.path.basename(__file__))[0]))
    cfg = nsat.ConfigurationNSAT.readfileb(nsat.fnames.pickled)

    nsat.run_c_nsat()

    # Load the results (read binary files)
    c_nsat_reader = nsat.C_NSATReader(cfg, nsat.fnames)
    states = c_nsat_reader.read_c_nsat_states()
    time_core0, states_core0 = states[0][0], states[0][1]

    out_spikelist = nsat.importAER(nsat.read_from_file(nsat.fnames.events +
                                                       '_core_0.dat'),
                                   sim_ticks=sim_ticks,
                                   id_list=[0])

    # Plot the results
    fig = plt.figure(figsize=(10, 10))
    for i in range(1, 9):
        ax = fig.add_subplot(8, 1, i)
        ax.plot(states_core0[:, 0, i - 1], 'b', lw=2)

    plt.savefig('/tmp/%s.png' %
                (os.path.splitext(os.path.basename(__file__))[0]))
    plt.close()
    print('Begin %s:run()' % (os.path.splitext(os.path.basename(__file__))[0]))
Пример #3
0
def run():
    # Call the C NSAT
    print('Begin %s:run()' % (os.path.splitext(os.path.basename(__file__))[0]))
    cfg = nsat.ConfigurationNSAT.readfileb(nsat.fnames.pickled)
    nsat.run_c_nsat()

    # Load the results (read binary files)
    c_nsat_reader = nsat.C_NSATReader(cfg, nsat.fnames)
    states = c_nsat_reader.read_c_nsat_states()
    states_core0 = states[0][1]

    # wt = c_nsat_reader.read_c_nsat_weights_evo(0)[:, 1, 1]
    wt, pids = c_nsat_reader.read_synaptic_weights_history(post=[0])
    in_spikelist = SL
    out_spikelist = nsat.importAER(nsat.read_from_file(nsat.fnames.events+'_core_0.dat'),
                                   sim_ticks=sim_ticks,
                                   id_list=[0])

    # Plot the results
    fig = plt.figure(figsize=(10, 10))
    i = 1
    ax = fig.add_subplot(4, 1, i)
    ax.plot(states_core0[:-1, 0, i - 1], 'b', lw=3, label='$V_m$')
    ax.set_ylabel('$V_m$')
    ax.set_xticks([])
    plt.locator_params(axis='y', nbins=4)
    i = 2
    ax = fig.add_subplot(4, 1, i)
    ax.plot(states_core0[:-1, 0, i - 1], 'b', lw=3, label='$I_{syn}$')
    ax.set_ylabel('$I_{syn}$')
    ax.set_xticks([])
    plt.locator_params(axis='y', nbins=4)
    for t in SL[0].spike_times:
        plt.axvline(t, color='k')

    i = 4
    ax = fig.add_subplot(4, 1, i)
    for t in SL[0].spike_times:
        plt.axvline(t, color='k')
    ax.plot(states_core0[:-1, 0, 2], 'b', lw=3, label='$x_m$')
    ax.set_ylabel('$x_m$')
    plt.axhline(0, color='b', alpha=.5, linewidth=3)
    plt.locator_params(axis='y', nbins=4)
    i = 3

    ax = fig.add_subplot(4, 1, i)
    for t in SL[0].spike_times:
        plt.axvline(t, color='k')
    ax.plot(wt[0][:, 1, 1], 'r', lw=3)
    ax.set_ylabel('$w$')
    ax.set_xticks([])
    plt.locator_params(axis='y', nbins=4)

    plt.savefig('/tmp/%s.png' % (os.path.splitext(os.path.basename(__file__))[0]))
    plt.close()
    print('End %s:run()' % (os.path.splitext(os.path.basename(__file__))[0]))
Пример #4
0
def run():
    # Call the C NSAT
    print('Begin %s:run()' % (os.path.splitext(os.path.basename(__file__))[0]))
    cfg = nsat.ConfigurationNSAT.readfileb(nsat.fnames.pickled)
    nsat.run_c_nsat()

    # Load the results (read binary files)
    c_nsat_reader = nsat.C_NSATReader(cfg, nsat.fnames)
    states = c_nsat_reader.read_c_nsat_states()
    states_core0 = states[0][1]

    plt.figure()
    for i in range(1, 5):
        plt.subplot(4, 1, i)
        plt.plot(states_core0[:, :, i - 1])

    plt.figure()
    S = np.maximum(states_core0[:, :, 0], 0)
    plt.imshow(
        S,
        interpolation='spline36',
        cmap=plt.get_cmap('gray'),  #plt.cm.gray,
        aspect='auto',
        origin='lower')

    spks = nsat.importAER(nsat.read_from_file(nsat.fnames.events +
                                              '_core_0.dat'),
                          sim_ticks=sim_ticks,
                          id_list=list(range(cfg.core_cfgs[0].n_neurons)))

    try:
        raster = spks.raster_plot()
        raster.savefig('/tmp/%s_raster.png' %
                       (os.path.splitext(os.path.basename(__file__))[0]))
        raster.close()
    except:
        print('test_nf: Failed to generate /tmp/%s_raster.png' %
              (os.path.splitext(os.path.basename(__file__))[0]))

    # Plot the results


#     events = spks.convert()
#     mat = np.zeros((sim_ticks, N_NEURONS[0]))
#     print(mat.shape)
#     print(len(events[0]))
#     print(len(events[1]))
#     mat[events[0].astype('i'), events[1].astype('i')] = 1

    plt.savefig('/tmp/%s.png' %
                (os.path.splitext(os.path.basename(__file__))[0]))
    plt.close()
    print('End %s:run()' % (os.path.splitext(os.path.basename(__file__))[0]))
Пример #5
0
def run(fnames):
    # Call the C NSAT
    print('Begin %s:run()' % (os.path.splitext(os.path.basename(__file__))[0]))
    cfg = nsat.ConfigurationNSAT.readfileb(fnames.pickled)
    nsat.run_c_nsat(fnames)

    # Load the results (read binary files)
    c_nsat_reader = nsat.C_NSATReader(cfg, fnames)
    states = c_nsat_reader.read_c_nsat_states()
    time_core0, states_core0 = states[0][0], states[0][1]

    wt, _ = c_nsat_reader.read_c_nsat_weights_evo([0, 1])
    wt = wt[0]

    out_spikelist = nsat.importAER(nsat.read_from_file(fnames.events +
                                                       '_core_0.dat'),
                                   sim_ticks=sim_ticks)

    # Plot the results
    fig = plt.figure(figsize=(15, 15))

    ax = fig.add_subplot(4, 2, 1)
    ax.plot(states_core0[:-1, 0, 0], 'b', lw=3, label='$x_m$')
    ax.set_ylabel('$V_m$')

    ax = fig.add_subplot(4, 2, 2)
    ax.plot(states_core0[:-1, 1, 0], 'b', lw=3, label='$x_m$')
    ax.set_ylabel('$V_m$')

    ax = fig.add_subplot(4, 2, 3)
    ax.plot(states_core0[:-1, 0, 1], 'b', lw=3, label='$I_{syn}$')
    ax.set_ylabel('$I_{syn}$')

    ax = fig.add_subplot(4, 2, 4)
    ax.plot(states_core0[:-1, 1, 1], 'b', lw=3, label='$I_{syn}$')
    ax.set_ylabel('$I_{syn}$')

    ax = fig.add_subplot(4, 2, 5)
    ax.plot(states_core0[:-1, 0, 2], 'b', lw=3, label='$x_m$')
    ax.set_ylabel('$x_m$')

    ax = fig.add_subplot(4, 2, 6)
    ax.plot(states_core0[:-1, 1, 2], 'b', lw=3, label='$x_m$')
    ax.set_ylabel('$x_m$')

    ax = fig.add_subplot(4, 2, 7)
    ax.plot(wt[:, 1, 1], 'r', lw=3)
    ax.set_ylabel('$w$')

    ax = fig.add_subplot(4, 2, 8)
    ax.plot(wt[:, 0, 1], 'r', lw=3)
    ax.set_ylabel('$w$')

    fig = plt.figure(figsize=(10, 5))
    plt.plot(wt[:, 0, 1], 'r', lw=2, zorder=10)
    plt.plot(wt[:, 1, 1], 'y', lw=2, zorder=10)
    # for i in out_spikelist[0].spike_times:
    # plt.axvline(i, color='k', lw=1, zorder=0)
    # for i in out_spikelist[1].spike_times:
    # plt.axvline(i, color='b', lw=1, zorder=0)

    plt.savefig('/tmp/%s.png' %
                (os.path.splitext(os.path.basename(__file__))[0]))
    plt.close()
    print('End %s:run()' % (os.path.splitext(os.path.basename(__file__))[0]))
Пример #6
0
    #    intel_fpga_writer.write()
    #    intel_fpga_writer.write_globals()

    # Call the C NSAT
    print("Running C NSAT!")
    nsat.run_c_nsat(c_nsat_writer.fname)

    # Load the results (read binary files)
    c_nsat_reader = nsat.C_NSATReader(cfg, c_nsat_writer.fname)
    #ww = np.array(c_nsat_reader.read_c_nsat_synaptic_weights()[0])
    states = c_nsat_reader.read_c_nsat_states()
    time_core0, states_core0 = states[0][0], states[0][1]
    # wt = c_nsat_reader.read_c_nsat_weights_evo(2)[0]
    wt = c_nsat_reader.read_c_nsat_syn_evo()[0][0]

    spk = nsat.importAER(nsat.read_from_file(c_nsat_writer.fname.events +
                                             '_core_0.dat'),
                         sim_ticks=sim_ticks)
    spk.raster_plot()

    print((SL[0].spike_times))
    print((SL[1].spike_times))
    print((spk[0].spike_times))

    #fig = plt.figure()
    #ax = fig.add_subplot(111)
    #ax.plot(ww[:N_INPUTS[0], N_INPUTS[0], 1], 'k.')

    # Plot the results
    fig = plt.figure(figsize=(15, 15))

    ax = fig.add_subplot(4, 2, 1)
Пример #7
0
    ##    intel_fpga_writer = nsat.IntelFPGAWriter(cfg, path='.',
    ##                                             prefix='test_two_neurons_stdp')
    ##    intel_fpga_writer.write()
    ##    intel_fpga_writer.write_globals()

    # Call the C NSAT
    print("Running C NSAT!")
    nsat.run_c_nsat(c_nsat_writer.fname)

    # Load the results (read binary files)
    c_nsat_reader = nsat.C_NSATReader(cfg, c_nsat_writer.fname)
    states = c_nsat_reader.read_c_nsat_states()
    time_core0, states_core0 = states[0][0], states[0][1]
    wt = c_nsat_reader.read_c_nsat_weights_evo(2)[0]
    out_spikelist = nsat.importAER(
        nsat.read_from_file(c_nsat_writer.fname.events + '_core_0.dat'),
        sim_ticks=sim_ticks,
        id_list=[0])

    # Plot the results
    fig = plt.figure(figsize=(15, 15))

    ax = fig.add_subplot(4, 2, 1)
    ax.plot(states_core0[:-1, 0, 0], 'b', lw=3, label='$x_m$')
    ax.set_ylabel('$V_m$')

    ax = fig.add_subplot(4, 2, 2)
    ax.plot(states_core0[:-1, 1, 0], 'b', lw=3, label='$x_m$')
    ax.set_ylabel('$V_m$')

    ax = fig.add_subplot(4, 2, 3)
Пример #8
0
    c_nsat_writer = nsat.C_NSATWriter(cfg, path='/tmp', prefix='test_td')
    c_nsat_writer.write()

    # Call the C NSAT
    print("Running C NSAT!")
    nsat.run_c_nsat(c_nsat_writer.fname)

    # Load the results (read binary files)
    c_nsat_reader = nsat.C_NSATReader(cfg, c_nsat_writer.fname)
    states = c_nsat_reader.read_c_nsat_states()
    states_core0 = states[0][1]
    # np.save('states', states_core0)

    in_spikelist = SL
    ifname = c_nsat_writer.fname.events + '_core_0.dat'
    out_spikelist = nsat.importAER(nsat.read_from_file(ifname),
                                   sim_ticks=sim_ticks,
                                   id_list=[0])

    # Plot the results
    fig = plt.figure(figsize=(10, 10))
    for i in range(1, 9):
        ax = fig.add_subplot(8, 1, i)
        ax.plot(states_core0[:-1, 15, i - 1], 'b', lw=1.5)

    # fig = plt.figure(figsize=(10, 10))
    # for i in range(1, 9):
    #     ax = fig.add_subplot(8, 1, i)
    #     ax.plot(states_core0[:-1, 16, i-1], 'b', lw=1.5)

    # out_spikelist.raster_plot()
Пример #9
0
    # Call the C NSAT
    print("Running C NSAT!")
    nsat.run_c_nsat(c_nsat_writer.fname)

    # Load the results (read binary files)
    c_nsat_reader = nsat.C_NSATReader(cfg, c_nsat_writer.fname)
    states = c_nsat_reader.read_c_nsat_states()
    time_core0, states_core0 = states[0][0], states[0][1]

    wt = c_nsat_reader.read_c_nsat_weights_evo([0, 1])[0]
    # cfg.write_hex_weights_monitors(wt[:, 0, 1])
    # out_spikelist = nsat.importAER(nsat.read_from_file(c_nsat_writer.fname.events+'_core_0.dat'),
    #                                sim_ticks=sim_ticks, id_list=[0])
    out_spikelist = nsat.importAER(
        nsat.read_from_file(c_nsat_writer.fname.events +
                            '_core_0.dat'.encode('utf-8')),
        sim_ticks=sim_ticks)

    # Plot the results
    fig = plt.figure(figsize=(15, 15))

    ax = fig.add_subplot(4, 2, 1)
    ax.plot(states_core0[:-1, 0, 0], 'b', lw=3, label='$x_m$')
    ax.set_ylabel('$V_m$')

    ax = fig.add_subplot(4, 2, 2)
    ax.plot(states_core0[:-1, 1, 0], 'b', lw=3, label='$x_m$')
    ax.set_ylabel('$V_m$')

    ax = fig.add_subplot(4, 2, 3)
    ax.plot(states_core0[:-1, 0, 1], 'b', lw=3, label='$I_{syn}$')
Пример #10
0
#    intel_fpga_writer.write_globals()

    # Call the C NSAT
    print("Running C NSAT!")
    nsat.run_c_nsat(c_nsat_writer.fname)

    # Load the results (read binary files)
    c_nsat_reader = nsat.C_NSATReader(cfg, c_nsat_writer.fname)
    states = c_nsat_reader.read_c_nsat_states()
    time_core0, states_core0 = states[0][0], states[0][1]

    wt = c_nsat_reader.read_c_nsat_weights_evo([0, 1])[0]
    # cfg.write_hex_weights_monitors(wt[:, 0, 1])
    # out_spikelist = nsat.importAER(nsat.read_from_file(c_nsat_writer.fname.events+'_core_0.dat'),
    #                                sim_ticks=sim_ticks, id_list=[0])
    out_spikelist = nsat.importAER(nsat.read_from_file(c_nsat_writer.fname.events+'_core_0.dat'.encode('utf-8')),
                                   sim_ticks=sim_ticks)

    # Plot the results
    fig = plt.figure(figsize=(15, 15))

    ax = fig.add_subplot(4, 2, 1)
    ax.plot(states_core0[:-1, 0, 0], 'b', lw=3, label='$x_m$')
    ax.set_ylabel('$V_m$')

    ax = fig.add_subplot(4, 2, 2)
    ax.plot(states_core0[:-1, 1, 0], 'b', lw=3, label='$x_m$')
    ax.set_ylabel('$V_m$')

    ax = fig.add_subplot(4, 2, 3)
    ax.plot(states_core0[:-1, 0, 1], 'b', lw=3, label='$I_{syn}$')
    copyfile(
        fname_train.shared_mem + '_core_0.dat',
        fname_test.syn_wgt_table + '_core_0.dat',
    )

    # c_nsat_writer_test.write_L0connectivity()
    # c_nsat_writer_train.write_L0connectivity()
    s = c_nsat_reader_train.read_stats()[0]
    stats_nsat.append(s)
    #stats_ext.append(n_ext)
    if test_every > 0:
        if i % test_every == test_every - 1:
            nsat.run_c_nsat(fname_test)
            test_spikelist = nsat.importAER(
                nsat.read_from_file(fname_test.events + '_core_0.dat'),
                sim_ticks=sim_ticks_test,
                id_list=np.arange(sP, sP + Np))

            pip.append([
                i,
                float(
                    sum(
                        np.argmax(test_spikelist.id_slice(range(
                            sP, sP + Np)).firing_rate(t_sample_test).T,
                                  axis=1) == targets_classify[:N_test])) /
                N_test * 100
            ])

            print exp_name
            print pip
Пример #12
0
if __name__ == '__main__':
    n_epoch = 50
    e = []
    print("############## Training ##############")
    for i in range(n_epoch):
        # Call the C NSAT for learning
        print("Epoch #:  ", i)
        c_nsat_writer_train.fname.stats_nsat = '/tmp/test_eCD_stats_nsat'+str(i)
        nsat.run_c_nsat(c_nsat_writer_train.fname)
        if n_epoch > 1:
            shutil.copyfile(fname_train.shared_mem+'_core_0.dat',
                            fname_train.syn_wgt_table+'_core_0.dat',)
            shutil.copyfile(fname_train.shared_mem+'_core_0.dat',
                            fname_test.syn_wgt_table+'_core_0.dat',)
        nsat.run_c_nsat(c_nsat_writer_test.fname)
        test_spk = nsat.importAER(nsat.read_from_file(c_nsat_writer_test.fname.events+'_core_0.dat'), sim_ticks=sim_ticks_test)
        train_spk = nsat.importAER(nsat.read_from_file(c_nsat_writer_train.fname.events+'_core_0.dat'), sim_ticks=sim_ticks_train)
        sl = test_spk.id_slice([16, 17])
        mm = np.argmax(sl.firing_rate(time_bin=test_duration), axis=0)[::2]
        print(100*sum(labels[::2] != mm)/32.0)
        e.append(sum(labels[::2] != mm) / 32.0)

    e = np.array(e)
    np.save('/tmp/error_full', e)
    # fig = plt.figure()
    # ax = fig.add_subplot(111)
    # ax.plot(e, 'x-k', lw=2)

    W_new = c_nsat_reader_train.read_c_nsat_weights()[0]
    r, c = Ns+Ne+Ni, Ns+Ne+Ni+Nv
    W = W_new[(Ns+Ne+Ni):(Ns+Ne+Ni+Nv), (Ns+Ne+Ni+Nv):, 1]