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