/netlab3.3/gpfwd.m

http://pmtksupport.googlecode.com/ · MATLAB · 53 lines · 19 code · 7 blank · 27 comment · 4 complexity · 0584f5e5d2bf702686b11ad18ac362c7 MD5 · raw file

  1. function [y, sigsq] = gpfwd(net, x, cninv)
  2. %GPFWD Forward propagation through Gaussian Process.
  3. %
  4. % Description
  5. % Y = GPFWD(NET, X) takes a Gaussian Process data structure NET
  6. % together with a matrix X of input vectors, and forward propagates
  7. % the inputs through the model to generate a matrix Y of output
  8. % vectors. Each row of X corresponds to one input vector and each row
  9. % of Y corresponds to one output vector. This assumes that the
  10. % training data (both inputs and targets) has been stored in NET by a
  11. % call to GPINIT; these are needed to compute the training data
  12. % covariance matrix.
  13. %
  14. % [Y, SIGSQ] = GPFWD(NET, X) also generates a column vector SIGSQ of
  15. % conditional variances (or squared error bars) where each value
  16. % corresponds to a pattern.
  17. %
  18. % [Y, SIGSQ] = GPFWD(NET, X, CNINV) uses the pre-computed inverse
  19. % covariance matrix CNINV in the forward propagation. This increases
  20. % efficiency if several calls to GPFWD are made.
  21. %
  22. % See also
  23. % GP, DEMGP, GPINIT
  24. %
  25. % Copyright (c) Ian T Nabney (1996-2001)
  26. errstring = consist(net, 'gp', x);
  27. if ~isempty(errstring);
  28. error(errstring);
  29. end
  30. if ~(isfield(net, 'tr_in') & isfield(net, 'tr_targets'))
  31. error('Require training inputs and targets');
  32. end
  33. if nargin == 2
  34. % Inverse covariance matrix not supplied.
  35. cninv = inv(gpcovar(net, net.tr_in));
  36. end
  37. ktest = gpcovarp(net, x, net.tr_in);
  38. % Predict mean
  39. y = ktest*cninv*net.tr_targets;
  40. if nargout >= 2
  41. % Predict error bar
  42. ndata = size(x, 1);
  43. sigsq = (ones(ndata, 1) * gpcovarp(net, x(1,:), x(1,:))) ...
  44. - sum((ktest*cninv).*ktest, 2);
  45. end
  46. end