annotate toolboxes/FullBNT-1.0.7/netlab3.3/glmerr.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 function [e, edata, eprior, y, a] = glmerr(net, x, t)
Daniel@0 2 %GLMERR Evaluate error function for generalized linear model.
Daniel@0 3 %
Daniel@0 4 % Description
Daniel@0 5 % E = GLMERR(NET, X, T) takes a generalized linear model data
Daniel@0 6 % structure NET together with a matrix X of input vectors and a matrix
Daniel@0 7 % T of target vectors, and evaluates the error function E. The choice
Daniel@0 8 % of error function corresponds to the output unit activation function.
Daniel@0 9 % Each row of X corresponds to one input vector and each row of T
Daniel@0 10 % corresponds to one target vector.
Daniel@0 11 %
Daniel@0 12 % [E, EDATA, EPRIOR, Y, A] = GLMERR(NET, X, T) also returns the data
Daniel@0 13 % and prior components of the total error.
Daniel@0 14 %
Daniel@0 15 % [E, EDATA, EPRIOR, Y, A] = GLMERR(NET, X) also returns a matrix Y
Daniel@0 16 % giving the outputs of the models and a matrix A giving the summed
Daniel@0 17 % inputs to each output unit, where each row corresponds to one
Daniel@0 18 % pattern.
Daniel@0 19 %
Daniel@0 20 % See also
Daniel@0 21 % GLM, GLMPAK, GLMUNPAK, GLMFWD, GLMGRAD, GLMTRAIN
Daniel@0 22 %
Daniel@0 23
Daniel@0 24 % Copyright (c) Ian T Nabney (1996-2001)
Daniel@0 25
Daniel@0 26 % Check arguments for consistency
Daniel@0 27 errstring = consist(net, 'glm', x, t);
Daniel@0 28 if ~isempty(errstring);
Daniel@0 29 error(errstring);
Daniel@0 30 end
Daniel@0 31
Daniel@0 32 [y, a] = glmfwd(net, x);
Daniel@0 33
Daniel@0 34 switch net.outfn
Daniel@0 35
Daniel@0 36 case 'linear' % Linear outputs
Daniel@0 37 edata = 0.5*sum(sum((y - t).^2));
Daniel@0 38
Daniel@0 39 case 'logistic' % Logistic outputs
Daniel@0 40 edata = - sum(sum(t.*log(y) + (1 - t).*log(1 - y)));
Daniel@0 41
Daniel@0 42 case 'softmax' % Softmax outputs
Daniel@0 43 edata = - sum(sum(t.*log(y)));
Daniel@0 44
Daniel@0 45 otherwise
Daniel@0 46 error(['Unknown activation function ', net.outfn]);
Daniel@0 47 end
Daniel@0 48
Daniel@0 49 [e, edata, eprior] = errbayes(net, edata);