feat(distributions): vectorize ricegamma logpdf, add K→0 fit fallback

- Replace per-term Python loop in _logpdf with a single vectorised kve
  call (shape N×M) in both ricegamma_gen and logricegamma_gen, giving
  order-of-magnitude speedup on large batch inputs.
- Add adaptive series truncation: n_terms ≈ 3K+30, collapses to n=1
  when K=0 so no unnecessary computation.
- Cache Gauss-Laguerre quadrature nodes in _cdf to avoid recomputing
  roots_genlaguerre on every optimiser call.
- Add fit() override that re-fits with K fixed to 0 when the MLE
  estimate falls below _K_ZERO_THRESH (1e-2), avoiding near-zero Rice
  series numerical issues.
- Register logricegamma in the generate_data.py fitting pipeline.
- Reduce ricegamma N_SERIES 90→36; adaptive truncation handles accuracy.
This commit is contained in:
2026-05-27 16:58:03 -03:00
parent bfb77c4720
commit 2db98e95da
2 changed files with 147 additions and 64 deletions

View File

@@ -5,7 +5,7 @@ import sys
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
from etc.fitting import Fitter
from etc.tools.distributions import logweibull,lognakagami, loggamma_dist, k_dist, lograyleigh, logrice,logk
from etc.tools.distributions import logweibull,lognakagami, loggamma_dist, k_dist, lograyleigh, logrice,logk, logricegamma
from etc.tools.statistics import aic_statistic, bic_statistic
import pandas as pd
import plotly.io as pio
@@ -37,7 +37,7 @@ if __name__ == "__main__":
if not os.path.exists(DATA_FOLDER):
os.makedirs(DATA_FOLDER)
dist_list = [weibull_min,nakagami,gamma, rice, rayleigh, k_dist]
dist_list_log = [logweibull,lognakagami,loggamma_dist,logrice,lograyleigh,logk]
dist_list_log = [logweibull,lognakagami,loggamma_dist,logrice,lograyleigh,logk,logricegamma]
statistics_dataframe_aic= pd.DataFrame(columns=[dist.name for dist in dist_list_log])
statistics_dataframe_bic= pd.DataFrame(columns=[dist.name for dist in dist_list_log])