svmmultival.m

来自「本程序实现了基于svm方法的基础上对分类样本进行模糊化处理。使其更精确」· M 代码 · 共 52 行

M
52
字号
function [ypred,maxi,ypredMat]=svmmultival(x,xsup,w,b,nbsv,kernel,kerneloption)




[n1,n2]=size(x);
nbclass=length(nbsv);
y=zeros(n1,nbclass);
nbsv=[0 nbsv];
aux=cumsum(nbsv);
for i=1:nbclass
    if ~isempty(xsup)
         xsupaux=xsup(aux(i)+1:aux(i)+nbsv(i+1),:);
        waux=w(aux(i)+1:aux(i)+nbsv(i+1));
        baux=b(i);
        ypred(:,i)= svmval(x,xsupaux,waux,baux,kernel,kerneloption);
    else
      if isempty(x)  %  Kernel matrix is given as a parameter 
        waux=w(aux(i)+1:aux(i)+nbsv(i+1));
        baux=b(i);
        kernel='numerical';
        xsupaux=[];
        pos=aux(i)+1:aux(i)+nbsv(i+1);
        kerneloption2.matrix=kerneloption.matrix(:,pos);
        ypred(:,i)= svmval(x,xsupaux,waux,baux,kernel,kerneloption2);
      end;
    end;
end;
%--------------------------------------------------------------
%把待分类点模糊化,
for i=1:nbclass
    for j=1:nbclass
        if i==j
            ind1=find(ypred(:,j)>=1);
            ind2=find(ypred(:,j)<1);
            ypred1(ind1,j)=1;
            ypred1(ind2,j)=ypred(ind2,j);
        else
            ind1=find(ypred(:,j)<=-1);
            ind2=find(ypred(:,j)>-1);
            ypred1(ind1,j)=1;
            ypred1(ind2,j)=-1*ypred(ind2,j);
        end
    end
    ypred2(:,i)=min(ypred1')';
end
%-----------------------------------------------------------------------
ypredMat=ypred2;
[maxi,ypred]=max(ypred2');
maxi=maxi';
ypred=ypred';

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?