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