Home > machines > prt_machine_gpr.m

prt_machine_gpr

PURPOSE ^

Run Gaussian process regression - meta-wrapper for regression with gpml

SYNOPSIS ^

function output = prt_machine_gpr(d,args)

DESCRIPTION ^

 Run Gaussian process regression - meta-wrapper for regression with gpml  
 FORMAT output = prt_machine_gpml(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])
     .testcov    - testing covariance (cell array of matrices row vectors,
                   each [Nte x Nte])
     .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) or in 
                   form of features (false)
    args     - argument string, where
       -h         - optimise hyperparameters (otherwise don't)
       -f iter    - max # iterations for optimiser (ignored if -h not set)
       -l likfun  - likelihood function:
                       'likErf' - erf/probit likelihood (binary only)
       -c covfun  - covariance function:
                       'covLINkcell' - simple dot product
                       'covLINglm'   - construct a GLM
       -m meanfun - mean function:
                       'meanConstcell' - suitable for dot product
                       'meanConstglm'  - suitable for GLM
       -i inffun  - inference function:
                       'prt_infEP' - Expectation Propagation
    experimental args (use at your own risk):
       -p         - use priors for the hyperparameters. If specified, this
                    indicates that a maximum a posteriori (MAP) approach
                    will be used to set covariance function
                    hyperparameters. The priors are obtained by calling
                    prt_gp_priors('covFuncName')

       N.B.: for the arguments specifying functions, pass in a string, not
       a function handle. This script will generate a function handle
 
 Output:
    output  - output of machine (struct).
     * Mandatory fields:
      .predictions - predictions of classification or regression [Nte x D]
     * Optional fields:
      .type     - which type of machine this is (here, 'classifier')
      .func_val - predictive probabilties
      .mu       - test latent means
      .s2       - test latent variances
      .loghyper - log hyperparameters
      .nlml     - negative log marginal likelihood
      .alpha    - GP weighting coefficients
      .sW       - likelihood matrix (see Rasmussen & Williams, 2006)
      .L        - Cholesky factor
__________________________________________________________________________
 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_gpr(d,args)
0002 % Run Gaussian process regression - meta-wrapper for regression with gpml
0003 % FORMAT output = prt_machine_gpml(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 %     .testcov    - testing covariance (cell array of matrices row vectors,
0013 %                   each [Nte x Nte])
0014 %     .tr_targets - training labels (for classification) or values (for
0015 %                   regression) (column vector, [Ntr x 1])
0016 %     .use_kernel - flag, is data in form of kernel matrices (true) or in
0017 %                   form of features (false)
0018 %    args     - argument string, where
0019 %       -h         - optimise hyperparameters (otherwise don't)
0020 %       -f iter    - max # iterations for optimiser (ignored if -h not set)
0021 %       -l likfun  - likelihood function:
0022 %                       'likErf' - erf/probit likelihood (binary only)
0023 %       -c covfun  - covariance function:
0024 %                       'covLINkcell' - simple dot product
0025 %                       'covLINglm'   - construct a GLM
0026 %       -m meanfun - mean function:
0027 %                       'meanConstcell' - suitable for dot product
0028 %                       'meanConstglm'  - suitable for GLM
0029 %       -i inffun  - inference function:
0030 %                       'prt_infEP' - Expectation Propagation
0031 %    experimental args (use at your own risk):
0032 %       -p         - use priors for the hyperparameters. If specified, this
0033 %                    indicates that a maximum a posteriori (MAP) approach
0034 %                    will be used to set covariance function
0035 %                    hyperparameters. The priors are obtained by calling
0036 %                    prt_gp_priors('covFuncName')
0037 %
0038 %       N.B.: for the arguments specifying functions, pass in a string, not
0039 %       a function handle. This script will generate a function handle
0040 %
0041 % Output:
0042 %    output  - output of machine (struct).
0043 %     * Mandatory fields:
0044 %      .predictions - predictions of classification or regression [Nte x D]
0045 %     * Optional fields:
0046 %      .type     - which type of machine this is (here, 'classifier')
0047 %      .func_val - predictive probabilties
0048 %      .mu       - test latent means
0049 %      .s2       - test latent variances
0050 %      .loghyper - log hyperparameters
0051 %      .nlml     - negative log marginal likelihood
0052 %      .alpha    - GP weighting coefficients
0053 %      .sW       - likelihood matrix (see Rasmussen & Williams, 2006)
0054 %      .L        - Cholesky factor
0055 %__________________________________________________________________________
0056 % Copyright (C) 2011 Machine Learning & Neuroimaging Laboratory
0057 
0058 % Written by A Marquand
0059 % $Id$
0060 
0061 % set default gp paramters (N.B.: these are strings, not function handles)
0062 meanfunc  = 'meanConstcell';
0063 covfunc   = 'covLINkcell'; 
0064 maxeval   = '100';
0065 likfunc   = 'likGauss';
0066 inffunc   = 'prt_infExact';
0067 
0068 % parse input arguments (i.e. check for non-default options)
0069 % -------------------------------------------------------------------------
0070 % hyperparameters
0071 if ~isempty(regexp(args,'-h','once'))
0072     opt = ' -h ';
0073     eargs = regexp(args,'-f\s+[0-9]*','match');
0074     if ~isempty(eargs)
0075         eargs = regexp(cell2mat(eargs),'-f\s+','split');
0076         maxeval  = [cell2mat(eargs(2))];
0077     end
0078 else
0079     opt = '';
0080 end
0081 % likelihood function
0082 largs = regexp(args,'-l\s+[a-zA-Z0-9_]*','match');
0083 if ~isempty(largs)
0084     largs = regexp(cell2mat(largs),'-l\s+','split');
0085     likfunc = str2func(cell2mat(largs(2)));
0086     if strcmpi(cell2mat(largs(2)),'Gauss')
0087         likfunc  = 'likGauss';
0088     end
0089 end
0090 % covariance function
0091 cargs = regexp(args,'-c\s+[a-zA-Z0-9_]*','match');
0092 if ~isempty(cargs)
0093     cargs = regexp(cell2mat(cargs),'-c\s+','split');
0094     covfunc = cell2mat(cargs(2));
0095 end
0096 % mean function
0097 margs = regexp(args,'-m\s+[a-zA-Z0-9_]*','match');
0098 if ~isempty(margs)
0099     margs = regexp(cell2mat(margs),'-m\s+','split');
0100     meanfunc = str2func(cell2mat(margs(2)));
0101 end
0102 % inference function
0103 iargs = regexp(args,'-i\s+[a-zA-Z0-9_]*','match');
0104 if ~isempty(iargs)
0105     iargs = regexp(cell2mat(iargs),'-i\s+','split');
0106     inffunc = cell2mat(iargs(2));
0107 end
0108 % priors
0109 if ~isempty(regexp(args,'-p','once'))
0110     map = ' -p ';
0111 else
0112     map = '';
0113 end
0114 
0115 % construct argument string for prt_machine_gpml
0116 args = ['-l ',likfunc,' -c ',covfunc,' -m ',meanfunc,...
0117        ' -i ',inffunc,' ',opt,' ','-f ',maxeval,map];
0118 
0119 % do the regression
0120 output = prt_machine_gpml(d, args);
0121 end
0122

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