Last active
January 14, 2021 21:36
-
-
Save cormullion/4388947effe95f70625fd6c890237fa5 to your computer and use it in GitHub Desktop.
poincare section of chaotic network of three neurons
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# most of the code is by Rainer Engelken | |
# updated to Julia 1.0 syntax, tested on 1.4 | |
using Luxor, StaticArrays | |
# poincare section of chaotic network of three neurons | |
function spikingnet(n, couplingstrength=1.0) | |
# number of spikes in calculation | |
nspikes = n | |
# define adjacency matrix | |
topo = SMatrix{3,3}(0.0 .< [0 0 0; | |
1 0 1; | |
0 1 0]) | |
# define effective coupling strength | |
c = couplingstrength | |
#initial network state | |
ϕ = rand(3) | |
# initialize phase history | |
𝚽 = Point[] | |
for s = 1:nspikes | |
# find next spiking neuron j | |
ϕmax, j = findmax(ϕ) | |
# calculate next spike time | |
dt = π/2 - ϕmax | |
# evolve phases till next spike time | |
ϕ .+= dt | |
# get postsynaptic neurons | |
post = topo[:, j] | |
# update postsynaptic neurons (quadratic integrate and fire neuron) | |
ϕ[post] = @. atan(tan(ϕ[post]) - c) | |
# reset spiking neuron | |
ϕ[j] = -π/2 | |
# save neuron 2 & 3 whenever neuron 1 spikes | |
j==1 && push!(𝚽, Point(ϕ[2], ϕ[3])) | |
end | |
return 𝚽 | |
end | |
# animation code: | |
poinchaos = Movie(1000, 1000, "poincare chaos") | |
backdrop(scene, framenumber) = background("black") | |
function frame(scene, framenumber) | |
background("white") | |
sethue("black") | |
r = 0.5 | |
# move coupling strength from 0.5 to 2 | |
cstrength = rescale(framenumber/scene.framerange.stop, 0, 1, 0.5, 2) | |
sn = spikingnet(10^6, cstrength) | |
circle.(sn .* 400, r, :fill) | |
end | |
animate(poinchaos, [ | |
Scene(poinchaos, backdrop, 0:100), | |
Scene(poinchaos, frame, 0:100)], | |
creategif=true, | |
pathname="/tmp/poincare.gif") |
Author
cormullion
commented
Jul 6, 2017
how can it be ported to current julia?
Hi Alex, it just needed a few changes for broadcasting, which I've made. (And I don't know why I left tic()
and toc()
in...:)
Thanks I'm new to Julia and wanted to see how something like this fares vs. similar python code. Pretty impressed.
Absolutely stunning, stumbled upon this while looking into poincare maps of other chaotic systems. Hoping to code up something similar in Python, and perhaps penplot some of the results
Cool! - It was mostly Rainer's work. 😂 I made a video https://youtu.be/ECt6esNtfHE :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment