comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
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
26 % Copyright (c) Ian T Nabney (1996-2001)
27
28 errstring = consist(net, 'gp', x);
29 if ~isempty(errstring);
30 error(errstring);
31 end
32
33 if ~(isfield(net, 'tr_in') & isfield(net, 'tr_targets'))
34 error('Require training inputs and targets');
35 end
36
37 if nargin == 2
38 % Inverse covariance matrix not supplied.
39 cninv = inv(gpcovar(net, net.tr_in));
40 end
41 ktest = gpcovarp(net, x, net.tr_in);
42
43 % Predict mean
44 y = ktest*cninv*net.tr_targets;
45
46 if nargout >= 2
47 % Predict error bar
48 ndata = size(x, 1);
49 sigsq = (ones(ndata, 1) * gpcovarp(net, x(1,:), x(1,:))) ...
50 - sum((ktest*cninv).*ktest, 2);
51 end