Skip to content

Commit

Permalink
Swap JansenRit implementation to flag
Browse files Browse the repository at this point in the history
Instead of separate `JansenRit()` and `JansenRitDelayed` constructors, create a single constructor with flag `delayed=false` default.
  • Loading branch information
agchesebro committed Mar 6, 2024
1 parent 9391f3e commit cbd145b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 48 deletions.
16 changes: 8 additions & 8 deletions examples/jansen_rit_liu_et_al.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ sol_dde_no_delays = solve(prob, alg, saveat=1)
# Example of delayed connections

# First, recreate the graph to remove previous connections
@named Str = JansenRitDelayed=0.0022*τ_factor, H=20, λ=300, r=0.3)
@named GPE = JansenRitDelayed=0.04*τ_factor, cortical=false) # all default subcortical except τ
@named STN = JansenRitDelayed=0.01*τ_factor, H=20, λ=500, r=0.1)
@named GPI = JansenRitDelayed(cortical=false) # default parameters subcortical Jansen Rit blox
@named Th = JansenRitDelayed=0.002*τ_factor, H=10, λ=20, r=5)
@named EI = JansenRitDelayed=0.01*τ_factor, H=20, λ=5, r=5)
@named PY = JansenRitDelayed(cortical=true) # default parameters cortical Jansen Rit blox
@named II = JansenRitDelayed=2.0*τ_factor, H=60, λ=5, r=5)
@named Str = JansenRit=0.0022*τ_factor, H=20, λ=300, r=0.3, delayed=true)
@named GPE = JansenRit=0.04*τ_factor, cortical=false, delayed=true) # all default subcortical except τ
@named STN = JansenRit=0.01*τ_factor, H=20, λ=500, r=0.1, delayed=true)
@named GPI = JansenRit(cortical=false, delayed=true) # default parameters subcortical Jansen Rit blox
@named Th = JansenRit=0.002*τ_factor, H=10, λ=20, r=5, delayed=true)
@named EI = JansenRit=0.01*τ_factor, H=20, λ=5, r=5, delayed=true)
@named PY = JansenRit(cortical=true, delayed=true) # default parameters cortical Jansen Rit blox
@named II = JansenRit=2.0*τ_factor, H=60, λ=5, r=5, delayed=true)
blox = [Str, GPE, STN, GPI, Th, EI, PY, II]
g = MetaDiGraph()
add_blox!.(Ref(g), blox)
Expand Down
2 changes: 1 addition & 1 deletion src/Neuroblox.jl
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export JansenRitSPM12, next_generation, qif_neuron, if_neuron, hh_neuron_excitat
hh_neuron_inhibitory, synaptic_network, van_der_pol
export IFNeuronBlox, LIFNeuronBlox, QIFNeuronBlox, HHNeuronExciBlox, HHNeuronInhibBlox,
CanonicalMicroCircuitBlox, WinnerTakeAllBlox, CorticalBlox, SuperCortical
export LinearNeuralMass, HarmonicOscillator, JansenRit, JansenRitDelayed, WilsonCowan, LarterBreakspear, NextGenerationBlox, NextGenerationResolvedBlox, NextGenerationEIBlox
export LinearNeuralMass, HarmonicOscillator, JansenRit, WilsonCowan, LarterBreakspear, NextGenerationBlox, NextGenerationResolvedBlox, NextGenerationEIBlox
export Matrisome, Striosome, Striatum, GPi, GPe, Thalamus, STN, TAN, SNc
export HebbianPlasticity, HebbianModulationPlasticity
export Agent, ClassificationEnvironment, GreedyPolicy, reset!
Expand Down
58 changes: 19 additions & 39 deletions src/blox/neural_mass.jl
Original file line number Diff line number Diff line change
Expand Up @@ -179,37 +179,6 @@ Citations:
1. Liu C, Zhou C, Wang J, Fietkiewicz C, Loparo KA. The role of coupling connections in a model of the cortico-basal ganglia-thalamocortical neural loop for the generation of beta oscillations. Neural Netw. 2020 Mar;123:381-392. doi: 10.1016/j.neunet.2019.12.021.
"""
struct JansenRitDelayed <: NeuralMassBlox
params
output
jcn
odesystem
namespace
function JansenRitDelayed(;name,
namespace=nothing,
τ=nothing,
H=nothing,
λ=nothing,
r=nothing,
cortical=true)

τ = isnothing(τ) ? (cortical ? 1 : 14) : τ
H = isnothing(H) ? 20.0 : H # H doesn't have different parameters for cortical and subcortical
λ = isnothing(λ) ? (cortical ? 5.0 : 400.0) : λ
r = isnothing(r) ? (cortical ? 0.15 : 0.1) : r

# p = progress_scope(τ, H, λ, r)
p = paramscoping=τ, H=H, λ=λ, r=r)
τ, H, λ, r = p
sts = @variables x(..)=1.0 [output=true] y(t)=1.0 jcn(t)=0.0 [input=true]
eqs = [D(x(t)) ~ y - ((2/τ)*x(t)),
D(y) ~ -x(t)/*τ) + (H/τ)*((2*λ)/(1 + exp(-r*(jcn))) - λ)]
sys = System(eqs, name=name)
#can't use outputs because x(t) is Num by then
#wrote inputs similarly to keep consistent
new(p, sts[1], sts[3], sys, namespace)
end
end

"""
JansenRit(name, namespace, τ, H, λ, r, cortical)
Expand Down Expand Up @@ -249,7 +218,8 @@ struct JansenRit <: NeuralMassBlox
H=nothing,
λ=nothing,
r=nothing,
cortical=true)
cortical=true,
delayed=false)

τ = isnothing(τ) ? (cortical ? 1 : 14) : τ
H = isnothing(H) ? 20.0 : H # H doesn't have different parameters for cortical and subcortical
Expand All @@ -259,13 +229,23 @@ struct JansenRit <: NeuralMassBlox
# p = progress_scope(τ, H, λ, r)
p = paramscoping=τ, H=H, λ=λ, r=r)
τ, H, λ, r = p
sts = @variables x(t)=1.0 [output=true] y(t)=1.0 jcn(t)=0.0 [input=true]
eqs = [D(x) ~ y - ((2/τ)*x),
D(y) ~ -x/*τ) + (H/τ)*((2*λ)/(1 + exp(-r*(jcn))) - λ)]
sys = System(eqs, name=name)
#can't use outputs because x(t) is Num by then
#wrote inputs similarly to keep consistent
new(p, sts[1], sts[3], sys, namespace)
if !delayed
sts = @variables x(t)=1.0 [output=true] y(t)=1.0 jcn(t)=0.0 [input=true]
eqs = [D(x) ~ y - ((2/τ)*x),
D(y) ~ -x/*τ) + (H/τ)*((2*λ)/(1 + exp(-r*(jcn))) - λ)]
sys = System(eqs, name=name)
#can't use outputs because x(t) is Num by then
#wrote inputs similarly to keep consistent
return new(p, sts[1], sts[3], sys, namespace)
else
sts = @variables x(..)=1.0 [output=true] y(t)=1.0 jcn(t)=0.0 [input=true]
eqs = [D(x(t)) ~ y - ((2/τ)*x(t)),
D(y) ~ -x(t)/*τ) + (H/τ)*((2*λ)/(1 + exp(-r*(jcn))) - λ)]
sys = System(eqs, name=name)
#can't use outputs because x(t) is Num by then
#wrote inputs similarly to keep consistent
return new(p, sts[1], sts[3], sys, namespace)
end
end
end

Expand Down

0 comments on commit cbd145b

Please sign in to comment.