Skip to content

ENH: Add new method to generate starting params - #3084

Merged
josef-pkt merged 3 commits into
statsmodels:masterfrom
bashtage:chelleych-arima_longar_start_params
Jul 8, 2016
Merged

josef-pkt merged 3 commits into
statsmodels:masterfrom
bashtage:chelleych-arima_longar_start_params

Conversation

@bashtage

Copy link
Copy Markdown
Member

Added ability to use the long AR method in fitting ARIMA start_params
Improved tests. Fixed case where longar_maxlag is greater than length of
series
Changed longar_start_params variable name to start_ar_lags

closes #2550

@coveralls

coveralls commented Jun 28, 2016 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.003%) to 88.814% when pulling d2ed8c7 on bashtage:chelleych-arima_longar_start_params into 032a9ab on statsmodels:master.

mod.fit(disp=0, start_params=[np.mean(y), .1, .1, .1])
assert_equal(mod.exog_names, ['const', 'ar.L1.y', 'ma.L1.y', 'ma.L2.y'])
with warnings.catch_warnings(record=True) as w:
mod.fit(disp=0, start_params=[np.mean(y), .1, .1, .1])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this not raise a warning anymore?
Do you have an idea what changed?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The warning doesn't show up in the test run. But I don't know if there is no warning anymore, or whether it is not set to always warn

@josef-pkt

Copy link
Copy Markdown
Member

I think it's better if we merge this (after fixing some details). It doesn't fix all the problems with the underlying code, but at least gives the option to work around some of them.

@chelleych

Added ability to use the long AR method in fitting ARIMA start_params
Improved tests. Fixed case where longar_maxlag is greater than length of
series
Changed longar_start_params variable name to start_ar_lags

closes statsmodels#2550
@bashtage
bashtage force-pushed the chelleych-arima_longar_start_params branch from d2ed8c7 to 1854d86 Compare July 4, 2016 13:42
the Results object's mle_retvals attribute. Output is dependent
on the solver. See Notes for more information.
disp : bool, optional
disp : int, optional

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was raising a warning in PyCharm since it was incorrectly labeled as bool

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My guess is that this depends on the scipy optimizer, but lbfgsb has numeric options.

@bashtage

bashtage commented Jul 4, 2016

Copy link
Copy Markdown
Member Author

No warnings are issued. I have no idea why those were there. In general one should always check the error is raised when catching warnings.

@bashtage
bashtage force-pushed the chelleych-arima_longar_start_params branch from 1854d86 to 3250892 Compare July 4, 2016 14:21
@coveralls

coveralls commented Jul 4, 2016 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.003%) to 88.814% when pulling 3250892 on bashtage:chelleych-arima_longar_start_params into c5b2f2e on statsmodels:master.

@bashtage

bashtage commented Jul 4, 2016

Copy link
Copy Markdown
Member Author

Recent Pythons get an error

statsmodels.tsa.tests.test_arima.test_arima_fit_mutliple_calls ... /home/travis/miniconda2/envs/statsmodels-test/lib/python3.4/site-packages/statsmodels-0.8.0-py3.4-linux-x86_64.egg/statsmodels/base/model.py:452: RuntimeWarning: Inverting hessian failed, no bse or cov_params available
  warn(warndoc, RuntimeWarning)
ok

Comment thread statsmodels/tsa/arima_model.py Outdated
exog = np.asarray(exog)
if self.k_exog == 1 and exog.ndim == 1:
exog = exog[:, None]
# we need the last k_ar exog for the lag-polynomial

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this part here is redundant/duplicate. It is now included in the lines just above under if exog is not None

@josef-pkt

Copy link
Copy Markdown
Member

Given that python 3.4 shows the warning, the catch_warning needs to stay in the unit tests.

@bashtage
bashtage force-pushed the chelleych-arima_longar_start_params branch 4 times, most recently from cc7a44c to 16f8890 Compare July 4, 2016 22:59
@bashtage

bashtage commented Jul 4, 2016

Copy link
Copy Markdown
Member Author

Hinv = np.linalg.inv(-1 * self.hessian(xopt))

Is not correct. There are many models in the test suite that have indefinite Hessians. This code will only show problems is an eigenvalue is very lose to 0, but when there are both + and - eigenvalues inv "work".

See

https://travis-ci.org/bashtage/statsmodels/jobs/142324299

for all of the tests that have been incorrectly using indefinite Hessians.

@bashtage

bashtage commented Jul 4, 2016

Copy link
Copy Markdown
Member Author

To understand

statsmodels.base.tests.test_generic_methods.TestGenericNegativeBinomial.test_ttest_tvalues ... 0.999913988078 -0.94096264686

The numbers printing are the maximum and minimum eigenvalue of Hinv

@josef-pkt

Copy link
Copy Markdown
Member

I'm not sure I understand.

First rebasing, amending or squashing during review makes it very difficult to follow what's going on.
https://mail.python.org/pipermail/scikit-learn/2016-June/000121.html

