microprediction / timemachines

Predict time-series with one line of code.
https://www.microprediction.com/blog/popular-timeseries-packages
MIT License
384 stars 50 forks source link

Uncaught Exception: OverflowError: math range error #81

Open cryptocoinserver opened 2 years ago

cryptocoinserver commented 2 years ago
    xi, x_std, self.s = self.skater(y=round(yi, 6), s=self.s, k=1)
  File "/usr/local/lib/python3.9/site-packages/timemachines/skaters/smdk/smdkarma.py", line 21, in smdk_p5_d0_q3_n500_aggressive
    return smdk_arma_factory(y=y, n_agents=500, max_p=5, max_q=3, s=s, k=k, a=a, t=t, e=e, r=0.95)
  File "/usr/local/lib/python3.9/site-packages/timemachines/skaters/smdk/smdkarmafactory.py", line 119, in smdk_arma_factory
    x, x_std, s['s_pks'] = precision_weighted_skater(y=y_for_pws, s=s['s_pws'], k=k, a=a, t=t, e=e, r=r)
  File "/usr/local/lib/python3.9/site-packages/timemachines/skatertools/ensembling/precisionweightedskater.py", line 30, in precision_weighted_skater
    w  = normalize( [ 1./math.pow(y_std,expon) for y_std in y_stds ] )
  File "/usr/local/lib/python3.9/site-packages/timemachines/skatertools/ensembling/precisionweightedskater.py", line 30, in <listcomp>
    w  = normalize( [ 1./math.pow(y_std,expon) for y_std in y_stds ] )
=========================================================================

 Uncaught Exception: OverflowError: math range error

Any idea why this happens and how to avoid that?

My code:

 self.skater = local_skater_from_name('smdk_p5_d0_q3_n500_aggressive')
 self.s = {}
 self.x = []

This is inside a loop:

if self.index == 0:
    returns = utils.prices_to_returns(self.candles[:, 2])[1:]
    # warmup
    for yi in returns:
        xi, x_std, self.s = self.skater(y=round(yi, 6), s=self.s, k=1, e=-1)
        self.x.append(xi)
else:
    yi = utils.prices_to_returns(self.candles[-5:, 2])[-1]
    # predict
    xi, x_std, self.s = self.skater(y=round(yi, 6), s=self.s, k=1)
    self.x.append(xi)
self.x = self.x[-240:]

Thank you.

cryptocoinserver commented 2 years ago

Could it be the s argument getting to big? Is there a way to limit/slice the memory of it?

cryptocoinserver commented 2 years ago

The s argument was the reason. If I reset it after a certain amount of iterations, this error doesn't happen. Would be great to not have to clear all the history, but being able to keep a certain amount. If I understood it right, the s dict is different for each skater, so not an easy task I think. Still an incredible repository you made. I think adding a warning to the docs, that s might have to be reset in certain cases might be enough.

microprediction commented 2 years ago

Hmm.. sorry just seeing this issue now. So you think the s is growing too large?

microprediction commented 2 years ago

And yes you are right the responsibility/interpretation of s is known to the skater, not the caller.

The memory should plateau though.

It might be something else. Can you try the same thing but without _aggressive? I just want to test a theory.

microprediction commented 2 years ago

I should put bounds on the variances anyway. There's no good reason to risk the error you are seeing.

microprediction commented 2 years ago

btw I have better reflexes in the slack

cryptocoinserver commented 2 years ago
    xi, x_std, self.s = self.skater(y=yi, s=self.s, k=3)
  File "/usr/local/lib/python3.9/site-packages/timemachines/skaters/smdk/smdkarma.py", line 17, in smdk_p5_d0_q3_n500
    return smdk_arma_factory(y=y, n_agents=500, max_p=5, max_q=3, s=s, k=k, a=a, t=t, e=e, r=0.75)
  File "/usr/local/lib/python3.9/site-packages/timemachines/skaters/smdk/smdkarmafactory.py", line 119, in smdk_arma_factory
    x, x_std, s['s_pks'] = precision_weighted_skater(y=y_for_pws, s=s['s_pws'], k=k, a=a, t=t, e=e, r=r)
  File "/usr/local/lib/python3.9/site-packages/timemachines/skatertools/ensembling/precisionweightedskater.py", line 30, in precision_weighted_skater
    w  = normalize( [ 1./math.pow(y_std,expon) for y_std in y_stds ] )
  File "/usr/local/lib/python3.9/site-packages/timemachines/skatertools/ensembling/precisionweightedskater.py", line 30, in <listcomp>
    w  = normalize( [ 1./math.pow(y_std,expon) for y_std in y_stds ] )
=========================================================================

 Uncaught Exception: OverflowError: math range error

Same for smdk_p5_d0_q3_n500

microprediction commented 2 years ago

Strange, as tests are passing. I made some minor changes can you try:

  pip install --upgrade git+https://github.com/microprediction/timemachines.git 

?

microprediction commented 2 years ago

Okay to close this?