Пример #1
0
mbon_spikes = None

NUM_STIM = 100
while model.timestep < (single_example_timesteps * NUM_STIM):
    # Calculate the timestep within the presentation
    timestep_in_example = model.timestep % single_example_timesteps
    example = int(model.timestep // single_example_timesteps)

    # If this is the first timestep of the presentation
    if timestep_in_example == 0:
        # Get image
        input_vector = training_images[example]

        # Normalize
        pn_input_current_view[:] = input_vector * INPUT_SCALE
        model.push_var_to_device("pn_input", "magnitude")

        pn_refrac_time_view[:] = 0.0
        model.push_var_to_device("pn", "RefracTime")

    # Otherwise, if this timestep is the start of the resting period
    elif timestep_in_example == NUM_PRESENT_TIMESTEPS:
        pn_input_current_view[:] = 0.0
        model.push_var_to_device("pn_input", "magnitude")

    model.step_time()

    if plot:
        model.pull_current_spikes_from_device("pn")
        pn_spikes = record_current_spikes(pn, pn_spikes, model.t)
Пример #2
0
    # If this is the first timestep of presenting the example
    if timestep_in_example == 0:

        print("Example: " + str(example))

        layer_spikes = [(np.empty(0), np.empty(0))
                        for _ in enumerate(neuron_layers)]

        # calculate the correct spiking rates for all populations
        digit = X[example, :].flatten()
        digit = np.divide(digit, np.amax(digit))
        active_pixels = np.count_nonzero(digit)

        inh_rate[:] = INH_V * active_pixels / NUM_INPUT
        model.push_var_to_device("inh", "rate")

        input_rate[:] = (digit * (INPUT_STIM - INPUT_UNSTIM)) + INPUT_UNSTIM
        model.push_var_to_device("inp", "rate")

        out_voltage[:] = 0.0
        model.push_var_to_device('out', "V")

        output_spike_count[:] = 0
        model.push_var_to_device("out", "SpikeCount")

    # Advance simulation
    model.step_time()

    for idx, layer in enumerate(neuron_layers):
        # Download spikes
Пример #3
0
        layer_spikes = [(np.empty(0), np.empty(0))
                        for _ in enumerate(neuron_layers)]
        # layer_spikes = np.empty(0)

        # if example % 10 == 0:
        #     print("Example: " + str(example))

        print("Example: " + str(example))

        # calculate the correct spiking rates for all populations
        digit = X[example, :].flatten()
        digit = np.divide(digit, np.amax(digit))
        active_pixels = np.count_nonzero(digit)

        inh_rate[:] = INH_V * active_pixels / NUM_INPUT
        model.push_var_to_device("inh", "rate")

        input_rate[:] = (digit * (INPUT_STIM - INPUT_UNSTIM)) + INPUT_UNSTIM
        model.push_var_to_device("inp", "rate")

        # one_hot = np.zeros(neurons_count["teacher"])
        one_hot = np.full(neurons_count["teacher"], TEACHER_UNSTIM_V)
        chosen_class = y[example]
        one_hot[chosen_class * TEACHER_NUM:(chosen_class + 1) *
                TEACHER_NUM] = TEACHER_V
        teacher_rate[:] = one_hot
        model.push_var_to_device("teacher", "rate")

        out_voltage[:] = 0.0
        model.push_var_to_device('out', "V")
Пример #4
0
# Simulate
# ----------------------------------------------------------------------------
# Load testing data
testing_images = np.load("testing_images.npy")
testing_labels = np.load("testing_labels.npy")

# Check dimensions match network
assert testing_images.shape[1] == weights[0].shape[0]
assert np.max(testing_labels) == (weights[1].shape[1] - 1)

# Set current input by scaling first image
current_input.vars[
    "magnitude"].view[:] = testing_images[0] * INPUT_CURRENT_SCALE

# Upload
model.push_var_to_device("current_input", "magnitude")

# Simulate
layer_spikes = [(np.empty(0), np.empty(0)) for _ in enumerate(neuron_layers)]
while model.timestep < PRESENT_TIMESTEPS:
    # Advance simulation
    model.step_time()

    # Loop through neuron layers
    for i, l in enumerate(neuron_layers):
        # Download spikes
        model.pull_current_spikes_from_device(l.name)

        # Add to data structure
        spike_times = np.ones_like(l.current_spikes) * model.t
        layer_spikes[i] = (np.hstack((layer_spikes[i][0], l.current_spikes)),
Пример #5
0
current_input_magnitude = current_input.vars["magnitude"].view
output_spike_count = neuron_layers[-1].vars["SpikeCount"].view
layer_voltages = [l.vars["V"].view for l in neuron_layers]

# Simulate
num_correct = 0
while model.timestep < (PRESENT_TIMESTEPS * testing_images.shape[0]):
    # Calculate the timestep within the presentation
    timestep_in_example = model.timestep % PRESENT_TIMESTEPS
    example = int(model.timestep // PRESENT_TIMESTEPS)

    # If this is the first timestep of presenting the example
    if timestep_in_example == 0:
        current_input_magnitude[:] = testing_images[
            example] * INPUT_CURRENT_SCALE
        model.push_var_to_device("current_input", "magnitude")

        # Loop through all layers and their corresponding voltage views
        for l, v in zip(neuron_layers, layer_voltages):
            # Manually 'reset' voltage
            v[:] = 0.0

            # Upload
            model.push_var_to_device(l.name, "V")

        # Zero spike count
        output_spike_count[:] = 0
        model.push_var_to_device(neuron_layers[-1].name, "SpikeCount")

    # Advance simulation
    model.step_time()
Пример #6
0
        # init a data structure for plotting the raster plots for this example
        layer_spikes = [(np.empty(0), np.empty(0))
                        for _ in enumerate(neuron_layers)]
        # synapse_weights = [np.array([]) for _ in enumerate(synapses)]
        # layer_currents = [np.array([]) for _ in enumerate(neuron_layers)]

        if example % 1000 == 0:
            print("Example: " + str(example))

        current_input_magnitude[:] = X[
            example, :].flatten() * INPUT_CURRENT_SCALE
        one_hot = np.zeros((NUM_CLASSES))
        one_hot[y[example]] = 1
        current_output_magnitude[:] = one_hot.flatten() * OUTPUT_CURRENT_SCALE
        model.push_var_to_device("current_input", "magnitude")
        model.push_var_to_device("current_output", "magnitude")

        # Loop through all layers and their corresponding voltage views
        for l, v in zip(neuron_layers, layer_voltages):
            # Manually 'reset' voltage
            v[:] = 0.0

            # Upload
            model.push_var_to_device(l.name, "V")

        # Zero spike count
        # output_spike_count[:] = 0
        # model.push_var_to_device(neuron_layers[-1].name, "SpikeCount")

    # Advance simulation