BUG: ive is nan from |x| near 2e9 on, inherited from scipy.special.ive (scipy/scipy#18088)

Aperta
#2,654 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
67/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
python

Direzione di ricerca

The issue identifies PyTensor’s scalar Ive implementation and the HSGPPeriodic spectral density as the affected paths, but names no source file or test. Start by locating Ive and its tests, then trace how it calls scipy.special.ive; reproduce the reported values near 2e9 and check the existing large-argument behavior. Done means large inputs return finite values consistent with the asymptotic behavior and the regression is covered by a test.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Describe the issue:

pt.ive(v, x) is nan from |x| of about 2e9 on, where the function is finite and smooth, close to 1 / sqrt(2 pi |x|). The nan comes from scipy.special.ive (AMOS reports a loss of significance, scipy/scipy#18088, open since 2023). Since PyTensor's Ive calls SciPy, it inherits it, and HSGPPeriodic's spectral density, ive(j, 1 / ls**2), is nan for a lengthscale below about 2.2e-5, which NUTS then rejects.

A fallback to the asymptotic expansion for large |x| in PyTensor's scalar Ive would avoid the NaN without waiting on SciPy.

Reproducible code example:
import numpy as np
import pytensor.tensor as pt
import scipy.special as sp

for x in [1e9, 2e9, 3e9]:
    x = np.float64(x)
    print(f"x={x:g}: pt.ive(0, x) = {float(pt.ive(0, x).eval())}, scipy = {sp.ive(0, x)}, 1/sqrt(2 pi x) = {1 / np.sqrt(2 * np.pi * x):.6e}")
x=1e+09: pt.ive(0, x) = 1.261566261167776e-05, scipy = 1.261566261167776e-05, 1/sqrt(2 pi x) = 1.261566e-05
x=2e+09: pt.ive(0, x) = nan, scipy = nan, 1/sqrt(2 pi x) = 8.920621e-06
x=3e+09: pt.ive(0, x) = nan, scipy = nan, 1/sqrt(2 pi x) = 7.283656e-06

mpmath at 50 digits: ive(0, 2e9) = 8.92062058132e-06 and ive(0, 3e9) = 7.28365620425e-06.

Error message:

None. The value is nan.

PyTensor version information:

pytensor 3.3.7, scipy 1.18.1, numpy 2.5.4, Python 3.12, macOS arm64.

Context for the issue:

Found while checking the spectral density of HSGPPeriodic at small lengthscales.

Lingua principale
Python
Stelle
654
Fork
258
Merge medio
2g 7h
PR unite (30g)
39

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di pymc-devs/pytensor

Tutte le issue di pymc-devs/pytensor

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.