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