annotate toolboxes/FullBNT-1.0.7/netlab3.3/gp.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function net = gp(nin, covar_fn, prior)
wolffd@0 2 %GP Create a Gaussian Process.
wolffd@0 3 %
wolffd@0 4 % Description
wolffd@0 5 %
wolffd@0 6 % NET = GP(NIN, COVARFN) takes the number of inputs NIN for a Gaussian
wolffd@0 7 % Process model with a single output, together with a string COVARFN
wolffd@0 8 % which specifies the type of the covariance function, and returns a
wolffd@0 9 % data structure NET. The parameters are set to zero.
wolffd@0 10 %
wolffd@0 11 % The fields in NET are
wolffd@0 12 % type = 'gp'
wolffd@0 13 % nin = number of inputs
wolffd@0 14 % nout = number of outputs: always 1
wolffd@0 15 % nwts = total number of weights and covariance function parameters
wolffd@0 16 % bias = logarithm of constant offset in covariance function
wolffd@0 17 % noise = logarithm of output noise variance
wolffd@0 18 % inweights = logarithm of inverse length scale for each input
wolffd@0 19 % covarfn = string describing the covariance function:
wolffd@0 20 % 'sqexp'
wolffd@0 21 % 'ratquad'
wolffd@0 22 % fpar = covariance function specific parameters (1 for squared exponential,
wolffd@0 23 % 2 for rational quadratic)
wolffd@0 24 % trin = training input data (initially empty)
wolffd@0 25 % trtargets = training target data (initially empty)
wolffd@0 26 %
wolffd@0 27 % NET = GP(NIN, COVARFN, PRIOR) sets a Gaussian prior on the parameters
wolffd@0 28 % of the model. PRIOR must contain the fields PR_MEAN and PR_VARIANCE.
wolffd@0 29 % If PR_MEAN is a scalar, then the Gaussian is assumed to be isotropic
wolffd@0 30 % and the additional fields NET.PR_MEAN and PR_VARIANCE are set.
wolffd@0 31 % Otherwise, the Gaussian prior has a mean defined by a column vector
wolffd@0 32 % of parameters PRIOR.PR_MEAN and covariance defined by a column vector
wolffd@0 33 % of parameters PRIOR.PR_VARIANCE. Each element of PRMEAN corresponds
wolffd@0 34 % to a separate group of parameters, which need not be mutually
wolffd@0 35 % exclusive. The membership of the groups is defined by the matrix
wolffd@0 36 % PRIOR.INDEX in which the columns correspond to the elements of
wolffd@0 37 % PRMEAN. Each column has one element for each weight in the matrix, in
wolffd@0 38 % the order defined by the function GPPAK, and each element is 1 or 0
wolffd@0 39 % according to whether the parameter is a member of the corresponding
wolffd@0 40 % group or not. The additional field NET.INDEX is set in this case.
wolffd@0 41 %
wolffd@0 42 % See also
wolffd@0 43 % GPPAK, GPUNPAK, GPFWD, GPERR, GPCOVAR, GPGRAD
wolffd@0 44 %
wolffd@0 45
wolffd@0 46 % Copyright (c) Ian T Nabney (1996-2001)
wolffd@0 47
wolffd@0 48 net.type = 'gp';
wolffd@0 49 net.nin = nin;
wolffd@0 50 net.nout = 1; % Only do single output GP
wolffd@0 51
wolffd@0 52 % Store log parameters
wolffd@0 53 net.bias = 0;
wolffd@0 54 net.min_noise = sqrt(eps); % Prevent output noise collapsing completely
wolffd@0 55 net.noise = 0;
wolffd@0 56 net.inweights = zeros(1,nin); % Weights on inputs in covariance function
wolffd@0 57
wolffd@0 58 covarfns = {'sqexp', 'ratquad'};
wolffd@0 59
wolffd@0 60 if sum(strcmp(covar_fn, covarfns)) == 0
wolffd@0 61 error('Undefined activation function. Exiting.');
wolffd@0 62 else
wolffd@0 63 net.covar_fn = covar_fn;
wolffd@0 64 end
wolffd@0 65
wolffd@0 66 switch covar_fn
wolffd@0 67
wolffd@0 68 case 'sqexp' % Squared exponential
wolffd@0 69 net.fpar = zeros(1,1); % One function specific parameter
wolffd@0 70
wolffd@0 71 case 'ratquad' % Rational quadratic
wolffd@0 72 net.fpar = zeros(1, 2); % Two function specific parameters
wolffd@0 73
wolffd@0 74 otherwise
wolffd@0 75 error(['Unknown covariance function ', covar_fn]);
wolffd@0 76 end
wolffd@0 77
wolffd@0 78 net.nwts = 2 + nin + length(net.fpar);
wolffd@0 79
wolffd@0 80 if nargin >= 3
wolffd@0 81 if size(prior.pr_mean) == [1 1]
wolffd@0 82 net.pr_mean = prior.pr_mean;
wolffd@0 83 net.pr_var = prior.pr_var;
wolffd@0 84 else
wolffd@0 85 net.pr_mean = prior.pr_mean;
wolffd@0 86 net.pr_var = prior.pr_var;
wolffd@0 87 net.index = prior.index;
wolffd@0 88 end
wolffd@0 89 end
wolffd@0 90
wolffd@0 91 % Store training data as needed for gpfwd
wolffd@0 92 net.tr_in = [];
wolffd@0 93 net.tr_targets = [];