Repository navigation
ENH: analytic version of arma_acovf - #5324
Conversation
Codecov Report
@@ Coverage Diff @@
## master #5324 +/- ##
==========================================
+ Coverage 81.72% 81.72% +<.01%
==========================================
Files 569 569
Lines 89712 89735 +23
Branches 10019 10017 -2
==========================================
+ Hits 73317 73339 +22
Misses 14126 14126
- Partials 2269 2270 +1
Continue to review full report at Codecov.
|
|
Green, but I will push up one more doc change w/ squashing, and then wait until tomorrow to merge in case anyone has thoughts / improvements / concerns. |
f89654d to
78e375b
Compare
|
I’ll give this a review in the next day or so. |
|
Do you have an example where the new implementation outperforms (in speed or accuracy or ...) the old one? |
|
My old version makes a detour via a infinite series that needs truncation, so there is a truncation error if the truncation happens too soon, or wasteful computation if truncation leaves a large number of terms. |
|
I'm not sure anymore whether there is a truncation error for acovf at small lags This looks similar to the forecast variance on the mailing list (except for the missing cumsum?), and it should be possible to compute the forecast covariance at different horizons/steps to get the joint distribution and a simultaneous confidence interval. Computationally the new version is better and LGTM, |
| assert_almost_equal(rep1, rep2, 8) # 8 is max precision here | ||
| assert_allclose(rep1, rep2) | ||
|
|
||
| # Test other cases, against R's ARMAacf |
There was a problem hiding this comment.
| # Test other cases, against R's ARMAacf | |
| def test_arma_acf_compare_R_ARMAacf(): | |
| # Test other cases, against R's ARMAacf; GH#5324 |
There was a problem hiding this comment.
Why the reference to the github PR?
There was a problem hiding this comment.
Habit. Avoids the need to look up git history.
| assert_almost_equal(ac1, ac2, decimal=7, | ||
| err_msg='acovf not equal for %s, %s' % (ar, ma)) | ||
| assert_allclose(ac1, ac2, atol=1e-15, | ||
| err_msg='acovf not equal for %s, %s' % (ar, ma)) |
There was a problem hiding this comment.
Are the actual values of ac1 and ac2 big enough that atol=1e-15 is decently tight?
There was a problem hiding this comment.
Without setting atol we have:
E AssertionError:
E Not equal to tolerance rtol=1e-07, atol=0
E acovf not equal for [1.0], [1, 0.9]
E (mismatch 80.0%)
E x: array([ 1.810000e+00, 9.000000e-01, -1.581012e-18, 1.073360e-17,
E 6.474231e-18, 2.394510e-18, 1.061885e-17, -2.302974e-18,
E 3.987144e-19, -1.813615e-18])
E y: array([1.81, 0.9 , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ])
so I think it's fine - basically we just need to drop numerical noise for comparison to exact zero.
| @@ -155,8 +173,8 @@ def test_armafft(): | |||
| arma = ArmaFft(ar, ma, 20) | |||
There was a problem hiding this comment.
This test should be parametrized
| assert_equal(res.ndim, 1) | ||
| assert_allclose(res, expected, atol=1e-6) | ||
| # atol=7 breaks at .999, worked at .995 | ||
| assert_allclose(res, expected) |
There was a problem hiding this comment.
Does the change in this PR improve the match? (i.e. the resolve the comment above)
There was a problem hiding this comment.
Yes, all of the precision improvements are due to the analytic compuation.
| nobs : int | ||
| number of terms (lags plus zero lag) to include in returned acovf | ||
| sigma2 : float | ||
| Variance of the innovation term. |
There was a problem hiding this comment.
require strictly positive?
| # Custom example 7 | ||
| ar_params = c(1, -0.25, 0.1, -0.05, 0.02) | ||
| ma_params = c(1, 0.2) | ||
| print(ARMAacf(ar_params, ma_params, lag.max=9)) |
There was a problem hiding this comment.
Is there a manual step to create results/arma_acov_results.py from the output of this script? Can that step be automated?
There was a problem hiding this comment.
It could surely be automated, but I'm not sure if it's worth it?
There was a problem hiding this comment.
Don’t bother; only if there were an obvious way to do it.
| @@ -0,0 +1,43 @@ | |||
| bd_example_3_3_2 = [ | |||
There was a problem hiding this comment.
Comment describing where these numbers come from, how to reproduce
|
I also forgot to mention that an alternative to this PR is to keep both approaches around in some form, so if that's preferable let me know. |
|
I thought about adding a (If there is interest, then parking the simplified old version in an example or test case could be useful just for documenting the theoretical relationship. Sometimes I like to keep an in most cases computationally inferior version around just as documentation or for quick experiments, but this is not really my area anymore.) |
|
Thanks for the review @jbrockmendel and the comments @josef-pkt. |
This is a good idea, I will make a test case that uses it. Thanks! |
|
Green as it gets right now (it looks like some deprecation warnings about |
|
|
||
| References | ||
| ---------- | ||
| Brockwell, Peter J., and Richard A. Davis. 2009. |
There was a problem hiding this comment.
Too late now, but ideally would be in rst reference style .. [*] Brockwell...
Updates
arima_process.arma_acovfto compute the autocovariances using the analytical approach of Brockwell and Davis (1991).mostsome cases, much faster in cases with high persistence