API reference
Basic schema
Functions to create basic Markov individual-based models (IBM).
Individual.SchemaBase.TheoryIBM
— ConstantACSet definition for a basic individual-based model See Catlab.jl documentation for description of the @present
syntax.
Individual.SchemaBase.AbstractIBM
— TypeAn abstract ACSet for a basic Markov individual-based model.
Individual.SchemaBase.IBM
— TypeA concrete ACSet for a basic Markov individual-based model inheriting from AbstractIBM
.
Individual.SchemaBase.npeople
— Functionnpeople(model::AbstractIBM, states)
Return the number of people in some set of states
(an element of the State Ob). If called without the argument states
, simply return the total population size.
Individual.SchemaBase.nstate
— Functionnstate(model::AbstractIBM)
Return the size of the finite state space.
Individual.SchemaBase.statelabel
— Functionstatelabel(model::AbstractIBM)
Return the labels (names) of the states in the finite state space.
Individual.SchemaBase.get_index_state
— Functionget_index_state(model::AbstractIBM, states)
Return an integer vector giving the persons who are in the states specified in states
. If called without the argument states
, simply return everyone's index.
Individual.SchemaBase.queue_state_update
— Functionqueue_state_update(model::AbstractIBM, persons, state)
For persons specified in persons
, queue a state update to state
, which will be applied at the end of the time step.
Individual.SchemaBase.render_states
— Functionrender_states(model::AbstractIBM, steps::Integer)
Return a tuple whose first element is a matrix containing counts of states (columns) by time step (rows), and whose second element is a process function which can be used in the simulation loop.
Individual.SchemaBase.initialize_states
— Functioninitialize_states(model::AbstractIBM, initial_states, state_labels::Vector{String})
Initialize the categorical states of a model. The argument initial_states
can either be provided as a vector of integers, corresponding to the internal storage of the ACSet, or as a vector of strings. It should be equal in length to the population which is to be simulated.
Individual.SchemaBase.reset_states
— Functioninitialize_states(model::AbstractIBM, initial_states)
Reset a model's categorical states.
Individual.SchemaBase.create_state_update
— Functioncreate_state_update(model::AbstractIBM)
Return a function that is called with no arguments that updates any Ob
that has an accompanying update Ob
. For example, if you provide both risk
and risk_update
, then risk_update
will be used to update risk
and then cleared.
Individual.SchemaBase.create_attr_update
— Functioncreateattrupdate(model::AbstractIBM)
Return a function that is called with no arguments that updates any Attr
that has an accompanying update Attr
. For example, if you provide both antibody
and antibody_titre
as Attr
objects from Person
to the apropriate AttrType
, this function will update antibody
to the values in antibody_titre
on each time step. This requires that when the model is initialized, each attribute and its update have approximately the same starting values.
Individual.SchemaBase.simulation_loop
— Functionsimulation_loop(model::AbstractIBM, processes::Union{Function, AbstractVector{Function}}, steps::Integer)
A simple predefined simulation loop for basic (no events) individual based models. Processes are called first, followed by state updates.
simulation_loop(model::AbstractIBM, processes::Union{Function, AbstractVector{Function}}, steps::Integer)
A method for simulation models with event scheduling.
Event scheduling schema
Create IBMs with event scheduling capabilities.
Individual.SchemaEvents.TheorySchedulingIBM
— ConstantA schema for an individual-based model inheriting from TheoryIBM
which allows for events to be scheduled for persons.
Individual.SchemaEvents.AbstractSchedulingIBM
— TypeAn abstract ACSet for an individual-based model inheriting from AbstractIBM
which allows for events to be scheduled for persons.
Individual.SchemaEvents.SchedulingIBM
— TypeA concrete ACSet for an individual-based model inheriting from AbstractSchedulingIBM
which allows for events to be scheduled for persons.
Individual.SchemaEvents.add_event
— Functionadd_event(model::AbstractSchedulingIBM, label::String, listeners...)
Add an event to the model, with name 'label',
Individual.SchemaEvents.schedule_event
— Functionschedule_event(model::AbstractSchedulingIBM, target, delay, event)
Schedule a set of persons in target
for the event
after some delay
. Note that event
should correspond to an element in the set EventLabel
in your model.
Individual.SchemaEvents.get_scheduled
— Functionget_scheduled(model::AbstractSchedulingIBM, event)
Get the set of persons scheduled for event
. Note that event
should correspond to an element in the set EventLabel
in your model.
Individual.SchemaEvents.clear_schedule
— Functionclear_schedule(model::AbstractSchedulingIBM, target)
Clear the persons in target
from any events they are scheduled for. If 'target' is not specified, clear all scheduled events.
Individual.SchemaEvents.event_tick
— Functionevent_tick(model::AbstractSchedulingIBM)
Reduce all delays by 1, called at the end of a time step.
Individual.SchemaEvents.event_process
— Functionevent_process(model::AbstractSchedulingIBM, t::Int)
Process events which are ready to fire.
Sampling
Methods for Sampling random variates commonly used in IBMs.
Individual.Sampling.delay_geom_sample
— Functiondelay_geom_sample(n::Integer, rate::AbstractFloat, dt::AbstractFloat)
Sample time steps until an event fires given a rate
and dt
where the waiting time follows a Geometric distribution. The minimum delay is 1
, otherwise there could be "instantaneous" events, which are better (more efficiently) simulated as processes.
Individual.Sampling.bernoulli_sample
— Functionbernoulli_sample(target::AbstractVector, prob::AbstractFloat)
Sample without replacement from target
with success probability prob
.
bernoulli_sample(target::AbstractVector, rate::AbstractFloat, dt::AbstractFloat)
Sample without replacement from target
with success probability calculated from $1 - e^{-\mathrm{rate} * \mathrm{dt}}$
bernoulli_sample(target::AbstractVector{T}, prob::Vector{R})
Sample without replacement from target
where each element has a unique success probability given in the vector prob
.
bernoulli_sample(target::AbstractVector{T}, rate::Vector{R}, dt::AbstractFloat)
Sample without replacement from target
where each element's success probability is calculated from $1 - e^{-\mathrm{rate} * \mathrm{dt}}$.
Individual.Sampling.choose
— Functionchoose(target::T, K::Integer) where {T <: Integer}
choose(target::AbstractVector{T}, K::Integer) where {T <: Integer}
Return a vector of size K
with that number of random elements selected without replacement from target
.