SciRuby / nmatrix

Dense and sparse linear algebra library for Ruby via SciRuby
Other
469 stars 133 forks source link

#positive_definite?, #positive_semidefinite?, #rank_deficient? #411

Open translunar opened 8 years ago

translunar commented 8 years ago

These methods, among others, would be useful for users wanting to check matrix properties.

johnmarinelli commented 8 years ago

Hi! I'd like to take a shot at this. I think I can have something to show within a week or two.

translunar commented 8 years ago

Wonderful! Thanks so much for getting involved. =D

johnmarinelli commented 8 years ago

@mohawkjohn Hey! I'm afraid I don't understand what the second parameter of NMatrix::rank is supposed to do, but if I can use that function to calculate the rank of the matrix then rank_deficient? would be really easy to implement.

translunar commented 8 years ago

#rank basically allows you to iterate along either rows or columns or through the depth of the tensor if it's more than 2-dimensional. So the first argument is row, column, or depth; and the second argument is which one of those. If you do rank(0,1), it gives you row 1. If you do rank(1,5), it gives you column 5. If you do rank(2,1), you get layer 1. Make sense?

johnmarinelli commented 8 years ago

@mohawkjohn yep, perfect sense! I ended up using the gesvd to calculate rank. Since this needs the nmatrix/lapacke gem, I have a couple of questions - 1) Is that okay? Or did you want it to be implemented without the lapacke dependency? 2) How can I test the nmatrix functions that require lapacke? The tests that are already in place catch a NotImplementedException, even though I have the nmatrix-lapacke gem installed.

wlevine commented 8 years ago

You can run the tests with rake spec nmatrix_plugins=lapacke which will require the nmatrix/lapacke gem On Dec 7, 2015 4:16 PM, "John Marinelli" notifications@github.com wrote:

@mohawkjohn https://github.com/mohawkjohn yep, perfect sense! I ended up using the gesvd to calculate rank. Since this needs the nmatrix/lapacke gem, I have a couple of questions - 1) Is that okay? Or did you want it to be implemented without the lapacke dependency? 2) How can I test the nmatrix functions that require lapacke? The tests that are already in place give me a NotImplementedException, even though I have the nmatrix-lapacke gem installed.

— Reply to this email directly or view it on GitHub https://github.com/SciRuby/nmatrix/issues/411#issuecomment-162666139.

translunar commented 8 years ago

Is using gesvd the most economical way to calculate rank?

johnmarinelli commented 8 years ago

@mohawkjohn , well, I know there are a variety of ways to calculate whether or not a matrix is full rank or not; but I thought that SVD was the only way to calculate rank?

translunar commented 8 years ago

Yup, you're right. Had to check my reference. =) Yes, lapacke sounds good.

johnmarinelli commented 8 years ago

@mohawkjohn sounds good; i will continue to push on :) @wlevine thanks!