Home > machines > prt_weights_sMKL_reg.m

prt_weights_sMKL_reg

PURPOSE ^

Run function to compute weights for binary MKL

SYNOPSIS ^

function weights = prt_weights_sMKL_reg(d,args)

DESCRIPTION ^

 Run function to compute weights for binary MKL
 FORMAT weights = prt_weights_sMKL (d,args)
 Inputs:
       d               - data structure
           .datamat    - data matrix [Nfeatures x Nexamples]
           .coeffs     - coefficients vector [Nexamples x 1]
           .betas      - kernel weights
           .idfeat_img - cell with indece
       args            - function arguments (can be left empty)
 Output:
       weights         - vector with weights [Nfeatures x 1]
__________________________________________________________________________
 Copyright (C) 2011 Machine Learning & Neuroimaging Laboratory

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function weights = prt_weights_sMKL_reg(d,args)
0002 % Run function to compute weights for binary MKL
0003 % FORMAT weights = prt_weights_sMKL (d,args)
0004 % Inputs:
0005 %       d               - data structure
0006 %           .datamat    - data matrix [Nfeatures x Nexamples]
0007 %           .coeffs     - coefficients vector [Nexamples x 1]
0008 %           .betas      - kernel weights
0009 %           .idfeat_img - cell with indece
0010 %       args            - function arguments (can be left empty)
0011 % Output:
0012 %       weights         - vector with weights [Nfeatures x 1]
0013 %__________________________________________________________________________
0014 % Copyright (C) 2011 Machine Learning & Neuroimaging Laboratory
0015 
0016 % Written by J.Mourao-Miranda
0017 
0018 SANITYCHECK = true; % turn off for speed
0019 
0020 % initial checks
0021 %--------------------------------------------------------------------------
0022 if SANITYCHECK == true
0023     if isempty(d)
0024         error('prt_weights_svm_bin:DataEmpty',...
0025             'Error: ''data'' cannot be empty!');
0026     else
0027         if ~isfield(d,'datamat')
0028             error('prt_weights_svm_bin:noDatamatField',...
0029                 ['Error: ''data'' struct must contain a ''datamat'' '...
0030                 ' field!']);
0031         end
0032         if isfield(d,'coeffs')
0033             if ~isvector(d.coeffs)
0034                 error('prt_weights_svm_bin:CoeffsnoVector',...
0035                     'Error: ''coeffs'' must be a vector!');
0036             else
0037                 ncoeffs = length(d.coeffs);
0038             end
0039         else
0040             error('prt_weights_svm_bin:noCoeffsField',...
0041                 ['Error: ''data'' struct must contain ''coeffs'' '...
0042                 ' field!']);
0043         end
0044     end
0045 end
0046 
0047 % create 1D image
0048 %--------------------------------------------------------------------------
0049 
0050 
0051 % compute weigths
0052 
0053 img1d     = zeros(size(d.datamat(1,:)),'single');
0054 
0055 for k=1:length(args.betas)
0056     
0057     betas = single(args.betas(k));
0058     index_k = args.idfeat_img{k};
0059     
0060     if ~isempty(index_k) && betas~=0
0061         if ~isfield(args,'flag') || ~args.flag
0062             for i=1:ncoeffs
0063             
0064             tmp1 = single(d.datamat(i,index_k));
0065             tmp2 = single(d.coeffs(i));
0066             
0067             img1d(index_k) = img1d(index_k) + tmp1 * tmp2;
0068             
0069             end   
0070         else
0071             img1d(index_k) = ones(1,length(index_k));
0072         end        
0073         
0074         img1d(index_k) = betas * img1d(index_k);
0075     end
0076 end
0077 
0078 % weigths
0079 weights{1}  = img1d; % originally, it was: weights  = img1d

Generated on Tue 10-Feb-2015 18:16:33 by m2html © 2005