Debian Codegraph @

examples/frompapers/Sturzl_et_al_2000.py

raw
1 #!/usr/bin/env python
2 """
3 Adapted from
4 Theory of Arachnid Prey Localization
5 W. Sturzl, R. Kempter, and J. L. van Hemmen
6 PRL 2000
7
8 Poisson inputs are replaced by integrate-and-fire neurons
9
10 Romain Brette
11 """
12 from brian2 import *
13
14 # Parameters
15 degree = 2 * pi / 360.
16 duration = 500*ms
17 R = 2.5*cm # radius of scorpion
18 vr = 50*meter/second # Rayleigh wave speed
19 phi = 144*degree # angle of prey
20 A = 250*Hz
21 deltaI = .7*ms # inhibitory delay
22 gamma = (22.5 + 45 * arange(8)) * degree # leg angle
23 delay = R / vr * (1 - cos(phi - gamma)) # wave delay
24
25 # Wave (vector w)
26 time = arange(int(duration / defaultclock.dt) + 1) * defaultclock.dt
27 Dtot = 0.
28 w = 0.
29 for f in arange(150, 451)*Hz:
30 D = exp(-(f/Hz - 300) ** 2 / (2 * (50 ** 2)))
31 rand_angle = 2 * pi * rand()
32 w += 100 * D * cos(2 * pi * f * time + rand_angle)
33 Dtot += D
34 w = .01 * w / Dtot
35
36 # Rates from the wave
37 rates = TimedArray(w, dt=defaultclock.dt)
38
39 # Leg mechanical receptors
40 tau_legs = 1 * ms
41 sigma = .01
42 eqs_legs = """
43 dv/dt = (1 + rates(t - d) - v)/tau_legs + sigma*(2./tau_legs)**.5*xi:1
44 d : second
45 """
46 legs = NeuronGroup(8, model=eqs_legs, threshold='v > 1', reset='v = 0',
47 refractory=1*ms, method='euler')
48 legs.d = delay
49 spikes_legs = SpikeMonitor(legs)
50
51 # Command neurons
52 tau = 1 * ms
53 taus = 1.001 * ms
54 wex = 7
55 winh = -2
56 eqs_neuron = '''
57 dv/dt = (x - v)/tau : 1
58 dx/dt = (y - x)/taus : 1 # alpha currents
59 dy/dt = -y/taus : 1
60 '''
61 neurons = NeuronGroup(8, model=eqs_neuron, threshold='v>1', reset='v=0',
62 method='exact')
63 synapses_ex = Synapses(legs, neurons, on_pre='y+=wex')
64 synapses_ex.connect(j='i')
65 synapses_inh = Synapses(legs, neurons, on_pre='y+=winh', delay=deltaI)
66 synapses_inh.connect('abs(((j - i) % N_post) - N_post/2) <= 1')
67 spikes = SpikeMonitor(neurons)
68
69 run(duration, report='text')
70
71 nspikes = spikes.count
72 phi_est = imag(log(sum(nspikes * exp(gamma * 1j))))
73 print("True angle (deg): %.2f" % (phi/degree))
74 print("Estimated angle (deg): %.2f" % (phi_est/degree))
75 rmax = amax(nspikes)/duration/Hz
76 polar(concatenate((gamma, [gamma[0] + 2 * pi])),
77 concatenate((nspikes, [nspikes[0]])) / duration / Hz,
78 c='k')
79 axvline(phi, ls='-', c='g')
80 axvline(phi_est, ls='-', c='b')
81 show()