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