comparison toolboxes/FullBNT-1.0.7/netlab3.3/mlpbkp.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 = mlpbkp(net, x, z, deltas)
2 %MLPBKP Backpropagate gradient of error function for 2-layer network.
3 %
4 % Description
5 % G = MLPBKP(NET, X, Z, DELTAS) takes a network data structure NET
6 % together with a matrix X of input vectors, a matrix Z of hidden unit
7 % activations, and a matrix DELTAS of the gradient of the error
8 % function with respect to the values of the output units (i.e. the
9 % summed inputs to the output units, before the activation function is
10 % applied). The return value is the gradient G of the error function
11 % with respect to the network weights. Each row of X corresponds to one
12 % input vector.
13 %
14 % This function is provided so that the common backpropagation
15 % algorithm can be used by multi-layer perceptron network models to
16 % compute gradients for mixture density networks as well as standard
17 % error functions.
18 %
19 % See also
20 % MLP, MLPGRAD, MLPDERIV, MDNGRAD
21 %
22
23 % Copyright (c) Ian T Nabney (1996-2001)
24
25 % Evaluate second-layer gradients.
26 gw2 = z'*deltas;
27 gb2 = sum(deltas, 1);
28
29 % Now do the backpropagation.
30 delhid = deltas*net.w2';
31 delhid = delhid.*(1.0 - z.*z);
32
33 % Finally, evaluate the first-layer gradients.
34 gw1 = x'*delhid;
35 gb1 = sum(delhid, 1);
36
37 g = [gw1(:)', gb1, gw2(:)', gb2];