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

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