Skip to content
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

Added three functions for linalg: SVD, Least Squares and PseudoInverse #258

Closed
wants to merge 1 commit into from

Conversation

wolfv
Copy link
Member

@wolfv wolfv commented Jun 13, 2015

SVD is only numeric and implemented via mpmath. Not sure if that's acceptable or not? Might need a check, too.

matrix = to_mpmath_matrix(m)
U, S, V = mp.svd(matrix)
S = mp.diag(S)
print(U, S, V)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to remove this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, thanks!

@sn6uv
Copy link
Member

sn6uv commented Jun 14, 2015

Sympy implements the singular value decomposition for exact inputs, see here. We should probably us this version if the argument is exact and the mpmath version otherwise.

Edit: Can never get the md hyperlink syntax right.

@sn6uv
Copy link
Member

sn6uv commented Jun 14, 2015

Also, we have a helper class function for wrapping Sympy functions. It's called SympyFunction and is defined in mathics/builtin/base.py.

There's also _MPMathFunction which subclasses SympyFunction and will use the relevant Sympy or mpmath functions depending on the 'exactness' of the arguments. There are heaps of examples scattered rountd In particular look in mathics/builtin/specialfunctions.py

I'm happy to help with this. Let me know if you have any questions.

@wolfv
Copy link
Member Author

wolfv commented Jun 14, 2015

Hey,

actually the function you're linking is the one I am using. But if you look closely, it's the mpmath Matrix package of sympy and unfortunately not the sympy Matrix... Took me some time to realize, too.

So I guess at least sympy doesn't have a algebraic solution up to now.

@sn6uv
Copy link
Member

sn6uv commented Jun 14, 2015

Oh, you're right sorry. I see there's an Sympy issue sympy/sympy#6832 to track this missing functionality. The only option we have is to provide the numerical SVD (as you've done).

</dl>

>> SingularValueDecomposition[{{1, 2}, {2, 3}, {3, 4}}]
= {{-11 / 6, -1 / 3, 7 / 6}, {4 / 3, 1 / 3, -2 / 3}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is failing (because we get inexact answers). It's nice to have the tests pass, and unfortunately in the current system there's no way to mark a test as xfail. I'd suggest adding a Line before this test explaining why the results are inexact, and then testing the inexact results.

Let me know if that's unclear.

@sn6uv sn6uv added this to the 0.9 milestone Jul 11, 2015
@sn6uv sn6uv mentioned this pull request Feb 14, 2016
4 tasks
@sn6uv
Copy link
Member

sn6uv commented Feb 14, 2016

Ideally I'd like to get this one into 0.9 too.

@sn6uv sn6uv mentioned this pull request Feb 18, 2016
@sn6uv
Copy link
Member

sn6uv commented Feb 18, 2016

Opened #321.

@sn6uv sn6uv closed this Feb 18, 2016
sn6uv added a commit that referenced this pull request Feb 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants