training_dataset = [] # for the number of specified training samples for i in range(training_samples): # randomly select a training sample # rand_sample = random.randint(0,n_classes-1) # provide an even number of training samples rand_sample = i % n_classes # add the sample to the list of training samples training_dataset.append(imgs[rand_sample]) # initialize the encoder encoder = BernoulliEncoder(time=time, dt=dt) # list of encoded images for random selection during training encoded_train_inputs = [] # loop through encode each image type and store into a list of encoded images for sample in training_dataset: # encode the image encoded_img = encoder(torch.flatten(sample["Image"])) # encoded image input for the network encoded_img_input = {input_layer_name: encoded_img} # encoded image label encoded_img_label = sample["Label"]
update_rule=MSTDPET, nu=2e-2, norm=0.15 * middle.n, ) # Add all layers and connections to the network. network.add_layer(inpt, name="X") network.add_layer(middle, name="Y") network.add_layer(out, name="Z") network.add_connection(inpt_middle, source="X", target="Y") network.add_connection(middle_out, source="Y", target="Z") # Load SpaceInvaders environment. environment = GymEnvironment( "SpaceInvaders-v0", BernoulliEncoder(time=int(network.dt), dt=network.dt), history_length=2, delta=4, ) environment.reset() # Plotting configuration. plot_config = { "data_step": 1, "data_length": 10, "reward_eps": 1, "reward_window": 10, "volts_type": "line" } # Build pipeline from specified components.
network.add_layer(layers[layer], name=layer) network.add_connection(input_exc_conn, source="X", target="E") network.add_connection(exc_readout_conn, source="E", target="R") # Add all monitors to the network. for layer in layers: network.add_monitor(spikes[layer], name="%s_spikes" % layer) if layer in voltages: network.add_monitor(voltages[layer], name="%s_voltages" % layer) # Load SpaceInvaders environment. environment = GymEnvironment( "SpaceInvaders-v0", BernoulliEncoder(time=1, dt=network.dt), history_length=2, delta=4, ) environment.reset() # Build pipeline from specified components. pipeline = EnvironmentPipeline( network, environment, action_function=select_multinomial, output="R", plot_interval=plot_interval, print_interval=print_interval, render_interval=render_interval, )