vector expressions with unspecified dimension

98 views
Skip to first unread message

Gustavo

unread,
Apr 28, 2014, 1:27:12 PM4/28/14
to sy...@googlegroups.com
Can I have matrices and vectors A and x with compatible but unspecified dimensions. And get diff(x.T * A * x , x) return 2*A*x ?

Thanks,
Gustavo

Tim Lahey

unread,
Apr 28, 2014, 3:18:00 PM4/28/14
to sy...@googlegroups.com
It's only 2*A*x is A is symmetric (A.T = A). Otherwise it's (A.T + A). That said, I don't think Matrix Expressions support derivatives at the moment.

Cheers,

Tim.

Aaron Meurer

unread,
Apr 28, 2014, 8:37:17 PM4/28/14
to sy...@googlegroups.com
These little issues with the transpose are the reason this isn't
implemented yet.

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/340D188D-2402-47E1-829B-1E42297C89BD%40gmail.com.
> For more options, visit https://groups.google.com/d/optout.

Matthew Rocklin

unread,
Apr 29, 2014, 12:01:33 AM4/29/14
to sy...@googlegroups.com
I'd love to have someone implement matrix derivative.  This shouldn't be hard for someone who understands them well.


Tim Lahey

unread,
Apr 29, 2014, 12:46:04 AM4/29/14
to sy...@googlegroups.com
I know how to handle x.T*A and A*x, but I'm not sure how to handle the
derivative if it appears in the middle of an term. It probably can be
handled, but I think that case would get a bit messy.

Cheers,

Tim.
> https://groups.google.com/d/msgid/sympy/CAJ8oX-Hfp90LqkHcdW5TzcrTqxvV4yCMj5ZOCkN64JKGSps1Kg%40mail.gmail.com.

Aaron Meurer

unread,
May 3, 2014, 2:47:36 PM5/3/14
to sy...@googlegroups.com
I think it's all explained in the matrix cookbook. See
https://github.com/sympy/sympy/issues/5858. The question I have
regarding the cookbook is, what is the minimum set of rules that need
to be implemented from which the rest can be derived?

Aaron Meurer
> https://groups.google.com/d/msgid/sympy/56371E44-E58D-49BA-AFEA-B2782D64E596%40gmail.com.

Tim Lahey

unread,
May 3, 2014, 6:06:04 PM5/3/14
to sy...@googlegroups.com
I commented on that issue. That result is actually correct.

The problem I have with the matrix cookbook is that it's just a list of
results, with no explanation on how each are derived. I've never found a
good reference for this in general. If someone knows of one, I'd
appreciate it.

I think the latest version of the cookbook is slightly newer because
equation 61 doesn't match with the specific issue anymore.

Cheers,

Tim.
> https://groups.google.com/d/msgid/sympy/CAKgW%3D6%2BbpuP1Km2j5sSY5NkUSuJrg3Yjz87Cp_XZ-9%2BxirSatA%40mail.gmail.com.

Aaron Meurer

unread,
May 3, 2014, 8:07:45 PM5/3/14
to sy...@googlegroups.com
Wikipedia seemed to be OK the last time I looked at it. It even split
things out based on the two Jabobian conventions.

Aaron Meurer
> https://groups.google.com/d/msgid/sympy/E3B791F1-F116-4C61-9D14-A05B8FE3FF24%40gmail.com.

Tim Lahey

unread,
May 3, 2014, 8:12:52 PM5/3/14
to sy...@googlegroups.com
What's it categorized as in Wikipedia? I'll take a look.

Cheers,

Tim.
> https://groups.google.com/d/msgid/sympy/CAKgW%3D6LoN27sjbjG59GUnJqsQnAcbQ7JH443T_cQvXZKhov0eg%40mail.gmail.com.

Aaron Meurer

unread,
May 3, 2014, 8:25:00 PM5/3/14
to sy...@googlegroups.com
I guess I was thinking of
https://en.wikipedia.org/wiki/Matrix_derivative. I didn't read it too
closely, so I can't say too much about it. I was mostly just impressed
that it kept track of the identities for both conventions.

