You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Dieter Vandenbussche (JIRA)" <ji...@apache.org> on 2009/11/10 16:43:27 UTC

[jira] Created: (MATH-320) NaN singular value from SVD

NaN singular value from SVD
---------------------------

                 Key: MATH-320
                 URL: https://issues.apache.org/jira/browse/MATH-320
             Project: Commons Math
          Issue Type: Bug
    Affects Versions: 2.0
         Environment: Linux (Ubuntu 9.10) java version "1.6.0_16"
            Reporter: Dieter Vandenbussche


The following jython code
## Start code
from org.apache.commons.math.linear import *
 
Alist = [[1.0, 2.0, 3.0],[2.0,3.0,4.0],[3.0,5.0,7.0]]
 
A = Array2DRowRealMatrix(Alist)
 
decomp = SingularValueDecompositionImpl(A)
 
print decomp.getSingularValues()
## End code
prints
array('d', [11.218599757513008, 0.3781791648535976, nan])
The last singular value should be something very close to 0 since the matrix
is rank deficient.  When i use the result from getSolver() to solve a system, i end 
up with a bunch of NaNs in the solution.  I assumed i would get back a least squares solution.

Does this SVD implementation require that the matrix be full rank?  If so, then i would expect
an exception to be thrown from the constructor or one of the methods.




-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (MATH-320) NaN singular value from SVD

Posted by "Dieter Vandenbussche (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-320?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12776449#action_12776449 ] 

Dieter Vandenbussche commented on MATH-320:
-------------------------------------------

Yes, making that change fixes the singular values, printing the singular values now gives

array('d', [11.218599757513008, 0.3781791648535976, 0.0])

The unittests for the project still pass as well.

However, now the solve fails with a SinularMatrixException

Traceback (most recent call last):
  File "testdecomp.py", line 14, in <module>
    soln = solver.solve([5.0, 6.0,7.0])
	at org.apache.commons.math.linear.SingularValueDecompositionImpl$Solver.solve(SingularValueDecompositionImpl.java:371)
	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)

org.apache.commons.math.linear.SingularMatrixException: org.apache.commons.math.linear.SingularMatrixException: matrix is singular

This confuses me, i guess i'm assuming incorrectly that if the solve method can solve in the least squares sense, then it should be
able to handle singular matrices.  Is that just a restriction on the current solve methods and if so, are there plans to relax that restriction?

thanks very much for your time

> NaN singular value from SVD
> ---------------------------
>
>                 Key: MATH-320
>                 URL: https://issues.apache.org/jira/browse/MATH-320
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 2.0
>         Environment: Linux (Ubuntu 9.10) java version "1.6.0_16"
>            Reporter: Dieter Vandenbussche
>
> The following jython code
> Start code
> from org.apache.commons.math.linear import *
>  
> Alist = [[1.0, 2.0, 3.0],[2.0,3.0,4.0],[3.0,5.0,7.0]]
>  
> A = Array2DRowRealMatrix(Alist)
>  
> decomp = SingularValueDecompositionImpl(A)
>  
> print decomp.getSingularValues()
> End code
> prints
> array('d', [11.218599757513008, 0.3781791648535976, nan])
> The last singular value should be something very close to 0 since the matrix
> is rank deficient.  When i use the result from getSolver() to solve a system, i end 
> up with a bunch of NaNs in the solution.  I assumed i would get back a least squares solution.
> Does this SVD implementation require that the matrix be full rank?  If so, then i would expect
> an exception to be thrown from the constructor or one of the methods.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (MATH-320) NaN singular value from SVD

Posted by "Luc Maisonobe (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/MATH-320?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Luc Maisonobe resolved MATH-320.
--------------------------------

    Resolution: Fixed

This should be fixed in subversion repository now (r894908).
Thanks for reporting the bug and sorry for the delay.

