comparison toolboxes/FullBNT-1.0.7/netlab3.3/glmderiv.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 = glmderiv(net, x)
2 %GLMDERIV Evaluate derivatives of GLM outputs with respect to weights.
3 %
4 % Description
5 % G = GLMDERIV(NET, X) takes a network data structure NET and a matrix
6 % of input vectors X and returns a three-index matrix mat{g} whose I,
7 % J, K element contains the derivative of network output K with respect
8 % to weight or bias parameter J for input pattern I. The ordering of
9 % the weight and bias parameters is defined by GLMUNPAK.
10 %
11
12 % Copyright (c) Ian T Nabney (1996-2001)
13
14 % Check arguments for consistency
15 errstring = consist(net, 'glm', x);
16 if ~isempty(errstring)
17 error(errstring);
18 end
19
20 ndata = size(x, 1);
21 if isfield(net, 'mask')
22 nwts = size(find(net.mask), 1);
23 mask_array = logical(net.mask)*ones(1, net.nout);
24 else
25 nwts = net.nwts;
26 end
27 g = zeros(ndata, nwts, net.nout);
28
29 temp = zeros(net.nwts, net.nout);
30 for n = 1:ndata
31 % Weight matrix w1
32 temp(1:(net.nin*net.nout), :) = kron(eye(net.nout), (x(n, :))');
33 % Bias term b1
34 temp(net.nin*net.nout+1:end, :) = eye(net.nout);
35 if isfield(net, 'mask')
36 g(n, :, :) = reshape(temp(find(mask_array)), nwts, net.nout);
37 else
38 g(n, :, :) = temp;
39 end
40 end