ojalgo-user Mailing List for oj! Algorithms (Page 9)
Mathematics, linear algebra and optimisation
Brought to you by:
apete
You can subscribe to this list here.
2003 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2004 |
Jan
|
Feb
(1) |
Mar
|
Apr
(14) |
May
(1) |
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
(1) |
2005 |
Jan
(3) |
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
(1) |
Sep
(3) |
Oct
|
Nov
|
Dec
(1) |
2006 |
Jan
(1) |
Feb
(1) |
Mar
(1) |
Apr
|
May
(1) |
Jun
(2) |
Jul
|
Aug
(5) |
Sep
|
Oct
(3) |
Nov
(4) |
Dec
(2) |
2007 |
Jan
(8) |
Feb
(1) |
Mar
(2) |
Apr
(11) |
May
(6) |
Jun
|
Jul
(10) |
Aug
(2) |
Sep
|
Oct
(4) |
Nov
|
Dec
(11) |
2008 |
Jan
(22) |
Feb
(4) |
Mar
(2) |
Apr
(4) |
May
(2) |
Jun
|
Jul
|
Aug
(1) |
Sep
|
Oct
(6) |
Nov
(17) |
Dec
(5) |
2009 |
Jan
(15) |
Feb
(2) |
Mar
(2) |
Apr
(3) |
May
(4) |
Jun
(5) |
Jul
(9) |
Aug
(2) |
Sep
|
Oct
(5) |
Nov
(14) |
Dec
|
2010 |
Jan
(3) |
Feb
(5) |
Mar
(2) |
Apr
(19) |
May
|
Jun
|
Jul
|
Aug
(2) |
Sep
|
Oct
(5) |
Nov
(3) |
Dec
|
2011 |
Jan
|
Feb
(1) |
Mar
(7) |
Apr
(10) |
May
(1) |
Jun
(15) |
Jul
(1) |
Aug
|
Sep
|
Oct
(13) |
Nov
(9) |
Dec
(11) |
2012 |
Jan
|
Feb
(1) |
Mar
(9) |
Apr
(23) |
May
(16) |
Jun
(9) |
Jul
(13) |
Aug
|
Sep
(4) |
Oct
(1) |
Nov
(1) |
Dec
|
2013 |
Jan
|
Feb
(12) |
Mar
(7) |
Apr
(24) |
May
|
Jun
(7) |
Jul
(4) |
Aug
|
Sep
(3) |
Oct
(16) |
Nov
(7) |
Dec
(3) |
2014 |
Jan
(22) |
Feb
(1) |
Mar
(1) |
Apr
|
May
(2) |
Jun
(3) |
Jul
(4) |
Aug
(4) |
Sep
(1) |
Oct
(2) |
Nov
(6) |
Dec
(2) |
2015 |
Jan
(11) |
Feb
(10) |
Mar
(1) |
Apr
(9) |
May
|
Jun
|
Jul
(1) |
Aug
(4) |
Sep
(6) |
Oct
(3) |
Nov
(15) |
Dec
(4) |
2016 |
Jan
(6) |
Feb
|
Mar
(18) |
Apr
(5) |
May
(9) |
Jun
(3) |
Jul
(5) |
Aug
(2) |
Sep
(5) |
Oct
(2) |
Nov
|
Dec
(5) |
2017 |
Jan
(4) |
Feb
(3) |
Mar
|
Apr
|
May
(12) |
Jun
(1) |
Jul
(4) |
Aug
|
Sep
(3) |
Oct
(1) |
Nov
|
Dec
(1) |
2018 |
Jan
(5) |
Feb
|
Mar
(1) |
Apr
(1) |
May
(1) |
Jun
|
Jul
(4) |
Aug
(1) |
Sep
(8) |
Oct
|
Nov
|
Dec
(1) |
2019 |
Jan
|
Feb
(2) |
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2022 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Oddvar G. <od...@pr...> - 2014-05-22 13:40:34
|
Hi all, I've been using the QuadraticSolver for a while, and suddenly stumbled over an unexpected failure to solve a problem. The solution state was APPROXIMATE and the solution was not correct. I tested the same system with another QP-solver and got the result I expected. I then condensed the problem as much as I could and made a test out of it (see below). To my surprise the test sometimes fails and sometimes passes(!). I've been running this test (alone) in TestNG. I'm using Ojalgo v35 and Java 1.7.55. The Q matrix is positive definite. Does anyone understand what is going on? Br Oddvar @Test(singleThreaded=true) public void Ojalgo_QuadraticSolver_Test() { double[][] q = new double[][] {{49.0, 31.0, 17.0, 6.0}, {31.0, 25.0, 13.0, 5.0}, {17.0, 13.0, 11.0, 3.5}, {6.0, 5.0, 3.5, 4.0}}; JamaMatrix JamaQ = JamaMatrix.FACTORY.rows(q); double[] c = new double[] {195.0, 59.0, -1.8, -11.7}; JamaMatrix JamaC = JamaMatrix.FACTORY.columns(c); double[][] ai = new double[][] {{1.0, 0.0, 0.0, 0.0}, {-1.0, 0.0, 0.0, 0.0}, {1.0, 1.0, 0.0, 0.0}, {-1.0, -1.0, 0.0, 0.0}, {1.0, 1.0, 1.0, 0.0}, {-1.0, -1.0, -1.0, 0.0}, {0.1, 0.0, 0.0, 0.0}, {0.01, 0.0, 0.0, 0.0}, {0.18, 0.1, 0.0, 0.0}, {-0.01, 0.0, 0.0, 0.0}, {-0.183, -0.1, 0.0, 0.0}, {0.0283, 0.01, 0.0, 0.0}, {0.25, 0.183, 0.1, 0.0}}; JamaMatrix JamaAI = JamaMatrix.FACTORY.rows(ai); double[] bi = new double[] {0.13, 0.87, 0.18, 0.82, 0.23, 0.77, -0.04, 99.67, -0.06, 100.33, 1.06, 99.62, -0.08}; JamaMatrix JamaBI = JamaMatrix.FACTORY.columns(bi); org.ojalgo.optimisation.Optimisation.Result result = null; try { QuadraticSolver.Builder qsBuilder = new QuadraticSolver.Builder(JamaQ, JamaC); qsBuilder.inequalities(JamaAI, JamaBI); QuadraticSolver qSolver = qsBuilder.build(); result = qSolver.solve(); } catch(Exception e) { e.printStackTrace(); assert false; } State state = result.getState(); assert state == State.OPTIMAL; int numElm = (int) result.count(); double[] solution = new double[numElm]; for(int i = 0; i < numElm; i++) { solution[i] = result.doubleValue(i); } double[] expectedSolution = new double[]{ -0.4, 0.12, -0.0196, -2.45785}; for(int i = 0; i < numElm; i++) { assert Math.abs(solution[i] - expectedSolution[i]) < 1e-4; } } |
From: Anders P. <an...@op...> - 2014-03-01 19:47:46
|
On 26 Feb 2014, at 16:06, Anthony Edwards <ant...@al...> wrote: > Hi > > I am trying to explore the efficient frontier using an ExpressionsBasedModel, as the MarkowitzModel doesnt let me enter the constraints I would like to use. Ive been looking at the posts and test cases and it seems that to do this i should follow the steps below: > > My approach with the ExpressionBasedModel is: > 1) vars = [Create the variables and set upper and lower limits for them] > 2) ExpressionsBasedModel model = new ExpressionsBasedModel(vars) > 3) covarExpr = [Create the covariance Expression based on the covariance matrix]. > 4) covarExpr.setQuadraticFactors(model.getVariables(), covar_matrix); > 5) balanceExpr = [Create the balance so sum of weights = 1] > 6) riskAversion = BigMath.PI.multiply(BigMath.E) > 7) covarExpr.weight(riskAversion.multiply(BigMath.HALF)); > > I have a couple of questions. > > 1) Are steps 5 and 6 sensible. It seems to be what yoou do in some of the tests, but I’d like to understand if thats right It depends on what you want to your model to express, and I don’t know that. “5" is a very common portfolio constraint. > 2) On the MarkowitzModel I can get out of it .getRiskAversion(), ..getSharpeRatio() and getMeanReturn(). How do I calculate those on an ExpressionsBasedModel? ExpressionsBasedModel lets you model optimisation problems. It has absolutely nothing to do with modern portfolio theory or any other specific domain. If you want to learn some basics about portfolio theory or various key figures wikipedia is a good place to start. /Anders > Apologies if this sounds obvious, but this isnt really my sort of thing! > > Thanks > ------------------------------------------------------------------------------ > Flow-based real-time traffic analytics software. Cisco certified tool. > Monitor traffic, SLAs, QoS, Medianet, WAAS etc. with NetFlow Analyzer > Customize your own dashboards, set traffic alerts and generate reports. > Network behavioral analysis & security monitoring. All-in-one tool. > http://pubads.g.doubleclick.net/gampad/clk?id=126839071&iu=/4140/ostg.clktrk_______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user |
From: Anthony E. <ant...@al...> - 2014-02-26 15:35:11
|
Hi I am trying to explore the efficient frontier using an ExpressionsBasedModel, as the MarkowitzModel doesnt let me enter the constraints I would like to use. Ive been looking at the posts and test cases and it seems that to do this i should follow the steps below: My approach with the ExpressionBasedModel is: 1) vars = [Create the variables and set upper and lower limits for them] 2) ExpressionsBasedModel model = new ExpressionsBasedModel(vars) 3) covarExpr = [Create the covariance Expression based on the covariance matrix]. 4) covarExpr.setQuadraticFactors(model.getVariables(), covar_matrix); 5) balanceExpr = [Create the balance so sum of weights = 1] 6) riskAversion = BigMath.PI.multiply(BigMath.E) 7) covarExpr.weight(riskAversion.multiply(BigMath.HALF)); I have a couple of questions. 1) Are steps 5 and 6 sensible. It seems to be what yoou do in some of the tests, but I’d like to understand if thats right 2) On the MarkowitzModel I can get out of it .getRiskAversion(), .getSharpeRatio() and getMeanReturn(). How do I calculate those on an ExpressionsBasedModel? Apologies if this sounds obvious, but this isnt really my sort of thing! Thanks |
From: Cristian B. <cri...@ho...> - 2014-01-17 11:20:12
|
Because it is the return of a portfolio composed by 100% Asset B and 0% Asset A. All other weights combination generate lower return. > From: an...@op... > Date: Fri, 17 Jan 2014 12:14:17 +0100 > To: oja...@li... > Subject: Re: [ojAlgo-user] Markowitz (portfolio maximum return ) > > Why is 9.00% portfolio return the correct result? When/where/how did you specify that you want the maximum return portfolio? > > Use setRiskAvesrion(Number), experiment with different values. > > > > On 17 jan 2014, at 11:09, Cristian Bissattini <cri...@ho...> wrote: > > > I have a problem with portfolio maximum return in Markowitz algorithm. > > > > Considering a simple portfolio composed by two asset class: > > > > Asset A: Return 8.50% and volatility 20.00% > > Asset B: Return 9.00% and volatility 30.00% > > > > Correlation coefficient=0 (matrix positive defined) > > > > I obtained a portfolio maximum return equal to 8.85% instead of 9.00% (100% Asset B) > > > > In fact, if I set the return of Asset A to 8.00% (instead of 8.50%), the result is correct (portfolio maximum return is 9.00%) > > > > Could you give me more info? > > Best Regards, > > Cristian > > > > > > > > ------------------------------------------------------------------------------ > > CenturyLink Cloud: The Leader in Enterprise Cloud Services. > > Learn Why More Businesses Are Choosing CenturyLink Cloud For > > Critical Workloads, Development Environments & Everything In Between. > > Get a Quote or Start a Free Trial Today. > > http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk_______________________________________________ > > ojAlgo-user mailing list > > ojA...@li... > > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > > ------------------------------------------------------------------------------ > CenturyLink Cloud: The Leader in Enterprise Cloud Services. > Learn Why More Businesses Are Choosing CenturyLink Cloud For > Critical Workloads, Development Environments & Everything In Between. > Get a Quote or Start a Free Trial Today. > http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user |
From: Anders P. <an...@op...> - 2014-01-17 11:14:27
|
Why is 9.00% portfolio return the correct result? When/where/how did you specify that you want the maximum return portfolio? Use setRiskAvesrion(Number), experiment with different values. On 17 jan 2014, at 11:09, Cristian Bissattini <cri...@ho...> wrote: > I have a problem with portfolio maximum return in Markowitz algorithm. > > Considering a simple portfolio composed by two asset class: > > Asset A: Return 8.50% and volatility 20.00% > Asset B: Return 9.00% and volatility 30.00% > > Correlation coefficient=0 (matrix positive defined) > > I obtained a portfolio maximum return equal to 8.85% instead of 9.00% (100% Asset B) > > In fact, if I set the return of Asset A to 8.00% (instead of 8.50%), the result is correct (portfolio maximum return is 9.00%) > > Could you give me more info? > Best Regards, > Cristian > > > > ------------------------------------------------------------------------------ > CenturyLink Cloud: The Leader in Enterprise Cloud Services. > Learn Why More Businesses Are Choosing CenturyLink Cloud For > Critical Workloads, Development Environments & Everything In Between. > Get a Quote or Start a Free Trial Today. > http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk_______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user |
From: Cristian B. <cri...@ho...> - 2014-01-17 10:10:03
|
I have a problem with portfolio maximum return in Markowitz algorithm. Considering a simple portfolio composed by two asset class: Asset A: Return 8.50% and volatility 20.00% Asset B: Return 9.00% and volatility 30.00% Correlation coefficient=0 (matrix positive defined) I obtained a portfolio maximum return equal to 8.85% instead of 9.00% (100% Asset B) In fact, if I set the return of Asset A to 8.00% (instead of 8.50%), the result is correct (portfolio maximum return is 9.00%) Could you give me more info? Best Regards, Cristian |
From: Anders P. <an...@op...> - 2014-01-16 21:42:40
|
I see the same behavior. It alternates between to different "solutions". You can't set "target return" to more than what any individual asset returns. In your case the assets return 4% and 13%, but you set the target return to 20%. You should call getOptimisatinState() to check the validity of the solution. In this case it returns APPROXIMATE which indicates that the solution may not be feasible. One of the solutions doesn't reach the target return (which is a constraint) and the other violates the asset class limits (but does reach the target return). /Anders On 16 jan 2014, at 21:23, Cristian Bissattini <cri...@ho...> wrote: > > Using Markowitz model, I have a problem with this simple portfolio. Sometimes the algorithm doesn’t respect the asset class limits (lower and upper limit). The correlation matric is of course positive defined. > > org.ojalgo.matrix.PrimitiveMatrix < 2 x 2 > > { { 0.0036, -0.0054 }, > { -0.0054, 0.0324 } } > Return Matrix:org.ojalgo.matrix.PrimitiveMatrix < 2 x 1 > > { { 0.04 }, > { 0.13 } } > =======result==================== > -0.7778 > 1.7778 > =======result==================== > 0.200002 > 0.119514408912 > > This problem seems to appear randomly… sometimes it works correctly and sometimes doesn’t work. > > Please find enclosed the java example. > > Could you give me more info? > > Best Regards, > Cristian > > > > <TestEquilibrium.java>------------------------------------------------------------------------------ > CenturyLink Cloud: The Leader in Enterprise Cloud Services. > Learn Why More Businesses Are Choosing CenturyLink Cloud For > Critical Workloads, Development Environments & Everything In Between. > Get a Quote or Start a Free Trial Today. > http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk_______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user |
From: Cristian B. <cri...@ho...> - 2014-01-16 20:23:14
|
/* * Copyright 1997-2014 Optimatika (www.optimatika.se) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ //package org.ojalgo.finance.portfolio; import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; //import org.ojalgo.TestUtils; import org.ojalgo.access.Access2D.Builder; import org.ojalgo.constant.BigMath; import org.ojalgo.function.PrimitiveFunction; import org.ojalgo.function.UnaryFunction; import org.ojalgo.matrix.BasicMatrix; import org.ojalgo.matrix.PrimitiveMatrix; import org.ojalgo.matrix.store.PhysicalStore; import org.ojalgo.matrix.store.PrimitiveDenseStore; import org.ojalgo.finance.portfolio.MarketEquilibrium; import org.ojalgo.finance.portfolio.MarkowitzModel; import org.ojalgo.random.Uniform; import org.ojalgo.type.StandardType; public class TestEquilibrium { public static void main(final String[] args) { final int assetNum = 2; final double[][] om = { { 0.0036, -0.0054 }, { -0.0054, 0.0324 } }; final TestEquilibrium tm = new TestEquilibrium(); final BasicMatrix covariances = tm.getACovariances(om); System.out.println(covariances); final BigDecimal riskAversion = new BigDecimal(1000.0); MarketEquilibrium marketEquilibrium = new MarketEquilibrium(covariances, riskAversion); marketEquilibrium = marketEquilibrium.clean(); Builder<PrimitiveMatrix> expectedExcessReturns1 = PrimitiveMatrix.getBuilder(assetNum, 1); expectedExcessReturns1 = expectedExcessReturns1.set(0, 0, 0.0400); expectedExcessReturns1 = expectedExcessReturns1.set(1, 0, 0.1300); System.out.println("Return Matrix:" + expectedExcessReturns1.build()); final MarkowitzModel markowitzModel = new MarkowitzModel(marketEquilibrium, expectedExcessReturns1.build()); //markowitzModel.setTargetReturn(new BigDecimal("0.08")); markowitzModel.setTargetReturn(new BigDecimal("0.20")); for (int i = 0; i < assetNum; i++) { markowitzModel.setLowerLimit(i, new BigDecimal(0.0)); markowitzModel.setUpperLimit(i, new BigDecimal(1.0)); } final List<BigDecimal> re = markowitzModel.getWeights(); System.out.println("=======result===================="); for (int i = 0; i < re.size(); i++) { System.out.println(re.get(i)); } System.out.println("=======result===================="); System.out.println(markowitzModel.getMeanReturn()); System.out.println(markowitzModel.getReturnVariance()); return; } public TestEquilibrium() { super(); } public BasicMatrix<?> getACovariances(final double[][] returns) { final int row = returns.length; final int col = returns[0].length; Builder<PrimitiveMatrix> covariances = PrimitiveMatrix.getBuilder(row, col); for (int i = 1; i <= row; i++) { for (int j = i; j <= col; j++) { covariances = covariances.set(i - 1, j - 1, returns[i - 1][j - 1]); covariances = covariances.set(j - 1, i - 1, returns[j - 1][i - 1]); } } return covariances.build(); } } |
From: Nico P. <Nic...@gm...> - 2014-01-16 13:54:24
|
> I've already added validation to the builder to avoid the kind of mistake (transposing C) you made before. When/how was there a NullPointerE? Sorry, I meant the ArrayIndexOutOfBoundsException that you already handled. Best regards Nico |
From: Anders P. <an...@op...> - 2014-01-16 13:25:16
|
On 16 jan 2014, at 10:31, Nico Potyka <Nic...@gm...> wrote: > Thanks for your tips. I tried the debug mode but didn't notice any differences in the output apart from improved accuracy for the expression based model. However, I saw that in the solve-method of the QuadraticSolver class all exceptions (including nullpointer exceptions) are swallowed in the catch-block if you are not in debug mode and the state is just set to FAILED. I'm not sure if this is the way it is meant to be. It's bad design and will be changed at some point. I've already added validation to the builder to avoid the kind of mistake (transposing C) you made before. When/how was there a NullPointerE? > I also followed your advice and stepped into the code, but couldn't really follow what was going on (not because of the code, but because I need more time to understand how things work together). I noticed, however, that the call of build() in > > QuadraticSolver qSolver = new QuadraticSolver.Builder(tmpQ, tmpC).equalities(tmpAE, tmpBE).inequalities(tmpAI, tmpBI).build(); > > also uses an ExpressionBasedModel of the QuadraticSolver.Builder, but it seems to be used in a different way, because its variable list is empty if I get it right. So maybe the crucial difference is the way I define non-negativity constraints in both implementations. For the expression based model I define non-negativity when defining the variables (via lower(BigMath.ZERO)), whereas I define non-negativity by means of the matrix AI (which is the negative unity matrix in my case) for my matrix implementation. If ojAlgo handles non-negativity constraints in a different way than general inequalities, maybe this is a reasonable explanation? By the way, is there another way to define non-negativity when using the build-method as above? In this case I wouldn't need any inequalities at all. ExpressionsBasedModel also makes use of that same builder. There's no special way to handle non-negativity, it just an inequality. > I also tried the NullspaceSolver but it yields wrong results for many examples I tested. These examples need some classes from another library, but if it helps for debugging, I will try to build some stand-alone examples and send them to you soon. Ok, never mind that then. It'll be some time before I finish it. > Best regards > Nico > > > > > Gesendet: Mittwoch, 15. Januar 2014 um 08:46 Uhr > Von: "Anders Peterson" <an...@op...> > An: "ojAlgo ojAlgo" <oja...@li...> > Betreff: Re: [ojAlgo-user] Quadratic Program fails > There's one more thing that maybe you're interested in trying. > > In the QuadraticSolver.Builder.build(Options) method you may change this > > return new LagrangeSolver(tmpModel, options, this); > //return new NullspaceSolver(tmpModel, options, this); > into > //return new LagrangeSolver(tmpModel, options, this); > return new NullspaceSolver(tmpModel, options, this); > > That solver is NOT READY! It's a very high level experimental implementation of a different algorithm with better numerical performance. In its current state it uses even more memory and executes about 4 times slower than the default algorithm, but it does handle most of the test cases. > > /Anders > > > > On 15 jan 2014, at 07:58, Anders Peterson <an...@op...> wrote: > >> I'm surprised your initial trials only worked up to 32 variables - that's not much at all... Must be something "unfortunate" with your numbers. >> >> ExpressionBasedModel obviously did something for you. Debug your code with a breakpoint in the static method QuadraticSolver.make(ExpressionBasedModel). There you should be able to see the actual matrices used in the solver. You can compare that to what you created when you used the solver builder directly.When you've learned what ExpressionBasedModel did maybe you can go back to using the solver/builder and manipulate the input matrices the same way, but more. In your case I'm guessing it's only simple scaling of the problem parameters. >> >> To learn a little about what goes wrong in the solver you can try this: Set this before you solve. >> >> tmpModel.options.debug(QuadraticSolver.class); >> or >> tmpSolver.options.debug(QuadraticSolver.class); >> >> Only do that for smaller models. Otherwise there will be too much output. >> >> >> /Anders >> >> >> On 14 jan 2014, at 12:53, Nico Potyka <Nic...@gm...> wrote: >> >>> I did some experiments now. My original implementation works fine for up to 32 variables (the number of variables doubles necessarily), then I had some numerical problems. Probably because I did not use the library in an optimal way. I changed to the ExpressionBasedModel and it's really quite easy to use and works fine. For 256 variables runtime "exploded" and computing a solution took several minutes (probably because Q can be quite dense) and I stopped experimenting. However, the use of aojalgo is quite elegant and I can compute several interesting examples. So I will keep using it. I'll have a look at the the other unit tests, too, to get a better feeling for the library. Anyway, thanks again for your help and keep on the good work. >>> >>> >>> >>> >>> Gesendet: Freitag, 10. Januar 2014 um 11:54 Uhr >>> Von: "Nico Potyka" <Nic...@gm...> >>> An: oja...@li... >>> Betreff: Re: [ojAlgo-user] Quadratic Program fails >>> Thanks for your input. Constraints are indeed always restricted to non-negativity and normalization, the problem specific information is encoded in Q. However, existence of a solution is guaranteed for all problem instances. I will let you know what problem size I can handle, after doing some experiments and trying the ExpressionBasedModel. >>> >>> >>>> Yes, the solver swallowed the exception, but did output it to the console. You displayed the solver state using System.out.println(); Didn't you see the exception there? >>> >>> For the code below, >>> >>> System.out.println(tmpResult.getState()); >>> >>> does not print any information about exceptions on my computer. >>> >>> Best regards >>> Nico >>> >>> >>> >>> >>> >>> Gesendet: Freitag, 10. Januar 2014 um 11:21 Uhr >>> Von: "Anders Peterson" <an...@op...> >>> An: "ojAlgo ojAlgo" <oja...@li...> >>> Betreff: Re: [ojAlgo-user] Quadratic Program fails >>> After writing that I felt I had to investigate how large problems ojAlgo can handle... >>> >>> Problems structured as in your test case are easy to solve because the inequality constraints doesn't actually affect the solution. >>> >>> dim=2 => >>> OPTIMAL in 0.042362s >>> dim=4 => >>> OPTIMAL in 6.18E-4s >>> dim=8 => >>> OPTIMAL in 6.97E-4s >>> dim=16 => >>> OPTIMAL in 0.001164s >>> dim=32 => >>> OPTIMAL in 0.003616s >>> dim=64 => >>> OPTIMAL in 0.021859s >>> dim=128 => >>> OPTIMAL in 0.026166s >>> dim=256 => >>> OPTIMAL in 0.02064s >>> dim=512 => >>> OPTIMAL in 0.073304s >>> dim=1024 => >>> OPTIMAL in 0.508432s >>> dim=2048 => >>> OPTIMAL in 3.590416s >>> dim=4096 => >>> OPTIMAL in 24.111358s >>> dim=8192 => >>> OPTIMAL in 186.600192s >>> dim=16384 => >>> Exception in thread "main" java.lang.OutOfMemoryError: Java heap space >>> at org.ojalgo.array.PrimitiveArray.<init>(PrimitiveArray.java:326) >>> >>> >>> If you start adding inequality constraints that actually affect the solution performance will be very different, and if in fact the inequalities make the problem infeasible the algorithm may not be able to recognize that. >>> >>> /Anders >>> >>> >>> On 9 jan 2014, at 22:29, Anders Peterson <an...@op...> wrote: >>> >>>> On 9 jan 2014, at 21:55, Nico Potyka <Nic...@gm...> wrote: >>>> >>>>> Thanks again and sorry for wasting your time. For some reason, there is no exception thrown on my computer and executing the code yields "FAILED". However, after switching to a column vector my general implementation works perfectly fine. >>>> >>>> Yes, the solver swallowed the exception, but did output it to the console. You displayed the solver state using System.out.println(); Didn't you see the exception there? >>>> >>>> >>>>> I took your advice, but I need to perform some matrix operations to determine Q in general and therefore prefered the following example from the unit tests. Furthermore, the problems can become quite large. In fact, most interesting problem instances have hundreds of variables and I can easily construct examples with thousands or millions of variables. Therefore I figured that generating a variable object for each optimization variable might not be the best way to go. But I will give it a try. >>>> >>>> ExpressionsBasedModel is "sparse" it only stores the nonzero problem parameters, so it's not as bad as you may think. The solvers are "dense". >>>> >>>> The general advice would be to initially use ExpressionsBasedModel and then maybe switch to a specific solver if necessary and possible. >>>> >>>> ojAlgo's quadratic solver cannot handle millions of variables! 20000 or so would be an absolute limit and I imagine it will struggle with numerical and performance issues long before that. I don't know where the practical limit is - it depends on your specific case. The largest successful cases I know of has hundreds of variables (not thousands). Please let me know how large models you manage to solve. >>>> >>>> /Anders >>>> >>>> >>>> >>>>> Best regards >>>>> Nico >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> Gesendet: Donnerstag, 09. Januar 2014 um 21:07 Uhr >>>>> Von: "Anders Peterson" <an...@op...> >>>>> An: "ojAlgo ojAlgo" <oja...@li...> >>>>> Betreff: Re: [ojAlgo-user] Quadratic Program fails >>>>> When I run that code I get an ArrayIndexOutOfBoundsException, and that's because "C" should be a column vector rather than a row vector. >>>>> >>>>> Had you taken my advice and used ExpressionsBasedModel this wouldn't have happened. That class actually does something for you: >>>>> >>>>> 1) You can model your problems without worrying about specific solver requirements. >>>>> 2) It knows which solver to use. >>>>> 3) It knows how to use that solver. >>>>> 4) It has a presolver that tries to simplify the problem before invoking a solver (sometimes it turns out there is no need to invoke a solver at all). >>>>> 5) When/if needed it scales problem parameters, before creating solver specific data structures, to minimize numerical problems in the solvers. >>>>> 6) It's the only way to access the integer solver. >>>>> >>>>> /Anders >>>>> >>>>> >>>>> On 9 jan 2014, at 16:53, Nico Potyka <Nic...@gm...> wrote: >>>>> >>>>>> Hi, >>>>>> >>>>>> I tried to use ojAlgo to implement a norm minimization problem, but the solver fails even for very simple instances. The following example is one particular simple instance. Q is the identity matrix, C the zero vector. The constraints express that the solution is a probability function (AE for normalization and AI for non-negativity). Q is positive definite and the solution should be (0.5, 0.5), but qSolver fails. >>>>>> >>>>>> >>>>>> PrimitiveDenseStore tmpQ = PrimitiveDenseStore.FACTORY.rows(new double[][]{{1, 0},{0, 1}}); >>>>>> PrimitiveDenseStore tmpC = PrimitiveDenseStore.FACTORY.rows(new double[][]{{0, 0}}); >>>>>> >>>>>> PrimitiveDenseStore tmpAE = PrimitiveDenseStore.FACTORY.rows(new double[][]{{1, 1}}); >>>>>> PrimitiveDenseStore tmpBE = PrimitiveDenseStore.FACTORY.rows(new double[][]{{1}}); >>>>>> >>>>>> PrimitiveDenseStore tmpAI = PrimitiveDenseStore.FACTORY.rows(new double[][]{{-1, 0}, {0, -1}}); >>>>>> PrimitiveDenseStore tmpBI = PrimitiveDenseStore.FACTORY.rows(new double[][]{{0}, {0}}); >>>>>> >>>>>> QuadraticSolver qSolver = new QuadraticSolver.Builder(tmpQ, tmpC).equalities(tmpAE, tmpBE).inequalities(tmpAI, tmpBI).build(); >>>>>> >>>>>> Optimisation.Result tmpResult = qSolver.solve(); >>>>>> System.out.println(tmpResult.getState()); >>>>>> >>>>>> >>>>>> Is there something wrong in my code or is there a problem with the quadratic solver? >>>>>> >>>>>> Thanks >>>>>> Nico >>>>>> >>>>>> ------------------------------------------------------------------------------ >>>>>> CenturyLink Cloud: The Leader in Enterprise Cloud Services. >>>>>> Learn Why More Businesses Are Choosing CenturyLink Cloud For >>>>>> Critical Workloads, Development Environments & Everything In Between. >>>>>> Get a Quote or Start a Free Trial Today. >>>>>> http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk >>>>>> _______________________________________________ >>>>>> ojAlgo-user mailing list >>>>>> ojA...@li... >>>>>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]]][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]]]] >>>>>> >>>>>> >>>>> >>>>> >>>>> ------------------------------------------------------------------------------ >>>>> CenturyLink Cloud: The Leader in Enterprise Cloud Services. >>>>> Learn Why More Businesses Are Choosing CenturyLink Cloud For >>>>> Critical Workloads, Development Environments & Everything In Between. >>>>> Get a Quote or Start a Free Trial Today. >>>>> http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk][http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk]][http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk][http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk]]][http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk][http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk]][http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk][http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk]]]] >>>>> _______________________________________________ >>>>> ojAlgo-user mailing list >>>>> ojA...@li... >>>>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]]][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]]]] >>>>> >>>>> ------------------------------------------------------------------------------ >>>>> CenturyLink Cloud: The Leader in Enterprise Cloud Services. >>>>> Learn Why More Businesses Are Choosing CenturyLink Cloud For >>>>> Critical Workloads, Development Environments & Everything In Between. >>>>> Get a Quote or Start a Free Trial Today. >>>>> http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk][http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk]][http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk][http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk]]] >>>>> _______________________________________________ >>>>> ojAlgo-user mailing list >>>>> ojA...@li... >>>>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]]] >>> >>> >>> ------------------------------------------------------------------------------ >>> CenturyLink Cloud: The Leader in Enterprise Cloud Services. >>> Learn Why More Businesses Are Choosing CenturyLink Cloud For >>> Critical Workloads, Development Environments & Everything In Between. >>> Get a Quote or Start a Free Trial Today. >>> http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk][http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk]][http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk][http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk]]] >>> _______________________________________________ >>> ojAlgo-user mailing list >>> ojA...@li... >>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]]] >>> >>> ------------------------------------------------------------------------------ >>> CenturyLink Cloud: The Leader in Enterprise Cloud Services. >>> Learn Why More Businesses Are Choosing CenturyLink Cloud For >>> Critical Workloads, Development Environments & Everything In Between. >>> Get a Quote or Start a Free Trial Today. >>> http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk][http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk]] >>> _______________________________________________ >>> ojAlgo-user mailing list >>> ojA...@li... >>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]] >>> >>> ------------------------------------------------------------------------------ >>> CenturyLink Cloud: The Leader in Enterprise Cloud Services. >>> Learn Why More Businesses Are Choosing CenturyLink Cloud For >>> Critical Workloads, Development Environments & Everything In Between. >>> Get a Quote or Start a Free Trial Today. >>> http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk] >>> _______________________________________________ >>> ojAlgo-user mailing list >>> ojA...@li... >>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user] > > > ------------------------------------------------------------------------------ > CenturyLink Cloud: The Leader in Enterprise Cloud Services. > Learn Why More Businesses Are Choosing CenturyLink Cloud For > Critical Workloads, Development Environments & Everything In Between. > Get a Quote or Start a Free Trial Today. > http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk] > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user] > > ------------------------------------------------------------------------------ > CenturyLink Cloud: The Leader in Enterprise Cloud Services. > Learn Why More Businesses Are Choosing CenturyLink Cloud For > Critical Workloads, Development Environments & Everything In Between. > Get a Quote or Start a Free Trial Today. > http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user |
From: Nico P. <Nic...@gm...> - 2014-01-16 09:31:19
|
Thanks for your tips. I tried the debug mode but didn't notice any differences in the output apart from improved accuracy for the expression based model. However, I saw that in the solve-method of the QuadraticSolver class all exceptions (including nullpointer exceptions) are swallowed in the catch-block if you are not in debug mode and the state is just set to FAILED. I'm not sure if this is the way it is meant to be. I also followed your advice and stepped into the code, but couldn't really follow what was going on (not because of the code, but because I need more time to understand how things work together). I noticed, however, that the call of build() in QuadraticSolver qSolver = new QuadraticSolver.Builder(tmpQ, tmpC).equalities(tmpAE, tmpBE).inequalities(tmpAI, tmpBI).build(); also uses an ExpressionBasedModel of the QuadraticSolver.Builder, but it seems to be used in a different way, because its variable list is empty if I get it right. So maybe the crucial difference is the way I define non-negativity constraints in both implementations. For the expression based model I define non-negativity when defining the variables (via lower(BigMath.ZERO)), whereas I define non-negativity by means of the matrix AI (which is the negative unity matrix in my case) for my matrix implementation. If ojAlgo handles non-negativity constraints in a different way than general inequalities, maybe this is a reasonable explanation? By the way, is there another way to define non-negativity when using the build-method as above? In this case I wouldn't need any inequalities at all. I also tried the NullspaceSolver but it yields wrong results for many examples I tested. These examples need some classes from another library, but if it helps for debugging, I will try to build some stand-alone examples and send them to you soon. Best regards Nico Gesendet: Mittwoch, 15. Januar 2014 um 08:46 Uhr Von: "Anders Peterson" <an...@op...> An: "ojAlgo ojAlgo" <oja...@li...> Betreff: Re: [ojAlgo-user] Quadratic Program fails There's one more thing that maybe you're interested in trying. In the QuadraticSolver.Builder.build(Options) method you may change this return new LagrangeSolver(tmpModel, options, this); //return new NullspaceSolver(tmpModel, options, this); into //return new LagrangeSolver(tmpModel, options, this); return new NullspaceSolver(tmpModel, options, this); That solver is NOT READY! It's a very high level experimental implementation of a different algorithm with better numerical performance. In its current state it uses even more memory and executes about 4 times slower than the default algorithm, but it does handle most of the test cases. /Anders On 15 jan 2014, at 07:58, Anders Peterson <an...@op...> wrote: > I'm surprised your initial trials only worked up to 32 variables - that's not much at all... Must be something "unfortunate" with your numbers. > > ExpressionBasedModel obviously did something for you. Debug your code with a breakpoint in the static method QuadraticSolver.make(ExpressionBasedModel). There you should be able to see the actual matrices used in the solver. You can compare that to what you created when you used the solver builder directly.When you've learned what ExpressionBasedModel did maybe you can go back to using the solver/builder and manipulate the input matrices the same way, but more. In your case I'm guessing it's only simple scaling of the problem parameters. > > To learn a little about what goes wrong in the solver you can try this: Set this before you solve. > > tmpModel.options.debug(QuadraticSolver.class); > or > tmpSolver.options.debug(QuadraticSolver.class); > > Only do that for smaller models. Otherwise there will be too much output. > > > /Anders > > > On 14 jan 2014, at 12:53, Nico Potyka <Nic...@gm...> wrote: > >> I did some experiments now. My original implementation works fine for up to 32 variables (the number of variables doubles necessarily), then I had some numerical problems. Probably because I did not use the library in an optimal way. I changed to the ExpressionBasedModel and it's really quite easy to use and works fine. For 256 variables runtime "exploded" and computing a solution took several minutes (probably because Q can be quite dense) and I stopped experimenting. However, the use of aojalgo is quite elegant and I can compute several interesting examples. So I will keep using it. I'll have a look at the the other unit tests, too, to get a better feeling for the library. Anyway, thanks again for your help and keep on the good work. >> >> >> >> >> Gesendet: Freitag, 10. Januar 2014 um 11:54 Uhr >> Von: "Nico Potyka" <Nic...@gm...> >> An: oja...@li... >> Betreff: Re: [ojAlgo-user] Quadratic Program fails >> Thanks for your input. Constraints are indeed always restricted to non-negativity and normalization, the problem specific information is encoded in Q. However, existence of a solution is guaranteed for all problem instances. I will let you know what problem size I can handle, after doing some experiments and trying the ExpressionBasedModel. >> >> >>> Yes, the solver swallowed the exception, but did output it to the console. You displayed the solver state using System.out.println(); Didn't you see the exception there? >> >> For the code below, >> >> System.out.println(tmpResult.getState()); >> >> does not print any information about exceptions on my computer. >> >> Best regards >> Nico >> >> >> >> >> >> Gesendet: Freitag, 10. Januar 2014 um 11:21 Uhr >> Von: "Anders Peterson" <an...@op...> >> An: "ojAlgo ojAlgo" <oja...@li...> >> Betreff: Re: [ojAlgo-user] Quadratic Program fails >> After writing that I felt I had to investigate how large problems ojAlgo can handle... >> >> Problems structured as in your test case are easy to solve because the inequality constraints doesn't actually affect the solution. >> >> dim=2 => >> OPTIMAL in 0.042362s >> dim=4 => >> OPTIMAL in 6.18E-4s >> dim=8 => >> OPTIMAL in 6.97E-4s >> dim=16 => >> OPTIMAL in 0.001164s >> dim=32 => >> OPTIMAL in 0.003616s >> dim=64 => >> OPTIMAL in 0.021859s >> dim=128 => >> OPTIMAL in 0.026166s >> dim=256 => >> OPTIMAL in 0.02064s >> dim=512 => >> OPTIMAL in 0.073304s >> dim=1024 => >> OPTIMAL in 0.508432s >> dim=2048 => >> OPTIMAL in 3.590416s >> dim=4096 => >> OPTIMAL in 24.111358s >> dim=8192 => >> OPTIMAL in 186.600192s >> dim=16384 => >> Exception in thread "main" java.lang.OutOfMemoryError: Java heap space >> at org.ojalgo.array.PrimitiveArray.<init>(PrimitiveArray.java:326) >> >> >> If you start adding inequality constraints that actually affect the solution performance will be very different, and if in fact the inequalities make the problem infeasible the algorithm may not be able to recognize that. >> >> /Anders >> >> >> On 9 jan 2014, at 22:29, Anders Peterson <an...@op...> wrote: >> >>> On 9 jan 2014, at 21:55, Nico Potyka <Nic...@gm...> wrote: >>> >>>> Thanks again and sorry for wasting your time. For some reason, there is no exception thrown on my computer and executing the code yields "FAILED". However, after switching to a column vector my general implementation works perfectly fine. >>> >>> Yes, the solver swallowed the exception, but did output it to the console. You displayed the solver state using System.out.println(); Didn't you see the exception there? >>> >>> >>>> I took your advice, but I need to perform some matrix operations to determine Q in general and therefore prefered the following example from the unit tests. Furthermore, the problems can become quite large. In fact, most interesting problem instances have hundreds of variables and I can easily construct examples with thousands or millions of variables. Therefore I figured that generating a variable object for each optimization variable might not be the best way to go. But I will give it a try. >>> >>> ExpressionsBasedModel is "sparse" it only stores the nonzero problem parameters, so it's not as bad as you may think. The solvers are "dense". >>> >>> The general advice would be to initially use ExpressionsBasedModel and then maybe switch to a specific solver if necessary and possible. >>> >>> ojAlgo's quadratic solver cannot handle millions of variables! 20000 or so would be an absolute limit and I imagine it will struggle with numerical and performance issues long before that. I don't know where the practical limit is - it depends on your specific case. The largest successful cases I know of has hundreds of variables (not thousands). Please let me know how large models you manage to solve. >>> >>> /Anders >>> >>> >>> >>>> Best regards >>>> Nico >>>> >>>> >>>> >>>> >>>> >>>> Gesendet: Donnerstag, 09. Januar 2014 um 21:07 Uhr >>>> Von: "Anders Peterson" <an...@op...> >>>> An: "ojAlgo ojAlgo" <oja...@li...> >>>> Betreff: Re: [ojAlgo-user] Quadratic Program fails >>>> When I run that code I get an ArrayIndexOutOfBoundsException, and that's because "C" should be a column vector rather than a row vector. >>>> >>>> Had you taken my advice and used ExpressionsBasedModel this wouldn't have happened. That class actually does something for you: >>>> >>>> 1) You can model your problems without worrying about specific solver requirements. >>>> 2) It knows which solver to use. >>>> 3) It knows how to use that solver. >>>> 4) It has a presolver that tries to simplify the problem before invoking a solver (sometimes it turns out there is no need to invoke a solver at all). >>>> 5) When/if needed it scales problem parameters, before creating solver specific data structures, to minimize numerical problems in the solvers. >>>> 6) It's the only way to access the integer solver. >>>> >>>> /Anders >>>> >>>> >>>> On 9 jan 2014, at 16:53, Nico Potyka <Nic...@gm...> wrote: >>>> >>>>> Hi, >>>>> >>>>> I tried to use ojAlgo to implement a norm minimization problem, but the solver fails even for very simple instances. The following example is one particular simple instance. Q is the identity matrix, C the zero vector. The constraints express that the solution is a probability function (AE for normalization and AI for non-negativity). Q is positive definite and the solution should be (0.5, 0.5), but qSolver fails. >>>>> >>>>> >>>>> PrimitiveDenseStore tmpQ = PrimitiveDenseStore.FACTORY.rows(new double[][]{{1, 0},{0, 1}}); >>>>> PrimitiveDenseStore tmpC = PrimitiveDenseStore.FACTORY.rows(new double[][]{{0, 0}}); >>>>> >>>>> PrimitiveDenseStore tmpAE = PrimitiveDenseStore.FACTORY.rows(new double[][]{{1, 1}}); >>>>> PrimitiveDenseStore tmpBE = PrimitiveDenseStore.FACTORY.rows(new double[][]{{1}}); >>>>> >>>>> PrimitiveDenseStore tmpAI = PrimitiveDenseStore.FACTORY.rows(new double[][]{{-1, 0}, {0, -1}}); >>>>> PrimitiveDenseStore tmpBI = PrimitiveDenseStore.FACTORY.rows(new double[][]{{0}, {0}}); >>>>> >>>>> QuadraticSolver qSolver = new QuadraticSolver.Builder(tmpQ, tmpC).equalities(tmpAE, tmpBE).inequalities(tmpAI, tmpBI).build(); >>>>> >>>>> Optimisation.Result tmpResult = qSolver.solve(); >>>>> System.out.println(tmpResult.getState()); >>>>> >>>>> >>>>> Is there something wrong in my code or is there a problem with the quadratic solver? >>>>> >>>>> Thanks >>>>> Nico >>>>> >>>>> ------------------------------------------------------------------------------ >>>>> CenturyLink Cloud: The Leader in Enterprise Cloud Services. >>>>> Learn Why More Businesses Are Choosing CenturyLink Cloud For >>>>> Critical Workloads, Development Environments & Everything In Between. >>>>> Get a Quote or Start a Free Trial Today. >>>>> http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk >>>>> _______________________________________________ >>>>> ojAlgo-user mailing list >>>>> ojA...@li... >>>>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]]][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]]]] >>>>> >>>>> >>>> >>>> >>>> ------------------------------------------------------------------------------ >>>> CenturyLink Cloud: The Leader in Enterprise Cloud Services. >>>> Learn Why More Businesses Are Choosing CenturyLink Cloud For >>>> Critical Workloads, Development Environments & Everything In Between. >>>> Get a Quote or Start a Free Trial Today. >>>> http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk][http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk]][http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk][http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk]]][http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk][http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk]][http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk][http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk]]]] >>>> _______________________________________________ >>>> ojAlgo-user mailing list >>>> ojA...@li... >>>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]]][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]]]] >>>> >>>> ------------------------------------------------------------------------------ >>>> CenturyLink Cloud: The Leader in Enterprise Cloud Services. >>>> Learn Why More Businesses Are Choosing CenturyLink Cloud For >>>> Critical Workloads, Development Environments & Everything In Between. >>>> Get a Quote or Start a Free Trial Today. >>>> http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk][http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk]][http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk][http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk]]] >>>> _______________________________________________ >>>> ojAlgo-user mailing list >>>> ojA...@li... >>>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]]] >> >> >> ------------------------------------------------------------------------------ >> CenturyLink Cloud: The Leader in Enterprise Cloud Services. >> Learn Why More Businesses Are Choosing CenturyLink Cloud For >> Critical Workloads, Development Environments & Everything In Between. >> Get a Quote or Start a Free Trial Today. >> http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk][http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk]][http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk][http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk]]] >> _______________________________________________ >> ojAlgo-user mailing list >> ojA...@li... >> https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]]] >> >> ------------------------------------------------------------------------------ >> CenturyLink Cloud: The Leader in Enterprise Cloud Services. >> Learn Why More Businesses Are Choosing CenturyLink Cloud For >> Critical Workloads, Development Environments & Everything In Between. >> Get a Quote or Start a Free Trial Today. >> http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk][http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk]] >> _______________________________________________ >> ojAlgo-user mailing list >> ojA...@li... >> https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]] >> >> ------------------------------------------------------------------------------ >> CenturyLink Cloud: The Leader in Enterprise Cloud Services. >> Learn Why More Businesses Are Choosing CenturyLink Cloud For >> Critical Workloads, Development Environments & Everything In Between. >> Get a Quote or Start a Free Trial Today. >> http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk] >> _______________________________________________ >> ojAlgo-user mailing list >> ojA...@li... >> https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user] ------------------------------------------------------------------------------ CenturyLink Cloud: The Leader in Enterprise Cloud Services. Learn Why More Businesses Are Choosing CenturyLink Cloud For Critical Workloads, Development Environments & Everything In Between. Get a Quote or Start a Free Trial Today. http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk] _______________________________________________ ojAlgo-user mailing list ojA...@li... https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user] |
From: Anders P. <an...@op...> - 2014-01-15 07:46:38
|
There's one more thing that maybe you're interested in trying. In the QuadraticSolver.Builder.build(Options) method you may change this return new LagrangeSolver(tmpModel, options, this); //return new NullspaceSolver(tmpModel, options, this); into //return new LagrangeSolver(tmpModel, options, this); return new NullspaceSolver(tmpModel, options, this); That solver is NOT READY! It's a very high level experimental implementation of a different algorithm with better numerical performance. In its current state it uses even more memory and executes about 4 times slower than the default algorithm, but it does handle most of the test cases. /Anders On 15 jan 2014, at 07:58, Anders Peterson <an...@op...> wrote: > I'm surprised your initial trials only worked up to 32 variables - that's not much at all... Must be something "unfortunate" with your numbers. > > ExpressionBasedModel obviously did something for you. Debug your code with a breakpoint in the static method QuadraticSolver.make(ExpressionBasedModel). There you should be able to see the actual matrices used in the solver. You can compare that to what you created when you used the solver builder directly.When you've learned what ExpressionBasedModel did maybe you can go back to using the solver/builder and manipulate the input matrices the same way, but more. In your case I'm guessing it's only simple scaling of the problem parameters. > > To learn a little about what goes wrong in the solver you can try this: Set this before you solve. > > tmpModel.options.debug(QuadraticSolver.class); > or > tmpSolver.options.debug(QuadraticSolver.class); > > Only do that for smaller models. Otherwise there will be too much output. > > > /Anders > > > On 14 jan 2014, at 12:53, Nico Potyka <Nic...@gm...> wrote: > >> I did some experiments now. My original implementation works fine for up to 32 variables (the number of variables doubles necessarily), then I had some numerical problems. Probably because I did not use the library in an optimal way. I changed to the ExpressionBasedModel and it's really quite easy to use and works fine. For 256 variables runtime "exploded" and computing a solution took several minutes (probably because Q can be quite dense) and I stopped experimenting. However, the use of aojalgo is quite elegant and I can compute several interesting examples. So I will keep using it. I'll have a look at the the other unit tests, too, to get a better feeling for the library. Anyway, thanks again for your help and keep on the good work. >> >> >> >> >> Gesendet: Freitag, 10. Januar 2014 um 11:54 Uhr >> Von: "Nico Potyka" <Nic...@gm...> >> An: oja...@li... >> Betreff: Re: [ojAlgo-user] Quadratic Program fails >> Thanks for your input. Constraints are indeed always restricted to non-negativity and normalization, the problem specific information is encoded in Q. However, existence of a solution is guaranteed for all problem instances. I will let you know what problem size I can handle, after doing some experiments and trying the ExpressionBasedModel. >> >> >>> Yes, the solver swallowed the exception, but did output it to the console. You displayed the solver state using System.out.println(); Didn't you see the exception there? >> >> For the code below, >> >> System.out.println(tmpResult.getState()); >> >> does not print any information about exceptions on my computer. >> >> Best regards >> Nico >> >> >> >> >> >> Gesendet: Freitag, 10. Januar 2014 um 11:21 Uhr >> Von: "Anders Peterson" <an...@op...> >> An: "ojAlgo ojAlgo" <oja...@li...> >> Betreff: Re: [ojAlgo-user] Quadratic Program fails >> After writing that I felt I had to investigate how large problems ojAlgo can handle... >> >> Problems structured as in your test case are easy to solve because the inequality constraints doesn't actually affect the solution. >> >> dim=2 => >> OPTIMAL in 0.042362s >> dim=4 => >> OPTIMAL in 6.18E-4s >> dim=8 => >> OPTIMAL in 6.97E-4s >> dim=16 => >> OPTIMAL in 0.001164s >> dim=32 => >> OPTIMAL in 0.003616s >> dim=64 => >> OPTIMAL in 0.021859s >> dim=128 => >> OPTIMAL in 0.026166s >> dim=256 => >> OPTIMAL in 0.02064s >> dim=512 => >> OPTIMAL in 0.073304s >> dim=1024 => >> OPTIMAL in 0.508432s >> dim=2048 => >> OPTIMAL in 3.590416s >> dim=4096 => >> OPTIMAL in 24.111358s >> dim=8192 => >> OPTIMAL in 186.600192s >> dim=16384 => >> Exception in thread "main" java.lang.OutOfMemoryError: Java heap space >> at org.ojalgo.array.PrimitiveArray.<init>(PrimitiveArray.java:326) >> >> >> If you start adding inequality constraints that actually affect the solution performance will be very different, and if in fact the inequalities make the problem infeasible the algorithm may not be able to recognize that. >> >> /Anders >> >> >> On 9 jan 2014, at 22:29, Anders Peterson <an...@op...> wrote: >> >>> On 9 jan 2014, at 21:55, Nico Potyka <Nic...@gm...> wrote: >>> >>>> Thanks again and sorry for wasting your time. For some reason, there is no exception thrown on my computer and executing the code yields "FAILED". However, after switching to a column vector my general implementation works perfectly fine. >>> >>> Yes, the solver swallowed the exception, but did output it to the console. You displayed the solver state using System.out.println(); Didn't you see the exception there? >>> >>> >>>> I took your advice, but I need to perform some matrix operations to determine Q in general and therefore prefered the following example from the unit tests. Furthermore, the problems can become quite large. In fact, most interesting problem instances have hundreds of variables and I can easily construct examples with thousands or millions of variables. Therefore I figured that generating a variable object for each optimization variable might not be the best way to go. But I will give it a try. >>> >>> ExpressionsBasedModel is "sparse" it only stores the nonzero problem parameters, so it's not as bad as you may think. The solvers are "dense". >>> >>> The general advice would be to initially use ExpressionsBasedModel and then maybe switch to a specific solver if necessary and possible. >>> >>> ojAlgo's quadratic solver cannot handle millions of variables! 20000 or so would be an absolute limit and I imagine it will struggle with numerical and performance issues long before that. I don't know where the practical limit is - it depends on your specific case. The largest successful cases I know of has hundreds of variables (not thousands). Please let me know how large models you manage to solve. >>> >>> /Anders >>> >>> >>> >>>> Best regards >>>> Nico >>>> >>>> >>>> >>>> >>>> >>>> Gesendet: Donnerstag, 09. Januar 2014 um 21:07 Uhr >>>> Von: "Anders Peterson" <an...@op...> >>>> An: "ojAlgo ojAlgo" <oja...@li...> >>>> Betreff: Re: [ojAlgo-user] Quadratic Program fails >>>> When I run that code I get an ArrayIndexOutOfBoundsException, and that's because "C" should be a column vector rather than a row vector. >>>> >>>> Had you taken my advice and used ExpressionsBasedModel this wouldn't have happened. That class actually does something for you: >>>> >>>> 1) You can model your problems without worrying about specific solver requirements. >>>> 2) It knows which solver to use. >>>> 3) It knows how to use that solver. >>>> 4) It has a presolver that tries to simplify the problem before invoking a solver (sometimes it turns out there is no need to invoke a solver at all). >>>> 5) When/if needed it scales problem parameters, before creating solver specific data structures, to minimize numerical problems in the solvers. >>>> 6) It's the only way to access the integer solver. >>>> >>>> /Anders >>>> >>>> >>>> On 9 jan 2014, at 16:53, Nico Potyka <Nic...@gm...> wrote: >>>> >>>>> Hi, >>>>> >>>>> I tried to use ojAlgo to implement a norm minimization problem, but the solver fails even for very simple instances. The following example is one particular simple instance. Q is the identity matrix, C the zero vector. The constraints express that the solution is a probability function (AE for normalization and AI for non-negativity). Q is positive definite and the solution should be (0.5, 0.5), but qSolver fails. >>>>> >>>>> >>>>> PrimitiveDenseStore tmpQ = PrimitiveDenseStore.FACTORY.rows(new double[][]{{1, 0},{0, 1}}); >>>>> PrimitiveDenseStore tmpC = PrimitiveDenseStore.FACTORY.rows(new double[][]{{0, 0}}); >>>>> >>>>> PrimitiveDenseStore tmpAE = PrimitiveDenseStore.FACTORY.rows(new double[][]{{1, 1}}); >>>>> PrimitiveDenseStore tmpBE = PrimitiveDenseStore.FACTORY.rows(new double[][]{{1}}); >>>>> >>>>> PrimitiveDenseStore tmpAI = PrimitiveDenseStore.FACTORY.rows(new double[][]{{-1, 0}, {0, -1}}); >>>>> PrimitiveDenseStore tmpBI = PrimitiveDenseStore.FACTORY.rows(new double[][]{{0}, {0}}); >>>>> >>>>> QuadraticSolver qSolver = new QuadraticSolver.Builder(tmpQ, tmpC).equalities(tmpAE, tmpBE).inequalities(tmpAI, tmpBI).build(); >>>>> >>>>> Optimisation.Result tmpResult = qSolver.solve(); >>>>> System.out.println(tmpResult.getState()); >>>>> >>>>> >>>>> Is there something wrong in my code or is there a problem with the quadratic solver? >>>>> >>>>> Thanks >>>>> Nico >>>>> >>>>> ------------------------------------------------------------------------------ >>>>> CenturyLink Cloud: The Leader in Enterprise Cloud Services. >>>>> Learn Why More Businesses Are Choosing CenturyLink Cloud For >>>>> Critical Workloads, Development Environments & Everything In Between. >>>>> Get a Quote or Start a Free Trial Today. >>>>> http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk >>>>> _______________________________________________ >>>>> ojAlgo-user mailing list >>>>> ojA...@li... >>>>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]]] >>>>> >>>>> >>>> >>>> >>>> ------------------------------------------------------------------------------ >>>> CenturyLink Cloud: The Leader in Enterprise Cloud Services. >>>> Learn Why More Businesses Are Choosing CenturyLink Cloud For >>>> Critical Workloads, Development Environments & Everything In Between. >>>> Get a Quote or Start a Free Trial Today. >>>> http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk][http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk]][http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk][http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk]]] >>>> _______________________________________________ >>>> ojAlgo-user mailing list >>>> ojA...@li... >>>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]]] >>>> >>>> ------------------------------------------------------------------------------ >>>> CenturyLink Cloud: The Leader in Enterprise Cloud Services. >>>> Learn Why More Businesses Are Choosing CenturyLink Cloud For >>>> Critical Workloads, Development Environments & Everything In Between. >>>> Get a Quote or Start a Free Trial Today. >>>> http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk][http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk]] >>>> _______________________________________________ >>>> ojAlgo-user mailing list >>>> ojA...@li... >>>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]] >> >> >> ------------------------------------------------------------------------------ >> CenturyLink Cloud: The Leader in Enterprise Cloud Services. >> Learn Why More Businesses Are Choosing CenturyLink Cloud For >> Critical Workloads, Development Environments & Everything In Between. >> Get a Quote or Start a Free Trial Today. >> http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk][http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk]] >> _______________________________________________ >> ojAlgo-user mailing list >> ojA...@li... >> https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]] >> >> ------------------------------------------------------------------------------ >> CenturyLink Cloud: The Leader in Enterprise Cloud Services. >> Learn Why More Businesses Are Choosing CenturyLink Cloud For >> Critical Workloads, Development Environments & Everything In Between. >> Get a Quote or Start a Free Trial Today. >> http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk] >> _______________________________________________ >> ojAlgo-user mailing list >> ojA...@li... >> https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user] >> >> ------------------------------------------------------------------------------ >> CenturyLink Cloud: The Leader in Enterprise Cloud Services. >> Learn Why More Businesses Are Choosing CenturyLink Cloud For >> Critical Workloads, Development Environments & Everything In Between. >> Get a Quote or Start a Free Trial Today. >> http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk >> _______________________________________________ >> ojAlgo-user mailing list >> ojA...@li... >> https://lists.sourceforge.net/lists/listinfo/ojalgo-user |
From: Anders P. <an...@op...> - 2014-01-15 07:11:42
|
The MarkowitzModel class in the finance.portfolio package cannot handle this. You have to build your own model using ExpressionBasedModel. it'a not hard. I posted a link to an example just the other day. /Anders On 14 jan 2014, at 16:31, Anthony Edwards <ant...@al...> wrote: > Hi Anders > > If i want to create a market neutral portfolio (same capital long and short), how can i do that with the MarkowitzModel ? > > The doc says that the sum of weights is 100% but you can emable shorting, but is there a way to keep the long and short side the same net value? > > Thanks > ------------------------------------------------------------------------------ > CenturyLink Cloud: The Leader in Enterprise Cloud Services. > Learn Why More Businesses Are Choosing CenturyLink Cloud For > Critical Workloads, Development Environments & Everything In Between. > Get a Quote or Start a Free Trial Today. > http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk_______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user |
From: Anders P. <an...@op...> - 2014-01-15 06:59:14
|
I'm surprised your initial trials only worked up to 32 variables - that's not much at all... Must be something "unfortunate" with your numbers. ExpressionBasedModel obviously did something for you. Debug your code with a breakpoint in the static method QuadraticSolver.make(ExpressionBasedModel). There you should be able to see the actual matrices used in the solver. You can compare that to what you created when you used the solver builder directly.When you've learned what ExpressionBasedModel did maybe you can go back to using the solver/builder and manipulate the input matrices the same way, but more. In your case I'm guessing it's only simple scaling of the problem parameters. To learn a little about what goes wrong in the solver you can try this: Set this before you solve. tmpModel.options.debug(QuadraticSolver.class); or tmpSolver.options.debug(QuadraticSolver.class); Only do that for smaller models. Otherwise there will be too much output. /Anders On 14 jan 2014, at 12:53, Nico Potyka <Nic...@gm...> wrote: > I did some experiments now. My original implementation works fine for up to 32 variables (the number of variables doubles necessarily), then I had some numerical problems. Probably because I did not use the library in an optimal way. I changed to the ExpressionBasedModel and it's really quite easy to use and works fine. For 256 variables runtime "exploded" and computing a solution took several minutes (probably because Q can be quite dense) and I stopped experimenting. However, the use of aojalgo is quite elegant and I can compute several interesting examples. So I will keep using it. I'll have a look at the the other unit tests, too, to get a better feeling for the library. Anyway, thanks again for your help and keep on the good work. > > > > > Gesendet: Freitag, 10. Januar 2014 um 11:54 Uhr > Von: "Nico Potyka" <Nic...@gm...> > An: oja...@li... > Betreff: Re: [ojAlgo-user] Quadratic Program fails > Thanks for your input. Constraints are indeed always restricted to non-negativity and normalization, the problem specific information is encoded in Q. However, existence of a solution is guaranteed for all problem instances. I will let you know what problem size I can handle, after doing some experiments and trying the ExpressionBasedModel. > > >> Yes, the solver swallowed the exception, but did output it to the console. You displayed the solver state using System.out.println(); Didn't you see the exception there? > > For the code below, > > System.out.println(tmpResult.getState()); > > does not print any information about exceptions on my computer. > > Best regards > Nico > > > > > > Gesendet: Freitag, 10. Januar 2014 um 11:21 Uhr > Von: "Anders Peterson" <an...@op...> > An: "ojAlgo ojAlgo" <oja...@li...> > Betreff: Re: [ojAlgo-user] Quadratic Program fails > After writing that I felt I had to investigate how large problems ojAlgo can handle... > > Problems structured as in your test case are easy to solve because the inequality constraints doesn't actually affect the solution. > > dim=2 => > OPTIMAL in 0.042362s > dim=4 => > OPTIMAL in 6.18E-4s > dim=8 => > OPTIMAL in 6.97E-4s > dim=16 => > OPTIMAL in 0.001164s > dim=32 => > OPTIMAL in 0.003616s > dim=64 => > OPTIMAL in 0.021859s > dim=128 => > OPTIMAL in 0.026166s > dim=256 => > OPTIMAL in 0.02064s > dim=512 => > OPTIMAL in 0.073304s > dim=1024 => > OPTIMAL in 0.508432s > dim=2048 => > OPTIMAL in 3.590416s > dim=4096 => > OPTIMAL in 24.111358s > dim=8192 => > OPTIMAL in 186.600192s > dim=16384 => > Exception in thread "main" java.lang.OutOfMemoryError: Java heap space > at org.ojalgo.array.PrimitiveArray.<init>(PrimitiveArray.java:326) > > > If you start adding inequality constraints that actually affect the solution performance will be very different, and if in fact the inequalities make the problem infeasible the algorithm may not be able to recognize that. > > /Anders > > > On 9 jan 2014, at 22:29, Anders Peterson <an...@op...> wrote: > >> On 9 jan 2014, at 21:55, Nico Potyka <Nic...@gm...> wrote: >> >>> Thanks again and sorry for wasting your time. For some reason, there is no exception thrown on my computer and executing the code yields "FAILED". However, after switching to a column vector my general implementation works perfectly fine. >> >> Yes, the solver swallowed the exception, but did output it to the console. You displayed the solver state using System.out.println(); Didn't you see the exception there? >> >> >>> I took your advice, but I need to perform some matrix operations to determine Q in general and therefore prefered the following example from the unit tests. Furthermore, the problems can become quite large. In fact, most interesting problem instances have hundreds of variables and I can easily construct examples with thousands or millions of variables. Therefore I figured that generating a variable object for each optimization variable might not be the best way to go. But I will give it a try. >> >> ExpressionsBasedModel is "sparse" it only stores the nonzero problem parameters, so it's not as bad as you may think. The solvers are "dense". >> >> The general advice would be to initially use ExpressionsBasedModel and then maybe switch to a specific solver if necessary and possible. >> >> ojAlgo's quadratic solver cannot handle millions of variables! 20000 or so would be an absolute limit and I imagine it will struggle with numerical and performance issues long before that. I don't know where the practical limit is - it depends on your specific case. The largest successful cases I know of has hundreds of variables (not thousands). Please let me know how large models you manage to solve. >> >> /Anders >> >> >> >>> Best regards >>> Nico >>> >>> >>> >>> >>> >>> Gesendet: Donnerstag, 09. Januar 2014 um 21:07 Uhr >>> Von: "Anders Peterson" <an...@op...> >>> An: "ojAlgo ojAlgo" <oja...@li...> >>> Betreff: Re: [ojAlgo-user] Quadratic Program fails >>> When I run that code I get an ArrayIndexOutOfBoundsException, and that's because "C" should be a column vector rather than a row vector. >>> >>> Had you taken my advice and used ExpressionsBasedModel this wouldn't have happened. That class actually does something for you: >>> >>> 1) You can model your problems without worrying about specific solver requirements. >>> 2) It knows which solver to use. >>> 3) It knows how to use that solver. >>> 4) It has a presolver that tries to simplify the problem before invoking a solver (sometimes it turns out there is no need to invoke a solver at all). >>> 5) When/if needed it scales problem parameters, before creating solver specific data structures, to minimize numerical problems in the solvers. >>> 6) It's the only way to access the integer solver. >>> >>> /Anders >>> >>> >>> On 9 jan 2014, at 16:53, Nico Potyka <Nic...@gm...> wrote: >>> >>>> Hi, >>>> >>>> I tried to use ojAlgo to implement a norm minimization problem, but the solver fails even for very simple instances. The following example is one particular simple instance. Q is the identity matrix, C the zero vector. The constraints express that the solution is a probability function (AE for normalization and AI for non-negativity). Q is positive definite and the solution should be (0.5, 0.5), but qSolver fails. >>>> >>>> >>>> PrimitiveDenseStore tmpQ = PrimitiveDenseStore.FACTORY.rows(new double[][]{{1, 0},{0, 1}}); >>>> PrimitiveDenseStore tmpC = PrimitiveDenseStore.FACTORY.rows(new double[][]{{0, 0}}); >>>> >>>> PrimitiveDenseStore tmpAE = PrimitiveDenseStore.FACTORY.rows(new double[][]{{1, 1}}); >>>> PrimitiveDenseStore tmpBE = PrimitiveDenseStore.FACTORY.rows(new double[][]{{1}}); >>>> >>>> PrimitiveDenseStore tmpAI = PrimitiveDenseStore.FACTORY.rows(new double[][]{{-1, 0}, {0, -1}}); >>>> PrimitiveDenseStore tmpBI = PrimitiveDenseStore.FACTORY.rows(new double[][]{{0}, {0}}); >>>> >>>> QuadraticSolver qSolver = new QuadraticSolver.Builder(tmpQ, tmpC).equalities(tmpAE, tmpBE).inequalities(tmpAI, tmpBI).build(); >>>> >>>> Optimisation.Result tmpResult = qSolver.solve(); >>>> System.out.println(tmpResult.getState()); >>>> >>>> >>>> Is there something wrong in my code or is there a problem with the quadratic solver? >>>> >>>> Thanks >>>> Nico >>>> >>>> ------------------------------------------------------------------------------ >>>> CenturyLink Cloud: The Leader in Enterprise Cloud Services. >>>> Learn Why More Businesses Are Choosing CenturyLink Cloud For >>>> Critical Workloads, Development Environments & Everything In Between. >>>> Get a Quote or Start a Free Trial Today. >>>> http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk >>>> _______________________________________________ >>>> ojAlgo-user mailing list >>>> ojA...@li... >>>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]]] >>>> >>>> >>> >>> >>> ------------------------------------------------------------------------------ >>> CenturyLink Cloud: The Leader in Enterprise Cloud Services. >>> Learn Why More Businesses Are Choosing CenturyLink Cloud For >>> Critical Workloads, Development Environments & Everything In Between. >>> Get a Quote or Start a Free Trial Today. >>> http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk][http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk]][http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk][http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk]]] >>> _______________________________________________ >>> ojAlgo-user mailing list >>> ojA...@li... >>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]]] >>> >>> ------------------------------------------------------------------------------ >>> CenturyLink Cloud: The Leader in Enterprise Cloud Services. >>> Learn Why More Businesses Are Choosing CenturyLink Cloud For >>> Critical Workloads, Development Environments & Everything In Between. >>> Get a Quote or Start a Free Trial Today. >>> http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk][http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk]] >>> _______________________________________________ >>> ojAlgo-user mailing list >>> ojA...@li... >>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]] > > > ------------------------------------------------------------------------------ > CenturyLink Cloud: The Leader in Enterprise Cloud Services. > Learn Why More Businesses Are Choosing CenturyLink Cloud For > Critical Workloads, Development Environments & Everything In Between. > Get a Quote or Start a Free Trial Today. > http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk][http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk]] > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]] > > ------------------------------------------------------------------------------ > CenturyLink Cloud: The Leader in Enterprise Cloud Services. > Learn Why More Businesses Are Choosing CenturyLink Cloud For > Critical Workloads, Development Environments & Everything In Between. > Get a Quote or Start a Free Trial Today. > http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk] > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user] > > ------------------------------------------------------------------------------ > CenturyLink Cloud: The Leader in Enterprise Cloud Services. > Learn Why More Businesses Are Choosing CenturyLink Cloud For > Critical Workloads, Development Environments & Everything In Between. > Get a Quote or Start a Free Trial Today. > http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user |
From: Anthony E. <ant...@al...> - 2014-01-14 16:01:25
|
Hi Anders If i want to create a market neutral portfolio (same capital long and short), how can i do that with the MarkowitzModel ? The doc says that the sum of weights is 100% but you can emable shorting, but is there a way to keep the long and short side the same net value? Thanks |
From: Nico P. <Nic...@gm...> - 2014-01-14 11:53:30
|
I did some experiments now. My original implementation works fine for up to 32 variables (the number of variables doubles necessarily), then I had some numerical problems. Probably because I did not use the library in an optimal way. I changed to the ExpressionBasedModel and it's really quite easy to use and works fine. For 256 variables runtime "exploded" and computing a solution took several minutes (probably because Q can be quite dense) and I stopped experimenting. However, the use of aojalgo is quite elegant and I can compute several interesting examples. So I will keep using it. I'll have a look at the the other unit tests, too, to get a better feeling for the library. Anyway, thanks again for your help and keep on the good work. Gesendet: Freitag, 10. Januar 2014 um 11:54 Uhr Von: "Nico Potyka" <Nic...@gm...> An: oja...@li... Betreff: Re: [ojAlgo-user] Quadratic Program fails Thanks for your input. Constraints are indeed always restricted to non-negativity and normalization, the problem specific information is encoded in Q. However, existence of a solution is guaranteed for all problem instances. I will let you know what problem size I can handle, after doing some experiments and trying the ExpressionBasedModel. > Yes, the solver swallowed the exception, but did output it to the console. You displayed the solver state using System.out.println(); Didn't you see the exception there? For the code below, System.out.println(tmpResult.getState()); does not print any information about exceptions on my computer. Best regards Nico Gesendet: Freitag, 10. Januar 2014 um 11:21 Uhr Von: "Anders Peterson" <an...@op...> An: "ojAlgo ojAlgo" <oja...@li...> Betreff: Re: [ojAlgo-user] Quadratic Program fails After writing that I felt I had to investigate how large problems ojAlgo can handle... Problems structured as in your test case are easy to solve because the inequality constraints doesn't actually affect the solution. dim=2 => OPTIMAL in 0.042362s dim=4 => OPTIMAL in 6.18E-4s dim=8 => OPTIMAL in 6.97E-4s dim=16 => OPTIMAL in 0.001164s dim=32 => OPTIMAL in 0.003616s dim=64 => OPTIMAL in 0.021859s dim=128 => OPTIMAL in 0.026166s dim=256 => OPTIMAL in 0.02064s dim=512 => OPTIMAL in 0.073304s dim=1024 => OPTIMAL in 0.508432s dim=2048 => OPTIMAL in 3.590416s dim=4096 => OPTIMAL in 24.111358s dim=8192 => OPTIMAL in 186.600192s dim=16384 => Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at org.ojalgo.array.PrimitiveArray.<init>(PrimitiveArray.java:326) If you start adding inequality constraints that actually affect the solution performance will be very different, and if in fact the inequalities make the problem infeasible the algorithm may not be able to recognize that. /Anders On 9 jan 2014, at 22:29, Anders Peterson <an...@op...> wrote: > On 9 jan 2014, at 21:55, Nico Potyka <Nic...@gm...> wrote: > >> Thanks again and sorry for wasting your time. For some reason, there is no exception thrown on my computer and executing the code yields "FAILED". However, after switching to a column vector my general implementation works perfectly fine. > > Yes, the solver swallowed the exception, but did output it to the console. You displayed the solver state using System.out.println(); Didn't you see the exception there? > > >> I took your advice, but I need to perform some matrix operations to determine Q in general and therefore prefered the following example from the unit tests. Furthermore, the problems can become quite large. In fact, most interesting problem instances have hundreds of variables and I can easily construct examples with thousands or millions of variables. Therefore I figured that generating a variable object for each optimization variable might not be the best way to go. But I will give it a try. > > ExpressionsBasedModel is "sparse" it only stores the nonzero problem parameters, so it's not as bad as you may think. The solvers are "dense". > > The general advice would be to initially use ExpressionsBasedModel and then maybe switch to a specific solver if necessary and possible. > > ojAlgo's quadratic solver cannot handle millions of variables! 20000 or so would be an absolute limit and I imagine it will struggle with numerical and performance issues long before that. I don't know where the practical limit is - it depends on your specific case. The largest successful cases I know of has hundreds of variables (not thousands). Please let me know how large models you manage to solve. > > /Anders > > > >> Best regards >> Nico >> >> >> >> >> >> Gesendet: Donnerstag, 09. Januar 2014 um 21:07 Uhr >> Von: "Anders Peterson" <an...@op...> >> An: "ojAlgo ojAlgo" <oja...@li...> >> Betreff: Re: [ojAlgo-user] Quadratic Program fails >> When I run that code I get an ArrayIndexOutOfBoundsException, and that's because "C" should be a column vector rather than a row vector. >> >> Had you taken my advice and used ExpressionsBasedModel this wouldn't have happened. That class actually does something for you: >> >> 1) You can model your problems without worrying about specific solver requirements. >> 2) It knows which solver to use. >> 3) It knows how to use that solver. >> 4) It has a presolver that tries to simplify the problem before invoking a solver (sometimes it turns out there is no need to invoke a solver at all). >> 5) When/if needed it scales problem parameters, before creating solver specific data structures, to minimize numerical problems in the solvers. >> 6) It's the only way to access the integer solver. >> >> /Anders >> >> >> On 9 jan 2014, at 16:53, Nico Potyka <Nic...@gm...> wrote: >> >>> Hi, >>> >>> I tried to use ojAlgo to implement a norm minimization problem, but the solver fails even for very simple instances. The following example is one particular simple instance. Q is the identity matrix, C the zero vector. The constraints express that the solution is a probability function (AE for normalization and AI for non-negativity). Q is positive definite and the solution should be (0.5, 0.5), but qSolver fails. >>> >>> >>> PrimitiveDenseStore tmpQ = PrimitiveDenseStore.FACTORY.rows(new double[][]{{1, 0},{0, 1}}); >>> PrimitiveDenseStore tmpC = PrimitiveDenseStore.FACTORY.rows(new double[][]{{0, 0}}); >>> >>> PrimitiveDenseStore tmpAE = PrimitiveDenseStore.FACTORY.rows(new double[][]{{1, 1}}); >>> PrimitiveDenseStore tmpBE = PrimitiveDenseStore.FACTORY.rows(new double[][]{{1}}); >>> >>> PrimitiveDenseStore tmpAI = PrimitiveDenseStore.FACTORY.rows(new double[][]{{-1, 0}, {0, -1}}); >>> PrimitiveDenseStore tmpBI = PrimitiveDenseStore.FACTORY.rows(new double[][]{{0}, {0}}); >>> >>> QuadraticSolver qSolver = new QuadraticSolver.Builder(tmpQ, tmpC).equalities(tmpAE, tmpBE).inequalities(tmpAI, tmpBI).build(); >>> >>> Optimisation.Result tmpResult = qSolver.solve(); >>> System.out.println(tmpResult.getState()); >>> >>> >>> Is there something wrong in my code or is there a problem with the quadratic solver? >>> >>> Thanks >>> Nico >>> >>> ------------------------------------------------------------------------------ >>> CenturyLink Cloud: The Leader in Enterprise Cloud Services. >>> Learn Why More Businesses Are Choosing CenturyLink Cloud For >>> Critical Workloads, Development Environments & Everything In Between. >>> Get a Quote or Start a Free Trial Today. >>> http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk >>> _______________________________________________ >>> ojAlgo-user mailing list >>> ojA...@li... >>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]]] >>> >>> >> >> >> ------------------------------------------------------------------------------ >> CenturyLink Cloud: The Leader in Enterprise Cloud Services. >> Learn Why More Businesses Are Choosing CenturyLink Cloud For >> Critical Workloads, Development Environments & Everything In Between. >> Get a Quote or Start a Free Trial Today. >> http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk][http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk]][http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk][http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk]]] >> _______________________________________________ >> ojAlgo-user mailing list >> ojA...@li... >> https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]]] >> >> ------------------------------------------------------------------------------ >> CenturyLink Cloud: The Leader in Enterprise Cloud Services. >> Learn Why More Businesses Are Choosing CenturyLink Cloud For >> Critical Workloads, Development Environments & Everything In Between. >> Get a Quote or Start a Free Trial Today. >> http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk][http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk]] >> _______________________________________________ >> ojAlgo-user mailing list >> ojA...@li... >> https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]] ------------------------------------------------------------------------------ CenturyLink Cloud: The Leader in Enterprise Cloud Services. Learn Why More Businesses Are Choosing CenturyLink Cloud For Critical Workloads, Development Environments & Everything In Between. Get a Quote or Start a Free Trial Today. http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk][http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk]] _______________________________________________ ojAlgo-user mailing list ojA...@li... https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]] ------------------------------------------------------------------------------ CenturyLink Cloud: The Leader in Enterprise Cloud Services. Learn Why More Businesses Are Choosing CenturyLink Cloud For Critical Workloads, Development Environments & Everything In Between. Get a Quote or Start a Free Trial Today. http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk] _______________________________________________ ojAlgo-user mailing list ojA...@li... https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user] |
From: Nico P. <Nic...@gm...> - 2014-01-10 10:55:02
|
Thanks for your input. Constraints are indeed always restricted to non-negativity and normalization, the problem specific information is encoded in Q. However, existence of a solution is guaranteed for all problem instances. I will let you know what problem size I can handle, after doing some experiments and trying the ExpressionBasedModel. > Yes, the solver swallowed the exception, but did output it to the console. You displayed the solver state using System.out.println(); Didn't you see the exception there? For the code below, System.out.println(tmpResult.getState()); does not print any information about exceptions on my computer. Best regards Nico Gesendet: Freitag, 10. Januar 2014 um 11:21 Uhr Von: "Anders Peterson" <an...@op...> An: "ojAlgo ojAlgo" <oja...@li...> Betreff: Re: [ojAlgo-user] Quadratic Program fails After writing that I felt I had to investigate how large problems ojAlgo can handle... Problems structured as in your test case are easy to solve because the inequality constraints doesn't actually affect the solution. dim=2 => OPTIMAL in 0.042362s dim=4 => OPTIMAL in 6.18E-4s dim=8 => OPTIMAL in 6.97E-4s dim=16 => OPTIMAL in 0.001164s dim=32 => OPTIMAL in 0.003616s dim=64 => OPTIMAL in 0.021859s dim=128 => OPTIMAL in 0.026166s dim=256 => OPTIMAL in 0.02064s dim=512 => OPTIMAL in 0.073304s dim=1024 => OPTIMAL in 0.508432s dim=2048 => OPTIMAL in 3.590416s dim=4096 => OPTIMAL in 24.111358s dim=8192 => OPTIMAL in 186.600192s dim=16384 => Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at org.ojalgo.array.PrimitiveArray.<init>(PrimitiveArray.java:326) If you start adding inequality constraints that actually affect the solution performance will be very different, and if in fact the inequalities make the problem infeasible the algorithm may not be able to recognize that. /Anders On 9 jan 2014, at 22:29, Anders Peterson <an...@op...> wrote: > On 9 jan 2014, at 21:55, Nico Potyka <Nic...@gm...> wrote: > >> Thanks again and sorry for wasting your time. For some reason, there is no exception thrown on my computer and executing the code yields "FAILED". However, after switching to a column vector my general implementation works perfectly fine. > > Yes, the solver swallowed the exception, but did output it to the console. You displayed the solver state using System.out.println(); Didn't you see the exception there? > > >> I took your advice, but I need to perform some matrix operations to determine Q in general and therefore prefered the following example from the unit tests. Furthermore, the problems can become quite large. In fact, most interesting problem instances have hundreds of variables and I can easily construct examples with thousands or millions of variables. Therefore I figured that generating a variable object for each optimization variable might not be the best way to go. But I will give it a try. > > ExpressionsBasedModel is "sparse" it only stores the nonzero problem parameters, so it's not as bad as you may think. The solvers are "dense". > > The general advice would be to initially use ExpressionsBasedModel and then maybe switch to a specific solver if necessary and possible. > > ojAlgo's quadratic solver cannot handle millions of variables! 20000 or so would be an absolute limit and I imagine it will struggle with numerical and performance issues long before that. I don't know where the practical limit is - it depends on your specific case. The largest successful cases I know of has hundreds of variables (not thousands). Please let me know how large models you manage to solve. > > /Anders > > > >> Best regards >> Nico >> >> >> >> >> >> Gesendet: Donnerstag, 09. Januar 2014 um 21:07 Uhr >> Von: "Anders Peterson" <an...@op...> >> An: "ojAlgo ojAlgo" <oja...@li...> >> Betreff: Re: [ojAlgo-user] Quadratic Program fails >> When I run that code I get an ArrayIndexOutOfBoundsException, and that's because "C" should be a column vector rather than a row vector. >> >> Had you taken my advice and used ExpressionsBasedModel this wouldn't have happened. That class actually does something for you: >> >> 1) You can model your problems without worrying about specific solver requirements. >> 2) It knows which solver to use. >> 3) It knows how to use that solver. >> 4) It has a presolver that tries to simplify the problem before invoking a solver (sometimes it turns out there is no need to invoke a solver at all). >> 5) When/if needed it scales problem parameters, before creating solver specific data structures, to minimize numerical problems in the solvers. >> 6) It's the only way to access the integer solver. >> >> /Anders >> >> >> On 9 jan 2014, at 16:53, Nico Potyka <Nic...@gm...> wrote: >> >>> Hi, >>> >>> I tried to use ojAlgo to implement a norm minimization problem, but the solver fails even for very simple instances. The following example is one particular simple instance. Q is the identity matrix, C the zero vector. The constraints express that the solution is a probability function (AE for normalization and AI for non-negativity). Q is positive definite and the solution should be (0.5, 0.5), but qSolver fails. >>> >>> >>> PrimitiveDenseStore tmpQ = PrimitiveDenseStore.FACTORY.rows(new double[][]{{1, 0},{0, 1}}); >>> PrimitiveDenseStore tmpC = PrimitiveDenseStore.FACTORY.rows(new double[][]{{0, 0}}); >>> >>> PrimitiveDenseStore tmpAE = PrimitiveDenseStore.FACTORY.rows(new double[][]{{1, 1}}); >>> PrimitiveDenseStore tmpBE = PrimitiveDenseStore.FACTORY.rows(new double[][]{{1}}); >>> >>> PrimitiveDenseStore tmpAI = PrimitiveDenseStore.FACTORY.rows(new double[][]{{-1, 0}, {0, -1}}); >>> PrimitiveDenseStore tmpBI = PrimitiveDenseStore.FACTORY.rows(new double[][]{{0}, {0}}); >>> >>> QuadraticSolver qSolver = new QuadraticSolver.Builder(tmpQ, tmpC).equalities(tmpAE, tmpBE).inequalities(tmpAI, tmpBI).build(); >>> >>> Optimisation.Result tmpResult = qSolver.solve(); >>> System.out.println(tmpResult.getState()); >>> >>> >>> Is there something wrong in my code or is there a problem with the quadratic solver? >>> >>> Thanks >>> Nico >>> >>> ------------------------------------------------------------------------------ >>> CenturyLink Cloud: The Leader in Enterprise Cloud Services. >>> Learn Why More Businesses Are Choosing CenturyLink Cloud For >>> Critical Workloads, Development Environments & Everything In Between. >>> Get a Quote or Start a Free Trial Today. >>> http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk >>> _______________________________________________ >>> ojAlgo-user mailing list >>> ojA...@li... >>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]] >>> >>> >> >> >> ------------------------------------------------------------------------------ >> CenturyLink Cloud: The Leader in Enterprise Cloud Services. >> Learn Why More Businesses Are Choosing CenturyLink Cloud For >> Critical Workloads, Development Environments & Everything In Between. >> Get a Quote or Start a Free Trial Today. >> http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk][http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk]] >> _______________________________________________ >> ojAlgo-user mailing list >> ojA...@li... >> https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user][https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user]] >> >> ------------------------------------------------------------------------------ >> CenturyLink Cloud: The Leader in Enterprise Cloud Services. >> Learn Why More Businesses Are Choosing CenturyLink Cloud For >> Critical Workloads, Development Environments & Everything In Between. >> Get a Quote or Start a Free Trial Today. >> http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk] >> _______________________________________________ >> ojAlgo-user mailing list >> ojA...@li... >> https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user] ------------------------------------------------------------------------------ CenturyLink Cloud: The Leader in Enterprise Cloud Services. Learn Why More Businesses Are Choosing CenturyLink Cloud For Critical Workloads, Development Environments & Everything In Between. Get a Quote or Start a Free Trial Today. http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk] _______________________________________________ ojAlgo-user mailing list ojA...@li... https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user] |
From: Anders P. <an...@op...> - 2014-01-10 10:21:39
|
After writing that I felt I had to investigate how large problems ojAlgo can handle... Problems structured as in your test case are easy to solve because the inequality constraints doesn't actually affect the solution. dim=2 => OPTIMAL in 0.042362s dim=4 => OPTIMAL in 6.18E-4s dim=8 => OPTIMAL in 6.97E-4s dim=16 => OPTIMAL in 0.001164s dim=32 => OPTIMAL in 0.003616s dim=64 => OPTIMAL in 0.021859s dim=128 => OPTIMAL in 0.026166s dim=256 => OPTIMAL in 0.02064s dim=512 => OPTIMAL in 0.073304s dim=1024 => OPTIMAL in 0.508432s dim=2048 => OPTIMAL in 3.590416s dim=4096 => OPTIMAL in 24.111358s dim=8192 => OPTIMAL in 186.600192s dim=16384 => Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at org.ojalgo.array.PrimitiveArray.<init>(PrimitiveArray.java:326) If you start adding inequality constraints that actually affect the solution performance will be very different, and if in fact the inequalities make the problem infeasible the algorithm may not be able to recognize that. /Anders On 9 jan 2014, at 22:29, Anders Peterson <an...@op...> wrote: > On 9 jan 2014, at 21:55, Nico Potyka <Nic...@gm...> wrote: > >> Thanks again and sorry for wasting your time. For some reason, there is no exception thrown on my computer and executing the code yields "FAILED". However, after switching to a column vector my general implementation works perfectly fine. > > Yes, the solver swallowed the exception, but did output it to the console. You displayed the solver state using System.out.println(); Didn't you see the exception there? > > >> I took your advice, but I need to perform some matrix operations to determine Q in general and therefore prefered the following example from the unit tests. Furthermore, the problems can become quite large. In fact, most interesting problem instances have hundreds of variables and I can easily construct examples with thousands or millions of variables. Therefore I figured that generating a variable object for each optimization variable might not be the best way to go. But I will give it a try. > > ExpressionsBasedModel is "sparse" it only stores the nonzero problem parameters, so it's not as bad as you may think. The solvers are "dense". > > The general advice would be to initially use ExpressionsBasedModel and then maybe switch to a specific solver if necessary and possible. > > ojAlgo's quadratic solver cannot handle millions of variables! 20000 or so would be an absolute limit and I imagine it will struggle with numerical and performance issues long before that. I don't know where the practical limit is - it depends on your specific case. The largest successful cases I know of has hundreds of variables (not thousands). Please let me know how large models you manage to solve. > > /Anders > > > >> Best regards >> Nico >> >> >> >> >> >> Gesendet: Donnerstag, 09. Januar 2014 um 21:07 Uhr >> Von: "Anders Peterson" <an...@op...> >> An: "ojAlgo ojAlgo" <oja...@li...> >> Betreff: Re: [ojAlgo-user] Quadratic Program fails >> When I run that code I get an ArrayIndexOutOfBoundsException, and that's because "C" should be a column vector rather than a row vector. >> >> Had you taken my advice and used ExpressionsBasedModel this wouldn't have happened. That class actually does something for you: >> >> 1) You can model your problems without worrying about specific solver requirements. >> 2) It knows which solver to use. >> 3) It knows how to use that solver. >> 4) It has a presolver that tries to simplify the problem before invoking a solver (sometimes it turns out there is no need to invoke a solver at all). >> 5) When/if needed it scales problem parameters, before creating solver specific data structures, to minimize numerical problems in the solvers. >> 6) It's the only way to access the integer solver. >> >> /Anders >> >> >> On 9 jan 2014, at 16:53, Nico Potyka <Nic...@gm...> wrote: >> >>> Hi, >>> >>> I tried to use ojAlgo to implement a norm minimization problem, but the solver fails even for very simple instances. The following example is one particular simple instance. Q is the identity matrix, C the zero vector. The constraints express that the solution is a probability function (AE for normalization and AI for non-negativity). Q is positive definite and the solution should be (0.5, 0.5), but qSolver fails. >>> >>> >>> PrimitiveDenseStore tmpQ = PrimitiveDenseStore.FACTORY.rows(new double[][]{{1, 0},{0, 1}}); >>> PrimitiveDenseStore tmpC = PrimitiveDenseStore.FACTORY.rows(new double[][]{{0, 0}}); >>> >>> PrimitiveDenseStore tmpAE = PrimitiveDenseStore.FACTORY.rows(new double[][]{{1, 1}}); >>> PrimitiveDenseStore tmpBE = PrimitiveDenseStore.FACTORY.rows(new double[][]{{1}}); >>> >>> PrimitiveDenseStore tmpAI = PrimitiveDenseStore.FACTORY.rows(new double[][]{{-1, 0}, {0, -1}}); >>> PrimitiveDenseStore tmpBI = PrimitiveDenseStore.FACTORY.rows(new double[][]{{0}, {0}}); >>> >>> QuadraticSolver qSolver = new QuadraticSolver.Builder(tmpQ, tmpC).equalities(tmpAE, tmpBE).inequalities(tmpAI, tmpBI).build(); >>> >>> Optimisation.Result tmpResult = qSolver.solve(); >>> System.out.println(tmpResult.getState()); >>> >>> >>> Is there something wrong in my code or is there a problem with the quadratic solver? >>> >>> Thanks >>> Nico >>> >>> ------------------------------------------------------------------------------ >>> CenturyLink Cloud: The Leader in Enterprise Cloud Services. >>> Learn Why More Businesses Are Choosing CenturyLink Cloud For >>> Critical Workloads, Development Environments & Everything In Between. >>> Get a Quote or Start a Free Trial Today. >>> http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk >>> _______________________________________________ >>> ojAlgo-user mailing list >>> ojA...@li... >>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user] >>> >>> >> >> >> ------------------------------------------------------------------------------ >> CenturyLink Cloud: The Leader in Enterprise Cloud Services. >> Learn Why More Businesses Are Choosing CenturyLink Cloud For >> Critical Workloads, Development Environments & Everything In Between. >> Get a Quote or Start a Free Trial Today. >> http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk] >> _______________________________________________ >> ojAlgo-user mailing list >> ojA...@li... >> https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user] >> >> ------------------------------------------------------------------------------ >> CenturyLink Cloud: The Leader in Enterprise Cloud Services. >> Learn Why More Businesses Are Choosing CenturyLink Cloud For >> Critical Workloads, Development Environments & Everything In Between. >> Get a Quote or Start a Free Trial Today. >> http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk >> _______________________________________________ >> ojAlgo-user mailing list >> ojA...@li... >> https://lists.sourceforge.net/lists/listinfo/ojalgo-user |
From: Anders P. <an...@op...> - 2014-01-09 21:29:11
|
On 9 jan 2014, at 21:55, Nico Potyka <Nic...@gm...> wrote: > Thanks again and sorry for wasting your time. For some reason, there is no exception thrown on my computer and executing the code yields "FAILED". However, after switching to a column vector my general implementation works perfectly fine. Yes, the solver swallowed the exception, but did output it to the console. You displayed the solver state using System.out.println(); Didn't you see the exception there? > I took your advice, but I need to perform some matrix operations to determine Q in general and therefore prefered the following example from the unit tests. Furthermore, the problems can become quite large. In fact, most interesting problem instances have hundreds of variables and I can easily construct examples with thousands or millions of variables. Therefore I figured that generating a variable object for each optimization variable might not be the best way to go. But I will give it a try. ExpressionsBasedModel is "sparse" it only stores the nonzero problem parameters, so it's not as bad as you may think. The solvers are "dense". The general advice would be to initially use ExpressionsBasedModel and then maybe switch to a specific solver if necessary and possible. ojAlgo's quadratic solver cannot handle millions of variables! 20000 or so would be an absolute limit and I imagine it will struggle with numerical and performance issues long before that. I don't know where the practical limit is - it depends on your specific case. The largest successful cases I know of has hundreds of variables (not thousands). Please let me know how large models you manage to solve. /Anders > Best regards > Nico > > > > > > Gesendet: Donnerstag, 09. Januar 2014 um 21:07 Uhr > Von: "Anders Peterson" <an...@op...> > An: "ojAlgo ojAlgo" <oja...@li...> > Betreff: Re: [ojAlgo-user] Quadratic Program fails > When I run that code I get an ArrayIndexOutOfBoundsException, and that's because "C" should be a column vector rather than a row vector. > > Had you taken my advice and used ExpressionsBasedModel this wouldn't have happened. That class actually does something for you: > > 1) You can model your problems without worrying about specific solver requirements. > 2) It knows which solver to use. > 3) It knows how to use that solver. > 4) It has a presolver that tries to simplify the problem before invoking a solver (sometimes it turns out there is no need to invoke a solver at all). > 5) When/if needed it scales problem parameters, before creating solver specific data structures, to minimize numerical problems in the solvers. > 6) It's the only way to access the integer solver. > > /Anders > > > On 9 jan 2014, at 16:53, Nico Potyka <Nic...@gm...> wrote: > >> Hi, >> >> I tried to use ojAlgo to implement a norm minimization problem, but the solver fails even for very simple instances. The following example is one particular simple instance. Q is the identity matrix, C the zero vector. The constraints express that the solution is a probability function (AE for normalization and AI for non-negativity). Q is positive definite and the solution should be (0.5, 0.5), but qSolver fails. >> >> >> PrimitiveDenseStore tmpQ = PrimitiveDenseStore.FACTORY.rows(new double[][]{{1, 0},{0, 1}}); >> PrimitiveDenseStore tmpC = PrimitiveDenseStore.FACTORY.rows(new double[][]{{0, 0}}); >> >> PrimitiveDenseStore tmpAE = PrimitiveDenseStore.FACTORY.rows(new double[][]{{1, 1}}); >> PrimitiveDenseStore tmpBE = PrimitiveDenseStore.FACTORY.rows(new double[][]{{1}}); >> >> PrimitiveDenseStore tmpAI = PrimitiveDenseStore.FACTORY.rows(new double[][]{{-1, 0}, {0, -1}}); >> PrimitiveDenseStore tmpBI = PrimitiveDenseStore.FACTORY.rows(new double[][]{{0}, {0}}); >> >> QuadraticSolver qSolver = new QuadraticSolver.Builder(tmpQ, tmpC).equalities(tmpAE, tmpBE).inequalities(tmpAI, tmpBI).build(); >> >> Optimisation.Result tmpResult = qSolver.solve(); >> System.out.println(tmpResult.getState()); >> >> >> Is there something wrong in my code or is there a problem with the quadratic solver? >> >> Thanks >> Nico >> >> ------------------------------------------------------------------------------ >> CenturyLink Cloud: The Leader in Enterprise Cloud Services. >> Learn Why More Businesses Are Choosing CenturyLink Cloud For >> Critical Workloads, Development Environments & Everything In Between. >> Get a Quote or Start a Free Trial Today. >> http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk >> _______________________________________________ >> ojAlgo-user mailing list >> ojA...@li... >> https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user] >> >> > > > ------------------------------------------------------------------------------ > CenturyLink Cloud: The Leader in Enterprise Cloud Services. > Learn Why More Businesses Are Choosing CenturyLink Cloud For > Critical Workloads, Development Environments & Everything In Between. > Get a Quote or Start a Free Trial Today. > http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk] > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user] > > ------------------------------------------------------------------------------ > CenturyLink Cloud: The Leader in Enterprise Cloud Services. > Learn Why More Businesses Are Choosing CenturyLink Cloud For > Critical Workloads, Development Environments & Everything In Between. > Get a Quote or Start a Free Trial Today. > http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user |
From: Nico P. <Nic...@gm...> - 2014-01-09 20:55:50
|
Thanks again and sorry for wasting your time. For some reason, there is no exception thrown on my computer and executing the code yields "FAILED". However, after switching to a column vector my general implementation works perfectly fine. I took your advice, but I need to perform some matrix operations to determine Q in general and therefore prefered the following example from the unit tests. Furthermore, the problems can become quite large. In fact, most interesting problem instances have hundreds of variables and I can easily construct examples with thousands or millions of variables. Therefore I figured that generating a variable object for each optimization variable might not be the best way to go. But I will give it a try. Best regards Nico Gesendet: Donnerstag, 09. Januar 2014 um 21:07 Uhr Von: "Anders Peterson" <an...@op...> An: "ojAlgo ojAlgo" <oja...@li...> Betreff: Re: [ojAlgo-user] Quadratic Program fails When I run that code I get an ArrayIndexOutOfBoundsException, and that's because "C" should be a column vector rather than a row vector. Had you taken my advice and used ExpressionsBasedModel this wouldn't have happened. That class actually does something for you: 1) You can model your problems without worrying about specific solver requirements. 2) It knows which solver to use. 3) It knows how to use that solver. 4) It has a presolver that tries to simplify the problem before invoking a solver (sometimes it turns out there is no need to invoke a solver at all). 5) When/if needed it scales problem parameters, before creating solver specific data structures, to minimize numerical problems in the solvers. 6) It's the only way to access the integer solver. /Anders On 9 jan 2014, at 16:53, Nico Potyka <Nic...@gm...> wrote: > Hi, > > I tried to use ojAlgo to implement a norm minimization problem, but the solver fails even for very simple instances. The following example is one particular simple instance. Q is the identity matrix, C the zero vector. The constraints express that the solution is a probability function (AE for normalization and AI for non-negativity). Q is positive definite and the solution should be (0.5, 0.5), but qSolver fails. > > > PrimitiveDenseStore tmpQ = PrimitiveDenseStore.FACTORY.rows(new double[][]{{1, 0},{0, 1}}); > PrimitiveDenseStore tmpC = PrimitiveDenseStore.FACTORY.rows(new double[][]{{0, 0}}); > > PrimitiveDenseStore tmpAE = PrimitiveDenseStore.FACTORY.rows(new double[][]{{1, 1}}); > PrimitiveDenseStore tmpBE = PrimitiveDenseStore.FACTORY.rows(new double[][]{{1}}); > > PrimitiveDenseStore tmpAI = PrimitiveDenseStore.FACTORY.rows(new double[][]{{-1, 0}, {0, -1}}); > PrimitiveDenseStore tmpBI = PrimitiveDenseStore.FACTORY.rows(new double[][]{{0}, {0}}); > > QuadraticSolver qSolver = new QuadraticSolver.Builder(tmpQ, tmpC).equalities(tmpAE, tmpBE).inequalities(tmpAI, tmpBI).build(); > > Optimisation.Result tmpResult = qSolver.solve(); > System.out.println(tmpResult.getState()); > > > Is there something wrong in my code or is there a problem with the quadratic solver? > > Thanks > Nico > > ------------------------------------------------------------------------------ > CenturyLink Cloud: The Leader in Enterprise Cloud Services. > Learn Why More Businesses Are Choosing CenturyLink Cloud For > Critical Workloads, Development Environments & Everything In Between. > Get a Quote or Start a Free Trial Today. > http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user] > > ------------------------------------------------------------------------------ CenturyLink Cloud: The Leader in Enterprise Cloud Services. Learn Why More Businesses Are Choosing CenturyLink Cloud For Critical Workloads, Development Environments & Everything In Between. Get a Quote or Start a Free Trial Today. http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk] _______________________________________________ ojAlgo-user mailing list ojA...@li... https://lists.sourceforge.net/lists/listinfo/ojalgo-user[https://lists.sourceforge.net/lists/listinfo/ojalgo-user] |
From: Anders P. <an...@op...> - 2014-01-09 20:07:39
|
When I run that code I get an ArrayIndexOutOfBoundsException, and that's because "C" should be a column vector rather than a row vector. Had you taken my advice and used ExpressionsBasedModel this wouldn't have happened. That class actually does something for you: 1) You can model your problems without worrying about specific solver requirements. 2) It knows which solver to use. 3) It knows how to use that solver. 4) It has a presolver that tries to simplify the problem before invoking a solver (sometimes it turns out there is no need to invoke a solver at all). 5) When/if needed it scales problem parameters, before creating solver specific data structures, to minimize numerical problems in the solvers. 6) It's the only way to access the integer solver. /Anders On 9 jan 2014, at 16:53, Nico Potyka <Nic...@gm...> wrote: > Hi, > > I tried to use ojAlgo to implement a norm minimization problem, but the solver fails even for very simple instances. The following example is one particular simple instance. Q is the identity matrix, C the zero vector. The constraints express that the solution is a probability function (AE for normalization and AI for non-negativity). Q is positive definite and the solution should be (0.5, 0.5), but qSolver fails. > > > PrimitiveDenseStore tmpQ = PrimitiveDenseStore.FACTORY.rows(new double[][]{{1, 0},{0, 1}}); > PrimitiveDenseStore tmpC = PrimitiveDenseStore.FACTORY.rows(new double[][]{{0, 0}}); > > PrimitiveDenseStore tmpAE = PrimitiveDenseStore.FACTORY.rows(new double[][]{{1, 1}}); > PrimitiveDenseStore tmpBE = PrimitiveDenseStore.FACTORY.rows(new double[][]{{1}}); > > PrimitiveDenseStore tmpAI = PrimitiveDenseStore.FACTORY.rows(new double[][]{{-1, 0}, {0, -1}}); > PrimitiveDenseStore tmpBI = PrimitiveDenseStore.FACTORY.rows(new double[][]{{0}, {0}}); > > QuadraticSolver qSolver = new QuadraticSolver.Builder(tmpQ, tmpC).equalities(tmpAE, tmpBE).inequalities(tmpAI, tmpBI).build(); > > Optimisation.Result tmpResult = qSolver.solve(); > System.out.println(tmpResult.getState()); > > > Is there something wrong in my code or is there a problem with the quadratic solver? > > Thanks > Nico > > ------------------------------------------------------------------------------ > CenturyLink Cloud: The Leader in Enterprise Cloud Services. > Learn Why More Businesses Are Choosing CenturyLink Cloud For > Critical Workloads, Development Environments & Everything In Between. > Get a Quote or Start a Free Trial Today. > http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > |
From: Nico P. <Nic...@gm...> - 2014-01-09 15:53:49
|
Hi, I tried to use ojAlgo to implement a norm minimization problem, but the solver fails even for very simple instances. The following example is one particular simple instance. Q is the identity matrix, C the zero vector. The constraints express that the solution is a probability function (AE for normalization and AI for non-negativity). Q is positive definite and the solution should be (0.5, 0.5), but qSolver fails. PrimitiveDenseStore tmpQ = PrimitiveDenseStore.FACTORY.rows(new double[][]{{1, 0},{0, 1}}); PrimitiveDenseStore tmpC = PrimitiveDenseStore.FACTORY.rows(new double[][]{{0, 0}}); PrimitiveDenseStore tmpAE = PrimitiveDenseStore.FACTORY.rows(new double[][]{{1, 1}}); PrimitiveDenseStore tmpBE = PrimitiveDenseStore.FACTORY.rows(new double[][]{{1}}); PrimitiveDenseStore tmpAI = PrimitiveDenseStore.FACTORY.rows(new double[][]{{-1, 0}, {0, -1}}); PrimitiveDenseStore tmpBI = PrimitiveDenseStore.FACTORY.rows(new double[][]{{0}, {0}}); QuadraticSolver qSolver = new QuadraticSolver.Builder(tmpQ, tmpC).equalities(tmpAE, tmpBE).inequalities(tmpAI, tmpBI).build(); Optimisation.Result tmpResult = qSolver.solve(); System.out.println(tmpResult.getState()); Is there something wrong in my code or is there a problem with the quadratic solver? Thanks Nico |
From: Nico P. <Nic...@gm...> - 2014-01-08 12:18:10
|
<html><head></head><body><div style="font-family: Verdana;font-size: 12.0px;"><div>Thanks a lot! That's exactly what I was looking for.<br/> <div> </div> <div> <div name="quote" style="margin:10px 5px 5px 10px; padding: 10px 0 10px 10px; border-left:2px solid #C3D9E5; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"> <div style="margin:0 0 10px 0;"><b>Gesendet:</b> Dienstag, 07. Januar 2014 um 22:06 Uhr<br/> <b>Von:</b> "Anders Peterson" <an...@op...><br/> <b>An:</b> "ojAlgo ojAlgo" <oja...@li...><br/> <b>Betreff:</b> Re: [ojAlgo-user] Examples for quadratic programming</div> <div name="quoted-content">Don't worry too much about how all those things work together. Just start with ExpressionBasedModel. Build your model, and execute minimise() or maximise().<br/> <br/> The mailing list archives should contain some examples, and the junit tests definitely does. Unfortunately not all those examples/test cases are good. Here's one that should be ok:<br/> <br/> <a href="http://ojalgo.cvs.sourceforge.net/viewvc/ojalgo/TestProj/src/org/ojalgo/optimisation/quadratic/ReportedProblems.java?view=markup" target="_blank">http://ojalgo.cvs.sourceforge.net/viewvc/ojalgo/TestProj/src/org/ojalgo/optimisation/quadratic/ReportedProblems.java?view=markup</a><br/> <br/> and look at<br/> <br/> testP20111129<br/> <br/> /Anders<br/> <br/> <br/> On 7 jan 2014, at 17:05, Nico Potyka <Nic...@gm...> wrote:<br/> <br/> > Hi,<br/> ><br/> > could someone please send me an example for applying the quadratic solver in the current version of ojalgo? I already read the linear algebra documentation and the javadoc, but I just don't understand how the matrices for the problem definition, the QuadraticSolver and the ExpressionBasedModel work together.<br/> ><br/> > Thanks a lot<br/> > Nico<br/> > ------------------------------------------------------------------------------<br/> > Rapidly troubleshoot problems before they affect your business. Most IT<br/> > organizations don't have a clear picture of how application performance<br/> > affects their revenue. With AppDynamics, you get 100% visibility into your<br/> > Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!<br/> > <a href="http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk_______________________________________________" target="_blank">http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk_______________________________________________</a><br/> > ojAlgo-user mailing list<br/> > ojA...@li...<br/> > <a href="https://lists.sourceforge.net/lists/listinfo/ojalgo-user" target="_blank">https://lists.sourceforge.net/lists/listinfo/ojalgo-user</a><br/> <br/> <br/> ------------------------------------------------------------------------------<br/> Rapidly troubleshoot problems before they affect your business. Most IT<br/> organizations don't have a clear picture of how application performance<br/> affects their revenue. With AppDynamics, you get 100% visibility into your<br/> Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!<br/> <a href="http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk" target="_blank">http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk</a><br/> _______________________________________________<br/> ojAlgo-user mailing list<br/> ojA...@li...<br/> <a href="https://lists.sourceforge.net/lists/listinfo/ojalgo-user" target="_blank">https://lists.sourceforge.net/lists/listinfo/ojalgo-user</a></div> </div> </div> </div></div></body></html> |
From: Anders P. <an...@op...> - 2014-01-07 21:06:42
|
Don't worry too much about how all those things work together. Just start with ExpressionBasedModel. Build your model, and execute minimise() or maximise(). The mailing list archives should contain some examples, and the junit tests definitely does. Unfortunately not all those examples/test cases are good. Here's one that should be ok: http://ojalgo.cvs.sourceforge.net/viewvc/ojalgo/TestProj/src/org/ojalgo/optimisation/quadratic/ReportedProblems.java?view=markup and look at testP20111129 /Anders On 7 jan 2014, at 17:05, Nico Potyka <Nic...@gm...> wrote: > Hi, > > could someone please send me an example for applying the quadratic solver in the current version of ojalgo? I already read the linear algebra documentation and the javadoc, but I just don't understand how the matrices for the problem definition, the QuadraticSolver and the ExpressionBasedModel work together. > > Thanks a lot > Nico > ------------------------------------------------------------------------------ > Rapidly troubleshoot problems before they affect your business. Most IT > organizations don't have a clear picture of how application performance > affects their revenue. With AppDynamics, you get 100% visibility into your > Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro! > http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk_______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user |
From: Nico P. <Nic...@gm...> - 2014-01-07 16:05:48
|
<html><head></head><body><div style="font-family: Verdana;font-size: 12.0px;"><div>Hi,</div> <div> </div> <div>could someone please send me an example for applying the quadratic solver in the current version of ojalgo? I already read the linear algebra documentation and the javadoc, but I just don't understand how the matrices for the problem definition, the QuadraticSolver and the ExpressionBasedModel work together.</div> <div> </div> <div>Thanks a lot</div> <div>Nico</div></div></body></html> |