Hazard Rate - adolgert/CTDE.jl GitHub Wiki

A hazard rate decides, given the series of states of the system since the transition last fired, what is the probability distribution for the hazard at this time. There is an abstract base class for hazards, called Intensity. The interface is

Enabled(intensity::Intensity) returns a boolean which says whether the hazard is currently enabled.

Reset!(intensity::RecoverIntensity, time::Float64, state, keys..) When a transition fires, this is called to tell the intensity that it must forget all past observations of the state and determine, from the state at the values specified by the keys, what is the new distribution going forward.

Update!(intensity::RecoverIntensity, time, state, keys...) This is the workhorse of the intensity distribution. Given the state at the given set of keys, the intensity chooses its current distribution for the hazard rate. It returns a symbol to report what happened. That symbol is either :Unmodified, :Disabled, :Enabled, or :Modified. The last choice, :Modified, means that the hazard was nonzero and is now nonzero but with a different distribution.

Sample(intensity::Intensity, when::Float64, rng::MersenneTwister) samples the current distribution for the hazard, given that it has not yet fired by time when.

Putative(intensity::Intensity, when::Float64, exponential_interval::Float64) integrates the current distribution for the hazard to determine at what time it will have used up an integrated hazard equal to exponential_interval. This is a way to sample distributions for Gibson and Bruck's Next Reaction Method or Anderson's method.

Infection example

Infection of an individual.

type InfectIntensity <: Intensity
    distribution::TransitionExponential
    enabled::Bool
    InfectIntensity(dist)=new(dist, false)
end

function Reset!(intensity::InfectIntensity, time, state, who, whom)
    Update!(intensity, time, state, who, whom)
end

function Update!(intensity::InfectIntensity, time, state, who, whom)
    modified=:Undefined
    enabled=(state[who]==1 && state[whom]==0)
    if enabled!=intensity.enabled
        if enabled
            intensity.distribution.enabling_time=time
            modified=:Enabled
        else
            modified=:Disabled
        end
        intensity.enabled=enabled
    else
        modified=:Unmodified
    end
    modified
end