markovmodel / PyEMMA

🚂 Python API for Emma's Markov Model Algorithms 🚂
http://pyemma.org
GNU Lesser General Public License v3.0
311 stars 119 forks source link

Random Walk with emna #1472

Closed toth12 closed 4 years ago

toth12 commented 4 years ago

Hi, I am writing to ask how I could use Pyemma for Random Walks. Say I have a state space with A,B,C and I would like to find the most likely state or states where we will be if we start from B after three steps?

Cheers,

Gabor

clonker commented 4 years ago

You can propagate a state probability vector using the msm api, starting with [0, 1, 0] representing state B.

import numpy as np
import pyemma

# this is your transition matrix
P = np.array([[.4, .3, .3], [.5, 0., .5], [0, .1, .9]])
# create markov state model
msm = pyemma.msm.markov_model(P)
# see how probabilities shift after some steps for state B
for n_steps in range(10):
    print(f"After {n_steps} steps: {msm.propagate([0, 1., 0], n_steps)}")
toth12 commented 4 years ago

thanks, @clonker sorry for the delayed acknowledgement

clonker commented 4 years ago

Not a problem, you are welcome!