Re: [ojAlgo-user] OjAlgo exception in SVD
Mathematics, linear algebra and optimisation
Brought to you by:
apete
From: Anders P. <ap...@op...> - 2007-05-01 12:10:14
|
Read my answers below... Dimitri Pourbaix wrote: > Dear Anders, > > You asked me for test cases of SVD. Here is one ... and the problem I > have with it. You need use the latest code from CVS. The solve() method in the SVD implementation was simply not yet implemented when I released Version 19, AND there was a problem with the getPseudoinverse() method. This is now fixed in CVS, and will of course be included with Version 20. > Still, your implementation is very elegant and the resul- > ting much more straightforward to read. Thank you. > > With my best regards, > Dim. > > Using the following class: > > class OjAlgoTest { > private final > org.ojalgo.matrix.factory.PhysicalFactory<Double> _factory > = org.ojalgo.matrix.store.PrimitiveDenseStore.FACTORY; > private org.ojalgo.matrix.store.MatrixStore<Double> _a; > private org.ojalgo.matrix.store.MatrixStore<Double> _b; > private org.ojalgo.matrix.store.MatrixStore<Double> _x; > > public OjAlgoTest(double[][] a, > double[][] b) { > _a = _factory.makeEmpty(a.length, a[0].length); > _b = _factory.makeEmpty(b.length, b[0].length); > > for (int i = 0, maxI = _a.getRowDim(); i < maxI; i++) { > for (int j = 0, maxJ = _a.getColDim(); j < maxJ; j++) { > _a.toPhysicalStore().set(i, j, a[i][j]); > } > } > for (int i = 0, maxI = _b.getRowDim(); i < maxI; i++) { > for (int j = 0, maxJ = _b.getColDim(); j < maxJ; j++) { > _b.toPhysicalStore().set(i, j, b[i][j]); > } > } > } > > public void svd() { > > org.ojalgo.matrix.decomposition.MatrixDecomposition<Double> dec > = new org.ojalgo.matrix.jama.JamaSingularValue(); > if (dec.compute(_a)) { > _x = dec.solve(_b); > } else { > throw new org.ojalgo.ProgrammingError("Matrix is not > solvable"); > } > } > } > > with "ojalgo-19.0.jar", the method "svd()" triggers an exception: > > Exception in thread "main" org.ojalgo.ProgrammingError: Don't use this > method/constructor! > at > org.ojalgo.ProgrammingError.throwForIllegalInvocation(ProgrammingError.java:36) > > at > org.ojalgo.matrix.jama.JamaSingularValue.solve(JamaSingularValue.java:193) > > at > org.ojalgo.matrix.jama.JamaAbstractDecomposition.solve(JamaAbstractDecomposition.java:69) > > at > my.MatrixComparisons$OjAlgoTest.svd(MatrixComparisons.java:308) > at my.MatrixComparisons.<init>(MatrixComparisons.java:88) > at my.StandAlone.main(StandAlone.java:31) > > Another question: Why isn't there a factory method to create a matrix > from a > two-dimensional array (which would avoid the explicit loop in the above > constructor)? Maybe PhysicalFactory needs another method. I'll think about that. Currently you have two ways to avoid explicit looping: 1) PrimitiveMatrix.FACTORY.make(double[][]).toPrimitiveStore(); 2) PrimitiveDenseStore.FACTORY.makeArrayCopy(Array2Dim.makePrimitive(double[][]).getDelegate()); /Anders |