wolffd@0: function net = gp(nin, covar_fn, prior) wolffd@0: %GP Create a Gaussian Process. wolffd@0: % wolffd@0: % Description wolffd@0: % wolffd@0: % NET = GP(NIN, COVARFN) takes the number of inputs NIN for a Gaussian wolffd@0: % Process model with a single output, together with a string COVARFN wolffd@0: % which specifies the type of the covariance function, and returns a wolffd@0: % data structure NET. The parameters are set to zero. wolffd@0: % wolffd@0: % The fields in NET are wolffd@0: % type = 'gp' wolffd@0: % nin = number of inputs wolffd@0: % nout = number of outputs: always 1 wolffd@0: % nwts = total number of weights and covariance function parameters wolffd@0: % bias = logarithm of constant offset in covariance function wolffd@0: % noise = logarithm of output noise variance wolffd@0: % inweights = logarithm of inverse length scale for each input wolffd@0: % covarfn = string describing the covariance function: wolffd@0: % 'sqexp' wolffd@0: % 'ratquad' wolffd@0: % fpar = covariance function specific parameters (1 for squared exponential, wolffd@0: % 2 for rational quadratic) wolffd@0: % trin = training input data (initially empty) wolffd@0: % trtargets = training target data (initially empty) wolffd@0: % wolffd@0: % NET = GP(NIN, COVARFN, PRIOR) sets a Gaussian prior on the parameters wolffd@0: % of the model. PRIOR must contain the fields PR_MEAN and PR_VARIANCE. wolffd@0: % If PR_MEAN is a scalar, then the Gaussian is assumed to be isotropic wolffd@0: % and the additional fields NET.PR_MEAN and PR_VARIANCE are set. wolffd@0: % Otherwise, the Gaussian prior has a mean defined by a column vector wolffd@0: % of parameters PRIOR.PR_MEAN and covariance defined by a column vector wolffd@0: % of parameters PRIOR.PR_VARIANCE. Each element of PRMEAN corresponds wolffd@0: % to a separate group of parameters, which need not be mutually wolffd@0: % exclusive. The membership of the groups is defined by the matrix wolffd@0: % PRIOR.INDEX in which the columns correspond to the elements of wolffd@0: % PRMEAN. Each column has one element for each weight in the matrix, in wolffd@0: % the order defined by the function GPPAK, and each element is 1 or 0 wolffd@0: % according to whether the parameter is a member of the corresponding wolffd@0: % group or not. The additional field NET.INDEX is set in this case. wolffd@0: % wolffd@0: % See also wolffd@0: % GPPAK, GPUNPAK, GPFWD, GPERR, GPCOVAR, GPGRAD wolffd@0: % wolffd@0: wolffd@0: % Copyright (c) Ian T Nabney (1996-2001) wolffd@0: wolffd@0: net.type = 'gp'; wolffd@0: net.nin = nin; wolffd@0: net.nout = 1; % Only do single output GP wolffd@0: wolffd@0: % Store log parameters wolffd@0: net.bias = 0; wolffd@0: net.min_noise = sqrt(eps); % Prevent output noise collapsing completely wolffd@0: net.noise = 0; wolffd@0: net.inweights = zeros(1,nin); % Weights on inputs in covariance function wolffd@0: wolffd@0: covarfns = {'sqexp', 'ratquad'}; wolffd@0: wolffd@0: if sum(strcmp(covar_fn, covarfns)) == 0 wolffd@0: error('Undefined activation function. Exiting.'); wolffd@0: else wolffd@0: net.covar_fn = covar_fn; wolffd@0: end wolffd@0: wolffd@0: switch covar_fn wolffd@0: wolffd@0: case 'sqexp' % Squared exponential wolffd@0: net.fpar = zeros(1,1); % One function specific parameter wolffd@0: wolffd@0: case 'ratquad' % Rational quadratic wolffd@0: net.fpar = zeros(1, 2); % Two function specific parameters wolffd@0: wolffd@0: otherwise wolffd@0: error(['Unknown covariance function ', covar_fn]); wolffd@0: end wolffd@0: wolffd@0: net.nwts = 2 + nin + length(net.fpar); wolffd@0: wolffd@0: if nargin >= 3 wolffd@0: if size(prior.pr_mean) == [1 1] wolffd@0: net.pr_mean = prior.pr_mean; wolffd@0: net.pr_var = prior.pr_var; wolffd@0: else wolffd@0: net.pr_mean = prior.pr_mean; wolffd@0: net.pr_var = prior.pr_var; wolffd@0: net.index = prior.index; wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: % Store training data as needed for gpfwd wolffd@0: net.tr_in = []; wolffd@0: net.tr_targets = [];