> NaN singular value from SVD
> ---------------------------
>
>                 Key: MATH-320
>                 URL: https://issues.apache.org/jira/browse/MATH-320
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 2.0
>         Environment: Linux (Ubuntu 9.10) java version "1.6.0_16"
>            Reporter: Dieter Vandenbussche
>
> The following jython code
> Start code
> from org.apache.commons.math.linear import *
>  
> Alist = [[1.0, 2.0, 3.0],[2.0,3.0,4.0],[3.0,5.0,7.0]]
>  
> A = Array2DRowRealMatrix(Alist)
>  
> decomp = SingularValueDecompositionImpl(A)
>  
> print decomp.getSingularValues()
> End code
> prints
> array('d', [11.218599757513008, 0.3781791648535976, nan])
> The last singular value should be something very close to 0 since the matrix
> is rank deficient.  When i use the result from getSolver() to solve a system, i end 
> up with a bunch of NaNs in the solution.  I assumed i would get back a least squares solution.
> Does this SVD implementation require that the matrix be full rank?  If so, then i would expect
> an exception to be thrown from the constructor or one of the methods.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (MATH-320) NaN singular value from SVD

Posted by "Axel Kramer (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-320?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12795591#action_12795591 ] 

Axel Kramer commented on MATH-320:
----------------------------------

This statement should print the values of the original matrix approximately:
{code:java} 
  System.out.println(svd.getU().multiply(svd.getS()).multiply(svd.getVT()));
{code} 

