我想使用 scipy.stats 进行一些概率计算,并避免下溢/溢出: 除了使用适当的日志函数之外,我还尝试使用 numpy.longdouble (Ubuntu 上的 float128)来提高浮点精度。
但是我尝试的功能都失败了,例如:
import numpy as np, scipy.stats as st
x = np.array([0.1, 0.2, 0.5], dtype=np.longdouble)
st.entropy(x)
st.gamma.pdf(x, 2)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-7-72225ce02b65> in <module>
----> 1 st.entropy(x)
~/.local/lib/python3.5/site-packages/scipy/stats/_distn_infrastructure.py in entropy(pk, qk, base, axis)
2664 pk = 1.0*pk / np.sum(pk, axis=axis, keepdims=True)
2665 if qk is None:
-> 2666 vec = entr(pk)
2667 else:
2668 qk = asarray(qk)
TypeError: ufunc 'entr' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
scipy.stats 中是否支持长 double ? 据此documentation page ,看来并非如此:-(
<小时/>详细信息和版本
我的问题类似于 this one ,除了 scipy.linalg.svd
或 mpmath.matrix
对我有用。
scipy 版本为 1.4.1,numpy.show_config()
:
lapack_opt_info:
libraries = ['openblas', 'openblas']
define_macros = [('HAVE_CBLAS', None)]
language = c
library_dirs = ['/usr/local/lib']
openblas_lapack_info:
libraries = ['openblas', 'openblas']
define_macros = [('HAVE_CBLAS', None)]
language = c
library_dirs = ['/usr/local/lib']
openblas_info:
libraries = ['openblas', 'openblas']
define_macros = [('HAVE_CBLAS', None)]
language = c
library_dirs = ['/usr/local/lib']
lapack_mkl_info:
NOT AVAILABLE
blis_info:
NOT AVAILABLE
blas_opt_info:
libraries = ['openblas', 'openblas']
define_macros = [('HAVE_CBLAS', None)]
language = c
library_dirs = ['/usr/local/lib']
blas_mkl_info:
NOT AVAILABLE
最佳答案
基本上,不,没有。特定发行版的选择方法可能有效,也可能无效,并且不能保证。
关于python - scipy.stats 中支持 float128 (np.longdouble),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60184953/