Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QPsolve failure case #43

Open
gilbo opened this issue Aug 7, 2013 · 2 comments
Open

QPsolve failure case #43

gilbo opened this issue Aug 7, 2013 · 2 comments

Comments

@gilbo
Copy link

gilbo commented Aug 7, 2013

The following input to qpsolve:

Dmat:
[13,18,-6]
[18,27,-9]
[-6,-9,4]
dvec:
[-4,0,-100]
Amat:
[0]
[0]
[-1]
bvec:
[-25]

produces the solution vector:

[21:56:14.131] x:-3.999999999999967 y:-30.666666666666707 z:-100.00000000000006

which is incorrect as best I can ascertain. The problem above was arrived at by summing the energy

(2x + 3y - z)^2 + (x-4)^2 + (z-100)^2

with the additional constraint that

z <= 25

From that description it is clear that the answer should be x=4, z=25, and y set appropriately to zero out the first energy term

@cygnyx
Copy link

cygnyx commented Nov 21, 2014

I see that quadprog has been updated.

@albertosantini
Copy link

Using the original quadprog package in R,

R version 3.2.2 (2015-08-14) -- "Fire Safety"
Copyright (C) 2015 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> require(quadprog)
Loading required package: quadprog
> 
> Dmat <- matrix(c(13,18,-6, 18,27,-9, -6,-9,4),3,3)
> dvec <- c(-4,0,-100)
> Amat <- matrix(c(0,0,-1),3,1)
> bvec <- c(-25)
> 
> solve.QP(Dmat,dvec,Amat,bvec=bvec,meq=1)
$solution
[1] -4 11 25

$value
[1] 2804.5

$unconstrained.solution
[1]   -4.00000  -30.66667 -100.00000

$iterations
[1] 2 0

$Lagrangian
[1] 125

$iact
[1] 1

> Dmat
     [,1] [,2] [,3]
[1,]   13   18   -6
[2,]   18   27   -9
[3,]   -6   -9    4
> dvec
[1]   -4    0 -100
> Amat
     [,1]
[1,]    0
[2,]    0
[3,]   -1
> bvec
[1] -25
> 

With quadprog js

var dmat = [], dvec = [], amat = [], bvec = [], meq;

    dmat[1] = [];
    dmat[2] = [];
    dmat[3] = [];
    dmat[1][1] = 13;
    dmat[2][1] = 18;
    dmat[3][1] = -6;
    dmat[1][2] = 18;
    dmat[2][2] = 27;
    dmat[3][2] = -9;
    dmat[1][3] = -6;
    dmat[2][3] = -9;
    dmat[3][3] = 4;

    dvec[1] = -4;
    dvec[2] = 0;
    dvec[3] = -100;

    amat[1] = [];
    amat[2] = [];
    amat[3] = [];
    amat[1][1] = 0;
    amat[2][1] = 0;
    amat[3][1] = -1;

    bvec[1] = -25;

    meq = 1;

    qp.solveQP(dmat, dvec, amat, bvec, meq);
{ solution: [ , -4.000000000000016, 11.000000000000007, 25 ],
  Lagrangian: [ , 125 ],
  value: [ , 2804.500000000001 ],
  unconstrained_solution: [ , -3.999999999999967, -30.666666666666707, -100.00000000000006 ],
  iterations: [ , 2, 0 ],
  iact: [ , 1 ],
  message: '' }

The response seems quite similar apart numerical rounding.

Feel free to open an issue in https://github.com/albertosantini/node-quadprog/ project if you found cases where the figures between R package and js porting are different.

albertosantini added a commit to albertosantini/quadprog that referenced this issue Dec 9, 2015
This example is based on issue sloisel/numeric#43.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants