Daniel@0: function [g, gdata, gprior] = mlpgrad(net, x, t) Daniel@0: %MLPGRAD Evaluate gradient of error function for 2-layer network. Daniel@0: % Daniel@0: % Description Daniel@0: % G = MLPGRAD(NET, X, T) takes a network data structure NET together Daniel@0: % with a matrix X of input vectors and a matrix T of target vectors, Daniel@0: % and evaluates the gradient G of the error function with respect to Daniel@0: % the network weights. The error funcion corresponds to the choice of Daniel@0: % output unit activation function. Each row of X corresponds to one Daniel@0: % input vector and each row of T corresponds to one target vector. Daniel@0: % Daniel@0: % [G, GDATA, GPRIOR] = MLPGRAD(NET, X, T) also returns separately the Daniel@0: % data and prior contributions to the gradient. In the case of multiple Daniel@0: % groups in the prior, GPRIOR is a matrix with a row for each group and Daniel@0: % a column for each weight parameter. Daniel@0: % Daniel@0: % See also Daniel@0: % MLP, MLPPAK, MLPUNPAK, MLPFWD, MLPERR, MLPBKP Daniel@0: % Daniel@0: Daniel@0: % Copyright (c) Ian T Nabney (1996-2001) Daniel@0: Daniel@0: % Check arguments for consistency Daniel@0: errstring = consist(net, 'mlp', x, t); Daniel@0: if ~isempty(errstring); Daniel@0: error(errstring); Daniel@0: end Daniel@0: [y, z] = mlpfwd(net, x); Daniel@0: delout = y - t; Daniel@0: Daniel@0: gdata = mlpbkp(net, x, z, delout); Daniel@0: Daniel@0: [g, gdata, gprior] = gbayes(net, gdata);