예제 #1
0
def runMNIST(run_params, imgs, states, net):
    num_train = run_params['num_trials']
    prefix = run_params['prefix']
    inp = run_params['input_intensity']
    run_time = run_params['time_per_image']
    N_AL = run_params['N_AL']
    labels = run_params['labels']
    numbers_to_inc = run_params['numbers_to_inc']
    bin_thresh = run_params['bin_thresh']
    n_input = run_params['n_input']

    G_AL = states['G_AL']
    spikes_AL = states['spikes_AL']
    trace_AL = states['trace_AL']

    num_run = {}
    for i in numbers_to_inc:
        num_run[i] = 0

    start = 100
    #run the network
    n = 0
    for i in range(60000):
        y = labels[i][0]
        if y in numbers_to_inc and num_run[y] < num_train:
            net.restore()
            print('image: ' + str(n))
            print('label: ' + str(labels[i][0]))

            #right now creating binary image
            rates = np.where(imgs[i % 60000, :, :] > bin_thresh, 1, 0) * inp

            linear = np.ravel(rates)
            padding = N_AL - n_input
            I = np.pad(linear, (0, padding),
                       'constant',
                       constant_values=(0, 0))
            I = I + rshuffle(I, random_state=10) + rshuffle(I, random_state=2)

            I = np.where(I > inp, inp, I)
            print(np.sum(I / inp))

            G_AL.I_inj = nA * I

            net.run(run_time * ms, report='text')

            np.save(prefix + 'spikes_t_' + str(n), spikes_AL.t)
            np.save(prefix + 'spikes_i_' + str(n), spikes_AL.i)
            np.save(prefix + 'I_' + str(n), I)
            np.save(prefix + 'trace_V_' + str(n), trace_AL.V[:, start:])
            np.save(prefix + 'trace_t_' + str(n), trace_AL.t[start:])

            np.save(prefix + 'labels_' + str(n),
                    np.ones(len(trace_AL.t[start:])) * y)
            n = n + 1
            num_run[y] = num_run[y] + 1
        if all(value == num_train for value in num_run.values()):
            break
예제 #2
0
#----------------------------------------------------------


#load MNIST data
start = time.time()
training = ex.get_labeled_data(MNIST_data_path + 'training', MNIST_data_path)
end = time.time()
print('time needed to load training set:', end - start)

n_input = training['rows']*training['cols'] #28x28=784

num_tot_images = len(training['x'])
imgs = training['x']
labels = training['y']

imgs, labels = rshuffle(imgs, labels)

#run the network
j = 0
for i in range(num_tot_images):
    if labels[i][0] in numbers_to_inc:
        print('image: ' + str(j))
        j = j+1

        #reset network
        G_AL.I_inj = 0.0*np.ones(N_AL)*nA
        net.run(reset_time*ms)
        print(G_AL.active)

        #right now creating binary image
        rates = np.where(imgs[i%60000,:,:] > bin_thresh, 1, 0)*input_intensity
예제 #3
0
                              MNIST_data_path,
                              bTrain=False)
end = time.time()
print('time needed to load test set:', end - start)

n_input = training['rows'] * training['cols']  #28x28=784

num_tot_train = len(training['x'])
imgs_train = training['x']
labels_train = training['y']

num_tot_test = len(testing['x'])
imgs_test = testing['x']
labels_test = testing['y']

imgs_train, labels_train = rshuffle(imgs_train, labels_train)
imgs_test, labels_test = rshuffle(imgs_test, labels_test)

#-------------------------------------------------------

run_params_train = dict(
    num_trials=num_train,
    prefix=tr_prefix,
    input_intensity=input_intensity,
    time_per_image=time_per_image,
    N_AL=N_AL,
    labels=labels_train,
    numbers_to_inc=numbers_to_inc,
    bin_thresh=bin_thresh,
    n_input=n_input,
)