Menu
  • HOME
  • TAGS

Text file probability calculation (Markov Chain) - Python

python,string,count,probability,markov-chains

Two things: This isn't related to Markov Chains. At All. Python actually has some really nice builtins that will make this more or less trivial. I won't spoon-feed an answer, but I don't want to leave you high and dry on this one. The gist is that depending on your...

For Loop error in r

r,for-loop,nested-loops,markov-chains,markov

Your y <- y+1 is in one too many curly brackets. It is not being called most of the time. I think this is what you want: x1 <- runif(100, 1.0, 100) markov <- matrix(c(.5,.3,.2,.4,.5,.1,.2,.4,.4),nrow=3) m1 <- markov[1:3] m2 <- markov[4:6] m3 <- markov[7:9] y <- 2 x <- 1...

Markov Chain Monte Carlo, proposal distribution for multivariate Bernoulli distribution?

machine-learning,statistics,probability,montecarlo,markov-chains

I think I found exactly what I want, which appears in last year's NIPS conference: "Auxiliary-variable Exact Hamiltonian Monte Carlo Samplers for Binary Distributions" Ari Pakman et al. http://www.stat.columbia.edu/~liam/research/pubs/pakman-exact-binary-hmc.pdf...

Random permutation of numbers in MATLAB with weights

matlab,random,weight,markov-chains

Use this transition matrix of your Markov chain: M = 1/9*[2, 3, 2, 2; ... 3, 2, 2, 2; ... 2, 2, 2, 3; ... 3, 2, 2, 2]; with the following algorithm: function realizations = realizeMarkovChain(M, start, numSteps) %// Generates realization of Markov chain given by transition matrix M....

R : function to generate a mixture distribution

r,probability,markov-chains,mcmc,mixture-model

There are of course other ways to do this, but the distr package makes it pretty darned simple. (See also this answer for another example and some more details about distr and friends). library(distr) ## Construct the distribution object. myMix <- UnivarMixingDistribution(Norm(mean=2, sd=8), Cauchy(location=25, scale=2), Norm(mean=10, sd=6), mixCoeff=c(0.4, 0.2, 0.4))...

How do I program bigram as a table in python?

python,list,table,dictionary,markov-chains

Assuming your file has no other punctuation (easy enough to strip out): import itertools def pairwise(s): a,b = itertools.tee(s) next(b) return zip(a,b) counts = [[0 for _ in range(52)] for _ in range(52)] # nothing has occurred yet with open('path/to/input') as infile: for a,b in pairwise(char for line in infile...

Probability of two transitions in Markov Chain

matlab,probability,markov-chains

You code A(S,S)*A(S,C) + A(S,R)*A(R,C) + A(S,C)*A(C,C) (i.e. sum over all possible intermediate states, or Chapman-Kolmogorov equation) is just matrix multiplication: A(S,:)*A(:,C) In general, A2 = A^2 gives the probabilty of all such double transitions, and An = A^n is the probability of n-order transitions (see for example here). So...

R msm package freezing

r,markov-chains

Are you running msm 1.5? In the changelog (http://cran.r-project.org/web/packages/msm/ChangeLog) it is mentioned that a bug has been fixed that led to infinite loops on windows. If your time-series has several short jumps you might get a log-likelihood underflow. You can study this using fixedpars = TRUE in the msm call...

random walk based on previous moves

math,probability,markov-chains,random-walk

Your state has to contain the last position, so that you have transitions (-1,-1) --> (-1,-1) (+1,+1) --> (+1,+1) with 70% probability and (-1,+1) --> (+1,-1) (+1,-1) --> (-1,+1) with 30% probability each....

Python numpy/scipy eigenvectors seemingly not correct for markov chain model

python,numpy,linear-algebra,eigenvector,markov-chains

Is the transition matrix symmetric? If not, consider checking for T.T (the transpose), because you need to make sure you're looking at the right state transitions: you need the left eigenvector of your stochastic matrix, but almost all out-of-the-box scientific packages (numpy included) default to computing the right eigenvectors (this...