(* Content-type: application/mathematica *) (*** Wolfram Notebook File ***) (* http://www.wolfram.com/nb *) (* CreatedBy='%s' *) (*CacheID: 234*) (* Internal cache information: NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 131, 6] NotebookDataLength[ 73393, 2361] NotebookOptionsPosition[ 66145, 2117] NotebookOutlinePosition[ 66822, 2146] CellTagsIndexPosition[ 66779, 2143] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell["Simplification of dot products", "Subsection", CellChangeTimes->{3.446230161131838*^9}, ImageRegion->{{0., 1.}, {0., 1.}}], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"ScalarQ", "[", "_List", "]"}], ":=", "False"}], ";"}], "\n", RowBox[{ RowBox[{ RowBox[{"ScalarQ", "[", "_", "]"}], "=", "True"}], ";"}], "\n", RowBox[{ RowBox[{"Unprotect", "[", "Dot", "]"}], ";"}], "\n", RowBox[{ RowBox[{ RowBox[{"a_List", ".", RowBox[{"b_", "?", "ScalarQ"}]}], ":=", RowBox[{"b", " ", "a"}]}], ";"}], "\n", RowBox[{ RowBox[{ RowBox[{ RowBox[{"a_", "?", "ScalarQ"}], ".", "b_List"}], ":=", RowBox[{"a", " ", "b"}]}], ";"}], "\n", RowBox[{ RowBox[{"Protect", "[", "Dot", "]"}], ";"}]}], "Input", ImageRegion->{{0., 1.}, {0., 1.}}], Cell["\<\ The following would not reduce without this modification to the built-in dot \ product.\ \>", "Text", ImageRegion->{{0., 1.}, {0., 1.}}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"1", ".", RowBox[{"{", RowBox[{"a", ",", "b", ",", "c"}], "}"}]}]], "Input", ImageRegion->{{0., 1.}, {0., 1.}}], Cell[BoxData[ RowBox[{"{", RowBox[{"a", ",", "b", ",", "c"}], "}"}]], "Output", CellChangeTimes->{{3.4462271739619093`*^9, 3.4462271865991907`*^9}}, ImageRegion->{{0., 1.}, {0., 1.}}] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell["Polynomial manipulations", "Subsection", CellChangeTimes->{3.4462301662336397`*^9}, ImageRegion->{{0., 1.}, {0., 1.}}], Cell[TextData[{ StyleBox["Mathematica", FontSlant->"Italic"], " makes it quite easy to manipulate polynomials as needed in ARMA \ calculations. For example, the first few terms of the MA representation (the \ psi's) of an AR(2) with coefficients 1.2 and -.5 are the coefficients in the \ polynomial shown here:" }], "Text", CellChangeTimes->{{3.4462287966062*^9, 3.446228798362509*^9}}, ImageRegion->{{0., 1.}, {0., 1.}}], Cell[BoxData[{ RowBox[{"Clear", "[", "phi", "]"}], "\n", RowBox[{ RowBox[{"phi", "[", "z_", "]"}], ":=", RowBox[{"1", "-", RowBox[{"1.2", " ", "z"}], "+", RowBox[{".5", " ", SuperscriptBox["z", "2"]}]}]}]}], "Input", ImageRegion->{{0., 1.}, {0., 1.}}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"Series", "[", RowBox[{ FractionBox["1", RowBox[{"phi", "[", "z", "]"}]], ",", RowBox[{"{", RowBox[{"z", ",", "0", ",", "4"}], "}"}]}], "]"}]], "Input", ImageRegion->{{0., 1.}, {0., 1.}}], Cell[BoxData[ InterpretationBox[ RowBox[{"1", "+", RowBox[{"1.2`", " ", "z"}], "+", RowBox[{"0.94`", " ", SuperscriptBox["z", "2"]}], "+", RowBox[{"0.5279999999999999`", " ", SuperscriptBox["z", "3"]}], "+", RowBox[{"0.16359999999999986`", " ", SuperscriptBox["z", "4"]}], "+", InterpretationBox[ SuperscriptBox[ RowBox[{"O", "[", "z", "]"}], "5"], SeriesData[$CellContext`z, 0, {}, 0, 5, 1], Editable->False]}], SeriesData[$CellContext`z, 0, { 1, 1.2, 0.94, 0.5279999999999999, 0.16359999999999986`}, 0, 5, 1], Editable->False]], "Output", CellChangeTimes->{3.446227217988215*^9}, ImageRegion->{{0., 1.}, {0., 1.}}] }, Open ]], Cell["\<\ By extracting the coefficients from the polynomial, we can then make plots \ and use these coefficients in other problems. (The trailing semicolon \ suppresses the printing of the result.)\ \>", "Text", ImageRegion->{{0., 1.}, {0., 1.}}], Cell[BoxData[ RowBox[{ RowBox[{"psi", "=", RowBox[{"CoefficientList", "[", RowBox[{ RowBox[{"Series", "[", RowBox[{ FractionBox["1", RowBox[{"phi", "[", "z", "]"}]], ",", RowBox[{"{", RowBox[{"z", ",", "0", ",", "25"}], "}"}]}], "]"}], ",", "z"}], "]"}]}], ";"}]], "Input", ImageRegion->{{0., 1.}, {0., 1.}}], Cell["\<\ Plots in MM assume that the input is a list of pairs, not a pair of lists. \ Indexing uses the double brackets (since function arguments are in single \ brackets). The plotting functions offer many options that allow \ customization.\ \>", "Text", ImageRegion->{{0., 1.}, {0., 1.}}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"ListPlot", "[", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"i", "-", "1"}], ",", RowBox[{ "psi", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}]}], "}"}], ",", RowBox[{"{", RowBox[{"i", ",", RowBox[{"Length", "[", "psi", "]"}]}], "}"}]}], "]"}], ",", RowBox[{"Joined", "\[Rule]", "True"}], ",", RowBox[{"PlotRange", "\[Rule]", "All"}], ",", RowBox[{"AxesOrigin", "\[Rule]", RowBox[{"{", RowBox[{"0", ",", "0"}], "}"}]}]}], "]"}]], "Input", CellChangeTimes->{3.446227208703063*^9}, ImageRegion->{{0., 1.}, {0., 1.}}], Cell[BoxData[ GraphicsBox[ {Hue[0.67, 0.6, 0.6], LineBox[CompressedData[" 1:eJxTTMoPSmViYGCQAmIQjQo+2MNoYzD4DOUzOIisc39YJfIOyudw8DbvdEx4 +gDKF3BYInzB5caHI1C+iIPNw+m/KoM37ofwJRw0jsQEbb17BMqXcfBQm+al txXGV3CQ+1eoq3B1D5Sv5LCjWoI7/MRqKF/FYULP2k272JqgfDWHY72P5zd8 nwC1T8NhXfGe+Y/uzoDytRxaYz8s8o+eCuXrOHyfv913ZXIXlK/nUBdnx/d9 XgmUb+DAsO3/yWI/K6j5hg6nd6qwKU3MgPKNHCY/jkjhu5YN5Rs7nPGNKN0s lwrlmzgoXHffynYrDMo3dbhkPjE2yNQSyjdzCFnc/0XxhR7UPnMHacPWgx9U 7aF8C4encutZNi2zhfItHd58KrW7y2hiDwAJAXGk "]]}, AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], Axes->True, AxesOrigin->{0, 0}, PlotRangeClipping->True]], "Output", CellChangeTimes->{{3.4462272122995443`*^9, 3.446227222062798*^9}}, ImageRegion->{{0., 1.}, {0., 1.}}] }, Open ]], Cell["\<\ The convergence of psi_i to zero suggests that the process is stationary, and \ the oscillations suggest that the zeros are complex. Its easy to check both \ of these by solving the equation 0 = psi(z). \ \>", "Text", ImageRegion->{{0., 1.}, {0., 1.}}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"roots", "=", RowBox[{"Solve", "[", RowBox[{"0", "\[Equal]", RowBox[{"phi", "[", "z", "]"}]}], "]"}]}]], "Input", ImageRegion->{{0., 1.}, {0., 1.}}], Cell[BoxData[ RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"z", "\[Rule]", RowBox[{"1.2`", "\[InvisibleSpace]", "-", RowBox[{"0.7483314773547882`", " ", "\[ImaginaryI]"}]}]}], "}"}], ",", RowBox[{"{", RowBox[{"z", "\[Rule]", RowBox[{"1.2`", "\[InvisibleSpace]", "+", RowBox[{"0.7483314773547882`", " ", "\[ImaginaryI]"}]}]}], "}"}]}], "}"}]], "Output", CellChangeTimes->{3.446227229330875*^9}, ImageRegion->{{0., 1.}, {0., 1.}}] }, Open ]], Cell["Both are outside the unit circle.", "Text", ImageRegion->{{0., 1.}, {0., 1.}}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"Abs", "[", RowBox[{"z", "/.", "\[InvisibleSpace]", "roots"}], "]"}]], "Input", ImageRegion->{{0., 1.}, {0., 1.}}], Cell[BoxData[ RowBox[{"{", RowBox[{"1.414213562373095`", ",", "1.414213562373095`"}], "}"}]], "Output",\ CellChangeTimes->{3.446227231470648*^9}, ImageRegion->{{0., 1.}, {0., 1.}}] }, Open ]], Cell["\<\ A rough approximation to the variance of this process is then sigma^2 times\ \>", "Text", ImageRegion->{{0., 1.}, {0., 1.}}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"psi", ".", "psi"}]], "Input", ImageRegion->{{0., 1.}, {0., 1.}}], Cell[BoxData["3.7037036714357847`"], "Output", CellChangeTimes->{3.446227234453558*^9}, ImageRegion->{{0., 1.}, {0., 1.}}] }, Open ]], Cell[TextData[{ "More elaborate manipulations of time series using MM are described in my \ paper which appears in the volume ", StyleBox["Economic Modeling with Mathematica", FontSlant->"Italic"], " (1992, H. Varian, Ed., Springer-Telos)." }], "Text", ImageRegion->{{0., 1.}, {0., 1.}}] }, Closed]], Cell[CellGroupData[{ Cell["Kalman Filter", "Subsection", ImageRegion->{{0., 1.}, {0., 1.}}], Cell["\<\ The following program implements the Kalman filter in a simple (albeit \ inefficient) form. The filter is expressed in \"prediction\" form, giving \ the recursion for \\hat{x}_{t+1|t} in terms of \\hat{x}_{t|-1}, omitting the \ intermediate update step.\ \>", "Text", ImageRegion->{{0., 1.}, {0., 1.}}], Cell["\<\ This small program assumes that the global parameters (F,H,Q,R) are \ externally defined. The arguments x and p are the estimates of x and its \ variance at time t given the information at time t-1. The function updates \ these for the information in y (treated as y_t) and returns estimates of \ x_{t+1|t} and the associated variance.\ \>", "Text", CellChangeTimes->{3.446227268576202*^9}, ImageRegion->{{0., 1.}, {0., 1.}}], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"Clear", "[", "KalmanStep", "]"}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"KalmanStep", "[", RowBox[{"x_", ",", "p_", ",", "y_"}], "]"}], ":=", RowBox[{"Module", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", RowBox[{"X", ",", "P", ",", "K", ",", "\[IndentingNewLine]", RowBox[{"Ht", "=", RowBox[{"Transpose", "[", "H", "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"Ft", "=", RowBox[{"Transpose", "[", "F", "]"}]}]}], "}"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"K", "=", RowBox[{"Simplify", "[", RowBox[{"p", ".", "Ht", ".", RowBox[{"Inverse", "[", RowBox[{ RowBox[{"H", ".", "p", ".", "Ht"}], "+", "R"}], "]"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{"\"\\"", ",", "K"}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"X", "=", RowBox[{"F", ".", RowBox[{"(", RowBox[{"x", " ", "+", " ", RowBox[{"K", ".", RowBox[{"(", RowBox[{"y", "-", RowBox[{"H", ".", "x"}]}], ")"}]}]}], ")"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"P", "=", RowBox[{"Q", "+", RowBox[{"F", ".", RowBox[{"(", RowBox[{"p", "-", RowBox[{"K", ".", "H", ".", "p"}]}], ")"}], ".", "Ft"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"Simplify", "[", RowBox[{"{", RowBox[{"X", ",", "P"}], "}"}], "]"}]}]}], "]"}]}]}], "Input", CellChangeTimes->{{3.446227278668611*^9, 3.446227324356949*^9}, { 3.446227485728074*^9, 3.446227492446827*^9}, {3.4462304662280703`*^9, 3.4462304745982227`*^9}, {3.446231167302985*^9, 3.4462312071700087`*^9}, { 3.4462312777704067`*^9, 3.4462312922336893`*^9}}, ImageRegion->{{0., 1.}, {0., 1.}}] }, Open ]], Cell[CellGroupData[{ Cell["Example", "Subsection", CellChangeTimes->{3.446230172337326*^9}, ImageRegion->{{0., 1.}, {0., 1.}}], Cell["\<\ In each case, the example begins by defining the needed coefficients. The \ sequence of iterations then commences from the initial value of zero.\ \>", "Text", ImageRegion->{{0., 1.}, {0., 1.}}], Cell[CellGroupData[{ Cell["AR(2)", "Subsubsection", ImageRegion->{{0., 1.}, {0., 1.}}], Cell["The vector H is a matrix with one row.", "Text", CellChangeTimes->{{3.446227420243783*^9, 3.4462274277634697`*^9}}, ImageRegion->{{0., 1.}, {0., 1.}}], Cell[BoxData[{ RowBox[{"Clear", "[", RowBox[{"\[Phi]", ",", "varW", ",", "F", ",", "H", ",", "Q", ",", "R"}], "]"}], "\n", RowBox[{ RowBox[{"F", "=", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"0", ",", "1"}], "}"}], ",", RowBox[{"{", RowBox[{ SubscriptBox["\[Phi]", "2"], ",", SubscriptBox["\[Phi]", "1"]}], "}"}]}], "}"}]}], ";"}], "\n", RowBox[{ RowBox[{"H", "=", RowBox[{"{", RowBox[{"{", RowBox[{"1", ",", "0"}], "}"}], "}"}]}], ";"}], "\n", RowBox[{ RowBox[{"Q", "=", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"varW", ",", "0"}], "}"}], ",", RowBox[{"{", RowBox[{"0", ",", "0"}], "}"}]}], "}"}]}], ";"}], "\n", RowBox[{ RowBox[{"R", "=", "0"}], ";"}]}], "Input", CellChangeTimes->{{3.446227382266296*^9, 3.446227415911607*^9}, { 3.446227637412718*^9, 3.446227637596383*^9}, {3.4462276695649242`*^9, 3.446227685074176*^9}}, ImageRegion->{{0., 1.}, {0., 1.}}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"s1", "=", RowBox[{"KalmanStep", "[", RowBox[{ RowBox[{"{", RowBox[{"0", ",", "0"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"g0", ",", "g1"}], "}"}], ",", RowBox[{"{", RowBox[{"g1", ",", "g0"}], "}"}]}], "}"}], ",", "y1"}], "]"}]}]], "Input", ImageRegion->{{0., 1.}, {0., 1.}}], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"Gain K = \"\>", "\[InvisibleSpace]", RowBox[{"{", RowBox[{ RowBox[{"{", "1", "}"}], ",", RowBox[{"{", FractionBox["g1", "g0"], "}"}]}], "}"}]}], SequenceForm["Gain K = ", {{1}, {$CellContext`g0^(-1) $CellContext`g1}}], Editable->False]], "Print", CellChangeTimes->{3.446227353745043*^9, 3.44622738723685*^9}, ImageRegion->{{0., 1.}, {0., 1.}}], Cell[BoxData[ RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"phi1", "+", FractionBox[ RowBox[{"g1", " ", "phi2"}], "g0"]}], ")"}], " ", "y1"}], ",", "y1"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"g0", "-", FractionBox[ SuperscriptBox["g1", "2"], "g0"]}], ")"}], " ", SuperscriptBox["phi2", "2"]}], "+", "varZ"}], ",", "0"}], "}"}], ",", RowBox[{"{", RowBox[{"0", ",", "0"}], "}"}]}], "}"}]}], "}"}]], "Output", CellChangeTimes->{3.446227353761148*^9, 3.446227387244155*^9}, ImageRegion->{{0., 1.}, {0., 1.}}] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"s2", "=", RowBox[{"KalmanStep", "[", RowBox[{ RowBox[{"s1", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}], ",", RowBox[{"s1", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}], ",", "y2"}], "]"}]}]], "Input", ImageRegion->{{0., 1.}, {0., 1.}}], Cell["Gain K = {{1}, {0}}", "Print", ImageRegion->{{0., 1.}, {0., 1.}}], Cell[OutputFormData["\<\ {{phi2*y1 + phi1*y2, y2}, {{varZ, 0}, {0, 0}}}\ \>", "\<\ {{phi2 y1 + phi1 y2, y2}, {{varZ, 0}, {0, 0}}}\ \>"], "Output", ImageRegion->{{0., 1.}, {0., 1.}}] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"s3", "=", RowBox[{"KalmanStep", "[", RowBox[{ RowBox[{"s2", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}], ",", RowBox[{"s2", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}], ",", "y3"}], "]"}]}]], "Input", ImageRegion->{{0., 1.}, {0., 1.}}], Cell["Gain K = {{1}, {0}}", "Print", ImageRegion->{{0., 1.}, {0., 1.}}], Cell[OutputFormData["\<\ {{phi2*y2 + phi1*y3, y3}, {{varZ, 0}, {0, 0}}}\ \>", "\<\ {{phi2 y2 + phi1 y3, y3}, {{varZ, 0}, {0, 0}}}\ \>"], "Output", ImageRegion->{{0., 1.}, {0., 1.}}] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell["ARMA(2,1) - symbolic", "Subsubsection", ImageRegion->{{0., 1.}, {0., 1.}}], Cell["\<\ Note that the first MA coefficient is psi_1= phi_1 + theta_1; the moving \ average term appears in the state-space form only via this expression. This \ term appears in the expression for the variance Q of the state error term. \ Again, there is no error in the observation equation (R=0).\ \>", "Text", ImageRegion->{{0., 1.}, {0., 1.}}], Cell[BoxData[{ RowBox[{"Clear", "[", RowBox[{ "phi1", ",", "phi2", ",", "th1", ",", "varZ", ",", "F", ",", "G", ",", "Q", ",", "R"}], "]"}], "\n", RowBox[{ RowBox[{"F", "=", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"phi1", ",", "phi2"}], "}"}], ",", RowBox[{"{", RowBox[{"1", ",", "0"}], "}"}]}], "}"}]}], ";"}], "\n", RowBox[{ RowBox[{"G", "=", RowBox[{"{", RowBox[{"{", RowBox[{"0", ",", "1"}], "}"}], "}"}]}], ";"}], "\n", RowBox[{ RowBox[{"Q", "=", RowBox[{"varZ", " ", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{ SuperscriptBox["psi1", "2"], ",", "psi1"}], "}"}], ",", RowBox[{"{", RowBox[{"psi1", ",", "1"}], "}"}]}], "}"}]}]}], ";"}], "\n", RowBox[{ RowBox[{"R", "=", "0"}], ";"}]}], "Input", ImageRegion->{{0., 1.}, {0., 1.}}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{ RowBox[{"s1", "=", RowBox[{"KalmanStep", "[", RowBox[{ RowBox[{"{", RowBox[{"0", ",", "0"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"g0", ",", "g1"}], "}"}], ",", RowBox[{"{", RowBox[{"g1", ",", "g0"}], "}"}]}], "}"}], ",", "y1"}], "]"}]}], ";"}]], "Input", ImageRegion->{{0., 1.}, {0., 1.}}], Cell["\<\ g1 Gain K = {{--}, {1}} g0\ \>", "Print", ImageRegion->{{0., 1.}, {0., 1.}}] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{ RowBox[{"s2", "=", RowBox[{"KalmanStep", "[", RowBox[{ RowBox[{"s1", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}], ",", RowBox[{"s1", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}], ",", "y2"}], "]"}]}], ";"}]], "Input", ImageRegion->{{0., 1.}, {0., 1.}}], Cell["\<\ 2 2 g0 phi1 - g1 phi1 + g0 psi1 varZ Gain K = {{----------------------------------}, {1}} 2 2 g0 - g1 + g0 varZ\ \>", "Print", ImageRegion->{{0., 1.}, {0., 1.}}] }, Open ]], Cell["General form.", "Text", ImageRegion->{{0., 1.}, {0., 1.}}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"s", "=", RowBox[{"KalmanStep", "[", RowBox[{ RowBox[{"{", RowBox[{"x1", ",", "x2"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"p11", ",", "p12"}], "}"}], ",", RowBox[{"{", RowBox[{"p12", ",", "p22"}], "}"}]}], "}"}], ",", "y"}], "]"}]}]], "Input", ImageRegion->{{0., 1.}, {0., 1.}}], Cell["\<\ p12 Gain K = {{---}, {1}} p22\ \>", "Print", ImageRegion->{{0., 1.}, {0., 1.}}], Cell[OutputFormData["\<\ {{phi1*x1 - (phi1*p12*x2)/p22 + phi2*y + (phi1*p12*y)/p22, x1 + (p12*(-x2 + y))/p22}, {{phi1^2*(p11 - p12^2/p22) + psi1^2*varZ, phi1*p11 - (phi1*p12^2)/p22 + psi1*varZ}, {phi1*p11 - (phi1*p12^2)/p22 + psi1*varZ, p11 - p12^2/p22 + varZ}}}\ \>", "\<\ phi1 p12 x2 phi1 p12 y {{phi1 x1 - ----------- + phi2 y + ----------, p22 p22 p12 (-x2 + y) x1 + -------------}, p22 2 2 p12 2 {{phi1 (p11 - ----) + psi1 varZ, p22 2 phi1 p12 phi1 p11 - --------- + psi1 varZ}, p22 2 2 phi1 p12 p12 {phi1 p11 - --------- + psi1 varZ, p11 - ---- + varZ}}} p22 p22\ \>"], "Output", ImageRegion->{{0., 1.}, {0., 1.}}] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell["ARMA(2,1) - numeric", "Subsubsection", ImageRegion->{{0., 1.}, {0., 1.}}], Cell[TextData[{ "For getting some numerical results, we need to fill in the details. The \ hard part is to get the initial variance matrix. The state vector in this \ form is ", Cell[BoxData[ FormBox[ RowBox[{"(", RowBox[{ SubscriptBox["y", "t"], ",", " ", SubscriptBox["y", RowBox[{ RowBox[{"t", "+", "1"}], "|", "t"}]]}]}], TraditionalForm]], FormatType->"TraditionalForm"], ") = ", Cell[BoxData[ FormBox[ RowBox[{"(", RowBox[{ SubscriptBox["y", "t"], ",", " ", RowBox[{ SubscriptBox["y", RowBox[{"t", "+", "1"}]], "-", SubscriptBox["w", RowBox[{"t", "+", "1"}]]}]}]}], TraditionalForm]], FormatType->"TraditionalForm"], ") so that its variance/covariance matrix is not that of the process. The \ leading diagonal element is reduced by ", Cell[BoxData[ FormBox[ SuperscriptBox["\[Sigma]", "2"], TraditionalForm]], FormatType->"TraditionalForm"], ". \[Theta] only appears in the variance setup (defining Q). It's not used \ in the observation equation as would be in some of the parameterizations." }], "Text", CellChangeTimes->{{3.446227730157061*^9, 3.4462278767493563`*^9}, { 3.4462288196893883`*^9, 3.44622884838842*^9}}, ImageRegion->{{0., 1.}, {0., 1.}}], Cell[CellGroupData[{ Cell[BoxData[{ RowBox[{"Clear", "[", RowBox[{ "\[Phi]", ",", "\[Theta]", ",", "\[Psi]", ",", "\[Sigma]", ",", "F", ",", "H", ",", "Q", ",", "R"}], "]"}], "\n", RowBox[{ RowBox[{ SubscriptBox["\[Phi]", "1"], "=", "1.2"}], ";"}], "\n", RowBox[{ RowBox[{ SubscriptBox["\[Phi]", "2"], "=", RowBox[{"-", "0.5"}]}], ";"}], "\n", RowBox[{ RowBox[{ SubscriptBox["\[Theta]", "1"], "=", "0.4"}], ";"}], "\n", RowBox[{ RowBox[{ SubscriptBox["\[Psi]", "1"], "=", RowBox[{ SubscriptBox["\[Phi]", "1"], "+", SubscriptBox["\[Theta]", "1"]}]}], ";"}], "\n", RowBox[{ RowBox[{"\[Sigma]", "=", "1"}], ";"}], "\n", RowBox[{ RowBox[{"(", RowBox[{"F", "=", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"0", ",", "1"}], "}"}], ",", RowBox[{"{", RowBox[{ SubscriptBox["\[Phi]", "2"], ",", SubscriptBox["\[Phi]", "1"]}], "}"}]}], "}"}]}], ")"}], "//", "MatrixForm"}], "\n", RowBox[{ RowBox[{"H", "=", RowBox[{"{", RowBox[{"{", RowBox[{"1", ",", "0"}], "}"}], "}"}]}], ";"}], "\n", RowBox[{ RowBox[{"(", RowBox[{"Q", "=", RowBox[{ SuperscriptBox["\[Sigma]", "2"], " ", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"1", ",", SubscriptBox["\[Psi]", "1"]}], "}"}], ",", RowBox[{"{", RowBox[{ SubscriptBox["\[Psi]", "1"], ",", SuperscriptBox[ SubscriptBox["\[Psi]", "1"], "2"]}], "}"}]}], "}"}]}]}], ")"}], " ", "//", " ", "MatrixForm"}], "\n", RowBox[{ RowBox[{"R", "=", "0"}], ";"}]}], "Input", CellChangeTimes->{{3.44622788119433*^9, 3.4462280285143414`*^9}, { 3.446228442773415*^9, 3.446228450492071*^9}, {3.446230592943174*^9, 3.446230613361619*^9}, {3.446230885809066*^9, 3.446230887945733*^9}}, ImageRegion->{{0., 1.}, {0., 1.}}], Cell[BoxData[ TagBox[ RowBox[{"(", "\[NoBreak]", GridBox[{ {"0", "1"}, { RowBox[{"-", "0.5`"}], "1.2`"} }, GridBoxAlignment->{ "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, "Rows" -> {{Baseline}}, "RowsIndexed" -> {}}, GridBoxSpacings->{"Columns" -> { Offset[0.27999999999999997`], { Offset[0.7]}, Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> { Offset[0.2], { Offset[0.4]}, Offset[0.2]}, "RowsIndexed" -> {}}], "\[NoBreak]", ")"}], Function[BoxForm`e$, MatrixForm[BoxForm`e$]]]], "Output", CellChangeTimes->{ 3.446228450847872*^9, {3.446230604447383*^9, 3.446230613732298*^9}, 3.44623078124739*^9, 3.446230888598888*^9, 3.44623135113361*^9}], Cell[BoxData[ TagBox[ RowBox[{"(", "\[NoBreak]", GridBox[{ {"1", "1.6`"}, {"1.6`", "2.5600000000000005`"} }, GridBoxAlignment->{ "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, "Rows" -> {{Baseline}}, "RowsIndexed" -> {}}, GridBoxSpacings->{"Columns" -> { Offset[0.27999999999999997`], { Offset[0.7]}, Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> { Offset[0.2], { Offset[0.4]}, Offset[0.2]}, "RowsIndexed" -> {}}], "\[NoBreak]", ")"}], Function[BoxForm`e$, MatrixForm[BoxForm`e$]]]], "Output", CellChangeTimes->{ 3.446228450847872*^9, {3.446230604447383*^9, 3.446230613732298*^9}, 3.44623078124739*^9, 3.446230888598888*^9, 3.446231351137673*^9}] }, Open ]], Cell["Check that the process as defined is stationary.", "Text", CellChangeTimes->{{3.44622833031028*^9, 3.446228336864162*^9}}], Cell[CellGroupData[{ Cell[BoxData[{ RowBox[{ RowBox[{"rules", " ", "=", RowBox[{"Solve", "[", RowBox[{ RowBox[{ RowBox[{"1", "-", RowBox[{ SubscriptBox["\[Phi]", "1"], "z"}], " ", "-", " ", RowBox[{ SubscriptBox["\[Phi]", "2"], SuperscriptBox["z", "2"]}]}], "\[Equal]", "0"}], ",", "z"}], "]"}]}], " "}], "\[IndentingNewLine]", RowBox[{ RowBox[{"Abs", "[", FractionBox["1", "z"], "]"}], "/.", "rules"}]}], "Input", CellChangeTimes->{{3.446228343556258*^9, 3.4462284214896183`*^9}, { 3.446228468127241*^9, 3.446228472628004*^9}}], Cell[BoxData[ RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"z", "\[Rule]", RowBox[{"1.2`", "\[InvisibleSpace]", "-", RowBox[{"0.7483314773547883`", " ", "\[ImaginaryI]"}]}]}], "}"}], ",", RowBox[{"{", RowBox[{"z", "\[Rule]", RowBox[{"1.2`", "\[InvisibleSpace]", "+", RowBox[{"0.7483314773547883`", " ", "\[ImaginaryI]"}]}]}], "}"}]}], "}"}]], "Output", CellChangeTimes->{{3.446228364032012*^9, 3.446228422263617*^9}, 3.446228473197177*^9}], Cell[BoxData[ RowBox[{"{", RowBox[{"0.7071067811865475`", ",", "0.7071067811865475`"}], "}"}]], "Output", CellChangeTimes->{{3.446228364032012*^9, 3.446228422263617*^9}, 3.446228473200902*^9}] }, Open ]], Cell[TextData[{ "The moduli of the eigenvalues of F match those of the reciprocals of the \ zeros of \[Phi](", StyleBox["z", FontSlant->"Italic"], ") found above." }], "Text", CellChangeTimes->{{3.4462284824348927`*^9, 3.446228510737452*^9}, { 3.446228875066256*^9, 3.446228885345916*^9}}, ImageRegion->{{0., 1.}, {0., 1.}}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"Abs", "[", RowBox[{"Eigenvalues", "[", "F", "]"}], "]"}]], "Input", ImageRegion->{{0., 1.}, {0., 1.}}], Cell[BoxData[ RowBox[{"{", RowBox[{"0.7071067811865476`", ",", "0.7071067811865476`"}], "}"}]], "Output", CellChangeTimes->{3.446228478726709*^9}, ImageRegion->{{0., 1.}, {0., 1.}}] }, Open ]], Cell[TextData[{ "To find the initial covariances, return to the Yule-Walker equations and \ solve three equations in three unknowns, ", Cell[BoxData[ FormBox[ SubscriptBox["\[Gamma]", "0"], TraditionalForm]], FormatType->"TraditionalForm"], ", ", Cell[BoxData[ FormBox[ SubscriptBox["\[Gamma]", "1"], TraditionalForm]], FormatType->"TraditionalForm"], ", and ", Cell[BoxData[ FormBox[ SubscriptBox["\[Gamma]", "2"], TraditionalForm]], FormatType->"TraditionalForm"], " (multiple the ARMA(2,1) process by ", Cell[BoxData[ FormBox[ RowBox[{ SubscriptBox["y", "t"], ",", " ", SubscriptBox["y", RowBox[{"t", "-", "1"}]], ",", " ", RowBox[{ RowBox[{"and", " ", "then", " ", SubscriptBox["y", RowBox[{"t", "-", "2"}]]}], ";"}], " "}], TraditionalForm]], FormatType->"TraditionalForm"], "take expectations.\n ", Cell[BoxData[ FormBox[ SubscriptBox["\[Gamma]", "0"], TraditionalForm]], FormatType->"TraditionalForm"], " - ", Cell[BoxData[ FormBox[ SubscriptBox["\[Phi]", "1"], TraditionalForm]], FormatType->"TraditionalForm"], " ", Cell[BoxData[ FormBox[ SubscriptBox["\[Gamma]", "1"], TraditionalForm]], FormatType->"TraditionalForm"], " - ", Cell[BoxData[ FormBox[ SubscriptBox["\[Phi]", "2"], TraditionalForm]], FormatType->"TraditionalForm"], " ", Cell[BoxData[ FormBox[ SubscriptBox["\[Gamma]", "2"], TraditionalForm]], FormatType->"TraditionalForm"], " = ", Cell[BoxData[ FormBox[ SuperscriptBox["\[Sigma]", "2"], TraditionalForm]], FormatType->"TraditionalForm"], " ", Cell[BoxData[ FormBox[ RowBox[{"(", RowBox[{"1", "+", SubscriptBox["\[Theta]", "1"]}]}], TraditionalForm]], FormatType->"TraditionalForm"], " ", Cell[BoxData[ FormBox[ SubscriptBox["\[Psi]", "1"], TraditionalForm]], FormatType->"TraditionalForm"], ")\n ", Cell[BoxData[ FormBox[ SubscriptBox["\[Gamma]", "1"], TraditionalForm]], FormatType->"TraditionalForm"], " - ", Cell[BoxData[ FormBox[ SubscriptBox["\[Phi]", "1"], TraditionalForm]], FormatType->"TraditionalForm"], " ", Cell[BoxData[ FormBox[ SubscriptBox["\[Gamma]", "0"], TraditionalForm]]], " - ", Cell[BoxData[ FormBox[ SubscriptBox["\[Phi]", "2"], TraditionalForm]]], " ", Cell[BoxData[ FormBox[ SubscriptBox["\[Gamma]", "1"], TraditionalForm]]], " = ", Cell[BoxData[ FormBox[ RowBox[{ SuperscriptBox["\[Sigma]", "2"], SubscriptBox["\[Theta]", "1"]}], TraditionalForm]], FormatType->"TraditionalForm"], "\n ", Cell[BoxData[ FormBox[ SubscriptBox["\[Gamma]", "2"], TraditionalForm]], FormatType->"TraditionalForm"], " - ", Cell[BoxData[ FormBox[ SubscriptBox["\[Phi]", "1"], TraditionalForm]], FormatType->"TraditionalForm"], " ", Cell[BoxData[ FormBox[ SubscriptBox["\[Gamma]", "1"], TraditionalForm]], FormatType->"TraditionalForm"], " - ", Cell[BoxData[ FormBox[ SubscriptBox["\[Phi]", "2"], TraditionalForm]]], " ", Cell[BoxData[ FormBox[ SubscriptBox["\[Gamma]", "0"], TraditionalForm]]], " = 0\nThe solution of these equations in the current model are found next \ (for ", Cell[BoxData[ FormBox[ RowBox[{ RowBox[{ SuperscriptBox["\[Sigma]", "2"], "=", "1"}], ")"}], TraditionalForm]], FormatType->"TraditionalForm"] }], "Text", CellChangeTimes->{{3.446228052387925*^9, 3.4462281951614027`*^9}, { 3.446228897159892*^9, 3.446229018427013*^9}, {3.446229049455452*^9, 3.446229070179595*^9}}, ImageRegion->{{0., 1.}, {0., 1.}}], Cell[CellGroupData[{ Cell[BoxData[{ RowBox[{ RowBox[{"Clear", "[", RowBox[{"g0", ",", "g1", ",", "g2"}], "]"}], ";"}], "\n", RowBox[{"covRules", "=", RowBox[{"Solve", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{ RowBox[{"g0", "-", RowBox[{ SubscriptBox["\[Phi]", "1"], " ", "g1"}], "-", RowBox[{ SubscriptBox["\[Phi]", "2"], " ", "g2"}]}], "\[Equal]", RowBox[{"1", "+", RowBox[{ SubscriptBox["\[Theta]", "1"], " ", SubscriptBox["\[Psi]", "1"]}]}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"g1", "-", RowBox[{ SubscriptBox["\[Phi]", "1"], " ", "g0"}], "-", RowBox[{ SubscriptBox["\[Phi]", "2"], " ", "g1"}]}], "\[Equal]", SubscriptBox["\[Theta]", "1"]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"g2", "-", RowBox[{ SubscriptBox["\[Phi]", "1"], " ", "g1"}], "-", RowBox[{ SubscriptBox["\[Phi]", "2"], " ", "g0"}]}], "\[Equal]", "0"}]}], "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"g0", ",", "g1", ",", "g2"}], "}"}]}], "]"}]}]}], "Input", CellChangeTimes->{{3.4462282099208107`*^9, 3.446228261993675*^9}}, ImageRegion->{{0., 1.}, {0., 1.}}], Cell[BoxData[ RowBox[{"{", RowBox[{"{", RowBox[{ RowBox[{"g0", "\[Rule]", "6.666666666666667`"}], ",", RowBox[{"g1", "\[Rule]", "5.6000000000000005`"}], ",", RowBox[{"g2", "\[Rule]", "3.3866666666666667`"}]}], "}"}], "}"}]], "Output", CellChangeTimes->{3.446228265456697*^9, 3.446230792166774*^9}, ImageRegion->{{0., 1.}, {0., 1.}}] }, Open ]], Cell["\<\ Thus the initial covariance matrix needed to get the ball rolling is (The \ function \"First\" gets rid of an unwanted level of nesting of lists.)\ \>", "Text", CellChangeTimes->{{3.446228284759197*^9, 3.446228288293694*^9}, { 3.446229085024132*^9, 3.446229086352028*^9}}, ImageRegion->{{0., 1.}, {0., 1.}}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{ RowBox[{"(", RowBox[{"Cov0", "=", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"g0", ",", "g1"}], "}"}], ",", RowBox[{"{", RowBox[{"g1", ",", RowBox[{"g0", "-", "1"}]}], "}"}]}], "}"}], "/.", "\[InvisibleSpace]", RowBox[{"First", "[", "covRules", "]"}]}]}], ")"}], "//", "MatrixForm"}]], "Input", CellChangeTimes->{{3.446228297649629*^9, 3.446228319008663*^9}}, ImageRegion->{{0., 1.}, {0., 1.}}], Cell[BoxData[ TagBox[ RowBox[{"(", "\[NoBreak]", GridBox[{ {"6.666666666666667`", "5.6000000000000005`"}, {"5.6000000000000005`", "5.666666666666667`"} }, GridBoxAlignment->{ "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, "Rows" -> {{Baseline}}, "RowsIndexed" -> {}}, GridBoxSpacings->{"Columns" -> { Offset[0.27999999999999997`], { Offset[0.7]}, Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> { Offset[0.2], { Offset[0.4]}, Offset[0.2]}, "RowsIndexed" -> {}}], "\[NoBreak]", ")"}], Function[BoxForm`e$, MatrixForm[BoxForm`e$]]]], "Output", CellChangeTimes->{{3.446228292355517*^9, 3.4462283200868187`*^9}}, ImageRegion->{{0., 1.}, {0., 1.}}] }, Open ]], Cell["\<\ The initial state vector (means at 0) and the initial covariances, bundled \ together.\ \>", "Text", CellChangeTimes->{{3.446228658292128*^9, 3.4462286682393923`*^9}, { 3.446230223442918*^9, 3.446230227803862*^9}}], Cell[BoxData[ RowBox[{ RowBox[{"s0", "=", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"0", ",", "0"}], "}"}], ",", "Cov0"}], "}"}]}], ";"}]], "Input"], Cell[TextData[{ "Here are the first few steps. ", Cell[BoxData[ FormBox[ SubscriptBox["P", RowBox[{"t", "|", RowBox[{"t", "-", "1"}]}]], TraditionalForm]], FormatType->"TraditionalForm"], " stabilizes as the iterations advance." }], "Text", CellChangeTimes->{{3.4462285305274553`*^9, 3.44622854970653*^9}}, ImageRegion->{{0., 1.}, {0., 1.}}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"s1", "=", RowBox[{"KalmanStep", "[", RowBox[{ RowBox[{"s0", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}], ",", RowBox[{"s0", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}], ",", SubscriptBox["y", "1"]}], "]"}]}]], "Input", CellChangeTimes->{{3.446228572109943*^9, 3.4462285743090343`*^9}, { 3.44622864572943*^9, 3.446228686582282*^9}}, ImageRegion->{{0., 1.}, {0., 1.}}], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"Gain K = \"\>", "\[InvisibleSpace]", RowBox[{"{", RowBox[{ RowBox[{"{", "1.`", "}"}], ",", RowBox[{"{", "0.8400000000000001`", "}"}]}], "}"}]}], SequenceForm["Gain K = ", {{1.}, {0.8400000000000001}}], Editable->False]], "Print", CellChangeTimes->{ 3.446230899369419*^9, 3.446231215644321*^9, {3.4462313436989527`*^9, 3.446231361841387*^9}}], Cell[BoxData[ RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"0.8400000000000001`", " ", SubscriptBox["y", "1"]}], ",", RowBox[{"0.508`", " ", SubscriptBox["y", "1"]}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"1.9626666666666663`", ",", "2.7551999999999994`"}], "}"}], ",", RowBox[{"{", RowBox[{"2.7551999999999994`", ",", "3.94624`"}], "}"}]}], "}"}]}], "}"}]], "Output", CellChangeTimes->{{3.4462308934420433`*^9, 3.44623089937322*^9}, 3.446231215650209*^9, {3.446231343705801*^9, 3.446231361845834*^9}}] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"s2", "=", RowBox[{"KalmanStep", "[", RowBox[{ RowBox[{"s1", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}], ",", RowBox[{"s1", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}], ",", SubscriptBox["y", "2"]}], "]"}]}]], "Input", CellChangeTimes->{{3.446228579216277*^9, 3.446228581420455*^9}}, ImageRegion->{{0., 1.}, {0., 1.}}], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"Gain K = \"\>", "\[InvisibleSpace]", RowBox[{"{", RowBox[{ RowBox[{"{", "1.`", "}"}], ",", RowBox[{"{", "1.403804347826087`", "}"}]}], "}"}]}], SequenceForm["Gain K = ", {{1.}, {1.403804347826087}}], Editable->False]], "Print", CellChangeTimes->{3.446228582404708*^9, 3.4462313729448557`*^9}, ImageRegion->{{0., 1.}, {0., 1.}}], Cell[BoxData[ RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{ RowBox[{ RowBox[{"-", "0.6711956521739133`"}], " ", SubscriptBox["y", "1"]}], "+", RowBox[{"1.403804347826087`", " ", SubscriptBox["y", "2"]}]}], ",", RowBox[{ RowBox[{ RowBox[{"-", "0.8054347826086959`"}], " ", SubscriptBox["y", "1"]}], "+", RowBox[{"1.1845652173913044`", " ", SubscriptBox["y", "2"]}]}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"1.0784782608695656`", ",", "1.694173913043479`"}], "}"}], ",", RowBox[{"{", RowBox[{"1.6941739130434788`", ",", "2.6730086956521752`"}], "}"}]}], "}"}]}], "}"}]], "Output", CellChangeTimes->{3.446228582409013*^9, 3.4462313729481163`*^9}, ImageRegion->{{0., 1.}, {0., 1.}}] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"s3", "=", RowBox[{"KalmanStep", "[", RowBox[{ RowBox[{"s2", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}], ",", RowBox[{"s2", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}], ",", SubscriptBox["y", "3"]}], "]"}]}]], "Input", CellChangeTimes->{{3.446228592642111*^9, 3.446228596798773*^9}}, ImageRegion->{{0., 1.}, {0., 1.}}], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"Gain K = \"\>", "\[InvisibleSpace]", RowBox[{"{", RowBox[{ RowBox[{"{", "1.`", "}"}], ",", RowBox[{"{", "1.5708929651279984`", "}"}]}], "}"}]}], SequenceForm["Gain K = ", {{1.}, {1.5708929651279984`}}], Editable->False]], "Print", CellChangeTimes->{3.4462285987104816`*^9, 3.446231396598441*^9}, ImageRegion->{{0., 1.}, {0., 1.}}], Cell[BoxData[ RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{ RowBox[{"0.2489417456158033`", " ", SubscriptBox["y", "1"]}], "-", RowBox[{"1.0206611570247934`", " ", SubscriptBox["y", "2"]}], "+", RowBox[{"1.5708929651279984`", " ", SubscriptBox["y", "3"]}]}], ",", RowBox[{ RowBox[{"0.29873009473896395`", " ", SubscriptBox["y", "1"]}], "-", RowBox[{"1.2247933884297522`", " ", SubscriptBox["y", "2"]}], "+", RowBox[{"1.385071558153598`", " ", SubscriptBox["y", "3"]}]}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"1.011642813948801`", ",", "1.6139713767385613`"}], "}"}], ",", RowBox[{"{", RowBox[{"1.6139713767385613`", ",", "2.576765652086274`"}], "}"}]}], "}"}]}], "}"}]], "Output", CellChangeTimes->{3.446228598714836*^9, 3.446231396602779*^9}, ImageRegion->{{0., 1.}, {0., 1.}}] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"s4", "=", RowBox[{"KalmanStep", "[", RowBox[{ RowBox[{"s3", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}], ",", RowBox[{"s3", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}], ",", SubscriptBox["y", "4"]}], "]"}]}]], "Input", CellChangeTimes->{{3.446228604521421*^9, 3.446228606692246*^9}}, ImageRegion->{{0., 1.}, {0., 1.}}], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"Gain K = \"\>", "\[InvisibleSpace]", RowBox[{"{", RowBox[{ RowBox[{"{", "1.`", "}"}], ",", RowBox[{"{", "1.5953964724354222`", "}"}]}], "}"}]}], SequenceForm["Gain K = ", {{1.}, {1.5953964724354222`}}], Editable->False]], "Print", CellChangeTimes->{3.446228607663164*^9, 3.446231403485865*^9}, ImageRegion->{{0., 1.}, {0., 1.}}], Cell[BoxData[ RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{ RowBox[{ RowBox[{"-", "0.09843068805840482`"}], " ", SubscriptBox["y", "1"]}], "+", RowBox[{"0.4035658210394597`", " ", SubscriptBox["y", "2"]}], "-", RowBox[{"1.121125536985231`", " ", SubscriptBox["y", "3"]}], "+", RowBox[{"1.5953964724354222`", " ", SubscriptBox["y", "4"]}]}], ",", RowBox[{ RowBox[{ RowBox[{"-", "0.11811682567008579`"}], " ", SubscriptBox["y", "1"]}], "+", RowBox[{"0.48427898524735163`", " ", SubscriptBox["y", "2"]}], "-", RowBox[{"1.3453506443822774`", " ", SubscriptBox["y", "3"]}], "+", RowBox[{"1.4144757669225065`", " ", SubscriptBox["y", "4"]}]}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"1.0018414110258314`", ",", "1.6022096932309977`"}], "}"}], ",", RowBox[{"{", RowBox[{"1.6022096932309977`", ",", "2.5626516318771975`"}], "}"}]}], "}"}]}], "}"}]], "Output", CellChangeTimes->{3.446228607709799*^9, 3.446231403490561*^9}, ImageRegion->{{0., 1.}, {0., 1.}}] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"s5", "=", RowBox[{"KalmanStep", "[", RowBox[{ RowBox[{"s4", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}], ",", RowBox[{"s4", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}], ",", SubscriptBox["y", "5"]}], "]"}]}]], "Input", CellChangeTimes->{{3.446228621137124*^9, 3.446228623667832*^9}}, ImageRegion->{{0., 1.}, {0., 1.}}], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"Gain K = \"\>", "\[InvisibleSpace]", RowBox[{"{", RowBox[{ RowBox[{"{", "1.`", "}"}], ",", RowBox[{"{", "1.599264789414546`", "}"}]}], "}"}]}], SequenceForm["Gain K = ", {{1.}, {1.599264789414546}}], Editable->False]], "Print", CellChangeTimes->{3.4462286266058064`*^9, 3.446231405921762*^9}, ImageRegion->{{0., 1.}, {0., 1.}}], Cell[BoxData[ RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{ RowBox[{"0.03929990793956788`", " ", SubscriptBox["y", "1"]}], "-", RowBox[{"0.16112962255222824`", " ", SubscriptBox["y", "2"]}], "+", RowBox[{"0.44762595143167805`", " ", SubscriptBox["y", "3"]}], "-", RowBox[{"1.1369856365996382`", " ", SubscriptBox["y", "4"]}], "+", RowBox[{"1.599264789414546`", " ", SubscriptBox["y", "5"]}]}], ",", RowBox[{ RowBox[{"0.04715988952748145`", " ", SubscriptBox["y", "1"]}], "-", RowBox[{"0.19335554706267388`", " ", SubscriptBox["y", "2"]}], "+", RowBox[{"0.5371511417180136`", " ", SubscriptBox["y", "3"]}], "-", RowBox[{"1.3643827639195658`", " ", SubscriptBox["y", "4"]}], "+", RowBox[{"1.419117747297455`", " ", SubscriptBox["y", "5"]}]}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"1.0002940842341816`", ",", "1.600352901081018`"}], "}"}], ",", RowBox[{"{", RowBox[{"1.600352901081018`", ",", "2.560423481297222`"}], "}"}]}], "}"}]}], "}"}]], "Output", CellChangeTimes->{3.44622862661051*^9, 3.446231405926279*^9}, ImageRegion->{{0., 1.}, {0., 1.}}] }, Open ]], Cell["\<\ With some \"data\" (defined as a set of rules to be used in place of the \ symbols), we can compute the likelihood based on the prior results. The \ sequence of conditional means and variances are\ \>", "Text", CellChangeTimes->{{3.446228704480339*^9, 3.446228717789485*^9}}, ImageRegion->{{0., 1.}, {0., 1.}}], Cell[BoxData[ RowBox[{ RowBox[{"data", "=", RowBox[{"{", RowBox[{ RowBox[{ SubscriptBox["y", "1"], "\[Rule]", "2"}], ",", RowBox[{ SubscriptBox["y", "2"], "\[Rule]", RowBox[{"-", "3"}]}], ",", RowBox[{ SubscriptBox["y", "3"], "\[Rule]", "2"}], ",", RowBox[{ SubscriptBox["y", "4"], "\[Rule]", "1"}], ",", RowBox[{ SubscriptBox["y", "5"], "\[Rule]", RowBox[{"-", "2"}]}]}], "}"}]}], ";"}]], "Input", CellChangeTimes->{{3.4462287206007423`*^9, 3.446228740272263*^9}}, ImageRegion->{{0., 1.}, {0., 1.}}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"condMean", "=", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"s0", "\[LeftDoubleBracket]", RowBox[{"1", ",", "2"}], "\[RightDoubleBracket]"}], ",", RowBox[{"s1", "\[LeftDoubleBracket]", RowBox[{"1", ",", "2"}], "\[RightDoubleBracket]"}], ",", RowBox[{"s2", "\[LeftDoubleBracket]", RowBox[{"1", ",", "2"}], "\[RightDoubleBracket]"}], ",", RowBox[{"s3", "\[LeftDoubleBracket]", RowBox[{"1", ",", "2"}], "\[RightDoubleBracket]"}], ",", RowBox[{"s4", "\[LeftDoubleBracket]", RowBox[{"1", ",", "2"}], "\[RightDoubleBracket]"}], ",", RowBox[{"s5", "\[LeftDoubleBracket]", RowBox[{"1", ",", "2"}], "\[RightDoubleBracket]"}]}], "}"}], "/.", "\[InvisibleSpace]", "data"}]}]], "Input", CellChangeTimes->{{3.4462287590553007`*^9, 3.4462287635240793`*^9}}, ImageRegion->{{0., 1.}, {0., 1.}}], Cell[BoxData[ RowBox[{"{", RowBox[{"0", ",", "1.016`", ",", RowBox[{"-", "5.164565217391305`"}], ",", "7.0419834710743805`", ",", RowBox[{"-", "2.965296128924275`"}], ",", RowBox[{"-", "2.453929554835465`"}]}], "}"}]], "Output", CellChangeTimes->{{3.446228743163479*^9, 3.446228764277555*^9}}, ImageRegion->{{0., 1.}, {0., 1.}}] }, Open ]], Cell["\<\ The variances do not depend upon the data. These can be \"precomputed\" in \ applications.\ \>", "Text", CellChangeTimes->{{3.446229168703047*^9, 3.446229176295092*^9}}, ImageRegion->{{0., 1.}, {0., 1.}}], Cell[CellGroupData[{ Cell[BoxData["s0"], "Input", CellChangeTimes->{{3.4462297767944603`*^9, 3.4462297769070597`*^9}}], Cell[BoxData[ RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"0", ",", "0"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"6.666666666666667`", ",", "5.6000000000000005`"}], "}"}], ",", RowBox[{"{", RowBox[{"5.6000000000000005`", ",", "5.666666666666667`"}], "}"}]}], "}"}]}], "}"}]], "Output", CellChangeTimes->{3.446229777475874*^9}] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"condVar", "=", RowBox[{"{", RowBox[{ RowBox[{"s0", "\[LeftDoubleBracket]", RowBox[{"2", ",", "1", ",", "1"}], "\[RightDoubleBracket]"}], ",", RowBox[{"s1", "\[LeftDoubleBracket]", RowBox[{"2", ",", "1", ",", "1"}], "\[RightDoubleBracket]"}], ",", RowBox[{"s2", "\[LeftDoubleBracket]", RowBox[{"2", ",", "1", ",", "1"}], "\[RightDoubleBracket]"}], ",", RowBox[{"s3", "\[LeftDoubleBracket]", RowBox[{"2", ",", "1", ",", "1"}], "\[RightDoubleBracket]"}], ",", RowBox[{"s4", "\[LeftDoubleBracket]", RowBox[{"2", ",", "1", ",", "1"}], "\[RightDoubleBracket]"}]}], "}"}]}]], "Input", CellChangeTimes->{{3.446229791440895*^9, 3.446229809128364*^9}}, ImageRegion->{{0., 1.}, {0., 1.}}], Cell[BoxData[ RowBox[{"{", RowBox[{ "6.666666666666667`", ",", "1.9626666666666663`", ",", "1.0784782608695656`", ",", "1.011642813948801`", ",", "1.0018414110258314`"}], "}"}]], "Output", CellChangeTimes->{ 3.446228771197057*^9, {3.446229794417844*^9, 3.446229810370038*^9}}, ImageRegion->{{0., 1.}, {0., 1.}}] }, Open ]] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell["Cholesky Factorization", "Subsection", ImageRegion->{{0., 1.}, {0., 1.}}], Cell[TextData[{ "The Cholesky factorization of the covariance matrix of the process offers \ an alternative approach to the calculations of the Kalman filter. The \ calculations are done differently, but are entirely equivalent. First, we \ need the covariance matrix of the data vector ", Cell[BoxData[ FormBox[ SubscriptBox["y", "1"], TraditionalForm]], FormatType->"TraditionalForm"], ",...,", Cell[BoxData[ FormBox[ SubscriptBox["y", "5"], TraditionalForm]], FormatType->"TraditionalForm"], ". The rules simply extend those found above using the AR(2) recursion for \ the remaining covariances." }], "Text", CellChangeTimes->{{3.446229197011607*^9, 3.44622920659015*^9}}, ImageRegion->{{0., 1.}, {0., 1.}}], Cell[CellGroupData[{ Cell[BoxData[{ RowBox[{ RowBox[{"Clear", "[", "g", "]"}], ";"}], "\n", RowBox[{"covRules", "=", RowBox[{"Solve", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{ RowBox[{ RowBox[{"g", "[", "0", "]"}], "-", RowBox[{ SubscriptBox["\[Phi]", "1"], " ", RowBox[{"g", "[", "1", "]"}]}], "-", RowBox[{ SubscriptBox["\[Phi]", "2"], " ", RowBox[{"g", "[", "2", "]"}]}]}], "\[Equal]", RowBox[{"1", "+", RowBox[{ SubscriptBox["\[Theta]", "1"], " ", SubscriptBox["\[Psi]", "1"]}]}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"g", "[", "1", "]"}], "-", RowBox[{ SubscriptBox["\[Phi]", "1"], " ", RowBox[{"g", "[", "0", "]"}]}], "-", RowBox[{ SubscriptBox["\[Phi]", "2"], " ", RowBox[{"g", "[", "1", "]"}]}]}], "\[Equal]", SubscriptBox["\[Theta]", "1"]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"g", "[", "2", "]"}], "-", RowBox[{ SubscriptBox["\[Phi]", "1"], " ", RowBox[{"g", "[", "1", "]"}]}], "-", RowBox[{ SubscriptBox["\[Phi]", "2"], " ", RowBox[{"g", "[", "0", "]"}]}]}], "\[Equal]", "0"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"g", "[", "3", "]"}], "-", RowBox[{ SubscriptBox["\[Phi]", "1"], " ", RowBox[{"g", "[", "2", "]"}]}], "-", RowBox[{ SubscriptBox["\[Phi]", "2"], " ", RowBox[{"g", "[", "1", "]"}]}]}], "\[Equal]", "0"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"g", "[", "4", "]"}], "-", RowBox[{ SubscriptBox["\[Phi]", "1"], " ", RowBox[{"g", "[", "3", "]"}]}], "-", RowBox[{ SubscriptBox["\[Phi]", "2"], " ", RowBox[{"g", "[", "2", "]"}]}]}], "\[Equal]", "0"}]}], "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{ RowBox[{"g", "[", "0", "]"}], ",", RowBox[{"g", "[", "1", "]"}], ",", RowBox[{"g", "[", "2", "]"}], ",", RowBox[{"g", "[", "3", "]"}], ",", RowBox[{"g", "[", "4", "]"}]}], "}"}]}], "]"}]}]}], "Input", CellChangeTimes->{{3.4462292140177317`*^9, 3.446229289332243*^9}}, ImageRegion->{{0., 1.}, {0., 1.}}], Cell[BoxData[ RowBox[{"{", RowBox[{"{", RowBox[{ RowBox[{ RowBox[{"g", "[", "0", "]"}], "\[Rule]", "6.666666666666667`"}], ",", RowBox[{ RowBox[{"g", "[", "1", "]"}], "\[Rule]", "5.6000000000000005`"}], ",", RowBox[{ RowBox[{"g", "[", "2", "]"}], "\[Rule]", "3.3866666666666667`"}], ",", RowBox[{ RowBox[{"g", "[", "3", "]"}], "\[Rule]", "1.2639999999999996`"}], ",", RowBox[{ RowBox[{"g", "[", "4", "]"}], "\[Rule]", RowBox[{"-", "0.17653333333333396`"}]}]}], "}"}], "}"}]], "Output", CellChangeTimes->{3.4462292960541553`*^9}, ImageRegion->{{0., 1.}, {0., 1.}}] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{ RowBox[{"(", RowBox[{"covMat", "=", RowBox[{"First", "[", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{"g", "[", RowBox[{"Abs", "[", RowBox[{"j", "-", "k"}], "]"}], "]"}], ",", RowBox[{"{", RowBox[{"j", ",", "5"}], "}"}], ",", RowBox[{"{", RowBox[{"k", ",", "5"}], "}"}]}], "]"}], "/.", "\[InvisibleSpace]", "covRules"}], "]"}]}], ")"}], "//", "MatrixForm", " "}]], "Input", CellChangeTimes->{{3.446229311863693*^9, 3.446229408990221*^9}}, ImageRegion->{{0., 1.}, {0., 1.}}], Cell[BoxData[ TagBox[ RowBox[{"(", "\[NoBreak]", GridBox[{ {"6.666666666666667`", "5.6000000000000005`", "3.3866666666666667`", "1.2639999999999996`", RowBox[{"-", "0.17653333333333396`"}]}, {"5.6000000000000005`", "6.666666666666667`", "5.6000000000000005`", "3.3866666666666667`", "1.2639999999999996`"}, {"3.3866666666666667`", "5.6000000000000005`", "6.666666666666667`", "5.6000000000000005`", "3.3866666666666667`"}, {"1.2639999999999996`", "3.3866666666666667`", "5.6000000000000005`", "6.666666666666667`", "5.6000000000000005`"}, { RowBox[{"-", "0.17653333333333396`"}], "1.2639999999999996`", "3.3866666666666667`", "5.6000000000000005`", "6.666666666666667`"} }, GridBoxAlignment->{ "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, "Rows" -> {{Baseline}}, "RowsIndexed" -> {}}, GridBoxSpacings->{"Columns" -> { Offset[0.27999999999999997`], { Offset[0.7]}, Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> { Offset[0.2], { Offset[0.4]}, Offset[0.2]}, "RowsIndexed" -> {}}], "\[NoBreak]", ")"}], Function[BoxForm`e$, MatrixForm[BoxForm`e$]]]], "Output", CellChangeTimes->{{3.446229333842942*^9, 3.446229409407804*^9}}] }, Open ]], Cell[TextData[{ " As implemented in ", StyleBox["Mathematica", FontSlant->"Italic"], ", the Cholesky factorization gives the upper triagular matrix." }], "Text", CellChangeTimes->{{3.4462294365191193`*^9, 3.446229452612805*^9}}, ImageRegion->{{0., 1.}, {0., 1.}}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{ RowBox[{"(", RowBox[{"U", "=", RowBox[{"CholeskyDecomposition", "[", "covMat", "]"}]}], ")"}], "//", "MatrixForm"}]], "Input", CellChangeTimes->{{3.44622946293447*^9, 3.446229469006295*^9}}, ImageRegion->{{0., 1.}, {0., 1.}}], Cell[BoxData[ TagBox[ RowBox[{"(", "\[NoBreak]", GridBox[{ {"2.581988897471611`", "2.1688706738761536`", "1.3116503599155787`", "0.4895450949606173`", RowBox[{"-", "0.06837106600504851`"}]}, {"0.`", "1.4009520572334608`", "1.9666625890402338`", "1.6595190782315503`", "1.0080915993577433`"}, {"0.`", "0.`", "1.0384980793769258`", "1.6313693271921519`", "1.4383941529421191`"}, {"0.`", "0.`", "0.`", "1.0058045605130244`", "1.604657047801942`"}, {"0.`", "0.`", "0.`", "0.`", "1.0009202820533847`"} }, GridBoxAlignment->{ "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, "Rows" -> {{Baseline}}, "RowsIndexed" -> {}}, GridBoxSpacings->{"Columns" -> { Offset[0.27999999999999997`], { Offset[0.7]}, Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> { Offset[0.2], { Offset[0.4]}, Offset[0.2]}, "RowsIndexed" -> {}}], "\[NoBreak]", ")"}], Function[BoxForm`e$, MatrixForm[BoxForm`e$]]]], "Output", CellChangeTimes->{3.446229469786955*^9}, ImageRegion->{{0., 1.}, {0., 1.}}] }, Open ]], Cell["\<\ Indeed, it does give the \"square root\" of the covariance matrix.\ \>", "Text", ImageRegion->{{0., 1.}, {0., 1.}}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"Round", "[", RowBox[{"1000", " ", RowBox[{"(", RowBox[{"covMat", "-", RowBox[{ RowBox[{"Transpose", "[", "U", "]"}], ".", "U"}]}], ")"}]}], "]"}]], "Input", CellChangeTimes->{{3.446229477832223*^9, 3.446229480286765*^9}}, ImageRegion->{{0., 1.}, {0., 1.}}], Cell[BoxData[ RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"0", ",", "0", ",", "0", ",", "0", ",", "0"}], "}"}], ",", RowBox[{"{", RowBox[{"0", ",", "0", ",", "0", ",", "0", ",", "0"}], "}"}], ",", RowBox[{"{", RowBox[{"0", ",", "0", ",", "0", ",", "0", ",", "0"}], "}"}], ",", RowBox[{"{", RowBox[{"0", ",", "0", ",", "0", ",", "0", ",", "0"}], "}"}], ",", RowBox[{"{", RowBox[{"0", ",", "0", ",", "0", ",", "0", ",", "0"}], "}"}]}], "}"}]], "Output", CellChangeTimes->{3.4462294808675823`*^9}, ImageRegion->{{0., 1.}, {0., 1.}}] }, Open ]], Cell[TextData[{ "In order to see how the Cholesky factorization compares to the Kalman \ filter, we need to modify this version of the factorization to one that \ obtains C = U'DU where U has 1's along its diagonals.\n\nExtract the diagonal \ of U using the transpose function. (", StyleBox["Mathematica", FontSlant->"Italic"], "'s notation is not always very intuitive.)" }], "Text", CellChangeTimes->{{3.446229498734375*^9, 3.446229532045497*^9}}, ImageRegion->{{0., 1.}, {0., 1.}}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"diag", "=", RowBox[{"Transpose", "[", RowBox[{"U", ",", RowBox[{"{", RowBox[{"1", ",", "1"}], "}"}]}], "]"}]}]], "Input", ImageRegion->{{0., 1.}, {0., 1.}}], Cell[BoxData[ RowBox[{"{", RowBox[{ "2.581988897471611`", ",", "1.4009520572334608`", ",", "1.0384980793769258`", ",", "1.0058045605130244`", ",", "1.0009202820533847`"}], "}"}]], "Output", CellChangeTimes->{3.446229523776367*^9}, ImageRegion->{{0., 1.}, {0., 1.}}] }, Open ]], Cell["\<\ These diagonal values are the same as the conditional variances of the \ one-step ahead errors computed via the Kalman filter.\ \>", "Text", ImageRegion->{{0., 1.}, {0., 1.}}], Cell[CellGroupData[{ Cell[BoxData[ SqrtBox["condVar"]], "Input", ImageRegion->{{0., 1.}, {0., 1.}}], Cell[BoxData[ RowBox[{"{", RowBox[{ "2.581988897471611`", ",", "1.4009520572334608`", ",", "1.0384980793769267`", ",", "1.0058045605130257`", ",", "1.0009202820533867`"}], "}"}]], "Output", CellChangeTimes->{3.446229544890771*^9, 3.4462298331886683`*^9}, ImageRegion->{{0., 1.}, {0., 1.}}] }, Open ]], Cell["\<\ Now we can continue by building the associated diagonal matrix and factor out \ these diagonal values from U, leaving a matrix with 1's along the diagonal.\ \>", "Text", CellChangeTimes->{3.446229580302623*^9}, ImageRegion->{{0., 1.}, {0., 1.}}], Cell[BoxData[ RowBox[{ RowBox[{"d", "=", RowBox[{"DiagonalMatrix", "[", "diag", "]"}]}], ";"}]], "Input", CellChangeTimes->{{3.4462298488335333`*^9, 3.446229908725247*^9}}, ImageRegion->{{0., 1.}, {0., 1.}}], Cell[BoxData[ RowBox[{ RowBox[{"u", "=", RowBox[{ RowBox[{"Inverse", "[", "d", "]"}], ".", "U"}]}], ";"}]], "Input", ImageRegion->{{0., 1.}, {0., 1.}}], Cell["\<\ Hence the covariance matrix is the matrix u'dd u, implying that Var \ (u'd)^{-1} Y = I.\ \>", "Text", ImageRegion->{{0., 1.}, {0., 1.}}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"Transpose", "[", "u", "]"}], ".", "d", ".", "d", ".", "u"}], ")"}], " ", "//", " ", "MatrixForm"}]], "Input", CellChangeTimes->{{3.4462299359603024`*^9, 3.446229945660761*^9}}, ImageRegion->{{0., 1.}, {0., 1.}}], Cell[BoxData[ TagBox[ RowBox[{"(", "\[NoBreak]", GridBox[{ {"6.666666666666666`", "5.6`", "3.386666666666667`", "1.2639999999999993`", RowBox[{"-", "0.17653333333333396`"}]}, {"5.6000000000000005`", "6.666666666666667`", "5.600000000000001`", "3.3866666666666676`", "1.2639999999999996`"}, {"3.3866666666666676`", "5.600000000000001`", "6.666666666666667`", "5.600000000000001`", "3.3866666666666667`"}, {"1.2639999999999996`", "3.3866666666666676`", "5.600000000000001`", "6.666666666666668`", "5.600000000000001`"}, { RowBox[{"-", "0.17653333333333396`"}], "1.2639999999999998`", "3.3866666666666667`", "5.600000000000001`", "6.666666666666667`"} }, GridBoxAlignment->{ "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, "Rows" -> {{Baseline}}, "RowsIndexed" -> {}}, GridBoxSpacings->{"Columns" -> { Offset[0.27999999999999997`], { Offset[0.7]}, Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> { Offset[0.2], { Offset[0.4]}, Offset[0.2]}, "RowsIndexed" -> {}}], "\[NoBreak]", ")"}], Function[BoxForm`e$, MatrixForm[BoxForm`e$]]]], "Output", CellChangeTimes->{{3.446229931692441*^9, 3.446229946073958*^9}}, ImageRegion->{{0., 1.}, {0., 1.}}] }, Open ]], Cell["Here is the inverse of the normalized factor u'.", "Text", ImageRegion->{{0., 1.}, {0., 1.}}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"Inverse", "[", RowBox[{"Transpose", "[", "u", "]"}], "]"}], ")"}], "//", "Chop"}], " ", "//", "MatrixForm"}]], "Input", CellChangeTimes->{{3.446229954815588*^9, 3.4462299715341063`*^9}}, ImageRegion->{{0., 1.}, {0., 1.}}], Cell[BoxData[ TagBox[ RowBox[{"(", "\[NoBreak]", GridBox[{ {"1.`", "0", "0", "0", "0"}, { RowBox[{"-", "0.8400000000000001`"}], "1.`", "0", "0", "0"}, {"0.6711956521739134`", RowBox[{"-", "1.4038043478260873`"}], "1.`", "0", "0"}, { RowBox[{"-", "0.24894174561580373`"}], "1.020661157024795`", RowBox[{"-", "1.5708929651279997`"}], "1.`", "0"}, {"0.09843068805840549`", RowBox[{"-", "0.4035658210394631`"}], "1.121125536985236`", RowBox[{"-", "1.5953964724354248`"}], "1.`"} }, GridBoxAlignment->{ "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, "Rows" -> {{Baseline}}, "RowsIndexed" -> {}}, GridBoxSpacings->{"Columns" -> { Offset[0.27999999999999997`], { Offset[0.7]}, Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> { Offset[0.2], { Offset[0.4]}, Offset[0.2]}, "RowsIndexed" -> {}}], "\[NoBreak]", ")"}], Function[BoxForm`e$, MatrixForm[BoxForm`e$]]]], "Output", CellChangeTimes->{{3.4462299652861643`*^9, 3.446229972083537*^9}}, ImageRegion->{{0., 1.}, {0., 1.}}] }, Open ]], Cell["\<\ Comparing these rows to the innovations computed in the Kalman filter shows \ that these two methods are in fact one in the same. The signs are reversed \ since in the Kalman filter, the linear combinations shown below are the \ conditional means which are to be subtracted from the next observations.\ \>", "Text", ImageRegion->{{0., 1.}, {0., 1.}}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"{", RowBox[{ RowBox[{"s0", "\[LeftDoubleBracket]", RowBox[{"1", ",", "2"}], "\[RightDoubleBracket]"}], ",", RowBox[{"s1", "\[LeftDoubleBracket]", RowBox[{"1", ",", "2"}], "\[RightDoubleBracket]"}], ",", RowBox[{"s2", "\[LeftDoubleBracket]", RowBox[{"1", ",", "2"}], "\[RightDoubleBracket]"}], ",", RowBox[{"s3", "\[LeftDoubleBracket]", RowBox[{"1", ",", "2"}], "\[RightDoubleBracket]"}], ",", RowBox[{"s4", "\[LeftDoubleBracket]", RowBox[{"1", ",", "2"}], "\[RightDoubleBracket]"}]}], "}"}]], "Input", CellChangeTimes->{{3.446229995686887*^9, 3.446230003311499*^9}}, ImageRegion->{{0., 1.}, {0., 1.}}], Cell[BoxData[ RowBox[{"{", RowBox[{"0", ",", RowBox[{"0.`", "\[InvisibleSpace]", "+", RowBox[{"0.508`", " ", SubscriptBox["y", "1"]}]}], ",", RowBox[{"0.`", "\[InvisibleSpace]", "-", RowBox[{"0.8054347826086958`", " ", SubscriptBox["y", "1"]}], "+", RowBox[{"1.1845652173913044`", " ", SubscriptBox["y", "2"]}]}], ",", RowBox[{"0.`", "\[InvisibleSpace]", "+", RowBox[{"0.29873009473896417`", " ", SubscriptBox["y", "1"]}], "-", RowBox[{"1.2247933884297522`", " ", SubscriptBox["y", "2"]}], "+", RowBox[{"1.385071558153598`", " ", SubscriptBox["y", "3"]}]}], ",", RowBox[{"0.`", "\[InvisibleSpace]", "-", RowBox[{"0.1181168256700858`", " ", SubscriptBox["y", "1"]}], "+", RowBox[{"0.4842789852473516`", " ", SubscriptBox["y", "2"]}], "-", RowBox[{"1.3453506443822776`", " ", SubscriptBox["y", "3"]}], "+", RowBox[{"1.4144757669225065`", " ", SubscriptBox["y", "4"]}]}]}], "}"}]], "Output", CellChangeTimes->{{3.4462299917547626`*^9, 3.4462299962658997`*^9}}, ImageRegion->{{0., 1.}, {0., 1.}}] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"s1", "\[LeftDoubleBracket]", RowBox[{"1", ",", "1"}], "\[RightDoubleBracket]"}], ",", RowBox[{"s2", "\[LeftDoubleBracket]", RowBox[{"1", ",", "1"}], "\[RightDoubleBracket]"}], ",", RowBox[{"s3", "\[LeftDoubleBracket]", RowBox[{"1", ",", "1"}], "\[RightDoubleBracket]"}], ",", RowBox[{"s4", "\[LeftDoubleBracket]", RowBox[{"1", ",", "1"}], "\[RightDoubleBracket]"}]}], "}"}], "//", "TableForm"}]], "Input", CellChangeTimes->{{3.446230009384192*^9, 3.446230045903262*^9}, { 3.446230087187171*^9, 3.446230143549996*^9}}], Cell[BoxData[ TagBox[ TagBox[GridBox[{ { RowBox[{"0.8400000000000001`", " ", SubscriptBox["y", "1"]}]}, { RowBox[{ RowBox[{ RowBox[{"-", "0.6711956521739133`"}], " ", SubscriptBox["y", "1"]}], "+", RowBox[{"1.403804347826087`", " ", SubscriptBox["y", "2"]}]}]}, { RowBox[{ RowBox[{"0.2489417456158033`", " ", SubscriptBox["y", "1"]}], "-", RowBox[{"1.0206611570247934`", " ", SubscriptBox["y", "2"]}], "+", RowBox[{"1.5708929651279984`", " ", SubscriptBox["y", "3"]}]}]}, { RowBox[{ RowBox[{ RowBox[{"-", "0.09843068805840482`"}], " ", SubscriptBox["y", "1"]}], "+", RowBox[{"0.4035658210394597`", " ", SubscriptBox["y", "2"]}], "-", RowBox[{"1.121125536985231`", " ", SubscriptBox["y", "3"]}], "+", RowBox[{"1.5953964724354222`", " ", SubscriptBox["y", "4"]}]}]} }, GridBoxAlignment->{ "Columns" -> {{Left}}, "ColumnsIndexed" -> {}, "Rows" -> {{Baseline}}, "RowsIndexed" -> {}}, GridBoxSpacings->{"Columns" -> { Offset[0.27999999999999997`], { Offset[0.5599999999999999]}, Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> { Offset[0.2], { Offset[0.4]}, Offset[0.2]}, "RowsIndexed" -> {}}], Column], Function[BoxForm`e$, TableForm[BoxForm`e$]]]], "Output", CellChangeTimes->{{3.446230034209415*^9, 3.446230048265402*^9}, { 3.446230093750486*^9, 3.4462301441967783`*^9}, 3.446231605435234*^9}] }, Open ]] }, WindowToolbars->{}, CellGrouping->Manual, WindowSize->{921, 1045}, WindowMargins->{{32, Automatic}, {47, Automatic}}, ShowSelection->True, Evaluatable->False, CellHorizontalScrolling->False, PageBreakWithin->Automatic, ShowCellLabel->True, ShowCellTags->False, AspectRatioFixed->True, RenderingOptions->{"ObjectDithering"->True, "RasterDithering"->False}, FontFamily->"Times", FontSize->12, Magnification->1.25, FrontEndVersion->"7.0 for Mac OS X x86 (32-bit) (February 18, 2009)", StyleDefinitions->"Default.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[553, 21, 130, 2, 42, "Subsection"], Cell[686, 25, 642, 21, 129, "Input"], Cell[1331, 48, 147, 4, 32, "Text"], Cell[CellGroupData[{ Cell[1503, 56, 142, 4, 33, "Input"], Cell[1648, 62, 189, 4, 33, "Output"] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell[1886, 72, 126, 2, 31, "Subsection"], Cell[2015, 76, 429, 9, 70, "Text"], Cell[2447, 87, 273, 8, 58, "Input"], Cell[CellGroupData[{ Cell[2745, 99, 231, 7, 59, "Input"], Cell[2979, 108, 680, 19, 38, "Output"] }, Open ]], Cell[3674, 130, 249, 5, 51, "Text"], Cell[3926, 137, 371, 12, 59, "Input"], Cell[4300, 151, 295, 6, 51, "Text"], Cell[CellGroupData[{ Cell[4620, 161, 670, 20, 53, "Input"], Cell[5293, 183, 735, 16, 289, "Output"] }, Open ]], Cell[6043, 202, 266, 5, 51, "Text"], Cell[CellGroupData[{ Cell[6334, 211, 184, 5, 33, "Input"], Cell[6521, 218, 478, 13, 33, "Output"] }, Open ]], Cell[7014, 234, 85, 1, 32, "Text"], Cell[CellGroupData[{ Cell[7124, 239, 141, 3, 33, "Input"], Cell[7268, 244, 187, 5, 33, "Output"] }, Open ]], Cell[7470, 252, 135, 3, 32, "Text"], Cell[CellGroupData[{ Cell[7630, 259, 89, 2, 33, "Input"], Cell[7722, 263, 124, 2, 33, "Output"] }, Open ]], Cell[7861, 268, 293, 7, 51, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[8191, 280, 71, 1, 31, "Subsection"], Cell[8265, 283, 314, 6, 51, "Text"], Cell[8582, 291, 439, 8, 70, "Text"], Cell[9024, 301, 1926, 51, 224, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[10987, 357, 107, 2, 42, "Subsection"], Cell[11097, 361, 206, 4, 51, "Text"], Cell[CellGroupData[{ Cell[11328, 369, 66, 1, 30, "Subsubsection"], Cell[11397, 372, 158, 2, 32, "Text"], Cell[11558, 376, 992, 32, 110, "Input"], Cell[CellGroupData[{ Cell[12575, 412, 378, 13, 33, "Input"], Cell[12956, 427, 425, 11, 48, "Print"], Cell[13384, 440, 753, 25, 63, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[14174, 470, 303, 7, 33, "Input"], Cell[14480, 479, 72, 1, 25, "Print"], Cell[14555, 482, 182, 5, 38, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[14774, 492, 303, 7, 33, "Input"], Cell[15080, 501, 72, 1, 25, "Print"], Cell[15155, 504, 182, 5, 38, "Output"] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell[15386, 515, 81, 1, 21, "Subsubsection"], Cell[15470, 518, 352, 6, 108, "Text"], Cell[15825, 526, 864, 30, 108, "Input"], Cell[CellGroupData[{ Cell[16714, 560, 405, 14, 108, "Input"], Cell[17122, 576, 109, 5, 108, "Print"] }, Open ]], Cell[CellGroupData[{ Cell[17268, 586, 332, 9, 108, "Input"], Cell[17603, 597, 251, 7, 108, "Print"] }, Open ]], Cell[17869, 607, 65, 1, 108, "Text"], Cell[CellGroupData[{ Cell[17959, 612, 382, 13, 108, "Input"], Cell[18344, 627, 112, 5, 108, "Print"], Cell[18459, 634, 993, 36, 108, "Output"] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell[19501, 676, 80, 1, 21, "Subsubsection"], Cell[19584, 679, 1274, 36, 101, "Text"], Cell[CellGroupData[{ Cell[20883, 719, 1866, 61, 213, "Input"], Cell[22752, 782, 772, 21, 67, "Output"], Cell[23527, 805, 769, 20, 67, "Output"] }, Open ]], Cell[24311, 828, 129, 1, 32, "Text"], Cell[CellGroupData[{ Cell[24465, 833, 585, 17, 84, "Input"], Cell[25053, 852, 492, 13, 33, "Output"], Cell[25548, 867, 204, 5, 33, "Output"] }, Open ]], Cell[25767, 875, 333, 9, 32, "Text"], Cell[CellGroupData[{ Cell[26125, 888, 130, 3, 33, "Input"], Cell[26258, 893, 190, 5, 33, "Output"] }, Open ]], Cell[26463, 901, 3558, 135, 141, "Text"], Cell[CellGroupData[{ Cell[30046, 1040, 1302, 36, 129, "Input"], Cell[31351, 1078, 359, 9, 33, "Output"] }, Open ]], Cell[31725, 1090, 322, 6, 51, "Text"], Cell[CellGroupData[{ Cell[32072, 1100, 510, 16, 33, "Input"], Cell[32585, 1118, 759, 19, 67, "Output"] }, Open ]], Cell[33359, 1140, 227, 5, 32, "Text"], Cell[33589, 1147, 173, 6, 33, "Input"], Cell[33765, 1155, 366, 11, 36, "Text"], Cell[CellGroupData[{ Cell[34156, 1170, 437, 9, 33, "Input"], Cell[34596, 1181, 421, 11, 25, "Print"], Cell[35020, 1194, 607, 17, 33, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[35664, 1216, 387, 8, 33, "Input"], Cell[36054, 1226, 402, 10, 25, "Print"], Cell[36459, 1238, 846, 26, 53, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[37342, 1269, 387, 8, 33, "Input"], Cell[37732, 1279, 405, 10, 25, "Print"], Cell[38140, 1291, 962, 28, 53, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[39139, 1324, 387, 8, 33, "Input"], Cell[39529, 1334, 403, 10, 25, "Print"], Cell[39935, 1346, 1170, 33, 72, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[41142, 1384, 387, 8, 33, "Input"], Cell[41532, 1394, 402, 10, 25, "Print"], Cell[41937, 1406, 1291, 36, 72, "Output"] }, Open ]], Cell[43243, 1445, 324, 6, 51, "Text"], Cell[43570, 1453, 587, 18, 33, "Input"], Cell[CellGroupData[{ Cell[44182, 1475, 891, 19, 33, "Input"], Cell[45076, 1496, 346, 7, 33, "Output"] }, Open ]], Cell[45437, 1506, 217, 5, 32, "Text"], Cell[CellGroupData[{ Cell[45679, 1515, 98, 1, 33, "Input"], Cell[45780, 1518, 400, 13, 33, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[46217, 1536, 768, 16, 33, "Input"], Cell[46988, 1554, 329, 8, 33, "Output"] }, Open ]] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[47378, 1569, 80, 1, 42, "Subsection"], Cell[47461, 1572, 733, 18, 70, "Text"], Cell[CellGroupData[{ Cell[48219, 1594, 2428, 69, 167, "Input"], Cell[50650, 1665, 628, 16, 33, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[51315, 1686, 608, 17, 33, "Input"], Cell[51926, 1705, 1303, 28, 123, "Output"] }, Open ]], Cell[53244, 1736, 270, 7, 32, "Text"], Cell[CellGroupData[{ Cell[53539, 1747, 265, 7, 33, "Input"], Cell[53807, 1756, 1121, 26, 123, "Output"] }, Open ]], Cell[54943, 1785, 126, 3, 32, "Text"], Cell[CellGroupData[{ Cell[55094, 1792, 309, 9, 33, "Input"], Cell[55406, 1803, 581, 15, 33, "Output"] }, Open ]], Cell[56002, 1821, 492, 10, 89, "Text"], Cell[CellGroupData[{ Cell[56519, 1835, 199, 6, 33, "Input"], Cell[56721, 1843, 281, 7, 33, "Output"] }, Open ]], Cell[57017, 1853, 186, 4, 32, "Text"], Cell[CellGroupData[{ Cell[57228, 1861, 80, 2, 40, "Input"], Cell[57311, 1865, 305, 7, 33, "Output"] }, Open ]], Cell[57631, 1875, 257, 5, 51, "Text"], Cell[57891, 1882, 216, 5, 33, "Input"], Cell[58110, 1889, 163, 5, 33, "Input"], Cell[58276, 1896, 149, 4, 32, "Text"], Cell[CellGroupData[{ Cell[58450, 1904, 282, 7, 33, "Input"], Cell[58735, 1913, 1317, 29, 123, "Output"] }, Open ]], Cell[60067, 1945, 100, 1, 32, "Text"], Cell[CellGroupData[{ Cell[60192, 1950, 297, 8, 33, "Input"], Cell[60492, 1960, 1137, 28, 123, "Output"] }, Open ]], Cell[61644, 1991, 362, 6, 70, "Text"], Cell[CellGroupData[{ Cell[62031, 2001, 674, 14, 33, "Input"], Cell[62708, 2017, 1124, 28, 53, "Output"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[63881, 2051, 627, 14, 33, "Input"], Cell[64511, 2067, 1618, 47, 107, "Output"] }, Open ]] } ] *)