Home > machines > prt_machine_krr.m

prt_machine_krr

PURPOSE ^

Kernel ridge regression

SYNOPSIS ^

function output = prt_machine_krr(d,args)

DESCRIPTION ^

 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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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$
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     m = mean(d.tr_targets);                     % mean of the training data
0053     t = d.tr_targets - m;                             % mean centre targets
0054     w = prt_KRR(K,t,args);
0055        
0056     output.predictions=d.test{1}*w + m;    % add mean from the training set
0057     output.func_val=output.predictions;
0058     output.alpha=w;
0059   
0060 end
0061 
0062 end

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