私はscipy.special.hyp2f1()
を使用して各ステップで超幾何関数の計算を必要とするMCMCサンプラーを実行しています。私のグリッド上の特定のポイントで正確な警告はscipy.specialで
(私は気にしない)超幾何関数の解決策は非常に不安定であり、scipyのダウンロードは警告を出力します。
Warning! You should check the accuracy
これはかなり面倒ですし、サンプルの1000を超えます私のルーチンを良くするかもしれない。
私はspecial.errprint(0)
を使用してみましたが、warnings
モジュールと-W ignore
フラグの両方を使用してPythonのすべての警告を無効にしました。
(別のファイルから呼び出された)問題の機能は
from numpy import pi, hypot, real, imag
import scipy.special as special
def deflection_angle(p, (x1, x2)):
# Find the normalisation constant
norm = (p.f * p.m * (p.r0 ** (t - 2.0))/pi) ** (1.0/t)
# Define the complex plane
z = x1 + 1j * x2
# Define the radial coordinates
r = hypot(x1, x2)
# Truncate the radial coordinates
r_ = r * (r < p.r0).astype('float') + p.r0 * (r >= p.r0).astype('float')
# Calculate the radial part
radial = (norm ** 2/(p.f * z)) * ((norm/r_) ** (t - 2))
# Calculate the angular part
h1, h2, h3 = 0.5, 1.0 - t/2.0, 2.0 - t/2.0
h4 = ((1 - p.f ** 2)/p.f ** 2) * (r_/z) ** 2
special.errprint(0)
angular = special.hyp2f1(h1, h2, h3, h4)
# Assemble the deflection angle
alpha = (- radial * angular).conjugate()
# Separate real and imaginary parts
return real(alpha), imag(alpha)`
警告を再現する簡単な方法は、 'hyp2f1(1/2。、2/3。、3/2。、.75j + .09j)'です。 – wrwrwr