Closed MGrunnill closed 1 month ago
Would halting occur when any class in the list went extinct or only if all classes went extinct?
I can think of cases where both would be helpful. How should the api look to allow eaither case?
Are there likely to be issues induced by having response variables of differing lengths from different runs?
Might be possible to make this a bit more generic and introduce stopping conditions for stochastic simulations. Perhaps the simulate api should accept an interable of stopping condition objects. These objects would then have state and conditional attributes. I.e. for the case outlined in @MGrunnill 's initial issue these might be 'S' and '<= 0'. There is also the thought that the condition itself should perhaps be an equation (like the transition objects) so that you could set up conditions like 'S' '< 2 R' to make this as flexible as possible.
With this the answer to the inital questions would be:
After consideration this significantly complicates the (already complicated) code. so will not happen at this stage.
Depending on the nature of the stochastic simulation if certain class/es have gone extinct it is not necessary to continue running the simulation. A break clause could be added to stop a simulation if the population in certain class/es reached 0.
Within the module
simulate.py
following additions could be made:The function
simulate_jump
could take the optional argumentstop_at_extinction_of
. This argument would take a list of indexes of state variables, the default argument would be an empty list.Before the while loop within the function
_jump
the codeextinction_clause = False
could be added.The while argument within the function
_jump
would becomewhile t < finalT and extinction_clause == False:
.At the end of the while loop within the function
_jump
the following code could be added:After the while loop within the function
_jump
there would have to be some post prossesing. Filling each of the time steps after extinction of the np.arraysxList
andtList
with either NA values or a string stating the selected population/s had gone extinct.