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