MathGroup Archive 2008

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

Search the Archive

Re: Simulate a finite-state markov process

  • To: mathgroup at smc.vnet.net
  • Subject: [mg91892] Re: Simulate a finite-state markov process
  • From: Mark Fisher <particlefilter at gmail.com>
  • Date: Fri, 12 Sep 2008 05:25:57 -0400 (EDT)
  • References: <gaar67$18e$1@smc.vnet.net>

On Sep 11, 6:16 am, edsferr <edsf... at uol.com.br> wrote:
> Dear Mark Fisher,
>
> I've seen a message in comp.soft-sys.math.mathematica :
>
> http://groups.google.com/group/comp.soft-sys.math.mathematica/browse_...
>
> I found it very interesting and tried to develop a similar program
> using the same idea.
>
> The problem is that I'm not that good with programming...
>
> Suppose I have the following Emission matrix:
>
> {{0.470949,0.260239,0.268812},{0.529412,0.470588,0},{0.625,0,0.375},
> {0.722222,0,0.277778},{0.446667,0.24,0.313333},{0.5,0.5,0},
> {0.481301,0.252846,0.265854},{0.471374,0.257634,0.270992},
> {0.47293,0.269108,0.257962},{0.52027,0.239865,0.239865},
> {0.595238,0.214286,0.190476},{0.444444,0.296296,0.259259},
> {0.478528,0.263804,0.257669},{0.507874,0.233071,0.259055},
> {0.434251,0.308869,0.256881},{0.504274,0.262108,0.233618},
> {0.419753,0.320988,0.259259},{0.473684,0.315789,0.210526},
> {0.512012,0.231231,0.256757},{0.5,0.19469,0.30531},
> {0.390244,0.195122,0.414634},{0.510949,0.19708,0.291971},
> {0.464286,0.25,0.285714},{0.285714,0,0.714286}}
>
> The alphabet is {"A","B","C"}
>
> And the following Transition Matrix:
>
> {{0.470949,0,0,0,0,0,0.260239,0,0,0,0,0,0,0.268812,0,0,0,0,0,0,0,0,0,0},
> {0.529412,0,0,0,0,0,0,0.470588,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
> {0.625,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.375,0,0,0,0,0,0,0,0},
> {0.722222,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.277778,0,0,0,0,0,0},
> {0.446667,0,0,0.24,0,0,0,0,0,0,0,0,0,0,0,0.313333,0,0,0,0,0,0,0,0},
> {0.5,0,0,0,0.5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
> {0.481301,0,0,0,0,0,0,0,0.252846,0,0,0,0,0,0.265854,0,0,0,0,0,0,0,0,0},
> {0.471374,0,0,0,0,0,0,0,0,0.257634,0,0,0,0,0,0.270992,0,0,0,0,0,0,0,0},
> {0.47293,0,0,0,0,0,0,0,0,0,0,0,0.269108,0,0,0,0.257962,0,0,0,0,0,0,0},
> {0.52027,0,0,0,0,0,0,0,0,0,0,0,0.239865,0,0,0,0,0.239865,0,0,0,0,0,0},
> {0.595238,0,0,0,0.214286,0.190476,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
> {0.444444,0.259259,0,0,0,0,0,0,0.296296,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
> {0.478528,0,0,0,0,0,0,0,0,0,0.257669,0,0.263804,0,0,0,0,0,0,0,0,0,0,0},
> {0.507874,0,0,0,0,0,0,0.233071,0,0,0,0,0,0,0,0,0,0,0.259055,0,0,0,0,0},
> {0.434251,0,0,0,0,0,0,0.308869,0,0,0,0,0,0,0,0,0,0,0,0.256881,0,0,0,0},
> {0.504274,0,0,0,0,0,0,0.262108,0,0,0,0,0,0,0,0,0,0,0,0,0.233618,0,0,0},
> {0.419753,0,0,0,0.320988,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.259259,0,0,0,0},
> {0.473684,0,0,0,0.315789,0,0,0,0,0,0,0,0,0,0,0,0,0,0.210526,0,0,0,0,0},
> {0.512012,0,0,0,0,0,0,0.231231,0,0,0,0,0,0,0,0,0,0,0,0,0,0.256757,0,0},
> {0.5,0,0,0,0.19469,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.30531,0,0},
> {0.390244,0,0.195122,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.414634,0,0},
> {0.510949,0,0,0,0,0,0,0,0,0,0,0.19708,0,0,0,0,0,0,0,0,0,0,0.291971,0},
> {0.464286,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.285714,0.25},
> {0.285714,0.714286,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}}
>
> How can I develop a program to generate x sequences of a specified
> length?
>
> By the way, does anyone know how to calculate the probability of a
> specific sequence to occur within n generated sequences??
>
> Thank you very much for your attention!
>
> Edson Ferreira

I'm not familiar with "emission matrixes" and "alphabets". But a quick
Google search suggests that the following might be what you're looking
for. First, make sure you have defined the functions randomChoice and
InvariantDistribution (from the message you reference). Next assign
your matrices to the symbols EmissionMatrix and TransitionMatrix.

(* get the starting value for the simulation *)
lambda = InvariantDistribution[TransitionMatrix];
start = randomChoice[lambda -> Range[24]];

(* simulate sequence of hidden states of length 100 *)
hiddenstatesim = NestList[randomChoice[TransitionMatrix[[#]] ->
Range[24]] &, start, 100];

(* simulate observable alphabet *)
alphasim = randomChoice[EmissionMatrix[[#]] -> {"A", "B", "C"}] & /@
hiddenstatesim

One way to compute probabilities is to run simulations and count
outcomes.

--Mark


  • Prev by Date: Re: Simulate a finite-state markov process
  • Next by Date: Re: Text-based interface: Editing line input
  • Previous by thread: Re: Simulate a finite-state markov process
  • Next by thread: Re: Simulate a finite-state markov process