class DiscreteOutputModel

class deeptime.markov.hmm.DiscreteOutputModel(output_probabilities: ndarray, prior: Optional[ndarray] = None, ignore_outliers: bool = False, discrete_states_manager=None)

HMM output probability model using discrete symbols. This corresponds to the “standard” HMM that is classically used in the literature.

Parameters:
  • output_probabilities (((N, M) dtype=float32 or float64) ndarray) – Row-stochastic output probability matrix for N hidden states and M observable symbols.

  • prior (None or type and shape of output_probabilities, optional, default=None) –

    Prior for the initial distribution of the HMM. Currently implements the Dirichlet prior that is conjugate to the Dirichlet distribution of \(b_i\), which is sampled from

    where \(n_{ij}\) are the number of times symbol \(j\) has been observed when the hidden trajectory was in state \(i\) and \(a_{ij}\) is the prior count. The default prior=None corresponds to \(a_{ij} = 0\). This option ensures coincidence between sample mean an MLE.

  • ignore_outliers (bool, optional, default=False) – Whether to ignore outliers, see ignore_outliers.

  • discrete_states_manager (DiscreteStatesManager, optional, default=None) –

Attributes

ignore_outliers

By outliers observations that have zero probability given the current model are meant.

n_hidden_states

Number of hidden states.

n_observable_states

Number of observable states, can be -1 if not applicable (e.g., in a continous observable space).

output_probabilities

A row-stochastic matrix of shape (n_hidden_states, n_observable_states) describing the (conditional) discrete probability distribution of observable states given one hidden state.

prior

Prior matrix.

Methods

copy()

Makes a deep copy of this model.

fit(observations, weights)

Fits the output model given the observations and weights.

generate_observation_trajectory(...)

Generates a synthetic trajectory in observation space given a trajectory in hidden state space.

get_params([deep])

Get the parameters.

map_observations_to_submodel(observations)

Map a sequence of observations to the reduced state space of a sub-model.

normalize()

Normalizes output probabilities so they are row-stochastic.

sample(observations_per_state)

Sample a new set of distribution parameters given a sample of observations from the given state.

set_params(**params)

Set the parameters of this estimator.

submodel([states, obs])

Restricts this model to a set of hidden states and observable states (if applicable).

to_state_probability_trajectory(observations)

Returns the output probabilities for an entire trajectory and all hidden states.

copy() Model

Makes a deep copy of this model.

Returns:

A new copy of this model.

Return type:

copy

fit(observations: List[ndarray], weights: List[ndarray])

Fits the output model given the observations and weights.

Parameters:
  • observations (list of ndarray) – A list of K observation trajectories

  • weights (list of ndarray) – A list of K weight matrices, each having length T_k of their corresponding observation trajectory. Evaluating weights[k][t,n] should yield the weight assignment from observations[k][t] to state index n.

Returns:

self – Reference to self.

Return type:

OutputModel

generate_observation_trajectory(hidden_state_trajectory: ndarray) ndarray

Generates a synthetic trajectory in observation space given a trajectory in hidden state space.

Parameters:

hidden_state_trajectory ((T, 1) ndarray) – Hidden state trajectory.

Returns:

observations – Observation timeseries \(\{o_t\}_t\), where \(o_t\) is the observation associated to hidden state \(s_t\).

Return type:

(T, d) ndarray

get_params(deep=False)

Get the parameters.

Returns:

params – Parameter names mapped to their values.

Return type:

mapping of string to any

map_observations_to_submodel(observations: ndarray)

Map a sequence of observations to the reduced state space of a sub-model.

Parameters:

observations (ndarray) – sequence of observations

Returns:

mapped_observations – array containing mapped observation sequence

Return type:

ndarray

normalize()

Normalizes output probabilities so they are row-stochastic.

sample(observations_per_state: List[ndarray]) None

Sample a new set of distribution parameters given a sample of observations from the given state. The internal parameters are updated.

Parameters:

observations_per_state ([ numpy.array with shape (N_k,) ] of length n_hidden_states) – observations[k] are all observations associated with hidden state k

Examples

Initialize output model

>>> B = np.array([[0.5, 0.5], [0.1, 0.9]])
>>> output_model = DiscreteOutputModel(B)

Sample given observation

>>> obs = [np.asarray([0, 0, 0, 1, 1, 1]),
...        np.asarray([1, 1, 1, 1, 1, 1])]
>>> output_model.sample(obs)
set_params(**params)

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as pipelines). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters:

**params (dict) – Estimator parameters.

Returns:

self – Estimator instance.

Return type:

object

submodel(states: Optional[ndarray] = None, obs: Optional[ndarray] = None)

Restricts this model to a set of hidden states and observable states (if applicable).

Parameters:
  • states (ndarray, optional, default=None) – The hidden states to restrict to, per default no restriction.

  • obs (ndarray, optional, default=None) – The observable states to restrict to (if applicable), per default no restriction.

Returns:

submodel – The restricted output model.

Return type:

OutputModel

to_state_probability_trajectory(observations: ndarray) ndarray

Returns the output probabilities for an entire trajectory and all hidden states.

Parameters:

observations (ndarray((T), dtype=int)) – a discrete trajectory of length T

Returns:

p_o – The probability of generating the symbol at time point t from any of the N hidden states.

Return type:

ndarray (T,N)

property ignore_outliers: bool

By outliers observations that have zero probability given the current model are meant. ignore_outliers=True means that outliers will be treated as if no observation was made, which is equivalent to making this observation with equal probability from any hidden state. ignore_outliers=False means that an Exception or in the worst case an unhandled crash will occur if an outlier is observed.

property n_hidden_states: int

Number of hidden states.

property n_observable_states: int

Number of observable states, can be -1 if not applicable (e.g., in a continous observable space).

property output_probabilities

A row-stochastic matrix of shape (n_hidden_states, n_observable_states) describing the (conditional) discrete probability distribution of observable states given one hidden state.

property prior: ndarray

Prior matrix.