Efficient evaluation of Auto Regressive Covariance matrix

1 vue (au cours des 30 derniers jours)
Sebastiano Piccolroaz
Sebastiano Piccolroaz le 9 Juil 2020
Modifié(e) : Shubham Rawat le 25 Août 2020
I need to improve the calculation of the following Covariance matrix (C), where p is the order of an autoregressive model and x(istart:istop) is the time series for which I would like to have C:
for i=0:p
for j=0:i
sum_=0;
for t=p+istart:istop
sum_ = sum_ + x(t-i)*x(t-j);
end
C(i+1,j+1)=sum_;
end
end

Réponses (1)

Shubham Rawat
Shubham Rawat le 24 Août 2020
Modifié(e) : Shubham Rawat le 25 Août 2020
Hi Sebastiano,
You can do the following things to evaluate efficiently,
  • You can pre-initialize the Covariance(C) matrix by zeros or ones.
C = zeros(p+1,p+1);
  • You can Vectorize the code for specific tasks.
t = p+istart:istop;
cumulative_sum = cumsum(x(t-i).*x(t-j));
sum_ = cumulative_sum(last_element);
  • You can also parallelize the for loop by using parfor.
parfor t = p+istart:istop

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by