SciCompMod / memilio

Modular spatio-temporal models for epidemic and pandemic simulations
https://scicompmod.github.io/memilio/
Apache License 2.0
51 stars 15 forks source link

SDE Models have different step sizes #1006

Closed nijawa closed 2 months ago

nijawa commented 2 months ago

Bug description

The SDE Models have a member variable step_size controlling the step size of the stochastic process. The function simulate also takes a function parameter dt which controls the step size of the integrator core. Those two can be different. This can result in NAN output (and the result is not what you would expect from the SDE model)

Version

Windows

To reproduce

  1. Set seed to 14159265u, 35897932u to get reproducable results (reproducable with basically all seeds)
  2. Build Code
  3. Run Example sde_sirs sirs_bug

Relevant log output

No response

Add any relevant information, e.g. used compiler, screenshots.

No response

Checklist

reneSchm commented 2 months ago

The values of step_size and dt are the same during simulation, at least when using a mio::ssirs::(Flow)Simulation. See models/sde_sirs/simulation.h:63 and :124.

I think the problem is that with the current parameters the flows have pretty extreme values, and can sometimes even get negative values. Clamping to 0 fixes the NaNs at least, here is some output:

         0.81800          0.56708       8442.04686       1557.38607
         0.81900          0.34570       8442.05194       1557.60237
         0.82000          0.37208       8441.09590       1558.53202
         0.82100          0.40253       8440.00211       1559.59536
         0.82200          0.57070       8439.48523       1559.94408
         0.82300          0.68348       8439.53834       1559.77818
         0.82400          0.44854       8438.97716       1560.57430
         0.82500          0.43399       8438.46640       1561.09961
         0.82600          0.42257       8438.52051       1561.05692
         0.82700          0.26341       8438.06443       1561.67215
         0.82800          0.33228       8438.03298       1561.63474
         0.82900          0.31843       8436.41828       1563.26329
         0.83000          0.23948       8435.94474       1563.81578
         0.83100          0.19645       8433.88955       1565.91400
         0.83200          0.19920       8433.33963       1566.46117
         0.83300          0.19920       8431.30414       1568.49666