chainopy.markov_chain¶
Classes
|
A class containing Fundamental Functions for Discrete Time Markov Chains. |
- class chainopy.markov_chain.MarkovChain(p=None, states=None)[source]¶
A class containing Fundamental Functions for Discrete Time Markov Chains.
This class provides a comprehensive suite of methods for working with discrete-time Markov chains (DTMCs), including validation, simulation, and analysis functionalities. It supports learning transition probability matrices (TPMs) from data, checking various properties of the Markov chain (e.g., ergodicity, aperiodicity, symmetry), and computing distributions and probabilities related to the chain’s behavior over time.
- tpm¶
Transition probability matrix (TPM) representing the Markov chain.
- Type:
np.ndarray
- eigenvalues¶
Eigenvalues of the TPM.
- Type:
np.ndarray
- eigenvectors¶
Eigenvectors of the TPM.
- Type:
np.ndarray
- absorption_probabilities()[source]¶
Returns the absorption probabilities matrix for each state.
- Return type:
- Returns:
ndarray: Absorption probabilities matrix.
- eigendecom¶
- eigenvalues¶
- eigenvectors¶
- epsilon¶
- expected_hitting_time(state)[source]¶
Returns the expected hitting time to reach the given absorbing state.
- expected_number_of_visits()[source]¶
Returns the expected number of visits to each state before absorption.
- Return type:
- Returns:
ndarray: Expected number of visits.
- expected_time_to_absorption()[source]¶
Returns the expected time to absorption for each state.
- Return type:
- Returns:
ndarray: Expected time to absorption.
- fit(data, epsilon=1e-16)[source]¶
Learn Transition Matrix from Sequence (list or str) of Data. Each Unique Word is considered a State. It will override the current transition-matrix.
- Parameters:
- Return type:
- Returns:
ndarray: Transition - Matrix based on data
Usage
—– – >>> chainopy.MarkovChain().fit(“My name is John.”)
- is_absorbing()[source]¶
Checks if the Markov chain is absorbing.
- Return type:
- Returns:
bool: True if the Markov chain is absorbing, False otherwise.
- is_aperiodic()[source]¶
Checks if the Markov chain is aperiodic.
- Return type:
- Returns:
bool: True if the Markov chain is aperiodic, False otherwise.
- is_ergodic()[source]¶
Checks if the Markov chain is ergodic.
- Return type:
- Returns:
bool: True if the Markov chain is ergodic, False otherwise.
- is_irreducible()[source]¶
Checks if the Markov chain is irreducible.
- Return type:
- Returns:
bool: True if the Markov chain is irreducible, False otherwise.
- is_symmetric()[source]¶
Checks if the Markov chain is symmetric.
- Return type:
- Returns:
bool: True if the Markov chain is symmetric, False otherwise.
- load_model(path)[source]¶
Load a ChainoPy Model stored as a JSON Object and return as a MarkovChain object.
- Parameters:
path (str) – Path to the file.
Raises:¶
ValueError: If the file cannot be loaded.
- period()[source]¶
Returns the period of the Markov chain.
- Return type:
- Returns:
int: Period of the Markov chain.
- save_model(filename, epsilon=1e-16)[source]¶
Save Model as a JSON Object. If tpm is sparsifyable, it stores tpm as a sparse matrix.
- states¶
- stationary_dist()[source]¶
Returns the stationary distribution of the Markov chain.
- Return type:
- Returns:
ndarray: Stationary distribution.
- tpm¶