<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Linear Algebra |</title><link>https://kristianeschenburg.netlify.app/tag/linear-algebra/</link><atom:link href="https://kristianeschenburg.netlify.app/tag/linear-algebra/index.xml" rel="self" type="application/rss+xml"/><description>Linear Algebra</description><generator>Source Themes Academic (https://sourcethemes.com/academic/)</generator><language>en-us</language><lastBuildDate>Thu, 24 May 2018 11:30:43 -0700</lastBuildDate><image><url>https://kristianeschenburg.netlify.app/img/Bayes.jpg</url><title>Linear Algebra</title><link>https://kristianeschenburg.netlify.app/tag/linear-algebra/</link></image><item><title>Exploring Neurological Dynamical Systems: Part 2</title><link>https://kristianeschenburg.netlify.app/post/exploring-neurological-dynamical-systems-part-2/</link><pubDate>Thu, 24 May 2018 11:30:43 -0700</pubDate><guid>https://kristianeschenburg.netlify.app/post/exploring-neurological-dynamical-systems-part-2/</guid><description>&lt;p>In my previous post on
&lt;a href="https://kristianeschenburg.netlify.app/post/exploring-neurological-dynamical-systems-part-1/">dynamic mode decomposition&lt;/a>, I discussed the foundations of DMD as a means for linearizing a dynamical system&lt;sup id="fnref:1">&lt;a href="#fn:1" class="footnote-ref" role="doc-noteref">1&lt;/a>&lt;/sup>&lt;sup id="fnref:2">&lt;a href="#fn:2" class="footnote-ref" role="doc-noteref">2&lt;/a>&lt;/sup>&lt;sup id="fnref:3">&lt;a href="#fn:3" class="footnote-ref" role="doc-noteref">3&lt;/a>&lt;/sup>. In this post, I want to look at a way in which we can use rank-updates to incorporate new information into the spectral decomposition of our linear operator, $A$, in the event that we are generating online measurements from our dynamical system&lt;sup id="fnref:4">&lt;a href="#fn:4" class="footnote-ref" role="doc-noteref">4&lt;/a>&lt;/sup> &amp;ndash; see the citation below if you want a more-detailed overview of this topic along with open source code for testing this method.&lt;/p>
&lt;p>Recall that we are given an initial data matrix&lt;/p>
&lt;p>$$\begin{align}
X = \begin{bmatrix}
x_{n_{1},m_{1}} &amp;amp; x_{n_{1},m_{2}} &amp;amp; x_{n_{1},m_{3}} &amp;amp; &amp;hellip; \\
x_{n_{2},m_{1}} &amp;amp; x_{n_{1},m_{2}} &amp;amp; x_{n_{2},m_{3}} &amp;amp; &amp;hellip; \\
x_{n_{3},m_{1}} &amp;amp; x_{n_{1},m_{2}} &amp;amp; x_{n_{3},m_{3}} &amp;amp; &amp;hellip; \\
&amp;hellip; &amp;amp; &amp;hellip; &amp;amp; &amp;hellip; &amp;amp; &amp;hellip; \\
\end{bmatrix}
\in R^{n \times m}
\end{align}$$&lt;/p>
&lt;p>which we can split into two matrices, shifted one unit in time apart:&lt;/p>
&lt;p>$$\begin{align}
X^{\ast} &amp;amp;=
\begin{bmatrix}
\vert &amp;amp; \vert &amp;amp; \dots &amp;amp; \vert \\
\vec{x}_1 &amp;amp; \vec{x}_2 &amp;amp; \dots &amp;amp; \vec{x}_{m-1} \\
\vert &amp;amp; \vert &amp;amp; \dots &amp;amp; \vert \\
\end{bmatrix} \in R^{n \times (m-1)} \\
Y &amp;amp;= \begin{bmatrix}
\vert &amp;amp; \vert &amp;amp; \dots &amp;amp; \vert \\
\vec{x}_2 &amp;amp; \vec{x}_3 &amp;amp; \dots &amp;amp; \vec{x}_{m} \\
\vert &amp;amp; \vert &amp;amp; \dots &amp;amp; \vert \\
\end{bmatrix} \in R^{n \times (m-1)}
\end{align}$$&lt;/p>
&lt;p>and we are interested in solving for the linear operator $A$, such that&lt;/p>
&lt;p>$$\begin{align}
Y = AX^{\ast}
\end{align}$$&lt;/p>
&lt;p>For simplicity, since we are no longer using the full matrix, I&amp;rsquo;ll just refer to $X^{\ast}$ as $X$. In the previous post, we made the constraint that $n &amp;gt; m$, and that rank($X$) $\leq m &amp;lt; n$. Here, however, we&amp;rsquo;ll reverse this assumption, such that $m &amp;gt; n$, and that rank($X$) $\leq m &amp;lt; n$, such that $XX^{T}$ is invertible, so by multiplying both sides by $X^{T}$ we have&lt;/p>
&lt;p>$$\begin{align}
AXX^{T} &amp;amp;= YX^{T} \\
A &amp;amp;= YX^{T}(XX^{T})^{-1} \\
A &amp;amp;= QP_{x}
\end{align}$$&lt;/p>
&lt;p>where $Q = YX^{T}$ and $P_{x} = (XX^{T})^{-1}$. Now, let&amp;rsquo;s say you observe some new data $x_{m+1}, y_{m+1}$, and you want to incorporate this new data into your $A$ matrix. As in the previous post on
&lt;a href="https://kristianeschenburg.netlify.app/post/rank-one-updates/">rank-one updates&lt;/a>, we saw that directly computing the inverse could potentially be costly, so we want to refrain from doing that if possible. Instead, we&amp;rsquo;ll use the Sherman-Morrison-Woodbury theorem again to incorporate our new $x_{m+1}$ sample into our inverse matrix, just as before:&lt;/p>
&lt;p>$$\begin{align}
(X_{m+1}X^{T}&lt;em>{m+1})^{-1} = P&lt;/em>{x} + \frac{P_{x}x_{m+1}x_{m+1}^{T}P_{x}}{1 + x_{m+1}^{T}P_{x}x_{m+1}}
\end{align}$$&lt;/p>
&lt;p>Likewise, since we&amp;rsquo;re appending new data to our $Y$ and $X$ matrices, we also have&lt;/p>
&lt;p>$$\begin{align}
Y_{m+1} = \begin{bmatrix}
Y &amp;amp; y_{m+1} \end{bmatrix} \\
X_{m+1} = \begin{bmatrix} \\
X &amp;amp; x_{m+1} \end{bmatrix} \\
\end{align}$$&lt;/p>
&lt;p>such that&lt;/p>
&lt;p>$$\begin{align}
Y_{m+1} X_{m+1}^{T} &amp;amp;= YX^{T} + y_{m+1}x_{m+1}^{T} \\
&amp;amp;= Q + y_{m+1}x_{m+1}^{T}
\end{align}$$&lt;/p>
&lt;p>which is simply the sum of our original matrix $Q$, plus a rank-one matrix. The authors go on to describe some pretty cool &amp;ldquo;local&amp;rdquo; DMD schemes, by incorporating weights, as well as binary thresholds, that are time-dependent into the computation of the linear operator, $A$.&lt;/p>
&lt;div class="footnotes" role="doc-endnotes">
&lt;hr>
&lt;ol>
&lt;li id="fn:1">
&lt;p>P.J. Schmid.
&lt;a href="https://hal-polytechnique.archives-ouvertes.fr/file/index/docid/1020654/filename/DMS0022112010001217a.pdf" target="_blank" rel="noopener">Dynamic mode decomposition of numerical and experimental data&lt;/a>. Journal of Fluid Mechanics 656.1. 2010.&amp;#160;&lt;a href="#fnref:1" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:2">
&lt;p>Tu et al.
&lt;a href="http://cwrowley.princeton.edu/papers/Tu-DMD.pdf" target="_blank" rel="noopener">On Dynamic Mode Decomposition: Theory And Applications&lt;/a>&amp;#160;&lt;a href="#fnref:2" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:3">
&lt;p>Kunert-Graf et al.
&lt;a href="https://www.frontiersin.org/articles/10.3389/fncom.2019.00075/full" target="_blank" rel="noopener">Extracting Reproducible Time-Resolved Resting State Networks Using Dynamic Mode Decomposition&lt;/a>. Front. Comput. Neurosci. 2019.&amp;#160;&lt;a href="#fnref:3" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:4">
&lt;p>Zhang et al.
&lt;a href="https://arxiv.org/abs/1707.02876" target="_blank" rel="noopener">Online dynamic mode decomposition for time-varying systems&lt;/a>. 2017.&amp;#160;&lt;a href="#fnref:4" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;/ol>
&lt;/div></description></item><item><title>Exploring Neurological Dynamical Systems: Part 1</title><link>https://kristianeschenburg.netlify.app/post/exploring-neurological-dynamical-systems-part-1/</link><pubDate>Tue, 22 May 2018 14:02:52 -0700</pubDate><guid>https://kristianeschenburg.netlify.app/post/exploring-neurological-dynamical-systems-part-1/</guid><description>&lt;p>In the next two posts, I want to talk briefly about an algorithm called Dynamic Mode Decomposition (DMD). DMD is a spatiotemporal modal decomposition technique that can be used to identify spatial patterns in a signal (modes), along with the time course of these spatial patterns (dynamics). As such, the algorithm assumes that the input data has both a spatial and a temporal component. We are interested in modeling &lt;em>how&lt;/em> the system evolves over time.&lt;/p>
&lt;p>If you&amp;rsquo;d like to find more information about DMD, Peter Schmid&lt;sup id="fnref:1">&lt;a href="#fn:1" class="footnote-ref" role="doc-noteref">1&lt;/a>&lt;/sup> and Jonathan Tu&lt;sup id="fnref:2">&lt;a href="#fn:2" class="footnote-ref" role="doc-noteref">2&lt;/a>&lt;/sup> have written excellent expositions on the topic. Likewise, if you&amp;rsquo;d like to follow along with the code for the following analysis, see
&lt;a href="https://github.com/kristianeschenburg/dmd" target="_blank" rel="noopener">my repo&lt;/a>. For a more in-depth analysis that applies DMD to brain activity in the resting brain, see a recent publication by my colleagues and me&lt;sup id="fnref:3">&lt;a href="#fn:3" class="footnote-ref" role="doc-noteref">3&lt;/a>&lt;/sup>, along with the
&lt;a href="https://github.com/kunert/DMD_RSN" target="_blank" rel="noopener">code&lt;/a> used for our analysis.&lt;/p>
&lt;h2 id="the-dmd-algorithm">The DMD Algorithm&lt;/h2>
&lt;p>Let&amp;rsquo;s assume that you&amp;rsquo;ve taken $n$ measurements from specific points in space for $m$ time points, where for now we assume that $m\lt n$. For now, we&amp;rsquo;ll assume that the sampling frequency, $\omega$, is stable across the entire experiment. We define our entire data matrix as&lt;/p>
&lt;p>$$\begin{align}
X = \begin{bmatrix}
x_{n_{1},m_{1}} &amp;amp; x_{n_{1},m_{2}} &amp;amp; x_{n_{1},m_{3}} &amp;amp; &amp;hellip; \\
x_{n_{2},m_{1}} &amp;amp; x_{n_{1},m_{2}} &amp;amp; x_{n_{2},m_{3}} &amp;amp; &amp;hellip; \\
x_{n_{3},m_{1}} &amp;amp; x_{n_{1},m_{2}} &amp;amp; x_{n_{3},m_{3}} &amp;amp; &amp;hellip; \\
&amp;hellip; &amp;amp; &amp;hellip; &amp;amp; &amp;hellip; &amp;amp; &amp;hellip; \\
\end{bmatrix}
\in R^{n \times m}
\end{align}$$&lt;/p>
&lt;p>We are interested in solving for the matrix, $A \in R^{n \times n}$, such that&lt;/p>
&lt;p>$$\begin{align}
x_{t+1} = A x_{t} \; \; \forall \; \; t = 1,2,&amp;hellip;m-1
\end{align}$$&lt;/p>
&lt;p>Given our full data matrix $X$, we can define two matrices $X^{*}$ and $Y$ such that&lt;/p>
&lt;p>$$\begin{align}
X^{*} &amp;amp;= \begin{bmatrix}
\vert &amp;amp; \vert &amp;amp; \dots &amp;amp; \vert \\
\vec{x}_{1} &amp;amp; \vec{x}_{2} &amp;amp; \dots &amp;amp; \vec{x}_{m-1} \\
\vert &amp;amp; \vert &amp;amp; \dots &amp;amp; \vert \\
\end{bmatrix} \in R^{n \times (m-1)} \\
Y &amp;amp;= \begin{bmatrix}
\vert &amp;amp; \vert &amp;amp; \dots &amp;amp; \vert \\
\vec{x}_2 &amp;amp; \vec{x}_3 &amp;amp; \dots &amp;amp; \vec{x}_{m} \\
\vert &amp;amp; \vert &amp;amp; \dots &amp;amp; \vert \\
\end{bmatrix} \in R^{n \times (m-1)}
\end{align}$$&lt;/p>
&lt;p>so that we can write&lt;/p>
&lt;p>$$\begin{align}
Y = AX^{\ast}
\end{align}$$&lt;/p>
&lt;p>If $n$ is small, this is relatively easy to compute &amp;ndash; however, if $n$ is large, as is the case when modeling temporal dynamics in resting-state MRI, it would be computationally inefficient to compute A directly. To alleviate this, we can make use of the Singular Value Decomposition (SVD) of our predictor matrix $X^{\ast}$. We define the SVD of $X^{\ast}$ as&lt;/p>
&lt;p>$$\begin{align}
X^{\ast} = U \Sigma V^{T} \
\end{align}$$&lt;/p>
&lt;p>as well as the Moore-Penrose pseudo-inverse of $X^{\ast} = X^{\dagger}$ as&lt;/p>
&lt;p>$$\begin{align}
X^{\dagger} = V \Sigma^{-1} U^{T} \\
\end{align}$$&lt;/p>
&lt;p>such that we can write&lt;/p>
&lt;p>$$\begin{align}
YX^{\dagger} = YV \Sigma^{-1} U^{T} = A X^{\ast}X^{\dagger} = A \\
\end{align}$$&lt;/p>
&lt;p>Additionally, if we assume that $rank(X^{\ast}) = r \leq m$, then we can use the truncated SVD such that&lt;/p>
&lt;p>$$\begin{align}
U &amp;amp; \in R^{n \times r} \\
V^{T} &amp;amp; \in R^{r \times m} \\
\end{align}$$&lt;/p>
&lt;p>and&lt;/p>
&lt;p>$$\begin{align}
\Sigma = \begin{bmatrix}
\sigma_{1} &amp;amp; 0 &amp;amp; 0 &amp;amp; &amp;hellip; \\
0 &amp;amp; \sigma_{2} &amp;amp; 0 &amp;amp; &amp;hellip; \\
0 &amp;amp; 0 &amp;amp; \ddots &amp;amp; &amp;hellip; \\
\vdots &amp;amp; \vdots &amp;amp; \vdots &amp;amp; \sigma_{r} \\
\end{bmatrix} \in R^{r \times r}
\end{align}$$&lt;/p>
&lt;p>As it stands now, we still compute an $A \in R^{n \times n}$ matrix. However, because we have a potentially low-rank system, we can apply a Similarity Transformation to $A$ in order to reduce its dimensionality, without changing its spectrum. Using our spatial singular vectors $U$, we define&lt;/p>
&lt;p>$$\begin{align}
\tilde{A} &amp;amp;= U^{T} A U \\
&amp;amp;= U^{T} (YV \Sigma^{-1} U^{T}) U \\
&amp;amp;= U^{T} Y V \Sigma^{-1} \\
\end{align}$$&lt;/p>
&lt;p>where $\tilde{A} \in R^{r \times r}$. If we consider the above SVD, we see that $U$ is the matrix of left singular vectors, an orthogonal basis that spans $C(X^{\ast})$, which is an r-dimensional subspace of $R^{n}$. Thus, the similarity transform represents a mapping $f(A) = U^{T} A U : R^{n} \rightarrow R^{r}$. We now have a reduced-dimensional representation of our linear operator, from which we can compute the spatial modes and dynamic behavior of each mode. First, however, because of the notion of variance captured by the singular values of our original predictor matrix, we weight $\tilde{A}$ by the singular values as&lt;/p>
&lt;p>$$\begin{align}
\hat{A} = \Sigma^{\frac{1}{2}} \tilde{A} \Sigma^{\frac{1}{2}} \\
\end{align}$$&lt;/p>
&lt;p>such that our computed spatial modes have been weighted by the amount they contribute to our measured signal. We can now compute the eigendecomposition of $\hat{A}$ as&lt;/p>
&lt;p>$$\begin{align}
\hat{A} W = W \Lambda \\
\end{align}$$&lt;/p>
&lt;p>where the eigenvectors $W$ are the reduced-dimension representations of our spatial modes, and the eigenvalues $\Lambda$ capture the dynamic behavior of our spatial modes. Because our original data matrix $X^{\ast}$ had spatial dimension $n$ and our eigenvectors have dimension $r$, we need to up-project our eigenvectors $W$ to compute the final spatial modes, via&lt;/p>
&lt;p>$$\begin{align}
\Phi = Y V \Sigma^{\frac{-1}{2}}W
\end{align}$$&lt;/p>
&lt;p>From the SVD of our prediction matrix $X^\ast=U \Sigma V^{T}$, the matrix $V \in R^{m \times r}$ is the matrix of right singular vectors, an orthogonal basis spanning the space of $X^{\ast T}$ (i.e. $r$ basis vectors spanning the space of the measured time courses). Thus, we see that $H = (V \Sigma^{\frac{-1}{2}})W$ represents a linear combination of the temporal basis vectors (a mapping from $R^{r} \rightarrow R^{m}$) for each eigenvector $w_{i}$ of $W$, weighted by the corresponding singular value $\sigma_{i}^{\frac{-1}{2}}$ (that acts to normalize the spatial mode amplitudes). Finally, we see that $\Phi = X^{\ast}H$ computes how much of each temporal basis vector is present in the measured time course at each point in space.&lt;/p>
&lt;p>Because we are modeling a dynamical system, we can compute the continuous time dynamics of our system using our spatial modes and eigenvalues as&lt;/p>
&lt;p>$$\begin{align}
\vec{x}(t) \approx \sum_{i=1}^{r} b_{i}\exp^{((\gamma_{i} + 2i\pi f_{i})\cdot t)} \vec{\phi}_{i}
\end{align}$$&lt;/p>
&lt;p>where $\gamma_{i}$ is a growth-decay constant and $f_{i}$ is the frequency of oscillation of the spatial mode $\phi_{i}$. We can compute these two constants as&lt;/p>
&lt;p>$$\begin{align}
\gamma_{i} &amp;amp;= \frac{\text{real}(\text{ln}(\lambda_{i}))}{\Delta t} \\
f_{i} &amp;amp;= \frac{\text{imag}(\text{ln}(\lambda_{i}))}{2\pi \Delta t}
\end{align}$$&lt;/p>
&lt;p>So, we can see that DMD linearizes our measured time series, by fitting what can be analogized to a &amp;ldquo;global&amp;rdquo; regression. That is, instead of computing how a single time point predicts the next time point, which could readily be solved using the simple &lt;strong>Normal equations&lt;/strong>, DMD computes how a matrix of time points predicts another matrix of time points that is shifted one unit of time into the future. To this extent, DMD minimizes the Frobenius norm of&lt;/p>
&lt;p>$$\begin{align}
\min \limits_{A} \lVert Y - AX^{\ast} \rVert^{2}_{F} \\
\end{align}$$&lt;/p>
&lt;p>However, rather than explicitly computing the matrix $A$, DMD computes the eigenvectors and eigenvalues of $A$, by utilizing the &lt;strong>Singular Value Decomposition&lt;/strong>, along with a &lt;strong>Similarity Transformation&lt;/strong>, in order to generate a reduced-dimensional representation of $A$.&lt;/p>
&lt;p>This spectral decomposition of our linear operator is of particular importance, because it sheds light on the fact that DMD models the temporal dynamics of our system using a &lt;strong>Fourier basis&lt;/strong>. Each spatial mode is represented by a particular Fourier frequency along with a growth-decay constant that determines the future behavior of our spatial mode. Additionally, the Fourier basis also determines what sorts of time series can be modeled using DMD &amp;ndash; time series that are expected to have sinusoidal behavior will be more reliably modeled using DMD, whereas signals that show abrupt spike patterns might be more difficult to model.&lt;/p>
&lt;div class="footnotes" role="doc-endnotes">
&lt;hr>
&lt;ol>
&lt;li id="fn:1">
&lt;p>P.J. Schmid.
&lt;a href="https://hal-polytechnique.archives-ouvertes.fr/file/index/docid/1020654/filename/DMS0022112010001217a.pdf" target="_blank" rel="noopener">Dynamic mode decomposition of numerical and experimental data&lt;/a>. Journal of Fluid Mechanics 656.1. 2010.&amp;#160;&lt;a href="#fnref:1" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:2">
&lt;p>Tu et al.
&lt;a href="http://cwrowley.princeton.edu/papers/Tu-DMD.pdf" target="_blank" rel="noopener">On Dynamic Mode Decomposition: Theory And Applications&lt;/a>&amp;#160;&lt;a href="#fnref:2" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:3">
&lt;p>Kunert-Graf et al.
&lt;a href="https://www.frontiersin.org/articles/10.3389/fncom.2019.00075/full" target="_blank" rel="noopener">Extracting Reproducible Time-Resolved Resting State Networks Using Dynamic Mode Decomposition&lt;/a>. Front. Comput. Neurosci. 2019.&amp;#160;&lt;a href="#fnref:3" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;/ol>
&lt;/div></description></item><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>