Re: [ojAlgo-user] ActiveSetSolver - RuntimeException: Matrix is singular.
Mathematics, linear algebra and optimisation
Brought to you by:
apete
From: Anders P. <an...@op...> - 2008-10-16 07:31:00
|
I don't see the ArrayIndexOutOfBoundsException. That's most likely because I use a later version (24.9) than you do. I've made some changes to ActiveSetSolver that would affect this (I think I know where/why you got that exception). The incorrect state: I don't see the same thing you do, but I do see something is wrong. I'll try to have a look at this later today. Is it possible for you to get the latest version from CVS? /Anders On 15 okt 2008, at 15.11, Oddvar Grønning wrote: > Thanks for your answer, Anders, it did solve my system (even though > the result state was FAILED). > > As you might have guessed, I am using the ActiveSetSolver as a part > of a larger system where the system matrixes to be solved changes > all the time (not the dimensions but the values of the matrixes). > > I still get errors in certain situations. I will present a system > that triggers an ArrayIndexOutOfBoundsException in ActiveSetSolver. > Again, Matlabs quadprog produces a correct result. > > public class QPTest { > > public static void main(String[] args) { > new QPTest(); > } > > public QPTest() { > > BasicMatrix[] system = new BasicMatrix[6]; > //{[AE], [be], [Q], [c], [AI], [bi]} > > double[][] AE = new double[][] > {{-0.6864742690952357, -0.5319998214213948, 1.2385363215384646, > -3.4914813388431334E-15, 0.976619978072726, 0.8727726942384015, > 1.0, 0.0, 0.0}, {-2.396812100141995E-15, 2.4168686217298863, > -2.2145077177955423, 1.0, 0.21497306442721648, 0.48812685256175126, > 0.0, 1.0, 0.0},{-7.190436300425984E-14, -67.71806025910404, > 77.58205842771245, 30.0, -15.23877173547103, -6.788851328706924, > 0.0, 0.0, 1.0}}; > system[0] = PrimitiveMatrix.FACTORY.copy(AE); // AE > system[1] = PrimitiveMatrix.FACTORY.copy(new double > [][]{{0.459002008118756}, {0.002566161917554134}, > {-0.03315618953218959}}); // be > system[2] = PrimitiveMatrix.FACTORY.buildEye(9, > 9); // Q > system[2] = system[2].set(3, 3, 10); > system[2] = system[2].set(4, 4, 10); > system[2] = system[2].set(5, 5, 10); > system[2] = system[2].set(6, 6, 1000000000); > system[2] = system[2].set(7, 7, 1000000000); > system[2] = system[2].set(8, 8, 1000000000); > system[3] = PrimitiveMatrix.FACTORY.copy(new double > [][]{{0}, {0}, {0}, {1}, {1}, {-1}, {0}, {0}, > {0}}); // c > > double[][] Ain = new double[18][9]; > > for(int i = 0; i < 9; i++) { > Ain[i][i] = 1; > Ain[i+9][i] = -1; > } > > system[4] = PrimitiveMatrix.FACTORY.copy(Ain); // AI > double[][] bin = new double[][]{{0}, {0.0175}, > {0.0175}, {0.5}, {0.5}, {0.5}, {100000}, {100000}, {100000}, {0}, > {0.0175}, {0.0175}, {0.5}, {0.5}, {0.5}, {100000}, {100000}, > {100000}}; > system[5] = PrimitiveMatrix.FACTORY.copy > (bin); // bi > > ActiveSetSolver as = new ActiveSetSolver(system); > Result res = as.solve(); > System.out.println("state: " + res.getState()); > } > } > > The result from Matlab: > X = > > -0.00000000000000 > -0.01750000000000 > 0.01750000000000 > 0.13427356981778 > 0.50000000000000 > -0.14913060410765 > 0.06986475572103 > -0.08535020176844 > 0.00284500680371 > > > Thanks, > - Oddvar > > -----Original Message----- >> From: Anders Peterson [mailto:an...@op...] > Sent: 14. oktober 2008 15:41 > To: oja...@li... > Subject: Re: [ojAlgo-user] ActiveSetSolver - RuntimeException: > Matrix is singular. > > If you use PrimitiveMatrix.FACTORY instead of JamaMatrix.FACTORY your > code will run successfully and produce a solution > that is the same as the one you got from Matlab (within 4 decimals). > > The reason is that PrimitiveMatrix, BigMatrix & ComplexMatrix (the > "native" ojAlgo matrices) are more intelligent in solving equation > systems than JamaMatrix. Look at the implementations of > BasicMatrix#solve() and you'll see what I mean. > > /Anders > > 14 okt 2008 kl. 12.56 skrev Oddvar Grønning: > >> Hi, >> >> >> >> I'm trying to solve some quadratic programming systems using >> version 24. The ActiveSetSolver does not always converge to a >> solution, but throws an exception, "Matrix is singular" (The >> exception is thrown by org.ojalgo.matrix.jama.LUDecomposition). >> >> The thing is that if I run Matlabs quadprog method on the exact >> same system, a solution is found without problems. Here is the code >> that produces the exception: >> >> >> >> public class QPTest { >> >> >> >> public static void main(String[] args) { >> >> new QPTest(); >> >> } >> >> >> >> public QPTest() { >> >> >> >> BasicMatrix[] system = new BasicMatrix[6]; >> >> //{[AE], [be], [Q], [c], [AI], [bi]} >> >> >> >> double[][] AE = new double[][] >> {{-0.0729971273939726,-0.31619624199405116,-0.14365990081105298,-3.49 >> 1 >> 4813388431334E-15,0.9963066090106673,0.9989967493404447,1.0,0.0,0.0}, >> {-2.5486810808521023E-16,3.6687950405257466,3.2047109656515507,1.0,0. >> 0 >> 8586699506600544,0.04478275122437895,0.0,1.0,0.0}, >> {-7.646043242556307E-15,-107.21808503782593,-97.434268076846,30.0,-11 >> . >> 54276933307617,7.647488207332634,0.0,0,1.0}}; >> >> system[0] = JamaMatrix.FACTORY.copy >> (AE); // AE >> >> system[1] = JamaMatrix.FACTORY.copy(new >> double[][]{{10.461669614447484}, {-0.5328532701990767}, >> {15.782527136201711}}); // be >> >> system[2] = JamaMatrix.FACTORY.buildEye(9, >> 9); // Q >> >> system[2] = system[2].set(3, 3, 10); >> >> system[2] = system[2].set(4, 4, 10); >> >> system[2] = system[2].set(5, 5, 10); >> >> system[2] = system[2].set(6, 6, 1000000000); >> >> system[2] = system[2].set(7, 7, 1000000000); >> >> system[2] = system[2].set(8, 8, 1000000000); >> >> system[3] = JamaMatrix.FACTORY.copy(new >> double[][]{{0}, {0}, {0}, {1}, {1}, {1}, {0}, {0}, >> {0}}); // c >> >> >> >> double[][] Ain = new double[18][9]; >> >> >> >> for(int i = 0; i < 9; i++) { >> >> Ain[i][i] = 1; >> >> Ain[i+9][i] = -1; >> >> } >> >> system[4] = JamaMatrix.FACTORY.copy >> (Ain); // AI >> >> >> >> double[][] bin = new double[][]{{0}, >> {0.0175}, {0.0175}, {5}, {5}, {5}, {100000}, {100000}, {100000}, >> {0}, {0.0175}, {0.0175}, {5}, {5}, {5}, {100000}, {100000}, >> {100000}}; >> >> system[5] = JamaMatrix.FACTORY.copy >> (bin); // bi >> >> >> >> ActiveSetSolver as = new ActiveSetSolver >> (system); >> >> Result res = as.solve(); >> >> } >> >> } >> >> >> >> Am I doing something wrong? Bug? >> >> >> >> Matlab is returning: >> >> X = >> >> >> >> 0.00000000000000 >> >> -0.01750000000000 >> >> -0.01750000000000 >> >> 0.88830035195990 >> >> 4.56989525276369 >> >> 5.00000000000000 >> >> 0.90562154243124 >> >> -1.91718419629399 >> >> 0.06390614020590 >> >> >> >> - Oddvar >> >> --------------------------------------------------------------------- >> - >> --- >> This SF.Net email is sponsored by the Moblin Your Move Developer's >> challenge >> Build the coolest Linux based applications with Moblin SDK & win >> great prizes >> Grand prize is a trip for two to an Open Source event anywhere in >> the world >> http://moblin-contest.org/redirect.php?banner_id=100&url=/ >> _______________________________________________ >> ojAlgo-user mailing list >> ojA...@li... >> https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > > ---------------------------------------------------------------------- > --- > This SF.Net email is sponsored by the Moblin Your Move Developer's > challenge > Build the coolest Linux based applications with Moblin SDK & win > great prizes > Grand prize is a trip for two to an Open Source event anywhere in > the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > > > ---------------------------------------------------------------------- > --- > This SF.Net email is sponsored by the Moblin Your Move Developer's > challenge > Build the coolest Linux based applications with Moblin SDK & win > great prizes > Grand prize is a trip for two to an Open Source event anywhere in > the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > |