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