Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/netlab3.3/gbayes.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 [g, gdata, gprior] = gbayes(net, gdata) | |
2 %GBAYES Evaluate gradient of Bayesian error function for network. | |
3 % | |
4 % Description | |
5 % G = GBAYES(NET, GDATA) takes a network data structure NET together | |
6 % the data contribution to the error gradient for a set of inputs and | |
7 % targets. It returns the regularised error gradient using any zero | |
8 % mean Gaussian priors on the weights defined in NET. In addition, if | |
9 % a MASK is defined in NET, then the entries in G that correspond to | |
10 % weights with a 0 in the mask are removed. | |
11 % | |
12 % [G, GDATA, GPRIOR] = GBAYES(NET, GDATA) additionally returns the data | |
13 % and prior components of the error. | |
14 % | |
15 % See also | |
16 % ERRBAYES, GLMGRAD, MLPGRAD, RBFGRAD | |
17 % | |
18 | |
19 % Copyright (c) Ian T Nabney (1996-2001) | |
20 | |
21 % Evaluate the data contribution to the gradient. | |
22 if (isfield(net, 'mask')) | |
23 gdata = gdata(logical(net.mask)); | |
24 end | |
25 if isfield(net, 'beta') | |
26 g1 = gdata*net.beta; | |
27 else | |
28 g1 = gdata; | |
29 end | |
30 | |
31 % Evaluate the prior contribution to the gradient. | |
32 if isfield(net, 'alpha') | |
33 w = netpak(net); | |
34 if size(net.alpha) == [1 1] | |
35 gprior = w; | |
36 g2 = net.alpha*gprior; | |
37 else | |
38 if (isfield(net, 'mask')) | |
39 nindx_cols = size(net.index, 2); | |
40 nmask_rows = size(find(net.mask), 1); | |
41 index = reshape(net.index(logical(repmat(net.mask, ... | |
42 1, nindx_cols))), nmask_rows, nindx_cols); | |
43 else | |
44 index = net.index; | |
45 end | |
46 | |
47 ngroups = size(net.alpha, 1); | |
48 gprior = index'.*(ones(ngroups, 1)*w); | |
49 g2 = net.alpha'*gprior; | |
50 end | |
51 else | |
52 gprior = 0; | |
53 g2 = 0; | |
54 end | |
55 | |
56 g = g1 + g2; |