-
Notifications
You must be signed in to change notification settings - Fork 133
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
Norm method format #54
Comments
@minivan I know little about matrix norms, but I think that the suggested API is interesting. A few questions:
Go ahead. When you have some code or doubt about NMatrix's API, please send a message to the mailing list. Thank you! |
I like this proposal. I'd say |
Hey @minivan, are you still interested in this? :) |
@agarie absolutely, but I got a bit stuck with porting a LAPACK function and getting the data types all correct for the |
@minivan |
@lazywei Looking at his fork, I don't see a branch that wasn't created by me or by John. So, I think you could start something on your own* and post your progress here (or as a pull request).
|
No work has been done on this in six months. Is anyone interested in finishing this? Otherwise I'm closing. |
I am interested! I agree with the format proposed by the initial post: mat = NMatrix.new([2, 2], [1, 2, 4, 8])
mat.norm # norm with p = 2
mat.norm 3 # norm with p = 3
mat.norm :inf # infinity norm
mat.norm :fro # Frobenius norm Symbols for norm names would be also accepted by their full names and case insensitive. I intend to implement the p-norm, frobenius (which would run the same code for p-norms) and max norm. Is that sufficient for a first stage? |
As an FYI, the 2-norm has been implemented for vectors: Line 535 in 18743e0
It's partially tested here: Line 140 in 55417c3
but note that this is not the way we want future tests to be written. Those should look more like this one: https://github.com/SciRuby/nmatrix/blob/master/spec/00_nmatrix_spec.rb#L476 (and note also that as I linked that I discovered the one after that is not properly named). I think your proposal sounds good. Go for it. =) |
My first attempt has been pushed! I added my implementation at the math.rb file, thought it was better than writing to the core NMatrix file. Check my nmatrix fork for the whole thing. Here are the gist pastes: I compared my output with the output at MATLAB. I might have mistaken something in the way I implemented. In all cases of the infinity norm my output was the same with MATLAB's. But when it comes to p-norms the results differ after the second decimal place. So I had to "hard-code" the values at the relevant tests. So, is MATLAB a good way to test the output? I couldn't find a way to test p-norms for values over 2. Seems like I miss something from the relevant theory because they are not commonly implemented. |
Couple of thoughts:
In general, a very good first attempt! Hopefully these tips are useful. |
mat = NMatrix.new([2, 2], [1, 2, 4, 8])
mat.norm # the “spectral” or 2-norm, which is the largest singular value of mat
mat.norm 2 # same as above
mat.norm 1 # one norm (absolute column sum)
mat.norm :inf # infinity norm (absolute row sum)
mat.norm :fro # Frobenius norm (the Euclidean norm of mat treated as if it were a vector) The implementation of vector norms should be independent from this. Towards which branch should I request the pull? I'll request it on the master branch for now. I used gists because I didn't feel my work was worthy enough to appear in the main repository before you reviewed it. But I guess you can just reject the request if that's the case? Thanks for the feedback! :) |
Yes. Protected functions outside of the norm method. Another concern I have is that you're doing column traversal for the 1-norm. This will be a fairly efficient operation for dense, but inefficient for list and especially yale. It may be that you wish to simply copy-transpose yale and list matrices and calculate the norm on the basis of rows instead. |
Cool, I'll work on these two things as soon as possible and drop a line at the pull request when I have news. |
Hey everyone,
I'd like to implement a norm method for
NMatrix
and would like to ask for your assistance.How do you see the function? At the moment, here's what I think:
What do you think?
The text was updated successfully, but these errors were encountered: