
function svm = svm_build(data,kernel)

y = data.y;
X = data.X;

n = length(y);  % y is n x 1
M = size(X,2);  % X is n x M

% evaluate the kernel matrix

K = feval(kernel,X,X);
K = K + (1e-10)*eye(n); % make sure eigenvalues are non-negative

% solve dual problem... insert code here

alpha = quadprog(...)




% select support vectors.
S = find(alpha > eps);
NS = length(S);

beta = alpha(S).*y(S);
XS = X(S,:);

% also, calculate w0 (offset parameter) ... insert code here



% store the results

svm.kernel = kernel;
svm.NS = NS; 
svm.w0 = w0;
svm.beta = beta;
svm.XS = XS;

