In [6]:
%pylab inline


Populating the interactive namespace from numpy and matplotlib
WARNING: pylab import has clobbered these variables: ['pylab', 'inf', 'dot', 'save']
`%matplotlib` prevents importing * from pylab and numpy

In [7]:
from plasticnet import *

1D BCM


In [8]:
from plasticnet import *
pre=neurons.pattern_neuron([10])
post=neurons.linear_neuron(1)

c=connections.BCM(pre,post,[0,.05])
c.eta=5e-7
c.tau=1000

sim=simulation(1000*1000)
sim.monitor(c,['weights','theta'],1000)

run_sim(sim,[pre,post],[c],display_hash=False)


('Time Elapsed...', '0.57 s')

In [9]:
w=sim.monitors['weights'].array().squeeze()
plot(w)
xlabel('Weights')
ylabel('Time')


Out[9]:
<matplotlib.text.Text at 0x110d39668>

2D BCM


In [10]:
pre=neurons.pattern_neuron([[2,3],[3,1]])
post=neurons.linear_neuron(1)

c=connections.BCM(pre,post,[0,.05])
c.eta=5e-5
c.tau=1000

sim=simulation(1000*1000)
sim.monitor(c,['weights','theta'],1000)

run_sim(sim,[pre,post],[c],display_hash=False)


('Time Elapsed...', '0.57 s')

In [11]:
weights=sim.monitors['weights'].array().squeeze()
plot(weights)
legend(['Weight 0','Weight 1'])
ylabel('Weights')
xlabel('Time')

figure()
theta=sim.monitors['theta'].array().squeeze()
plot(theta)
ylabel(r'$\theta_M$')
xlabel('Time')


Out[11]:
<matplotlib.text.Text at 0x1112026a0>

In [12]:
outputs=[]
for w in weights:
    output=[sum(x*w) for x in pre.patterns]
    outputs.append(output)
outputs=array(outputs)

plot(outputs)
xlabel('Time')
ylabel('Response')
legend(['Pattern 0','Pattern 1'])


Out[12]:
<matplotlib.legend.Legend at 0x110629d68>

2D Hebb


In [13]:
pre=neurons.pattern_neuron([[2,3],[3,1]])
post=neurons.linear_neuron(1)

c=connections.Hebb(pre,post,[0,.05])
c+=connections.process.normalization()

c.eta=5e-5
c.tau=1000

sim=simulation(1000*1000)
sim.monitor(c,['weights','theta'],1000)

run_sim(sim,[pre,post],[c],display_hash=False)


('Time Elapsed...', '0.66 s')

In [14]:
weights=sim.monitors['weights'].array().squeeze()
plot(weights)
legend(['Weight 0','Weight 1'])
ylabel('Weights')
xlabel('Time')

figure()
theta=sim.monitors['theta'].array().squeeze()
plot(theta)
ylabel(r'$\theta_M$')
xlabel('Time')


Out[14]:
<matplotlib.text.Text at 0x111584710>

In [15]:
outputs=[]
for w in weights:
    output=[sum(x*w) for x in pre.patterns]
    outputs.append(output)
outputs=array(outputs)

plot(outputs)
xlabel('Time')
ylabel('Response')
legend(['Pattern 0','Pattern 1'])


Out[15]:
<matplotlib.legend.Legend at 0x110ee4240>

In [ ]: