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

オープン
#2,654 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
67/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
python

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Python
スター
654
フォーク
258
平均マージ
3日 41分
マージ済み PR(30日)
42

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

pymc-devs/pytensor のほかの issue

pymc-devs/pytensor の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。