Quick Reference
Essential Imports
from stochlab.core import StateSpace, Path, SimulationResult
from stochlab.models import MarkovChain
import numpy as np
Basic Workflow
1. Create State Space
states = StateSpace(["A", "B", "C"])
2. Build Markov Chain
P = np.array([[0.7, 0.2, 0.1],
[0.3, 0.4, 0.3],
[0.1, 0.1, 0.8]])
mc = MarkovChain.from_transition_matrix(["A", "B", "C"], P)
3. Simulate Paths
# Single path
path = mc.sample_path(T=100, x0="A")
# Multiple paths
result = mc.simulate_paths(n_paths=1000, T=100)
4. Analyze Results
# Convert to DataFrame
df = result.to_dataframe()
# State distribution at time t
dist = result.state_distribution(t=50)
# Access individual paths
first_path = result.paths[0]
final_state = first_path[-1]
Key Methods
Class |
Method |
Purpose |
|---|---|---|
|
|
Get index of state |
|
|
Get state at index |
|
|
Generate single trajectory |
|
|
Monte Carlo simulation |
|
|
Get state at time i |
|
|
Convert to pandas DataFrame |
|
|
Empirical distribution |