0

i have a problem that i'd like to solve in R.

I see that i can use the function lsei in the package limSolve to minimise a system of linear equations written Ax=b in the matrix form, subject to equality constraints Ex=f and the inequality constraints Gx>=h.

However, rather than a system of linear equations, i now have a system of quadratic equations that can be written t(x)Ax=b.

I see there's the package quadprog for the quadratic case, but it doesn't seem to allow for a set of quadratic equations, just the one equation.

Does anyone know what i could use to minimise a system of quadratic equations under both an equality and an inequality constraint?

Here's my example. I'm trying to combine 3 probabilities P(A), P(B), P(C) - this creates 7 segments v1 to v7, where v1 is P(A solus) etc... v4 is P((A AND B) NOT C) etc.. and v7 is P(A AND B AND C).

The function i'm trying to minimise is:

obj.fc<-function(x){
  f<-rep(NA,4)
  v1<-x[1]
  v2<-x[2]
  v3<-x[3]
  v4<-x[4]
  v5<-x[5]
  v6<-x[6]
  v7<-x[7]
  f[1]<-(v4+v7)*(1-(v1+v2+v4+v5+v6+v7))-2*(v1+v6)*(v2+v5)
  f[2]<-(v5+v7)*(1-(v2+v3+v4+v5+v6+v7))-13*(v2+v4)*(v3+v6)
  f[3]<-(v6+v7)*(1-(v1+v3+v4+v5+v6+v7))-11*(v1+v4)*(v3+v5)
  f[4]<-(v4+v5+v6)*(1-(v1+v2+v3+v4+v5+v6+v7))-4*(v1+v2+v3)*v7
  return(f)
}

My equality constraints are:

v1+v4+v6+v7=0.14
v2+v4+v5+v7=0.01
v3+v5+v6+v7=0.08

And my inequality constraints are that the Vi have to be between 0 and 1 and their sum can't exceed 1.

chrisjacques
  • 635
  • 1
  • 5
  • 17
  • The function `solve.QP` from the `quadprog` package is used quite routinely to solve quadratic programming problems with both linear and nonlinear constraints. A search for `solve.QP` on SO will return many examples. To address your specific question, you'll need to construct the constraint matrix `A` with the equality constraints first and then the inequality constraints. The argument `meq` is used to tell `solve.QP` how many of the first equations in `A` are equality constraints. – WaltS Jan 13 '16 at 21:31
  • thanks for this. Unfortunately it seems solve.QP can't handle a system of quadratic equations, only one quadratic equation... I've tried various functions in the BB package but it seems i can either optimise for a set of quadratic equations without contraints, or one quadratic equation with contraints... still trying to find something that will do both at the same time... – chrisjacques Jan 14 '16 at 16:24
  • It would be helpful if you could update your post with a small example problem to help us better understand your question. – WaltS Jan 15 '16 at 00:01
  • yes sorry, i've now included my example. I've now also tried package BB but didn't manage to add contraints, and NlcOptim but don't seem to be able to specify it properly (again - problems including the constraints...). – chrisjacques Jan 15 '16 at 09:54
  • 1
    The objective should be a scalar to use standard optimization tools. If the objective is a vector we really have a multi-objective optimization problem which is a very specialized area. – Erwin Kalvelagen Jan 15 '16 at 11:36
  • With multi-objective problems one must be much more precise in defining the problem and what you want back. Is there is a hierarchy in the objectives? Do you want just a few weighted solutions, a balanced solution, or all (or many) Pareto optimal solutions. – Erwin Kalvelagen Jan 15 '16 at 14:02

1 Answers1

0

You can represent each of your equality constraints as two inequality constraints, e.g.

Ax = b <=> Ax <= b, and
           Ax >= b

Note however that quadprog only allows solving "quadratic programs" in the sense of a quadratic objective function with linear constraints. From quadprog documentation:

This routine implements the dual method of Goldfarb and Idnani (1982, 1983) for solving quadratic programming problems of the form min(−dT b + 1/2bT Db) with the constraints AT b >= b0.

So in your case, you should probably look at another package. I would suggest e.g. [NlcOptim][2], or, find the most appropriate solver for you from here:

dfrib
  • 70,367
  • 12
  • 127
  • 192
  • thanks for this. I'm trying to use NlcOptim but i can't get it to work... i suspect i'm not specifying my problem properly in NlcOptim, unfortunately the documentation is not very helpful as it only shows examples where the objective function returns a scalar... – chrisjacques Jan 15 '16 at 12:25
  • @chrisjacques As Erwin writes above; for a non-scalar objective function return, we are in essence considering multi-objective optimization, in which case there is no univocal interpretation of what is an "optimal solution". I suggest you reduce you'r problem to a single-objective opt. problem, and and additional objective functions as constraints in your function. Let's say you have two objective values you want to study. Put one of them as a constraint in your program: starting with quite a slack constraint, and make this increasingly more restrictive (until program becomes infeasible). ... – dfrib Jan 15 '16 at 14:09
  • @chrisjacques ... This will yield a [pareto front](https://en.wikipedia.org/wiki/Pareto_efficiency) which is a valuable way of study how the pareto-optimality of optimization problems with two objective functions. – dfrib Jan 15 '16 at 14:11
  • i see... in that case i'm probably over-complicating things and i would probably be better of reverting to the objective function giving a scalar by using the norm of the 4-dimensional objective function i created. So my function should be the sum of squares of my f[i]. Thank you for all your help! – chrisjacques Jan 15 '16 at 15:34
  • @chrisjacques happy to help. – dfrib Jan 15 '16 at 15:35