You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
Computing the acf of a vector of length T=10^6 (with nlags=100) takes more than 10 minutes on my machine. In addition, it seems impossible to stop the execution before completion (using Ctrl-C).
Looking at the code, I think the problem comes from this line: >> acov = (np.correlate(xo, xo, 'full') / d)[n - 1:]
in function acovf
Correct me if I'm wrong, but this seems to compute the ACF for all the lags 1, ..., T-1, then keeping only the (n-1) first. This means the complexity is O(T^2), whereas computing the ACF at lags 1 to L
should have complexity O(TL). In most practical cases L << T.
Looking at the doc, I can see now that with the fft option I can compute the ACF faster. However, I think
it's problematic that the default implementation would be so inefficient. The acf command in R does not have such an option, and manages to compute and plot the ACF of a vector of length T=10^6 in one second.
I think most examples that we had in mind for acf will not have T >> L. We use explicit loops over lags in some other cases where we expect L to be small.
Never underestimate the ability of users to use your software in crazy ways... :-)
More seriously, I was trying to compute the ACF of MCMC chains https://en.wikipedia.org/wiki/Markov_chain_Monte_Carlo
as reporting the ACF is standard practice in MCMC simulation. In MCMC it is typical to have T = 10^6 - 10^8, and a number of lags L << T. So other MCMC ppl might run into the same issue. (plus also maybe ppl dealing with very long time series like in e.g. finance.)
I was unaware that this was related to some numpy issues: looping over l, as josef-pkt suggests seems quite reasonable to me. At any rate, thanks for looking into this.
Activity
bashtage commentedon Nov 23, 2017
use
fft=Truejosef-pkt commentedon Nov 23, 2017
I think most examples that we had in mind for acf will not have T >> L. We use explicit loops over lags in some other cases where we expect L to be small.
I didn't follow the related recent discussions closely and don't have an overview anymore:
numpy PR to add maxlag option to correlate has stalled numpy/numpy#5978 scipy/scipy#4940 https://mail.python.org/pipermail/numpy-discussion/2016-May/075398.html
In scipy.signal there was also the discussion to combine convolve and fft_convolve with auto option, but I didn't pay attention.
Besides using an explicit loop, it is also possible to adjust the correlate options and padding to limit maxlag, https://github.com/NeuralEnsemble/elephant/blob/master/elephant/spike_train_correlation.py#L535 (link was provided in numpy PR)
nchopin commentedon Nov 23, 2017
Never underestimate the ability of users to use your software in crazy ways... :-)
More seriously, I was trying to compute the ACF of MCMC chains
https://en.wikipedia.org/wiki/Markov_chain_Monte_Carlo
as reporting the ACF is standard practice in MCMC simulation. In MCMC it is typical to have T = 10^6 - 10^8, and a number of lags L << T. So other MCMC ppl might run into the same issue. (plus also maybe ppl dealing with very long time series like in e.g. finance.)
I was unaware that this was related to some numpy issues: looping over l, as josef-pkt suggests seems quite reasonable to me. At any rate, thanks for looking into this.
ENH: Add nlag argument to acovf
ENH: Add nlag argument to acovf
ENH: Add nlag argument to acovf
ENH: Add nlag argument to acovf
ENH: Add nlag argument to acovf