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