This is true for
{code:java} 
    public void testMath320A() {
{code} 
but not for
{code:java} 
    public void testMath320B() {
{code} 

> NaN singular value from SVD
> ---------------------------
>
>                 Key: MATH-320
>                 URL: https://issues.apache.org/jira/browse/MATH-320
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 2.0
>         Environment: Linux (Ubuntu 9.10) java version "1.6.0_16"
>            Reporter: Dieter Vandenbussche
>
> The following jython code
> Start code
> from org.apache.commons.math.linear import *
>  
> Alist = [[1.0, 2.0, 3.0],[2.0,3.0,4.0],[3.0,5.0,7.0]]
>  
> A = Array2DRowRealMatrix(Alist)
>  
> decomp = SingularValueDecompositionImpl(A)
>  
> print decomp.getSingularValues()
> End code
> prints
> array('d', [11.218599757513008, 0.3781791648535976, nan])
> The last singular value should be something very close to 0 since the matrix
> is rank deficient.  When i use the result from getSolver() to solve a system, i end 
> up with a bunch of NaNs in the solution.  I assumed i would get back a least squares solution.
> Does this SVD implementation require that the matrix be full rank?  If so, then i would expect
> an exception to be thrown from the constructor or one of the methods.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (MATH-320) NaN singular value from SVD

Posted by "Phil Steitz (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/MATH-320?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Phil Steitz updated MATH-320:
-----------------------------

    Fix Version/s: 2.1

> NaN singular value from SVD
> ---------------------------
>
>                 Key: MATH-320
>                 URL: https://issues.apache.org/jira/browse/MATH-320
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 2.0
>         Environment: Linux (Ubuntu 9.10) java version "1.6.0_16"
>            Reporter: Dieter Vandenbussche
>             Fix For: 2.1
>
>
> The following jython code
> Start code
> from org.apache.commons.math.linear import *
>  
> Alist = [[1.0, 2.0, 3.0],[2.0,3.0,4.0],[3.0,5.0,7.0]]
>  
> A = Array2DRowRealMatrix(Alist)
>  
> decomp = SingularValueDecompositionImpl(A)
>  
> print decomp.getSingularValues()
> End code
> prints
> array('d', [11.218599757513008, 0.3781791648535976, nan])
> The last singular value should be something very close to 0 since the matrix
> is rank deficient.  When i use the result from getSolver() to solve a system, i end 
> up with a bunch of NaNs in the solution.  I assumed i would get back a least squares solution.
> Does this SVD implementation require that the matrix be full rank?  If so, then i would expect
> an exception to be thrown from the constructor or one of the methods.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (MATH-320) NaN singular value from SVD

Posted by "Luc Maisonobe (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-320?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12776063#action_12776063 ] 

Luc Maisonobe commented on MATH-320:
------------------------------------

This is a real new bug, thanks for reporting it.

Before I look more precisely at it, could you do a quick check for me ?

If at the end of the SingularValueDecompositionImpl constructor, around line 118 in the java source file you change from:
{noformat}
  singularValues[i] = Math.sqrt(singularValues[i]);
{noformat}
to
{noformat}
  singularValues[i] = Math.sqrt(Math.max(0, singularValues[i]));
{noformat}

does the problem still appear on singular values and does the solver work properly ?

> NaN singular value from SVD
> ---------------------------
>
>                 Key: MATH-320
>                 URL: https://issues.apache.org/jira/browse/MATH-320
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 2.0
>         Environment: Linux (Ubuntu 9.10) java version "1.6.0_16"
>            Reporter: Dieter Vandenbussche
>
> The following jython code
> Start code
> from org.apache.commons.math.linear import *
>  
> Alist = [[1.0, 2.0, 3.0],[2.0,3.0,4.0],[3.0,5.0,7.0]]
>  
> A = Array2DRowRealMatrix(Alist)
>  
> decomp = SingularValueDecompositionImpl(A)
>  
> print decomp.getSingularValues()
> End code
> prints
> array('d', [11.218599757513008, 0.3781791648535976, nan])
> The last singular value should be something very close to 0 since the matrix
> is rank deficient.  When i use the result from getSolver() to solve a system, i end 
> up with a bunch of NaNs in the solution.  I assumed i would get back a least squares solution.
> Does this SVD implementation require that the matrix be full rank?  If so, then i would expect
> an exception to be thrown from the constructor or one of the methods.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (MATH-320) NaN singular value from SVD

Posted by "Luc Maisonobe (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-320?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12792132#action_12792132 ] 

Luc Maisonobe commented on MATH-320:
------------------------------------

The two issues are probably related.
I'll look at both cases.

> NaN singular value from SVD
> ---------------------------
>
>                 Key: MATH-320
>                 URL: https://issues.apache.org/jira/browse/MATH-320
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 2.0
>         Environment: Linux (Ubuntu 9.10) java version "1.6.0_16"
>            Reporter: Dieter Vandenbussche
>
> The following jython code
> Start code
> from org.apache.commons.math.linear import *
>  
> Alist = [[1.0, 2.0, 3.0],[2.0,3.0,4.0],[3.0,5.0,7.0]]
>  
> A = Array2DRowRealMatrix(Alist)
>  
> decomp = SingularValueDecompositionImpl(A)
>  
> print decomp.getSingularValues()
> End code
> prints
> array('d', [11.218599757513008, 0.3781791648535976, nan])
> The last singular value should be something very close to 0 since the matrix
> is rank deficient.  When i use the result from getSolver() to solve a system, i end 
> up with a bunch of NaNs in the solution.  I assumed i would get back a least squares solution.
> Does this SVD implementation require that the matrix be full rank?  If so, then i would expect
> an exception to be thrown from the constructor or one of the methods.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Closed: (MATH-320) NaN singular value from SVD

Posted by "Phil Steitz (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/MATH-320?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Phil Steitz closed MATH-320.
----------------------------


> NaN singular value from SVD
> ---------------------------
>
>                 Key: MATH-320
>                 URL: https://issues.apache.org/jira/browse/MATH-320
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 2.0
>         Environment: Linux (Ubuntu 9.10) java version "1.6.0_16"
>            Reporter: Dieter Vandenbussche
>             Fix For: 2.1
>
>
> The following jython code
> Start code
> from org.apache.commons.math.linear import *
>  
> Alist = [[1.0, 2.0, 3.0],[2.0,3.0,4.0],[3.0,5.0,7.0]]
>  
> A = Array2DRowRealMatrix(Alist)
>  
> decomp = SingularValueDecompositionImpl(A)
>  
> print decomp.getSingularValues()
> End code
> prints
> array('d', [11.218599757513008, 0.3781791648535976, nan])
> The last singular value should be something very close to 0 since the matrix
> is rank deficient.  When i use the result from getSolver() to solve a system, i end 
> up with a bunch of NaNs in the solution.  I assumed i would get back a least squares solution.
> Does this SVD implementation require that the matrix be full rank?  If so, then i would expect
> an exception to be thrown from the constructor or one of the methods.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (MATH-320) NaN singular value from SVD

Posted by "Luc Maisonobe (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-320?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12776462#action_12776462 ] 

Luc Maisonobe commented on MATH-320:
------------------------------------

The method should solve the problem in the least square sense.
The fact it does not do it is not a restriction, it's a bug.
I'll have a look at it

> NaN singular value from SVD
> ---------------------------
>
>                 Key: MATH-320
>                 URL: https://issues.apache.org/jira/browse/MATH-320
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 2.0
>         Environment: Linux (Ubuntu 9.10) java version "1.6.0_16"
>            Reporter: Dieter Vandenbussche
>
> The following jython code
> Start code
> from org.apache.commons.math.linear import *
>  
> Alist = [[1.0, 2.0, 3.0],[2.0,3.0,4.0],[3.0,5.0,7.0]]
>  
> A = Array2DRowRealMatrix(Alist)
>  
> decomp = SingularValueDecompositionImpl(A)
>  
> print decomp.getSingularValues()
> End code
> prints
> array('d', [11.218599757513008, 0.3781791648535976, nan])
> The last singular value should be something very close to 0 since the matrix
> is rank deficient.  When i use the result from getSolver() to solve a system, i end 
> up with a bunch of NaNs in the solution.  I assumed i would get back a least squares solution.
> Does this SVD implementation require that the matrix be full rank?  If so, then i would expect
> an exception to be thrown from the constructor or one of the methods.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (MATH-320) NaN singular value from SVD

Posted by "Dieter Vandenbussche (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/MATH-320?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Dieter Vandenbussche updated MATH-320:
--------------------------------------

    Description: 
The following jython code
Start code

from org.apache.commons.math.linear import *
 
Alist = [[1.0, 2.0, 3.0],[2.0,3.0,4.0],[3.0,5.0,7.0]]
 
A = Array2DRowRealMatrix(Alist)
 
decomp = SingularValueDecompositionImpl(A)
 
print decomp.getSingularValues()

End code

prints
array('d', [11.218599757513008, 0.3781791648535976, nan])
The last singular value should be something very close to 0 since the matrix
is rank deficient.  When i use the result from getSolver() to solve a system, i end 
up with a bunch of NaNs in the solution.  I assumed i would get back a least squares solution.

Does this SVD implementation require that the matrix be full rank?  If so, then i would expect
an exception to be thrown from the constructor or one of the methods.




  was:
The following jython code
## Start code
from org.apache.commons.math.linear import *
 
Alist = [[1.0, 2.0, 3.0],[2.0,3.0,4.0],[3.0,5.0,7.0]]
 
A = Array2DRowRealMatrix(Alist)
 
decomp = SingularValueDecompositionImpl(A)
 
print decomp.getSingularValues()
## End code
prints
array('d', [11.218599757513008, 0.3781791648535976, nan])
The last singular value should be something very close to 0 since the matrix
is rank deficient.  When i use the result from getSolver() to solve a system, i end 
up with a bunch of NaNs in the solution.  I assumed i would get back a least squares solution.

Does this SVD implementation require that the matrix be full rank?  If so, then i would expect
an exception to be thrown from the constructor or one of the methods.





> NaN singular value from SVD
> ---------------------------
>
>                 Key: MATH-320
>                 URL: https://issues.apache.org/jira/browse/MATH-320
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 2.0
>         Environment: Linux (Ubuntu 9.10) java version "1.6.0_16"
>            Reporter: Dieter Vandenbussche
>
> The following jython code
> Start code
> from org.apache.commons.math.linear import *
>  
> Alist = [[1.0, 2.0, 3.0],[2.0,3.0,4.0],[3.0,5.0,7.0]]
>  
> A = Array2DRowRealMatrix(Alist)
>  
> decomp = SingularValueDecompositionImpl(A)
>  
> print decomp.getSingularValues()
> End code
> prints
> array('d', [11.218599757513008, 0.3781791648535976, nan])
> The last singular value should be something very close to 0 since the matrix
> is rank deficient.  When i use the result from getSolver() to solve a system, i end 
> up with a bunch of NaNs in the solution.  I assumed i would get back a least squares solution.
> Does this SVD implementation require that the matrix be full rank?  If so, then i would expect
> an exception to be thrown from the constructor or one of the methods.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (MATH-320) NaN singular value from SVD

Posted by "Axel Kramer (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-320?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12792062#action_12792062 ] 

Axel Kramer commented on MATH-320:
----------------------------------


Is this a similar problem for the getU() method?

  public void testU() {
      double[][] testMatrix = {
          { 1.0 , 2.0 },
          { 1.0 , 2.0 } };
      SingularValueDecompositionImpl svd =
          new SingularValueDecompositionImpl(MatrixUtils.createRealMatrix(testMatrix));
// wrong result:
      assertEquals("Array2DRowRealMatrix{{-0.7071067811865472,NaN},{-0.7071067811865475,NaN}}", svd.getU().toString());
    }

> NaN singular value from SVD
> ---------------------------
>
>                 Key: MATH-320
>                 URL: https://issues.apache.org/jira/browse/MATH-320
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 2.0
>         Environment: Linux (Ubuntu 9.10) java version "1.6.0_16"
>            Reporter: Dieter Vandenbussche
>
> The following jython code
> Start code
> from org.apache.commons.math.linear import *
>  
> Alist = [[1.0, 2.0, 3.0],[2.0,3.0,4.0],[3.0,5.0,7.0]]
>  
> A = Array2DRowRealMatrix(Alist)
>  
> decomp = SingularValueDecompositionImpl(A)
>  
> print decomp.getSingularValues()
> End code
> prints
> array('d', [11.218599757513008, 0.3781791648535976, nan])
> The last singular value should be something very close to 0 since the matrix
> is rank deficient.  When i use the result from getSolver() to solve a system, i end 
> up with a bunch of NaNs in the solution.  I assumed i would get back a least squares solution.
> Does this SVD implementation require that the matrix be full rank?  If so, then i would expect
> an exception to be thrown from the constructor or one of the methods.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (MATH-320) NaN singular value from SVD

Posted by "Axel Kramer (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-320?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12795591#action_12795591 ] 

Axel Kramer edited comment on MATH-320 at 12/31/09 12:02 PM:
-------------------------------------------------------------

This statement should print the values of the original matrix approximately:
{code:java} 
  System.out.println(svd.getU().multiply(svd.getS()).multiply(svd.getVT()));
{code} 

This is true for
{code:java} 
    public void testMath320A() {
{code} 
but not for
{code:java} 
    public void testMath320B() {
{code} 

For reference values try wolfram alpha:
N[SingularValueDecomposition[{{1,2},{1,2}}]]

      was (Author: axelclk):
    This statement should print the values of the original matrix approximately:
{code:java} 
  System.out.println(svd.getU().multiply(svd.getS()).multiply(svd.getVT()));
{code} 

This is true for
{code:java} 
    public void testMath320A() {
{code} 
but not for
{code:java} 
    public void testMath320B() {
{code} 

For reference valus try wolfram alpha:
N[SingularValueDecomposition[{{1,2},{1,2}}]]
  
> NaN singular value from SVD
> ---------------------------
>
>                 Key: MATH-320
>                 URL: https://issues.apache.org/jira/browse/MATH-320
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 2.0
>         Environment: Linux (Ubuntu 9.10) java version "1.6.0_16"
>            Reporter: Dieter Vandenbussche
>
> The following jython code
> Start code
> from org.apache.commons.math.linear import *
>  
> Alist = [[1.0, 2.0, 3.0],[2.0,3.0,4.0],[3.0,5.0,7.0]]
>  
> A = Array2DRowRealMatrix(Alist)
>  
> decomp = SingularValueDecompositionImpl(A)
>  
> print decomp.getSingularValues()
> End code
> prints
> array('d', [11.218599757513008, 0.3781791648535976, nan])
> The last singular value should be something very close to 0 since the matrix
> is rank deficient.  When i use the result from getSolver() to solve a system, i end 
> up with a bunch of NaNs in the solution.  I assumed i would get back a least squares solution.
> Does this SVD implementation require that the matrix be full rank?  If so, then i would expect
> an exception to be thrown from the constructor or one of the methods.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (MATH-320) NaN singular value from SVD

Posted by "Luc Maisonobe (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-320?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12795606#action_12795606 ] 

Luc Maisonobe commented on MATH-320:
------------------------------------

Thanks for the hint Axel!
The print statement is even not satisfying for testMath320A, the approximation is really too bad. I would expect about 13 exact figures, not 1 or 2.
The problem seems to be related to matrix U which is not correct. In fact, it is even not unitary (i.e. U^T^.U is not the identity matrix).
I'll look at this.

> NaN singular value from SVD
> ---------------------------
>
>                 Key: MATH-320
>                 URL: https://issues.apache.org/jira/browse/MATH-320
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 2.0
>         Environment: Linux (Ubuntu 9.10) java version "1.6.0_16"
>            Reporter: Dieter Vandenbussche
>
> The following jython code
> Start code
> from org.apache.commons.math.linear import *
>  
> Alist = [[1.0, 2.0, 3.0],[2.0,3.0,4.0],[3.0,5.0,7.0]]
>  
> A = Array2DRowRealMatrix(Alist)
>  
> decomp = SingularValueDecompositionImpl(A)
>  
> print decomp.getSingularValues()
> End code
> prints
> array('d', [11.218599757513008, 0.3781791648535976, nan])
> The last singular value should be something very close to 0 since the matrix
> is rank deficient.  When i use the result from getSolver() to solve a system, i end 
> up with a bunch of NaNs in the solution.  I assumed i would get back a least squares solution.
> Does this SVD implementation require that the matrix be full rank?  If so, then i would expect
> an exception to be thrown from the constructor or one of the methods.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (MATH-320) NaN singular value from SVD

Posted by "Luc Maisonobe (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-320?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12795490#action_12795490 ] 

Luc Maisonobe commented on MATH-320:
------------------------------------

A first round on fixing this bug has been committed in the subversion repository as of r894735.
Axel example is confirmed to be an occurrence of the same bug as Dieter example.

The SVD is now computed either as a compact SVD (only positive singular values considered) or as a truncated SVD
(max number of singular values to consider is user-specified). The solver simply applies the pseudo-inverse.

The fix is not considered complete yet because I think that the results provided by the solver are not really the ones
that give the smallest residuals. See for example the commented out parts of testMath320A in
SingularValueSolverTest.  Could you check this, please ?

> NaN singular value from SVD
> ---------------------------
>
>                 Key: MATH-320
>                 URL: https://issues.apache.org/jira/browse/MATH-320
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 2.0
>         Environment: Linux (Ubuntu 9.10) java version "1.6.0_16"
>            Reporter: Dieter Vandenbussche
>
> The following jython code
> Start code
> from org.apache.commons.math.linear import *
>  
> Alist = [[1.0, 2.0, 3.0],[2.0,3.0,4.0],[3.0,5.0,7.0]]
>  
> A = Array2DRowRealMatrix(Alist)
>  
> decomp = SingularValueDecompositionImpl(A)
>  
> print decomp.getSingularValues()
> End code
> prints
> array('d', [11.218599757513008, 0.3781791648535976, nan])
> The last singular value should be something very close to 0 since the matrix
> is rank deficient.  When i use the result from getSolver() to solve a system, i end 
> up with a bunch of NaNs in the solution.  I assumed i would get back a least squares solution.
> Does this SVD implementation require that the matrix be full rank?  If so, then i would expect
> an exception to be thrown from the constructor or one of the methods.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (MATH-320) NaN singular value from SVD

Posted by "Axel Kramer (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-320?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12795591#action_12795591 ] 

Axel Kramer edited comment on MATH-320 at 12/31/09 12:01 PM:
-------------------------------------------------------------

This statement should print the values of the original matrix approximately:
{code:java} 
  System.out.println(svd.getU().multiply(svd.getS()).multiply(svd.getVT()));
{code} 

This is true for
{code:java} 
    public void testMath320A() {
{code} 
but not for
{code:java} 
    public void testMath320B() {
{code} 

For reference valus try wolfram alpha:
N[SingularValueDecomposition[{{1,2},{1,2}}]]

      was (Author: axelclk):
    This statement should print the values of the original matrix approximately:
{code:java} 
  System.out.println(svd.getU().multiply(svd.getS()).multiply(svd.getVT()));
{code} 

This is true for
{code:java} 
    public void testMath320A() {
{code} 
but not for
{code:java} 
    public void testMath320B() {
{code} 
  
> NaN singular value from SVD
> ---------------------------
>
>                 Key: MATH-320
>                 URL: https://issues.apache.org/jira/browse/MATH-320
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 2.0
>         Environment: Linux (Ubuntu 9.10) java version "1.6.0_16"
>            Reporter: Dieter Vandenbussche
>
> The following jython code
> Start code
> from org.apache.commons.math.linear import *
>  
> Alist = [[1.0, 2.0, 3.0],[2.0,3.0,4.0],[3.0,5.0,7.0]]
>  
> A = Array2DRowRealMatrix(Alist)
>  
> decomp = SingularValueDecompositionImpl(A)
>  
> print decomp.getSingularValues()
> End code
> prints
> array('d', [11.218599757513008, 0.3781791648535976, nan])
> The last singular value should be something very close to 0 since the matrix
> is rank deficient.  When i use the result from getSolver() to solve a system, i end 
> up with a bunch of NaNs in the solution.  I assumed i would get back a least squares solution.
> Does this SVD implementation require that the matrix be full rank?  If so, then i would expect
> an exception to be thrown from the constructor or one of the methods.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.