Copyright | (c) 2021 Alexander E. Zarebski |
---|---|
License | MIT |
Maintainer | Alexander E. Zarebski <aezarebski@gmail.com> |
Stability | unstable |
Portability | ghc |
Safe Haskell | None |
Language | Haskell2010 |
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
- configuration :: TimeDelta -> Bool -> Maybe (InhomBDSCODPop -> Bool, [EpidemicEvent] -> s) -> ([(AbsoluteTime, Rate)], [(AbsoluteTime, Rate)], [(AbsoluteTime, Rate)], [(AbsoluteTime, Probability)], [(AbsoluteTime, Rate)], [(AbsoluteTime, Probability)]) -> Maybe (SimulationConfiguration InhomBDSCODRates InhomBDSCODPop s)
- randomEvent :: SimulationRandEvent InhomBDSCODRates InhomBDSCODPop
- data InhomBDSCODRates = InhomBDSCODRates {}
- data InhomBDSCODPop = InhomBDSCODPop {}
- getNumRemovedByDeath :: InhomBDSCODPop -> Int
- getNumRemovedBySampling :: InhomBDSCODPop -> Int
- getNumRemovedByCatastrophe :: InhomBDSCODPop -> Int
- getNumRemovedByOccurrence :: InhomBDSCODPop -> Int
- getNumRemovedByDisaster :: InhomBDSCODPop -> Int
Documentation
:: 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
data InhomBDSCODRates Source #
Instances
Eq InhomBDSCODRates Source # | |
Defined in Epidemic.Model.InhomogeneousBDSCOD (==) :: InhomBDSCODRates -> InhomBDSCODRates -> Bool # (/=) :: InhomBDSCODRates -> InhomBDSCODRates -> Bool # | |
Show InhomBDSCODRates Source # | |
Defined in Epidemic.Model.InhomogeneousBDSCOD showsPrec :: Int -> InhomBDSCODRates -> ShowS # show :: InhomBDSCODRates -> String # showList :: [InhomBDSCODRates] -> ShowS # | |
ModelParameters InhomBDSCODRates InhomBDSCODPop Source # | |
Defined in Epidemic.Model.InhomogeneousBDSCOD rNaught :: InhomBDSCODPop -> InhomBDSCODRates -> AbsoluteTime -> Maybe Double Source # eventRate :: InhomBDSCODPop -> InhomBDSCODRates -> AbsoluteTime -> Maybe Rate Source # birthProb :: InhomBDSCODPop -> InhomBDSCODRates -> AbsoluteTime -> Maybe Probability Source # eventWeights :: InhomBDSCODPop -> InhomBDSCODRates -> AbsoluteTime -> Maybe (Vector Double) Source # |
data InhomBDSCODPop Source #
The population in which the epidemic occurs. This includes information about the number of people that have previously been infected and subsequently removed.
Instances
Show InhomBDSCODPop Source # | |
Defined in Epidemic.Model.InhomogeneousBDSCOD showsPrec :: Int -> InhomBDSCODPop -> ShowS # show :: InhomBDSCODPop -> String # showList :: [InhomBDSCODPop] -> ShowS # | |
Population InhomBDSCODPop Source # | |
Defined in Epidemic.Model.InhomogeneousBDSCOD | |
ModelParameters InhomBDSCODRates InhomBDSCODPop Source # | |
Defined in Epidemic.Model.InhomogeneousBDSCOD rNaught :: InhomBDSCODPop -> InhomBDSCODRates -> AbsoluteTime -> Maybe Double Source # eventRate :: InhomBDSCODPop -> InhomBDSCODRates -> AbsoluteTime -> Maybe Rate Source # birthProb :: InhomBDSCODPop -> InhomBDSCODRates -> AbsoluteTime -> Maybe Probability Source # eventWeights :: InhomBDSCODPop -> InhomBDSCODRates -> AbsoluteTime -> Maybe (Vector Double) Source # |