⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readin_model.m

📁 libsvm is a simple, easy-to-use, and efficient software for SVM classification and regression. It s
💻 M
字号:
function [CA,SV,b]=readin_model(fname_model,D)

%      This function is to read the parameters (CA, SV, b) out of the model file (namely, "fname_model") trained by SVM machine.

%      The explanations of CA, SV, b----see "Build_classifier.m"

%      D is the dimension of the training data.



fid=fopen(fname_model,'r');


for i=1:9
    
    a=fgetl(fid);
    
    if i==6
       rho=str2num(a(5:end));
    end
    
    if i==7
       index=a(7);
    end
    
end

b=-rho;


i=1;
while 1
    tline = fgetl(fid);    
    if ~ischar(tline),   break,   end  

    index_1=find(tline==' '); %%%% basically index_1 has D+1 elements, but sometimes due to sparse representation it may have fewer elements
    index_2=find(tline==':'); %%%% basically index_2 has D elements, but sometimes due to sparse representation it may have fewer elements
     
    %%%% size(index_1) is always == size(index_2)+1.
    
    y=zeros(1,D);
    ay=str2num(tline(1:index_1(1)-1));
    
    
    if size(index_2,2)<D
        
        for k=1:size(index_2,2)
                
            dimen_location = str2num(  tline(index_2(k)-1) );
            y(dimen_location)= str2num(           tline(   index_2(k)+1   :   index_1(k+1)-1   )            );
        
        end      
                     
    else %%% size(index_2,2)==D
        
        for k=1:D
            y(k)=str2num(tline( index_2(k)+1 : index_1(k+1)-1));
        end

    end
           
    
    if i==1
        CA=ay;
        SV=y;
    else
        CA=[CA;ay];
        SV=[SV;y];
    end
  
    i=i+1;
end    
    


fclose(fid);

fclose all;


if index=='-'
   
   CA=-CA;
   b=-b;

end












⌨️ 快捷键说明

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