annotate toolboxes/FullBNT-1.0.7/netlab3.3/gpcovarf.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 covf = gpcovarf(net, x1, x2)
wolffd@0 2 %GPCOVARF Calculate the covariance function for a Gaussian Process.
wolffd@0 3 %
wolffd@0 4 % Description
wolffd@0 5 %
wolffd@0 6 % COVF = GPCOVARF(NET, X1, X2) takes a Gaussian Process data structure
wolffd@0 7 % NET together with two matrices X1 and X2 of input vectors, and
wolffd@0 8 % computes the matrix of the covariance function values COVF.
wolffd@0 9 %
wolffd@0 10 % See also
wolffd@0 11 % GP, GPCOVAR, GPCOVARP, GPERR, GPGRAD
wolffd@0 12 %
wolffd@0 13
wolffd@0 14 % Copyright (c) Ian T Nabney (1996-2001)
wolffd@0 15
wolffd@0 16 errstring = consist(net, 'gp', x1);
wolffd@0 17 if ~isempty(errstring);
wolffd@0 18 error(errstring);
wolffd@0 19 end
wolffd@0 20
wolffd@0 21 if size(x1, 2) ~= size(x2, 2)
wolffd@0 22 error('Number of variables in x1 and x2 must be the same');
wolffd@0 23 end
wolffd@0 24
wolffd@0 25 n1 = size(x1, 1);
wolffd@0 26 n2 = size(x2, 1);
wolffd@0 27 beta = diag(exp(net.inweights));
wolffd@0 28
wolffd@0 29 % Compute the weighted squared distances between x1 and x2
wolffd@0 30 z = (x1.*x1)*beta*ones(net.nin, n2) - 2*x1*beta*x2' ...
wolffd@0 31 + ones(n1, net.nin)*beta*(x2.*x2)';
wolffd@0 32
wolffd@0 33 switch net.covar_fn
wolffd@0 34
wolffd@0 35 case 'sqexp' % Squared exponential
wolffd@0 36 covf = exp(net.fpar(1) - 0.5*z);
wolffd@0 37
wolffd@0 38 case 'ratquad' % Rational quadratic
wolffd@0 39 nu = exp(net.fpar(2));
wolffd@0 40 covf = exp(net.fpar(1))*((ones(size(z)) + z).^(-nu));
wolffd@0 41
wolffd@0 42 otherwise
wolffd@0 43 error(['Unknown covariance function ', net.covar_fn]);
wolffd@0 44 end