New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MatrixSymbol Needs Differentiation Ability #10509

Closed
dusenberrymw opened this Issue Feb 2, 2016 · 11 comments

Comments

Projects
None yet
4 participants
@dusenberrymw
Copy link

dusenberrymw commented Feb 2, 2016

Currently, it does not appear to be possible to take a partial derivative of an expression of MatrixSymbols, failing with the error 'MatrixSymbol' object has no attribute '_diff_wrt'.

The following example highlights this:

A = MatrixSymbol('A', 3, 2)
B = MatrixSymbol('B', 2, 3)
expr = A*B
diff(expr, A)
...
AttributeError: 'MatrixSymbol' object has no attribute '_diff_wrt'

This would be great for the project to have, especially for those working with vectorized functions.

@moorepants

This comment has been minimized.

Copy link
Member

moorepants commented Feb 2, 2016

What is your expected answer for the above example?

Are you requesting this: https://en.wikipedia.org/wiki/Matrix_calculus#Scalar-by-matrix?

@asmeurer

This comment has been minimized.

Copy link
Member

asmeurer commented Feb 4, 2016

Related (or possibly a duplicate) #5858

@asmeurer

This comment has been minimized.

Copy link
Member

asmeurer commented Feb 4, 2016

Actually I'm going to say that this is a duplicate.

@asmeurer asmeurer closed this Feb 4, 2016

@asmeurer asmeurer added the duplicate label Feb 4, 2016

@dusenberrymw

This comment has been minimized.

Copy link

dusenberrymw commented Feb 10, 2016

@moorepants Apologies for the delay. As a followup, I would expect B for the given expression dA*B/dB.

@asmeurer Thanks. From the opening post (~2011) on that PR, it looks like differentiation on MatrixSymbols was once possible (albeit, possibly incorrect). Was this removed at some point?

@megh1241 megh1241 referenced this issue Feb 17, 2016

Closed

eval derivative wrt modified #7437 b #10594

0 of 6 tasks complete
@asmeurer

This comment has been minimized.

Copy link
Member

asmeurer commented Feb 23, 2016

It did work but it was completely wrong, so we removed it (non-behavior is better than wrong answers).

@dusenberrymw

This comment has been minimized.

Copy link

dusenberrymw commented Feb 27, 2016

@asmeurer Agreed. Incorrect behavior is worse than lack of functionality.

@moorepants

This comment has been minimized.

Copy link
Member

moorepants commented Dec 4, 2018

Just saw this paper:

http://www.matrixcalculus.org/matrixcalculus.pdf

and website:

http://www.matrixcalculus.org/matrixCalculus

SymPy should be able to do these things and the code gen the results.

@asmeurer

This comment has been minimized.

Copy link
Member

asmeurer commented Dec 4, 2018

@Upabjojr has been doing a lot of work on this recently. A lot of these things may already work. Also see the new sympy.codegen.array_utils module.

@Upabjojr

This comment has been minimized.

Copy link
Contributor

Upabjojr commented Dec 7, 2018

My approach is probably very buggy. We should replace it with that algorithm.

Anyway, I would keep the work on a parser for indexed expressions, that could be extremely useful in certain cases.

@asmeurer

This comment has been minimized.

Copy link
Member

asmeurer commented Dec 11, 2018

Yes, I think it could be useful for taking an expression that manipulates an ndarray (for instance, using something like uarray, or even just parsing some code) and translating it into a high level tensor or matrix expression.

@Upabjojr

This comment has been minimized.

Copy link
Contributor

Upabjojr commented Dec 11, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment