covSEiso.m 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. function K = covSEiso(hyp, x, z, i)
  2. % borrowed from gpml-toolbox of Rasmussen and Nikkisch
  3. % see http://www.gaussianprocess.org/gpml/code/matlab/doc/
  4. % Squared Exponential covariance function with isotropic distance measure. The
  5. % covariance function is parameterized as:
  6. %
  7. % k(x^p,x^q) = sf^2 * exp(-(x^p - x^q)'*inv(P)*(x^p - x^q)/2)
  8. %
  9. % where the P matrix is ell^2 times the unit matrix and sf^2 is the signal
  10. % variance. The hyperparameters are:
  11. %
  12. % hyp = [ log(ell)
  13. % log(sf) ]
  14. %
  15. % For more help on design of covariance functions, try "help covFunctions".
  16. %
  17. % Copyright (c) by Carl Edward Rasmussen and Hannes Nickisch, 2010-09-10.
  18. %
  19. % See also COVFUNCTIONS.M.
  20. if nargin<2, K = '2'; return; end % report number of parameters
  21. if nargin<3, z = []; end % make sure, z exists
  22. xeqz = numel(z)==0; dg = strcmp(z,'diag') && numel(z)>0; % determine mode
  23. ell = exp(hyp(1)); % characteristic length scale
  24. sf2 = exp(2*hyp(2)); % signal variance
  25. % precompute squared distances
  26. if dg % vector kxx
  27. K = zeros(size(x,1),1);
  28. else
  29. if xeqz % symmetric matrix Kxx
  30. K = sq_dist(x'/ell);
  31. else % cross covariances Kxz
  32. K = sq_dist(x'/ell,z'/ell);
  33. end
  34. end
  35. if nargin<4 % covariances
  36. K = sf2*exp(-K/2);
  37. else % derivatives
  38. if i==1
  39. K = sf2*exp(-K/2).*K;
  40. elseif i==2
  41. K = 2*sf2*exp(-K/2);
  42. else
  43. error('Unknown hyperparameter')
  44. end
  45. end