function [ypred, values] = predictSVMC(Xtrain, ytrain, Xtest, s, C, B)

% SVM + Cumulative chain

if(~exist('s','var'))
    s = 1;
end

if(~exist('C','var'))
    C = 1;
end

if(~exist('B','var'))
    B = -1;
end

params = sprintf('-s %d -c %f -B %f -q',s,C,B);

classes = size(ytrain,2);

%popularity = sum(ytrain);
%[~,indexes] = sort(popularity,'descend');
%ytrain(:,1:classes) = ytrain(:,indexes);

ypred = zeros(size(Xtest,1),classes);
testvalues = zeros(size(Xtest,1),classes);
trainvalues = zeros(size(Xtrain,1),classes);
for i=1:classes
    model = train(full(ytrain(:,i)), [Xtrain trainvalues(:,1:i-1)], params);
    [~,~,trainvalues(:,i)] = predict(zeros(size(Xtrain,1),1), [Xtrain trainvalues(:,1:i-1)], model);
    [ypred(:,i),~,testvalues(:,i)] = predict(zeros(size(Xtest,1),1), [Xtest testvalues(:,1:i-1)], model);
end
values = testvalues;