(************** Content-type: application/mathematica ************** CreatedBy='Mathematica 5.0' Mathematica-Compatible Notebook This notebook can be used with any Mathematica-compatible application, such as Mathematica, MathReader or Publicon. The data for the notebook starts with the line containing stars above. To get the notebook into a Mathematica-compatible application, do one of the following: * Save the data starting with the line of stars above into a file with a name ending in .nb, then open the file inside the application; * Copy the data starting with the line of stars above to the clipboard, then use the Paste menu command inside the application. Data for notebooks contains only printable 7-bit ASCII and can be sent directly in email or through ftp in text mode. Newlines can be CR, LF or CRLF (Unix, Macintosh or MS-DOS style). NOTE: If you modify the data for this notebook not in a Mathematica- compatible application, you must delete the line below containing the word CacheID, otherwise Mathematica-compatible applications may try to use invalid cache data. For more information on notebooks and Mathematica-compatible applications, contact Wolfram Research: web: http://www.wolfram.com email: info@wolfram.com phone: +1-217-398-0700 (U.S.) Notebook reader applications are available free of charge from Wolfram Research. *******************************************************************) (*CacheID: 232*) (*NotebookFileLineBreakTest NotebookFileLineBreakTest*) (*NotebookOptionsPosition[ 11208, 348]*) (*NotebookOutlinePosition[ 11957, 374]*) (* CellTagsIndexPosition[ 11913, 370]*) (*WindowFrame->Normal*) Notebook[{ Cell[CellGroupData[{ Cell["Markov Chains", "Section"], Cell["\<\ The matrix manipulation for the Markov Chain in #1--the ant moving \ on a wire frame. This MC has a unique steady state distribution.\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{\(Clear[T]\), ";", RowBox[{"T", " ", "=", " ", GridBox[{ {"0", \(1/2\), "0", \(1/3\), \(1/3\)}, {\(1/3\), "0", \(1/3\), "0", "0"}, {"0", \(1/2\), "0", \(1/3\), \(1/3\)}, {\(1/3\), "0", \(1/3\), "0", \(1/3\)}, {\(1/3\), "0", \(1/3\), \(1/3\), "0"} }]}]}]], "Input"], Cell[BoxData[ \({{0, 1\/2, 0, 1\/3, 1\/3}, {1\/3, 0, 1\/3, 0, 0}, {0, 1\/2, 0, 1\/3, 1\/3}, {1\/3, 0, 1\/3, 0, 1\/3}, {1\/3, 0, 1\/3, 1\/3, 0}}\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(Clear[X]; X[0] = {0, \ 0, \ 1, \ 0, \ 0}\)], "Input"], Cell[BoxData[ \({0, 0, 1, 0, 0}\)], "Output"] }, Open ]], Cell[BoxData[ \(X[t_] := MatrixPower[T, \ t] . X[0]\)], "Input"], Cell[CellGroupData[{ Cell[BoxData[ \(X[1]\)], "Input"], Cell[BoxData[ \({0, 1\/3, 0, 1\/3, 1\/3}\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(X[10]\)], "Input"], Cell[BoxData[ \({28927\/118098, 2312\/19683, 28927\/118098, 11593\/59049, 11593\/59049}\)], "Output"] }, Open ]], Cell["\<\ Looking at large powers of T gives us the approximate steady state \ distribution. You can figure it out directly by solving the fixed point \ equation. (Note on the use of MatrixForm below: if you want to do anything \ with the output, don't use MatrixForm. For instance, in the definition of T \ above, it would be a big mistake to use it there...)\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(N[MatrixPower[T, 100]] // MatrixForm\)], "Input"], Cell[BoxData[ TagBox[ RowBox[{"(", "\[NoBreak]", GridBox[{ {"0.21428571438466046`", "0.2142857141627597`", "0.21428571438466046`", "0.21428571422775294`", "0.21428571422775294`"}, {"0.14285714277517314`", "0.14285714295900173`", "0.14285714277517314`", "0.1428571429051596`", "0.1428571429051596`"}, {"0.21428571438466046`", "0.2142857141627597`", "0.21428571438466046`", "0.21428571422775294`", "0.21428571422775294`"}, {"0.21428571422775294`", "0.2142857143577394`", "0.21428571422775294`", "0.21428571431966725`", "0.21428571431966725`"}, {"0.21428571422775294`", "0.2142857143577394`", "0.21428571422775294`", "0.21428571431966725`", "0.21428571431966725`"} }], "\[NoBreak]", ")"}], Function[ BoxForm`e$, MatrixForm[ BoxForm`e$]]]], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(N[X[10]]\)], "Input"], Cell[BoxData[ \({0.24494064251723144`, 0.11746176903927247`, 0.24494064251723144`, 0.1963284729631323`, 0.1963284729631323`}\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(N[X[100]]\)], "Input"], Cell[BoxData[ \({0.21428571438466046`, 0.14285714277517314`, 0.21428571438466046`, 0.21428571422775294`, 0.21428571422775294`}\)], "Output"] }, Open ]], Cell["\<\ Now the matrix manipulation for the Markov chain in #2, the rat in \ a maze. Here you have two absorbing states, so we won't get a unique steady \ state distribution.\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(R = {{1, \ 1/2, \ 1/3, \ 0, \ 0, \ 0}, {0, \ 0, \ 0, \ 1/3, \ 0, \ 0}, {0, \ 0, \ 0, \ 1/3, \ 1/2, \ 0}, {0, \ 1/2, \ 1/3, \ 0, \ 0, \ 0}, {0, \ 0, \ 1/3, \ 0, \ 0, \ 0}, {0, \ 0, \ 0, \ 1/3, \ 1/2, \ 1}}\)], "Input"], Cell[BoxData[ \({{1, 1\/2, 1\/3, 0, 0, 0}, {0, 0, 0, 1\/3, 0, 0}, {0, 0, 0, 1\/3, 1\/2, 0}, {0, 1\/2, 1\/3, 0, 0, 0}, {0, 0, 1\/3, 0, 0, 0}, {0, 0, 0, 1\/3, 1\/2, 1}}\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(Clear[Y]; Y[0] = {0, \ 0, \ 1, \ 0, \ 0, \ 0}\)], "Input"], Cell[BoxData[ \({0, 0, 1, 0, 0, 0}\)], "Output"] }, Open ]], Cell[BoxData[ \(Y[t_] := MatrixPower[R, t] . Y[0]\)], "Input"], Cell[CellGroupData[{ Cell[BoxData[ \(Y[1]\)], "Input"], Cell[BoxData[ \({1\/3, 0, 0, 1\/3, 1\/3, 0}\)], "Output"] }, Open ]], Cell["\<\ Notice that this matrix will never have all positive entries (of \ course this doesn't constitute a proof!). A real proof would be to argue \ that it is never possible to move from room 1 to any other room, thus the \ first column will always be the column vector {1, 0, 0, 0, 0, 0}, etc.\ \>", \ "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(N[MatrixPower[R, 100]] // MatrixForm\)], "Input"], Cell[BoxData[ TagBox[ RowBox[{"(", "\[NoBreak]", GridBox[{ {"1.`", "0.7142857142857143`", "0.5714285714285715`", "0.42857142857142855`", "0.28571428571428575`", "0.`"}, {"0.`", "7.183965204884268`*^-23", "8.730316854783072`*^-23", "0.`", "0.`", "0.`"}, {"0.`", "1.309547528217461`*^-22", "1.591428205966734`*^-22", "0.`", "0.`", "0.`"}, {"0.`", "0.`", "0.`", "1.591428205966734`*^-22", "1.309547528217461`*^-22", "0.`"}, {"0.`", "0.`", "0.`", "8.730316854783072`*^-23", "7.183965204884268`*^-23", "0.`"}, {"0.`", "0.28571428571428575`", "0.42857142857142855`", "0.5714285714285715`", "0.7142857142857143`", "1.`"} }], "\[NoBreak]", ")"}], (MatrixForm[ #]&)]], "Output"] }, Open ]], Cell["\<\ To figure out the absorbtion probabilities, and consider the \ average number of steps until absorbtion, we need to rewrite the transition \ matrix by putting the absorbtion states in the lower right 'block' of the \ matrix. Here, the columns (and rows) are numbered 2, 3, 4, 5, 1, 6 for the \ rooms.\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(Clear[R]; R = {{0, \ 0, \ 1/3, \ 0, \ 0, \ 0}, {0, \ 0, \ 1/3, \ 1/2, \ 0, \ 0}, {1/2, \ 1/3, \ 0, \ 0, \ 0, \ 0}, {0, \ 1/3, \ 0, \ 0, \ 0, \ 0}, {1/2, \ 1/3, \ 0, \ 0, \ 1, \ 0}, {0, \ 0, \ 1/3, \ 1/2, \ 0, \ 1}}\)], "Input"], Cell[BoxData[ \({{0, 0, 1\/3, 0, 0, 0}, {0, 0, 1\/3, 1\/2, 0, 0}, {1\/2, 1\/3, 0, 0, 0, 0}, {0, 1\/3, 0, 0, 0, 0}, {1\/2, 1\/3, 0, 0, 1, 0}, {0, 0, 1\/3, 1\/2, 0, 1}}\)], "Output"] }, Open ]], Cell["\<\ Then the matrix B (see page 126--127) and A become the following:\ \ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(Clear\ [A, B]; A = {{0, \ 0, \ 1/3, \ 0}, {0, \ 0, \ 1/3, \ 1/2}, {1/2, \ 1/3, \ 0, \ 0}, {0, \ 1/3, \ 0, \ 0}}; B = {{1/2, \ 1/3, \ 0, \ 0}, {0, \ 0, \ 1/3, \ 1/2}}\)], "Input"], Cell[BoxData[ \({{1\/2, 1\/3, 0, 0}, {0, 0, 1\/3, 1\/2}}\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(Clear[F]; F = N[Inverse[IdentityMatrix[4] - A]]\)], "Input"], Cell[BoxData[ \({{1.2380952380952381`, 0.19047619047619047`, 0.47619047619047616`, 0.09523809523809523`}, {0.2857142857142857`, 1.4285714285714286`, 0.5714285714285714`, 0.7142857142857143`}, {0.7142857142857143`, 0.5714285714285714`, 1.4285714285714286`, 0.2857142857142857`}, {0.09523809523809523`, 0.47619047619047616`, 0.19047619047619047`, 1.2380952380952381`}}\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(% // MatrixForm\)], "Input"], Cell[BoxData[ TagBox[ RowBox[{"(", "\[NoBreak]", GridBox[{ {"1.2380952380952381`", "0.19047619047619047`", "0.47619047619047616`", "0.09523809523809523`"}, {"0.2857142857142857`", "1.4285714285714286`", "0.5714285714285714`", "0.7142857142857143`"}, {"0.7142857142857143`", "0.5714285714285714`", "1.4285714285714286`", "0.2857142857142857`"}, {"0.09523809523809523`", "0.47619047619047616`", "0.19047619047619047`", "1.2380952380952381`"} }], "\[NoBreak]", ")"}], (MatrixForm[ #]&)]], "Output"] }, Open ]], Cell[TextData[{ "F is called the fundamental matrix. Here are two ways to interpret the \ entries. The entry ", Cell[BoxData[ \(TraditionalForm\`F\_33\)]], "represents the average number of times the rat which starts in room 4 is \ in room 4. The sum of column 4 represents the number of rooms the rat visits \ before hitting room 1 or 6 given that it starts in room 5." }], "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(Clear[L]; L = B . F\ // MatrixForm\)], "Input"], Cell[BoxData[ TagBox[ RowBox[{"(", "\[NoBreak]", GridBox[{ {"0.7142857142857143`", "0.5714285714285714`", "0.42857142857142855`", "0.2857142857142857`"}, {"0.2857142857142857`", "0.42857142857142855`", "0.5714285714285714`", "0.7142857142857143`"} }], "\[NoBreak]", ")"}], (MatrixForm[ #]&)]], "Output"] }, Open ]], Cell[TextData[{ "This is the absorbtion probability matrix. For instance, ", Cell[BoxData[ \(TraditionalForm\`L\_12\)]], " represents the probability that the rat will eventually be absorbed in \ room 1 given it started in room 3.\n\nNotice the wonderful symmetry in all \ these matrices!" }], "Text"] }, Open ]] }, FrontEndVersion->"5.0 for Macintosh", ScreenRectangle->{{0, 1020}, {0, 746}}, ScreenStyleEnvironment->"Presentation", WindowSize->{915, 698}, WindowMargins->{{7, Automatic}, {Automatic, 3}}, PrintingCopies->1, PrintingPageRange->{1, Automatic}, Magnification->1.5 ] (******************************************************************* Cached data follows. If you edit this Notebook file directly, not using Mathematica, you must remove the line containing CacheID at the top of the file. The cache data will then be recreated when you save this file from within Mathematica. *******************************************************************) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[1776, 53, 32, 0, 108, "Section"], Cell[1811, 55, 158, 3, 100, "Text"], Cell[CellGroupData[{ Cell[1994, 62, 369, 8, 174, "Input"], Cell[2366, 72, 179, 3, 210, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[2582, 80, 73, 1, 55, "Input"], Cell[2658, 83, 49, 1, 55, "Output"] }, Open ]], Cell[2722, 87, 68, 1, 55, "Input"], Cell[CellGroupData[{ Cell[2815, 92, 37, 1, 55, "Input"], Cell[2855, 95, 58, 1, 82, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[2950, 101, 38, 1, 55, "Input"], Cell[2991, 104, 112, 2, 82, "Output"] }, Open ]], Cell[3118, 109, 378, 6, 205, "Text"], Cell[CellGroupData[{ Cell[3521, 119, 69, 1, 55, "Input"], Cell[3593, 122, 993, 20, 170, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[4623, 147, 41, 1, 55, "Input"], Cell[4667, 150, 149, 2, 55, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[4853, 157, 42, 1, 55, "Input"], Cell[4898, 160, 151, 2, 55, "Output"] }, Open ]], Cell[5064, 165, 191, 4, 100, "Text"], Cell[CellGroupData[{ Cell[5280, 173, 270, 4, 117, "Input"], Cell[5553, 179, 202, 3, 210, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[5792, 187, 78, 1, 55, "Input"], Cell[5873, 190, 52, 1, 55, "Output"] }, Open ]], Cell[5940, 194, 66, 1, 55, "Input"], Cell[CellGroupData[{ Cell[6031, 199, 37, 1, 55, "Input"], Cell[6071, 202, 61, 1, 82, "Output"] }, Open ]], Cell[6147, 206, 316, 6, 170, "Text"], Cell[CellGroupData[{ Cell[6488, 216, 69, 1, 55, "Input"], Cell[6560, 219, 859, 16, 216, "Output"] }, Open ]], Cell[7434, 238, 326, 6, 129, "Text"], Cell[CellGroupData[{ Cell[7785, 248, 285, 5, 112, "Input"], Cell[8073, 255, 202, 3, 114, "Output"] }, Open ]], Cell[8290, 261, 91, 3, 48, "Text"], Cell[CellGroupData[{ Cell[8406, 268, 219, 4, 112, "Input"], Cell[8628, 274, 74, 1, 63, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[8739, 280, 80, 1, 40, "Input"], Cell[8822, 283, 429, 6, 112, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[9288, 294, 48, 1, 40, "Input"], Cell[9339, 297, 631, 12, 127, "Output"] }, Open ]], Cell[9985, 312, 397, 8, 93, "Text"], Cell[CellGroupData[{ Cell[10407, 324, 68, 1, 40, "Input"], Cell[10478, 327, 385, 8, 79, "Output"] }, Open ]], Cell[10878, 338, 314, 7, 117, "Text"] }, Open ]] } ] *) (******************************************************************* End of Mathematica Notebook file. *******************************************************************)