#!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 ANNarchy as ann
ann.clear()=0.1)
ann.setup(dt
# Rate-coded input neuron
= ann.Neuron(
input_neuron = "baseline = 0.0",
parameters = "r = baseline"
equations
)# Rate-coded output neuron
= ann.Neuron(
simple_neuron = "r = sum(exc)"
equations
)
# Rate-coded population for input
= ann.Population(geometry=1, neuron=input_neuron)
pop1
# Poisson Population to encode
= ann.PoissonPopulation(geometry=1000, target="exc")
pop2 = ann.Projection(pop1, pop2, 'exc').connect_all_to_all(weights=1.)
proj
# Rate-coded population to decode
= ann.Population(geometry=1000, neuron =simple_neuron)
pop3 = 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.connect_with_func(method
compile()
ann.
# Monitors
= ann.Monitor(pop1, 'r')
m1 = ann.Monitor(pop2, 'spike')
m2 = ann.Monitor(pop3, 'r')
m3
# Simulate
= 250.
duration # 0 Hz
= 0.0
pop1.baseline
ann.simulate(duration)# 10 Hz
= 10.0
pop1.baseline
ann.simulate(duration)# 50 Hz
= 50.0
pop1.baseline
ann.simulate(duration)# 100 Hz
= 100.0
pop1.baseline
ann.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/ann.dt()):int(2*duration/ann.dt()), :]
data_10 = data3['r'][int(2.0*duration/ann.dt()):int(3*duration/ann.dt()), :]
data_50 = data3['r'][int(3.0*duration/ann.dt()):int(4*duration/ann.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 4.8 (4.8.2) on darwin (posix).
Compiling ... OK
import matplotlib.pyplot as plt
=(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()