felipeangelimvieira / prophetverse

A multiverse of Prophet models for timeseries
https://prophetverse.com
Apache License 2.0
33 stars 3 forks source link

[BUG] _to_positive returning zeros due to float precision. #84

Closed felipeangelimvieira closed 4 months ago

felipeangelimvieira commented 4 months ago

The function _to_positive, which is used to force a positive mean for Gamma and Neg Binomial likelihoods can return zeros due to float precision. This then breaks the model, leading to "NaNs" in the loss. A solution would be to add a clip to avoid this error.

Code for reproducing the bug

from prophetverse.sktime import Prophetverse
import pandas as pd
import numpy as np

min_val = 3
_y =np.clip(np.linspace(0, 10, 1000), min_val, None) - min_val + 1e-6
y = pd.Series(
    _y,
    index=pd.date_range("2022-01-01", periods=len(_y), freq="D"),
)
Prophetverse(likelihood="gamma").fit(y)