Efficient evaluation of Auto Regressive Covariance matrix

1 次查看(过去 30 天)
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

回答(1 个)

Shubham Rawat
Shubham Rawat 2020-8-24
编辑:Shubham Rawat 2020-8-25
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

类别

Help CenterFile Exchange 中查找有关 Conditional Mean Models 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by