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