我的SciPy版本是1.7.3,我在苹果的M1芯片上运行(不确定它是否相关)。我的Python版本是3.9.11,通过Annaconda安装。
在运行以下/opt/anaconda3/lib/python3.9/site-packages/scipy/stats/_continuous_distns.py:624: RuntimeWarning: overflow encountered in _beta_ppf return _boost._beta_ppf(q, a, b)
代码时,我会得到错误消息PyMC3:
import pymc3 as pm
from scipy import stats
Y = stats.bernoulli(0.7).rvs(20)
with pm.Model() as model:
theta = pm.Beta("theta", alpha=0.1, beta=0.1)
y_obs = pm.Binomial("y_obs", n=2, p=theta, observed=Y)
idata = pm.sample(1000, return_inferencedata=True)
我认为问题不在于PyMC3,因为PyMC3代码someone else wrote运行时没有任何错误:
np.random.seed(123)
n_experiments=4
theta_real =0.35
data =stats.bernoulli.rvs(p=theta_real,size=n_experiments)
with pm.Model() as our_first_model:
theta =pm.Beta('theta',alpha=1,beta=1)
y =pm.Bernoulli('y',p=theta,observed=data)
start =pm.find_MAP()
step =pm.Metropolis()
trace =pm.sample(1000,step=step,start=start)
burnin=100
chain =trace[burnin:]
pm.traceplot(chain,lines={'theta':theta_real})
然而,下面的SciPy代码片段提供了相同的错误:
import numpy as np
from scipy import stats
q = 0.999995
a = np.array([ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20])
b = np.array([99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, 99990, 99989, 99988, 99987, 99986, 99985, 99984, 99983, 99982, 99981])
stats.beta.ppf(q, a, b)
我在谷歌上搜索了"overflow encountered in _beta_ppf
“,发现了一个GitHub问题(https://github.com/scipy/scipy/issues/14901),指出了SciPy <=1.7.2在英特尔芯片上的问题。但是,我在M1芯片上使用了1.7.3。
Anaconda不允许我更新最新的SciPy版本(1.8.0)。使用pip来更新(pip install scipy==1.8.0
)会导致与ArviZ (arviz 0.11.2 requires typing-extensions<4,>=3.7.4.3, but you have typing-extensions 4.1.1 which is incompatible
)的不兼容。我想我可以降低typing-extensions
的评级,但是它可能会给其他软件包带来更多的问题,所以我宁愿不要。
我想知道我能做些什么来解决这个问题。谢谢!
发布于 2022-04-04 05:42:39
如果不能升级到1.8.0,则可以将其降级为1.6.x ( 1.6.x系列中不使用IIRC boost )
发布于 2022-04-11 07:56:04
本土Conda环境
FWIW,我在osx-arm64中使用本地Mambaforge,并且在使用SciPy v1.8.0创建原生PythonV3.10时没有问题。如果您已经有了一个Anaconda/Miniconda base (即osx-64),那么您应该能够使用以下方法创建一个本机环境:
Shell会话
conda create -n arm64
conda activate arm64
conda config --env --add channel conda-forge
conda config --env --set subdir osx-arm64
conda install -y scipy=1.8 pymc3
python
Python会话
Python 3.10.4 | packaged by conda-forge | (main, Mar 24 2022, 17:39:37) [Clang 12.0.1 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> from scipy import stats
>>> q = 0.999995
>>> a = np.array([ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20])
>>> b = np.array([99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, 99990, 99989, 99988, 99987, 99986, 99985, 99984, 99983, 99982, 99981])
>>> stats.beta.ppf(q, a, b)
array([0.00014976, 0.00017332, 0.00019478, 0.00021492, 0.0002341 ,
0.00025256, 0.00027046, 0.00028788, 0.00030491, 0.00032161,
0.00033802, 0.00035417, 0.00037009, 0.0003858 , 0.00040134,
0.0004167 , 0.00043192, 0.00044699, 0.00046193])
只需确保在安装其他软件包之前激活环境即可。
而且,scipy=1.7.3
似乎也没有任何错误。
https://stackoverflow.com/questions/71731484
复制相似问题