comparison toolboxes/FullBNT-1.0.7/netlabKPM/glmgrad_weighted.m @ 0:e9a9cd732c1e tip

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