MarkovChain

class pycave.bayes.MarkovChain(num_states=None, *, symmetric=False, batch_size=None, trainer_params=None)[source]

Bases: ConfigurableBaseEstimator[MarkovChainModel]

Probabilistic model for observed state transitions. The Markov chain is similar to the hidden Markov model, only that the hidden states are known. More information on the Markov chain is available on Wikipedia.

See also

MarkovChainModel

PyTorch module for a Markov chain.

MarkovChainModelConfig

Configuration class for a Markov chain model.

Parameters:
  • num_states (int | None) -- The number of states that the Markov chain has. If not provided, it will be derived automatically when calling fit(). Note that this requires a pass through the data. Consider setting this option explicitly if you're fitting a lot of data.

  • symmetric (bool) -- Whether the transitions between states should be considered symmetric.

  • batch_size (int | None) -- The batch size to use when fitting the model. If not provided, the full data will be used as a single batch. Set this if the full data does not fit into memory.

  • num_workers -- The number of workers to use for loading the data. Only used if a PyTorch dataset is passed to fit() or related methods.

  • trainer_params (dict[str, Any] | None) --

    Initialization parameters to use when initializing a PyTorch Lightning trainer. By default, it disables various stdout logs unless PyCave is configured to do verbose logging. Checkpointing and logging are disabled regardless of the log level. This estimator further enforces the following parameters:

    • max_epochs=1

Methods

fit

Fits the Markov chain on the provided data and returns the fitted estimator.

sample

Samples state sequences from the fitted Markov chain.

score

Computes the average negative log-likelihood (NLL) of observing the provided sequences.

score_samples

Computes the average negative log-likelihood (NLL) of observing the provided sequences.

Inherited Methods

clone

Clones the estimator without copying any fitted attributes.

get_params

Returns the estimator's parameters as passed to the initializer.

load

Loads the estimator and (if available) the fitted model.

load_attributes

Loads the fitted attributes that are stored at the fitted path.

load_parameters

Initializes this estimator by loading its parameters.

save

Saves the estimator to the provided directory.

save_attributes

Saves the fitted attributes of this estimator.

save_parameters

Saves the parameters of this estimator.

set_params

Sets the provided values on the estimator.

trainer

Returns the trainer as configured by the estimator.

Attributes

persistent_attributes

Returns the list of fitted attributes that ought to be saved and loaded.

model_

The fitted PyTorch module with all estimated parameters.