Daniel@0: function g = mlpderiv(net, x) Daniel@0: %MLPDERIV Evaluate derivatives of network outputs with respect to weights. Daniel@0: % Daniel@0: % Description Daniel@0: % G = MLPDERIV(NET, X) takes a network data structure NET and a matrix Daniel@0: % of input vectors X and returns a three-index matrix G whose I, J, K Daniel@0: % element contains the derivative of network output K with respect to Daniel@0: % weight or bias parameter J for input pattern I. The ordering of the Daniel@0: % weight and bias parameters is defined by MLPUNPAK. Daniel@0: % Daniel@0: % See also Daniel@0: % MLP, MLPPAK, MLPGRAD, 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); Daniel@0: if ~isempty(errstring); Daniel@0: error(errstring); Daniel@0: end Daniel@0: Daniel@0: [y, z] = mlpfwd(net, x); Daniel@0: Daniel@0: ndata = size(x, 1); Daniel@0: Daniel@0: if isfield(net, 'mask') Daniel@0: nwts = size(find(net.mask), 1); Daniel@0: temp = zeros(1, net.nwts); Daniel@0: else Daniel@0: nwts = net.nwts; Daniel@0: end Daniel@0: Daniel@0: g = zeros(ndata, nwts, net.nout); Daniel@0: for k = 1 : net.nout Daniel@0: delta = zeros(1, net.nout); Daniel@0: delta(1, k) = 1; Daniel@0: for n = 1 : ndata Daniel@0: if isfield(net, 'mask') Daniel@0: temp = mlpbkp(net, x(n, :), z(n, :), delta); Daniel@0: g(n, :, k) = temp(logical(net.mask)); Daniel@0: else Daniel@0: g(n, :, k) = mlpbkp(net, x(n, :), z(n, :),... Daniel@0: delta); Daniel@0: end Daniel@0: end Daniel@0: end