Notions of Matrix Differentiation - MathOverflow most recent 30 from http://mathoverflow.net 2013-05-20T16:48:37Z http://mathoverflow.net/feeds/question/5209 http://www.creativecommons.org/licenses/by-nc/2.5/rdf http://mathoverflow.net/questions/5209/notions-of-matrix-differentiation Notions of Matrix Differentiation Elisha Peterson 2009-11-12T17:41:10Z 2009-11-13T16:55:18Z <p>There are a few standard notions of matrix derivatives, e.g.</p> <ul> <li>If <em>f</em> is a function defined on the entries of a matrix <em>A</em>, then one can talk about the matrix of partial derivatives of <em>f</em>.</li> <li>If the entries of a matrix are all functions of a scalar <em>x</em>, then it makes sense to talk about the derivative of the matrix as the matrix of derivatives of the entries.</li> </ul> <p>In the second case, it makes sense to talk about higher order derivatives, but in the first example the derivative provides a matrix from a scalar function, so you have to massage it a little bit to define a higher order derivative (e.g. take the trace of the resulting matrix).</p> <p>I was wondering what other notions of matrix differentiation might exist out there, particularly any notions that allow for higher-order differentiation. I am also interested in any connections between various forms of matrix derivatives. As this is related to an undergraduate research project, I am mostly looking for answers that include a minimum of advanced terminology, but a discussion of how more general concepts (e.g. differential forms, matrix exponentials, etc.) relate to matrix derivatives would also be helpful.</p> http://mathoverflow.net/questions/5209/notions-of-matrix-differentiation/5215#5215 Answer by Harald Hanche-Olsen for Notions of Matrix Differentiation Harald Hanche-Olsen 2009-11-12T18:00:15Z 2009-11-12T18:00:15Z <p>In the first case, there is no difficulty in working with higher derivatives. All you have is a function $f$ of $n^2$ variables $a_{ij}$, and you can form and work with derivatives like $\partial^3f/\partial a_{12}\partial a_{23}\partial a_{34}$ with reckless abandon. Don't let the double indices worry you.</p> <p>A more abstract approach would be to consider maps between any two finite dimensional spaces, or more generally Banach spaces. If $f\colon E\to F$ is a map between two such spaces and $x\in E$ then $f'(x)$, if it exists, is a bounded linear map, $f'(x)\in B(E,F)$, so that $f(x+h)=f(x)+f'(x)h+o(\|h\|)$ for $h\in E$ as $\|h\|\to0$. You want higher deriviatives? Well, $f'\colon E\to B(E,F)$ so we can employ the definition again and get a double derivative $f''(x)\in B(E,B(E,F))$. And so on. Actually, $B(E,B(E,F))$ is better identified with the space of bounded bilinear maps $E\times E\to F$, and the equality of mixed partial derivatives becomes the symmetry of $f''(x)$ in its two variables. You wanted to keep this simple, so I'll keep tensor products out of it for now.</p> <p>(Quick addition: I forgot to mention that of course, the space of $n\times n$ matrices can stand in for either of the spaces $E$, $F$. Also, if you work with finite dimensional spaces only, you can delete the word “bounded” wherever it appears above.)</p> http://mathoverflow.net/questions/5209/notions-of-matrix-differentiation/5229#5229 Answer by Dinakar Muthiah for Notions of Matrix Differentiation Dinakar Muthiah 2009-11-12T19:01:10Z 2009-11-12T19:01:10Z <p>Since you say you are doing an undergraduate research project, I think the following document, <a href="http://www2.imm.dtu.dk/pubdb/views/edoc%5Fdownload.php/3274/pdf/imm3274.pdf" rel="nofollow">The Matrix Cookbook</a>, might be useful for you. There is a whole section devoted to computations of matrix derivatives. There is no deep mathematics going on, but it's a great reference.</p> http://mathoverflow.net/questions/5209/notions-of-matrix-differentiation/5241#5241 Answer by Barak A. Pearlmutter for Notions of Matrix Differentiation Barak A. Pearlmutter 2009-11-12T19:54:15Z 2009-11-12T19:54:15Z <p>Check out the chapter on matrix derivatives in "Some Eclectic Matrix Theory" by Kenneth S. Miller (1987, Robert E. Krieger Publishing Company). It has an elegant formulation that allows higher-order derivatives etc, and handles the case df(X)/dX where f(X) and X are both matrices by making the result also be a matrix.</p> http://mathoverflow.net/questions/5209/notions-of-matrix-differentiation/5256#5256 Answer by Vectornaut for Notions of Matrix Differentiation Vectornaut 2009-11-12T21:03:46Z 2009-11-13T16:55:18Z <p>For me, the clearest way to think about matrix differentiation is as a special case of differentiation on real or complex vector spaces. In this answer, I'll stick to real vector spaces, because the complex case might have subtleties I'm not aware of. The definition I'm going to present may not be equivalent to the standard definition (given by Harald Hanche-Olsen), but I think it's at least morally correct, and I find it very useful in practice. Corrections to make it more rigorous would be welcome!</p> <p>[<strong>Edit:</strong> Harald Hanche-Olsen has let me know that if you drop the linearity and boundedness condition from my definition, you get the Gâteaux derivative. It follows that the derivative I've defined is <b>not</b> equivalent to the standard derivative, the Fréchet derivative, because a function can have a linear Gâteaux derivative even if the Fréchet derivative doesn't exist. If the Fréchet derivative does exist, however, the Gâteaux derivative also exists, and is equal to the Fréchet derivative.]</p> <p>Without further ado, let $E$ be a real vector space, and let $F$ be a real Banach space. (In the first example you mentioned, $E$ would be the set of $n \times m$ matrices, and $F$ would be the reals. In your second example, $E$ would be the reals, and $F$ would be the $n \times m$ matrices with a suitable norm---maybe the uniform norm?) We want to define the derivative of a function $f \colon E \to F$. For each point $x \in E$, let $df_x \colon E \to F$ be the function</p> <p>$$df_x(v) = \frac{d}{d\epsilon} f(x + \epsilon v)|_{\epsilon = 0},$$</p> <p>where $\epsilon$ is a real number. If this function exists <strong>and is linear</strong>, it's called the derivative of $f$ at $x$. (Actually, if $F$ is infinite-dimensional, we also have to demand that $df_x$ be bounded. If $F$ is finite-dimensional, every linear map into $F$ is bounded, so we don't have to worry about it. See the footnote for more details.)</p> <p>I like this definition because it spotlights the fact that $df_x(v)$ is the directional derivative of $f$ along $v$. If you want to work with partial derivatives, you can pick a basis $e_{1}, e_{2}, e_{3} \ldots$ for $E$ and define $\partial_i f(x) = df_x(e_i)$. It follows from the linearity condition that</p> <p>$$df_x(\beta_{1} e_{1} + \ldots + \beta_{n} e_{n}) = \beta_{1} \partial_{1} f(x) + \ldots + \beta_{n} \partial_{n} f(x).$$</p> <p>What about higher derivatives? Again, Harald Hanche-Olsen has given the standard definition, and that definition will work with any definition of the first derivative. However, I get a little squitchy thinking about nested function spaces like $B(E, B(E, B(E, F)))$. I wish there were a better way! Intuitively, you'd want the second derivative to be something like this:</p> <p>$$d^{2} f_{x}(v_{1}, v_{2}) = \frac{d}{d\epsilon_{1}} \frac{d}{d\epsilon_{2}} f(x + \epsilon_{1} v_{1} + \epsilon_{2} v_{2})|<em>{\epsilon</em>{1} = \epsilon_{2} = 0},$$</p> <p>with, of course, conditions about existence, bilinearity, and boundedness. (You might also have to explicitly demand symmetry in the arguments $v_{1}$ and $v_{2}$.) I would be very interested to know whether (or under what conditions) this definition is equivalent to the standard one! In fact, I might even ask a question about it...</p> <p><hr /></p> <p><em>Footnote</em></p> <p>To be thorough, I should say how the derivative</p> <p>$$\frac{d}{d\epsilon} f(x + \epsilon v)|_{\epsilon = 0}$$</p> <p>is defined! It's just the usual derivative from intro analysis:</p> <p>$$\frac{d}{d\epsilon} f(x + \epsilon v) |<em>{\epsilon = 0} = \lim</em>{\epsilon \to 0} \frac{1}{\epsilon}[f(x + \epsilon v) - f(x)].$$</p> <p>The notion of a limit is well-defined (although the limit is not guaranteed to exist) because $F$, being a Banach space, gets a topology from its norm.</p> <p>p.s. Sorry about the LaTeX! I swear it's working in the preview.</p> http://mathoverflow.net/questions/5209/notions-of-matrix-differentiation/5318#5318 Answer by Greg Kuperberg for Notions of Matrix Differentiation Greg Kuperberg 2009-11-13T06:47:57Z 2009-11-13T06:54:00Z <p>There is another interpretation of Elisha's question that I think has not yet been addressed: How, and to what extent, can you do differential calculus with functional expressions of square matrices? For instance, how do you differentiate $\exp(A)$, which is defined for all square matrices $A$?</p> <p>There is a good answer to this question for polynomials and an even better answer for the trace of a univariate polynomial. Both of these good answers extend automatically to analytic functions $f(z)$ evaluated at matrices by means of their Taylor series. (Which of course includes exponentiation.) I like to write the answer in terms of differentials. The differential of matrices $A$, $B$, etc., is $dA$, $dB$, etc., which you can take to mean that the matrices are unspecified functions of some dummy parameter $t$, and $dA$ then represents the formal numerator of the matrix-valued derivative $dA/dt$.</p> <p>In this formalism, the Leibniz rule still holds, as long as you remember that matrix multiplication is non-commutative: $d(AB) = (dA)B + A(dB)$. Indeed, the matrices don't actually need to be square. The sum rule holds trivially. The negative power rule has a creative correct answer: $d(A^{-1}) = A^{-1}(dA)A^{-1}$. You can then differentiate exponentiation: $$d\exp(A) = dA + \frac{(dA)A + A(dA)}2 + \frac{(dA)A^2 + A(dA)A+A^2(dA)}6 + \cdots.$$ As you can see from this example, you can differentiate a power series, but nothing all that great happens because $dA$ might not commute with $A$. However, if you're computing the differential of $\mathrm{Tr}(f(A))$, then something very nice happens: You can cyclically permute each term of the differentiated power series to put $dA$ at the end. Thus, you get the very nice formula $$d\mathrm{Tr}(f(A)) = \mathrm{Tr}(f'(A)dA).$$ I have only derived this formula when $A$ is within the radius of convergence of the Taylor series of $f$. However, by continuity it applies generally when $f(A)$ and $f'(A)$ are well-defined. (For instance, if $A$ and $dA$ are both real symmetric or Hermitian, then it is enough for $f$ to exist as a real function and have one continuous derivative near the eigenvalues of $A$.)</p> <p>Higher derivatives work basically the same way as first derivatives. Again, you should take $A$ to be a function of a dummy parameter $t$. To get the simplest expressions for higher derivatives, you should assume that $A$ is a linear function of $t$ (including a constant). Then for example: $$d^2\exp(A) = (dA)^2 + \frac{(dA)^2A + (dA)A(dA) + A(dA)^2}3 + \cdots.$$ The trace of this looks good at first, but the quadratic term in $A$ has both $\mathrm{Tr}((dA)^2A^2)$ and $\mathrm{Tr}((A(dA))^2)$, and I don't think that the rest of the traced Taylor series simplifies the way that it did for the first derivative.</p> <p>A final remark: All of this works the best for functions $f(x)$ that are entire (in the sense of complex analysis, i.e., an infinite radius of convergence). One of the definitions of an entire function is one whose Taylor series decays superexponentially, and this is also a good condition for a non-commutative multivariate Taylor series, in the sense that it will converge for any matrices that you plug in.</p> http://mathoverflow.net/questions/5209/notions-of-matrix-differentiation/5331#5331 Answer by anonymous for Notions of Matrix Differentiation anonymous 2009-11-13T09:55:25Z 2009-11-13T09:55:25Z <p>A good resource for what Harald Hanche-Olsen wrote is Chapter VIII of Dieudonne's <a href="http://books.google.de/books?id=hE0mueNxcCYC&amp;dq=dieudonne+%22foundations+of+modern+analysis%22&amp;printsec=frontcover&amp;source=bl&amp;ots=dw4VxV0UB9&amp;sig=Nq0mbPzUBl8FSnstUedFa7nADcI&amp;hl=en&amp;ei=Viv9SsT8FpTe-QaDnPDzCg&amp;sa=X&amp;oi=book%5Fresult&amp;ct=result&amp;resnum=1&amp;ved=0CAgQ6AEwAA" rel="nofollow">Foundations of Modern Analysis (Vol. 1)</a>. (Sorry, couldn't make it a comment.)</p>