wolffd@0: function [e, edata, eprior] = errbayes(net, edata) wolffd@0: %ERRBAYES Evaluate Bayesian error function for network. wolffd@0: % wolffd@0: % Description wolffd@0: % E = ERRBAYES(NET, EDATA) takes a network data structure NET together wolffd@0: % the data contribution to the error for a set of inputs and targets. wolffd@0: % It returns the regularised error using any zero mean Gaussian priors wolffd@0: % on the weights defined in NET. wolffd@0: % wolffd@0: % [E, EDATA, EPRIOR] = ERRBAYES(NET, X, T) additionally returns the wolffd@0: % data and prior components of the error. wolffd@0: % wolffd@0: % See also wolffd@0: % GLMERR, MLPERR, RBFERR wolffd@0: % wolffd@0: wolffd@0: % Copyright (c) Ian T Nabney (1996-2001) wolffd@0: wolffd@0: % Evaluate the data contribution to the error. wolffd@0: if isfield(net, 'beta') wolffd@0: e1 = net.beta*edata; wolffd@0: else wolffd@0: e1 = edata; wolffd@0: end wolffd@0: wolffd@0: % Evaluate the prior contribution to the error. wolffd@0: if isfield(net, 'alpha') wolffd@0: w = netpak(net); wolffd@0: if size(net.alpha) == [1 1] wolffd@0: eprior = 0.5*(w*w'); wolffd@0: e2 = eprior*net.alpha; 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: eprior = 0.5*(w.^2)*index; wolffd@0: e2 = eprior*net.alpha; wolffd@0: end wolffd@0: else wolffd@0: eprior = 0; wolffd@0: e2 = 0; wolffd@0: end wolffd@0: wolffd@0: e = e1 + e2;