HiddenMarkovModel

lumicks.pylake.HiddenMarkovModel

class HiddenMarkovModel(data, n_states, *, tol=0.001, max_iter=250, initial_guess=None)

A Hidden Markov Model describing hidden state occupancy and state transitions of observed time series data (force, fluorescence, etc.)

A detailed description of the model properties and training algorithms can be found in [1].

Warning

This is early access alpha functionality. While usable, this has not yet been tested in a large number of different scenarios. The API can still be subject to change without any prior deprecation notice! If you use this functionality keep a close eye on the changelog for any changes that may affect your analysis.

Parameters:
  • data (numpy.ndarray | Slice) – Data array used for model training.

  • n_states (int) – The number of hidden states in the model.

  • tol (float) – The tolerance for training convergence.

  • max_iter (int) – The maximum number of iterations to perform.

  • initial_guess (HiddenMarkovModel | GaussianMixtureModel | None) – Initial guess for the observation model parameters.

References

emission_path(trace)

Calculate the emission path for a given data trace.

Parameters:

trace (Slice) – Channel data to determine path.

Returns:

emission_path – Estimated emission path

Return type:

Slice

extract_dwell_times(trace, *, exclude_ambiguous_dwells=True)

Calculate lists of dwelltimes for each state in a time-ordered state path array.

Parameters:
  • trace (Slice) – Channel data to be analyzed.

  • exclude_ambiguous_dwells (bool) – Determines whether to exclude dwelltimes which are not exactly determined. If True, the first and last dwells are not used in the analysis, since the exact start/stop times of these events are not definitively known.

Returns:

Dictionary of all dwell times (in seconds) for each state. Keys are state labels.

Return type:

dict

hist(trace, n_bins=100, plot_kwargs=None, hist_kwargs=None)

Plot a histogram of the trace data overlaid with the model state path.

Parameters:
  • trace (Slice) – Data object to histogram.

  • n_bins (int) – Number of histogram bins.

  • plot_kwargs (Optional[dict]) – Plotting keyword arguments passed to the state path line plot.

  • hist_kwargs (Optional[dict]) – Plotting keyword arguments passed to the histogram plot.

plot(trace, *, trace_kwargs=None, label_kwargs=None)

Plot a histogram of the trace data with data points classified in states.

Parameters:
  • trace (Slice) – Data object to histogram.

  • trace_kwargs (Optional[dict]) – Plotting keyword arguments passed to the data line plot.

  • label_kwargs (Optional[dict]) – Plotting keyword arguments passed to the state labels plot.

plot_path(trace, *, trace_kwargs=None, path_kwargs=None)

Plot a histogram of the trace data overlaid with the model path.

Parameters:
  • trace (Slice) – Data object to histogram.

  • trace_kwargs (Optional[dict]) – Plotting keyword arguments passed to the data line plot.

  • path_kwargs (Optional[dict]) – Plotting keyword arguments passed to the path line plot.

state_path(trace)

Calculate the state path for a given data trace.

Parameters:

trace (Slice) – Channel data to determine path.

Returns:

state_path – Estimated state path

Return type:

Slice

property fit_info: PopulationFitInfo

Information about the model training exit conditions.

property initial_state_probability: ndarray

Model initial state probability.

property means: ndarray

Model state means.

property std: ndarray

Model state standard deviations.

property transition_matrix: ndarray

Model state transition matrix.

Element i, j gives the probability of transitioning from state i at time point t to state j at time point t+1.

property variances: ndarray

Model state variances.