4.1.8.5. causality/Stochsim¶
- class mod.MassActionKinetics¶
A helper class for performing stochastic simulations where events are drawn according to the law of mass action. Importantly, if the underlying derivation graph is enlarged then
syncSize()
must be called before callingdraw()
.
- mod.__init__(dg, inputRate, reactionRate, outputRate)¶
Construct a new instance, based on the given derivation graph. The rates returned by the input, reaction, and output rate callbacks may be cached.
- Parameters
dg (DG) – the underlying derivation graph.
inputRate (Callable[[DGVertex], float] or float) – the injection rate callback or constant.
reactionRate (Callable[[DGHyperEdge], float] or float) – the reaction rate callback or constant.
outputRate (Callable[[DGVertex], float] or float) – the drain rate callback or constant.
- Raises
LogicError
ifnot dg
.- Raises
LogicError
if neitherdg.hasActiveBuilder
nordg.locked
.
- mod.syncSize()¶
Enlarges the internal data structures to the current size of the underlying derivation graph.
- mod.draw(m)¶
- Parameters
m (DGPetriNetMarking) – the population to take into account.
- Returns
one of the hyperedges enabled in
m
, randomly selected according to the low of mass action based on the given population/marking and the reaction rates. The second returned component is the sum of reactivity for the given reactions/hyperedges.If no events are possible, then the second component is 0.
Use
rngReseed()
to seed the pseudo-random bit generator used for the selection.- Return type
tuple[Union[CausalityEdgeAction, CausalityInputAction, CausalityOutputAction], float]
- Raises
LogicError
ifm
is not a marking on the underlying derivation graph.
Requires
syncSize()
to have been called since the last time the underlying derivation graph has changed size.