JuliaDynamics / CriticalTransitions.jl

A Julia package for critical transitions in dynamical systems with time-dependent forcing
https://juliadynamics.github.io/CriticalTransitions.jl/dev/
MIT License
26 stars 3 forks source link

Dealing with deterministic parameter and stochastic parameter #42

Closed oameye closed 2 months ago

oameye commented 6 months ago

Now the user is expected construct their deterministic function in a way that it takes in parameter of the form [dp, sp] with dp the deterministic vector of parameters and sp the stochastic vector of parameters. However, this makes it dificult to convert deterministic ODE of other packages from DynamicalSystems, OrdinaryDiffEq and HarmonicBalance. Instead, I propose we change handling of the parameters in such a way that the deterministic function f(u, p, t) takes in a Vector instead of Vector{Vector}.

https://github.com/JuliaDynamics/CriticalTransitions.jl/blob/09bb88dc69fdf2d119e5dfd6e60c064234308abc/docs/src/tutorial.md?plain=1#L27-L35

reykboerner commented 6 months ago

Yes, we thought about this as well back then when writing the StochSystem struct. The reason why we did this is that the SDEProblem from DiffEq only has one parameter field p for both the deterministic function f and the noise function g. However, in the StochSystem struct, we wanted to have the deterministic and stochastic parameters separately because the idea is to e.g. take a deterministic system with a set of parameters and throw different noise terms at it which might have different numbers of parameters.

Ideally, f(u,p,t) would take in a Vector for p (and not Vector{Vector}) and behind the scenes the StochSystem would sort this together with the stochastic parameters pg to pass it to SDEProblem in a way that still works. Any ideas on how to best do this are very welcome :)

oameye commented 5 months ago

Ideally, f(u,p,t) would take in a Vector for p (and not Vector{Vector}) and behind the scenes the StochSystem would sort this together with the stochastic parameters pg to pass it to SDEProblem in a way that still works. Any ideas on how to best do this are very welcome :)

I think we can work this out. I will start a PR

oameye commented 5 months ago

I have been looking into how StochasticDiffEq does parameter handling and it seems to opt for one iterator (vector, tuple, etc.) where the functions f or g know which index to call for a specific param. I would try to mimic this framework such that we have a smooth interplay between ModelingToolkit and StochasticDiffEq. We should do this in parallel with #75.