markov-chains

Estimate Markov Chain Transition Matrix in MATLAB With Different State Sequence Lengths

感情迁移 提交于 2019-11-29 02:41:25
I'm trying to build the transition matrix for a Markov Chain in MATLAB; I have several different observation sequences (all of varying lengths) and I need to generate the transition matrix using those. Constructing a multi-order Markov chain transition matrix in Matlab shows me how to build a transition matrix with a single observation sequence. How can I construct one using observations of different length? One example can be that one sequence is 1,2,3,4 and another is 4,5,6. Is there any way to do this without having to for loop through all sequences and computing counts? So for Markov

Markov chain stationary distributions with scipy.sparse?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-29 02:40:33
I have a Markov chain given as a large sparse scipy matrix A . (I've constructed the matrix in scipy.sparse.dok_matrix format, but converting to other ones or constructing it as csc_matrix are fine.) I'd like to know any stationary distribution p of this matrix, which is an eigenvector to the eigenvalue 1 . All entries in this eigenvector should be positive and add up to 1, in order to represent a probability distribution. This means I want any solution for the system (A-I) p = 0 , p.sum()=1 (where I=scipy.sparse.eye(*A.shape) is the idententy matrix), but (A-I) will not be of full rank, and

Constructing a multi-order Markov chain transition matrix in Matlab

此生再无相见时 提交于 2019-11-28 23:21:29
问题 A first-order transition matrix of 6 states can be constructed very elegantly as follows x = [1 6 1 6 4 4 4 3 1 2 2 3 4 5 4 5 2 6 2 6 2 6]; % the Markov chain tm = full(sparse(x(1:end-1),x(2:end),1)) % the transition matrix. So here is my problem, how do you construct a second-order transition matrix elegantly? The solution I came up with is as follows [si sj] = ndgrid(1:6); s2 = [si(:) sj(:)]; % combinations for 2 contiguous states tm2 = zeros([numel(si),6]); % initialize transition matrix

R library for discrete Markov chain simulation

孤者浪人 提交于 2019-11-27 20:18:05
I am looking for something like the 'msm' package, but for discrete Markov chains. For example, if I had a transition matrix defined as such Pi <- matrix(c(1/3,1/3,1/3, 0,2/3,1/6, 2/3,0,1/2)) for states A,B,C. How can I simulate a Markov chain according to that transition matrix? Thanks, A while back I wrote a set of functions for simulation and estimation of Discrete Markov Chain probability matrices: http://www.feferraz.net/files/lista/DTMC.R . Relevant code for what you're asking: simula <- function(trans,N) { transita <- function(char,trans) { sample(colnames(trans),1,prob=trans[char,]) }

Estimate Markov Chain Transition Matrix in MATLAB With Different State Sequence Lengths

大憨熊 提交于 2019-11-27 17:00:53
问题 I'm trying to build the transition matrix for a Markov Chain in MATLAB; I have several different observation sequences (all of varying lengths) and I need to generate the transition matrix using those. Constructing a multi-order Markov chain transition matrix in Matlab shows me how to build a transition matrix with a single observation sequence. How can I construct one using observations of different length? One example can be that one sequence is 1,2,3,4 and another is 4,5,6. Is there any

R library for discrete Markov chain simulation

自闭症网瘾萝莉.ら 提交于 2019-11-26 20:16:27
问题 I am looking for something like the 'msm' package, but for discrete Markov chains. For example, if I had a transition matrix defined as such Pi <- matrix(c(1/3,1/3,1/3, 0,2/3,1/6, 2/3,0,1/2)) for states A,B,C. How can I simulate a Markov chain according to that transition matrix? Thanks, 回答1: A while back I wrote a set of functions for simulation and estimation of Discrete Markov Chain probability matrices: http://www.feferraz.net/files/lista/DTMC.R. Relevant code for what you're asking: