wolffd@0: function [e, edata, eprior, y, a] = glmerr_weighted(net, x, t, eso_w) 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-9) 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.actfn wolffd@0: switch net.outfn wolffd@0: wolffd@0: case 'softmax' % Softmax outputs wolffd@0: wolffd@0: nout = size(a,2); wolffd@0: % Ensure that sum(exp(a), 2) does not overflow wolffd@0: maxcut = log(realmax) - log(nout); wolffd@0: % Ensure that exp(a) > 0 wolffd@0: mincut = log(realmin); wolffd@0: a = min(a, maxcut); wolffd@0: a = max(a, mincut); wolffd@0: temp = exp(a); wolffd@0: y = temp./(sum(temp, 2)*ones(1,nout)); wolffd@0: % Ensure that log(y) is computable wolffd@0: y(y