function [G,Z] = repcov(M,N,g) % REPCOV Calculates the intermediate matrix computations for a % covariance function. % % [G,Z] = REPCOV(M,N,g) % % This computes the nominal terms in a covariance function for, % % G = (zi-zj)'*D*(zi-zj) % Z = (zdi-zdj).*(zdi-zdj) % % where D=diag{g1,g2,...,gd} is a diagonal matrix. Z = (zi-zj).^2 in 'd' % sets for different lengthscales and G computers the vector % multiplication of Z'DZ giving a matrix size of N0xN0xD0. % % Inputs: % M = Input explanatory variable of dimension {n1 x d} % N = Input explanatory variable of dimension {n2 x d} % p = Hyperparameters, [a g1 g2 ... gd], D=diag{g1,g2,...,gd} % % Output: % G = Resulting [Z.*Z] % Z = Resulting [Z'*D*Z] % % % (C) Gaussian Process Toolbox 1.0 % (C) Copyright 2005-2007, Keith Neo % http://www.hamilton.ie N0=size(M,1); Nt=size(N,1); Z=(repmat(permute(M,[1,3,2]),[1,Nt,1])-repmat(permute(N',[3,2 1]),[N0,1,1])).^2; G=Z.*repmat(permute(g',[3,2,1]),[N0,Nt,1]);