-
Notifications
You must be signed in to change notification settings - Fork 0
/
Transformation.py
41 lines (33 loc) · 1.15 KB
/
Transformation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import nengo
import numpy as np
import matplotlib.pyplot as plt
from nengo.utils.matplotlib import rasterplot
from nengo.processes import WhiteNoise
# Transforming sin(x) to 2sin(x) by decoder scaling
T = 1.0
max_freq = 5
model = nengo.Network()
with model:
stim = nengo.Node(lambda t: 0.5 * np.sin(10 * t))
ensA = nengo.Ensemble(100, dimensions=1)
ensB = nengo.Ensemble(100, dimensions=1)
nengo.Connection(stim, ensA)
nengo.Connection(ensA, ensB, transform=2) # function=lambda x: 2*x
stim_p = nengo.Probe(stim)
ensA_p = nengo.Probe(ensA, synapse=.01)
ensB_p = nengo.Probe(ensB, synapse=.01)
# Probeable attributes: ('output', 'voltage', 'refractory_time', 'input')
ensA_spikes_p = nengo.Probe(ensA.neurons, 'output')
ensB_spikes_p = nengo.Probe(ensB.neurons, 'output')
sim = nengo.Simulator(model, seed=4)
sim.run(T)
t = sim.trange()
plt.figure(figsize=(6, 4))
plt.ax = plt.gca()
plt.plot(t, sim.data[stim_p], 'r', linewidth=4, label='x')
plt.plot(t, sim.data[ensA_p], 'g', label='$\hat{x}$')
plt.plot(t, sim.data[ensB_p], 'b', label='$f(\hat{x})=2\hat{x}$')
plt.legend()
plt.ylabel("Output")
plt.xlabel("Time")
plt.show()