Re: [ojAlgo-user] using quadratic solver
Mathematics, linear algebra and optimisation
Brought to you by:
apete
From: Anders P. <an...@op...> - 2010-10-06 20:22:46
|
The code you've written declares an optimisation problem with 2 variables, but the variable H is not part of the objective function, not part of any expression and not constrained in any way. Actually I think you ask too many things at the same time; how can you not know if alpha and H should be "listed" as variables or not? Are they variables? You make something (a single variable, or a whole expression) part of the objective function by setting its contribution weight. What you set individual weights to only matters in relation other weights. You constrain something (single variable, or whole expressions) by setting lower and/or upper limits. /Anders On 6 okt 2010, at 01.17, David Johnson wrote: > Hi, I'm new to ojalgo, and trying to work out the exact syntax needed to configure the quadratic solver. > > Specifically, I'm trying to solve a standard quadratic minimization problem: min(1/2*transpose(alpha)*H*alpha - sum(alpha)), given 0 <= alphai <= C (where C is a constant), for each element in alpha. Alpha will be initialized to 0s (or uninitialized, if no initial input is needed) and H to a given input matrix. I'm unclear on exactly what I need to configure in the QuadraticExpressionsModel versus what is handled by the builder. I also can't seem to find a current example of how to configure an expression-based model (except for the one in MarkowitzModel, which helped, but didn't entirely clarify the logic). > > My current (very rough) code skeleton looks like this: > > final Variable[] vars = new Variable[2]; > vars[0] = new Variable("alpha"); > vars[0].setLowerLimit(new BigDecimal(0)); > vars[0].setUpperLimit(new BigDecimal(C)); > vars[0].setContributionWeight(BigMath.ONE); > vars[1] = new Variable("H"); > > final QuadraticExpressionsModel qem = new QuadraticExpressionsModel(vars); > qem.setMinimisation(true); > > final QuadraticSolver.Builder build = new QuadraticSolver.Builder(qem); > > I can't tell if alpha and H should even be listed as variables (as opposed to expressions), how to associate my input matrices with them if they should be, and how to describe range limits on alpha if they should not. I'm also not certain how to define my objective function - is the basic format handled by the builder, or do I need to describe it in the model somehow? Should I be using the inequalities(...) and objective(...) functions in the builder, or defining those via the model? > > Also, I know I can represent sum(alpha) in my equation by just setting C (the vector in the basic equation format, not my constant) to be a singular 1 vector, but is there any way to ensure that the solver will then treat C as a constant? > > Thanks > David Johnson > ------------------------------------------------------------------------------ > Beautiful is writing same markup. Internet Explorer 9 supports > standards for HTML5, CSS3, SVG 1.1, ECMAScript5, and DOM L2 & L3. > Spend less time writing and rewriting code and more time creating great > experiences on the web. Be a part of the beta today. > http://p.sf.net/sfu/beautyoftheweb_______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user |