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