Skip to content

Commit 3320428

Browse files
author
xiaoming
committed
format the doc
1 parent 9e87a1d commit 3320428

File tree

5 files changed

+34
-25
lines changed

5 files changed

+34
-25
lines changed

src/DelaySSAToolkit.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import JumpProcesses: AbstractJumpAggregator, AbstractJump, JumpProblem, Constan
1414
# Dependency graph functions
1515
import JumpProcesses: make_dependency_graph, add_self_dependencies!, var_to_jumps_map
1616
# other functions
17-
import JumpProcesses: using_params, get_jump_info_fwrappers, isinplace_jump, extend_problem, build_variable_callback, get_num_majumps, num_crjs
17+
import JumpProcesses: using_params, get_jump_info_fwrappers, isinplace_jump, extend_problem,
18+
build_variable_callback, get_num_majumps, num_crjs
1819

1920
# VariableRateJump
2021
import JumpProcesses: isbounded, num_bndvrjs, supports_variablerates, haslrate, nullrate

src/delayaggregator/aggregators.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ An abstract type that contains delay stochastic simulation algorithms:
55
- DelayRejection
66
- DelayMNRM
77
- DelayDirectCR
8+
- DelayCoevolve
89
"""
910
abstract type AbstractDelayAggregatorAlgorithm end
1011
"""
@@ -57,4 +58,4 @@ needs_vartojumps_map(aggregator::DelayDirectCR) = true
5758
needs_depgraph(aggregator::DelayCoevolve) = true
5859
needs_vartojumps_map(aggregator::DelayCoevolve) = true
5960
supports_variablerates(aggregator::AbstractDelayAggregatorAlgorithm) = false
60-
supports_variablerates(aggregator::DelayCoevolve) = true
61+
supports_variablerates(aggregator::DelayCoevolve) = true

src/delayaggregator/delayssajump.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,8 @@ input::Vector{Int} species indices
352352
output::Vector{Int} reactions need to be updated
353353
"""
354354

355-
function vars_to_jumps_delay(vartojumps_map::Vector{Vector{Int}}, vars::Vector{Int})::Vector{Int}
355+
function vars_to_jumps_delay(vartojumps_map::Vector{Vector{Int}},
356+
vars::Vector{Int})::Vector{Int}
356357
jumps = Vector{Int}[]
357358
for var in vars
358359
push!(jumps, vartojumps_map[var])
@@ -398,7 +399,7 @@ julia> find_next_delay_vec(A, x)
398399
([1, 2, 3], [2, 1, 1])
399400
```
400401
"""
401-
function find_next_delay_vec(de_chan::Vector{Vector{T}}, ttnj::T) where {T<:Real}
402+
function find_next_delay_vec(de_chan::Vector{Vector{T}}, ttnj::T) where {T <: Real}
402403
position_indices = Vector{Int64}()
403404
num_in_vec = Vector{Int64}()
404405
for idx in eachindex(de_chan)

