Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iip or oop functionality #27

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/StochSystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ end
Concatenates the deterministic and stochastic parameter vectors `pf` and `pg` of a StochSystem `sys`.
"""
function p(sys::StochSystem)
[sys.pf, sys.pg]
end;
isnothing(sys.pg) ? sys.pf : [sys.pf, sys.pg]
reykboerner marked this conversation as resolved.
Show resolved Hide resolved
end

"""
CoupledODEs(sys::StochSystem; diffeq, t0=0.0)
Expand All @@ -67,4 +67,4 @@ Converts a [`CoupledODEs`](https://juliadynamics.github.io/DynamicalSystems.jl/s
system into a [`StochSystem`](@ref).
"""
StochSystem(ds::DynamicalSystemsBase.CoupledODEs; σ=0.0, g=idfunc, pg=nothing, Σ=I(length(get_state(ds))), process="WhiteGauss") =
StochSystem(dynamic_rule(ds), [ds.p0], get_state(ds), σ, g, pg, Σ, process)
StochSystem(dynamic_rule(ds), [ds.p0], get_state(ds), σ, g, pg, Σ, process)
34 changes: 18 additions & 16 deletions src/trajectories/simulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@ For more info, see [`SDEProblem`](https://diffeq.sciml.ai/stable/types/sde_types

> Warning: This function has only been tested for the `EM()` solver and out-of-place `SDEFunction`s.
"""
function simulate(sys::StochSystem, init::State;
dt=0.01,
tmax=1e3,
solver=EM(),
callback=nothing,
progress=true,
kwargs...)

prob = SDEProblem(sys.f, σg(sys), init, (0, tmax), p(sys), noise=stochprocess(sys))
solve(prob, solver; dt=dt, callback=callback, progress=progress, kwargs...)
end;

function simulate(sys::StochSystem, init;
dt = 0.01,
tmax = 1e3,
solver = EM(),
callback = nothing,
progress = true,
iip = is_iip(sys.f),
kwargs...)

prob = SDEProblem{iip}(
sys.f, σg(sys), init, (0, tmax), p(sys), noise = stochprocess(sys))
solve(prob, solver; dt = dt, callback = callback, progress = progress, kwargs...)
end
"""
relax(sys::StochSystem, init::State; kwargs...)
Simulates the deterministic dynamics of StochSystem `sys` in time, starting at initial condition `init`.
Expand All @@ -43,7 +44,7 @@ This function integrates `sys.f` forward in time, using the [`ODEProblem`](https
* `callback=nothing`: callback condition
* `kwargs...`: keyword arguments for [`solve(ODEProblem)`](https://docs.sciml.ai/DiffEqDocs/stable/basics/common_solver_opts/#solver_options)

For more info, see [`ODEProblem`](https://diffeq.sciml.ai/stable/types/ode_types/#SciMLBase.ODEProblem).
For more info, see [`ODEProblem`](https://diffeq.sciml.ai/stable/types/ode_types/#SciMLBase.ODEProblem).
For stochastic integration, see [`simulate`](@ref).

> Warning: This function has only been tested for the `Euler()` solver.
Expand All @@ -53,8 +54,9 @@ function relax(sys::StochSystem, init::State;
tmax=1e3,
solver=Euler(),
callback=nothing,
iip = is_iip(sys.f),
kwargs...)
prob = ODEProblem(sys.f, init, (0, tmax), p(sys))

prob = ODEProblem{iip}(sys.f, init, (0, tmax), p(sys))
solve(prob, solver; dt=dt, callback=callback, kwargs...)
end;
end;
Loading