Example #1
0
def test_modell():
    timesteps = 12000

    neurons_input = 180
    neurons_output = 180
    neurons = neurons_input + neurons_output

    spiking_model = spiking.SRM(neurons=neurons, threshold=1.0, t_current=0.3,
                                t_membrane=20, eta_reset=5, verbose=False)

    learning_model = learning.STDP(eta=0.05, w_in=0.0, w_out=-0.05, tau=10.0, window_size=5, verbose=False)

    weights = np.zeros((neurons, neurons))

    # Input Neurons are fully connected to the output neurons
    mu, sigma = 0.5, 0.05
    weights[:neurons_input, neurons_input:] = sigma * np.random.randn(neurons_input, neurons_output) + mu

    # Output Neurons are fully connected to each other with inhibitory weights
    mu, sigma = -0.5, 0.05
    weights_output = sigma * np.random.randn(neurons_output, neurons_output) + mu
    weights[neurons_input:, neurons_input:] = weights_output

    # Output neurons have exhibitory weights for their neighboring neurons
    mu, sigma = 0.5, 0.05
    b = np.eye(neurons_output) * (sigma * np.random.randn(neurons_output, 1) + mu)
    weights[neurons_input:, neurons_input:] += np.roll(b, 1, 1)
    weights_output = weights[neurons_input:, neurons_input:].copy()

    spikes = np.zeros((neurons, timesteps), dtype=bool)

    # Generate some spikes in the input layer
    for i in range(neurons_input):
        spikes[i] = tools.sound(timesteps, 20 * i, 0.4, 50)
        spikes[i + neurons_input, 20 * i - 5:20 * i + 5] = True

    for i in range(neurons_input - 1, -1, -1):
        spikes[i] = spikes[i] + tools.sound(timesteps, neurons_input * 20 + 20 * i, 0.4, 50)
        spikes[i + neurons_input, neurons_input * 20 + 20 * i - 5: neurons_input * 20 + 20 * i + 5] = True

    # Weight plot
    weightplotter = plotting.WeightHeatmapAnimation()
    weightplotter.add(weights)

    save_interval = 10

    for t in range(timesteps):

        print("Timestep: ", t)

        if weightplotter and t % save_interval == 0:
            weightplotter.add(weights)

        spiking_model.simulate(spikes, weights, t)

        learning_model.weight_change(spikes, weights, t)
        # Reset output layer weights
        weights[neurons_input:, neurons_input:] = weights_output

    weightplotter.show_animation()
Example #2
0
def test_jeffress():
    neurons = 11
    timesteps = 100

    ax_delays = np.array([0, 5, 15, 25, 0, 25, 15, 5, 0, 0, 0])
    model = spiking.SRM_X(neurons=neurons, threshold=np.array([1]*neurons), t_current=np.array([5]*neurons),
                          t_membrane=np.array([10]*neurons), eta_reset=np.array([2.0]*neurons), ax_delay=ax_delays)

    weights = np.zeros((neurons, neurons))

    # Connect input layer
    weights[0, (1, 2, 3)] = 1
    weights[4, (5, 6, 7)] = 1

    # Connect to output layer
    weights[(1, 5), 8] = 1.05
    weights[(2, 6), 9] = 1.05
    weights[(3, 7), 10] = 1.05

    print(weights)

    spiketrain = np.zeros((neurons, timesteps), dtype=bool)

    manual_spiketrain = True

    if manual_spiketrain:
        spiketrain[0, (20, 25, 30)] = 1
        spiketrain[4, (0, 5, 10)] = 1
    else:
        spiketrain[0,:] = tools.sound(timesteps, 85, 0.6, 4)
        spiketrain[4,:] = tools.sound(timesteps, 60, 0.6, 4)

    psth = plotting.PSTH(spiketrain, binsize=5)
    curr = plotting.CurrentPlot(4)

    for t in range(timesteps):
        current = model.check_spikes(spiketrain, weights, t)
        curr.add(current[[0, 3, 7, 10]])

    psth.show_plot()
    curr.show_plot()
Example #3
0
def test_modell():
    timesteps = 12000

    neurons_input = 180
    neurons_output = 180
    neurons = neurons_input + neurons_output

    spiking_model = spiking.SRM(neurons=neurons,
                                threshold=1.0,
                                t_current=0.3,
                                t_membrane=20,
                                eta_reset=5,
                                verbose=False)

    learning_model = learning.STDP(eta=0.05,
                                   w_in=0.0,
                                   w_out=-0.05,
                                   tau=10.0,
                                   window_size=5,
                                   verbose=False)

    weights = np.zeros((neurons, neurons))

    # Input Neurons are fully connected to the output neurons
    mu, sigma = 0.5, 0.05
    weights[:neurons_input, neurons_input:] = sigma * np.random.randn(
        neurons_input, neurons_output) + mu

    # Output Neurons are fully connected to each other with inhibitory weights
    mu, sigma = -0.5, 0.05
    weights_output = sigma * np.random.randn(neurons_output,
                                             neurons_output) + mu
    weights[neurons_input:, neurons_input:] = weights_output

    # Output neurons have exhibitory weights for their neighboring neurons
    mu, sigma = 0.5, 0.05
    b = np.eye(neurons_output) * (sigma * np.random.randn(neurons_output, 1) +
                                  mu)
    weights[neurons_input:, neurons_input:] += np.roll(b, 1, 1)
    weights_output = weights[neurons_input:, neurons_input:].copy()

    spikes = np.zeros((neurons, timesteps), dtype=bool)

    # Generate some spikes in the input layer
    for i in range(neurons_input):
        spikes[i] = tools.sound(timesteps, 20 * i, 0.4, 50)
        spikes[i + neurons_input, 20 * i - 5:20 * i + 5] = True

    for i in range(neurons_input - 1, -1, -1):
        spikes[i] = spikes[i] + tools.sound(
            timesteps, neurons_input * 20 + 20 * i, 0.4, 50)
        spikes[i + neurons_input, neurons_input * 20 + 20 * i -
               5:neurons_input * 20 + 20 * i + 5] = True

    # Weight plot
    weightplotter = plotting.WeightHeatmapAnimation()
    weightplotter.add(weights)

    save_interval = 10

    for t in range(timesteps):

        print("Timestep: ", t)

        if weightplotter and t % save_interval == 0:
            weightplotter.add(weights)

        spiking_model.simulate(spikes, weights, t)

        learning_model.weight_change(spikes, weights, t)
        # Reset output layer weights
        weights[neurons_input:, neurons_input:] = weights_output

    weightplotter.show_animation()