Home > machines > prt_weights.m

prt_weights

PURPOSE ^

Run function to compute weights

SYNOPSIS ^

function weights = prt_weights(d,m)

DESCRIPTION ^

 Run function to compute weights
 FORMAT weights = prt_weights(d,m)
 Inputs:
       d   - data structure
             (fields of .d can vary depending on weights function)
       m   - machine structure
           .function - function to compute weights (string)
           .args     - function arguments
 Output:
       weights - weights vector [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(d,m)
0002 % Run function to compute weights
0003 % FORMAT weights = prt_weights(d,m)
0004 % Inputs:
0005 %       d   - data structure
0006 %             (fields of .d can vary depending on weights function)
0007 %       m   - machine structure
0008 %           .function - function to compute weights (string)
0009 %           .args     - function arguments
0010 % Output:
0011 %       weights - weights vector [Nfeatures x 1]
0012 %__________________________________________________________________________
0013 % Copyright (C) 2011 Machine Learning & Neuroimaging Laboratory
0014 
0015 % Written by M.J.Rosa and J.Mourao-Miranda
0016 % $Id: prt_weights.m 425 2012-01-26 13:08:43Z mjrosa $
0017 
0018 SANITYCHECK = true; % turn off for speed
0019 
0020 % initial checks
0021 %--------------------------------------------------------------------------
0022 if SANITYCHECK == true
0023     if ~isempty(m)
0024         if isstruct(m)
0025             if isfield(m,'function')
0026                 if ~ischar(m.function)
0027                     error('prt_weights:functionNotString',...
0028                         'Error: ''function'' should be a string!');
0029                 end
0030                 if ~exist(m.function,'file')
0031                     error('prt_weights:functionFileNotFound',...
0032                         'Error: %s function could not be found!',...
0033                         m.function);
0034                 end
0035             else
0036                 error('prt_weights:functionNotField',...
0037                     'Error: ''function'' should be a field of machine!');
0038             end
0039             if ~isfield(m,'args')
0040                 m.args = [];
0041             end
0042         else
0043             error('prt_weights:machineNotStruct',...
0044                 'Error: machine should be a structure!');
0045         end
0046     else
0047         error('prt_weights:machineEmpty',...
0048             'Error: ''machine'' cannot be empty!');
0049     end
0050     if ~isempty(d)
0051         if ~isstruct(d)
0052             error('prt_weights:dataNotStruct',...
0053                 'Error: data should be a structure!');
0054         end
0055     else
0056         error('prt_weights:dataStructEmpty',...
0057             'Error: ''data'' struct cannot be empty!');
0058     end
0059 end
0060 
0061 % run weights
0062 %--------------------------------------------------------------------------
0063 fnch    = str2func(m.function);
0064 weights = fnch(d,m.args);
0065 
0066 % final checks
0067 %--------------------------------------------------------------------------
0068 if SANITYCHECK == true
0069     if ~isvector(weights)
0070         error('prt_weights:weightsNotVector',...
0071             'Error: weights should be a vector!');
0072     end
0073 end

Generated on Mon 03-Sep-2012 18:07:18 by m2html © 2005