wolffd@0: function [e, edata, eprior] = gperr(net, x, t) wolffd@0: %GPERR Evaluate error function for Gaussian Process. wolffd@0: % wolffd@0: % Description wolffd@0: % E = GPERR(NET, X, T) takes a Gaussian Process data structure NET wolffd@0: % together with a matrix X of input vectors and a matrix T of target wolffd@0: % vectors, and evaluates the error function E. Each row of X wolffd@0: % corresponds to one input vector and each row of T corresponds to one wolffd@0: % target vector. wolffd@0: % wolffd@0: % [E, EDATA, EPRIOR] = GPERR(NET, X, T) additionally returns the data wolffd@0: % and hyperprior components of the error, assuming a Gaussian prior on wolffd@0: % the weights with mean and variance parameters PRMEAN and PRVARIANCE wolffd@0: % taken from the network data structure NET. wolffd@0: % wolffd@0: % See also wolffd@0: % GP, GPCOVAR, GPFWD, GPGRAD wolffd@0: % wolffd@0: wolffd@0: % Copyright (c) Ian T Nabney (1996-2001) wolffd@0: wolffd@0: errstring = consist(net, 'gp', x, t); wolffd@0: if ~isempty(errstring); wolffd@0: error(errstring); wolffd@0: end wolffd@0: wolffd@0: cn = gpcovar(net, x); wolffd@0: wolffd@0: edata = 0.5*(sum(log(eig(cn, 'nobalance'))) + t'*inv(cn)*t); wolffd@0: wolffd@0: % Evaluate the hyperprior contribution to the error. wolffd@0: % The hyperprior is Gaussian with mean pr_mean and variance wolffd@0: % pr_variance wolffd@0: if isfield(net, 'pr_mean') wolffd@0: w = gppak(net); wolffd@0: m = repmat(net.pr_mean, size(w)); wolffd@0: if size(net.pr_mean) == [1 1] wolffd@0: eprior = 0.5*((w-m)*(w-m)'); wolffd@0: e2 = eprior/net.pr_var; wolffd@0: else wolffd@0: wpr = repmat(w, size(net.pr_mean, 1), 1)'; wolffd@0: eprior = 0.5*(((wpr - m').^2).*net.index); wolffd@0: e2 = (sum(eprior, 1))*(1./net.pr_var); wolffd@0: end wolffd@0: else wolffd@0: e2 = 0; wolffd@0: eprior = 0; wolffd@0: end wolffd@0: wolffd@0: e = edata + e2; wolffd@0: