def initialize_network(self, params): allBut1 = schemes.get("allBut1") all2all = schemes.get("all2all") Input = population.Image_Input(28, 28) c_params = { "eta": params.get("eta", 0.0005), "mu": params.get("mu", 0.05), } L1 = population.Population(num_neurons=params.get("num_neurons", 16), v_init=params.get("v_init", -65), v_decay=params.get("v_decay", .99), v_reset=params.get("v_reset", -65), min_volt=params.get("v_rest", -65), t_init=params.get("min_volt", -50), min_thresh=params.get("min_thresh", -52), t_bias=params.get("t_bias", 0.25), t_decay=params.get("t_decay", .9999999), trace_decay=params.get("trace_decay", 0.95), refrac=params.get("refrac", 5), one_spike=params.get("one_spike", True)) inh = params.get("inh", -120) C1 = Connection(Input, L1, 0.3 * all2all(Input.num_neurons, L1.num_neurons), params, rule="PreAndPost", wmin=0, wmax=1) C2 = Connection(L1, L1, allBut1(L1.num_neurons) * inh, params, rule="static", wmin=inh, wmax=0) self.network = Network([ Input, L1, ], [ C1, C2, ])
C2 = Connection(L1, L2, one2one(L1.num_neurons) * exc, params, rule="static", wmin=0, wmax=exc) C3 = Connection(L2, L1, allBut1(L1.num_neurons) * inh, params, rule="static", wmin=inh, wmax=0) network = Network([Input, L1, L2], [C1, C2, C3]) plotter = Plotter(["voltage", "trace", "activation"]) outer = tqdm(total=100, desc='Epochs', position=0) for i in range(100): train.all_at_once(network, x_train[1000 * i:1000 * (i + 1)], y_train[1000 * i:1000 * (i + 1)], 10, 300, draw_weights=True, plot=plotter) outer.update(1)
wmin=0, wmax=1, norm=78.4) C2 = Connection(L1, L1, allBut1(L1.num_neurons) * inh, params, rule="static", wmin=inh, wmax=0) network = Network([ Input, L1, ], [ C1, C2, ]) plotter = Plotter(["trace"]) # outer = tqdm(total = 100, desc = 'Epochs', position = 0) for i in range(100): # train.all_at_once(network, x_train[500 * i: 500 * (i+1)], y_train[500 * i: 500 * (i+1)], 10, 250, draw_weights = True) print("Training", i) train.train(network, x_train[500 * i:500 * (i + 1)], 250, save_weights=True, plot=plotter)
0.3 * all2all(Input.num_neurons, L1.num_neurons), params, rule = "static", wmin = 0, wmax = 1, norm = 78.4) C2 = Connection(L1, L1, allBut1(L1.num_neurons) * inh, params, rule = "static", wmin = inh, wmax = 0) network = Network([Input, L1], [C1, C2]) ''' Import and load saved weights ''' weight_file = open('weights.pickle', 'rb') weights = pickle.load(weight_file) weight_file.close() network.set_weights(weights) ''' Record spiking activity of Layer 1 while showing it a bunch of images ''' print("Recording Spikes") num_images = 1 time_step = 50 spikes = [] for i in tqdm(range(num_images)): network.populations[0].set_input(x_train[i]) spikes.append(network.run(time_step, learning=False, record_spikes=True, pop_index=1).get("spikes"))