/netlab3.3/rbfjacob.m

http://pmtksupport.googlecode.com/ · MATLAB · 51 lines · 28 code · 7 blank · 16 comment · 6 complexity · 5f1a12e19f16e1840ad3a6d3996a6921 MD5 · raw file

  1. function jac = rbfjacob(net, x)
  2. %RBFJACOB Evaluate derivatives of RBF network outputs with respect to inputs.
  3. %
  4. % Description
  5. % G = RBFJACOB(NET, X) takes a network data structure NET and a matrix
  6. % of input vectors X and returns a three-index matrix G whose I, J, K
  7. % element contains the derivative of network output K with respect to
  8. % input parameter J for input pattern I.
  9. %
  10. % See also
  11. % RBF, RBFGRAD, RBFBKP
  12. %
  13. % Copyright (c) Ian T Nabney (1996-2001)
  14. % Check arguments for consistency
  15. errstring = consist(net, 'rbf', x);
  16. if ~isempty(errstring);
  17. error(errstring);
  18. end
  19. if ~strcmp(net.outfn, 'linear')
  20. error('Function only implemented for linear outputs')
  21. end
  22. [y, z, n2] = rbffwd(net, x);
  23. ndata = size(x, 1);
  24. jac = zeros(ndata, net.nin, net.nout);
  25. Psi = zeros(net.nin, net.nhidden);
  26. % Calculate derivative of activations wrt n2
  27. switch net.actfn
  28. case 'gaussian'
  29. dz = -z./(ones(ndata, 1)*net.wi);
  30. case 'tps'
  31. dz = 2*(1 + log(n2+(n2==0)));
  32. case 'r4logr'
  33. dz = 2*(n2.*(1+2.*log(n2+(n2==0))));
  34. otherwise
  35. error(['Unknown activation function ', net.actfn]);
  36. end
  37. % Ignore biases as they cannot affect Jacobian
  38. for n = 1:ndata
  39. Psi = (ones(net.nin, 1)*dz(n, :)).* ...
  40. (x(n, :)'*ones(1, net.nhidden) - net.c');
  41. % Now compute the Jacobian
  42. jac(n, :, :) = Psi * net.w2;
  43. end
  44. end