0
votes

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.

1
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
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
It would be helpful if you could update your post with a small example problem to help us better understand your question.WaltS
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
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

1 Answers

0
votes

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: