Efficient evaluation of Auto Regressive Covariance matrix

1 visualización (últimos 30 días)
Sebastiano Piccolroaz
Sebastiano Piccolroaz el 9 de Jul. de 2020
Editada: Shubham Rawat el 25 de Ag. de 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

Respuestas (1)

Shubham Rawat
Shubham Rawat el 24 de Ag. de 2020
Editada: Shubham Rawat el 25 de Ag. de 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

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by