API reference
ControlledHiddenMarkovModels.CHMMs
— ModuleCHMMs
Alias for ControlledHiddenMarkovModels
.
ControlledHiddenMarkovModels.ControlledHiddenMarkovModels
— ModuleControlledHiddenMarkovModels
A package for Hidden Markov Models with exogenous control variables.
Types
ControlledHiddenMarkovModels.AbstractControlledHMM
— TypeAbstractControlledHMM
Alias for AbstractControlledHiddenMarkovModel
.
ControlledHiddenMarkovModels.AbstractControlledHiddenMarkovModel
— TypeAbstractControlledHiddenMarkovModel
Interface for Hidden Markov Models with arbitrary emissions and exogenous control variables.
Required methods
nb_states(hmm, par)
initial_distribution(hmm, par)
transition_matrix(hmm, control, par)
emission_parameters(hmm, control, par)
emission_distribution(hmm, s, θ)
Compatible with
ControlledHiddenMarkovModels.AbstractHMM
— TypeAbstractHMM
Alias for AbstractHiddenMarkovModel
.
ControlledHiddenMarkovModels.AbstractHiddenMarkovModel
— TypeAbstractHiddenMarkovModel
Interface for Hidden Markov Models with arbitrary emissions.
Required methods
nb_states(hmm, par)
initial_distribution(hmm, par)
transition_matrix(hmm, par)
emission_distribution(hmm, s, par)
Compatible with
ControlledHiddenMarkovModels.HMM
— TypeHMM
Alias for HiddenMarkovModel
.
ControlledHiddenMarkovModels.HiddenMarkovModel
— TypeHiddenMarkovModel{R1,R2,D}
Concrete subtype of AbstractHMM
which stores the state and observation parameters directly.
Fields
p0::Vector{R1}
P::Matrix{R2}
emissions::Vector{D}
Compatible with
Methods
Base.rand
— Functionrand(rng, hmm::AbstractHMM, T, par)
Sample a trajectory of length T
from hmm
with parameters par
.
Returns a couple (state_sequence, obs_sequence)
.
Base.rand
— Methodrand(rng, hmm::AbstractControlledHMM, control_sequence, par)
Sample a trajectory from hmm
with controls control_sequence
and parameters par
.
Returns a couple (state_sequence, obs_sequence)
.
ControlledHiddenMarkovModels.backward!
— Methodbackward!(β, eβ, c, obs_density, P)
Perform a backward pass by mutating β
and eβ
. Comes after forward pass.
ControlledHiddenMarkovModels.baum_welch
— Methodbaum_welch(obs_sequences, hmm_init::HMM[, par; maxiter, tol])
Apply the Baum-Welch algorithm on multiple observation sequences, starting from an initial HMM
hmm_init
with parameters par
(not modifed).
ControlledHiddenMarkovModels.emission_distribution
— Methodemission_distribution(hmm::AbstractControlledHMM, s, θ)
Compute the emission distribution in state s
for hmm
with emission parameters θ
. Note that θ
was computed using emission_parameters(hmm, control, par)
.
The object returned must be sampleable and implement DensityInterface.jl.
ControlledHiddenMarkovModels.emission_distribution
— Methodemission_distribution(hmm::AbstractHMM, s, par)
Compute the emission distribution in state s
for hmm
with parameters par
.
The object returned must be sampleable and implement DensityInterface.jl.
ControlledHiddenMarkovModels.emission_parameters
— Methodemission_parameters(hmm::AbstractControlledHMM, control, par)
Compute the parameters of all emission distributions for hmm
with control control
and parameters par
.
ControlledHiddenMarkovModels.emission_type
— Methodemission_type(::Type{<:HMM})
Return the type of an emission distribution object.
ControlledHiddenMarkovModels.fit_mle_from_multiple_sequences
— Methodfit_mle_from_multiple_sequences(::Type{D}, xs, ws)
Fit a distribution of type D
based on multiple sequences of observations xs
associated with multiple sequences of weights ws
.
Must accept arbitrary iterables for xs
and ws
.
ControlledHiddenMarkovModels.fit_mle_from_single_sequence
— Methodfit_mle_from_single_sequence(::Type{D}, x, w)
Fit a distribution of type D
based on a single sequence of observations x
associated with a single sequence of weights w
.
Defaults to Distributions.fit_mle
, with a special case for vectors of vectors (because Distributions.fit_mle
accepts matrices instead). Users are free to override this default for concrete distributions.
ControlledHiddenMarkovModels.forward!
— Methodforward!(α, c, obs_density, p0, P)
Perform a forward pass by mutating α
and c
.
ControlledHiddenMarkovModels.forward_backward!
— Methodforward_backward!(α, c, β, eβ, γ, ξ, obs_density, p0, P)
Apply the full forward-backward algorithm by mutating α
, c
, β
, eβ
, γ
and ξ
.
ControlledHiddenMarkovModels.infer_current_state
— Functioninfer_current_state(hmm::AbstractHMM, obs_sequence, par; safe)
Infer the posterior distribution of the current state given obs_sequence
for hmm
with parameters par
.
ControlledHiddenMarkovModels.infer_current_state
— Functioninfer_current_state(hmm::AbstractControlledHMM, obs_sequence, control_sequence, par; safe)
Infer the posterior distribution of the current state given obs_sequence
for hmm
with controls control_sequence
and parameters par
.
ControlledHiddenMarkovModels.initial_distribution
— Methodinitial_distribution(hmm::AbstractControlledHMM, par)
Return the vector of initial state probabilities for hmm
with parameters par
.
ControlledHiddenMarkovModels.initial_distribution
— Methodinitial_distribution(hmm::AbstractHMM, par)
Compute the vector of initial state probabilities for hmm
with parameters par
.
ControlledHiddenMarkovModels.initialize_obs_density
— Methodinitialize_obs_density(obs_sequence, hmm, par)
Create a new observation density matrix and apply update_obs_density!
.
ControlledHiddenMarkovModels.is_prob_vec
— Methodis_prob_vec(p; atol)
Check if p
is a probability distribution vector.
ControlledHiddenMarkovModels.iszero_safe
— Methodiszero_safe(x::R)
Check if a number x
is zero by comparing its inverse with typemax(R)
.
This is useful in the following case:
julia> x = 1e-320
1.0e-320
julia> iszero(x)
false
julia> inv(x)
Inf
ControlledHiddenMarkovModels.light_forward
— Methodlight_forward(obs_sequence, hmm::AbstractHMM, par)
Perform a lightweight forward pass with minimal storage requirements.
ControlledHiddenMarkovModels.light_forward
— Methodlight_forward(obs_sequence, control_sequence, hmm::AbstractControlledHMM, par)
Perform a lightweight forward pass with minimal storage requirements.
ControlledHiddenMarkovModels.log_initial_distribution
— Methodlog_initial_distribution(hmm::AbstractControlledHMM, par)
Return the vector of initial state probabilities in log scale for hmm
with parameters par
.
ControlledHiddenMarkovModels.log_initial_distribution
— Methodlog_initial_distribution(hmm::AbstractHMM, par)
Compute the vector of initial state probabilities in log scale for hmm
with parameters par
.
ControlledHiddenMarkovModels.log_transition_matrix
— Methodlog_transition_matrix(hmm::AbstractControlledHMM, control, par)
Compute the state transition matrix in log scale for hmm
with control control
and parameters par
.
ControlledHiddenMarkovModels.log_transition_matrix
— Methodlog_transition_matrix(hmm::AbstractHMM, par)
Compute the state transition matrix in log scale for hmm
with parameters par
.
ControlledHiddenMarkovModels.logsumexp
— Methodlogsumexp(a)
Use logsumexp_offline
to compute the logsumexp of an iterable a
.
ControlledHiddenMarkovModels.logsumexp_stream
— Methodlogsumexp_stream(::Type{T}, a)
Compute the logsumexp function in a single pass for an iterable a
with elements of type T
. Source: https://www.nowozin.net/sebastian/blog/streaming-log-sum-exp-computation.html
ControlledHiddenMarkovModels.make_log_prob_vec!
— Methodmake_log_prob_vec!(logp)
Shift logp
so that exp.(logp)
becomes a probability distribution vector.
ControlledHiddenMarkovModels.make_log_trans_mat!
— Methodmake_log_trans_mat!(logP)
Scale logP
so that exp.(logP)
becomes a transition (stochastic) matrix.
ControlledHiddenMarkovModels.make_prob_vec!
— Methodmake_prob_vec!(p)
Scale p
into a probability distribution vector.
ControlledHiddenMarkovModels.make_trans_mat!
— Methodmake_trans_mat!(P)
Scale P
into a transition (stochastic) matrix.
ControlledHiddenMarkovModels.marginals!
— Methodmarginals!(γ, ξ, α, β, eβ, P)
Compute state and transition marginals by mutating γ
and ξ
. Comes after backward pass.
ControlledHiddenMarkovModels.nb_states
— Methodnb_states(hmm::AbstractControlledHMM, par)
Return the number of states for hmm
with parameters par
.
ControlledHiddenMarkovModels.nb_states
— Methodnb_states(hmm::AbstractHMM, par)
Compute the number of states for hmm
with parameters par
.
ControlledHiddenMarkovModels.rand_prob_vec
— Methodrand_prob_vec(rng, n)
Return a random probability distribution vector of size n
.
ControlledHiddenMarkovModels.rand_trans_mat
— Methodrand_trans_mat(rng, n)
Return a transition (stochastic) matrix of size n
with random transition probability distributions.
ControlledHiddenMarkovModels.transition_matrix
— Methodtransition_matrix(hmm::AbstractControlledHMM, control, par)
Compute the state transition matrix for hmm
with control control
and parameters par
.
ControlledHiddenMarkovModels.transition_matrix
— Methodtransition_matrix(hmm::AbstractHMM, par)
Compute the state transition matrix for hmm
with parameters par
.
ControlledHiddenMarkovModels.uniform_prob_vec
— Methoduniform_prob_vec(n)
Return a uniform probability distribution vector of size n
.
ControlledHiddenMarkovModels.uniform_trans_mat
— Methoduniform_trans_mat(n)
Return a transition (stochastic) matrix of size n
with uniform transition probability distributions.
ControlledHiddenMarkovModels.update_obs_density!
— Methodupdate_obs_density!(obs_density, obs_sequence, hmm::AbstractHMM, par)
Update the values obs_density[s, t]
using the emission density of hmm
with parameters par
applied to obs_sequence[t]
.
DensityInterface.logdensityof
— Functionlogdensityof(hmm::AbstractHMM, obs_sequence, par; safe)
Compute the log likelihood of obs_sequence
for hmm
with parameters par
.
DensityInterface.logdensityof
— Functionlogdensityof(hmm::AbstractControlledHMM, obs_sequence, control_sequence, par; safe)
Compute the log likelihood of obs_sequence
for hmm
with controls control_sequence
and parameters par
.
Index
ControlledHiddenMarkovModels.CHMMs
ControlledHiddenMarkovModels.ControlledHiddenMarkovModels
ControlledHiddenMarkovModels.AbstractControlledHMM
ControlledHiddenMarkovModels.AbstractControlledHiddenMarkovModel
ControlledHiddenMarkovModels.AbstractHMM
ControlledHiddenMarkovModels.AbstractHiddenMarkovModel
ControlledHiddenMarkovModels.HMM
ControlledHiddenMarkovModels.HiddenMarkovModel
ControlledHiddenMarkovModels.backward!
ControlledHiddenMarkovModels.baum_welch
ControlledHiddenMarkovModels.emission_distribution
ControlledHiddenMarkovModels.emission_distribution
ControlledHiddenMarkovModels.emission_parameters
ControlledHiddenMarkovModels.emission_type
ControlledHiddenMarkovModels.fit_mle_from_multiple_sequences
ControlledHiddenMarkovModels.fit_mle_from_single_sequence
ControlledHiddenMarkovModels.forward!
ControlledHiddenMarkovModels.forward_backward!
ControlledHiddenMarkovModels.infer_current_state
ControlledHiddenMarkovModels.infer_current_state
ControlledHiddenMarkovModels.initial_distribution
ControlledHiddenMarkovModels.initial_distribution
ControlledHiddenMarkovModels.initialize_obs_density
ControlledHiddenMarkovModels.is_prob_vec
ControlledHiddenMarkovModels.iszero_safe
ControlledHiddenMarkovModels.light_forward
ControlledHiddenMarkovModels.light_forward
ControlledHiddenMarkovModels.log_initial_distribution
ControlledHiddenMarkovModels.log_initial_distribution
ControlledHiddenMarkovModels.log_transition_matrix
ControlledHiddenMarkovModels.log_transition_matrix
ControlledHiddenMarkovModels.logsumexp
ControlledHiddenMarkovModels.logsumexp_stream
ControlledHiddenMarkovModels.make_log_prob_vec!
ControlledHiddenMarkovModels.make_log_trans_mat!
ControlledHiddenMarkovModels.make_prob_vec!
ControlledHiddenMarkovModels.make_trans_mat!
ControlledHiddenMarkovModels.marginals!
ControlledHiddenMarkovModels.nb_states
ControlledHiddenMarkovModels.nb_states
ControlledHiddenMarkovModels.rand_prob_vec
ControlledHiddenMarkovModels.rand_trans_mat
ControlledHiddenMarkovModels.transition_matrix
ControlledHiddenMarkovModels.transition_matrix
ControlledHiddenMarkovModels.uniform_prob_vec
ControlledHiddenMarkovModels.uniform_trans_mat
ControlledHiddenMarkovModels.update_obs_density!