Home > machines > prt_machine_gpr.m

prt_machine_gpr

PURPOSE ^

Run Gaussian process regression - meta-wrapper for regression with gpml FORMAT output = prt_machine_gpml(d,args)

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

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