RJT1990 / pyflux

Open source time series library for Python
BSD 3-Clause "New" or "Revised" License
2.11k stars 240 forks source link

RuntimeWarning: overflow when running ARIMA example #47

Closed jpintar closed 7 years ago

jpintar commented 7 years ago

I'm trying to use PyFlux on a Windows 10 64-bit machine with Python 3.4 (Anaconda with NumPy 1.11.2 and SciPy 0.18.1). I installed PyFlux 0.4.0 using Christoph Gohlke's precompiled wheel. However when I run the ARIMA example from the documentation, when I fit the model, I get the following result:

C:\Anaconda3\lib\site-packages\scipy\stats\_continuous_distns.py:84: RuntimeWarning: overflow encountered in square
  return -x**2 / 2.0 - _norm_pdf_logC
ARIMA(4,0,4)                                                                                              
======================================================= ==================================================
Dependent Variable: sunspot.year                        Method: MLE                                       
Start Date: 1704                                        Log Likelihood: -1180.5324                        
End Date: 1988                                          AIC: 2381.0648                                    
Number of observations: 285                             BIC: 2417.5897                                    
==========================================================================================================
Latent Variable                          Estimate   Std Error  z        P>|z|    95% C.I.                 
======================================== ========== ========== ======== ======== =========================
Constant                                 2.6396     1.0944     2.412    0.0159   (0.4947 | 4.7846)        
AR(1)                                    1.8146     0.1035     17.5364  0.0      (1.6118 | 2.0174)        
AR(2)                                    -0.606     0.2661     -2.2776  0.0227   (-1.1275 | -0.0845)      
AR(3)                                    -0.8672    0.2707     -3.2031  0.0014   (-1.3979 | -0.3366)      
AR(4)                                    0.6084     0.1074     5.6638   0.0      (0.3978 | 0.8189)        
MA(1)                                    -0.6369    0.0958     -6.648   0.0      (-0.8246 | -0.4491)      
MA(2)                                    -0.5629    0.1497     -3.7595  0.0002   (-0.8563 | -0.2694)      
MA(3)                                    0.2923     0.1207     2.421    0.0155   (0.0557 | 0.5289)        
MA(4)                                    0.2367     0.0684     3.4602   0.0005   (0.1026 | 0.3707)        
Sigma                                    15.2314                                                          
==========================================================================================================

Do you have any thoughts on what could be going wrong and how it could be fixed?

RJT1990 commented 7 years ago

Thanks for reporting. It looks like it returned the results okay; the problem seems to be that during optimization one of the squared terms (y-mean) become very large, hence why it raised the overflow warning. This may not actually be a major problem as the optimizer has dealt with it and escaped a bad likelihood region, but ideally the models shouldn't hit these types of problem at all - I tend to experience overflow based issues most frequently with the GAS models.

As a resolution, I will look to do following in future versions:

But again, I stress that it looks like it may not actually be a problem in your case above.

jpintar commented 7 years ago

Thank you!

RJT1990 commented 7 years ago

Warnings have been temporarily suppressed - may want to unremove if more clever routines to avoid temporary overround and nan slice problems in optimization are avoided.