-
Notifications
You must be signed in to change notification settings - Fork 134
Matrix norms implementation #204
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
Conversation
|
I converted the lambdas to protected functions. Now I am trying to manipulate yale and list matrices when calculating the one norm. Is there a specific method which returns the |
|
Good. One more change, if you would. Best practice is to use full words ( Thanks! |
lib/nmatrix/math.rb
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you break this line into two? Keeping a limit of 80 characters per line is good practice!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I was wondering what's the exact limit anyway. Will commit this along with the planned changes I am working with now. :)
|
Done! I also added some |
|
Can I have some feedback please? :) |
lib/nmatrix/math.rb
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty sure you can rearrange this giant if-else into a case expression:
case type
when nil then self.two_norm
when 1 then self.one_norm
when 2 then self.two_norm
when :frobenius, :fro then self.fro_norm
endPlay with it for some time. Ruby's case expressions are very cool. 🎉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about this the other day. You're right, I'll push a commit in a few minutes. :)
|
Well, it looks sooo much better now. Thanks for the tip @agarie! :-) |
lib/nmatrix/math.rb
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you creating an NMatrix of arrays here? That's what it looks like, and it seems unsafe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it's the NMatrix on which the norm calculation occurs, converted into a column vector. A column is appended per iteration. Should I change this to an 1xn NMatrix?
|
Fixed bad calculations and added some more. It was done based on SciPy's documentation for the relevant method: https://github.com/numpy/numpy/blob/v1.8.0/numpy/linalg/linalg.py#L1924 Should I reference their code somewhere? I didn't copy anything, I just tested my results against theirs. MATLAB totally avoided. :)
|
lib/nmatrix/math.rb
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is inefficient. Create the NMatrix but without default values, since you know its final shape, and insert the values directly. You're doing array construction, array resizing, and then NMatrix initialization from that array, which is an order of magnitude more expensive than necessary.
|
It's extremely bizarre that the results would differ from those in SciPy. What method are they using to perform this calculation? And yes, I think if you do a |
|
Arrays exterminated! =) Besides that, after doing some tests today, I discovered the svd results' bias might be a precision issue. Defaulting the Furthermore, I guess there is an overflow issue when it comes to the lowest singular value because for |
|
Is the feature fully implemented ? If it is not, I would really like to contribute. |
|
I never got to finish it since I did not get any answer to my last questions and was unable to "dive deeper" on my own. Now I have other obligations and I guess I can't keep working on this. From my side: you're good to go. I guess @MohawkJohn will not have any objections either. :) Good luck! |
|
@MohawkJohn Could you please guide me a little, because I am completely new to open source and is completely clueless at the moment on how to proceed. What all modifications can I do ? |
|
@abhinavagarwalla Hey, sorry, somehow I missed your comment. Are you still working on this? |
|
Is it really necessary to compare float64 results to 16th decimal place? I think we should change the test to compare the difference between the expected result and and the computed result and accept it if it falls below a sensible threshold (say, 1.0e-10) and then call it a day. Thoughts? I'd be happy to put that in if that's the only thing holding this up. |
|
New PR at #400. |
|
Should this be closed? Outdated. |
Progress on #54! Read the issue comments for more info on the progress so far. The numbers in the tests were compared with the results of the same runs in MATLAB.
Looks like the singular values returned by MATLAB's
svdand LAPACK'sgesvddiffer after some decimal places. Any feedback on that?