Learning with SNN
Chapter 13
Python / Nengo demonstration
Imports:
import nengo
import numpy as np
import matplotlib.pyplot as plt
from nengo.processes import WhiteSignal
from urllib.request import urlretrieve
import tensorflow as tf
import nengo_dlPES learning: communication channel
model = nengo.Network('Learn a Communication Channel')
with model:
stim = nengo.Node(output=WhiteSignal(10, high=5, rms=0.5))
pre = nengo.Ensemble(60, dimensions=1)
post = nengo.Ensemble(60, dimensions=1)
nengo.Connection(stim, pre)
conn = nengo.Connection(pre, post, function=lambda x: np.random.random())
inp_p = nengo.Probe(stim)
pre_p = nengo.Probe(pre, synapse=0.01)
post_p = nengo.Probe(post, synapse=0.01)
error = nengo.Ensemble(60, dimensions=1)
error_p = nengo.Probe(error, synapse=0.03)
nengo.Connection(post, error)
nengo.Connection(pre, error, transform=-1) # Learn simple communication line
conn.learning_rule_type = nengo.PES()
learn_conn = nengo.Connection(error, conn.learning_rule)
sim = nengo.Simulator(model)
sim.run(10.0)
t=sim.trange()
import matplotlib.pyplot as plt
plt.figure(figsize=(12, 4))
plt.plot(t, sim.data[inp_p].T[0], c='k', label='Input')
plt.plot(t, sim.data[pre_p].T[0], c='b', label='Pre')
plt.plot(t, sim.data[post_p].T[0], c='r', label='Post')
plt.ylabel("Value")
plt.legend(loc=1)
plt.figure(figsize=(12, 4))
plt.plot(t, sim.data[error_p].T[0], c='k', label='Error')
plt.ylabel("Value")
plt.xlabel("Time (sec)")
plt.legend(loc='best')Result:

Pavlovian conditioning
Results:




Diffrentiable LIF tuning curve
Result:

MNIST classification
This demonstration was adopted from:
Data loading:
Model definition:
Network building:
Preprocessing:
SNN compilation before training:
Training:
Evaluating after training:
Plotting:
Results:

Last updated
Was this helpful?