epi-sim-0.7.0: A library for simulating epidemics as birth-death processes.
Copyright(c) 2021 Alexander E. Zarebski
LicenseMIT
MaintainerAlexander E. Zarebski <aezarebski@gmail.com>
Stabilityunstable
Portabilityghc
Safe HaskellNone
LanguageHaskell2010

Epidemic.Model.InhomogeneousBDSCOD

Description

This module defines a birth-death model with continuous time sampling and scheduled sampling and rates that are piece-wise constant in time.

Example: we will run a simulation for one unit of time and require that there be at least two sequenced samples.

>>> simDuration = TimeDelta 1.0
>>> atLeastTwoSequences = True

The rates can change through time so we need to specify the times at which they change. In this example the birth rate starts at 1.0 and then drops down to 0.5. The other rates stay at their initial values.

>>> birthRateSpec = [(AbsoluteTime 0.0, 1.0), (AbsoluteTime 0.5, 0.5)]
>>> deathRateSpec = [(AbsoluteTime 0.0, 0.2)]
>>> sampRateSpec = [(AbsoluteTime 0.0, 0.1)]
>>> occRateSpec = [(AbsoluteTime 0.0, 0.1)]

There are a couple of scheduled samples with probabilities specified for them, ie there will be a scheduled sample at time 0.9 where each lineage is removed and sequenced individually with probability 0.1 and at times 0.5 and 0.75 there is a scheduled sample where individuals are removed but not sequenced with probabilities 0.4 and 0.5 respectively.

>>> seqSched = [(AbsoluteTime 0.9, 0.1)]
>>> unseqSched = [(AbsoluteTime 0.5, 0.4), (AbsoluteTime 0.75, 0.5)]

This is enough to define a SimulationConfiguration. We will ignore the possibility of using a termination handler for this example.

>>> ratesAndProbs = (birthRateSpec,deathRateSpec,sampRateSpec,seqSched,occRateSpec,unseqSched)
>>> (Just simConfig) = configuration simDuration atLeastTwoSequences Nothing ratesAndProbs

Then we can use this to generated a list of epidemic events in the simulation

>>> myEpidemicEvents = simulationWithSystem simConfig (allEvents randomEvent)

and from this we can extract the observations

>>> myObservedEvents = do
>>> simState <- myEpidemicEvents
>>> case simState of
>>> Right es -> return $ observedEvents es
>>> Left _ -> return $ Left "simulation terminated early"
Synopsis

Documentation

configuration Source #

Arguments

:: TimeDelta

Duration of the simulation after starting at time 0.

-> Bool

condition upon at least two sequenced samples.

-> Maybe (InhomBDSCODPop -> Bool, [EpidemicEvent] -> s)

values for termination handling.

-> ([(AbsoluteTime, Rate)], [(AbsoluteTime, Rate)], [(AbsoluteTime, Rate)], [(AbsoluteTime, Probability)], [(AbsoluteTime, Rate)], [(AbsoluteTime, Probability)]) 
-> Maybe (SimulationConfiguration InhomBDSCODRates InhomBDSCODPop s) 

Configuration for the simulation of the inhomogeneous rates BDSCOD process.

randomEvent :: SimulationRandEvent InhomBDSCODRates InhomBDSCODPop Source #

A random event and the state afterwards