annotate toolboxes/FullBNT-1.0.7/netlab3.3/rbfbkp.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 = rbfbkp(net, x, z, n2, deltas)
Daniel@0 2 %RBFBKP Backpropagate gradient of error function for RBF network.
Daniel@0 3 %
Daniel@0 4 % Description
Daniel@0 5 % G = RBFBKP(NET, X, Z, N2, DELTAS) takes a network data structure NET
Daniel@0 6 % together with a matrix X of input vectors, a matrix Z of hidden unit
Daniel@0 7 % activations, a matrix N2 of the squared distances between centres and
Daniel@0 8 % inputs, and a matrix DELTAS of the gradient of the error function
Daniel@0 9 % with respect to the values of the output units (i.e. the summed
Daniel@0 10 % inputs to the output units, before the activation function is
Daniel@0 11 % applied). The return value is the gradient G of the error function
Daniel@0 12 % with respect to the network weights. Each row of X corresponds to one
Daniel@0 13 % input vector.
Daniel@0 14 %
Daniel@0 15 % This function is provided so that the common backpropagation
Daniel@0 16 % algorithm can be used by RBF network models to compute gradients for
Daniel@0 17 % the output values (in RBFDERIV) as well as standard error functions.
Daniel@0 18 %
Daniel@0 19 % See also
Daniel@0 20 % RBF, RBFGRAD, RBFDERIV
Daniel@0 21 %
Daniel@0 22
Daniel@0 23 % Copyright (c) Ian T Nabney (1996-2001)
Daniel@0 24
Daniel@0 25 % Evaluate second-layer gradients.
Daniel@0 26 gw2 = z'*deltas;
Daniel@0 27 gb2 = sum(deltas);
Daniel@0 28
Daniel@0 29 % Evaluate hidden unit gradients
Daniel@0 30 delhid = deltas*net.w2';
Daniel@0 31
Daniel@0 32 gc = zeros(net.nhidden, net.nin);
Daniel@0 33 ndata = size(x, 1);
Daniel@0 34 t1 = ones(ndata, 1);
Daniel@0 35 t2 = ones(1, net.nin);
Daniel@0 36 % Switch on activation function type
Daniel@0 37 switch net.actfn
Daniel@0 38
Daniel@0 39 case 'gaussian' % Gaussian
Daniel@0 40 delhid = (delhid.*z);
Daniel@0 41 % A loop seems essential, so do it with the shortest index vector
Daniel@0 42 if (net.nin < net.nhidden)
Daniel@0 43 for i = 1:net.nin
Daniel@0 44 gc(:,i) = (sum(((x(:,i)*ones(1, net.nhidden)) - ...
Daniel@0 45 (ones(ndata, 1)*(net.c(:,i)'))).*delhid, 1)./net.wi)';
Daniel@0 46 end
Daniel@0 47 else
Daniel@0 48 for i = 1:net.nhidden
Daniel@0 49 gc(i,:) = sum((x - (t1*(net.c(i,:)))./net.wi(i)).*(delhid(:,i)*t2), 1);
Daniel@0 50 end
Daniel@0 51 end
Daniel@0 52 gwi = sum((n2.*delhid)./(2.*(ones(ndata, 1)*(net.wi.^2))), 1);
Daniel@0 53
Daniel@0 54 case 'tps' % Thin plate spline activation function
Daniel@0 55 delhid = delhid.*(1+log(n2+(n2==0)));
Daniel@0 56 for i = 1:net.nhidden
Daniel@0 57 gc(i,:) = sum(2.*((t1*(net.c(i,:)) - x)).*(delhid(:,i)*t2), 1);
Daniel@0 58 end
Daniel@0 59 % widths are not adjustable in this model
Daniel@0 60 gwi = [];
Daniel@0 61 case 'r4logr' % r^4 log r activation function
Daniel@0 62 delhid = delhid.*(n2.*(1+2.*log(n2+(n2==0))));
Daniel@0 63 for i = 1:net.nhidden
Daniel@0 64 gc(i,:) = sum(2.*((t1*(net.c(i,:)) - x)).*(delhid(:,i)*t2), 1);
Daniel@0 65 end
Daniel@0 66 % widths are not adjustable in this model
Daniel@0 67 gwi = [];
Daniel@0 68 otherwise
Daniel@0 69 error('Unknown activation function in rbfgrad')
Daniel@0 70 end
Daniel@0 71
Daniel@0 72 g = [gc(:)', gwi, gw2(:)', gb2];