function [HY,BETA] = ModelToHyperplane(M,svmname)
%function [HY,BETA] = ModelToHyperplane(M,svmname)
%
%converts a linear SVM classifier into an actual hyperplane.

if(nargin < 2)
  svmname = 'libsvm';
end

HY = M.SVs'*M.sv_coef;
BETA = M.rho;
X = rand(size(HY,1),1);
cmd = sprintf('[lab,score] = CLS%sC(X,M);',svmname);
eval(cmd);
myscore = (HY'*X-BETA);
if sign(myscore)~=lab
	HY = -HY;
	BETA = -BETA;
	myscore = (HY'*X-BETA);
end

if (myscore-score)>1e-8
	error('something is fucked up');
end	