7
4

3 に答える 3

9

I don't see how it can be a problem. Let z be our vector of (2n + 1) variables:

z = (w, eps, b)

Then, H becomes diagonal matrix with first n values on the diagonal equal to 1 and the last n + 1 set to zero:

H = diag([ones(1, n), zeros(1, n + 1)])

Vector f can be expressed as:

f = [zeros(1, n), C * ones(1, n), 0]'

First set of constrains becomes:

Aineq = [A1, eye(n), zeros(n, 1)]
bineq = ones(n, 1)

where A1 is a the same matrix as in primal form.

Second set of constraints becomes lower bounds:

lb = (inf(n, 1), zeros(n, 1), inf(n, 1))

Then you can call MATLAB:

z = quadprog(H, f, Aineq, bineq, [], [], lb);

P.S. I can be mistaken in some small details, but the general idea is right.

于 2013-03-20T16:45:04.913 に答える
-1

完全なコード。考え方は上と同じです。

n = size(X,1);
m = size(X,2);
H = diag([ones(1, m), zeros(1, n + 1)]);
f = [zeros(1,m+1) c*ones(1,n)]';
p = diag(Y) * X;
A = -[p Y eye(n)];
B = -ones(n,1);
lb = [-inf * ones(m+1,1) ;zeros(n,1)];
z = quadprog(H,f,A,B,[],[],lb);
w = z(1:m,:);
b = z(m+1:m+1,:);
eps = z(m+2:m+n+1,:);
于 2017-10-31T23:29:11.407 に答える