sloisel / numeric

Numerical analysis in Javascript
http://www.numericjs.com/
Other
1.42k stars 176 forks source link

solveQP failes, but is correct in original albertosantini/node-quadprog #78

Open tornordqvist opened 7 years ago

tornordqvist commented 7 years ago

I have a test case, where numeric.solveQP failes, but it is correct in the the original Alberto Santini's quadprog code. The D-matrix has ok eigen-values. But I guess it has something to do with the constraints A and b0. Maybe base0to1 or base1to0 is used incorrectly.

===================================================== var numeric = require('numeric'); var qp = require("quadprog");

var mu = [0.14097628928335038, 0.09964705882352941, 0.043873181810709344, 0.02623529411764705, 0.10058823529411764]; var cov = [[0.05970495870153234, 0.01296574669996471, 0.034799597965346166, -0.001511744225804883, 0.005894763962355329], [0.01296574669996471, 0.02144394140625, 0.016214107224563266, 0.0071884048109013875, 0.0022726480300834452], [0.034799597965346166, 0.016214107224563266, 0.06446081115219693, 0.000544637705909025, 0.002215406265157739], [-0.001511744225804883, 0.0071884048109013875, 0.000544637705909025, 0.007711035156249998, 0.00013323325202656668], [0.005894763962355329, 0.0022726480300834452, 0.002215406265157739, 0.00013323325202656668, 0.0018651601562500004]]; var A = [[1, -1, 1, 0, 0, 0, 0, 0.14097628928335038, -0.14097628928335038], [1, -1, 0, 1, 0, 0, 0, 0.09964705882352941, -0.09964705882352941], [1, -1, 0, 0, 1, 0, 0, 0.043873181810709344, -0.043873181810709344], [1, -1, 0, 0, 0, 1, 0, 0.02623529411764705, -0.02623529411764705], [1, -1, 0, 0, 0, 0, 1, 0.10058823529411764, -0.10058823529411764]]; var d = [0, 0, 0, 0, 0]; var b0 = [1, -1, 0, 0, 0, 0, 0, 0.10819314780743514, -0.10819314780743514];

var res_wrong = numeric.solveQP(cov, d, A, b0); var res_correct = qp.solveQP(base0to1(cov), base0to1(d), base0to1(A), base0to1(b0));

function base0to1(A) { if (typeof A !== "object") { return A; } var ret = [], i, n = A.length; for (i = 0; i < n; i++) ret[i + 1] = base0to1(A[i]); return ret; }