2

I would like to make some probability computations with scipy.stats, and avoid under/overflows: in addition to using the appropriate log-functions, I tried to increase the float precision using numpy.longdouble (float128 on Ubuntu).

However, the functions I tried failed, for example:

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''

Is there any support for long double precision in scipy.stats? According to this documentation page, it does not seem so :-(


Details and versions

My problem is similar to this one, except that scipy.linalg.svd or mpmath.matrix work for me.

scipy version is 1.4.1, and 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
PlasmaBinturong
  • 1,428
  • 13
  • 16

1 Answers1

0

Basically, no, there isn't. Select methods of specific distributions may or may not work, and it's not guaranteed.

ev-br
  • 21,230
  • 9
  • 54
  • 70