SciML / StochasticDiffEq.jl

Solvers for stochastic differential equations which connect with the scientific machine learning (SciML) ecosystem
Other
247 stars 66 forks source link

plotting with default solver #136

Closed isaacsas closed 5 years ago

isaacsas commented 5 years ago
using DifferentialEquations, DiffEqBiological, Plots
bdp = @reaction_network begin
  c₁, X --> 2X
  c₂, X --> 0
  c₃, 0 --> X
end c₁ c₂ c₃
p = (1.0,2.0,50.)
u₀ = [5.]
tspan = (0.,4.)
sprob = SDEProblem(bdp, u₀, tspan, p)
sol = solve(sprob, saveat=.004)
plot(sol, fmt=:svg)

gives a plot that seems to have way too few points and just uses linear interpolation:

download

I've played around with tstops in the solver and plotdensity and neither seems to fix this issue.

ChrisRackauckas commented 5 years ago

Way too few points? I thought the issue was too many in the plot?

isaacsas commented 5 years ago

No, the issue is I can't get the plot to actually look well-resolved. Changing tstops to also be 1000 points doesn't seem to make a difference.

ChrisRackauckas commented 5 years ago

What did you set tstops to?

The "issue" that you're having is that the true solution hits the tolerance with only a few steps and uses linear interpolation, so it doesn't look like a small dt SDE solution, but it's still a valid path. You can constrain the dt, lower the tolerance, tstops, etc. if you want more steps, but without a stochastic interpolation (whatever that would be) it would be hard to noise the intermediate parts between steps.

isaacsas commented 5 years ago
sol = solve(sprob, saveat=4e-3, tstops=4e-5)

gives test

ChrisRackauckas commented 5 years ago

tstops doesn't expand scalars. You need an array if you want more than one point.

isaacsas commented 5 years ago

I see. I'll check that fixes it and then close if it looks good. Thanks!

isaacsas commented 5 years ago

Yup, I was dumb. Sorry to waste your time on that one. Thanks.

ChrisRackauckas commented 5 years ago

If you have ideas for high order stochastic interpolation then I'm interested though. It's a funny little problem that comes up once you're able to start solving these things efficiently!

isaacsas commented 5 years ago

That is an interesting issue I hadn't thought about before; since I usually just work with ODEs/PDEs and jump processes I'm not super familiar with the intermediate SDE/SPDE representations and issues that crop up there.