Aaron Meurer
> https://groups.google.com/d/msgid/sympy/67788538-8910-4451-BEA5-F01ECDF7CE56%40gmail.com.

Tim Lahey

unread,
May 3, 2014, 9:02:40 PM5/3/14
to sy...@googlegroups.com
Thanks,

I covers the basics pretty well, but the Matrix Cookbook has
considerably more involved identities that aren't explained. I'm going
to check out some of the references and hopefully find more details.

Cheers,

Tim.
> https://groups.google.com/d/msgid/sympy/CAKgW%3D6%2B-6b-B%2BrbeAFx0n4UO_Am5zz%3DLFpDDHWeoxZdkQNe1Qw%40mail.gmail.com.

Alan Bromborsky

unread,
May 3, 2014, 10:52:00 PM5/3/14
to sy...@googlegroups.com
XLatexIt! run report...
*** Found expression $ij$
The basic definition should be that the directional derivative of of a matrix valued function of a matrix is

   $$
        \lim_{h\rightarrow 0} \frac{F(A+hB)}{h}$$

where the directional derivative is in the direction of the matrix $B$ and $A$ and $B$ must have the same dimension.  The if $B$ is decomposed into components $B_{ij}$ (components of a vector or matrix) then

$$\lim_{h\rightarrow 0}\frac{F(A+hB_{ij})}{h}$$

are the $ij$ components of the derivative.  I did not put any expression to the left of the limits due to notational uncertainty.

Tim Lahey

unread,
May 3, 2014, 11:12:29 PM5/3/14
to sy...@googlegroups.com
On 3 May 2014, at 22:52, Alan Bromborsky wrote:

> X <#>LatexIt! run report...
>
> *** Found expression $ij$
>
> The basic definition should be that the directional derivative of of a
> matrix valued function of a matrix is
>
> $$ \lim_{h\rightarrow 0} \frac{F(A+hB)}{h}$$
>
> where the directional derivative is in the direction of the matrix $B$
> and $A$ and $B$ must have the same dimension. The if $B$ is
> decomposed into components $B_{ij}$ (components of a vector or matrix)
> then
>
> $$\lim_{h\rightarrow 0}\frac{F(A+hB_{ij})}{h}$$
>
> are the $ij$ components of the derivative. I did not put any
> expression to the left of the limits due to notational uncertainty.

This is the basics, which I understand quite well. The problem is that
the Matrix Cookbook has lots of identities which are just stated, many
of which involve inverses and transposes (sometimes at the same time),
so it's not a simple exercise to derive them.

The one in the issue that Aaron referenced

diff(A.T*x,x) = A.T

which I guess the Cookbook had as A (not A.T), is simple enough. It's
quite easy to derive and show that it should be A.T for a general
matrix.

It seems that there isn't one good reference for general matrix
calculus. It seems that there's individual references for specific
aspects. I've looked through most of the Wikipedia page references, I'll
have to look through the references for the Matrix Cookbook next.

Thanks,

Tim.

Aaron Meurer

unread,
May 12, 2014, 3:12:52 AM5/12/14
to sy...@googlegroups.com
Actually, that's a good point. What we need for SymPy, as I've noted
before, is a minimal set of identities from which the rest can be
derived. I think what is needed is a simple minimal set of identities,
which are all derived manually from the definitions, and then the rest
which are just shown algebraically from those identities. Seeing those
derivations explicitly should make it easier to understand how to
implement them. Let us know if you find a good resource.

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/F9C1C872-E83E-4423-81F4-A15BF061DFF6%40gmail.com.

Alan Bromborsky

unread,
May 13, 2014, 3:43:53 PM5/13/14
to sy...@googlegroups.com
See section 11.1.2 from "Geometric Algebra for Physicists" by Doran and
Lasenby. This has an approach for taking the
derivative with respect to a linear function (matrix).
linearfunctionderiv.pdf
Reply all
Reply to author
Forward
0 new messages