0

I want to generate 1000 samples from a distribution in python:

p(x1, ..., xn) = p(x1)p(x2|x1)(x3|x2)...p(xn|xn-1) where xn can take 0or 1

where p(x1=1) = 0.75, p(x_n = 1|x_n-1 = 1)=0.75 and p(x_n = 0|x_n-1 = 0)=0.75 and then count the number of samples out of the 1000 samples that has x2=1, so as to get rough approximation of the p(x2=1)

Had it been a normal distribution, I would have used numpy.random.normal(mean, covariance, no of samples)

How do I implement it?

horchler
  • 18,384
  • 4
  • 37
  • 73
VeilEclipse
  • 2,766
  • 9
  • 35
  • 53
  • This seems simple enough; if you can generate {0,1} with {0.75,0.25} probability, then the rest is just logic. – Oliver Charlesworth Aug 30 '14 at 00:13
  • Are you really looking for p(x2=1), or did you mean to say p(xn=1)? Be that as it may, this is a discrete time, discrete state Markov chain, and the transition probabilities are the same at every step, so the transition matrix p(xk | xj) for any j < k is just A^^(k - j) where A is the transition matrix and A^^m is the m-fold product A . A . A ... A (m times). Be careful, that's not each element raised to the power m. You can get the marginal p(xk = 1) by multiplying A^^(k - 1) . p(x1). – Robert Dodier Aug 30 '14 at 19:50

0 Answers0