#!pip install ANNarchy
Hybrid network
Simple example showing hybrid spike/rate-coded networks.
Reproduces Fig.4 of (Vitay, Dinkelbach and Hamker, 2015)
import numpy as np
import matplotlib.pyplot as plt
import ANNarchy as ann
# Rate-coded output neuron
= ann.Neuron(
simple_neuron = "r = sum(exc)"
equations
)
# Network
= ann.Network(dt=0.1)
net
# Rate-coded population for input
= net.create(ann.InputArray(geometry=1))
pop1
# Poisson Population to encode
= net.create(ann.PoissonPopulation(geometry=1000, target="exc"))
pop2 = net.connect(pop1, pop2, 'exc')
proj =1.)
proj.all_to_all(weights
# Rate-coded population to decode
= net.create(geometry=1000, neuron=simple_neuron)
pop3 = net.connect(ann.DecodingProjection(pop2, pop3, 'exc', window=10.0))
proj
def diagonal(pre, post, weights):
"""
Simple connector pattern to progressively connect each post-synaptic neuron to a growing number of pre-synaptic neurons.
"""
= ann.LILConnectivity()
lil for rk_post in range(post.size):
range((rk_post+1)), [weights], [0] )
lil.add(rk_post, return lil
=diagonal, weights=1.)
proj.from_function(method
compile()
net.
# Monitors
= net.monitor(pop1, 'r')
m1 = net.monitor(pop2, 'spike')
m2 = net.monitor(pop3, 'r')
m3
# Simulate
= 250.
duration # 0 Hz
= 0.0
pop1.r
net.simulate(duration)# 10 Hz
= 10.0
pop1.r
net.simulate(duration)# 50 Hz
= 50.0
pop1.r
net.simulate(duration)# 100 Hz
= 100.0
pop1.r
net.simulate(duration)
# Get recordings
= m1.get()
data1 = m2.get()
data2 = m3.get()
data3
# Raster plot of the spiking population
= m2.raster_plot(data2['spike'])
t, n
# Variance of the the decoded firing rate
= data3['r'][int(1.0*duration/net.dt):int(2*duration/net.dt), :]
data_10 = data3['r'][int(2.0*duration/net.dt):int(3*duration/net.dt), :]
data_50 = data3['r'][int(3.0*duration/net.dt):int(4*duration/net.dt), :]
data_100 = np.mean(np.abs((data_10 - 10.)/10.), axis=0)
var_10 = np.mean(np.abs((data_50 - 50.)/50.), axis=0)
var_50 = np.mean(np.abs((data_100 - 100.)/100.), axis=0) var_100
ANNarchy 5.0 (5.0.0) on darwin (posix).
Compiling network 1... OK
=(12, 15))
plt.figure(figsize3,1,1)
plt.subplot('.', markersize=0.5)
plt.plot(t, n, 'a) Raster plot')
plt.title('Time (ms)')
plt.xlabel('# neurons')
plt.ylabel(0, 4*duration))
plt.xlim((
3,1,2)
plt.subplot(0, 4*duration, 0.1), data1['r'][:, 0], label='Original firing rate')
plt.plot(np.arange(0, 4*duration, 0.1), data3['r'][:, 999], label='Decoded firing rate')
plt.plot(np.arange(=False, loc=2)
plt.legend(frameon'b) Decoded firing rate')
plt.title('Time (ms)')
plt.xlabel('Activity (Hz)')
plt.ylabel(
3,1,3)
plt.subplot(='10 Hz')
plt.plot(var_10, label='50 Hz')
plt.plot(var_50, label='100 Hz')
plt.plot(var_100, label=False)
plt.legend(frameon'c) Precision')
plt.title('# neurons used for decoding')
plt.xlabel('Normalized error')
plt.ylabel(0,1))
plt.ylim((
plt.show()