Re: Simulate a finite-state markov process

*To*: mathgroup at smc.vnet.net*Subject*: [mg91913] Re: Simulate a finite-state markov process*From*: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>*Date*: Fri, 12 Sep 2008 05:29:56 -0400 (EDT)*Organization*: The Open University, Milton Keynes, UK*References*: <gaar67$18e$1@smc.vnet.net>

edsferr 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_thread/thread/2d5a18a5d7067ca9/066c8a2335605f1f?lnk=gst&q=finite+state#066c8a2335605f1f > > 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 My answer might be irrelevant to your true problem (that I have not grasp), but if you want to apply repeatedly a computation to its previous result, you can use functions of the *Nest* family [1, 2]. For instance, In[1]:= P = {{.9, .1}, {.5, .5}}; x = {1, 0}; Nest[#.P &, x, 5] NestList[#.P &, x, 5] Out[3]= {0.83504, 0.16496} Out[4]= {{1, 0}, {0.9, 0.1}, {0.86, 0.14}, {0.844, 0.156}, {0.8376, 0.1624}, {0.83504, 0.16496}} HTH, - Jean-Marc [1] "Nest" http://reference.wolfram.com/mathematica/ref/Nest.html [2] "Applying Functions Repeatedly", http://reference.wolfram.com/mathematica/tutorial/ApplyingFunctionsRepeatedly.html