Daniel@0: function [g, gdata, gprior] = glmgrad(net, x, t) Daniel@0: %GLMGRAD Evaluate gradient of error function for generalized linear model. Daniel@0: % Daniel@0: % Description Daniel@0: % G = GLMGRAD(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 gradient G of the error Daniel@0: % function with respect to the network weights. The error function Daniel@0: % corresponds to the choice of output unit activation function. Each Daniel@0: % row of X corresponds to one input vector and each row of T Daniel@0: % corresponds to one target vector. Daniel@0: % Daniel@0: % [G, GDATA, GPRIOR] = GLMGRAD(NET, X, T) also returns separately the Daniel@0: % data and prior contributions to the gradient. Daniel@0: % Daniel@0: % See also Daniel@0: % GLM, GLMPAK, GLMUNPAK, GLMFWD, GLMERR, GLMTRAIN Daniel@0: % Daniel@0: Daniel@0: % Copyright (c) Ian T Nabney (1996-2001) 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 = glmfwd(net, x); Daniel@0: delout = y - t; Daniel@0: Daniel@0: gw1 = x'*delout; Daniel@0: gb1 = sum(delout, 1); Daniel@0: Daniel@0: gdata = [gw1(:)', gb1]; Daniel@0: Daniel@0: [g, gdata, gprior] = gbayes(net, gdata);