wolffd@0
|
1 function [e, edata, eprior] = errbayes(net, edata)
|
wolffd@0
|
2 %ERRBAYES Evaluate Bayesian error function for network.
|
wolffd@0
|
3 %
|
wolffd@0
|
4 % Description
|
wolffd@0
|
5 % E = ERRBAYES(NET, EDATA) takes a network data structure NET together
|
wolffd@0
|
6 % the data contribution to the error for a set of inputs and targets.
|
wolffd@0
|
7 % It returns the regularised error using any zero mean Gaussian priors
|
wolffd@0
|
8 % on the weights defined in NET.
|
wolffd@0
|
9 %
|
wolffd@0
|
10 % [E, EDATA, EPRIOR] = ERRBAYES(NET, X, T) additionally returns the
|
wolffd@0
|
11 % data and prior components of the error.
|
wolffd@0
|
12 %
|
wolffd@0
|
13 % See also
|
wolffd@0
|
14 % GLMERR, MLPERR, RBFERR
|
wolffd@0
|
15 %
|
wolffd@0
|
16
|
wolffd@0
|
17 % Copyright (c) Ian T Nabney (1996-2001)
|
wolffd@0
|
18
|
wolffd@0
|
19 % Evaluate the data contribution to the error.
|
wolffd@0
|
20 if isfield(net, 'beta')
|
wolffd@0
|
21 e1 = net.beta*edata;
|
wolffd@0
|
22 else
|
wolffd@0
|
23 e1 = edata;
|
wolffd@0
|
24 end
|
wolffd@0
|
25
|
wolffd@0
|
26 % Evaluate the prior contribution to the error.
|
wolffd@0
|
27 if isfield(net, 'alpha')
|
wolffd@0
|
28 w = netpak(net);
|
wolffd@0
|
29 if size(net.alpha) == [1 1]
|
wolffd@0
|
30 eprior = 0.5*(w*w');
|
wolffd@0
|
31 e2 = eprior*net.alpha;
|
wolffd@0
|
32 else
|
wolffd@0
|
33 if (isfield(net, 'mask'))
|
wolffd@0
|
34 nindx_cols = size(net.index, 2);
|
wolffd@0
|
35 nmask_rows = size(find(net.mask), 1);
|
wolffd@0
|
36 index = reshape(net.index(logical(repmat(net.mask, ...
|
wolffd@0
|
37 1, nindx_cols))), nmask_rows, nindx_cols);
|
wolffd@0
|
38 else
|
wolffd@0
|
39 index = net.index;
|
wolffd@0
|
40 end
|
wolffd@0
|
41 eprior = 0.5*(w.^2)*index;
|
wolffd@0
|
42 e2 = eprior*net.alpha;
|
wolffd@0
|
43 end
|
wolffd@0
|
44 else
|
wolffd@0
|
45 eprior = 0;
|
wolffd@0
|
46 e2 = 0;
|
wolffd@0
|
47 end
|
wolffd@0
|
48
|
wolffd@0
|
49 e = e1 + e2;
|