Daniel@0: function [y, sigsq] = gpfwd(net, x, cninv) Daniel@0: %GPFWD Forward propagation through Gaussian Process. Daniel@0: % Daniel@0: % Description Daniel@0: % Y = GPFWD(NET, X) takes a Gaussian Process data structure NET Daniel@0: % together with a matrix X of input vectors, and forward propagates Daniel@0: % the inputs through the model to generate a matrix Y of output Daniel@0: % vectors. Each row of X corresponds to one input vector and each row Daniel@0: % of Y corresponds to one output vector. This assumes that the Daniel@0: % training data (both inputs and targets) has been stored in NET by a Daniel@0: % call to GPINIT; these are needed to compute the training data Daniel@0: % covariance matrix. Daniel@0: % Daniel@0: % [Y, SIGSQ] = GPFWD(NET, X) also generates a column vector SIGSQ of Daniel@0: % conditional variances (or squared error bars) where each value Daniel@0: % corresponds to a pattern. Daniel@0: % Daniel@0: % [Y, SIGSQ] = GPFWD(NET, X, CNINV) uses the pre-computed inverse Daniel@0: % covariance matrix CNINV in the forward propagation. This increases Daniel@0: % efficiency if several calls to GPFWD are made. Daniel@0: % Daniel@0: % See also Daniel@0: % GP, DEMGP, GPINIT Daniel@0: % Daniel@0: Daniel@0: % Copyright (c) Ian T Nabney (1996-2001) Daniel@0: Daniel@0: errstring = consist(net, 'gp', x); Daniel@0: if ~isempty(errstring); Daniel@0: error(errstring); Daniel@0: end Daniel@0: Daniel@0: if ~(isfield(net, 'tr_in') & isfield(net, 'tr_targets')) Daniel@0: error('Require training inputs and targets'); Daniel@0: end Daniel@0: Daniel@0: if nargin == 2 Daniel@0: % Inverse covariance matrix not supplied. Daniel@0: cninv = inv(gpcovar(net, net.tr_in)); Daniel@0: end Daniel@0: ktest = gpcovarp(net, x, net.tr_in); Daniel@0: Daniel@0: % Predict mean Daniel@0: y = ktest*cninv*net.tr_targets; Daniel@0: Daniel@0: if nargout >= 2 Daniel@0: % Predict error bar Daniel@0: ndata = size(x, 1); Daniel@0: sigsq = (ones(ndata, 1) * gpcovarp(net, x(1,:), x(1,:))) ... Daniel@0: - sum((ktest*cninv).*ktest, 2); Daniel@0: end