Skip to content

Commit

Permalink
use ComponentArrays
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrea committed Mar 6, 2024
1 parent 1d5511b commit 855db8c
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions docs/src/examples/spiking_neural_systems.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ The LIF model has five parameters, `gL, EL, C, Vth, I` and we define it in the `

```@example spikingneural
using DifferentialEquations
using ComponentArrays
using Plots
gr()
Expand Down Expand Up @@ -56,30 +57,29 @@ They can make discontinuous changes to the model when certain conditions are met

```@example spikingneural
function thr(u, t, integrator)
u - integrator.p[4]
u - integrator.p.Vth
end
function reset!(integrator)
integrator.u = integrator.p[2]
integrator.u = integrator.p.EL
end
threshold = ContinuousCallback(thr, reset!, nothing)
current_step = PresetTimeCallback([2, 15], integrator -> integrator.p[5] += 150.0)
current_step = PresetTimeCallback([2, 15], integrator -> integrator.p.I += 150.0)
cb = CallbackSet(current_step, threshold)
```

Our condition is `thr(u,t,integrator)` and the condition kicks in when `integrator.u > integrator.p[4]` where `p[4]` is our threshold parameter `Vth`. Our effect of the condition is `reset!(integrator)`. It sets `u` back to the equilibrium potential `p[2]`. We then wrap both the condition and the effect into a `DiscreteCallback` called threshold. There is one more callback called `PresetTimeCallback` that is particularly useful. This one increases the input `p[5]` at `t=2` and `t=15` by `150.0`. Both callbacks are then combined into a `CallbackSet`. We are almost done to simulate our system, we just need to put numbers on our initial voltage and parameters.
Our condition is `thr(u,t,integrator)` and the condition kicks in when `u > integrator.p.Vth`. Our effect of the condition is `reset!(integrator)`. It sets `u` back to the equilibrium potential `p.EL`. We then wrap both the condition and the effect into a `ContinuousCallback` called threshold. There is one more callback called `PresetTimeCallback` that is particularly useful. This one increases the input `p.I` at `t=2` and `t=15` by `150.0`. Both callbacks are then combined into a `CallbackSet`. We are almost done to simulate our system, we just need to put numbers on our initial voltage and parameters.

```@example spikingneural
u0 = -75
tspan = (0.0, 40.0)
# p = (gL, EL, C, Vth, I)
p = [5.0, -75.0, 50.0, -55.0, 0]
p = ComponentArray(gL = 5.0, EL = -75.0, C = 50.0, Vth = -55.0, I = 0)
prob = ODEProblem(lif, u0, tspan, p, callback = cb)
```

Our initial voltage is `u0 = - 75`, which will be the same as our equilibrium potential, so we start at a stable point. Then we define the timespan we want to simulate. The timescale of the LIF as it is defined conforms roughly to milliseconds. Then we define our parameters as `p = [5.0, -75.0, 50.0, -55.0, 0]`. Remember that `gL, EL, C, Vth, I = p`. Finally, we wrap everything into a call to `ODEProblem`. Can't forget the `CallbackSet`. With that, our model is defined. Now we just need to solve it with a quick call to `solve`.
Our initial voltage is `u0 = - 75`, which will be the same as our equilibrium potential, so we start at a stable point. Then we define the timespan we want to simulate. The timescale of the LIF as it is defined conforms roughly to milliseconds. Then we define our parameters as `p = ComponentArray(gL = 5.0, EL = -75.0, C = 50.0, Vth = -55.0, I = 0)`. Finally, we wrap everything into a call to `ODEProblem`. Can't forget the `CallbackSet`. With that, our model is defined. Now we just need to solve it with a quick call to `solve`.

```@example spikingneural
sol = solve(prob)
Expand Down

0 comments on commit 855db8c

Please sign in to comment.