annotate toolboxes/FullBNT-1.0.7/netlab3.3/gpfwd.m @ 0:e9a9cd732c1e tip

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