Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +8 -0
- mantis_evalkit/bin/python +3 -0
- mantis_evalkit/lib/python3.10/site-packages/numpy/random/mtrand.cpython-310-x86_64-linux-gnu.so +3 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_binned_statistic.cpython-310.pyc +0 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_binomtest.cpython-310.pyc +0 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_bws_test.cpython-310.pyc +0 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_censored_data.cpython-310.pyc +0 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_common.cpython-310.pyc +0 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_discrete_distns.cpython-310.pyc +0 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_distr_params.cpython-310.pyc +0 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_entropy.cpython-310.pyc +0 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_fit.cpython-310.pyc +0 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_hypotests.cpython-310.pyc +0 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_ksstats.cpython-310.pyc +0 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_mannwhitneyu.cpython-310.pyc +0 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_mstats_extras.cpython-310.pyc +0 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_odds_ratio.cpython-310.pyc +0 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_probability_distribution.cpython-310.pyc +0 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_qmc.cpython-310.pyc +0 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_qmvnt.cpython-310.pyc +0 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_relative_risk.cpython-310.pyc +0 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_resampling.cpython-310.pyc +0 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_result_classes.cpython-310.pyc +0 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_sampling.cpython-310.pyc +0 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_sensitivity_analysis.cpython-310.pyc +0 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_stats_mstats_common.cpython-310.pyc +0 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_survival.cpython-310.pyc +0 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_tukeylambda_stats.cpython-310.pyc +0 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_variation.cpython-310.pyc +0 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_warnings_errors.cpython-310.pyc +0 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_wilcoxon.cpython-310.pyc +0 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/biasedurn.cpython-310.pyc +0 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/contingency.cpython-310.pyc +0 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/kde.cpython-310.pyc +0 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/morestats.cpython-310.pyc +0 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/mstats_basic.cpython-310.pyc +0 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/mvn.cpython-310.pyc +0 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/stats.cpython-310.pyc +0 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/_ansari_swilk_statistics.cpython-310-x86_64-linux-gnu.so +3 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/_biasedurn.cpython-310-x86_64-linux-gnu.so +3 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/_levy_stable/__init__.py +1239 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/_levy_stable/__pycache__/__init__.cpython-310.pyc +0 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/_levy_stable/levyst.cpython-310-x86_64-linux-gnu.so +0 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/_qmc_cy.cpython-310-x86_64-linux-gnu.so +3 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/_sobol.cpython-310-x86_64-linux-gnu.so +3 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/_stats.cpython-310-x86_64-linux-gnu.so +3 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/_stats_pythran.cpython-310-x86_64-linux-gnu.so +3 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/tests/data/jf_skew_t_gamlss_pdf_data.npy +3 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/tests/data/levy_stable/stable-Z1-cdf-sample-data.npy +3 -0
- mantis_evalkit/lib/python3.10/site-packages/scipy/stats/tests/data/levy_stable/stable-Z1-pdf-sample-data.npy +3 -0
.gitattributes
CHANGED
|
@@ -554,3 +554,11 @@ moondream/lib/python3.10/site-packages/altair/vegalite/v5/__pycache__/api.cpytho
|
|
| 554 |
mantis_evalkit/bin/python3.10 filter=lfs diff=lfs merge=lfs -text
|
| 555 |
openflamingo/lib/python3.10/site-packages/torch/lib/libnvrtc-672ee683.so.11.2 filter=lfs diff=lfs merge=lfs -text
|
| 556 |
mantis_evalkit/lib/python3.10/site-packages/numpy/lib/tests/__pycache__/test_function_base.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 554 |
mantis_evalkit/bin/python3.10 filter=lfs diff=lfs merge=lfs -text
|
| 555 |
openflamingo/lib/python3.10/site-packages/torch/lib/libnvrtc-672ee683.so.11.2 filter=lfs diff=lfs merge=lfs -text
|
| 556 |
mantis_evalkit/lib/python3.10/site-packages/numpy/lib/tests/__pycache__/test_function_base.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
| 557 |
+
mantis_evalkit/lib/python3.10/site-packages/numpy/random/mtrand.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 558 |
+
mantis_evalkit/bin/python filter=lfs diff=lfs merge=lfs -text
|
| 559 |
+
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/_sobol.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 560 |
+
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/_stats_pythran.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 561 |
+
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/_biasedurn.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 562 |
+
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/_ansari_swilk_statistics.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 563 |
+
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/_qmc_cy.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 564 |
+
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/_stats.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
mantis_evalkit/bin/python
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:942d139b2c77dad76f23ac64382f5e2714b5b2f0b1be3e76a8f79e1214cf0e6d
|
| 3 |
+
size 17225608
|
mantis_evalkit/lib/python3.10/site-packages/numpy/random/mtrand.cpython-310-x86_64-linux-gnu.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5f35bd15dab38edbffbfe4e481a21d0ecb367e8f70469a821198a2df9691b7ed
|
| 3 |
+
size 850576
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_binned_statistic.cpython-310.pyc
ADDED
|
Binary file (28.2 kB). View file
|
|
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_binomtest.cpython-310.pyc
ADDED
|
Binary file (11.4 kB). View file
|
|
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_bws_test.cpython-310.pyc
ADDED
|
Binary file (6.7 kB). View file
|
|
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_censored_data.cpython-310.pyc
ADDED
|
Binary file (17.2 kB). View file
|
|
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_common.cpython-310.pyc
ADDED
|
Binary file (318 Bytes). View file
|
|
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_discrete_distns.cpython-310.pyc
ADDED
|
Binary file (68.6 kB). View file
|
|
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_distr_params.cpython-310.pyc
ADDED
|
Binary file (6.93 kB). View file
|
|
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_entropy.cpython-310.pyc
ADDED
|
Binary file (15.2 kB). View file
|
|
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_fit.cpython-310.pyc
ADDED
|
Binary file (52.3 kB). View file
|
|
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_hypotests.cpython-310.pyc
ADDED
|
Binary file (69.4 kB). View file
|
|
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_ksstats.cpython-310.pyc
ADDED
|
Binary file (12 kB). View file
|
|
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_mannwhitneyu.cpython-310.pyc
ADDED
|
Binary file (16.3 kB). View file
|
|
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_mstats_extras.cpython-310.pyc
ADDED
|
Binary file (15.4 kB). View file
|
|
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_odds_ratio.cpython-310.pyc
ADDED
|
Binary file (14.9 kB). View file
|
|
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_probability_distribution.cpython-310.pyc
ADDED
|
Binary file (62.3 kB). View file
|
|
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_qmc.cpython-310.pyc
ADDED
|
Binary file (95.3 kB). View file
|
|
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_qmvnt.cpython-310.pyc
ADDED
|
Binary file (13.5 kB). View file
|
|
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_relative_risk.cpython-310.pyc
ADDED
|
Binary file (8.32 kB). View file
|
|
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_resampling.cpython-310.pyc
ADDED
|
Binary file (90.8 kB). View file
|
|
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_result_classes.cpython-310.pyc
ADDED
|
Binary file (1.03 kB). View file
|
|
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_sampling.cpython-310.pyc
ADDED
|
Binary file (43 kB). View file
|
|
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_sensitivity_analysis.cpython-310.pyc
ADDED
|
Binary file (23.9 kB). View file
|
|
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_stats_mstats_common.cpython-310.pyc
ADDED
|
Binary file (10.7 kB). View file
|
|
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_survival.cpython-310.pyc
ADDED
|
Binary file (22.8 kB). View file
|
|
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_tukeylambda_stats.cpython-310.pyc
ADDED
|
Binary file (3.1 kB). View file
|
|
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_variation.cpython-310.pyc
ADDED
|
Binary file (4.6 kB). View file
|
|
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_warnings_errors.cpython-310.pyc
ADDED
|
Binary file (1.72 kB). View file
|
|
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/_wilcoxon.cpython-310.pyc
ADDED
|
Binary file (6.68 kB). View file
|
|
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/biasedurn.cpython-310.pyc
ADDED
|
Binary file (632 Bytes). View file
|
|
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/contingency.cpython-310.pyc
ADDED
|
Binary file (16.9 kB). View file
|
|
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/kde.cpython-310.pyc
ADDED
|
Binary file (583 Bytes). View file
|
|
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/morestats.cpython-310.pyc
ADDED
|
Binary file (955 Bytes). View file
|
|
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/mstats_basic.cpython-310.pyc
ADDED
|
Binary file (1.29 kB). View file
|
|
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/mvn.cpython-310.pyc
ADDED
|
Binary file (614 Bytes). View file
|
|
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/__pycache__/stats.cpython-310.pyc
ADDED
|
Binary file (1.36 kB). View file
|
|
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/_ansari_swilk_statistics.cpython-310-x86_64-linux-gnu.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8a17af6ad204a46c4a5cc9eba23fef13744115af681e54decd0d288a15892831
|
| 3 |
+
size 278232
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/_biasedurn.cpython-310-x86_64-linux-gnu.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d4516e57803a75cc4aad2314689dc5123bcafd31845850453836dd4e227ac307
|
| 3 |
+
size 323168
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/_levy_stable/__init__.py
ADDED
|
@@ -0,0 +1,1239 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
|
| 3 |
+
import warnings
|
| 4 |
+
from functools import partial
|
| 5 |
+
|
| 6 |
+
import numpy as np
|
| 7 |
+
|
| 8 |
+
from scipy import optimize
|
| 9 |
+
from scipy import integrate
|
| 10 |
+
from scipy.integrate._quadrature import _builtincoeffs
|
| 11 |
+
from scipy import interpolate
|
| 12 |
+
from scipy.interpolate import RectBivariateSpline
|
| 13 |
+
import scipy.special as sc
|
| 14 |
+
from scipy._lib._util import _lazywhere
|
| 15 |
+
from .._distn_infrastructure import rv_continuous, _ShapeInfo, rv_continuous_frozen
|
| 16 |
+
from .._continuous_distns import uniform, expon, _norm_pdf, _norm_cdf
|
| 17 |
+
from .levyst import Nolan
|
| 18 |
+
from scipy._lib.doccer import inherit_docstring_from
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
__all__ = ["levy_stable", "levy_stable_gen", "pdf_from_cf_with_fft"]
|
| 22 |
+
|
| 23 |
+
# Stable distributions are known for various parameterisations
|
| 24 |
+
# some being advantageous for numerical considerations and others
|
| 25 |
+
# useful due to their location/scale awareness.
|
| 26 |
+
#
|
| 27 |
+
# Here we follow [NO] convention (see the references in the docstring
|
| 28 |
+
# for levy_stable_gen below).
|
| 29 |
+
#
|
| 30 |
+
# S0 / Z0 / x0 (aka Zoleterav's M)
|
| 31 |
+
# S1 / Z1 / x1
|
| 32 |
+
#
|
| 33 |
+
# Where S* denotes parameterisation, Z* denotes standardized
|
| 34 |
+
# version where gamma = 1, delta = 0 and x* denotes variable.
|
| 35 |
+
#
|
| 36 |
+
# Scipy's original Stable was a random variate generator. It
|
| 37 |
+
# uses S1 and unfortunately is not a location/scale aware.
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
# default numerical integration tolerance
|
| 41 |
+
# used for epsrel in piecewise and both epsrel and epsabs in dni
|
| 42 |
+
# (epsabs needed in dni since weighted quad requires epsabs > 0)
|
| 43 |
+
_QUAD_EPS = 1.2e-14
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def _Phi_Z0(alpha, t):
|
| 47 |
+
return (
|
| 48 |
+
-np.tan(np.pi * alpha / 2) * (np.abs(t) ** (1 - alpha) - 1)
|
| 49 |
+
if alpha != 1
|
| 50 |
+
else -2.0 * np.log(np.abs(t)) / np.pi
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def _Phi_Z1(alpha, t):
|
| 55 |
+
return (
|
| 56 |
+
np.tan(np.pi * alpha / 2)
|
| 57 |
+
if alpha != 1
|
| 58 |
+
else -2.0 * np.log(np.abs(t)) / np.pi
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def _cf(Phi, t, alpha, beta):
|
| 63 |
+
"""Characteristic function."""
|
| 64 |
+
return np.exp(
|
| 65 |
+
-(np.abs(t) ** alpha) * (1 - 1j * beta * np.sign(t) * Phi(alpha, t))
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
_cf_Z0 = partial(_cf, _Phi_Z0)
|
| 70 |
+
_cf_Z1 = partial(_cf, _Phi_Z1)
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def _pdf_single_value_cf_integrate(Phi, x, alpha, beta, **kwds):
|
| 74 |
+
"""To improve DNI accuracy convert characteristic function in to real
|
| 75 |
+
valued integral using Euler's formula, then exploit cosine symmetry to
|
| 76 |
+
change limits to [0, inf). Finally use cosine addition formula to split
|
| 77 |
+
into two parts that can be handled by weighted quad pack.
|
| 78 |
+
"""
|
| 79 |
+
quad_eps = kwds.get("quad_eps", _QUAD_EPS)
|
| 80 |
+
|
| 81 |
+
def integrand1(t):
|
| 82 |
+
if t == 0:
|
| 83 |
+
return 0
|
| 84 |
+
return np.exp(-(t ** alpha)) * (
|
| 85 |
+
np.cos(beta * (t ** alpha) * Phi(alpha, t))
|
| 86 |
+
)
|
| 87 |
+
|
| 88 |
+
def integrand2(t):
|
| 89 |
+
if t == 0:
|
| 90 |
+
return 0
|
| 91 |
+
return np.exp(-(t ** alpha)) * (
|
| 92 |
+
np.sin(beta * (t ** alpha) * Phi(alpha, t))
|
| 93 |
+
)
|
| 94 |
+
|
| 95 |
+
with np.errstate(invalid="ignore"):
|
| 96 |
+
int1, *ret1 = integrate.quad(
|
| 97 |
+
integrand1,
|
| 98 |
+
0,
|
| 99 |
+
np.inf,
|
| 100 |
+
weight="cos",
|
| 101 |
+
wvar=x,
|
| 102 |
+
limit=1000,
|
| 103 |
+
epsabs=quad_eps,
|
| 104 |
+
epsrel=quad_eps,
|
| 105 |
+
full_output=1,
|
| 106 |
+
)
|
| 107 |
+
|
| 108 |
+
int2, *ret2 = integrate.quad(
|
| 109 |
+
integrand2,
|
| 110 |
+
0,
|
| 111 |
+
np.inf,
|
| 112 |
+
weight="sin",
|
| 113 |
+
wvar=x,
|
| 114 |
+
limit=1000,
|
| 115 |
+
epsabs=quad_eps,
|
| 116 |
+
epsrel=quad_eps,
|
| 117 |
+
full_output=1,
|
| 118 |
+
)
|
| 119 |
+
|
| 120 |
+
return (int1 + int2) / np.pi
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
_pdf_single_value_cf_integrate_Z0 = partial(
|
| 124 |
+
_pdf_single_value_cf_integrate, _Phi_Z0
|
| 125 |
+
)
|
| 126 |
+
_pdf_single_value_cf_integrate_Z1 = partial(
|
| 127 |
+
_pdf_single_value_cf_integrate, _Phi_Z1
|
| 128 |
+
)
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
def _nolan_round_x_near_zeta(x0, alpha, zeta, x_tol_near_zeta):
|
| 132 |
+
"""Round x close to zeta for Nolan's method in [NO]."""
|
| 133 |
+
# "8. When |x0-beta*tan(pi*alpha/2)| is small, the
|
| 134 |
+
# computations of the density and cumulative have numerical problems.
|
| 135 |
+
# The program works around this by setting
|
| 136 |
+
# z = beta*tan(pi*alpha/2) when
|
| 137 |
+
# |z-beta*tan(pi*alpha/2)| < tol(5)*alpha**(1/alpha).
|
| 138 |
+
# (The bound on the right is ad hoc, to get reasonable behavior
|
| 139 |
+
# when alpha is small)."
|
| 140 |
+
# where tol(5) = 0.5e-2 by default.
|
| 141 |
+
#
|
| 142 |
+
# We seem to have partially addressed this through re-expression of
|
| 143 |
+
# g(theta) here, but it still needs to be used in some extreme cases.
|
| 144 |
+
# Perhaps tol(5) = 0.5e-2 could be reduced for our implementation.
|
| 145 |
+
if np.abs(x0 - zeta) < x_tol_near_zeta * alpha ** (1 / alpha):
|
| 146 |
+
x0 = zeta
|
| 147 |
+
return x0
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
def _nolan_round_difficult_input(
|
| 151 |
+
x0, alpha, beta, zeta, x_tol_near_zeta, alpha_tol_near_one
|
| 152 |
+
):
|
| 153 |
+
"""Round difficult input values for Nolan's method in [NO]."""
|
| 154 |
+
|
| 155 |
+
# following Nolan's STABLE,
|
| 156 |
+
# "1. When 0 < |alpha-1| < 0.005, the program has numerical problems
|
| 157 |
+
# evaluating the pdf and cdf. The current version of the program sets
|
| 158 |
+
# alpha=1 in these cases. This approximation is not bad in the S0
|
| 159 |
+
# parameterization."
|
| 160 |
+
if np.abs(alpha - 1) < alpha_tol_near_one:
|
| 161 |
+
alpha = 1.0
|
| 162 |
+
|
| 163 |
+
# "2. When alpha=1 and |beta| < 0.005, the program has numerical
|
| 164 |
+
# problems. The current version sets beta=0."
|
| 165 |
+
# We seem to have addressed this through re-expression of g(theta) here
|
| 166 |
+
|
| 167 |
+
x0 = _nolan_round_x_near_zeta(x0, alpha, zeta, x_tol_near_zeta)
|
| 168 |
+
return x0, alpha, beta
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
def _pdf_single_value_piecewise_Z1(x, alpha, beta, **kwds):
|
| 172 |
+
# convert from Nolan's S_1 (aka S) to S_0 (aka Zolaterev M)
|
| 173 |
+
# parameterization
|
| 174 |
+
|
| 175 |
+
zeta = -beta * np.tan(np.pi * alpha / 2.0)
|
| 176 |
+
x0 = x + zeta if alpha != 1 else x
|
| 177 |
+
|
| 178 |
+
return _pdf_single_value_piecewise_Z0(x0, alpha, beta, **kwds)
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
def _pdf_single_value_piecewise_Z0(x0, alpha, beta, **kwds):
|
| 182 |
+
|
| 183 |
+
quad_eps = kwds.get("quad_eps", _QUAD_EPS)
|
| 184 |
+
x_tol_near_zeta = kwds.get("piecewise_x_tol_near_zeta", 0.005)
|
| 185 |
+
alpha_tol_near_one = kwds.get("piecewise_alpha_tol_near_one", 0.005)
|
| 186 |
+
|
| 187 |
+
zeta = -beta * np.tan(np.pi * alpha / 2.0)
|
| 188 |
+
x0, alpha, beta = _nolan_round_difficult_input(
|
| 189 |
+
x0, alpha, beta, zeta, x_tol_near_zeta, alpha_tol_near_one
|
| 190 |
+
)
|
| 191 |
+
|
| 192 |
+
# some other known distribution pdfs / analytical cases
|
| 193 |
+
# TODO: add more where possible with test coverage,
|
| 194 |
+
# eg https://en.wikipedia.org/wiki/Stable_distribution#Other_analytic_cases
|
| 195 |
+
if alpha == 2.0:
|
| 196 |
+
# normal
|
| 197 |
+
return _norm_pdf(x0 / np.sqrt(2)) / np.sqrt(2)
|
| 198 |
+
elif alpha == 0.5 and beta == 1.0:
|
| 199 |
+
# levy
|
| 200 |
+
# since S(1/2, 1, gamma, delta; <x>) ==
|
| 201 |
+
# S(1/2, 1, gamma, gamma + delta; <x0>).
|
| 202 |
+
_x = x0 + 1
|
| 203 |
+
if _x <= 0:
|
| 204 |
+
return 0
|
| 205 |
+
|
| 206 |
+
return 1 / np.sqrt(2 * np.pi * _x) / _x * np.exp(-1 / (2 * _x))
|
| 207 |
+
elif alpha == 0.5 and beta == 0.0 and x0 != 0:
|
| 208 |
+
# analytical solution [HO]
|
| 209 |
+
S, C = sc.fresnel([1 / np.sqrt(2 * np.pi * np.abs(x0))])
|
| 210 |
+
arg = 1 / (4 * np.abs(x0))
|
| 211 |
+
return (
|
| 212 |
+
np.sin(arg) * (0.5 - S[0]) + np.cos(arg) * (0.5 - C[0])
|
| 213 |
+
) / np.sqrt(2 * np.pi * np.abs(x0) ** 3)
|
| 214 |
+
elif alpha == 1.0 and beta == 0.0:
|
| 215 |
+
# cauchy
|
| 216 |
+
return 1 / (1 + x0 ** 2) / np.pi
|
| 217 |
+
|
| 218 |
+
return _pdf_single_value_piecewise_post_rounding_Z0(
|
| 219 |
+
x0, alpha, beta, quad_eps, x_tol_near_zeta
|
| 220 |
+
)
|
| 221 |
+
|
| 222 |
+
|
| 223 |
+
def _pdf_single_value_piecewise_post_rounding_Z0(x0, alpha, beta, quad_eps,
|
| 224 |
+
x_tol_near_zeta):
|
| 225 |
+
"""Calculate pdf using Nolan's methods as detailed in [NO]."""
|
| 226 |
+
|
| 227 |
+
_nolan = Nolan(alpha, beta, x0)
|
| 228 |
+
zeta = _nolan.zeta
|
| 229 |
+
xi = _nolan.xi
|
| 230 |
+
c2 = _nolan.c2
|
| 231 |
+
g = _nolan.g
|
| 232 |
+
|
| 233 |
+
# round x0 to zeta again if needed. zeta was recomputed and may have
|
| 234 |
+
# changed due to floating point differences.
|
| 235 |
+
# See https://github.com/scipy/scipy/pull/18133
|
| 236 |
+
x0 = _nolan_round_x_near_zeta(x0, alpha, zeta, x_tol_near_zeta)
|
| 237 |
+
# handle Nolan's initial case logic
|
| 238 |
+
if x0 == zeta:
|
| 239 |
+
return (
|
| 240 |
+
sc.gamma(1 + 1 / alpha)
|
| 241 |
+
* np.cos(xi)
|
| 242 |
+
/ np.pi
|
| 243 |
+
/ ((1 + zeta ** 2) ** (1 / alpha / 2))
|
| 244 |
+
)
|
| 245 |
+
elif x0 < zeta:
|
| 246 |
+
return _pdf_single_value_piecewise_post_rounding_Z0(
|
| 247 |
+
-x0, alpha, -beta, quad_eps, x_tol_near_zeta
|
| 248 |
+
)
|
| 249 |
+
|
| 250 |
+
# following Nolan, we may now assume
|
| 251 |
+
# x0 > zeta when alpha != 1
|
| 252 |
+
# beta != 0 when alpha == 1
|
| 253 |
+
|
| 254 |
+
# spare calculating integral on null set
|
| 255 |
+
# use isclose as macos has fp differences
|
| 256 |
+
if np.isclose(-xi, np.pi / 2, rtol=1e-014, atol=1e-014):
|
| 257 |
+
return 0.0
|
| 258 |
+
|
| 259 |
+
def integrand(theta):
|
| 260 |
+
# limit any numerical issues leading to g_1 < 0 near theta limits
|
| 261 |
+
g_1 = g(theta)
|
| 262 |
+
if not np.isfinite(g_1) or g_1 < 0:
|
| 263 |
+
g_1 = 0
|
| 264 |
+
return g_1 * np.exp(-g_1)
|
| 265 |
+
|
| 266 |
+
with np.errstate(all="ignore"):
|
| 267 |
+
peak = optimize.bisect(
|
| 268 |
+
lambda t: g(t) - 1, -xi, np.pi / 2, xtol=quad_eps
|
| 269 |
+
)
|
| 270 |
+
|
| 271 |
+
# this integrand can be very peaked, so we need to force
|
| 272 |
+
# QUADPACK to evaluate the function inside its support
|
| 273 |
+
#
|
| 274 |
+
|
| 275 |
+
# lastly, we add additional samples at
|
| 276 |
+
# ~exp(-100), ~exp(-10), ~exp(-5), ~exp(-1)
|
| 277 |
+
# to improve QUADPACK's detection of rapidly descending tail behavior
|
| 278 |
+
# (this choice is fairly ad hoc)
|
| 279 |
+
tail_points = [
|
| 280 |
+
optimize.bisect(lambda t: g(t) - exp_height, -xi, np.pi / 2)
|
| 281 |
+
for exp_height in [100, 10, 5]
|
| 282 |
+
# exp_height = 1 is handled by peak
|
| 283 |
+
]
|
| 284 |
+
intg_points = [0, peak] + tail_points
|
| 285 |
+
intg, *ret = integrate.quad(
|
| 286 |
+
integrand,
|
| 287 |
+
-xi,
|
| 288 |
+
np.pi / 2,
|
| 289 |
+
points=intg_points,
|
| 290 |
+
limit=100,
|
| 291 |
+
epsrel=quad_eps,
|
| 292 |
+
epsabs=0,
|
| 293 |
+
full_output=1,
|
| 294 |
+
)
|
| 295 |
+
|
| 296 |
+
return c2 * intg
|
| 297 |
+
|
| 298 |
+
|
| 299 |
+
def _cdf_single_value_piecewise_Z1(x, alpha, beta, **kwds):
|
| 300 |
+
# convert from Nolan's S_1 (aka S) to S_0 (aka Zolaterev M)
|
| 301 |
+
# parameterization
|
| 302 |
+
|
| 303 |
+
zeta = -beta * np.tan(np.pi * alpha / 2.0)
|
| 304 |
+
x0 = x + zeta if alpha != 1 else x
|
| 305 |
+
|
| 306 |
+
return _cdf_single_value_piecewise_Z0(x0, alpha, beta, **kwds)
|
| 307 |
+
|
| 308 |
+
|
| 309 |
+
def _cdf_single_value_piecewise_Z0(x0, alpha, beta, **kwds):
|
| 310 |
+
|
| 311 |
+
quad_eps = kwds.get("quad_eps", _QUAD_EPS)
|
| 312 |
+
x_tol_near_zeta = kwds.get("piecewise_x_tol_near_zeta", 0.005)
|
| 313 |
+
alpha_tol_near_one = kwds.get("piecewise_alpha_tol_near_one", 0.005)
|
| 314 |
+
|
| 315 |
+
zeta = -beta * np.tan(np.pi * alpha / 2.0)
|
| 316 |
+
x0, alpha, beta = _nolan_round_difficult_input(
|
| 317 |
+
x0, alpha, beta, zeta, x_tol_near_zeta, alpha_tol_near_one
|
| 318 |
+
)
|
| 319 |
+
|
| 320 |
+
# some other known distribution cdfs / analytical cases
|
| 321 |
+
# TODO: add more where possible with test coverage,
|
| 322 |
+
# eg https://en.wikipedia.org/wiki/Stable_distribution#Other_analytic_cases
|
| 323 |
+
if alpha == 2.0:
|
| 324 |
+
# normal
|
| 325 |
+
return _norm_cdf(x0 / np.sqrt(2))
|
| 326 |
+
elif alpha == 0.5 and beta == 1.0:
|
| 327 |
+
# levy
|
| 328 |
+
# since S(1/2, 1, gamma, delta; <x>) ==
|
| 329 |
+
# S(1/2, 1, gamma, gamma + delta; <x0>).
|
| 330 |
+
_x = x0 + 1
|
| 331 |
+
if _x <= 0:
|
| 332 |
+
return 0
|
| 333 |
+
|
| 334 |
+
return sc.erfc(np.sqrt(0.5 / _x))
|
| 335 |
+
elif alpha == 1.0 and beta == 0.0:
|
| 336 |
+
# cauchy
|
| 337 |
+
return 0.5 + np.arctan(x0) / np.pi
|
| 338 |
+
|
| 339 |
+
return _cdf_single_value_piecewise_post_rounding_Z0(
|
| 340 |
+
x0, alpha, beta, quad_eps, x_tol_near_zeta
|
| 341 |
+
)
|
| 342 |
+
|
| 343 |
+
|
| 344 |
+
def _cdf_single_value_piecewise_post_rounding_Z0(x0, alpha, beta, quad_eps,
|
| 345 |
+
x_tol_near_zeta):
|
| 346 |
+
"""Calculate cdf using Nolan's methods as detailed in [NO]."""
|
| 347 |
+
_nolan = Nolan(alpha, beta, x0)
|
| 348 |
+
zeta = _nolan.zeta
|
| 349 |
+
xi = _nolan.xi
|
| 350 |
+
c1 = _nolan.c1
|
| 351 |
+
# c2 = _nolan.c2
|
| 352 |
+
c3 = _nolan.c3
|
| 353 |
+
g = _nolan.g
|
| 354 |
+
# round x0 to zeta again if needed. zeta was recomputed and may have
|
| 355 |
+
# changed due to floating point differences.
|
| 356 |
+
# See https://github.com/scipy/scipy/pull/18133
|
| 357 |
+
x0 = _nolan_round_x_near_zeta(x0, alpha, zeta, x_tol_near_zeta)
|
| 358 |
+
# handle Nolan's initial case logic
|
| 359 |
+
if (alpha == 1 and beta < 0) or x0 < zeta:
|
| 360 |
+
# NOTE: Nolan's paper has a typo here!
|
| 361 |
+
# He states F(x) = 1 - F(x, alpha, -beta), but this is clearly
|
| 362 |
+
# incorrect since F(-infty) would be 1.0 in this case
|
| 363 |
+
# Indeed, the alpha != 1, x0 < zeta case is correct here.
|
| 364 |
+
return 1 - _cdf_single_value_piecewise_post_rounding_Z0(
|
| 365 |
+
-x0, alpha, -beta, quad_eps, x_tol_near_zeta
|
| 366 |
+
)
|
| 367 |
+
elif x0 == zeta:
|
| 368 |
+
return 0.5 - xi / np.pi
|
| 369 |
+
|
| 370 |
+
# following Nolan, we may now assume
|
| 371 |
+
# x0 > zeta when alpha != 1
|
| 372 |
+
# beta > 0 when alpha == 1
|
| 373 |
+
|
| 374 |
+
# spare calculating integral on null set
|
| 375 |
+
# use isclose as macos has fp differences
|
| 376 |
+
if np.isclose(-xi, np.pi / 2, rtol=1e-014, atol=1e-014):
|
| 377 |
+
return c1
|
| 378 |
+
|
| 379 |
+
def integrand(theta):
|
| 380 |
+
g_1 = g(theta)
|
| 381 |
+
return np.exp(-g_1)
|
| 382 |
+
|
| 383 |
+
with np.errstate(all="ignore"):
|
| 384 |
+
# shrink supports where required
|
| 385 |
+
left_support = -xi
|
| 386 |
+
right_support = np.pi / 2
|
| 387 |
+
if alpha > 1:
|
| 388 |
+
# integrand(t) monotonic 0 to 1
|
| 389 |
+
if integrand(-xi) != 0.0:
|
| 390 |
+
res = optimize.minimize(
|
| 391 |
+
integrand,
|
| 392 |
+
(-xi,),
|
| 393 |
+
method="L-BFGS-B",
|
| 394 |
+
bounds=[(-xi, np.pi / 2)],
|
| 395 |
+
)
|
| 396 |
+
left_support = res.x[0]
|
| 397 |
+
else:
|
| 398 |
+
# integrand(t) monotonic 1 to 0
|
| 399 |
+
if integrand(np.pi / 2) != 0.0:
|
| 400 |
+
res = optimize.minimize(
|
| 401 |
+
integrand,
|
| 402 |
+
(np.pi / 2,),
|
| 403 |
+
method="L-BFGS-B",
|
| 404 |
+
bounds=[(-xi, np.pi / 2)],
|
| 405 |
+
)
|
| 406 |
+
right_support = res.x[0]
|
| 407 |
+
|
| 408 |
+
intg, *ret = integrate.quad(
|
| 409 |
+
integrand,
|
| 410 |
+
left_support,
|
| 411 |
+
right_support,
|
| 412 |
+
points=[left_support, right_support],
|
| 413 |
+
limit=100,
|
| 414 |
+
epsrel=quad_eps,
|
| 415 |
+
epsabs=0,
|
| 416 |
+
full_output=1,
|
| 417 |
+
)
|
| 418 |
+
|
| 419 |
+
return c1 + c3 * intg
|
| 420 |
+
|
| 421 |
+
|
| 422 |
+
def _rvs_Z1(alpha, beta, size=None, random_state=None):
|
| 423 |
+
"""Simulate random variables using Nolan's methods as detailed in [NO].
|
| 424 |
+
"""
|
| 425 |
+
|
| 426 |
+
def alpha1func(alpha, beta, TH, aTH, bTH, cosTH, tanTH, W):
|
| 427 |
+
return (
|
| 428 |
+
2
|
| 429 |
+
/ np.pi
|
| 430 |
+
* (
|
| 431 |
+
(np.pi / 2 + bTH) * tanTH
|
| 432 |
+
- beta * np.log((np.pi / 2 * W * cosTH) / (np.pi / 2 + bTH))
|
| 433 |
+
)
|
| 434 |
+
)
|
| 435 |
+
|
| 436 |
+
def beta0func(alpha, beta, TH, aTH, bTH, cosTH, tanTH, W):
|
| 437 |
+
return (
|
| 438 |
+
W
|
| 439 |
+
/ (cosTH / np.tan(aTH) + np.sin(TH))
|
| 440 |
+
* ((np.cos(aTH) + np.sin(aTH) * tanTH) / W) ** (1.0 / alpha)
|
| 441 |
+
)
|
| 442 |
+
|
| 443 |
+
def otherwise(alpha, beta, TH, aTH, bTH, cosTH, tanTH, W):
|
| 444 |
+
# alpha is not 1 and beta is not 0
|
| 445 |
+
val0 = beta * np.tan(np.pi * alpha / 2)
|
| 446 |
+
th0 = np.arctan(val0) / alpha
|
| 447 |
+
val3 = W / (cosTH / np.tan(alpha * (th0 + TH)) + np.sin(TH))
|
| 448 |
+
res3 = val3 * (
|
| 449 |
+
(
|
| 450 |
+
np.cos(aTH)
|
| 451 |
+
+ np.sin(aTH) * tanTH
|
| 452 |
+
- val0 * (np.sin(aTH) - np.cos(aTH) * tanTH)
|
| 453 |
+
)
|
| 454 |
+
/ W
|
| 455 |
+
) ** (1.0 / alpha)
|
| 456 |
+
return res3
|
| 457 |
+
|
| 458 |
+
def alphanot1func(alpha, beta, TH, aTH, bTH, cosTH, tanTH, W):
|
| 459 |
+
res = _lazywhere(
|
| 460 |
+
beta == 0,
|
| 461 |
+
(alpha, beta, TH, aTH, bTH, cosTH, tanTH, W),
|
| 462 |
+
beta0func,
|
| 463 |
+
f2=otherwise,
|
| 464 |
+
)
|
| 465 |
+
return res
|
| 466 |
+
|
| 467 |
+
alpha = np.broadcast_to(alpha, size)
|
| 468 |
+
beta = np.broadcast_to(beta, size)
|
| 469 |
+
TH = uniform.rvs(
|
| 470 |
+
loc=-np.pi / 2.0, scale=np.pi, size=size, random_state=random_state
|
| 471 |
+
)
|
| 472 |
+
W = expon.rvs(size=size, random_state=random_state)
|
| 473 |
+
aTH = alpha * TH
|
| 474 |
+
bTH = beta * TH
|
| 475 |
+
cosTH = np.cos(TH)
|
| 476 |
+
tanTH = np.tan(TH)
|
| 477 |
+
res = _lazywhere(
|
| 478 |
+
alpha == 1,
|
| 479 |
+
(alpha, beta, TH, aTH, bTH, cosTH, tanTH, W),
|
| 480 |
+
alpha1func,
|
| 481 |
+
f2=alphanot1func,
|
| 482 |
+
)
|
| 483 |
+
return res
|
| 484 |
+
|
| 485 |
+
|
| 486 |
+
def _fitstart_S0(data):
|
| 487 |
+
alpha, beta, delta1, gamma = _fitstart_S1(data)
|
| 488 |
+
|
| 489 |
+
# Formulas for mapping parameters in S1 parameterization to
|
| 490 |
+
# those in S0 parameterization can be found in [NO]. Note that
|
| 491 |
+
# only delta changes.
|
| 492 |
+
if alpha != 1:
|
| 493 |
+
delta0 = delta1 + beta * gamma * np.tan(np.pi * alpha / 2.0)
|
| 494 |
+
else:
|
| 495 |
+
delta0 = delta1 + 2 * beta * gamma * np.log(gamma) / np.pi
|
| 496 |
+
|
| 497 |
+
return alpha, beta, delta0, gamma
|
| 498 |
+
|
| 499 |
+
|
| 500 |
+
def _fitstart_S1(data):
|
| 501 |
+
# We follow McCullock 1986 method - Simple Consistent Estimators
|
| 502 |
+
# of Stable Distribution Parameters
|
| 503 |
+
|
| 504 |
+
# fmt: off
|
| 505 |
+
# Table III and IV
|
| 506 |
+
nu_alpha_range = [2.439, 2.5, 2.6, 2.7, 2.8, 3, 3.2, 3.5, 4,
|
| 507 |
+
5, 6, 8, 10, 15, 25]
|
| 508 |
+
nu_beta_range = [0, 0.1, 0.2, 0.3, 0.5, 0.7, 1]
|
| 509 |
+
|
| 510 |
+
# table III - alpha = psi_1(nu_alpha, nu_beta)
|
| 511 |
+
alpha_table = np.array([
|
| 512 |
+
[2.000, 2.000, 2.000, 2.000, 2.000, 2.000, 2.000],
|
| 513 |
+
[1.916, 1.924, 1.924, 1.924, 1.924, 1.924, 1.924],
|
| 514 |
+
[1.808, 1.813, 1.829, 1.829, 1.829, 1.829, 1.829],
|
| 515 |
+
[1.729, 1.730, 1.737, 1.745, 1.745, 1.745, 1.745],
|
| 516 |
+
[1.664, 1.663, 1.663, 1.668, 1.676, 1.676, 1.676],
|
| 517 |
+
[1.563, 1.560, 1.553, 1.548, 1.547, 1.547, 1.547],
|
| 518 |
+
[1.484, 1.480, 1.471, 1.460, 1.448, 1.438, 1.438],
|
| 519 |
+
[1.391, 1.386, 1.378, 1.364, 1.337, 1.318, 1.318],
|
| 520 |
+
[1.279, 1.273, 1.266, 1.250, 1.210, 1.184, 1.150],
|
| 521 |
+
[1.128, 1.121, 1.114, 1.101, 1.067, 1.027, 0.973],
|
| 522 |
+
[1.029, 1.021, 1.014, 1.004, 0.974, 0.935, 0.874],
|
| 523 |
+
[0.896, 0.892, 0.884, 0.883, 0.855, 0.823, 0.769],
|
| 524 |
+
[0.818, 0.812, 0.806, 0.801, 0.780, 0.756, 0.691],
|
| 525 |
+
[0.698, 0.695, 0.692, 0.689, 0.676, 0.656, 0.597],
|
| 526 |
+
[0.593, 0.590, 0.588, 0.586, 0.579, 0.563, 0.513]]).T
|
| 527 |
+
# transpose because interpolation with `RectBivariateSpline` is with
|
| 528 |
+
# `nu_beta` as `x` and `nu_alpha` as `y`
|
| 529 |
+
|
| 530 |
+
# table IV - beta = psi_2(nu_alpha, nu_beta)
|
| 531 |
+
beta_table = np.array([
|
| 532 |
+
[0, 2.160, 1.000, 1.000, 1.000, 1.000, 1.000],
|
| 533 |
+
[0, 1.592, 3.390, 1.000, 1.000, 1.000, 1.000],
|
| 534 |
+
[0, 0.759, 1.800, 1.000, 1.000, 1.000, 1.000],
|
| 535 |
+
[0, 0.482, 1.048, 1.694, 1.000, 1.000, 1.000],
|
| 536 |
+
[0, 0.360, 0.760, 1.232, 2.229, 1.000, 1.000],
|
| 537 |
+
[0, 0.253, 0.518, 0.823, 1.575, 1.000, 1.000],
|
| 538 |
+
[0, 0.203, 0.410, 0.632, 1.244, 1.906, 1.000],
|
| 539 |
+
[0, 0.165, 0.332, 0.499, 0.943, 1.560, 1.000],
|
| 540 |
+
[0, 0.136, 0.271, 0.404, 0.689, 1.230, 2.195],
|
| 541 |
+
[0, 0.109, 0.216, 0.323, 0.539, 0.827, 1.917],
|
| 542 |
+
[0, 0.096, 0.190, 0.284, 0.472, 0.693, 1.759],
|
| 543 |
+
[0, 0.082, 0.163, 0.243, 0.412, 0.601, 1.596],
|
| 544 |
+
[0, 0.074, 0.147, 0.220, 0.377, 0.546, 1.482],
|
| 545 |
+
[0, 0.064, 0.128, 0.191, 0.330, 0.478, 1.362],
|
| 546 |
+
[0, 0.056, 0.112, 0.167, 0.285, 0.428, 1.274]]).T
|
| 547 |
+
|
| 548 |
+
# Table V and VII
|
| 549 |
+
# These are ordered with decreasing `alpha_range`; so we will need to
|
| 550 |
+
# reverse them as required by RectBivariateSpline.
|
| 551 |
+
alpha_range = [2, 1.9, 1.8, 1.7, 1.6, 1.5, 1.4, 1.3, 1.2, 1.1,
|
| 552 |
+
1, 0.9, 0.8, 0.7, 0.6, 0.5][::-1]
|
| 553 |
+
beta_range = [0, 0.25, 0.5, 0.75, 1]
|
| 554 |
+
|
| 555 |
+
# Table V - nu_c = psi_3(alpha, beta)
|
| 556 |
+
nu_c_table = np.array([
|
| 557 |
+
[1.908, 1.908, 1.908, 1.908, 1.908],
|
| 558 |
+
[1.914, 1.915, 1.916, 1.918, 1.921],
|
| 559 |
+
[1.921, 1.922, 1.927, 1.936, 1.947],
|
| 560 |
+
[1.927, 1.930, 1.943, 1.961, 1.987],
|
| 561 |
+
[1.933, 1.940, 1.962, 1.997, 2.043],
|
| 562 |
+
[1.939, 1.952, 1.988, 2.045, 2.116],
|
| 563 |
+
[1.946, 1.967, 2.022, 2.106, 2.211],
|
| 564 |
+
[1.955, 1.984, 2.067, 2.188, 2.333],
|
| 565 |
+
[1.965, 2.007, 2.125, 2.294, 2.491],
|
| 566 |
+
[1.980, 2.040, 2.205, 2.435, 2.696],
|
| 567 |
+
[2.000, 2.085, 2.311, 2.624, 2.973],
|
| 568 |
+
[2.040, 2.149, 2.461, 2.886, 3.356],
|
| 569 |
+
[2.098, 2.244, 2.676, 3.265, 3.912],
|
| 570 |
+
[2.189, 2.392, 3.004, 3.844, 4.775],
|
| 571 |
+
[2.337, 2.634, 3.542, 4.808, 6.247],
|
| 572 |
+
[2.588, 3.073, 4.534, 6.636, 9.144]])[::-1].T
|
| 573 |
+
# transpose because interpolation with `RectBivariateSpline` is with
|
| 574 |
+
# `beta` as `x` and `alpha` as `y`
|
| 575 |
+
|
| 576 |
+
# Table VII - nu_zeta = psi_5(alpha, beta)
|
| 577 |
+
nu_zeta_table = np.array([
|
| 578 |
+
[0, 0.000, 0.000, 0.000, 0.000],
|
| 579 |
+
[0, -0.017, -0.032, -0.049, -0.064],
|
| 580 |
+
[0, -0.030, -0.061, -0.092, -0.123],
|
| 581 |
+
[0, -0.043, -0.088, -0.132, -0.179],
|
| 582 |
+
[0, -0.056, -0.111, -0.170, -0.232],
|
| 583 |
+
[0, -0.066, -0.134, -0.206, -0.283],
|
| 584 |
+
[0, -0.075, -0.154, -0.241, -0.335],
|
| 585 |
+
[0, -0.084, -0.173, -0.276, -0.390],
|
| 586 |
+
[0, -0.090, -0.192, -0.310, -0.447],
|
| 587 |
+
[0, -0.095, -0.208, -0.346, -0.508],
|
| 588 |
+
[0, -0.098, -0.223, -0.380, -0.576],
|
| 589 |
+
[0, -0.099, -0.237, -0.424, -0.652],
|
| 590 |
+
[0, -0.096, -0.250, -0.469, -0.742],
|
| 591 |
+
[0, -0.089, -0.262, -0.520, -0.853],
|
| 592 |
+
[0, -0.078, -0.272, -0.581, -0.997],
|
| 593 |
+
[0, -0.061, -0.279, -0.659, -1.198]])[::-1].T
|
| 594 |
+
# fmt: on
|
| 595 |
+
|
| 596 |
+
psi_1 = RectBivariateSpline(nu_beta_range, nu_alpha_range,
|
| 597 |
+
alpha_table, kx=1, ky=1, s=0)
|
| 598 |
+
|
| 599 |
+
def psi_1_1(nu_beta, nu_alpha):
|
| 600 |
+
return psi_1(nu_beta, nu_alpha) \
|
| 601 |
+
if nu_beta > 0 else psi_1(-nu_beta, nu_alpha)
|
| 602 |
+
|
| 603 |
+
psi_2 = RectBivariateSpline(nu_beta_range, nu_alpha_range,
|
| 604 |
+
beta_table, kx=1, ky=1, s=0)
|
| 605 |
+
|
| 606 |
+
def psi_2_1(nu_beta, nu_alpha):
|
| 607 |
+
return psi_2(nu_beta, nu_alpha) \
|
| 608 |
+
if nu_beta > 0 else -psi_2(-nu_beta, nu_alpha)
|
| 609 |
+
|
| 610 |
+
phi_3 = RectBivariateSpline(beta_range, alpha_range, nu_c_table,
|
| 611 |
+
kx=1, ky=1, s=0)
|
| 612 |
+
|
| 613 |
+
def phi_3_1(beta, alpha):
|
| 614 |
+
return phi_3(beta, alpha) if beta > 0 else phi_3(-beta, alpha)
|
| 615 |
+
|
| 616 |
+
phi_5 = RectBivariateSpline(beta_range, alpha_range, nu_zeta_table,
|
| 617 |
+
kx=1, ky=1, s=0)
|
| 618 |
+
|
| 619 |
+
def phi_5_1(beta, alpha):
|
| 620 |
+
return phi_5(beta, alpha) if beta > 0 else -phi_5(-beta, alpha)
|
| 621 |
+
|
| 622 |
+
# quantiles
|
| 623 |
+
p05 = np.percentile(data, 5)
|
| 624 |
+
p50 = np.percentile(data, 50)
|
| 625 |
+
p95 = np.percentile(data, 95)
|
| 626 |
+
p25 = np.percentile(data, 25)
|
| 627 |
+
p75 = np.percentile(data, 75)
|
| 628 |
+
|
| 629 |
+
nu_alpha = (p95 - p05) / (p75 - p25)
|
| 630 |
+
nu_beta = (p95 + p05 - 2 * p50) / (p95 - p05)
|
| 631 |
+
|
| 632 |
+
if nu_alpha >= 2.439:
|
| 633 |
+
eps = np.finfo(float).eps
|
| 634 |
+
alpha = np.clip(psi_1_1(nu_beta, nu_alpha)[0, 0], eps, 2.)
|
| 635 |
+
beta = np.clip(psi_2_1(nu_beta, nu_alpha)[0, 0], -1.0, 1.0)
|
| 636 |
+
else:
|
| 637 |
+
alpha = 2.0
|
| 638 |
+
beta = np.sign(nu_beta)
|
| 639 |
+
c = (p75 - p25) / phi_3_1(beta, alpha)[0, 0]
|
| 640 |
+
zeta = p50 + c * phi_5_1(beta, alpha)[0, 0]
|
| 641 |
+
delta = zeta-beta*c*np.tan(np.pi*alpha/2.) if alpha != 1. else zeta
|
| 642 |
+
|
| 643 |
+
return (alpha, beta, delta, c)
|
| 644 |
+
|
| 645 |
+
|
| 646 |
+
class levy_stable_gen(rv_continuous):
|
| 647 |
+
r"""A Levy-stable continuous random variable.
|
| 648 |
+
|
| 649 |
+
%(before_notes)s
|
| 650 |
+
|
| 651 |
+
See Also
|
| 652 |
+
--------
|
| 653 |
+
levy, levy_l, cauchy, norm
|
| 654 |
+
|
| 655 |
+
Notes
|
| 656 |
+
-----
|
| 657 |
+
The distribution for `levy_stable` has characteristic function:
|
| 658 |
+
|
| 659 |
+
.. math::
|
| 660 |
+
|
| 661 |
+
\varphi(t, \alpha, \beta, c, \mu) =
|
| 662 |
+
e^{it\mu -|ct|^{\alpha}(1-i\beta\operatorname{sign}(t)\Phi(\alpha, t))}
|
| 663 |
+
|
| 664 |
+
where two different parameterizations are supported. The first :math:`S_1`:
|
| 665 |
+
|
| 666 |
+
.. math::
|
| 667 |
+
|
| 668 |
+
\Phi = \begin{cases}
|
| 669 |
+
\tan \left({\frac {\pi \alpha }{2}}\right)&\alpha \neq 1\\
|
| 670 |
+
-{\frac {2}{\pi }}\log |t|&\alpha =1
|
| 671 |
+
\end{cases}
|
| 672 |
+
|
| 673 |
+
The second :math:`S_0`:
|
| 674 |
+
|
| 675 |
+
.. math::
|
| 676 |
+
|
| 677 |
+
\Phi = \begin{cases}
|
| 678 |
+
-\tan \left({\frac {\pi \alpha }{2}}\right)(|ct|^{1-\alpha}-1)
|
| 679 |
+
&\alpha \neq 1\\
|
| 680 |
+
-{\frac {2}{\pi }}\log |ct|&\alpha =1
|
| 681 |
+
\end{cases}
|
| 682 |
+
|
| 683 |
+
|
| 684 |
+
The probability density function for `levy_stable` is:
|
| 685 |
+
|
| 686 |
+
.. math::
|
| 687 |
+
|
| 688 |
+
f(x) = \frac{1}{2\pi}\int_{-\infty}^\infty \varphi(t)e^{-ixt}\,dt
|
| 689 |
+
|
| 690 |
+
where :math:`-\infty < t < \infty`. This integral does not have a known
|
| 691 |
+
closed form.
|
| 692 |
+
|
| 693 |
+
`levy_stable` generalizes several distributions. Where possible, they
|
| 694 |
+
should be used instead. Specifically, when the shape parameters
|
| 695 |
+
assume the values in the table below, the corresponding equivalent
|
| 696 |
+
distribution should be used.
|
| 697 |
+
|
| 698 |
+
========= ======== ===========
|
| 699 |
+
``alpha`` ``beta`` Equivalent
|
| 700 |
+
========= ======== ===========
|
| 701 |
+
1/2 -1 `levy_l`
|
| 702 |
+
1/2 1 `levy`
|
| 703 |
+
1 0 `cauchy`
|
| 704 |
+
2 any `norm` (with ``scale=sqrt(2)``)
|
| 705 |
+
========= ======== ===========
|
| 706 |
+
|
| 707 |
+
Evaluation of the pdf uses Nolan's piecewise integration approach with the
|
| 708 |
+
Zolotarev :math:`M` parameterization by default. There is also the option
|
| 709 |
+
to use direct numerical integration of the standard parameterization of the
|
| 710 |
+
characteristic function or to evaluate by taking the FFT of the
|
| 711 |
+
characteristic function.
|
| 712 |
+
|
| 713 |
+
The default method can changed by setting the class variable
|
| 714 |
+
``levy_stable.pdf_default_method`` to one of 'piecewise' for Nolan's
|
| 715 |
+
approach, 'dni' for direct numerical integration, or 'fft-simpson' for the
|
| 716 |
+
FFT based approach. For the sake of backwards compatibility, the methods
|
| 717 |
+
'best' and 'zolotarev' are equivalent to 'piecewise' and the method
|
| 718 |
+
'quadrature' is equivalent to 'dni'.
|
| 719 |
+
|
| 720 |
+
The parameterization can be changed by setting the class variable
|
| 721 |
+
``levy_stable.parameterization`` to either 'S0' or 'S1'.
|
| 722 |
+
The default is 'S1'.
|
| 723 |
+
|
| 724 |
+
To improve performance of piecewise and direct numerical integration one
|
| 725 |
+
can specify ``levy_stable.quad_eps`` (defaults to 1.2e-14). This is used
|
| 726 |
+
as both the absolute and relative quadrature tolerance for direct numerical
|
| 727 |
+
integration and as the relative quadrature tolerance for the piecewise
|
| 728 |
+
method. One can also specify ``levy_stable.piecewise_x_tol_near_zeta``
|
| 729 |
+
(defaults to 0.005) for how close x is to zeta before it is considered the
|
| 730 |
+
same as x [NO]. The exact check is
|
| 731 |
+
``abs(x0 - zeta) < piecewise_x_tol_near_zeta*alpha**(1/alpha)``. One can
|
| 732 |
+
also specify ``levy_stable.piecewise_alpha_tol_near_one`` (defaults to
|
| 733 |
+
0.005) for how close alpha is to 1 before being considered equal to 1.
|
| 734 |
+
|
| 735 |
+
To increase accuracy of FFT calculation one can specify
|
| 736 |
+
``levy_stable.pdf_fft_grid_spacing`` (defaults to 0.001) and
|
| 737 |
+
``pdf_fft_n_points_two_power`` (defaults to None which means a value is
|
| 738 |
+
calculated that sufficiently covers the input range).
|
| 739 |
+
|
| 740 |
+
Further control over FFT calculation is available by setting
|
| 741 |
+
``pdf_fft_interpolation_degree`` (defaults to 3) for spline order and
|
| 742 |
+
``pdf_fft_interpolation_level`` for determining the number of points to use
|
| 743 |
+
in the Newton-Cotes formula when approximating the characteristic function
|
| 744 |
+
(considered experimental).
|
| 745 |
+
|
| 746 |
+
Evaluation of the cdf uses Nolan's piecewise integration approach with the
|
| 747 |
+
Zolatarev :math:`S_0` parameterization by default. There is also the option
|
| 748 |
+
to evaluate through integration of an interpolated spline of the pdf
|
| 749 |
+
calculated by means of the FFT method. The settings affecting FFT
|
| 750 |
+
calculation are the same as for pdf calculation. The default cdf method can
|
| 751 |
+
be changed by setting ``levy_stable.cdf_default_method`` to either
|
| 752 |
+
'piecewise' or 'fft-simpson'. For cdf calculations the Zolatarev method is
|
| 753 |
+
superior in accuracy, so FFT is disabled by default.
|
| 754 |
+
|
| 755 |
+
Fitting estimate uses quantile estimation method in [MC]. MLE estimation of
|
| 756 |
+
parameters in fit method uses this quantile estimate initially. Note that
|
| 757 |
+
MLE doesn't always converge if using FFT for pdf calculations; this will be
|
| 758 |
+
the case if alpha <= 1 where the FFT approach doesn't give good
|
| 759 |
+
approximations.
|
| 760 |
+
|
| 761 |
+
Any non-missing value for the attribute
|
| 762 |
+
``levy_stable.pdf_fft_min_points_threshold`` will set
|
| 763 |
+
``levy_stable.pdf_default_method`` to 'fft-simpson' if a valid
|
| 764 |
+
default method is not otherwise set.
|
| 765 |
+
|
| 766 |
+
|
| 767 |
+
|
| 768 |
+
.. warning::
|
| 769 |
+
|
| 770 |
+
For pdf calculations FFT calculation is considered experimental.
|
| 771 |
+
|
| 772 |
+
For cdf calculations FFT calculation is considered experimental. Use
|
| 773 |
+
Zolatarev's method instead (default).
|
| 774 |
+
|
| 775 |
+
The probability density above is defined in the "standardized" form. To
|
| 776 |
+
shift and/or scale the distribution use the ``loc`` and ``scale``
|
| 777 |
+
parameters.
|
| 778 |
+
Generally ``%(name)s.pdf(x, %(shapes)s, loc, scale)`` is identically
|
| 779 |
+
equivalent to ``%(name)s.pdf(y, %(shapes)s) / scale`` with
|
| 780 |
+
``y = (x - loc) / scale``, except in the ``S1`` parameterization if
|
| 781 |
+
``alpha == 1``. In that case ``%(name)s.pdf(x, %(shapes)s, loc, scale)``
|
| 782 |
+
is identically equivalent to ``%(name)s.pdf(y, %(shapes)s) / scale`` with
|
| 783 |
+
``y = (x - loc - 2 * beta * scale * np.log(scale) / np.pi) / scale``.
|
| 784 |
+
See [NO2]_ Definition 1.8 for more information.
|
| 785 |
+
Note that shifting the location of a distribution
|
| 786 |
+
does not make it a "noncentral" distribution.
|
| 787 |
+
|
| 788 |
+
References
|
| 789 |
+
----------
|
| 790 |
+
.. [MC] McCulloch, J., 1986. Simple consistent estimators of stable
|
| 791 |
+
distribution parameters. Communications in Statistics - Simulation and
|
| 792 |
+
Computation 15, 11091136.
|
| 793 |
+
.. [WZ] Wang, Li and Zhang, Ji-Hong, 2008. Simpson's rule based FFT method
|
| 794 |
+
to compute densities of stable distribution.
|
| 795 |
+
.. [NO] Nolan, J., 1997. Numerical Calculation of Stable Densities and
|
| 796 |
+
distributions Functions.
|
| 797 |
+
.. [NO2] Nolan, J., 2018. Stable Distributions: Models for Heavy Tailed
|
| 798 |
+
Data.
|
| 799 |
+
.. [HO] Hopcraft, K. I., Jakeman, E., Tanner, R. M. J., 1999. Lévy random
|
| 800 |
+
walks with fluctuating step number and multiscale behavior.
|
| 801 |
+
|
| 802 |
+
%(example)s
|
| 803 |
+
|
| 804 |
+
"""
|
| 805 |
+
# Configurable options as class variables
|
| 806 |
+
# (accessible from self by attribute lookup).
|
| 807 |
+
parameterization = "S1"
|
| 808 |
+
pdf_default_method = "piecewise"
|
| 809 |
+
cdf_default_method = "piecewise"
|
| 810 |
+
quad_eps = _QUAD_EPS
|
| 811 |
+
piecewise_x_tol_near_zeta = 0.005
|
| 812 |
+
piecewise_alpha_tol_near_one = 0.005
|
| 813 |
+
pdf_fft_min_points_threshold = None
|
| 814 |
+
pdf_fft_grid_spacing = 0.001
|
| 815 |
+
pdf_fft_n_points_two_power = None
|
| 816 |
+
pdf_fft_interpolation_level = 3
|
| 817 |
+
pdf_fft_interpolation_degree = 3
|
| 818 |
+
|
| 819 |
+
def __call__(self, *args, **params):
|
| 820 |
+
dist = levy_stable_frozen(self, *args, **params)
|
| 821 |
+
dist.parameterization = self.parameterization
|
| 822 |
+
return dist
|
| 823 |
+
|
| 824 |
+
def _argcheck(self, alpha, beta):
|
| 825 |
+
return (alpha > 0) & (alpha <= 2) & (beta <= 1) & (beta >= -1)
|
| 826 |
+
|
| 827 |
+
def _shape_info(self):
|
| 828 |
+
ialpha = _ShapeInfo("alpha", False, (0, 2), (False, True))
|
| 829 |
+
ibeta = _ShapeInfo("beta", False, (-1, 1), (True, True))
|
| 830 |
+
return [ialpha, ibeta]
|
| 831 |
+
|
| 832 |
+
def _parameterization(self):
|
| 833 |
+
allowed = ("S0", "S1")
|
| 834 |
+
pz = self.parameterization
|
| 835 |
+
if pz not in allowed:
|
| 836 |
+
raise RuntimeError(
|
| 837 |
+
f"Parameterization '{pz}' in supported list: {allowed}"
|
| 838 |
+
)
|
| 839 |
+
return pz
|
| 840 |
+
|
| 841 |
+
@inherit_docstring_from(rv_continuous)
|
| 842 |
+
def rvs(self, *args, **kwds):
|
| 843 |
+
X1 = super().rvs(*args, **kwds)
|
| 844 |
+
|
| 845 |
+
kwds.pop("discrete", None)
|
| 846 |
+
kwds.pop("random_state", None)
|
| 847 |
+
(alpha, beta), delta, gamma, size = self._parse_args_rvs(*args, **kwds)
|
| 848 |
+
|
| 849 |
+
# shift location for this parameterisation (S1)
|
| 850 |
+
X1 = np.where(
|
| 851 |
+
alpha == 1.0, X1 + 2 * beta * gamma * np.log(gamma) / np.pi, X1
|
| 852 |
+
)
|
| 853 |
+
|
| 854 |
+
if self._parameterization() == "S0":
|
| 855 |
+
return np.where(
|
| 856 |
+
alpha == 1.0,
|
| 857 |
+
X1 - (beta * 2 * gamma * np.log(gamma) / np.pi),
|
| 858 |
+
X1 - gamma * beta * np.tan(np.pi * alpha / 2.0),
|
| 859 |
+
)
|
| 860 |
+
elif self._parameterization() == "S1":
|
| 861 |
+
return X1
|
| 862 |
+
|
| 863 |
+
def _rvs(self, alpha, beta, size=None, random_state=None):
|
| 864 |
+
return _rvs_Z1(alpha, beta, size, random_state)
|
| 865 |
+
|
| 866 |
+
@inherit_docstring_from(rv_continuous)
|
| 867 |
+
def pdf(self, x, *args, **kwds):
|
| 868 |
+
# override base class version to correct
|
| 869 |
+
# location for S1 parameterization
|
| 870 |
+
if self._parameterization() == "S0":
|
| 871 |
+
return super().pdf(x, *args, **kwds)
|
| 872 |
+
elif self._parameterization() == "S1":
|
| 873 |
+
(alpha, beta), delta, gamma = self._parse_args(*args, **kwds)
|
| 874 |
+
if np.all(np.reshape(alpha, (1, -1))[0, :] != 1):
|
| 875 |
+
return super().pdf(x, *args, **kwds)
|
| 876 |
+
else:
|
| 877 |
+
# correct location for this parameterisation
|
| 878 |
+
x = np.reshape(x, (1, -1))[0, :]
|
| 879 |
+
x, alpha, beta = np.broadcast_arrays(x, alpha, beta)
|
| 880 |
+
|
| 881 |
+
data_in = np.dstack((x, alpha, beta))[0]
|
| 882 |
+
data_out = np.empty(shape=(len(data_in), 1))
|
| 883 |
+
# group data in unique arrays of alpha, beta pairs
|
| 884 |
+
uniq_param_pairs = np.unique(data_in[:, 1:], axis=0)
|
| 885 |
+
for pair in uniq_param_pairs:
|
| 886 |
+
_alpha, _beta = pair
|
| 887 |
+
_delta = (
|
| 888 |
+
delta + 2 * _beta * gamma * np.log(gamma) / np.pi
|
| 889 |
+
if _alpha == 1.0
|
| 890 |
+
else delta
|
| 891 |
+
)
|
| 892 |
+
data_mask = np.all(data_in[:, 1:] == pair, axis=-1)
|
| 893 |
+
_x = data_in[data_mask, 0]
|
| 894 |
+
data_out[data_mask] = (
|
| 895 |
+
super()
|
| 896 |
+
.pdf(_x, _alpha, _beta, loc=_delta, scale=gamma)
|
| 897 |
+
.reshape(len(_x), 1)
|
| 898 |
+
)
|
| 899 |
+
output = data_out.T[0]
|
| 900 |
+
if output.shape == (1,):
|
| 901 |
+
return output[0]
|
| 902 |
+
return output
|
| 903 |
+
|
| 904 |
+
def _pdf(self, x, alpha, beta):
|
| 905 |
+
if self._parameterization() == "S0":
|
| 906 |
+
_pdf_single_value_piecewise = _pdf_single_value_piecewise_Z0
|
| 907 |
+
_pdf_single_value_cf_integrate = _pdf_single_value_cf_integrate_Z0
|
| 908 |
+
_cf = _cf_Z0
|
| 909 |
+
elif self._parameterization() == "S1":
|
| 910 |
+
_pdf_single_value_piecewise = _pdf_single_value_piecewise_Z1
|
| 911 |
+
_pdf_single_value_cf_integrate = _pdf_single_value_cf_integrate_Z1
|
| 912 |
+
_cf = _cf_Z1
|
| 913 |
+
|
| 914 |
+
x = np.asarray(x).reshape(1, -1)[0, :]
|
| 915 |
+
|
| 916 |
+
x, alpha, beta = np.broadcast_arrays(x, alpha, beta)
|
| 917 |
+
|
| 918 |
+
data_in = np.dstack((x, alpha, beta))[0]
|
| 919 |
+
data_out = np.empty(shape=(len(data_in), 1))
|
| 920 |
+
|
| 921 |
+
pdf_default_method_name = self.pdf_default_method
|
| 922 |
+
if pdf_default_method_name in ("piecewise", "best", "zolotarev"):
|
| 923 |
+
pdf_single_value_method = _pdf_single_value_piecewise
|
| 924 |
+
elif pdf_default_method_name in ("dni", "quadrature"):
|
| 925 |
+
pdf_single_value_method = _pdf_single_value_cf_integrate
|
| 926 |
+
elif (
|
| 927 |
+
pdf_default_method_name == "fft-simpson"
|
| 928 |
+
or self.pdf_fft_min_points_threshold is not None
|
| 929 |
+
):
|
| 930 |
+
pdf_single_value_method = None
|
| 931 |
+
|
| 932 |
+
pdf_single_value_kwds = {
|
| 933 |
+
"quad_eps": self.quad_eps,
|
| 934 |
+
"piecewise_x_tol_near_zeta": self.piecewise_x_tol_near_zeta,
|
| 935 |
+
"piecewise_alpha_tol_near_one": self.piecewise_alpha_tol_near_one,
|
| 936 |
+
}
|
| 937 |
+
|
| 938 |
+
fft_grid_spacing = self.pdf_fft_grid_spacing
|
| 939 |
+
fft_n_points_two_power = self.pdf_fft_n_points_two_power
|
| 940 |
+
fft_interpolation_level = self.pdf_fft_interpolation_level
|
| 941 |
+
fft_interpolation_degree = self.pdf_fft_interpolation_degree
|
| 942 |
+
|
| 943 |
+
# group data in unique arrays of alpha, beta pairs
|
| 944 |
+
uniq_param_pairs = np.unique(data_in[:, 1:], axis=0)
|
| 945 |
+
for pair in uniq_param_pairs:
|
| 946 |
+
data_mask = np.all(data_in[:, 1:] == pair, axis=-1)
|
| 947 |
+
data_subset = data_in[data_mask]
|
| 948 |
+
if pdf_single_value_method is not None:
|
| 949 |
+
data_out[data_mask] = np.array(
|
| 950 |
+
[
|
| 951 |
+
pdf_single_value_method(
|
| 952 |
+
_x, _alpha, _beta, **pdf_single_value_kwds
|
| 953 |
+
)
|
| 954 |
+
for _x, _alpha, _beta in data_subset
|
| 955 |
+
]
|
| 956 |
+
).reshape(len(data_subset), 1)
|
| 957 |
+
else:
|
| 958 |
+
warnings.warn(
|
| 959 |
+
"Density calculations experimental for FFT method."
|
| 960 |
+
+ " Use combination of piecewise and dni methods instead.",
|
| 961 |
+
RuntimeWarning, stacklevel=3,
|
| 962 |
+
)
|
| 963 |
+
_alpha, _beta = pair
|
| 964 |
+
_x = data_subset[:, (0,)]
|
| 965 |
+
|
| 966 |
+
if _alpha < 1.0:
|
| 967 |
+
raise RuntimeError(
|
| 968 |
+
"FFT method does not work well for alpha less than 1."
|
| 969 |
+
)
|
| 970 |
+
|
| 971 |
+
# need enough points to "cover" _x for interpolation
|
| 972 |
+
if fft_grid_spacing is None and fft_n_points_two_power is None:
|
| 973 |
+
raise ValueError(
|
| 974 |
+
"One of fft_grid_spacing or fft_n_points_two_power "
|
| 975 |
+
+ "needs to be set."
|
| 976 |
+
)
|
| 977 |
+
max_abs_x = np.max(np.abs(_x))
|
| 978 |
+
h = (
|
| 979 |
+
2 ** (3 - fft_n_points_two_power) * max_abs_x
|
| 980 |
+
if fft_grid_spacing is None
|
| 981 |
+
else fft_grid_spacing
|
| 982 |
+
)
|
| 983 |
+
q = (
|
| 984 |
+
np.ceil(np.log(2 * max_abs_x / h) / np.log(2)) + 2
|
| 985 |
+
if fft_n_points_two_power is None
|
| 986 |
+
else int(fft_n_points_two_power)
|
| 987 |
+
)
|
| 988 |
+
|
| 989 |
+
# for some parameters, the range of x can be quite
|
| 990 |
+
# large, let's choose an arbitrary cut off (8GB) to save on
|
| 991 |
+
# computer memory.
|
| 992 |
+
MAX_Q = 30
|
| 993 |
+
if q > MAX_Q:
|
| 994 |
+
raise RuntimeError(
|
| 995 |
+
"fft_n_points_two_power has a maximum "
|
| 996 |
+
+ f"value of {MAX_Q}"
|
| 997 |
+
)
|
| 998 |
+
|
| 999 |
+
density_x, density = pdf_from_cf_with_fft(
|
| 1000 |
+
lambda t: _cf(t, _alpha, _beta),
|
| 1001 |
+
h=h,
|
| 1002 |
+
q=q,
|
| 1003 |
+
level=fft_interpolation_level,
|
| 1004 |
+
)
|
| 1005 |
+
f = interpolate.InterpolatedUnivariateSpline(
|
| 1006 |
+
density_x, np.real(density), k=fft_interpolation_degree
|
| 1007 |
+
) # patch FFT to use cubic
|
| 1008 |
+
data_out[data_mask] = f(_x)
|
| 1009 |
+
|
| 1010 |
+
return data_out.T[0]
|
| 1011 |
+
|
| 1012 |
+
@inherit_docstring_from(rv_continuous)
|
| 1013 |
+
def cdf(self, x, *args, **kwds):
|
| 1014 |
+
# override base class version to correct
|
| 1015 |
+
# location for S1 parameterization
|
| 1016 |
+
# NOTE: this is near identical to pdf() above
|
| 1017 |
+
if self._parameterization() == "S0":
|
| 1018 |
+
return super().cdf(x, *args, **kwds)
|
| 1019 |
+
elif self._parameterization() == "S1":
|
| 1020 |
+
(alpha, beta), delta, gamma = self._parse_args(*args, **kwds)
|
| 1021 |
+
if np.all(np.reshape(alpha, (1, -1))[0, :] != 1):
|
| 1022 |
+
return super().cdf(x, *args, **kwds)
|
| 1023 |
+
else:
|
| 1024 |
+
# correct location for this parameterisation
|
| 1025 |
+
x = np.reshape(x, (1, -1))[0, :]
|
| 1026 |
+
x, alpha, beta = np.broadcast_arrays(x, alpha, beta)
|
| 1027 |
+
|
| 1028 |
+
data_in = np.dstack((x, alpha, beta))[0]
|
| 1029 |
+
data_out = np.empty(shape=(len(data_in), 1))
|
| 1030 |
+
# group data in unique arrays of alpha, beta pairs
|
| 1031 |
+
uniq_param_pairs = np.unique(data_in[:, 1:], axis=0)
|
| 1032 |
+
for pair in uniq_param_pairs:
|
| 1033 |
+
_alpha, _beta = pair
|
| 1034 |
+
_delta = (
|
| 1035 |
+
delta + 2 * _beta * gamma * np.log(gamma) / np.pi
|
| 1036 |
+
if _alpha == 1.0
|
| 1037 |
+
else delta
|
| 1038 |
+
)
|
| 1039 |
+
data_mask = np.all(data_in[:, 1:] == pair, axis=-1)
|
| 1040 |
+
_x = data_in[data_mask, 0]
|
| 1041 |
+
data_out[data_mask] = (
|
| 1042 |
+
super()
|
| 1043 |
+
.cdf(_x, _alpha, _beta, loc=_delta, scale=gamma)
|
| 1044 |
+
.reshape(len(_x), 1)
|
| 1045 |
+
)
|
| 1046 |
+
output = data_out.T[0]
|
| 1047 |
+
if output.shape == (1,):
|
| 1048 |
+
return output[0]
|
| 1049 |
+
return output
|
| 1050 |
+
|
| 1051 |
+
def _cdf(self, x, alpha, beta):
|
| 1052 |
+
if self._parameterization() == "S0":
|
| 1053 |
+
_cdf_single_value_piecewise = _cdf_single_value_piecewise_Z0
|
| 1054 |
+
_cf = _cf_Z0
|
| 1055 |
+
elif self._parameterization() == "S1":
|
| 1056 |
+
_cdf_single_value_piecewise = _cdf_single_value_piecewise_Z1
|
| 1057 |
+
_cf = _cf_Z1
|
| 1058 |
+
|
| 1059 |
+
x = np.asarray(x).reshape(1, -1)[0, :]
|
| 1060 |
+
|
| 1061 |
+
x, alpha, beta = np.broadcast_arrays(x, alpha, beta)
|
| 1062 |
+
|
| 1063 |
+
data_in = np.dstack((x, alpha, beta))[0]
|
| 1064 |
+
data_out = np.empty(shape=(len(data_in), 1))
|
| 1065 |
+
|
| 1066 |
+
cdf_default_method_name = self.cdf_default_method
|
| 1067 |
+
if cdf_default_method_name == "piecewise":
|
| 1068 |
+
cdf_single_value_method = _cdf_single_value_piecewise
|
| 1069 |
+
elif cdf_default_method_name == "fft-simpson":
|
| 1070 |
+
cdf_single_value_method = None
|
| 1071 |
+
|
| 1072 |
+
cdf_single_value_kwds = {
|
| 1073 |
+
"quad_eps": self.quad_eps,
|
| 1074 |
+
"piecewise_x_tol_near_zeta": self.piecewise_x_tol_near_zeta,
|
| 1075 |
+
"piecewise_alpha_tol_near_one": self.piecewise_alpha_tol_near_one,
|
| 1076 |
+
}
|
| 1077 |
+
|
| 1078 |
+
fft_grid_spacing = self.pdf_fft_grid_spacing
|
| 1079 |
+
fft_n_points_two_power = self.pdf_fft_n_points_two_power
|
| 1080 |
+
fft_interpolation_level = self.pdf_fft_interpolation_level
|
| 1081 |
+
fft_interpolation_degree = self.pdf_fft_interpolation_degree
|
| 1082 |
+
|
| 1083 |
+
# group data in unique arrays of alpha, beta pairs
|
| 1084 |
+
uniq_param_pairs = np.unique(data_in[:, 1:], axis=0)
|
| 1085 |
+
for pair in uniq_param_pairs:
|
| 1086 |
+
data_mask = np.all(data_in[:, 1:] == pair, axis=-1)
|
| 1087 |
+
data_subset = data_in[data_mask]
|
| 1088 |
+
if cdf_single_value_method is not None:
|
| 1089 |
+
data_out[data_mask] = np.array(
|
| 1090 |
+
[
|
| 1091 |
+
cdf_single_value_method(
|
| 1092 |
+
_x, _alpha, _beta, **cdf_single_value_kwds
|
| 1093 |
+
)
|
| 1094 |
+
for _x, _alpha, _beta in data_subset
|
| 1095 |
+
]
|
| 1096 |
+
).reshape(len(data_subset), 1)
|
| 1097 |
+
else:
|
| 1098 |
+
warnings.warn(
|
| 1099 |
+
"Cumulative density calculations experimental for FFT"
|
| 1100 |
+
+ " method. Use piecewise method instead.",
|
| 1101 |
+
RuntimeWarning, stacklevel=3,
|
| 1102 |
+
)
|
| 1103 |
+
_alpha, _beta = pair
|
| 1104 |
+
_x = data_subset[:, (0,)]
|
| 1105 |
+
|
| 1106 |
+
# need enough points to "cover" _x for interpolation
|
| 1107 |
+
if fft_grid_spacing is None and fft_n_points_two_power is None:
|
| 1108 |
+
raise ValueError(
|
| 1109 |
+
"One of fft_grid_spacing or fft_n_points_two_power "
|
| 1110 |
+
+ "needs to be set."
|
| 1111 |
+
)
|
| 1112 |
+
max_abs_x = np.max(np.abs(_x))
|
| 1113 |
+
h = (
|
| 1114 |
+
2 ** (3 - fft_n_points_two_power) * max_abs_x
|
| 1115 |
+
if fft_grid_spacing is None
|
| 1116 |
+
else fft_grid_spacing
|
| 1117 |
+
)
|
| 1118 |
+
q = (
|
| 1119 |
+
np.ceil(np.log(2 * max_abs_x / h) / np.log(2)) + 2
|
| 1120 |
+
if fft_n_points_two_power is None
|
| 1121 |
+
else int(fft_n_points_two_power)
|
| 1122 |
+
)
|
| 1123 |
+
|
| 1124 |
+
density_x, density = pdf_from_cf_with_fft(
|
| 1125 |
+
lambda t: _cf(t, _alpha, _beta),
|
| 1126 |
+
h=h,
|
| 1127 |
+
q=q,
|
| 1128 |
+
level=fft_interpolation_level,
|
| 1129 |
+
)
|
| 1130 |
+
f = interpolate.InterpolatedUnivariateSpline(
|
| 1131 |
+
density_x, np.real(density), k=fft_interpolation_degree
|
| 1132 |
+
)
|
| 1133 |
+
data_out[data_mask] = np.array(
|
| 1134 |
+
[f.integral(self.a, float(x_1.squeeze())) for x_1 in _x]
|
| 1135 |
+
).reshape(data_out[data_mask].shape)
|
| 1136 |
+
|
| 1137 |
+
return data_out.T[0]
|
| 1138 |
+
|
| 1139 |
+
def _fitstart(self, data):
|
| 1140 |
+
if self._parameterization() == "S0":
|
| 1141 |
+
_fitstart = _fitstart_S0
|
| 1142 |
+
elif self._parameterization() == "S1":
|
| 1143 |
+
_fitstart = _fitstart_S1
|
| 1144 |
+
return _fitstart(data)
|
| 1145 |
+
|
| 1146 |
+
def _stats(self, alpha, beta):
|
| 1147 |
+
mu = 0 if alpha > 1 else np.nan
|
| 1148 |
+
mu2 = 2 if alpha == 2 else np.inf
|
| 1149 |
+
g1 = 0.0 if alpha == 2.0 else np.nan
|
| 1150 |
+
g2 = 0.0 if alpha == 2.0 else np.nan
|
| 1151 |
+
return mu, mu2, g1, g2
|
| 1152 |
+
|
| 1153 |
+
|
| 1154 |
+
# cotes numbers - see sequence from http://oeis.org/A100642
|
| 1155 |
+
Cotes_table = np.array(
|
| 1156 |
+
[[], [1]] + [v[2] for v in _builtincoeffs.values()], dtype=object
|
| 1157 |
+
)
|
| 1158 |
+
Cotes = np.array(
|
| 1159 |
+
[
|
| 1160 |
+
np.pad(r, (0, len(Cotes_table) - 1 - len(r)), mode='constant')
|
| 1161 |
+
for r in Cotes_table
|
| 1162 |
+
]
|
| 1163 |
+
)
|
| 1164 |
+
|
| 1165 |
+
|
| 1166 |
+
def pdf_from_cf_with_fft(cf, h=0.01, q=9, level=3):
|
| 1167 |
+
"""Calculates pdf from characteristic function.
|
| 1168 |
+
|
| 1169 |
+
Uses fast Fourier transform with Newton-Cotes integration following [WZ].
|
| 1170 |
+
Defaults to using Simpson's method (3-point Newton-Cotes integration).
|
| 1171 |
+
|
| 1172 |
+
Parameters
|
| 1173 |
+
----------
|
| 1174 |
+
cf : callable
|
| 1175 |
+
Single argument function from float -> complex expressing a
|
| 1176 |
+
characteristic function for some distribution.
|
| 1177 |
+
h : Optional[float]
|
| 1178 |
+
Step size for Newton-Cotes integration. Default: 0.01
|
| 1179 |
+
q : Optional[int]
|
| 1180 |
+
Use 2**q steps when performing Newton-Cotes integration.
|
| 1181 |
+
The infinite integral in the inverse Fourier transform will then
|
| 1182 |
+
be restricted to the interval [-2**q * h / 2, 2**q * h / 2]. Setting
|
| 1183 |
+
the number of steps equal to a power of 2 allows the fft to be
|
| 1184 |
+
calculated in O(n*log(n)) time rather than O(n**2).
|
| 1185 |
+
Default: 9
|
| 1186 |
+
level : Optional[int]
|
| 1187 |
+
Calculate integral using n-point Newton-Cotes integration for
|
| 1188 |
+
n = level. The 3-point Newton-Cotes formula corresponds to Simpson's
|
| 1189 |
+
rule. Default: 3
|
| 1190 |
+
|
| 1191 |
+
Returns
|
| 1192 |
+
-------
|
| 1193 |
+
x_l : ndarray
|
| 1194 |
+
Array of points x at which pdf is estimated. 2**q equally spaced
|
| 1195 |
+
points from -pi/h up to but not including pi/h.
|
| 1196 |
+
density : ndarray
|
| 1197 |
+
Estimated values of pdf corresponding to cf at points in x_l.
|
| 1198 |
+
|
| 1199 |
+
References
|
| 1200 |
+
----------
|
| 1201 |
+
.. [WZ] Wang, Li and Zhang, Ji-Hong, 2008. Simpson's rule based FFT method
|
| 1202 |
+
to compute densities of stable distribution.
|
| 1203 |
+
"""
|
| 1204 |
+
n = level
|
| 1205 |
+
N = 2**q
|
| 1206 |
+
steps = np.arange(0, N)
|
| 1207 |
+
L = N * h / 2
|
| 1208 |
+
x_l = np.pi * (steps - N / 2) / L
|
| 1209 |
+
if level > 1:
|
| 1210 |
+
indices = np.arange(n).reshape(n, 1)
|
| 1211 |
+
s1 = np.sum(
|
| 1212 |
+
(-1) ** steps * Cotes[n, indices] * np.fft.fft(
|
| 1213 |
+
(-1)**steps * cf(-L + h * steps + h * indices / (n - 1))
|
| 1214 |
+
) * np.exp(
|
| 1215 |
+
1j * np.pi * indices / (n - 1)
|
| 1216 |
+
- 2 * 1j * np.pi * indices * steps /
|
| 1217 |
+
(N * (n - 1))
|
| 1218 |
+
),
|
| 1219 |
+
axis=0
|
| 1220 |
+
)
|
| 1221 |
+
else:
|
| 1222 |
+
s1 = (-1) ** steps * Cotes[n, 0] * np.fft.fft(
|
| 1223 |
+
(-1) ** steps * cf(-L + h * steps)
|
| 1224 |
+
)
|
| 1225 |
+
density = h * s1 / (2 * np.pi * np.sum(Cotes[n]))
|
| 1226 |
+
return (x_l, density)
|
| 1227 |
+
|
| 1228 |
+
|
| 1229 |
+
levy_stable = levy_stable_gen(name="levy_stable")
|
| 1230 |
+
|
| 1231 |
+
|
| 1232 |
+
class levy_stable_frozen(rv_continuous_frozen):
|
| 1233 |
+
@property
|
| 1234 |
+
def parameterization(self):
|
| 1235 |
+
return self.dist.parameterization
|
| 1236 |
+
|
| 1237 |
+
@parameterization.setter
|
| 1238 |
+
def parameterization(self, value):
|
| 1239 |
+
self.dist.parameterization = value
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/_levy_stable/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (33.3 kB). View file
|
|
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/_levy_stable/levyst.cpython-310-x86_64-linux-gnu.so
ADDED
|
Binary file (66.5 kB). View file
|
|
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/_qmc_cy.cpython-310-x86_64-linux-gnu.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e6c6b8af5d83b62a559a26f491830e572e2bb55e436678d594175c8881e4892f
|
| 3 |
+
size 291104
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/_sobol.cpython-310-x86_64-linux-gnu.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6d52f27469b53d9dfd8ed9af1c245dcf4d2dc54a62d3a44181f14d7d013beedb
|
| 3 |
+
size 404048
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/_stats.cpython-310-x86_64-linux-gnu.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f9e29650334427d32b598e968b424b917ce22942679f86ff3c99212170271486
|
| 3 |
+
size 766544
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/_stats_pythran.cpython-310-x86_64-linux-gnu.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:433df3699d3ca5610697eeea3d2fcbadd6b70ccc6f2309e65bffc9e33b97aa56
|
| 3 |
+
size 182128
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/tests/data/jf_skew_t_gamlss_pdf_data.npy
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:254d2dee4a4d547b9331c60243c6fcfcaffd26c8b104d08d4f6045a7645b3bba
|
| 3 |
+
size 4064
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/tests/data/levy_stable/stable-Z1-cdf-sample-data.npy
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cf18c1f2d65a232bf2c7121282df31bf2a8be827afafc4ed810ed37457ee898a
|
| 3 |
+
size 183728
|
mantis_evalkit/lib/python3.10/site-packages/scipy/stats/tests/data/levy_stable/stable-Z1-pdf-sample-data.npy
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fee99512bab4ccc6569b47b924e4b034e1cdbab5624fafc7e120648bd5f7a128
|
| 3 |
+
size 183688
|