


Kernel ridge regression
FORMAT output = prt_machine_svm_bin(d,args)
Inputs:
d - structure with data information, with mandatory fields:
.train - training data (cell array of matrices of row vectors,
each [Ntr x D]). each matrix contains one representation
of the data. This is useful for approaches such as
multiple kernel learning.
.test - testing data (cell array of matrices row vectors, each
[Nte x D])
.tr_targets - training labels (for classification) or values (for
regression) (column vector, [Ntr x 1])
.use_kernel - flag, is data in form of kernel matrices (true) of in
form of features (false)
args - libSVM arguments
Output:
output - output of machine (struct).
* Mandatory fields:
.predictions - predictions of classification or regression [Nte x D]
* Optional fields:
.func_val - value of the decision function
.type - which type of machine this is (here, 'classifier')
__________________________________________________________________________
Copyright (C) 2011 Machine Learning & Neuroimaging Laboratory

0001 function output = prt_machine_krr(d,args) 0002 % Kernel ridge regression 0003 % FORMAT output = prt_machine_svm_bin(d,args) 0004 % Inputs: 0005 % d - structure with data information, with mandatory fields: 0006 % .train - training data (cell array of matrices of row vectors, 0007 % each [Ntr x D]). each matrix contains one representation 0008 % of the data. This is useful for approaches such as 0009 % multiple kernel learning. 0010 % .test - testing data (cell array of matrices row vectors, each 0011 % [Nte x D]) 0012 % .tr_targets - training labels (for classification) or values (for 0013 % regression) (column vector, [Ntr x 1]) 0014 % .use_kernel - flag, is data in form of kernel matrices (true) of in 0015 % form of features (false) 0016 % args - libSVM arguments 0017 % Output: 0018 % output - output of machine (struct). 0019 % * Mandatory fields: 0020 % .predictions - predictions of classification or regression [Nte x D] 0021 % * Optional fields: 0022 % .func_val - value of the decision function 0023 % .type - which type of machine this is (here, 'classifier') 0024 %__________________________________________________________________________ 0025 % Copyright (C) 2011 Machine Learning & Neuroimaging Laboratory 0026 0027 % Written by Carlton Chu 0028 % $Id: prt_machine_krr.m 370 2011-11-12 15:30:53Z cphillip $ 0029 0030 0031 output.type=d.pred_type; 0032 0033 SANITYCHECK=true; % can turn off for "speed". Expert only. 0034 0035 if SANITYCHECK==true 0036 % args should be a string (empty or otherwise) 0037 if ~isnumeric(args) 0038 error('prt_machine_krr:krrRegNotNumeric',['Error: krr'... 0039 ' regularization should be a number. ' ... 0040 ' SOLUTION: Please use a number']); 0041 end 0042 K=d.train{1}; 0043 [n m]=size(K); 0044 if n~=m 0045 error('prt_machine_krr:kernelSize',['Error: krr'... 0046 ' training kernel should be square ' ... 0047 ' SOLUTION: do the right thing']); 0048 end 0049 0050 % Run KRR 0051 %-------------------------------------------------------------------------- 0052 t=d.tr_targets; 0053 w=prt_KRR(K,t,args); 0054 0055 output.predictions=d.test{1}*w; 0056 output.func_val=output.predictions; 0057 output.alpha=w; 0058 0059 end 0060 0061 end