wolffd@0: function g = mlpbkp(net, x, z, deltas) wolffd@0: %MLPBKP Backpropagate gradient of error function for 2-layer network. wolffd@0: % wolffd@0: % Description wolffd@0: % G = MLPBKP(NET, X, Z, DELTAS) takes a network data structure NET wolffd@0: % together with a matrix X of input vectors, a matrix Z of hidden unit wolffd@0: % activations, and a matrix DELTAS of the gradient of the error wolffd@0: % function with respect to the values of the output units (i.e. the wolffd@0: % summed inputs to the output units, before the activation function is wolffd@0: % applied). The return value is the gradient G of the error function wolffd@0: % with respect to the network weights. Each row of X corresponds to one wolffd@0: % input vector. wolffd@0: % wolffd@0: % This function is provided so that the common backpropagation wolffd@0: % algorithm can be used by multi-layer perceptron network models to wolffd@0: % compute gradients for mixture density networks as well as standard wolffd@0: % error functions. wolffd@0: % wolffd@0: % See also wolffd@0: % MLP, MLPGRAD, MLPDERIV, MDNGRAD wolffd@0: % wolffd@0: wolffd@0: % Copyright (c) Ian T Nabney (1996-2001) wolffd@0: wolffd@0: % Evaluate second-layer gradients. wolffd@0: gw2 = z'*deltas; wolffd@0: gb2 = sum(deltas, 1); wolffd@0: wolffd@0: % Now do the backpropagation. wolffd@0: delhid = deltas*net.w2'; wolffd@0: delhid = delhid.*(1.0 - z.*z); wolffd@0: wolffd@0: % Finally, evaluate the first-layer gradients. wolffd@0: gw1 = x'*delhid; wolffd@0: gb1 = sum(delhid, 1); wolffd@0: wolffd@0: g = [gw1(:)', gb1, gw2(:)', gb2];