src/delayproblem.jl

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,11 @@ function DelayJumpProblem(p::P, a::A, dj::J, jc::C, vj::J2, rj::J3, mj::J4, djs:
122122
error("To solve DelayJumpProblem, one has to use one of the delay aggregators.")
123123
end
124124
iip = isinplace_jump(p, rj)
125-
DelayJumpProblem{iip, P, A, C, J, J2, J3, J4, J5, deType, R, K}(p, a, dj, jc, vj, rj, mj,
126-
djs, de_chan0,
127-
save_delay_channel, rng, kwargs)
125+
DelayJumpProblem{iip, P, A, C, J, J2, J3, J4, J5, deType, R, K}(p, a, dj, jc, vj, rj,
126+
mj,
127+
djs, de_chan0,
128+
save_delay_channel, rng,
129+
kwargs)
128130
end
129131

130132
"""
@@ -182,7 +184,6 @@ function DelayJumpProblem(prob, aggregator::AbstractDelayAggregatorAlgorithm,
182184
bvrjs = nothing
183185
cvrjs = jumps.variable_jumps
184186
end
185-
186187

187188
## Constant Rate Handling
188189
t, end_time, u = prob.tspan[1], prob.tspan[2], prob.u0
@@ -219,12 +220,16 @@ function DelayJumpProblem(prob, aggregator::AbstractDelayAggregatorAlgorithm,
219220
DelayJumpProblem{iip, typeof(new_prob), typeof(aggregator), typeof(callbacks),
220221
typeof(disc_agg), typeof(cont_agg),
221222
typeof(jumps.regular_jump), typeof(maj), typeof(delayjumpsets),
222-
typeof(de_chan0), typeof(rng), typeof(solkwargs)}(new_prob, aggregator, disc_agg,
223-
callbacks,
224-
cont_agg,
225-
jumps.regular_jump, maj,
226-
delayjumpsets, de_chan0,
227-
save_delay_channel, rng, solkwargs)
223+
typeof(de_chan0), typeof(rng), typeof(solkwargs)}(new_prob, aggregator,
224+
disc_agg,
225+
callbacks,
226+
cont_agg,
227+
jumps.regular_jump,
228+
maj,
229+
delayjumpsets,
230+
de_chan0,
231+
save_delay_channel,
232+
rng, solkwargs)
228233
end
229234

230235
make_kwarg(; kwargs...) = kwargs
@@ -264,7 +269,7 @@ function DelayJumpProblem(js::JumpSystem, prob, aggregator, delayjumpset, de_cha
264269
crjs = ConstantRateJump[assemble_crj(js, j, statetoid) for j in eqs.x[2]]
265270
vrjs = VariableRateJump[assemble_vrj(js, j, statetoid) for j in eqs.x[3]]
266271
# ((prob isa DiscreteProblem) && !isempty(vrjs)) &&
267-
# error("Use continuous problems such as an ODEProblem or a SDEProblem with VariableRateJumps")
272+
# error("Use continuous problems such as an ODEProblem or a SDEProblem with VariableRateJumps")
268273
jset = JumpSet(Tuple(vrjs), Tuple(crjs), nothing, majs)
269274

270275
if needs_vartojumps_map(aggregator) || needs_depgraph(aggregator)
@@ -326,7 +331,8 @@ function DiffEqBase.remake(thing::DelayJumpProblem; kwargs...)
326331
DelayJumpProblem(dprob, thing.aggregator, thing.discrete_jump_aggregation,
327332
thing.jump_callback,
328333
thing.variable_jumps, thing.regular_jump, thing.massaction_jump,
329-
delayjumpsets, de_chan0, thing.save_delay_channel, thing.rng, thing.kwargs)
334+
delayjumpsets, de_chan0, thing.save_delay_channel, thing.rng,
335+
thing.kwargs)
330336
end
331337

332338
function update_delayjumpsets(delayjumpsets::DelayJumpSet; kwargs...)

test/hawkes_delay_test.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ function hawkes_jump(i::Int, g, h, agg; uselrate = true)
5454
end
5555
end
5656
if typeof(agg) <: DelayCoevolve
57-
affect! = (integrator) -> begin
57+
affect! = (integrator) -> begin
5858
push!(h[i], integrator.t)
5959
integrator.u[i] += 0
6060
end
6161
else
62-
affect! = (integrator) -> begin
62+
affect! = (integrator) -> begin
6363
push!(h[i], integrator.t)
6464
integrator.u[i] += 1
6565
end
@@ -77,11 +77,12 @@ function hawkes_problem(p, agg::DelayCoevolve; u = [0.0], tspan = (0.0, 50.0),
7777
dprob = DiscreteProblem(u, tspan, p)
7878
jumps = JumpSet(hawkes_jump(u, g, h, agg; uselrate)...)
7979
de_chan0 = [[]]
80-
delay_trigger = Dict(1=>[1=>delay]) # add a delay of 1.0 to the first jump
81-
delay_complete = Dict(1=>[1=>1]) # complete the delay will duplicate 1 product
80+
delay_trigger = Dict(1 => [1 => delay]) # add a delay of 1.0 to the first jump
81+
delay_complete = Dict(1 => [1 => 1]) # complete the delay will duplicate 1 product
8282
delay_interrupt = Dict()
8383
delayjumpset = DelayJumpSet(delay_trigger, delay_complete, delay_interrupt)
84-
jprob = DelayJumpProblem(dprob, agg, jumps, delayjumpset, de_chan0; dep_graph = g, save_positions, rng)
84+
jprob = DelayJumpProblem(dprob, agg, jumps, delayjumpset, de_chan0; dep_graph = g,
85+
save_positions, rng)
8586
return jprob
8687
end
8788

@@ -109,7 +110,7 @@ function expected_stats_hawkes_problem(p, tspan, agg)
109110
λ, α, β = p
110111
γ = β - α
111112
κ = β / γ
112-
= λ * κ
113+
= λ * κ
113114
# Equation 21
114115
# J. Da Fonseca and R. Zaatour,
115116
# “Hawkes Process: Fast Calibration, Application to Trade Clustering and Diffusive Limit.”
@@ -124,8 +125,6 @@ tspan = (0.0, 250.0)
124125
g = [[1]]
125126
h = [Float64[]]
126127

127-
128-
129128
aggs = (Direct(), DelayCoevolve(), DelayCoevolve())
130129
uselrate = zeros(Bool, length(aggs))
131130
uselrate[3] = true
@@ -148,7 +147,8 @@ for (i, agg) in enumerate(aggs)
148147
λs = permutedims(mapreduce((sol) -> empirical_rate(sol, agg), hcat, sols))
149148
else
150149
cols = length(sols[1].u[1].u)
151-
λs = permutedims(mapreduce((sol) -> empirical_rate(sol, agg), hcat, sols))[:, 1:cols]
150+
λs = permutedims(mapreduce((sol) -> empirical_rate(sol, agg), hcat, sols))[:,
151+
1:cols]
152152
end
153153
Eλ, Varλ = expected_stats_hawkes_problem(p, tspan, agg)
154154
@test isapprox(mean(λs), Eλ; atol = 0.01)

0 commit comments

Comments
 (0)