wolffd@0: function [g, gdata, gprior] = gbayes(net, gdata) wolffd@0: %GBAYES Evaluate gradient of Bayesian error function for network. wolffd@0: % wolffd@0: % Description wolffd@0: % G = GBAYES(NET, GDATA) takes a network data structure NET together wolffd@0: % the data contribution to the error gradient for a set of inputs and wolffd@0: % targets. It returns the regularised error gradient using any zero wolffd@0: % mean Gaussian priors on the weights defined in NET. In addition, if wolffd@0: % a MASK is defined in NET, then the entries in G that correspond to wolffd@0: % weights with a 0 in the mask are removed. wolffd@0: % wolffd@0: % [G, GDATA, GPRIOR] = GBAYES(NET, GDATA) additionally returns the data wolffd@0: % and prior components of the error. wolffd@0: % wolffd@0: % See also wolffd@0: % ERRBAYES, GLMGRAD, MLPGRAD, RBFGRAD wolffd@0: % wolffd@0: wolffd@0: % Copyright (c) Ian T Nabney (1996-2001) wolffd@0: wolffd@0: % Evaluate the data contribution to the gradient. wolffd@0: if (isfield(net, 'mask')) wolffd@0: gdata = gdata(logical(net.mask)); wolffd@0: end wolffd@0: if isfield(net, 'beta') wolffd@0: g1 = gdata*net.beta; wolffd@0: else wolffd@0: g1 = gdata; wolffd@0: end wolffd@0: wolffd@0: % Evaluate the prior contribution to the gradient. wolffd@0: if isfield(net, 'alpha') wolffd@0: w = netpak(net); wolffd@0: if size(net.alpha) == [1 1] wolffd@0: gprior = w; wolffd@0: g2 = net.alpha*gprior; wolffd@0: else wolffd@0: if (isfield(net, 'mask')) wolffd@0: nindx_cols = size(net.index, 2); wolffd@0: nmask_rows = size(find(net.mask), 1); wolffd@0: index = reshape(net.index(logical(repmat(net.mask, ... wolffd@0: 1, nindx_cols))), nmask_rows, nindx_cols); wolffd@0: else wolffd@0: index = net.index; wolffd@0: end wolffd@0: wolffd@0: ngroups = size(net.alpha, 1); wolffd@0: gprior = index'.*(ones(ngroups, 1)*w); wolffd@0: g2 = net.alpha'*gprior; wolffd@0: end wolffd@0: else wolffd@0: gprior = 0; wolffd@0: g2 = 0; wolffd@0: end wolffd@0: wolffd@0: g = g1 + g2;