<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Matrix Inversion |</title><link>https://kristianeschenburg.netlify.app/tag/matrix-inversion/</link><atom:link href="https://kristianeschenburg.netlify.app/tag/matrix-inversion/index.xml" rel="self" type="application/rss+xml"/><description>Matrix Inversion</description><generator>Source Themes Academic (https://sourcethemes.com/academic/)</generator><language>en-us</language><lastBuildDate>Fri, 11 May 2018 16:53:45 -0700</lastBuildDate><image><url>https://kristianeschenburg.netlify.app/img/Bayes.jpg</url><title>Matrix Inversion</title><link>https://kristianeschenburg.netlify.app/tag/matrix-inversion/</link></image><item><title>Rank One Updates</title><link>https://kristianeschenburg.netlify.app/post/rank-one-updates/</link><pubDate>Fri, 11 May 2018 16:53:45 -0700</pubDate><guid>https://kristianeschenburg.netlify.app/post/rank-one-updates/</guid><description>&lt;p>In this post, I&amp;rsquo;m going to go over some examples of rank-one updates of matrices. To compute rank-one updates, we rely on the Sherman-Morrison-Woodbury theorem. From the previous post on
&lt;a href="https://kristianeschenburg.netlify.app/post/blockwise-matrix-inversion/">Blockwise Matrix Inversion&lt;/a>, recall that, given a matrix and its inverse&lt;/p>
&lt;p>$$R = \begin{bmatrix}
A &amp;amp; B \\
C &amp;amp; D
\end{bmatrix} \; \; \; \; R^{-1} = \begin{bmatrix}
W &amp;amp; X \\
Y &amp;amp; Z
\end{bmatrix}$$&lt;/p>
&lt;p>we have that&lt;/p>
&lt;p>$$\begin{align}
W = (A-BD^{-1}C)^{-1} = C^{-1}D(D-CA^{-1}B)^{-1}CA^{-1}
\end{align}$$&lt;/p>
&lt;p>Expanding this further, the Woodbury formula proves the following identity&lt;/p>
&lt;p>$$\begin{align}
(A+BD^{-1}C)^{-1}=A^{-1}-A^{-1}B(D−CA^{-1}B)^{-1}CA^{-1}
\end{align}$$&lt;/p>
&lt;p>Given an initial matrix $A$ and its inverse $A^{-1}$, and a new matrix $R=BD^{-1}C$, we see that we can define the inverse of our new updated matrix $A+R$ in terms of the inverse of our original matrix $A$ and components of $R$. Importantly, we can perform rank-$k$ updates, where $rank(R) = k$.&lt;/p>
&lt;p>For example, if we want to update our matrix $A$ with a new vector, $v$, we can rewrite the formula above as follows:&lt;/p>
&lt;p>$$\begin{align}
(A+vv^{T})^{-1} &amp;amp;=A^{-1}-A^{-1}v(1+v^{T}A^{-1}v)^{-1}v^{T}A^{-1} \\
&amp;amp;=A^{-1}-\frac{A^{-1}vv^{T}A^{-1}}{1+v^{T}A^{-1}v} \\
\end{align}$$&lt;/p>
&lt;p>where the updated inverse is defined so long as the quadratic form $v^{T}A^{-1}v \neq -1$.&lt;/p>
&lt;hr>
&lt;p>&lt;strong>Rank-One Updates for Linear Models&lt;/strong>&lt;/p>
&lt;p>Recall the Normal equations for linear models:&lt;/p>
&lt;p>$$\begin{align}
X^{T}X\beta = X^{T}y
\end{align}$$&lt;/p>
&lt;p>and&lt;/p>
&lt;p>$$\begin{align}
\beta = (X^{T}X)^{g}X^{T}y
\end{align}$$&lt;/p>
&lt;p>where $X$ is our design matrix, $y$ is our dependent variable, and $\beta$ is a solution to the Normal equation, due to the fact that the Normal equations are consistent. $(X^{T}X)^{g}$ is the generalized inverse of $X^{T}X$, which is unique (i.e. $(X^{T}X)^{g} = (X^{T}X)^{-1}$) only if $X$ has full column-rank. For our immediate purpose, we assume that $X$ has full column rank.&lt;/p>
&lt;p>Assume that we observe a set of observations, $X \in R^{n \times p}$ and response variable, $y$, and compute our coefficient estimates $\hat{\beta}$ via the Normal equations above, using $(X^{T}X)^{-1}$. Now given a new observation, $v \in R^{p}$, how can we update our coefficient estimates? We can append $v$ to $X$ as&lt;/p>
&lt;p>$$ X^{\text{*}} = \begin{bmatrix}
X \\
v
\end{bmatrix} \in R^{(n+1) \times p}$$&lt;/p>
&lt;p>and directly compute $(X^{\text{*T}}X^{\text{*}})^{-1}$, &lt;strong>or&lt;/strong> we can use the Sherman-Morrison-Woodbury theorem:&lt;/p>
&lt;p>$$
\begin{align}
(X^{\text{*T}}X^{\text{*}})^{-1} = (X^{T}X + vv^{T})^{-1} = (X^{T}X)^{-1} - \frac{(X^{T}X)^{-1}vv^{T}(X^{T}X)^{-1}}{1+v^{T}(X^{T}X)^{-1}v} \\
\end{align}
$$&lt;/p>
&lt;p>from which we can easily compute our new coefficient estimates with $$.&lt;/p>
&lt;p>$$\begin{align}
\beta^{\text{*}} = (X^{\text{*T}}X^{\text{*}})^{-1}X^{\text{*}T}y \\
\end{align}$$&lt;/p>
&lt;p>Importantly, in the case of regression, for example, this means that we can update our linear model via simple matrix calculations, rather than having to refit the model from scratch to incorporate our new data. In the next few posts, I&amp;rsquo;ll go over an example of an implementation of rank-updating methods that I&amp;rsquo;ve been using in lab to study brain dynamics.&lt;/p></description></item><item><title>Blockwise Matrix Inversion</title><link>https://kristianeschenburg.netlify.app/post/blockwise-matrix-inversion/</link><pubDate>Tue, 08 May 2018 23:24:17 -0700</pubDate><guid>https://kristianeschenburg.netlify.app/post/blockwise-matrix-inversion/</guid><description>&lt;p>I&amp;rsquo;m taking a Statistics course on the theory of linear models, which covers Gauss-Markov models and various extensions of them. Sometimes, when dealing with partitioned matrices, and commonly Multivariate Normal Distributions, we&amp;rsquo;ll often need to invert matrices in a blockwise manner. This has happened often enough during this course (coincidentally was necessary knowledge for a midterm question), so I figured I should just document some of the inversion lemmas.&lt;/p>
&lt;p>Let&amp;rsquo;s define our partitioned matrix as&lt;/p>
&lt;p>$$ R = \begin{bmatrix}
A &amp;amp; B \\
C &amp;amp; D
\end{bmatrix}$$&lt;/p>
&lt;p>We are specifically interested in finding&lt;/p>
&lt;p>$$ R^{-1} = \begin{bmatrix}
W &amp;amp; X \\
Y &amp;amp; Z
\end{bmatrix}$$&lt;/p>
&lt;p>such that&lt;/p>
&lt;p>$$ R R^{-1} = R^{-1}R =
\begin{bmatrix}
I &amp;amp; 0 \\
0 &amp;amp; I
\end{bmatrix}$$&lt;/p>
&lt;p>&lt;strong>Part 1: $R R^{-1}$&lt;/strong>&lt;/p>
&lt;p>For the right inverse ($R R^{-1}$), we can define&lt;/p>
&lt;p>$$ \begin{aligned}
AW + BY = I \\
AX + BZ = 0 \\
CW + DY = 0 \\
CX + DZ = I \\
\end{aligned}
$$&lt;/p>
&lt;p>and, assuming $A$ and $D$ are invertible,&lt;/p>
&lt;p>$$\begin{aligned}
X = -A^{-1}BZ \\
Y = -D^{-1}CW \\
\end{aligned}$$&lt;/p>
&lt;p>We can plug these identities back into the first system of equations as&lt;/p>
&lt;p>$$\begin{aligned}
AW + B(-D^{-1}CW) &amp;amp;= (A - BD^{-1}C)W = I \\
C(-A^{-1}BZ) + DZ &amp;amp;= (D - CA^{-1}B)Z = I \\
\end{aligned}$$&lt;/p>
&lt;p>so that&lt;/p>
&lt;p>$$\begin{aligned}
W = (A-BD^{-1}C)^{-1} \\
Z = (D-CA^{-1}B)^{-1} \\
\end{aligned}$$&lt;/p>
&lt;p>and finally&lt;/p>
&lt;p>$$ R^{-1} = \begin{bmatrix}
W &amp;amp; X \\
Y &amp;amp; Z
\end{bmatrix}
= \begin{bmatrix}
(A-BD^{-1}C)^{-1} &amp;amp; -A^{-1}B(D-CA^{-1}B)^{-1} \\
-D^{-1}C(A-BD^{-1}C)^{-1} &amp;amp; (D-CA^{-1}B)^{-1} \\
\end{bmatrix}$$&lt;/p>
&lt;p>It is important to note that the above result only holds if $A$, $D$, $(D-CA^{-1}B)$, and $(A-BD^{-1}C)$ are invertible.&lt;/p>
&lt;p>&lt;strong>Part 2: $R^{-1} R$&lt;/strong>&lt;/p>
&lt;p>Following the same logic as above, we have the following systems of equations for the left inverse ($R^{-1}R$)&lt;/p>
&lt;p>$$\begin{aligned}
WA + XC = I \\
WB + XD = 0 \\
YA + ZC = 0 \\
YB + ZD = I \\
\end{aligned}$$&lt;/p>
&lt;p>so that&lt;/p>
&lt;p>$$\begin{aligned}
X = WBD^{-1} = A^{-1}BZ \\
Y = ZCA^{-1} = D^{-1}CW \\
\end{aligned}$$&lt;/p>
&lt;p>which indicates that&lt;/p>
&lt;p>$$\begin{aligned}
W = (A-BD^{-1}C)^{-1} = C^{-1}D(D-CA^{-1}B)^{-1}CA^{-1} \\
X = (A-BD^{-1}C)^{-1}BD^{-1} = A^{-1}B(D-CA^{-1}B)^{-1} \\
\end{aligned}$$&lt;/p>
&lt;p>Importantly, blockwise matrix inversion allows us to define the inverse of a larger matrix, with respect to its subcomponents. Likewise, from here, we can go on to derive the Sherman-Morrison formula and Woodbury theorem, which allow us to do all kinds of cool stuff, like rank-one matrix updates. In the next few posts, I&amp;rsquo;ll go over a few examples of where blockwise matrix inversions are useful, and common scenarios where rank-one updates of matrices are applicable.&lt;/p></description></item></channel></rss>