annotate toolboxes/FullBNT-1.0.7/netlab3.3/gperr.m @ 0:cc4b1211e677 tip

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