wolffd@0: function [e, edata, eprior, y, a] = glmerr(net, x, t) wolffd@0: %GLMERR Evaluate error function for generalized linear model. wolffd@0: % wolffd@0: % Description wolffd@0: % E = GLMERR(NET, X, T) takes a generalized linear model data wolffd@0: % structure NET together with a matrix X of input vectors and a matrix wolffd@0: % T of target vectors, and evaluates the error function E. The choice wolffd@0: % of error function corresponds to the output unit activation function. wolffd@0: % Each row of X corresponds to one input vector and each row of T wolffd@0: % corresponds to one target vector. wolffd@0: % wolffd@0: % [E, EDATA, EPRIOR, Y, A] = GLMERR(NET, X, T) also returns the data wolffd@0: % and prior components of the total error. wolffd@0: % wolffd@0: % [E, EDATA, EPRIOR, Y, A] = GLMERR(NET, X) also returns a matrix Y wolffd@0: % giving the outputs of the models and a matrix A giving the summed wolffd@0: % inputs to each output unit, where each row corresponds to one wolffd@0: % pattern. wolffd@0: % wolffd@0: % See also wolffd@0: % GLM, GLMPAK, GLMUNPAK, GLMFWD, GLMGRAD, GLMTRAIN wolffd@0: % wolffd@0: wolffd@0: % Copyright (c) Ian T Nabney (1996-2001) wolffd@0: wolffd@0: % Check arguments for consistency wolffd@0: errstring = consist(net, 'glm', x, t); wolffd@0: if ~isempty(errstring); wolffd@0: error(errstring); wolffd@0: end wolffd@0: wolffd@0: [y, a] = glmfwd(net, x); wolffd@0: wolffd@0: switch net.outfn wolffd@0: wolffd@0: case 'linear' % Linear outputs wolffd@0: edata = 0.5*sum(sum((y - t).^2)); wolffd@0: wolffd@0: case 'logistic' % Logistic outputs wolffd@0: edata = - sum(sum(t.*log(y) + (1 - t).*log(1 - y))); wolffd@0: wolffd@0: case 'softmax' % Softmax outputs wolffd@0: edata = - sum(sum(t.*log(y))); wolffd@0: wolffd@0: otherwise wolffd@0: error(['Unknown activation function ', net.outfn]); wolffd@0: end wolffd@0: wolffd@0: [e, edata, eprior] = errbayes(net, edata);