annotate toolboxes/FullBNT-1.0.7/netlab3.3/glmgrad.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 [g, gdata, gprior] = glmgrad(net, x, t)
Daniel@0 2 %GLMGRAD Evaluate gradient of error function for generalized linear model.
Daniel@0 3 %
Daniel@0 4 % Description
Daniel@0 5 % G = GLMGRAD(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 gradient G of the error
Daniel@0 8 % function with respect to the network weights. The error function
Daniel@0 9 % corresponds to the choice of output unit activation function. Each
Daniel@0 10 % row of X corresponds to one input vector and each row of T
Daniel@0 11 % corresponds to one target vector.
Daniel@0 12 %
Daniel@0 13 % [G, GDATA, GPRIOR] = GLMGRAD(NET, X, T) also returns separately the
Daniel@0 14 % data and prior contributions to the gradient.
Daniel@0 15 %
Daniel@0 16 % See also
Daniel@0 17 % GLM, GLMPAK, GLMUNPAK, GLMFWD, GLMERR, GLMTRAIN
Daniel@0 18 %
Daniel@0 19
Daniel@0 20 % Copyright (c) Ian T Nabney (1996-2001)
Daniel@0 21
Daniel@0 22 % Check arguments for consistency
Daniel@0 23 errstring = consist(net, 'glm', x, t);
Daniel@0 24 if ~isempty(errstring);
Daniel@0 25 error(errstring);
Daniel@0 26 end
Daniel@0 27
Daniel@0 28 y = glmfwd(net, x);
Daniel@0 29 delout = y - t;
Daniel@0 30
Daniel@0 31 gw1 = x'*delout;
Daniel@0 32 gb1 = sum(delout, 1);
Daniel@0 33
Daniel@0 34 gdata = [gw1(:)', gb1];
Daniel@0 35
Daniel@0 36 [g, gdata, gprior] = gbayes(net, gdata);