Neuromorphic and biological learning

Read Chapter 7.4

Python demonstration

STDP demonstration:

import numpy as np
import matplotlib.pyplot as plt

A_W_P = lambda w: 1
tau_p = 0.01
w     = 0
dt_space = np.linspace(-0.05, 0.05, 100)

def dw (dt):
    if dt < 0:
        return A_W_P(w) * np.exp(dt/tau_p)
    if dt == 0:
        return 1
    return -A_W_P(w) * np.exp(-dt/tau_p)

dw_value = [dw(dt) for dt in dt_space]
plt.plot(dt_space, dw_value)

Check the results!

Python / BRIAN demonstration

Imports:

import matplotlib.pyplot as plt
from brian2 import NeuronGroup, Network, SpikeMonitor
from brian2.units import second, ms, Hz
from brian2 import seed

Model creation:

dict_data = {}

# Vary the correlation within the group
plt.figure(figsize=(12, 12))
for i, c in enumerate([0.0, 0.5, 1.0]):

    N = 10            # Number of neuron in the group
    rate = 10 * Hz    # Mean firing rate of each neuron

    G = NeuronGroup(N, 'v : 1 (shared)', threshold='((v < rate*dt) and rand() < sqrt(c)) or rand() < rate*(1 - sqrt(c))*dt')
    G.run_regularly('v = rand()')

Simulating:

    duration = 4 * second
    S = SpikeMonitor(G)
    net = Network(G, S)
    net.run(duration)

Plotting:

    plt.subplot(3, 1, i + 1)
    plt.title('Correlation = %1.1f' % (c), fontsize=15)
    plt.ylabel('Neurons', fontsize=15)
    plt.plot(S.t / ms, S.i, '.')
    print('Mean firing rate (c = %1.1f): ' % (c), len(S.t) / (N * duration))
    
    dict_data[c] = {'i': S.i, 't': S.t/ms}

plt.xlabel('Time [sec]', fontsize=15)
plt.tight_layout()
plt.savefig('STDP1.jpg', dpi=350)
plt.show()

Results:

Visualizing weight change for neurons with different correlations:

plt.figure()

for corr in [0.0, 0.5, 1.0]:
    
    W_0_1 = 0
    W_0_1_t = []

    for i, spike_cell in enumerate(dict_data[corr]['i']):

        weight_update = 0

        if i == len(dict_data[corr]['i'])-2:
            break

        if (dict_data[corr]['i'][i]==1) and (dict_data[corr]['i'][i+1]==0):
            dt = dict_data[corr]['t'][i+1] - dict_data[corr]['t'][i]
            weight_update = dw(dt/1000)
            #print('diminishing weight by: {}, dt: {}'.format(weight_update, dt))

        if (dict_data[corr]['i'][i]==0) and (dict_data[corr]['i'][i+1]==1):
            dt = dict_data[corr]['t'][i] - dict_data[corr]['t'][i+1]
            weight_update = dw(dt/1000)
            #print('augmenting weight by: {}, dt: {}'.format(weight_update, dt/1000))

        W_0_1 = W_0_1 + weight_update
        W_0_1_t.append(W_0_1)
    
    plt.plot(W_0_1_t, label = 'Correlation = {}'.format(corr), linewidth=3)

plt.xlim(0,350)
plt.ylim(-5,35)
plt.legend(loc='best')
plt.ylabel("Synaptic weight")
plt.xlabel("Time (sec)")

Result:

Last updated