Borrar filtros
Borrar filtros

Optimise creation of matern 3/2 covariance matrix

5 visualizaciones (últimos 30 días)
snhah
snhah el 16 de Abr. de 2020
Respondida: darova el 17 de Abr. de 2020
I'm making a function to create a Matern 3/2 covariance matrix (see below). The size of the matrix varies but is typically with n >= 1e5. My attempt currently takes very long.
How can I increase the performance of this code?
function K = matern32(n,tau)
% Function creates n x n matern covariance matrix
K = sparse(n,n);
eps = 1e-9;
for i = 1:n
for j = 1:n
K(i,j) = (1+sqrt(3)*abs(i-j)/tau)*exp(-sqrt(3)*abs(i-j)/tau);
if K(i,j) < eps
K(i,j) = 0;
end
end
end
end

Respuestas (1)

darova
darova el 17 de Abr. de 2020
Try this
[X,Y] = meshgrid(1:n);
K = (1+sqrt(3)*abs(X-Y)/tau).*exp(-sqrt(3)*abs(X-Y)/tau);
K = (K>1e-9).*K;
read this

Categorías

Más información sobre Sparse Matrices en Help Center y File Exchange.

Productos


Versión

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by