Repository navigation
ENH: Improve numerical stability of _ar_transparams, _ar_invtransparams - #5569
Conversation
|
Thanks! Would you mind also updating |
I can update that specific part of the code but I don't think @jseabold Can you help? This my proposed change: to |
|
That looks good to me. The code you referenced is a little less clear than it could be, but it seems to be computing the partial autocorrelations just fine, which is what it is intended to do. |
Codecov Report
@@ Coverage Diff @@
## master #5569 +/- ##
==========================================
+ Coverage 82.03% 82.03% +<.01%
==========================================
Files 588 588
Lines 93061 93064 +3
Branches 10317 10317
==========================================
+ Hits 76344 76347 +3
Misses 14355 14355
Partials 2362 2362
Continue to review full report at Codecov.
|
1 similar comment
Codecov Report
@@ Coverage Diff @@
## master #5569 +/- ##
==========================================
+ Coverage 82.03% 82.03% +<.01%
==========================================
Files 588 588
Lines 93061 93064 +3
Branches 10317 10317
==========================================
+ Hits 76344 76347 +3
Misses 14355 14355
Partials 2362 2362
Continue to review full report at Codecov.
|
I can tell you for a fact that |
Can you expand on this? In practice, they seem to work as inverses. import numpy as np
from numpy.testing import assert_allclose
from statsmodels.tsa.tsatools import _ar_transparams, _ar_invtransparams
ar_params = np.r_[0.3, 0.2123, -0.1]
assert_allclose(ar_params, _ar_invtransparams(_ar_transparams(ar_params))) |
|
Here's one of the param inputs I caught while running ARIMA: It seems to be okay for params between 0 and 1 but larger numbers will throw it off Maybe what I'm using is not a valid test scenario? |
|
I see, thanks for the example. After applying ar_params = np.r_[63.07415068, -4.5933353, -6.1342963, -7.82067222, -9.73510476, -12.0269079, -14.95639924]
transformed = _ar_transparams(ar_params.copy())
p = np.polynomial.Polynomial(np.r_[1, -transformed])
print(np.abs(1 / p.roots()))yields: I think probably the issue is that we're losing some precision somewhere. It's not surprising that it pops up in your example, since the transformation is to require the parameters to correspond to a stationary process, while the process that you are fitting is definitely non-stationary. The version of the transformation in the state space library ( |
|
@jcdang Any chance you could implement the other direction and then we can get this merged for the upcoming release? |
|
@bashtage It's implemented already. I didn't write a test for it. Do you want me to add the composed inverse test @ChadFulton gave? |
|
@jcdang Nope, goo to go then. |
(1 - e^-x)/(1 + e^-x) = tanh(x/2)
I modified the code to use numpy's tanh since it doesn't have the issue with large scale numbers.