MathGroup Archive 2003

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: simulating a 2-state Markov process

  • To: mathgroup at smc.vnet.net
  • Subject: [mg41387] Re: [mg41369] simulating a 2-state Markov process
  • From: Bobby Treat <drmajorbob at mailblocks.com>
  • Date: Sat, 17 May 2003 05:49:53 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Here's the initial conditions as a probability vector, where a is the 
probability of starting with Heads.  (In your post, a=1)

initial := {a, 1 - a};

Here's the transition probability matrix:

tpm := {{1 - p, q}, {p, 1 - q}};

After one transition, the probabilities add up to one as expected:

tpm.initial
Simplify@(Plus @@ %)

{a (1-p)+(1-a) q,a p+(1-a) (1-q)}

1

After n transitions, the probability vector is computed by

state[n_Integer] /; n >= 0 := Nest[tpm.# &, initial, n]

or this may work better, if you're not specifying the parameters:

state[n_Integer] /; n >= 0 := Nest[Simplify[tpm.#] &, initial, n]

a, p, and q can be set as desired and state[] is automatically defined 
accordingly, or you can compute state[n]/.{a->1, p->0.1, q->0.3}, for 
instance.

The latter will not work after you have given values to the parameters. 
  The former is much faster, but you may want to see parametric results. 
 Clear[a, p, q] gives you the choice again.

If speed is an issue, you will want to specify p and q, and define the 
state vector after n transitions this way:

p = 0.1; q = 0.3;
Clear[n]
{values, vectors} = Eigensystem[tpm];
fastState[n_Integer] /; n >= 0 =
  Simplify[Transpose[vectors].DiagonalMatrix[values^n].
     Inverse[Transpose[vectors]].initial]

{-0.75*0.6^n + 0.75*1.^n + 1.*0.6^n*a,
  0.7499999999999998*0.6^n +
   0.24999999999999994*1.^n -
   0.9999999999999998*0.6^n*a}

Bobby

-----Original Message-----
From: David E. Burmaster <deb at alceon.com>
To: mathgroup at smc.vnet.net
Subject: [mg41387] [mg41369] simulating a 2-state Markov process

Dear MathGroup,

Can someone please suggest an efficient way to use Mathematica to
draw realizations from a 2-state Markov process as outlined below?

i want to specify the transition probabilities and the number of
transitions to simulate.

=-=

for notation....

1. let's denote the two states as H and T (for Heads and Tails, even
though i am thinking about a process more general than flipping a
coin)

2. let's denote the four conditional transition probabilities as follows

    prob(T | H) = p

    prob(H | H) = 1-p

and

    prob(H | T) = q

    prob(T | T) = 1-q

3. for initial conditions, let the process begin in state H

=-=

within this framework, p and q can take any values in the unit square

	(0, 1] x (0, 1]


=-=-=

thank you for your help
dave



--
************************************

David E. Burmaster, Ph.D.
Alceon Corporation
POBox 382069
Cambridge, MA 02238-2069

617-864-4300

deb at alceon.com
www.alceon.com

************************************


  • Prev by Date: Boundary Conditions for NDSolve
  • Next by Date: Real-time rotations of 3-D plots
  • Previous by thread: simulating a 2-state Markov process
  • Next by thread: Re: simulating a 2-state Markov process