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

If let z = (w; w0; eps)T be a the long vector with n+1+m elements.(m the number of points) Then,

H= diag([ones(1,n),zeros(1,m+1)]).
f = [zeros(1; n + 1); ones(1;m)]

The inequality constraints can be specified as :

A = -diag(y)[X; ones(m; 1); zeroes(m;m)] -[zeros(m,n+1),eye(m)],

where X is the n x m input matrix in the primal form.Out of the 2 parts for A, the first part is for w0 and the second part is for eps.

b = ones(m,1) 

The equality constraints :

Aeq = zeros(1,n+1 +m)
beq = 0

Bounds:

lb = [-inf*ones(n+1,1); zeros(m,1)]
ub = [inf*ones(n+1+m,1)]

Now, z=quadprog(H,f,A,b,Aeq,beq,lb,ub)

于 2017-03-31T13:30:38.577 回答
-1

Complete code. The idea is the same as above.

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 回答