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

MatrixSingularException when column is 0 all at pinv #304

Closed
y-shimizu opened this issue Aug 31, 2014 · 2 comments
Closed

MatrixSingularException when column is 0 all at pinv #304

y-shimizu opened this issue Aug 31, 2014 · 2 comments

Comments

@y-shimizu
Copy link

Hi,

I wanted to compute the Moore-Penrose pseudo inverse of a Matrix.
But I am troubled by the exception:

val m = DenseMatrix((0d,3d,6d), (0d,4d,7d), (0d,5d,9d))
val mi = pinv(m)


>Exception in thread "main" breeze.linalg.MatrixSingularException: 
>   at breeze.linalg.operators.DenseMatrixMultiplyStuff$implOpSolveMatrixBy_DMD_DMD_eq_DMD$.LUSolve(DenseMatrixOps.scala:145)
>   at breeze.linalg.operators.DenseMatrixMultiplyStuff$implOpSolveMatrixBy_DMD_DMD_eq_DMD$.apply(DenseMatrixOps.scala:119)
>   at breeze.linalg.operators.DenseMatrixMultiplyStuff$implOpSolveMatrixBy_DMD_DMD_eq_DMD$.apply(DenseMatrixOps.scala:107)
>   at breeze.linalg.NumericOps$class.$bslash(NumericOps.scala:270)
>   at breeze.linalg.DenseMatrix.$bslash(DenseMatrix.scala:54)
>   at breeze.linalg.pinv$$anon$2.apply(inv.scala:79)
>   at breeze.generic.UFunc$class.apply(UFunc.scala:48)
>   at breeze.linalg.pinv$.apply(inv.scala:54)
>   at Test$.delayedEndpoint$Test$1(Test.scala:11)
>   at Test$delayedInit$body.apply(Test.scala:3)
>   at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
>   at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
>   at scala.App$$anonfun$main$1.apply(App.scala:76)
>   at scala.App$$anonfun$main$1.apply(App.scala:76)
>   at scala.collection.immutable.List.foreach(List.scala:381)
>   at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:35)
>   at scala.App$class.main(App.scala:76)
>   at Test$.main(Test.scala:3)
>   at Test.main(Test.scala)
>   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>   at java.lang.reflect.Method.invoke(Method.java:597)
>   at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)

I wanted to get matrix [(0, 0, 0) (-2.526316,1.4210526,0.5789474), (1.421053, -0.7368421, -0.2631579)]
like R:

> m <- rbind(c(0,3,6), c(0,4,7), c(0,5,9))
> ginv(m)
          [,1]       [,2]       [,3]
[1,]  0.000000  0.0000000  0.0000000
[2,] -2.526316  1.4210526  0.5789474
[3,]  1.421053 -0.7368421 -0.2631579

Please tell me why is the implementation different from pinv and R:ginv .

@dlwh
Copy link
Member

dlwh commented Sep 2, 2014

looks like the correct way to implement pinv is not with the usual
mathematical formula (as we currently do), but with an svd:
http://the-lost-beauty.blogspot.com/2009/04/moore-penrose-pseudoinverse-in-jama.html

We should fix this.

On Sun, Aug 31, 2014 at 5:07 AM, y-shimizu notifications@github.com wrote:

Hi,

I wanted to compute the Moore-Penrose pseudo inverse of a Matrix.
But I am troubled by the exception:

val m = DenseMatrix((0d,3d,6d), (0d,4d,7d), (0d,5d,9d))
val mi = pinv(m)

Exception in thread "main" breeze.linalg.MatrixSingularException:
at breeze.linalg.operators.DenseMatrixMultiplyStuff$implOpSolveMatrixBy_DMD_DMD_eq_DMD$.LUSolve(DenseMatrixOps.scala:145)
at breeze.linalg.operators.DenseMatrixMultiplyStuff$implOpSolveMatrixBy_DMD_DMD_eq_DMD$.apply(DenseMatrixOps.scala:119)
at breeze.linalg.operators.DenseMatrixMultiplyStuff$implOpSolveMatrixBy_DMD_DMD_eq_DMD$.apply(DenseMatrixOps.scala:107)
at breeze.linalg.NumericOps$class.$bslash(NumericOps.scala:270)
at breeze.linalg.DenseMatrix.$bslash(DenseMatrix.scala:54)
at breeze.linalg.pinv$$anon$2.apply(inv.scala:79)
at breeze.generic.UFunc$class.apply(UFunc.scala:48)
at breeze.linalg.pinv$.apply(inv.scala:54)
at Test$.delayedEndpoint$Test$1(Test.scala:11)
at Test$delayedInit$body.apply(Test.scala:3)
at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
at scala.App$$anonfun$main$1.apply(App.scala:76)
at scala.App$$anonfun$main$1.apply(App.scala:76)
at scala.collection.immutable.List.foreach(List.scala:381)
at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:35)
at scala.App$class.main(App.scala:76)
at Test$.main(Test.scala:3)
at Test.main(Test.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)

I wanted to get matrix [(0, 0, 0) (-2.526316,1.4210526,0.5789474),
(1.421053, -0.7368421, -0.2631579)]
like R:

m <- rbind(c(0,3,6), c(0,4,7), c(0,5,9))
ginv(m)
[,1] [,2] [,3]
[1,] 0.000000 0.0000000 0.0000000
[2,] -2.526316 1.4210526 0.5789474
[3,] 1.421053 -0.7368421 -0.2631579

Please tell me why is the implementation different from pinv and R:ginv .


Reply to this email directly or view it on GitHub
#304.

@y-shimizu
Copy link
Author

@dlwh
Thank you for comment.
I will try this.

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

No branches or pull requests

2 participants