About Hessian with negative eigenvalues:
AFAICS, this is a separate, new issue that is not directly related to the adding the start_params option to ARIMA.
Given the number of test errors the raise on negative eigenvalue causes, it will take some time to look at the incorrect hessian cases.
However, many test cases like test_arima_fit_mutliple_calls don't need or use a valid hessian because they just test some specific feature or run a regression test for a specific item. (ARMA(1, 2) with 5 observations)
I have seen hessian with negative eigenvalues in some cases, but didn't realize that we have them pretty widespread in the test suite. This definitely needs a new issue and some design decisions.

@bashtage

bashtage commented Jul 5, 2016

Copy link
Copy Markdown
Member Author

First rebasing, amending or squashing during review makes it very difficult to follow what's going on.

I don't like writing commit messages.

@bashtage
bashtage force-pushed the chelleych-arima_longar_start_params branch from 16f8890 to 9cbc0e0 Compare July 5, 2016 07:31
@bashtage

bashtage commented Jul 5, 2016

Copy link
Copy Markdown
Member Author

Back to passing, but ignoring the big issue.

If an explicit eigenvalue check is put in when convputing the inverse Hessian, there are many examples that have indefinite Hessians.

                _, v = np.linalg.eig(-1 * self.hessian(xopt))
                if np.min(v) < 0.0:
                    print(np.max(v), np.min(v))
                    raise RuntimeError

@bashtage

bashtage commented Jul 5, 2016

Copy link
Copy Markdown
Member Author

The bigger issue is that warning catchers should not be allowed unless the source of the warning is fully understood and the warning is fully reproducible across platforms.

If the warning differs depending on other modules (e.g. NumPy) then there should be a compat fix to unify the behavior.

@josef-pkt

Copy link
Copy Markdown
Member

roughly: It takes a few seconds to write a commit message, and half an hour for a reviewer to figure out what changed.

(I'm also amending commits and force pushing, but not during review. Which is an empty statement because I usually don't get reviews.)

@coveralls

coveralls commented Jul 5, 2016 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.003%) to 88.814% when pulling 9cbc0e0 on bashtage:chelleych-arima_longar_start_params into c5b2f2e on statsmodels:master.

@josef-pkt

Copy link
Copy Markdown
Member

The bigger issue is that warning catchers should not be allowed unless the source of the warning is fully understood and the warning is fully reproducible across platforms.
If the warning differs depending on other modules (e.g. NumPy) then there should be a compat fix to unify the behavior.

open new issues with what should be changed so it doesn't get lost in PR discussion.

Right now we have no guarantee about consistent behavior in corner cases across machines, operating system, linalg libraries or versions of dependencies. For example, scipy optimizers change all the time, sometimes it handles a case better, sometimes worse. Differences in BLAS/LAPACK libraries can have quite large effects in edge cases.
The only thing that is currently guaranteed by our test suite are the numerical results, checked with assert_allclose or similar where precision is adjusted to the common denominator across computers and versions.
(To the latter: there were several difficult optimization problems in the test suite that didn't converge and unit tests failed or errored on some platforms and fixing them took quite a bit of time, mainly to figure out what might be the problem on a machine that we don't have access to.)

@bashtage
bashtage force-pushed the chelleych-arima_longar_start_params branch from 9cbc0e0 to bf8a72b Compare July 6, 2016 10:53
@coveralls

coveralls commented Jul 6, 2016 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.004%) to 88.815% when pulling bf8a72b on bashtage:chelleych-arima_longar_start_params into c5b2f2e on statsmodels:master.

@bashtage
bashtage force-pushed the chelleych-arima_longar_start_params branch 5 times, most recently from a43afc4 to a866399 Compare July 6, 2016 12:22
Add correct type to disp
@bashtage
bashtage force-pushed the chelleych-arima_longar_start_params branch from a866399 to 652bf5c Compare July 6, 2016 12:33
@coveralls

coveralls commented Jul 6, 2016 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.003%) to 88.814% when pulling 652bf5c on bashtage:chelleych-arima_longar_start_params into c5b2f2e on statsmodels:master.

Remove redundant lines that entered on rebase
@coveralls

coveralls commented Jul 6, 2016 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.004%) to 88.815% when pulling 7334451 on bashtage:chelleych-arima_longar_start_params into c5b2f2e on statsmodels:master.

@josef-pkt
josef-pkt merged commit 35ef666 into statsmodels:master Jul 8, 2016
@josef-pkt

Copy link
Copy Markdown
Member

Thanks @chelleych @bashtage

AFAICS, this should be good to backport to 0.8.

@josef-pkt josef-pkt mentioned this pull request Aug 16, 2016
4 of 28 tasks
josef-pkt added a commit to josef-pkt/statsmodels that referenced this pull request Aug 19, 2016
…gar_start_params

ENH: Add new method to generate starting params (fixed lags for hr start ar)
@TomAugspurger TomAugspurger mentioned this pull request Feb 2, 2017
2 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants