annotate toolboxes/FullBNT-1.0.7/netlab3.3/gperr.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 [e, edata, eprior] = gperr(net, x, t)
wolffd@0 2 %GPERR Evaluate error function for Gaussian Process.
wolffd@0 3 %
wolffd@0 4 % Description
wolffd@0 5 % E = GPERR(NET, X, T) takes a Gaussian Process data structure NET
wolffd@0 6 % together with a matrix X of input vectors and a matrix T of target
wolffd@0 7 % vectors, and evaluates the error function E. Each row of X
wolffd@0 8 % corresponds to one input vector and each row of T corresponds to one
wolffd@0 9 % target vector.
wolffd@0 10 %
wolffd@0 11 % [E, EDATA, EPRIOR] = GPERR(NET, X, T) additionally returns the data
wolffd@0 12 % and hyperprior components of the error, assuming a Gaussian prior on
wolffd@0 13 % the weights with mean and variance parameters PRMEAN and PRVARIANCE
wolffd@0 14 % taken from the network data structure NET.
wolffd@0 15 %
wolffd@0 16 % See also
wolffd@0 17 % GP, GPCOVAR, GPFWD, GPGRAD
wolffd@0 18 %
wolffd@0 19
wolffd@0 20 % Copyright (c) Ian T Nabney (1996-2001)
wolffd@0 21
wolffd@0 22 errstring = consist(net, 'gp', x, t);
wolffd@0 23 if ~isempty(errstring);
wolffd@0 24 error(errstring);
wolffd@0 25 end
wolffd@0 26
wolffd@0 27 cn = gpcovar(net, x);
wolffd@0 28
wolffd@0 29 edata = 0.5*(sum(log(eig(cn, 'nobalance'))) + t'*inv(cn)*t);
wolffd@0 30
wolffd@0 31 % Evaluate the hyperprior contribution to the error.
wolffd@0 32 % The hyperprior is Gaussian with mean pr_mean and variance
wolffd@0 33 % pr_variance
wolffd@0 34 if isfield(net, 'pr_mean')
wolffd@0 35 w = gppak(net);
wolffd@0 36 m = repmat(net.pr_mean, size(w));
wolffd@0 37 if size(net.pr_mean) == [1 1]
wolffd@0 38 eprior = 0.5*((w-m)*(w-m)');
wolffd@0 39 e2 = eprior/net.pr_var;
wolffd@0 40 else
wolffd@0 41 wpr = repmat(w, size(net.pr_mean, 1), 1)';
wolffd@0 42 eprior = 0.5*(((wpr - m').^2).*net.index);
wolffd@0 43 e2 = (sum(eprior, 1))*(1./net.pr_var);
wolffd@0 44 end
wolffd@0 45 else
wolffd@0 46 e2 = 0;
wolffd@0 47 eprior = 0;
wolffd@0 48 end
wolffd@0 49
wolffd@0 50 e = edata + e2;
wolffd@0 51