class GaussianOutputModel

class deeptime.markov.hmm.GaussianOutputModel(n_states: int, means=None, sigmas=None, ignore_outliers: bool = True)

HMM output probability model using one-dimensional Gaussians.

Parameters:
  • n_states (int) – number of hidden states

  • means (array_like, optional, default=None) – means of the output Gaussians, length must match number of hidden states

  • sigmas (array_like, optional, default=None) – sigmas of the output Gaussians, length must match number of hidden states

  • ignore_outliers (bool, optional, default=True) – whether to ignore outliers which could cause numerical instabilities

Attributes

ignore_outliers

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

means

Mean values of Gaussian output densities.

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).

sigmas

Standard deviations of Gaussian output densities.

Methods

copy()

Makes a deep copy of this model.

fit(observations, weights)

Fits the output model given the observations and weights

generate_observation_trajectory(...)

Generate synthetic observation data from a given state sequence.

get_params([deep])

Get the parameters.

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)

Converts a list of observations to hidden state probabilities, i.e., for each observation \(o_t\), one obtains a vector \(p_t\in\mathbb{R}^{n_\mathrm{hidden}}\) denoting how probable that particular observation is in one of the 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 ([ ndarray(T_k,) ] with K elements) – A list of K observation trajectories, each having length T_k and d dimensions

  • weights ([ ndarray(T_k,n_states) ] with K elements) – A list of K weight matrices, each having length T_k weights[k][t,n] is the weight assignment from observations[k][t] to state index n

Examples

Generate an observation model and samples from each state.

>>> ntrajectories = 3
>>> nobs = 1000
>>> output_model = GaussianOutputModel(n_states=3, means=np.array([-1, 0, +1]), sigmas=np.array([0.5, 1, 2]))
>>> observations = [ np.random.randn(nobs) for _ in range(ntrajectories) ] # random observations
>>> weights = [ np.random.dirichlet([2, 3, 4], size=nobs) for _ in range(ntrajectories) ] # random weights

Update the observation model parameters my a maximum-likelihood fit. Fit returns self.

>>> output_model = output_model.fit(observations, weights)
generate_observation_trajectory(hidden_state_trajectory: ndarray) ndarray

Generate synthetic observation data from a given state sequence.

Parameters:

hidden_state_trajectory (numpy.array with shape (T,) of int type) – s_t[t] is the hidden state sampled at time t

Returns:

o_t – o_t[t] is the observation associated with state s_t[t]

Return type:

numpy.array with shape (T,) of type dtype

Examples

Generate an observation model and synthetic state trajectory.

>>> nobs = 1000
>>> output_model = GaussianOutputModel(n_states=3, means=[-1, 0, +1], sigmas=[0.5, 1, 2])
>>> s_t = np.random.randint(0, output_model.n_hidden_states, size=[nobs])

Generate a synthetic trajectory

>>> o_t = output_model.generate_observation_trajectory(s_t)
get_params(deep=False)

Get the parameters.

Returns:

params – Parameter names mapped to their values.

Return type:

mapping of string to any

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 accordingly.

Parameters:

observations_per_state ([ numpy.array with shape (N_k,) ] with n_states elements) – observations[k] is a set of observations sampled from state k

Examples

Generate synthetic observations.

>>> n_states = 3
>>> nobs = 1000
>>> output_model = GaussianOutputModel(n_states=n_states, means=np.array([-1, 0, 1]),
...                                    sigmas=np.array([0.5, 1, 2]))
>>> observations = [output_model.generate_observation_trajectory(np.array([state_index]*nobs))
...                 for state_index in range(n_states)]

Update output parameters by sampling.

>>> output_model.sample(observations)
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

Converts a list of observations to hidden state probabilities, i.e., for each observation \(o_t\), one obtains a vector \(p_t\in\mathbb{R}^{n_\mathrm{hidden}}\) denoting how probable that particular observation is in one of the hidden states.

Parameters:

observations ((T, d) ndarray) – Array of observations.

Returns:

state_probabilities – State probability trajectory.

Return type:

(T, n_hidden) ndarray

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 means

Mean values of Gaussian output densities.

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 sigmas

Standard deviations of Gaussian output densities.