wolffd@0: function [g, gdata, gprior] = rbfgrad(net, x, t) wolffd@0: %RBFGRAD Evaluate gradient of error function for RBF network. wolffd@0: % wolffd@0: % Description wolffd@0: % G = RBFGRAD(NET, X, T) takes a network data structure NET together wolffd@0: % with a matrix X of input vectors and a matrix T of target vectors, wolffd@0: % and evaluates the gradient G of the error function with respect to wolffd@0: % the network weights (i.e. including the hidden unit parameters). The wolffd@0: % error function is sum of squares. Each row of X corresponds to one wolffd@0: % input vector and each row of T contains the corresponding target wolffd@0: % vector. If the output function is 'NEUROSCALE' then the gradient is wolffd@0: % only computed for the output layer weights and biases. wolffd@0: % wolffd@0: % [G, GDATA, GPRIOR] = RBFGRAD(NET, X, T) also returns separately the wolffd@0: % data and prior contributions to the gradient. In the case of multiple wolffd@0: % groups in the prior, GPRIOR is a matrix with a row for each group and wolffd@0: % a column for each weight parameter. wolffd@0: % wolffd@0: % See also wolffd@0: % RBF, RBFFWD, RBFERR, RBFPAK, RBFUNPAK, RBFBKP wolffd@0: % wolffd@0: wolffd@0: % Copyright (c) Ian T Nabney (1996-2001) wolffd@0: wolffd@0: % Check arguments for consistency wolffd@0: switch net.outfn wolffd@0: case 'linear' wolffd@0: errstring = consist(net, 'rbf', x, t); wolffd@0: case 'neuroscale' wolffd@0: errstring = consist(net, 'rbf', x); wolffd@0: otherwise wolffd@0: error(['Unknown output function ', net.outfn]); wolffd@0: end wolffd@0: if ~isempty(errstring); wolffd@0: error(errstring); wolffd@0: end wolffd@0: wolffd@0: ndata = size(x, 1); wolffd@0: wolffd@0: [y, z, n2] = rbffwd(net, x); wolffd@0: wolffd@0: switch net.outfn wolffd@0: case 'linear' wolffd@0: wolffd@0: % Sum squared error at output units wolffd@0: delout = y - t; wolffd@0: wolffd@0: gdata = rbfbkp(net, x, z, n2, delout); wolffd@0: [g, gdata, gprior] = gbayes(net, gdata); wolffd@0: wolffd@0: case 'neuroscale' wolffd@0: % Compute the error gradient with respect to outputs wolffd@0: y_dist = sqrt(dist2(y, y)); wolffd@0: D = (t - y_dist)./(y_dist+diag(ones(ndata, 1))); wolffd@0: temp = y'; wolffd@0: gradient = 2.*sum(kron(D, ones(1, net.nout)) .* ... wolffd@0: (repmat(y, 1, ndata) - repmat((temp(:))', ndata, 1)), 1); wolffd@0: gradient = (reshape(gradient, net.nout, ndata))'; wolffd@0: % Compute the error gradient wolffd@0: gdata = rbfbkp(net, x, z, n2, gradient); wolffd@0: [g, gdata, gprior] = gbayes(net, gdata); wolffd@0: otherwise wolffd@0: error(['Unknown output function ', net.outfn]); wolffd@0: end wolffd@0: