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