Daniel@0: function [e, edata, eprior, y, a] = glmerr_weighted(net, x, t, eso_w) Daniel@0: %GLMERR Evaluate error function for generalized linear model. Daniel@0: % Daniel@0: % Description Daniel@0: % E = GLMERR(NET, X, T) takes a generalized linear model data Daniel@0: % structure NET together with a matrix X of input vectors and a matrix Daniel@0: % T of target vectors, and evaluates the error function E. The choice Daniel@0: % of error function corresponds to the output unit activation function. Daniel@0: % Each row of X corresponds to one input vector and each row of T Daniel@0: % corresponds to one target vector. Daniel@0: % Daniel@0: % [E, EDATA, EPRIOR, Y, A] = GLMERR(NET, X, T) also returns the data Daniel@0: % and prior components of the total error. Daniel@0: % Daniel@0: % [E, EDATA, EPRIOR, Y, A] = GLMERR(NET, X) also returns a matrix Y Daniel@0: % giving the outputs of the models and a matrix A giving the summed Daniel@0: % inputs to each output unit, where each row corresponds to one Daniel@0: % pattern. Daniel@0: % Daniel@0: % See also Daniel@0: % GLM, GLMPAK, GLMUNPAK, GLMFWD, GLMGRAD, GLMTRAIN Daniel@0: % Daniel@0: Daniel@0: % Copyright (c) Ian T Nabney (1996-9) Daniel@0: Daniel@0: % Check arguments for consistency Daniel@0: errstring = consist(net, 'glm', x, t); Daniel@0: if ~isempty(errstring); Daniel@0: error(errstring); Daniel@0: end Daniel@0: Daniel@0: [y, a] = glmfwd(net, x); Daniel@0: Daniel@0: %switch net.actfn Daniel@0: switch net.outfn Daniel@0: Daniel@0: case 'softmax' % Softmax outputs Daniel@0: Daniel@0: nout = size(a,2); Daniel@0: % Ensure that sum(exp(a), 2) does not overflow Daniel@0: maxcut = log(realmax) - log(nout); Daniel@0: % Ensure that exp(a) > 0 Daniel@0: mincut = log(realmin); Daniel@0: a = min(a, maxcut); Daniel@0: a = max(a, mincut); Daniel@0: temp = exp(a); Daniel@0: y = temp./(sum(temp, 2)*ones(1,nout)); Daniel@0: % Ensure that log(y) is computable Daniel@0: y(y