필터 지우기
필터 지우기

Optimise creation of matern 3/2 covariance matrix

조회 수: 5 (최근 30일)
snhah
snhah 2020년 4월 16일
답변: darova 2020년 4월 17일
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

답변 (1개)

darova
darova 2020년 4월 17일
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

카테고리

Help CenterFile Exchange에서 Sparse Matrices에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by