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