scipy 1.16.2__cp314-cp314t-win_arm64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- scipy/__config__.py +161 -0
- scipy/__init__.py +150 -0
- scipy/_cyutility.cp314t-win_arm64.lib +0 -0
- scipy/_cyutility.cp314t-win_arm64.pyd +0 -0
- scipy/_distributor_init.py +18 -0
- scipy/_lib/__init__.py +14 -0
- scipy/_lib/_array_api.py +931 -0
- scipy/_lib/_array_api_compat_vendor.py +9 -0
- scipy/_lib/_array_api_no_0d.py +103 -0
- scipy/_lib/_bunch.py +229 -0
- scipy/_lib/_ccallback.py +251 -0
- scipy/_lib/_ccallback_c.cp314t-win_arm64.lib +0 -0
- scipy/_lib/_ccallback_c.cp314t-win_arm64.pyd +0 -0
- scipy/_lib/_disjoint_set.py +254 -0
- scipy/_lib/_docscrape.py +761 -0
- scipy/_lib/_elementwise_iterative_method.py +346 -0
- scipy/_lib/_fpumode.cp314t-win_arm64.lib +0 -0
- scipy/_lib/_fpumode.cp314t-win_arm64.pyd +0 -0
- scipy/_lib/_gcutils.py +105 -0
- scipy/_lib/_pep440.py +487 -0
- scipy/_lib/_sparse.py +41 -0
- scipy/_lib/_test_ccallback.cp314t-win_arm64.lib +0 -0
- scipy/_lib/_test_ccallback.cp314t-win_arm64.pyd +0 -0
- scipy/_lib/_test_deprecation_call.cp314t-win_arm64.lib +0 -0
- scipy/_lib/_test_deprecation_call.cp314t-win_arm64.pyd +0 -0
- scipy/_lib/_test_deprecation_def.cp314t-win_arm64.lib +0 -0
- scipy/_lib/_test_deprecation_def.cp314t-win_arm64.pyd +0 -0
- scipy/_lib/_testutils.py +373 -0
- scipy/_lib/_threadsafety.py +58 -0
- scipy/_lib/_tmpdirs.py +86 -0
- scipy/_lib/_uarray/LICENSE +29 -0
- scipy/_lib/_uarray/__init__.py +116 -0
- scipy/_lib/_uarray/_backend.py +707 -0
- scipy/_lib/_uarray/_uarray.cp314t-win_arm64.lib +0 -0
- scipy/_lib/_uarray/_uarray.cp314t-win_arm64.pyd +0 -0
- scipy/_lib/_util.py +1283 -0
- scipy/_lib/array_api_compat/__init__.py +22 -0
- scipy/_lib/array_api_compat/_internal.py +59 -0
- scipy/_lib/array_api_compat/common/__init__.py +1 -0
- scipy/_lib/array_api_compat/common/_aliases.py +727 -0
- scipy/_lib/array_api_compat/common/_fft.py +213 -0
- scipy/_lib/array_api_compat/common/_helpers.py +1058 -0
- scipy/_lib/array_api_compat/common/_linalg.py +232 -0
- scipy/_lib/array_api_compat/common/_typing.py +192 -0
- scipy/_lib/array_api_compat/cupy/__init__.py +13 -0
- scipy/_lib/array_api_compat/cupy/_aliases.py +156 -0
- scipy/_lib/array_api_compat/cupy/_info.py +336 -0
- scipy/_lib/array_api_compat/cupy/_typing.py +31 -0
- scipy/_lib/array_api_compat/cupy/fft.py +36 -0
- scipy/_lib/array_api_compat/cupy/linalg.py +49 -0
- scipy/_lib/array_api_compat/dask/__init__.py +0 -0
- scipy/_lib/array_api_compat/dask/array/__init__.py +12 -0
- scipy/_lib/array_api_compat/dask/array/_aliases.py +376 -0
- scipy/_lib/array_api_compat/dask/array/_info.py +416 -0
- scipy/_lib/array_api_compat/dask/array/fft.py +21 -0
- scipy/_lib/array_api_compat/dask/array/linalg.py +72 -0
- scipy/_lib/array_api_compat/numpy/__init__.py +28 -0
- scipy/_lib/array_api_compat/numpy/_aliases.py +190 -0
- scipy/_lib/array_api_compat/numpy/_info.py +366 -0
- scipy/_lib/array_api_compat/numpy/_typing.py +30 -0
- scipy/_lib/array_api_compat/numpy/fft.py +35 -0
- scipy/_lib/array_api_compat/numpy/linalg.py +143 -0
- scipy/_lib/array_api_compat/torch/__init__.py +22 -0
- scipy/_lib/array_api_compat/torch/_aliases.py +855 -0
- scipy/_lib/array_api_compat/torch/_info.py +369 -0
- scipy/_lib/array_api_compat/torch/_typing.py +3 -0
- scipy/_lib/array_api_compat/torch/fft.py +85 -0
- scipy/_lib/array_api_compat/torch/linalg.py +121 -0
- scipy/_lib/array_api_extra/__init__.py +38 -0
- scipy/_lib/array_api_extra/_delegation.py +171 -0
- scipy/_lib/array_api_extra/_lib/__init__.py +1 -0
- scipy/_lib/array_api_extra/_lib/_at.py +463 -0
- scipy/_lib/array_api_extra/_lib/_backends.py +46 -0
- scipy/_lib/array_api_extra/_lib/_funcs.py +937 -0
- scipy/_lib/array_api_extra/_lib/_lazy.py +357 -0
- scipy/_lib/array_api_extra/_lib/_testing.py +278 -0
- scipy/_lib/array_api_extra/_lib/_utils/__init__.py +1 -0
- scipy/_lib/array_api_extra/_lib/_utils/_compat.py +74 -0
- scipy/_lib/array_api_extra/_lib/_utils/_compat.pyi +45 -0
- scipy/_lib/array_api_extra/_lib/_utils/_helpers.py +559 -0
- scipy/_lib/array_api_extra/_lib/_utils/_typing.py +10 -0
- scipy/_lib/array_api_extra/_lib/_utils/_typing.pyi +105 -0
- scipy/_lib/array_api_extra/testing.py +359 -0
- scipy/_lib/cobyqa/__init__.py +20 -0
- scipy/_lib/cobyqa/framework.py +1240 -0
- scipy/_lib/cobyqa/main.py +1506 -0
- scipy/_lib/cobyqa/models.py +1529 -0
- scipy/_lib/cobyqa/problem.py +1296 -0
- scipy/_lib/cobyqa/settings.py +132 -0
- scipy/_lib/cobyqa/subsolvers/__init__.py +14 -0
- scipy/_lib/cobyqa/subsolvers/geometry.py +387 -0
- scipy/_lib/cobyqa/subsolvers/optim.py +1203 -0
- scipy/_lib/cobyqa/utils/__init__.py +18 -0
- scipy/_lib/cobyqa/utils/exceptions.py +22 -0
- scipy/_lib/cobyqa/utils/math.py +77 -0
- scipy/_lib/cobyqa/utils/versions.py +67 -0
- scipy/_lib/decorator.py +399 -0
- scipy/_lib/deprecation.py +274 -0
- scipy/_lib/doccer.py +366 -0
- scipy/_lib/messagestream.cp314t-win_arm64.lib +0 -0
- scipy/_lib/messagestream.cp314t-win_arm64.pyd +0 -0
- scipy/_lib/pyprima/__init__.py +212 -0
- scipy/_lib/pyprima/cobyla/__init__.py +0 -0
- scipy/_lib/pyprima/cobyla/cobyla.py +559 -0
- scipy/_lib/pyprima/cobyla/cobylb.py +714 -0
- scipy/_lib/pyprima/cobyla/geometry.py +226 -0
- scipy/_lib/pyprima/cobyla/initialize.py +215 -0
- scipy/_lib/pyprima/cobyla/trustregion.py +492 -0
- scipy/_lib/pyprima/cobyla/update.py +289 -0
- scipy/_lib/pyprima/common/__init__.py +0 -0
- scipy/_lib/pyprima/common/_bounds.py +34 -0
- scipy/_lib/pyprima/common/_linear_constraints.py +46 -0
- scipy/_lib/pyprima/common/_nonlinear_constraints.py +54 -0
- scipy/_lib/pyprima/common/_project.py +173 -0
- scipy/_lib/pyprima/common/checkbreak.py +93 -0
- scipy/_lib/pyprima/common/consts.py +47 -0
- scipy/_lib/pyprima/common/evaluate.py +99 -0
- scipy/_lib/pyprima/common/history.py +38 -0
- scipy/_lib/pyprima/common/infos.py +30 -0
- scipy/_lib/pyprima/common/linalg.py +435 -0
- scipy/_lib/pyprima/common/message.py +290 -0
- scipy/_lib/pyprima/common/powalg.py +131 -0
- scipy/_lib/pyprima/common/preproc.py +277 -0
- scipy/_lib/pyprima/common/present.py +5 -0
- scipy/_lib/pyprima/common/ratio.py +54 -0
- scipy/_lib/pyprima/common/redrho.py +47 -0
- scipy/_lib/pyprima/common/selectx.py +296 -0
- scipy/_lib/tests/__init__.py +0 -0
- scipy/_lib/tests/test__gcutils.py +110 -0
- scipy/_lib/tests/test__pep440.py +67 -0
- scipy/_lib/tests/test__testutils.py +32 -0
- scipy/_lib/tests/test__threadsafety.py +51 -0
- scipy/_lib/tests/test__util.py +641 -0
- scipy/_lib/tests/test_array_api.py +322 -0
- scipy/_lib/tests/test_bunch.py +169 -0
- scipy/_lib/tests/test_ccallback.py +196 -0
- scipy/_lib/tests/test_config.py +45 -0
- scipy/_lib/tests/test_deprecation.py +10 -0
- scipy/_lib/tests/test_doccer.py +143 -0
- scipy/_lib/tests/test_import_cycles.py +18 -0
- scipy/_lib/tests/test_public_api.py +482 -0
- scipy/_lib/tests/test_scipy_version.py +28 -0
- scipy/_lib/tests/test_tmpdirs.py +48 -0
- scipy/_lib/tests/test_warnings.py +137 -0
- scipy/_lib/uarray.py +31 -0
- scipy/cluster/__init__.py +31 -0
- scipy/cluster/_hierarchy.cp314t-win_arm64.lib +0 -0
- scipy/cluster/_hierarchy.cp314t-win_arm64.pyd +0 -0
- scipy/cluster/_optimal_leaf_ordering.cp314t-win_arm64.lib +0 -0
- scipy/cluster/_optimal_leaf_ordering.cp314t-win_arm64.pyd +0 -0
- scipy/cluster/_vq.cp314t-win_arm64.lib +0 -0
- scipy/cluster/_vq.cp314t-win_arm64.pyd +0 -0
- scipy/cluster/hierarchy.py +4348 -0
- scipy/cluster/tests/__init__.py +0 -0
- scipy/cluster/tests/hierarchy_test_data.py +145 -0
- scipy/cluster/tests/test_disjoint_set.py +202 -0
- scipy/cluster/tests/test_hierarchy.py +1238 -0
- scipy/cluster/tests/test_vq.py +434 -0
- scipy/cluster/vq.py +832 -0
- scipy/conftest.py +683 -0
- scipy/constants/__init__.py +358 -0
- scipy/constants/_codata.py +2266 -0
- scipy/constants/_constants.py +369 -0
- scipy/constants/codata.py +21 -0
- scipy/constants/constants.py +53 -0
- scipy/constants/tests/__init__.py +0 -0
- scipy/constants/tests/test_codata.py +78 -0
- scipy/constants/tests/test_constants.py +83 -0
- scipy/datasets/__init__.py +90 -0
- scipy/datasets/_download_all.py +71 -0
- scipy/datasets/_fetchers.py +225 -0
- scipy/datasets/_registry.py +26 -0
- scipy/datasets/_utils.py +81 -0
- scipy/datasets/tests/__init__.py +0 -0
- scipy/datasets/tests/test_data.py +128 -0
- scipy/differentiate/__init__.py +27 -0
- scipy/differentiate/_differentiate.py +1129 -0
- scipy/differentiate/tests/__init__.py +0 -0
- scipy/differentiate/tests/test_differentiate.py +694 -0
- scipy/fft/__init__.py +114 -0
- scipy/fft/_backend.py +196 -0
- scipy/fft/_basic.py +1650 -0
- scipy/fft/_basic_backend.py +197 -0
- scipy/fft/_debug_backends.py +22 -0
- scipy/fft/_fftlog.py +223 -0
- scipy/fft/_fftlog_backend.py +200 -0
- scipy/fft/_helper.py +348 -0
- scipy/fft/_pocketfft/LICENSE.md +25 -0
- scipy/fft/_pocketfft/__init__.py +9 -0
- scipy/fft/_pocketfft/basic.py +251 -0
- scipy/fft/_pocketfft/helper.py +249 -0
- scipy/fft/_pocketfft/pypocketfft.cp314t-win_arm64.lib +0 -0
- scipy/fft/_pocketfft/pypocketfft.cp314t-win_arm64.pyd +0 -0
- scipy/fft/_pocketfft/realtransforms.py +109 -0
- scipy/fft/_pocketfft/tests/__init__.py +0 -0
- scipy/fft/_pocketfft/tests/test_basic.py +1011 -0
- scipy/fft/_pocketfft/tests/test_real_transforms.py +505 -0
- scipy/fft/_realtransforms.py +706 -0
- scipy/fft/_realtransforms_backend.py +63 -0
- scipy/fft/tests/__init__.py +0 -0
- scipy/fft/tests/mock_backend.py +96 -0
- scipy/fft/tests/test_backend.py +98 -0
- scipy/fft/tests/test_basic.py +504 -0
- scipy/fft/tests/test_fftlog.py +215 -0
- scipy/fft/tests/test_helper.py +558 -0
- scipy/fft/tests/test_multithreading.py +84 -0
- scipy/fft/tests/test_real_transforms.py +247 -0
- scipy/fftpack/__init__.py +103 -0
- scipy/fftpack/_basic.py +428 -0
- scipy/fftpack/_helper.py +115 -0
- scipy/fftpack/_pseudo_diffs.py +554 -0
- scipy/fftpack/_realtransforms.py +598 -0
- scipy/fftpack/basic.py +20 -0
- scipy/fftpack/convolve.cp314t-win_arm64.lib +0 -0
- scipy/fftpack/convolve.cp314t-win_arm64.pyd +0 -0
- scipy/fftpack/helper.py +19 -0
- scipy/fftpack/pseudo_diffs.py +22 -0
- scipy/fftpack/realtransforms.py +19 -0
- scipy/fftpack/tests/__init__.py +0 -0
- scipy/fftpack/tests/fftw_double_ref.npz +0 -0
- scipy/fftpack/tests/fftw_longdouble_ref.npz +0 -0
- scipy/fftpack/tests/fftw_single_ref.npz +0 -0
- scipy/fftpack/tests/test.npz +0 -0
- scipy/fftpack/tests/test_basic.py +877 -0
- scipy/fftpack/tests/test_helper.py +54 -0
- scipy/fftpack/tests/test_import.py +33 -0
- scipy/fftpack/tests/test_pseudo_diffs.py +388 -0
- scipy/fftpack/tests/test_real_transforms.py +836 -0
- scipy/integrate/__init__.py +122 -0
- scipy/integrate/_bvp.py +1160 -0
- scipy/integrate/_cubature.py +729 -0
- scipy/integrate/_dop.cp314t-win_arm64.lib +0 -0
- scipy/integrate/_dop.cp314t-win_arm64.pyd +0 -0
- scipy/integrate/_ivp/__init__.py +8 -0
- scipy/integrate/_ivp/base.py +290 -0
- scipy/integrate/_ivp/bdf.py +478 -0
- scipy/integrate/_ivp/common.py +451 -0
- scipy/integrate/_ivp/dop853_coefficients.py +193 -0
- scipy/integrate/_ivp/ivp.py +755 -0
- scipy/integrate/_ivp/lsoda.py +224 -0
- scipy/integrate/_ivp/radau.py +572 -0
- scipy/integrate/_ivp/rk.py +601 -0
- scipy/integrate/_ivp/tests/__init__.py +0 -0
- scipy/integrate/_ivp/tests/test_ivp.py +1287 -0
- scipy/integrate/_ivp/tests/test_rk.py +37 -0
- scipy/integrate/_lebedev.py +5450 -0
- scipy/integrate/_lsoda.cp314t-win_arm64.lib +0 -0
- scipy/integrate/_lsoda.cp314t-win_arm64.pyd +0 -0
- scipy/integrate/_ode.py +1395 -0
- scipy/integrate/_odepack.cp314t-win_arm64.lib +0 -0
- scipy/integrate/_odepack.cp314t-win_arm64.pyd +0 -0
- scipy/integrate/_odepack_py.py +273 -0
- scipy/integrate/_quad_vec.py +674 -0
- scipy/integrate/_quadpack.cp314t-win_arm64.lib +0 -0
- scipy/integrate/_quadpack.cp314t-win_arm64.pyd +0 -0
- scipy/integrate/_quadpack_py.py +1283 -0
- scipy/integrate/_quadrature.py +1336 -0
- scipy/integrate/_rules/__init__.py +12 -0
- scipy/integrate/_rules/_base.py +518 -0
- scipy/integrate/_rules/_gauss_kronrod.py +202 -0
- scipy/integrate/_rules/_gauss_legendre.py +62 -0
- scipy/integrate/_rules/_genz_malik.py +210 -0
- scipy/integrate/_tanhsinh.py +1385 -0
- scipy/integrate/_test_multivariate.cp314t-win_arm64.lib +0 -0
- scipy/integrate/_test_multivariate.cp314t-win_arm64.pyd +0 -0
- scipy/integrate/_test_odeint_banded.cp314t-win_arm64.lib +0 -0
- scipy/integrate/_test_odeint_banded.cp314t-win_arm64.pyd +0 -0
- scipy/integrate/_vode.cp314t-win_arm64.lib +0 -0
- scipy/integrate/_vode.cp314t-win_arm64.pyd +0 -0
- scipy/integrate/dop.py +15 -0
- scipy/integrate/lsoda.py +15 -0
- scipy/integrate/odepack.py +17 -0
- scipy/integrate/quadpack.py +23 -0
- scipy/integrate/tests/__init__.py +0 -0
- scipy/integrate/tests/test__quad_vec.py +211 -0
- scipy/integrate/tests/test_banded_ode_solvers.py +305 -0
- scipy/integrate/tests/test_bvp.py +714 -0
- scipy/integrate/tests/test_cubature.py +1375 -0
- scipy/integrate/tests/test_integrate.py +840 -0
- scipy/integrate/tests/test_odeint_jac.py +74 -0
- scipy/integrate/tests/test_quadpack.py +680 -0
- scipy/integrate/tests/test_quadrature.py +730 -0
- scipy/integrate/tests/test_tanhsinh.py +1171 -0
- scipy/integrate/vode.py +15 -0
- scipy/interpolate/__init__.py +228 -0
- scipy/interpolate/_bary_rational.py +715 -0
- scipy/interpolate/_bsplines.py +2469 -0
- scipy/interpolate/_cubic.py +973 -0
- scipy/interpolate/_dfitpack.cp314t-win_arm64.lib +0 -0
- scipy/interpolate/_dfitpack.cp314t-win_arm64.pyd +0 -0
- scipy/interpolate/_dierckx.cp314t-win_arm64.lib +0 -0
- scipy/interpolate/_dierckx.cp314t-win_arm64.pyd +0 -0
- scipy/interpolate/_fitpack.cp314t-win_arm64.lib +0 -0
- scipy/interpolate/_fitpack.cp314t-win_arm64.pyd +0 -0
- scipy/interpolate/_fitpack2.py +2397 -0
- scipy/interpolate/_fitpack_impl.py +811 -0
- scipy/interpolate/_fitpack_py.py +898 -0
- scipy/interpolate/_fitpack_repro.py +996 -0
- scipy/interpolate/_interpnd.cp314t-win_arm64.lib +0 -0
- scipy/interpolate/_interpnd.cp314t-win_arm64.pyd +0 -0
- scipy/interpolate/_interpolate.py +2266 -0
- scipy/interpolate/_ndbspline.py +415 -0
- scipy/interpolate/_ndgriddata.py +329 -0
- scipy/interpolate/_pade.py +67 -0
- scipy/interpolate/_polyint.py +1025 -0
- scipy/interpolate/_ppoly.cp314t-win_arm64.lib +0 -0
- scipy/interpolate/_ppoly.cp314t-win_arm64.pyd +0 -0
- scipy/interpolate/_rbf.py +290 -0
- scipy/interpolate/_rbfinterp.py +550 -0
- scipy/interpolate/_rbfinterp_pythran.cp314t-win_arm64.lib +0 -0
- scipy/interpolate/_rbfinterp_pythran.cp314t-win_arm64.pyd +0 -0
- scipy/interpolate/_rgi.py +764 -0
- scipy/interpolate/_rgi_cython.cp314t-win_arm64.lib +0 -0
- scipy/interpolate/_rgi_cython.cp314t-win_arm64.pyd +0 -0
- scipy/interpolate/dfitpack.py +24 -0
- scipy/interpolate/fitpack.py +31 -0
- scipy/interpolate/fitpack2.py +29 -0
- scipy/interpolate/interpnd.py +24 -0
- scipy/interpolate/interpolate.py +30 -0
- scipy/interpolate/ndgriddata.py +23 -0
- scipy/interpolate/polyint.py +24 -0
- scipy/interpolate/rbf.py +18 -0
- scipy/interpolate/tests/__init__.py +0 -0
- scipy/interpolate/tests/data/bug-1310.npz +0 -0
- scipy/interpolate/tests/data/estimate_gradients_hang.npy +0 -0
- scipy/interpolate/tests/data/gcvspl.npz +0 -0
- scipy/interpolate/tests/test_bary_rational.py +368 -0
- scipy/interpolate/tests/test_bsplines.py +3754 -0
- scipy/interpolate/tests/test_fitpack.py +519 -0
- scipy/interpolate/tests/test_fitpack2.py +1431 -0
- scipy/interpolate/tests/test_gil.py +64 -0
- scipy/interpolate/tests/test_interpnd.py +452 -0
- scipy/interpolate/tests/test_interpolate.py +2630 -0
- scipy/interpolate/tests/test_ndgriddata.py +308 -0
- scipy/interpolate/tests/test_pade.py +107 -0
- scipy/interpolate/tests/test_polyint.py +972 -0
- scipy/interpolate/tests/test_rbf.py +246 -0
- scipy/interpolate/tests/test_rbfinterp.py +534 -0
- scipy/interpolate/tests/test_rgi.py +1151 -0
- scipy/io/__init__.py +116 -0
- scipy/io/_fast_matrix_market/__init__.py +600 -0
- scipy/io/_fast_matrix_market/_fmm_core.cp314t-win_arm64.lib +0 -0
- scipy/io/_fast_matrix_market/_fmm_core.cp314t-win_arm64.pyd +0 -0
- scipy/io/_fortran.py +354 -0
- scipy/io/_harwell_boeing/__init__.py +7 -0
- scipy/io/_harwell_boeing/_fortran_format_parser.py +316 -0
- scipy/io/_harwell_boeing/hb.py +571 -0
- scipy/io/_harwell_boeing/tests/__init__.py +0 -0
- scipy/io/_harwell_boeing/tests/test_fortran_format.py +74 -0
- scipy/io/_harwell_boeing/tests/test_hb.py +70 -0
- scipy/io/_idl.py +917 -0
- scipy/io/_mmio.py +968 -0
- scipy/io/_netcdf.py +1104 -0
- scipy/io/_test_fortran.cp314t-win_arm64.lib +0 -0
- scipy/io/_test_fortran.cp314t-win_arm64.pyd +0 -0
- scipy/io/arff/__init__.py +28 -0
- scipy/io/arff/_arffread.py +873 -0
- scipy/io/arff/arffread.py +19 -0
- scipy/io/arff/tests/__init__.py +0 -0
- scipy/io/arff/tests/data/iris.arff +225 -0
- scipy/io/arff/tests/data/missing.arff +8 -0
- scipy/io/arff/tests/data/nodata.arff +11 -0
- scipy/io/arff/tests/data/quoted_nominal.arff +13 -0
- scipy/io/arff/tests/data/quoted_nominal_spaces.arff +13 -0
- scipy/io/arff/tests/data/test1.arff +10 -0
- scipy/io/arff/tests/data/test10.arff +8 -0
- scipy/io/arff/tests/data/test11.arff +11 -0
- scipy/io/arff/tests/data/test2.arff +15 -0
- scipy/io/arff/tests/data/test3.arff +6 -0
- scipy/io/arff/tests/data/test4.arff +11 -0
- scipy/io/arff/tests/data/test5.arff +26 -0
- scipy/io/arff/tests/data/test6.arff +12 -0
- scipy/io/arff/tests/data/test7.arff +15 -0
- scipy/io/arff/tests/data/test8.arff +12 -0
- scipy/io/arff/tests/data/test9.arff +14 -0
- scipy/io/arff/tests/test_arffread.py +421 -0
- scipy/io/harwell_boeing.py +17 -0
- scipy/io/idl.py +17 -0
- scipy/io/matlab/__init__.py +66 -0
- scipy/io/matlab/_byteordercodes.py +75 -0
- scipy/io/matlab/_mio.py +375 -0
- scipy/io/matlab/_mio4.py +632 -0
- scipy/io/matlab/_mio5.py +901 -0
- scipy/io/matlab/_mio5_params.py +281 -0
- scipy/io/matlab/_mio5_utils.cp314t-win_arm64.lib +0 -0
- scipy/io/matlab/_mio5_utils.cp314t-win_arm64.pyd +0 -0
- scipy/io/matlab/_mio_utils.cp314t-win_arm64.lib +0 -0
- scipy/io/matlab/_mio_utils.cp314t-win_arm64.pyd +0 -0
- scipy/io/matlab/_miobase.py +435 -0
- scipy/io/matlab/_streams.cp314t-win_arm64.lib +0 -0
- scipy/io/matlab/_streams.cp314t-win_arm64.pyd +0 -0
- scipy/io/matlab/byteordercodes.py +17 -0
- scipy/io/matlab/mio.py +16 -0
- scipy/io/matlab/mio4.py +17 -0
- scipy/io/matlab/mio5.py +19 -0
- scipy/io/matlab/mio5_params.py +18 -0
- scipy/io/matlab/mio5_utils.py +17 -0
- scipy/io/matlab/mio_utils.py +17 -0
- scipy/io/matlab/miobase.py +16 -0
- scipy/io/matlab/streams.py +16 -0
- scipy/io/matlab/tests/__init__.py +0 -0
- scipy/io/matlab/tests/data/bad_miuint32.mat +0 -0
- scipy/io/matlab/tests/data/bad_miutf8_array_name.mat +0 -0
- scipy/io/matlab/tests/data/big_endian.mat +0 -0
- scipy/io/matlab/tests/data/broken_utf8.mat +0 -0
- scipy/io/matlab/tests/data/corrupted_zlib_checksum.mat +0 -0
- scipy/io/matlab/tests/data/corrupted_zlib_data.mat +0 -0
- scipy/io/matlab/tests/data/debigged_m4.mat +0 -0
- scipy/io/matlab/tests/data/japanese_utf8.txt +5 -0
- scipy/io/matlab/tests/data/little_endian.mat +0 -0
- scipy/io/matlab/tests/data/logical_sparse.mat +0 -0
- scipy/io/matlab/tests/data/malformed1.mat +0 -0
- scipy/io/matlab/tests/data/miuint32_for_miint32.mat +0 -0
- scipy/io/matlab/tests/data/miutf8_array_name.mat +0 -0
- scipy/io/matlab/tests/data/nasty_duplicate_fieldnames.mat +0 -0
- scipy/io/matlab/tests/data/one_by_zero_char.mat +0 -0
- scipy/io/matlab/tests/data/parabola.mat +0 -0
- scipy/io/matlab/tests/data/single_empty_string.mat +0 -0
- scipy/io/matlab/tests/data/some_functions.mat +0 -0
- scipy/io/matlab/tests/data/sqr.mat +0 -0
- scipy/io/matlab/tests/data/test3dmatrix_6.1_SOL2.mat +0 -0
- scipy/io/matlab/tests/data/test3dmatrix_6.5.1_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/test3dmatrix_7.1_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/test3dmatrix_7.4_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/test_empty_struct.mat +0 -0
- scipy/io/matlab/tests/data/test_mat4_le_floats.mat +0 -0
- scipy/io/matlab/tests/data/test_skip_variable.mat +0 -0
- scipy/io/matlab/tests/data/testbool_8_WIN64.mat +0 -0
- scipy/io/matlab/tests/data/testcell_6.1_SOL2.mat +0 -0
- scipy/io/matlab/tests/data/testcell_6.5.1_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/testcell_7.1_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/testcell_7.4_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/testcellnest_6.1_SOL2.mat +0 -0
- scipy/io/matlab/tests/data/testcellnest_6.5.1_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/testcellnest_7.1_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/testcellnest_7.4_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/testcomplex_4.2c_SOL2.mat +0 -0
- scipy/io/matlab/tests/data/testcomplex_6.1_SOL2.mat +0 -0
- scipy/io/matlab/tests/data/testcomplex_6.5.1_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/testcomplex_7.1_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/testcomplex_7.4_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/testdouble_4.2c_SOL2.mat +0 -0
- scipy/io/matlab/tests/data/testdouble_6.1_SOL2.mat +0 -0
- scipy/io/matlab/tests/data/testdouble_6.5.1_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/testdouble_7.1_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/testdouble_7.4_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/testemptycell_5.3_SOL2.mat +0 -0
- scipy/io/matlab/tests/data/testemptycell_6.5.1_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/testemptycell_7.1_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/testemptycell_7.4_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/testfunc_7.4_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/testhdf5_7.4_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/testmatrix_4.2c_SOL2.mat +0 -0
- scipy/io/matlab/tests/data/testmatrix_6.1_SOL2.mat +0 -0
- scipy/io/matlab/tests/data/testmatrix_6.5.1_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/testmatrix_7.1_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/testmatrix_7.4_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/testminus_4.2c_SOL2.mat +0 -0
- scipy/io/matlab/tests/data/testminus_6.1_SOL2.mat +0 -0
- scipy/io/matlab/tests/data/testminus_6.5.1_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/testminus_7.1_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/testminus_7.4_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/testmulti_4.2c_SOL2.mat +0 -0
- scipy/io/matlab/tests/data/testmulti_7.1_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/testmulti_7.4_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/testobject_6.1_SOL2.mat +0 -0
- scipy/io/matlab/tests/data/testobject_6.5.1_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/testobject_7.1_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/testobject_7.4_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/testonechar_4.2c_SOL2.mat +0 -0
- scipy/io/matlab/tests/data/testonechar_6.1_SOL2.mat +0 -0
- scipy/io/matlab/tests/data/testonechar_6.5.1_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/testonechar_7.1_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/testonechar_7.4_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/testscalarcell_7.4_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/testsimplecell.mat +0 -0
- scipy/io/matlab/tests/data/testsparse_4.2c_SOL2.mat +0 -0
- scipy/io/matlab/tests/data/testsparse_6.1_SOL2.mat +0 -0
- scipy/io/matlab/tests/data/testsparse_6.5.1_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/testsparse_7.1_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/testsparse_7.4_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/testsparsecomplex_4.2c_SOL2.mat +0 -0
- scipy/io/matlab/tests/data/testsparsecomplex_6.1_SOL2.mat +0 -0
- scipy/io/matlab/tests/data/testsparsecomplex_6.5.1_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/testsparsecomplex_7.1_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/testsparsecomplex_7.4_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/testsparsefloat_7.4_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/teststring_4.2c_SOL2.mat +0 -0
- scipy/io/matlab/tests/data/teststring_6.1_SOL2.mat +0 -0
- scipy/io/matlab/tests/data/teststring_6.5.1_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/teststring_7.1_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/teststring_7.4_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/teststringarray_4.2c_SOL2.mat +0 -0
- scipy/io/matlab/tests/data/teststringarray_6.1_SOL2.mat +0 -0
- scipy/io/matlab/tests/data/teststringarray_6.5.1_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/teststringarray_7.1_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/teststringarray_7.4_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/teststruct_6.1_SOL2.mat +0 -0
- scipy/io/matlab/tests/data/teststruct_6.5.1_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/teststruct_7.1_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/teststruct_7.4_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/teststructarr_6.1_SOL2.mat +0 -0
- scipy/io/matlab/tests/data/teststructarr_6.5.1_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/teststructarr_7.1_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/teststructarr_7.4_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/teststructnest_6.1_SOL2.mat +0 -0
- scipy/io/matlab/tests/data/teststructnest_6.5.1_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/teststructnest_7.1_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/teststructnest_7.4_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/testunicode_7.1_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/testunicode_7.4_GLNX86.mat +0 -0
- scipy/io/matlab/tests/data/testvec_4_GLNX86.mat +0 -0
- scipy/io/matlab/tests/test_byteordercodes.py +29 -0
- scipy/io/matlab/tests/test_mio.py +1399 -0
- scipy/io/matlab/tests/test_mio5_utils.py +179 -0
- scipy/io/matlab/tests/test_mio_funcs.py +51 -0
- scipy/io/matlab/tests/test_mio_utils.py +45 -0
- scipy/io/matlab/tests/test_miobase.py +32 -0
- scipy/io/matlab/tests/test_pathological.py +33 -0
- scipy/io/matlab/tests/test_streams.py +241 -0
- scipy/io/mmio.py +17 -0
- scipy/io/netcdf.py +17 -0
- scipy/io/tests/__init__.py +0 -0
- scipy/io/tests/data/Transparent Busy.ani +0 -0
- scipy/io/tests/data/array_float32_1d.sav +0 -0
- scipy/io/tests/data/array_float32_2d.sav +0 -0
- scipy/io/tests/data/array_float32_3d.sav +0 -0
- scipy/io/tests/data/array_float32_4d.sav +0 -0
- scipy/io/tests/data/array_float32_5d.sav +0 -0
- scipy/io/tests/data/array_float32_6d.sav +0 -0
- scipy/io/tests/data/array_float32_7d.sav +0 -0
- scipy/io/tests/data/array_float32_8d.sav +0 -0
- scipy/io/tests/data/array_float32_pointer_1d.sav +0 -0
- scipy/io/tests/data/array_float32_pointer_2d.sav +0 -0
- scipy/io/tests/data/array_float32_pointer_3d.sav +0 -0
- scipy/io/tests/data/array_float32_pointer_4d.sav +0 -0
- scipy/io/tests/data/array_float32_pointer_5d.sav +0 -0
- scipy/io/tests/data/array_float32_pointer_6d.sav +0 -0
- scipy/io/tests/data/array_float32_pointer_7d.sav +0 -0
- scipy/io/tests/data/array_float32_pointer_8d.sav +0 -0
- scipy/io/tests/data/example_1.nc +0 -0
- scipy/io/tests/data/example_2.nc +0 -0
- scipy/io/tests/data/example_3_maskedvals.nc +0 -0
- scipy/io/tests/data/fortran-3x3d-2i.dat +0 -0
- scipy/io/tests/data/fortran-mixed.dat +0 -0
- scipy/io/tests/data/fortran-sf8-11x1x10.dat +0 -0
- scipy/io/tests/data/fortran-sf8-15x10x22.dat +0 -0
- scipy/io/tests/data/fortran-sf8-1x1x1.dat +0 -0
- scipy/io/tests/data/fortran-sf8-1x1x5.dat +0 -0
- scipy/io/tests/data/fortran-sf8-1x1x7.dat +0 -0
- scipy/io/tests/data/fortran-sf8-1x3x5.dat +0 -0
- scipy/io/tests/data/fortran-si4-11x1x10.dat +0 -0
- scipy/io/tests/data/fortran-si4-15x10x22.dat +0 -0
- scipy/io/tests/data/fortran-si4-1x1x1.dat +0 -0
- scipy/io/tests/data/fortran-si4-1x1x5.dat +0 -0
- scipy/io/tests/data/fortran-si4-1x1x7.dat +0 -0
- scipy/io/tests/data/fortran-si4-1x3x5.dat +0 -0
- scipy/io/tests/data/invalid_pointer.sav +0 -0
- scipy/io/tests/data/null_pointer.sav +0 -0
- scipy/io/tests/data/scalar_byte.sav +0 -0
- scipy/io/tests/data/scalar_byte_descr.sav +0 -0
- scipy/io/tests/data/scalar_complex32.sav +0 -0
- scipy/io/tests/data/scalar_complex64.sav +0 -0
- scipy/io/tests/data/scalar_float32.sav +0 -0
- scipy/io/tests/data/scalar_float64.sav +0 -0
- scipy/io/tests/data/scalar_heap_pointer.sav +0 -0
- scipy/io/tests/data/scalar_int16.sav +0 -0
- scipy/io/tests/data/scalar_int32.sav +0 -0
- scipy/io/tests/data/scalar_int64.sav +0 -0
- scipy/io/tests/data/scalar_string.sav +0 -0
- scipy/io/tests/data/scalar_uint16.sav +0 -0
- scipy/io/tests/data/scalar_uint32.sav +0 -0
- scipy/io/tests/data/scalar_uint64.sav +0 -0
- scipy/io/tests/data/struct_arrays.sav +0 -0
- scipy/io/tests/data/struct_arrays_byte_idl80.sav +0 -0
- scipy/io/tests/data/struct_arrays_replicated.sav +0 -0
- scipy/io/tests/data/struct_arrays_replicated_3d.sav +0 -0
- scipy/io/tests/data/struct_inherit.sav +0 -0
- scipy/io/tests/data/struct_pointer_arrays.sav +0 -0
- scipy/io/tests/data/struct_pointer_arrays_replicated.sav +0 -0
- scipy/io/tests/data/struct_pointer_arrays_replicated_3d.sav +0 -0
- scipy/io/tests/data/struct_pointers.sav +0 -0
- scipy/io/tests/data/struct_pointers_replicated.sav +0 -0
- scipy/io/tests/data/struct_pointers_replicated_3d.sav +0 -0
- scipy/io/tests/data/struct_scalars.sav +0 -0
- scipy/io/tests/data/struct_scalars_replicated.sav +0 -0
- scipy/io/tests/data/struct_scalars_replicated_3d.sav +0 -0
- scipy/io/tests/data/test-1234Hz-le-1ch-10S-20bit-extra.wav +0 -0
- scipy/io/tests/data/test-44100Hz-2ch-32bit-float-be.wav +0 -0
- scipy/io/tests/data/test-44100Hz-2ch-32bit-float-le.wav +0 -0
- scipy/io/tests/data/test-44100Hz-be-1ch-4bytes.wav +0 -0
- scipy/io/tests/data/test-44100Hz-le-1ch-4bytes-early-eof-no-data.wav +0 -0
- scipy/io/tests/data/test-44100Hz-le-1ch-4bytes-early-eof.wav +0 -0
- scipy/io/tests/data/test-44100Hz-le-1ch-4bytes-incomplete-chunk.wav +0 -0
- scipy/io/tests/data/test-44100Hz-le-1ch-4bytes-rf64.wav +0 -0
- scipy/io/tests/data/test-44100Hz-le-1ch-4bytes.wav +0 -0
- scipy/io/tests/data/test-48000Hz-2ch-64bit-float-le-wavex.wav +0 -0
- scipy/io/tests/data/test-8000Hz-be-3ch-5S-24bit.wav +0 -0
- scipy/io/tests/data/test-8000Hz-le-1ch-1byte-ulaw.wav +0 -0
- scipy/io/tests/data/test-8000Hz-le-2ch-1byteu.wav +0 -0
- scipy/io/tests/data/test-8000Hz-le-3ch-5S-24bit-inconsistent.wav +0 -0
- scipy/io/tests/data/test-8000Hz-le-3ch-5S-24bit-rf64.wav +0 -0
- scipy/io/tests/data/test-8000Hz-le-3ch-5S-24bit.wav +0 -0
- scipy/io/tests/data/test-8000Hz-le-3ch-5S-36bit.wav +0 -0
- scipy/io/tests/data/test-8000Hz-le-3ch-5S-45bit.wav +0 -0
- scipy/io/tests/data/test-8000Hz-le-3ch-5S-53bit.wav +0 -0
- scipy/io/tests/data/test-8000Hz-le-3ch-5S-64bit.wav +0 -0
- scipy/io/tests/data/test-8000Hz-le-4ch-9S-12bit.wav +0 -0
- scipy/io/tests/data/test-8000Hz-le-5ch-9S-5bit.wav +0 -0
- scipy/io/tests/data/various_compressed.sav +0 -0
- scipy/io/tests/test_fortran.py +264 -0
- scipy/io/tests/test_idl.py +483 -0
- scipy/io/tests/test_mmio.py +831 -0
- scipy/io/tests/test_netcdf.py +550 -0
- scipy/io/tests/test_paths.py +93 -0
- scipy/io/tests/test_wavfile.py +501 -0
- scipy/io/wavfile.py +938 -0
- scipy/linalg/__init__.pxd +1 -0
- scipy/linalg/__init__.py +236 -0
- scipy/linalg/_basic.py +2146 -0
- scipy/linalg/_blas_subroutines.h +164 -0
- scipy/linalg/_cythonized_array_utils.cp314t-win_arm64.lib +0 -0
- scipy/linalg/_cythonized_array_utils.cp314t-win_arm64.pyd +0 -0
- scipy/linalg/_cythonized_array_utils.pxd +40 -0
- scipy/linalg/_cythonized_array_utils.pyi +16 -0
- scipy/linalg/_decomp.py +1645 -0
- scipy/linalg/_decomp_cholesky.py +413 -0
- scipy/linalg/_decomp_cossin.py +236 -0
- scipy/linalg/_decomp_interpolative.cp314t-win_arm64.lib +0 -0
- scipy/linalg/_decomp_interpolative.cp314t-win_arm64.pyd +0 -0
- scipy/linalg/_decomp_ldl.py +356 -0
- scipy/linalg/_decomp_lu.py +401 -0
- scipy/linalg/_decomp_lu_cython.cp314t-win_arm64.lib +0 -0
- scipy/linalg/_decomp_lu_cython.cp314t-win_arm64.pyd +0 -0
- scipy/linalg/_decomp_lu_cython.pyi +6 -0
- scipy/linalg/_decomp_polar.py +113 -0
- scipy/linalg/_decomp_qr.py +494 -0
- scipy/linalg/_decomp_qz.py +452 -0
- scipy/linalg/_decomp_schur.py +336 -0
- scipy/linalg/_decomp_svd.py +545 -0
- scipy/linalg/_decomp_update.cp314t-win_arm64.lib +0 -0
- scipy/linalg/_decomp_update.cp314t-win_arm64.pyd +0 -0
- scipy/linalg/_expm_frechet.py +417 -0
- scipy/linalg/_fblas.cp314t-win_arm64.lib +0 -0
- scipy/linalg/_fblas.cp314t-win_arm64.pyd +0 -0
- scipy/linalg/_flapack.cp314t-win_arm64.lib +0 -0
- scipy/linalg/_flapack.cp314t-win_arm64.pyd +0 -0
- scipy/linalg/_lapack_subroutines.h +1521 -0
- scipy/linalg/_linalg_pythran.cp314t-win_arm64.lib +0 -0
- scipy/linalg/_linalg_pythran.cp314t-win_arm64.pyd +0 -0
- scipy/linalg/_matfuncs.py +1050 -0
- scipy/linalg/_matfuncs_expm.cp314t-win_arm64.lib +0 -0
- scipy/linalg/_matfuncs_expm.cp314t-win_arm64.pyd +0 -0
- scipy/linalg/_matfuncs_expm.pyi +6 -0
- scipy/linalg/_matfuncs_inv_ssq.py +886 -0
- scipy/linalg/_matfuncs_schur_sqrtm.cp314t-win_arm64.lib +0 -0
- scipy/linalg/_matfuncs_schur_sqrtm.cp314t-win_arm64.pyd +0 -0
- scipy/linalg/_matfuncs_sqrtm.py +107 -0
- scipy/linalg/_matfuncs_sqrtm_triu.cp314t-win_arm64.lib +0 -0
- scipy/linalg/_matfuncs_sqrtm_triu.cp314t-win_arm64.pyd +0 -0
- scipy/linalg/_misc.py +191 -0
- scipy/linalg/_procrustes.py +113 -0
- scipy/linalg/_sketches.py +189 -0
- scipy/linalg/_solve_toeplitz.cp314t-win_arm64.lib +0 -0
- scipy/linalg/_solve_toeplitz.cp314t-win_arm64.pyd +0 -0
- scipy/linalg/_solvers.py +862 -0
- scipy/linalg/_special_matrices.py +1322 -0
- scipy/linalg/_testutils.py +65 -0
- scipy/linalg/basic.py +23 -0
- scipy/linalg/blas.py +495 -0
- scipy/linalg/cython_blas.cp314t-win_arm64.lib +0 -0
- scipy/linalg/cython_blas.cp314t-win_arm64.pyd +0 -0
- scipy/linalg/cython_blas.pxd +169 -0
- scipy/linalg/cython_blas.pyx +1432 -0
- scipy/linalg/cython_lapack.cp314t-win_arm64.lib +0 -0
- scipy/linalg/cython_lapack.cp314t-win_arm64.pyd +0 -0
- scipy/linalg/cython_lapack.pxd +1528 -0
- scipy/linalg/cython_lapack.pyx +12045 -0
- scipy/linalg/decomp.py +23 -0
- scipy/linalg/decomp_cholesky.py +21 -0
- scipy/linalg/decomp_lu.py +21 -0
- scipy/linalg/decomp_qr.py +20 -0
- scipy/linalg/decomp_schur.py +21 -0
- scipy/linalg/decomp_svd.py +21 -0
- scipy/linalg/interpolative.py +989 -0
- scipy/linalg/lapack.py +1081 -0
- scipy/linalg/matfuncs.py +23 -0
- scipy/linalg/misc.py +21 -0
- scipy/linalg/special_matrices.py +22 -0
- scipy/linalg/tests/__init__.py +0 -0
- scipy/linalg/tests/_cython_examples/extending.pyx +23 -0
- scipy/linalg/tests/_cython_examples/meson.build +34 -0
- scipy/linalg/tests/data/carex_15_data.npz +0 -0
- scipy/linalg/tests/data/carex_18_data.npz +0 -0
- scipy/linalg/tests/data/carex_19_data.npz +0 -0
- scipy/linalg/tests/data/carex_20_data.npz +0 -0
- scipy/linalg/tests/data/carex_6_data.npz +0 -0
- scipy/linalg/tests/data/gendare_20170120_data.npz +0 -0
- scipy/linalg/tests/test_basic.py +2074 -0
- scipy/linalg/tests/test_batch.py +588 -0
- scipy/linalg/tests/test_blas.py +1127 -0
- scipy/linalg/tests/test_cython_blas.py +118 -0
- scipy/linalg/tests/test_cython_lapack.py +22 -0
- scipy/linalg/tests/test_cythonized_array_utils.py +130 -0
- scipy/linalg/tests/test_decomp.py +3189 -0
- scipy/linalg/tests/test_decomp_cholesky.py +268 -0
- scipy/linalg/tests/test_decomp_cossin.py +314 -0
- scipy/linalg/tests/test_decomp_ldl.py +137 -0
- scipy/linalg/tests/test_decomp_lu.py +308 -0
- scipy/linalg/tests/test_decomp_polar.py +110 -0
- scipy/linalg/tests/test_decomp_update.py +1701 -0
- scipy/linalg/tests/test_extending.py +46 -0
- scipy/linalg/tests/test_fblas.py +607 -0
- scipy/linalg/tests/test_interpolative.py +232 -0
- scipy/linalg/tests/test_lapack.py +3620 -0
- scipy/linalg/tests/test_matfuncs.py +1125 -0
- scipy/linalg/tests/test_matmul_toeplitz.py +136 -0
- scipy/linalg/tests/test_procrustes.py +214 -0
- scipy/linalg/tests/test_sketches.py +118 -0
- scipy/linalg/tests/test_solve_toeplitz.py +150 -0
- scipy/linalg/tests/test_solvers.py +844 -0
- scipy/linalg/tests/test_special_matrices.py +636 -0
- scipy/misc/__init__.py +6 -0
- scipy/misc/common.py +6 -0
- scipy/misc/doccer.py +6 -0
- scipy/ndimage/__init__.py +174 -0
- scipy/ndimage/_ctest.cp314t-win_arm64.lib +0 -0
- scipy/ndimage/_ctest.cp314t-win_arm64.pyd +0 -0
- scipy/ndimage/_cytest.cp314t-win_arm64.lib +0 -0
- scipy/ndimage/_cytest.cp314t-win_arm64.pyd +0 -0
- scipy/ndimage/_delegators.py +303 -0
- scipy/ndimage/_filters.py +2422 -0
- scipy/ndimage/_fourier.py +306 -0
- scipy/ndimage/_interpolation.py +1033 -0
- scipy/ndimage/_measurements.py +1689 -0
- scipy/ndimage/_morphology.py +2634 -0
- scipy/ndimage/_nd_image.cp314t-win_arm64.lib +0 -0
- scipy/ndimage/_nd_image.cp314t-win_arm64.pyd +0 -0
- scipy/ndimage/_ndimage_api.py +16 -0
- scipy/ndimage/_ni_docstrings.py +214 -0
- scipy/ndimage/_ni_label.cp314t-win_arm64.lib +0 -0
- scipy/ndimage/_ni_label.cp314t-win_arm64.pyd +0 -0
- scipy/ndimage/_ni_support.py +139 -0
- scipy/ndimage/_rank_filter_1d.cp314t-win_arm64.lib +0 -0
- scipy/ndimage/_rank_filter_1d.cp314t-win_arm64.pyd +0 -0
- scipy/ndimage/_support_alternative_backends.py +84 -0
- scipy/ndimage/filters.py +27 -0
- scipy/ndimage/fourier.py +21 -0
- scipy/ndimage/interpolation.py +22 -0
- scipy/ndimage/measurements.py +24 -0
- scipy/ndimage/morphology.py +27 -0
- scipy/ndimage/tests/__init__.py +12 -0
- scipy/ndimage/tests/data/label_inputs.txt +21 -0
- scipy/ndimage/tests/data/label_results.txt +294 -0
- scipy/ndimage/tests/data/label_strels.txt +42 -0
- scipy/ndimage/tests/dots.png +0 -0
- scipy/ndimage/tests/test_c_api.py +102 -0
- scipy/ndimage/tests/test_datatypes.py +67 -0
- scipy/ndimage/tests/test_filters.py +3083 -0
- scipy/ndimage/tests/test_fourier.py +187 -0
- scipy/ndimage/tests/test_interpolation.py +1491 -0
- scipy/ndimage/tests/test_measurements.py +1592 -0
- scipy/ndimage/tests/test_morphology.py +2950 -0
- scipy/ndimage/tests/test_ni_support.py +78 -0
- scipy/ndimage/tests/test_splines.py +70 -0
- scipy/odr/__init__.py +131 -0
- scipy/odr/__odrpack.cp314t-win_arm64.lib +0 -0
- scipy/odr/__odrpack.cp314t-win_arm64.pyd +0 -0
- scipy/odr/_add_newdocs.py +34 -0
- scipy/odr/_models.py +315 -0
- scipy/odr/_odrpack.py +1154 -0
- scipy/odr/models.py +20 -0
- scipy/odr/odrpack.py +21 -0
- scipy/odr/tests/__init__.py +0 -0
- scipy/odr/tests/test_odr.py +607 -0
- scipy/optimize/__init__.pxd +1 -0
- scipy/optimize/__init__.py +460 -0
- scipy/optimize/_basinhopping.py +741 -0
- scipy/optimize/_bglu_dense.cp314t-win_arm64.lib +0 -0
- scipy/optimize/_bglu_dense.cp314t-win_arm64.pyd +0 -0
- scipy/optimize/_bracket.py +706 -0
- scipy/optimize/_chandrupatla.py +551 -0
- scipy/optimize/_cobyla_py.py +297 -0
- scipy/optimize/_cobyqa_py.py +72 -0
- scipy/optimize/_constraints.py +598 -0
- scipy/optimize/_dcsrch.py +728 -0
- scipy/optimize/_differentiable_functions.py +835 -0
- scipy/optimize/_differentialevolution.py +1970 -0
- scipy/optimize/_direct.cp314t-win_arm64.lib +0 -0
- scipy/optimize/_direct.cp314t-win_arm64.pyd +0 -0
- scipy/optimize/_direct_py.py +280 -0
- scipy/optimize/_dual_annealing.py +732 -0
- scipy/optimize/_elementwise.py +798 -0
- scipy/optimize/_group_columns.cp314t-win_arm64.lib +0 -0
- scipy/optimize/_group_columns.cp314t-win_arm64.pyd +0 -0
- scipy/optimize/_hessian_update_strategy.py +479 -0
- scipy/optimize/_highspy/__init__.py +0 -0
- scipy/optimize/_highspy/_core.cp314t-win_arm64.lib +0 -0
- scipy/optimize/_highspy/_core.cp314t-win_arm64.pyd +0 -0
- scipy/optimize/_highspy/_highs_options.cp314t-win_arm64.lib +0 -0
- scipy/optimize/_highspy/_highs_options.cp314t-win_arm64.pyd +0 -0
- scipy/optimize/_highspy/_highs_wrapper.py +338 -0
- scipy/optimize/_isotonic.py +157 -0
- scipy/optimize/_lbfgsb.cp314t-win_arm64.lib +0 -0
- scipy/optimize/_lbfgsb.cp314t-win_arm64.pyd +0 -0
- scipy/optimize/_lbfgsb_py.py +634 -0
- scipy/optimize/_linesearch.py +896 -0
- scipy/optimize/_linprog.py +733 -0
- scipy/optimize/_linprog_doc.py +1434 -0
- scipy/optimize/_linprog_highs.py +422 -0
- scipy/optimize/_linprog_ip.py +1141 -0
- scipy/optimize/_linprog_rs.py +572 -0
- scipy/optimize/_linprog_simplex.py +663 -0
- scipy/optimize/_linprog_util.py +1521 -0
- scipy/optimize/_lsap.cp314t-win_arm64.lib +0 -0
- scipy/optimize/_lsap.cp314t-win_arm64.pyd +0 -0
- scipy/optimize/_lsq/__init__.py +5 -0
- scipy/optimize/_lsq/bvls.py +183 -0
- scipy/optimize/_lsq/common.py +731 -0
- scipy/optimize/_lsq/dogbox.py +345 -0
- scipy/optimize/_lsq/givens_elimination.cp314t-win_arm64.lib +0 -0
- scipy/optimize/_lsq/givens_elimination.cp314t-win_arm64.pyd +0 -0
- scipy/optimize/_lsq/least_squares.py +1044 -0
- scipy/optimize/_lsq/lsq_linear.py +361 -0
- scipy/optimize/_lsq/trf.py +587 -0
- scipy/optimize/_lsq/trf_linear.py +249 -0
- scipy/optimize/_milp.py +394 -0
- scipy/optimize/_minimize.py +1199 -0
- scipy/optimize/_minpack.cp314t-win_arm64.lib +0 -0
- scipy/optimize/_minpack.cp314t-win_arm64.pyd +0 -0
- scipy/optimize/_minpack_py.py +1178 -0
- scipy/optimize/_moduleTNC.cp314t-win_arm64.lib +0 -0
- scipy/optimize/_moduleTNC.cp314t-win_arm64.pyd +0 -0
- scipy/optimize/_nnls.py +96 -0
- scipy/optimize/_nonlin.py +1634 -0
- scipy/optimize/_numdiff.py +963 -0
- scipy/optimize/_optimize.py +4169 -0
- scipy/optimize/_pava_pybind.cp314t-win_arm64.lib +0 -0
- scipy/optimize/_pava_pybind.cp314t-win_arm64.pyd +0 -0
- scipy/optimize/_qap.py +760 -0
- scipy/optimize/_remove_redundancy.py +522 -0
- scipy/optimize/_root.py +732 -0
- scipy/optimize/_root_scalar.py +538 -0
- scipy/optimize/_shgo.py +1606 -0
- scipy/optimize/_shgo_lib/__init__.py +0 -0
- scipy/optimize/_shgo_lib/_complex.py +1225 -0
- scipy/optimize/_shgo_lib/_vertex.py +460 -0
- scipy/optimize/_slsqp_py.py +603 -0
- scipy/optimize/_slsqplib.cp314t-win_arm64.lib +0 -0
- scipy/optimize/_slsqplib.cp314t-win_arm64.pyd +0 -0
- scipy/optimize/_spectral.py +260 -0
- scipy/optimize/_tnc.py +438 -0
- scipy/optimize/_trlib/__init__.py +12 -0
- scipy/optimize/_trlib/_trlib.cp314t-win_arm64.lib +0 -0
- scipy/optimize/_trlib/_trlib.cp314t-win_arm64.pyd +0 -0
- scipy/optimize/_trustregion.py +318 -0
- scipy/optimize/_trustregion_constr/__init__.py +6 -0
- scipy/optimize/_trustregion_constr/canonical_constraint.py +390 -0
- scipy/optimize/_trustregion_constr/equality_constrained_sqp.py +231 -0
- scipy/optimize/_trustregion_constr/minimize_trustregion_constr.py +584 -0
- scipy/optimize/_trustregion_constr/projections.py +411 -0
- scipy/optimize/_trustregion_constr/qp_subproblem.py +637 -0
- scipy/optimize/_trustregion_constr/report.py +49 -0
- scipy/optimize/_trustregion_constr/tests/__init__.py +0 -0
- scipy/optimize/_trustregion_constr/tests/test_canonical_constraint.py +296 -0
- scipy/optimize/_trustregion_constr/tests/test_nested_minimize.py +39 -0
- scipy/optimize/_trustregion_constr/tests/test_projections.py +214 -0
- scipy/optimize/_trustregion_constr/tests/test_qp_subproblem.py +645 -0
- scipy/optimize/_trustregion_constr/tests/test_report.py +34 -0
- scipy/optimize/_trustregion_constr/tr_interior_point.py +361 -0
- scipy/optimize/_trustregion_dogleg.py +122 -0
- scipy/optimize/_trustregion_exact.py +437 -0
- scipy/optimize/_trustregion_krylov.py +65 -0
- scipy/optimize/_trustregion_ncg.py +126 -0
- scipy/optimize/_tstutils.py +972 -0
- scipy/optimize/_zeros.cp314t-win_arm64.lib +0 -0
- scipy/optimize/_zeros.cp314t-win_arm64.pyd +0 -0
- scipy/optimize/_zeros_py.py +1475 -0
- scipy/optimize/cobyla.py +19 -0
- scipy/optimize/cython_optimize/__init__.py +133 -0
- scipy/optimize/cython_optimize/_zeros.cp314t-win_arm64.lib +0 -0
- scipy/optimize/cython_optimize/_zeros.cp314t-win_arm64.pyd +0 -0
- scipy/optimize/cython_optimize/_zeros.pxd +33 -0
- scipy/optimize/cython_optimize/c_zeros.pxd +26 -0
- scipy/optimize/cython_optimize.pxd +11 -0
- scipy/optimize/elementwise.py +38 -0
- scipy/optimize/lbfgsb.py +23 -0
- scipy/optimize/linesearch.py +18 -0
- scipy/optimize/minpack.py +27 -0
- scipy/optimize/minpack2.py +17 -0
- scipy/optimize/moduleTNC.py +19 -0
- scipy/optimize/nonlin.py +29 -0
- scipy/optimize/optimize.py +40 -0
- scipy/optimize/slsqp.py +22 -0
- scipy/optimize/tests/__init__.py +0 -0
- scipy/optimize/tests/_cython_examples/extending.pyx +43 -0
- scipy/optimize/tests/_cython_examples/meson.build +32 -0
- scipy/optimize/tests/test__basinhopping.py +535 -0
- scipy/optimize/tests/test__differential_evolution.py +1703 -0
- scipy/optimize/tests/test__dual_annealing.py +416 -0
- scipy/optimize/tests/test__linprog_clean_inputs.py +312 -0
- scipy/optimize/tests/test__numdiff.py +885 -0
- scipy/optimize/tests/test__remove_redundancy.py +228 -0
- scipy/optimize/tests/test__root.py +124 -0
- scipy/optimize/tests/test__shgo.py +1164 -0
- scipy/optimize/tests/test__spectral.py +226 -0
- scipy/optimize/tests/test_bracket.py +896 -0
- scipy/optimize/tests/test_chandrupatla.py +982 -0
- scipy/optimize/tests/test_cobyla.py +195 -0
- scipy/optimize/tests/test_cobyqa.py +252 -0
- scipy/optimize/tests/test_constraint_conversion.py +286 -0
- scipy/optimize/tests/test_constraints.py +255 -0
- scipy/optimize/tests/test_cython_optimize.py +92 -0
- scipy/optimize/tests/test_differentiable_functions.py +1025 -0
- scipy/optimize/tests/test_direct.py +321 -0
- scipy/optimize/tests/test_extending.py +28 -0
- scipy/optimize/tests/test_hessian_update_strategy.py +300 -0
- scipy/optimize/tests/test_isotonic_regression.py +167 -0
- scipy/optimize/tests/test_lbfgsb_hessinv.py +65 -0
- scipy/optimize/tests/test_lbfgsb_setulb.py +122 -0
- scipy/optimize/tests/test_least_squares.py +986 -0
- scipy/optimize/tests/test_linear_assignment.py +116 -0
- scipy/optimize/tests/test_linesearch.py +328 -0
- scipy/optimize/tests/test_linprog.py +2577 -0
- scipy/optimize/tests/test_lsq_common.py +297 -0
- scipy/optimize/tests/test_lsq_linear.py +287 -0
- scipy/optimize/tests/test_milp.py +459 -0
- scipy/optimize/tests/test_minimize_constrained.py +845 -0
- scipy/optimize/tests/test_minpack.py +1194 -0
- scipy/optimize/tests/test_nnls.py +469 -0
- scipy/optimize/tests/test_nonlin.py +572 -0
- scipy/optimize/tests/test_optimize.py +3344 -0
- scipy/optimize/tests/test_quadratic_assignment.py +455 -0
- scipy/optimize/tests/test_regression.py +40 -0
- scipy/optimize/tests/test_slsqp.py +645 -0
- scipy/optimize/tests/test_tnc.py +345 -0
- scipy/optimize/tests/test_trustregion.py +110 -0
- scipy/optimize/tests/test_trustregion_exact.py +351 -0
- scipy/optimize/tests/test_trustregion_krylov.py +170 -0
- scipy/optimize/tests/test_zeros.py +998 -0
- scipy/optimize/tnc.py +22 -0
- scipy/optimize/zeros.py +26 -0
- scipy/signal/__init__.py +316 -0
- scipy/signal/_arraytools.py +264 -0
- scipy/signal/_czt.py +575 -0
- scipy/signal/_delegators.py +568 -0
- scipy/signal/_filter_design.py +5893 -0
- scipy/signal/_fir_filter_design.py +1458 -0
- scipy/signal/_lti_conversion.py +534 -0
- scipy/signal/_ltisys.py +3546 -0
- scipy/signal/_max_len_seq.py +139 -0
- scipy/signal/_max_len_seq_inner.cp314t-win_arm64.lib +0 -0
- scipy/signal/_max_len_seq_inner.cp314t-win_arm64.pyd +0 -0
- scipy/signal/_peak_finding.py +1310 -0
- scipy/signal/_peak_finding_utils.cp314t-win_arm64.lib +0 -0
- scipy/signal/_peak_finding_utils.cp314t-win_arm64.pyd +0 -0
- scipy/signal/_polyutils.py +172 -0
- scipy/signal/_savitzky_golay.py +357 -0
- scipy/signal/_short_time_fft.py +2228 -0
- scipy/signal/_signal_api.py +30 -0
- scipy/signal/_signaltools.py +5309 -0
- scipy/signal/_sigtools.cp314t-win_arm64.lib +0 -0
- scipy/signal/_sigtools.cp314t-win_arm64.pyd +0 -0
- scipy/signal/_sosfilt.cp314t-win_arm64.lib +0 -0
- scipy/signal/_sosfilt.cp314t-win_arm64.pyd +0 -0
- scipy/signal/_spectral_py.py +2471 -0
- scipy/signal/_spline.cp314t-win_arm64.lib +0 -0
- scipy/signal/_spline.cp314t-win_arm64.pyd +0 -0
- scipy/signal/_spline.pyi +34 -0
- scipy/signal/_spline_filters.py +848 -0
- scipy/signal/_support_alternative_backends.py +73 -0
- scipy/signal/_upfirdn.py +219 -0
- scipy/signal/_upfirdn_apply.cp314t-win_arm64.lib +0 -0
- scipy/signal/_upfirdn_apply.cp314t-win_arm64.pyd +0 -0
- scipy/signal/_waveforms.py +687 -0
- scipy/signal/_wavelets.py +29 -0
- scipy/signal/bsplines.py +21 -0
- scipy/signal/filter_design.py +28 -0
- scipy/signal/fir_filter_design.py +21 -0
- scipy/signal/lti_conversion.py +20 -0
- scipy/signal/ltisys.py +25 -0
- scipy/signal/signaltools.py +27 -0
- scipy/signal/spectral.py +21 -0
- scipy/signal/spline.py +18 -0
- scipy/signal/tests/__init__.py +0 -0
- scipy/signal/tests/_scipy_spectral_test_shim.py +311 -0
- scipy/signal/tests/mpsig.py +122 -0
- scipy/signal/tests/test_array_tools.py +111 -0
- scipy/signal/tests/test_bsplines.py +365 -0
- scipy/signal/tests/test_cont2discrete.py +424 -0
- scipy/signal/tests/test_czt.py +221 -0
- scipy/signal/tests/test_dltisys.py +599 -0
- scipy/signal/tests/test_filter_design.py +4744 -0
- scipy/signal/tests/test_fir_filter_design.py +851 -0
- scipy/signal/tests/test_ltisys.py +1225 -0
- scipy/signal/tests/test_max_len_seq.py +71 -0
- scipy/signal/tests/test_peak_finding.py +915 -0
- scipy/signal/tests/test_result_type.py +51 -0
- scipy/signal/tests/test_savitzky_golay.py +363 -0
- scipy/signal/tests/test_short_time_fft.py +1107 -0
- scipy/signal/tests/test_signaltools.py +4735 -0
- scipy/signal/tests/test_spectral.py +2141 -0
- scipy/signal/tests/test_splines.py +427 -0
- scipy/signal/tests/test_upfirdn.py +322 -0
- scipy/signal/tests/test_waveforms.py +400 -0
- scipy/signal/tests/test_wavelets.py +59 -0
- scipy/signal/tests/test_windows.py +987 -0
- scipy/signal/waveforms.py +20 -0
- scipy/signal/wavelets.py +17 -0
- scipy/signal/windows/__init__.py +52 -0
- scipy/signal/windows/_windows.py +2513 -0
- scipy/signal/windows/windows.py +23 -0
- scipy/sparse/__init__.py +350 -0
- scipy/sparse/_base.py +1613 -0
- scipy/sparse/_bsr.py +880 -0
- scipy/sparse/_compressed.py +1328 -0
- scipy/sparse/_construct.py +1454 -0
- scipy/sparse/_coo.py +1581 -0
- scipy/sparse/_csc.py +367 -0
- scipy/sparse/_csparsetools.cp314t-win_arm64.lib +0 -0
- scipy/sparse/_csparsetools.cp314t-win_arm64.pyd +0 -0
- scipy/sparse/_csr.py +558 -0
- scipy/sparse/_data.py +569 -0
- scipy/sparse/_dia.py +677 -0
- scipy/sparse/_dok.py +669 -0
- scipy/sparse/_extract.py +178 -0
- scipy/sparse/_index.py +444 -0
- scipy/sparse/_lil.py +632 -0
- scipy/sparse/_matrix.py +169 -0
- scipy/sparse/_matrix_io.py +167 -0
- scipy/sparse/_sparsetools.cp314t-win_arm64.lib +0 -0
- scipy/sparse/_sparsetools.cp314t-win_arm64.pyd +0 -0
- scipy/sparse/_spfuncs.py +76 -0
- scipy/sparse/_sputils.py +632 -0
- scipy/sparse/base.py +24 -0
- scipy/sparse/bsr.py +22 -0
- scipy/sparse/compressed.py +20 -0
- scipy/sparse/construct.py +38 -0
- scipy/sparse/coo.py +23 -0
- scipy/sparse/csc.py +22 -0
- scipy/sparse/csgraph/__init__.py +210 -0
- scipy/sparse/csgraph/_flow.cp314t-win_arm64.lib +0 -0
- scipy/sparse/csgraph/_flow.cp314t-win_arm64.pyd +0 -0
- scipy/sparse/csgraph/_laplacian.py +563 -0
- scipy/sparse/csgraph/_matching.cp314t-win_arm64.lib +0 -0
- scipy/sparse/csgraph/_matching.cp314t-win_arm64.pyd +0 -0
- scipy/sparse/csgraph/_min_spanning_tree.cp314t-win_arm64.lib +0 -0
- scipy/sparse/csgraph/_min_spanning_tree.cp314t-win_arm64.pyd +0 -0
- scipy/sparse/csgraph/_reordering.cp314t-win_arm64.lib +0 -0
- scipy/sparse/csgraph/_reordering.cp314t-win_arm64.pyd +0 -0
- scipy/sparse/csgraph/_shortest_path.cp314t-win_arm64.lib +0 -0
- scipy/sparse/csgraph/_shortest_path.cp314t-win_arm64.pyd +0 -0
- scipy/sparse/csgraph/_tools.cp314t-win_arm64.lib +0 -0
- scipy/sparse/csgraph/_tools.cp314t-win_arm64.pyd +0 -0
- scipy/sparse/csgraph/_traversal.cp314t-win_arm64.lib +0 -0
- scipy/sparse/csgraph/_traversal.cp314t-win_arm64.pyd +0 -0
- scipy/sparse/csgraph/_validation.py +66 -0
- scipy/sparse/csgraph/tests/__init__.py +0 -0
- scipy/sparse/csgraph/tests/test_connected_components.py +119 -0
- scipy/sparse/csgraph/tests/test_conversions.py +61 -0
- scipy/sparse/csgraph/tests/test_flow.py +209 -0
- scipy/sparse/csgraph/tests/test_graph_laplacian.py +368 -0
- scipy/sparse/csgraph/tests/test_matching.py +307 -0
- scipy/sparse/csgraph/tests/test_pydata_sparse.py +197 -0
- scipy/sparse/csgraph/tests/test_reordering.py +70 -0
- scipy/sparse/csgraph/tests/test_shortest_path.py +540 -0
- scipy/sparse/csgraph/tests/test_spanning_tree.py +66 -0
- scipy/sparse/csgraph/tests/test_traversal.py +148 -0
- scipy/sparse/csr.py +22 -0
- scipy/sparse/data.py +18 -0
- scipy/sparse/dia.py +22 -0
- scipy/sparse/dok.py +22 -0
- scipy/sparse/extract.py +23 -0
- scipy/sparse/lil.py +22 -0
- scipy/sparse/linalg/__init__.py +148 -0
- scipy/sparse/linalg/_dsolve/__init__.py +71 -0
- scipy/sparse/linalg/_dsolve/_add_newdocs.py +147 -0
- scipy/sparse/linalg/_dsolve/_superlu.cp314t-win_arm64.lib +0 -0
- scipy/sparse/linalg/_dsolve/_superlu.cp314t-win_arm64.pyd +0 -0
- scipy/sparse/linalg/_dsolve/linsolve.py +882 -0
- scipy/sparse/linalg/_dsolve/tests/__init__.py +0 -0
- scipy/sparse/linalg/_dsolve/tests/test_linsolve.py +928 -0
- scipy/sparse/linalg/_eigen/__init__.py +22 -0
- scipy/sparse/linalg/_eigen/_svds.py +540 -0
- scipy/sparse/linalg/_eigen/_svds_doc.py +382 -0
- scipy/sparse/linalg/_eigen/arpack/COPYING +45 -0
- scipy/sparse/linalg/_eigen/arpack/__init__.py +20 -0
- scipy/sparse/linalg/_eigen/arpack/_arpack.cp314t-win_arm64.lib +0 -0
- scipy/sparse/linalg/_eigen/arpack/_arpack.cp314t-win_arm64.pyd +0 -0
- scipy/sparse/linalg/_eigen/arpack/arpack.py +1706 -0
- scipy/sparse/linalg/_eigen/arpack/tests/__init__.py +0 -0
- scipy/sparse/linalg/_eigen/arpack/tests/test_arpack.py +717 -0
- scipy/sparse/linalg/_eigen/lobpcg/__init__.py +16 -0
- scipy/sparse/linalg/_eigen/lobpcg/lobpcg.py +1110 -0
- scipy/sparse/linalg/_eigen/lobpcg/tests/__init__.py +0 -0
- scipy/sparse/linalg/_eigen/lobpcg/tests/test_lobpcg.py +725 -0
- scipy/sparse/linalg/_eigen/tests/__init__.py +0 -0
- scipy/sparse/linalg/_eigen/tests/test_svds.py +886 -0
- scipy/sparse/linalg/_expm_multiply.py +816 -0
- scipy/sparse/linalg/_interface.py +920 -0
- scipy/sparse/linalg/_isolve/__init__.py +20 -0
- scipy/sparse/linalg/_isolve/_gcrotmk.py +503 -0
- scipy/sparse/linalg/_isolve/iterative.py +1051 -0
- scipy/sparse/linalg/_isolve/lgmres.py +230 -0
- scipy/sparse/linalg/_isolve/lsmr.py +486 -0
- scipy/sparse/linalg/_isolve/lsqr.py +589 -0
- scipy/sparse/linalg/_isolve/minres.py +372 -0
- scipy/sparse/linalg/_isolve/tests/__init__.py +0 -0
- scipy/sparse/linalg/_isolve/tests/test_gcrotmk.py +183 -0
- scipy/sparse/linalg/_isolve/tests/test_iterative.py +809 -0
- scipy/sparse/linalg/_isolve/tests/test_lgmres.py +225 -0
- scipy/sparse/linalg/_isolve/tests/test_lsmr.py +185 -0
- scipy/sparse/linalg/_isolve/tests/test_lsqr.py +120 -0
- scipy/sparse/linalg/_isolve/tests/test_minres.py +97 -0
- scipy/sparse/linalg/_isolve/tests/test_utils.py +9 -0
- scipy/sparse/linalg/_isolve/tfqmr.py +179 -0
- scipy/sparse/linalg/_isolve/utils.py +121 -0
- scipy/sparse/linalg/_matfuncs.py +940 -0
- scipy/sparse/linalg/_norm.py +195 -0
- scipy/sparse/linalg/_onenormest.py +467 -0
- scipy/sparse/linalg/_propack/_cpropack.cp314t-win_arm64.lib +0 -0
- scipy/sparse/linalg/_propack/_cpropack.cp314t-win_arm64.pyd +0 -0
- scipy/sparse/linalg/_propack/_dpropack.cp314t-win_arm64.lib +0 -0
- scipy/sparse/linalg/_propack/_dpropack.cp314t-win_arm64.pyd +0 -0
- scipy/sparse/linalg/_propack/_spropack.cp314t-win_arm64.lib +0 -0
- scipy/sparse/linalg/_propack/_spropack.cp314t-win_arm64.pyd +0 -0
- scipy/sparse/linalg/_propack/_zpropack.cp314t-win_arm64.lib +0 -0
- scipy/sparse/linalg/_propack/_zpropack.cp314t-win_arm64.pyd +0 -0
- scipy/sparse/linalg/_special_sparse_arrays.py +949 -0
- scipy/sparse/linalg/_svdp.py +309 -0
- scipy/sparse/linalg/dsolve.py +22 -0
- scipy/sparse/linalg/eigen.py +21 -0
- scipy/sparse/linalg/interface.py +20 -0
- scipy/sparse/linalg/isolve.py +22 -0
- scipy/sparse/linalg/matfuncs.py +18 -0
- scipy/sparse/linalg/tests/__init__.py +0 -0
- scipy/sparse/linalg/tests/propack_test_data.npz +0 -0
- scipy/sparse/linalg/tests/test_expm_multiply.py +367 -0
- scipy/sparse/linalg/tests/test_interface.py +561 -0
- scipy/sparse/linalg/tests/test_matfuncs.py +592 -0
- scipy/sparse/linalg/tests/test_norm.py +154 -0
- scipy/sparse/linalg/tests/test_onenormest.py +252 -0
- scipy/sparse/linalg/tests/test_propack.py +165 -0
- scipy/sparse/linalg/tests/test_pydata_sparse.py +272 -0
- scipy/sparse/linalg/tests/test_special_sparse_arrays.py +337 -0
- scipy/sparse/sparsetools.py +17 -0
- scipy/sparse/spfuncs.py +17 -0
- scipy/sparse/sputils.py +17 -0
- scipy/sparse/tests/__init__.py +0 -0
- scipy/sparse/tests/data/csc_py2.npz +0 -0
- scipy/sparse/tests/data/csc_py3.npz +0 -0
- scipy/sparse/tests/test_arithmetic1d.py +341 -0
- scipy/sparse/tests/test_array_api.py +561 -0
- scipy/sparse/tests/test_base.py +5870 -0
- scipy/sparse/tests/test_common1d.py +447 -0
- scipy/sparse/tests/test_construct.py +872 -0
- scipy/sparse/tests/test_coo.py +1119 -0
- scipy/sparse/tests/test_csc.py +98 -0
- scipy/sparse/tests/test_csr.py +214 -0
- scipy/sparse/tests/test_dok.py +209 -0
- scipy/sparse/tests/test_extract.py +51 -0
- scipy/sparse/tests/test_indexing1d.py +603 -0
- scipy/sparse/tests/test_matrix_io.py +109 -0
- scipy/sparse/tests/test_minmax1d.py +128 -0
- scipy/sparse/tests/test_sparsetools.py +344 -0
- scipy/sparse/tests/test_spfuncs.py +97 -0
- scipy/sparse/tests/test_sputils.py +424 -0
- scipy/spatial/__init__.py +129 -0
- scipy/spatial/_ckdtree.cp314t-win_arm64.lib +0 -0
- scipy/spatial/_ckdtree.cp314t-win_arm64.pyd +0 -0
- scipy/spatial/_distance_pybind.cp314t-win_arm64.lib +0 -0
- scipy/spatial/_distance_pybind.cp314t-win_arm64.pyd +0 -0
- scipy/spatial/_distance_wrap.cp314t-win_arm64.lib +0 -0
- scipy/spatial/_distance_wrap.cp314t-win_arm64.pyd +0 -0
- scipy/spatial/_geometric_slerp.py +238 -0
- scipy/spatial/_hausdorff.cp314t-win_arm64.lib +0 -0
- scipy/spatial/_hausdorff.cp314t-win_arm64.pyd +0 -0
- scipy/spatial/_kdtree.py +920 -0
- scipy/spatial/_plotutils.py +274 -0
- scipy/spatial/_procrustes.py +132 -0
- scipy/spatial/_qhull.cp314t-win_arm64.lib +0 -0
- scipy/spatial/_qhull.cp314t-win_arm64.pyd +0 -0
- scipy/spatial/_qhull.pyi +213 -0
- scipy/spatial/_spherical_voronoi.py +341 -0
- scipy/spatial/_voronoi.cp314t-win_arm64.lib +0 -0
- scipy/spatial/_voronoi.cp314t-win_arm64.pyd +0 -0
- scipy/spatial/_voronoi.pyi +4 -0
- scipy/spatial/ckdtree.py +18 -0
- scipy/spatial/distance.py +3147 -0
- scipy/spatial/distance.pyi +210 -0
- scipy/spatial/kdtree.py +25 -0
- scipy/spatial/qhull.py +25 -0
- scipy/spatial/qhull_src/COPYING_QHULL.txt +39 -0
- scipy/spatial/tests/__init__.py +0 -0
- scipy/spatial/tests/data/cdist-X1.txt +10 -0
- scipy/spatial/tests/data/cdist-X2.txt +20 -0
- scipy/spatial/tests/data/degenerate_pointset.npz +0 -0
- scipy/spatial/tests/data/iris.txt +150 -0
- scipy/spatial/tests/data/pdist-boolean-inp.txt +20 -0
- scipy/spatial/tests/data/pdist-chebyshev-ml-iris.txt +1 -0
- scipy/spatial/tests/data/pdist-chebyshev-ml.txt +1 -0
- scipy/spatial/tests/data/pdist-cityblock-ml-iris.txt +1 -0
- scipy/spatial/tests/data/pdist-cityblock-ml.txt +1 -0
- scipy/spatial/tests/data/pdist-correlation-ml-iris.txt +1 -0
- scipy/spatial/tests/data/pdist-correlation-ml.txt +1 -0
- scipy/spatial/tests/data/pdist-cosine-ml-iris.txt +1 -0
- scipy/spatial/tests/data/pdist-cosine-ml.txt +1 -0
- scipy/spatial/tests/data/pdist-double-inp.txt +20 -0
- scipy/spatial/tests/data/pdist-euclidean-ml-iris.txt +1 -0
- scipy/spatial/tests/data/pdist-euclidean-ml.txt +1 -0
- scipy/spatial/tests/data/pdist-hamming-ml.txt +1 -0
- scipy/spatial/tests/data/pdist-jaccard-ml.txt +1 -0
- scipy/spatial/tests/data/pdist-jensenshannon-ml-iris.txt +1 -0
- scipy/spatial/tests/data/pdist-jensenshannon-ml.txt +1 -0
- scipy/spatial/tests/data/pdist-minkowski-3.2-ml-iris.txt +1 -0
- scipy/spatial/tests/data/pdist-minkowski-3.2-ml.txt +1 -0
- scipy/spatial/tests/data/pdist-minkowski-5.8-ml-iris.txt +1 -0
- scipy/spatial/tests/data/pdist-seuclidean-ml-iris.txt +1 -0
- scipy/spatial/tests/data/pdist-seuclidean-ml.txt +1 -0
- scipy/spatial/tests/data/pdist-spearman-ml.txt +1 -0
- scipy/spatial/tests/data/random-bool-data.txt +100 -0
- scipy/spatial/tests/data/random-double-data.txt +100 -0
- scipy/spatial/tests/data/random-int-data.txt +100 -0
- scipy/spatial/tests/data/random-uint-data.txt +100 -0
- scipy/spatial/tests/data/selfdual-4d-polytope.txt +27 -0
- scipy/spatial/tests/test__plotutils.py +91 -0
- scipy/spatial/tests/test__procrustes.py +116 -0
- scipy/spatial/tests/test_distance.py +2389 -0
- scipy/spatial/tests/test_hausdorff.py +199 -0
- scipy/spatial/tests/test_kdtree.py +1536 -0
- scipy/spatial/tests/test_qhull.py +1313 -0
- scipy/spatial/tests/test_slerp.py +417 -0
- scipy/spatial/tests/test_spherical_voronoi.py +358 -0
- scipy/spatial/transform/__init__.py +31 -0
- scipy/spatial/transform/_rigid_transform.cp314t-win_arm64.lib +0 -0
- scipy/spatial/transform/_rigid_transform.cp314t-win_arm64.pyd +0 -0
- scipy/spatial/transform/_rotation.cp314t-win_arm64.lib +0 -0
- scipy/spatial/transform/_rotation.cp314t-win_arm64.pyd +0 -0
- scipy/spatial/transform/_rotation_groups.py +140 -0
- scipy/spatial/transform/_rotation_spline.py +460 -0
- scipy/spatial/transform/rotation.py +21 -0
- scipy/spatial/transform/tests/__init__.py +0 -0
- scipy/spatial/transform/tests/test_rigid_transform.py +1221 -0
- scipy/spatial/transform/tests/test_rotation.py +2569 -0
- scipy/spatial/transform/tests/test_rotation_groups.py +169 -0
- scipy/spatial/transform/tests/test_rotation_spline.py +183 -0
- scipy/special/__init__.pxd +1 -0
- scipy/special/__init__.py +841 -0
- scipy/special/_add_newdocs.py +9961 -0
- scipy/special/_basic.py +3576 -0
- scipy/special/_comb.cp314t-win_arm64.lib +0 -0
- scipy/special/_comb.cp314t-win_arm64.pyd +0 -0
- scipy/special/_ellip_harm.py +214 -0
- scipy/special/_ellip_harm_2.cp314t-win_arm64.lib +0 -0
- scipy/special/_ellip_harm_2.cp314t-win_arm64.pyd +0 -0
- scipy/special/_gufuncs.cp314t-win_arm64.lib +0 -0
- scipy/special/_gufuncs.cp314t-win_arm64.pyd +0 -0
- scipy/special/_input_validation.py +17 -0
- scipy/special/_lambertw.py +149 -0
- scipy/special/_logsumexp.py +426 -0
- scipy/special/_mptestutils.py +453 -0
- scipy/special/_multiufuncs.py +610 -0
- scipy/special/_orthogonal.py +2592 -0
- scipy/special/_orthogonal.pyi +330 -0
- scipy/special/_precompute/__init__.py +0 -0
- scipy/special/_precompute/cosine_cdf.py +17 -0
- scipy/special/_precompute/expn_asy.py +54 -0
- scipy/special/_precompute/gammainc_asy.py +116 -0
- scipy/special/_precompute/gammainc_data.py +124 -0
- scipy/special/_precompute/hyp2f1_data.py +484 -0
- scipy/special/_precompute/lambertw.py +68 -0
- scipy/special/_precompute/loggamma.py +43 -0
- scipy/special/_precompute/struve_convergence.py +131 -0
- scipy/special/_precompute/utils.py +38 -0
- scipy/special/_precompute/wright_bessel.py +342 -0
- scipy/special/_precompute/wright_bessel_data.py +152 -0
- scipy/special/_precompute/wrightomega.py +41 -0
- scipy/special/_precompute/zetac.py +27 -0
- scipy/special/_sf_error.py +15 -0
- scipy/special/_specfun.cp314t-win_arm64.lib +0 -0
- scipy/special/_specfun.cp314t-win_arm64.pyd +0 -0
- scipy/special/_special_ufuncs.cp314t-win_arm64.lib +0 -0
- scipy/special/_special_ufuncs.cp314t-win_arm64.pyd +0 -0
- scipy/special/_spfun_stats.py +106 -0
- scipy/special/_spherical_bessel.py +397 -0
- scipy/special/_support_alternative_backends.py +295 -0
- scipy/special/_test_internal.cp314t-win_arm64.lib +0 -0
- scipy/special/_test_internal.cp314t-win_arm64.pyd +0 -0
- scipy/special/_test_internal.pyi +9 -0
- scipy/special/_testutils.py +321 -0
- scipy/special/_ufuncs.cp314t-win_arm64.lib +0 -0
- scipy/special/_ufuncs.cp314t-win_arm64.pyd +0 -0
- scipy/special/_ufuncs.pyi +522 -0
- scipy/special/_ufuncs.pyx +13173 -0
- scipy/special/_ufuncs_cxx.cp314t-win_arm64.lib +0 -0
- scipy/special/_ufuncs_cxx.cp314t-win_arm64.pyd +0 -0
- scipy/special/_ufuncs_cxx.pxd +142 -0
- scipy/special/_ufuncs_cxx.pyx +427 -0
- scipy/special/_ufuncs_cxx_defs.h +147 -0
- scipy/special/_ufuncs_defs.h +57 -0
- scipy/special/add_newdocs.py +15 -0
- scipy/special/basic.py +87 -0
- scipy/special/cython_special.cp314t-win_arm64.lib +0 -0
- scipy/special/cython_special.cp314t-win_arm64.pyd +0 -0
- scipy/special/cython_special.pxd +259 -0
- scipy/special/cython_special.pyi +3 -0
- scipy/special/orthogonal.py +45 -0
- scipy/special/sf_error.py +20 -0
- scipy/special/specfun.py +24 -0
- scipy/special/spfun_stats.py +17 -0
- scipy/special/tests/__init__.py +0 -0
- scipy/special/tests/_cython_examples/extending.pyx +12 -0
- scipy/special/tests/_cython_examples/meson.build +34 -0
- scipy/special/tests/data/__init__.py +0 -0
- scipy/special/tests/data/boost.npz +0 -0
- scipy/special/tests/data/gsl.npz +0 -0
- scipy/special/tests/data/local.npz +0 -0
- scipy/special/tests/test_basic.py +4815 -0
- scipy/special/tests/test_bdtr.py +112 -0
- scipy/special/tests/test_boost_ufuncs.py +64 -0
- scipy/special/tests/test_boxcox.py +125 -0
- scipy/special/tests/test_cdflib.py +712 -0
- scipy/special/tests/test_cdft_asymptotic.py +49 -0
- scipy/special/tests/test_cephes_intp_cast.py +29 -0
- scipy/special/tests/test_cosine_distr.py +83 -0
- scipy/special/tests/test_cython_special.py +363 -0
- scipy/special/tests/test_data.py +719 -0
- scipy/special/tests/test_dd.py +42 -0
- scipy/special/tests/test_digamma.py +45 -0
- scipy/special/tests/test_ellip_harm.py +278 -0
- scipy/special/tests/test_erfinv.py +89 -0
- scipy/special/tests/test_exponential_integrals.py +118 -0
- scipy/special/tests/test_extending.py +28 -0
- scipy/special/tests/test_faddeeva.py +85 -0
- scipy/special/tests/test_gamma.py +12 -0
- scipy/special/tests/test_gammainc.py +152 -0
- scipy/special/tests/test_hyp2f1.py +2566 -0
- scipy/special/tests/test_hypergeometric.py +234 -0
- scipy/special/tests/test_iv_ratio.py +249 -0
- scipy/special/tests/test_kolmogorov.py +491 -0
- scipy/special/tests/test_lambertw.py +109 -0
- scipy/special/tests/test_legendre.py +1518 -0
- scipy/special/tests/test_log1mexp.py +85 -0
- scipy/special/tests/test_loggamma.py +70 -0
- scipy/special/tests/test_logit.py +162 -0
- scipy/special/tests/test_logsumexp.py +469 -0
- scipy/special/tests/test_mpmath.py +2293 -0
- scipy/special/tests/test_nan_inputs.py +65 -0
- scipy/special/tests/test_ndtr.py +77 -0
- scipy/special/tests/test_ndtri_exp.py +94 -0
- scipy/special/tests/test_orthogonal.py +821 -0
- scipy/special/tests/test_orthogonal_eval.py +275 -0
- scipy/special/tests/test_owens_t.py +53 -0
- scipy/special/tests/test_pcf.py +24 -0
- scipy/special/tests/test_pdtr.py +48 -0
- scipy/special/tests/test_powm1.py +65 -0
- scipy/special/tests/test_precompute_expn_asy.py +24 -0
- scipy/special/tests/test_precompute_gammainc.py +108 -0
- scipy/special/tests/test_precompute_utils.py +36 -0
- scipy/special/tests/test_round.py +18 -0
- scipy/special/tests/test_sf_error.py +146 -0
- scipy/special/tests/test_sici.py +36 -0
- scipy/special/tests/test_specfun.py +48 -0
- scipy/special/tests/test_spence.py +32 -0
- scipy/special/tests/test_spfun_stats.py +61 -0
- scipy/special/tests/test_sph_harm.py +85 -0
- scipy/special/tests/test_spherical_bessel.py +400 -0
- scipy/special/tests/test_support_alternative_backends.py +248 -0
- scipy/special/tests/test_trig.py +72 -0
- scipy/special/tests/test_ufunc_signatures.py +46 -0
- scipy/special/tests/test_wright_bessel.py +205 -0
- scipy/special/tests/test_wrightomega.py +117 -0
- scipy/special/tests/test_zeta.py +301 -0
- scipy/stats/__init__.py +670 -0
- scipy/stats/_ansari_swilk_statistics.cp314t-win_arm64.lib +0 -0
- scipy/stats/_ansari_swilk_statistics.cp314t-win_arm64.pyd +0 -0
- scipy/stats/_axis_nan_policy.py +692 -0
- scipy/stats/_biasedurn.cp314t-win_arm64.lib +0 -0
- scipy/stats/_biasedurn.cp314t-win_arm64.pyd +0 -0
- scipy/stats/_biasedurn.pxd +27 -0
- scipy/stats/_binned_statistic.py +795 -0
- scipy/stats/_binomtest.py +375 -0
- scipy/stats/_bws_test.py +177 -0
- scipy/stats/_censored_data.py +459 -0
- scipy/stats/_common.py +5 -0
- scipy/stats/_constants.py +42 -0
- scipy/stats/_continued_fraction.py +387 -0
- scipy/stats/_continuous_distns.py +12486 -0
- scipy/stats/_correlation.py +210 -0
- scipy/stats/_covariance.py +636 -0
- scipy/stats/_crosstab.py +204 -0
- scipy/stats/_discrete_distns.py +2098 -0
- scipy/stats/_distn_infrastructure.py +4201 -0
- scipy/stats/_distr_params.py +299 -0
- scipy/stats/_distribution_infrastructure.py +5750 -0
- scipy/stats/_entropy.py +428 -0
- scipy/stats/_finite_differences.py +145 -0
- scipy/stats/_fit.py +1351 -0
- scipy/stats/_hypotests.py +2060 -0
- scipy/stats/_kde.py +732 -0
- scipy/stats/_ksstats.py +600 -0
- scipy/stats/_levy_stable/__init__.py +1231 -0
- scipy/stats/_levy_stable/levyst.cp314t-win_arm64.lib +0 -0
- scipy/stats/_levy_stable/levyst.cp314t-win_arm64.pyd +0 -0
- scipy/stats/_mannwhitneyu.py +492 -0
- scipy/stats/_mgc.py +550 -0
- scipy/stats/_morestats.py +4626 -0
- scipy/stats/_mstats_basic.py +3658 -0
- scipy/stats/_mstats_extras.py +521 -0
- scipy/stats/_multicomp.py +449 -0
- scipy/stats/_multivariate.py +7281 -0
- scipy/stats/_new_distributions.py +452 -0
- scipy/stats/_odds_ratio.py +466 -0
- scipy/stats/_page_trend_test.py +486 -0
- scipy/stats/_probability_distribution.py +1964 -0
- scipy/stats/_qmc.py +2956 -0
- scipy/stats/_qmc_cy.cp314t-win_arm64.lib +0 -0
- scipy/stats/_qmc_cy.cp314t-win_arm64.pyd +0 -0
- scipy/stats/_qmc_cy.pyi +54 -0
- scipy/stats/_qmvnt.py +454 -0
- scipy/stats/_qmvnt_cy.cp314t-win_arm64.lib +0 -0
- scipy/stats/_qmvnt_cy.cp314t-win_arm64.pyd +0 -0
- scipy/stats/_quantile.py +335 -0
- scipy/stats/_rcont/__init__.py +4 -0
- scipy/stats/_rcont/rcont.cp314t-win_arm64.lib +0 -0
- scipy/stats/_rcont/rcont.cp314t-win_arm64.pyd +0 -0
- scipy/stats/_relative_risk.py +263 -0
- scipy/stats/_resampling.py +2352 -0
- scipy/stats/_result_classes.py +40 -0
- scipy/stats/_sampling.py +1314 -0
- scipy/stats/_sensitivity_analysis.py +713 -0
- scipy/stats/_sobol.cp314t-win_arm64.lib +0 -0
- scipy/stats/_sobol.cp314t-win_arm64.pyd +0 -0
- scipy/stats/_sobol.pyi +54 -0
- scipy/stats/_sobol_direction_numbers.npz +0 -0
- scipy/stats/_stats.cp314t-win_arm64.lib +0 -0
- scipy/stats/_stats.cp314t-win_arm64.pyd +0 -0
- scipy/stats/_stats.pxd +10 -0
- scipy/stats/_stats_mstats_common.py +322 -0
- scipy/stats/_stats_py.py +11089 -0
- scipy/stats/_stats_pythran.cp314t-win_arm64.lib +0 -0
- scipy/stats/_stats_pythran.cp314t-win_arm64.pyd +0 -0
- scipy/stats/_survival.py +683 -0
- scipy/stats/_tukeylambda_stats.py +199 -0
- scipy/stats/_unuran/__init__.py +0 -0
- scipy/stats/_unuran/unuran_wrapper.cp314t-win_arm64.lib +0 -0
- scipy/stats/_unuran/unuran_wrapper.cp314t-win_arm64.pyd +0 -0
- scipy/stats/_unuran/unuran_wrapper.pyi +179 -0
- scipy/stats/_variation.py +126 -0
- scipy/stats/_warnings_errors.py +38 -0
- scipy/stats/_wilcoxon.py +265 -0
- scipy/stats/biasedurn.py +16 -0
- scipy/stats/contingency.py +521 -0
- scipy/stats/distributions.py +24 -0
- scipy/stats/kde.py +18 -0
- scipy/stats/morestats.py +27 -0
- scipy/stats/mstats.py +140 -0
- scipy/stats/mstats_basic.py +42 -0
- scipy/stats/mstats_extras.py +25 -0
- scipy/stats/mvn.py +17 -0
- scipy/stats/qmc.py +236 -0
- scipy/stats/sampling.py +73 -0
- scipy/stats/stats.py +41 -0
- scipy/stats/tests/__init__.py +0 -0
- scipy/stats/tests/common_tests.py +356 -0
- scipy/stats/tests/data/_mvt.py +171 -0
- scipy/stats/tests/data/fisher_exact_results_from_r.py +607 -0
- scipy/stats/tests/data/jf_skew_t_gamlss_pdf_data.npy +0 -0
- scipy/stats/tests/data/levy_stable/stable-Z1-cdf-sample-data.npy +0 -0
- scipy/stats/tests/data/levy_stable/stable-Z1-pdf-sample-data.npy +0 -0
- scipy/stats/tests/data/levy_stable/stable-loc-scale-sample-data.npy +0 -0
- scipy/stats/tests/data/nist_anova/AtmWtAg.dat +108 -0
- scipy/stats/tests/data/nist_anova/SiRstv.dat +85 -0
- scipy/stats/tests/data/nist_anova/SmLs01.dat +249 -0
- scipy/stats/tests/data/nist_anova/SmLs02.dat +1869 -0
- scipy/stats/tests/data/nist_anova/SmLs03.dat +18069 -0
- scipy/stats/tests/data/nist_anova/SmLs04.dat +249 -0
- scipy/stats/tests/data/nist_anova/SmLs05.dat +1869 -0
- scipy/stats/tests/data/nist_anova/SmLs06.dat +18069 -0
- scipy/stats/tests/data/nist_anova/SmLs07.dat +249 -0
- scipy/stats/tests/data/nist_anova/SmLs08.dat +1869 -0
- scipy/stats/tests/data/nist_anova/SmLs09.dat +18069 -0
- scipy/stats/tests/data/nist_linregress/Norris.dat +97 -0
- scipy/stats/tests/data/rel_breitwigner_pdf_sample_data_ROOT.npy +0 -0
- scipy/stats/tests/data/studentized_range_mpmath_ref.json +1499 -0
- scipy/stats/tests/test_axis_nan_policy.py +1388 -0
- scipy/stats/tests/test_binned_statistic.py +568 -0
- scipy/stats/tests/test_censored_data.py +152 -0
- scipy/stats/tests/test_contingency.py +294 -0
- scipy/stats/tests/test_continued_fraction.py +173 -0
- scipy/stats/tests/test_continuous.py +2198 -0
- scipy/stats/tests/test_continuous_basic.py +1053 -0
- scipy/stats/tests/test_continuous_fit_censored.py +683 -0
- scipy/stats/tests/test_correlation.py +80 -0
- scipy/stats/tests/test_crosstab.py +115 -0
- scipy/stats/tests/test_discrete_basic.py +580 -0
- scipy/stats/tests/test_discrete_distns.py +700 -0
- scipy/stats/tests/test_distributions.py +10413 -0
- scipy/stats/tests/test_entropy.py +322 -0
- scipy/stats/tests/test_fast_gen_inversion.py +435 -0
- scipy/stats/tests/test_fit.py +1090 -0
- scipy/stats/tests/test_hypotests.py +1991 -0
- scipy/stats/tests/test_kdeoth.py +676 -0
- scipy/stats/tests/test_marray.py +289 -0
- scipy/stats/tests/test_mgc.py +217 -0
- scipy/stats/tests/test_morestats.py +3259 -0
- scipy/stats/tests/test_mstats_basic.py +2071 -0
- scipy/stats/tests/test_mstats_extras.py +172 -0
- scipy/stats/tests/test_multicomp.py +405 -0
- scipy/stats/tests/test_multivariate.py +4381 -0
- scipy/stats/tests/test_odds_ratio.py +148 -0
- scipy/stats/tests/test_qmc.py +1492 -0
- scipy/stats/tests/test_quantile.py +199 -0
- scipy/stats/tests/test_rank.py +345 -0
- scipy/stats/tests/test_relative_risk.py +95 -0
- scipy/stats/tests/test_resampling.py +2000 -0
- scipy/stats/tests/test_sampling.py +1450 -0
- scipy/stats/tests/test_sensitivity_analysis.py +310 -0
- scipy/stats/tests/test_stats.py +9707 -0
- scipy/stats/tests/test_survival.py +466 -0
- scipy/stats/tests/test_tukeylambda_stats.py +85 -0
- scipy/stats/tests/test_variation.py +216 -0
- scipy/version.py +12 -0
- scipy-1.16.2.dist-info/DELVEWHEEL +2 -0
- scipy-1.16.2.dist-info/LICENSE.txt +912 -0
- scipy-1.16.2.dist-info/METADATA +1061 -0
- scipy-1.16.2.dist-info/RECORD +1530 -0
- scipy-1.16.2.dist-info/WHEEL +4 -0
- scipy.libs/msvcp140-5f1c5dd31916990d94181e07bc3afb32.dll +0 -0
- scipy.libs/scipy_openblas-f3ac85b1f412f7e86514c923dc4058d1.dll +0 -0
@@ -0,0 +1,2352 @@
|
|
1
|
+
import warnings
|
2
|
+
import numpy as np
|
3
|
+
from itertools import combinations, permutations, product
|
4
|
+
from collections.abc import Sequence
|
5
|
+
from dataclasses import dataclass, field
|
6
|
+
import inspect
|
7
|
+
|
8
|
+
from scipy._lib._util import (check_random_state, _rename_parameter, rng_integers,
|
9
|
+
_transition_to_rng)
|
10
|
+
from scipy._lib._array_api import array_namespace, is_numpy, xp_result_type
|
11
|
+
from scipy.special import ndtr, ndtri, comb, factorial
|
12
|
+
|
13
|
+
from ._common import ConfidenceInterval
|
14
|
+
from ._axis_nan_policy import _broadcast_concatenate, _broadcast_arrays
|
15
|
+
from ._warnings_errors import DegenerateDataWarning
|
16
|
+
|
17
|
+
__all__ = ['bootstrap', 'monte_carlo_test', 'permutation_test']
|
18
|
+
|
19
|
+
|
20
|
+
def _vectorize_statistic(statistic):
|
21
|
+
"""Vectorize an n-sample statistic"""
|
22
|
+
# This is a little cleaner than np.nditer at the expense of some data
|
23
|
+
# copying: concatenate samples together, then use np.apply_along_axis
|
24
|
+
def stat_nd(*data, axis=0):
|
25
|
+
lengths = [sample.shape[axis] for sample in data]
|
26
|
+
split_indices = np.cumsum(lengths)[:-1]
|
27
|
+
z = _broadcast_concatenate(data, axis)
|
28
|
+
|
29
|
+
# move working axis to position 0 so that new dimensions in the output
|
30
|
+
# of `statistic` are _prepended_. ("This axis is removed, and replaced
|
31
|
+
# with new dimensions...")
|
32
|
+
z = np.moveaxis(z, axis, 0)
|
33
|
+
|
34
|
+
def stat_1d(z):
|
35
|
+
data = np.split(z, split_indices)
|
36
|
+
return statistic(*data)
|
37
|
+
|
38
|
+
return np.apply_along_axis(stat_1d, 0, z)[()]
|
39
|
+
return stat_nd
|
40
|
+
|
41
|
+
|
42
|
+
def _jackknife_resample(sample, batch=None):
|
43
|
+
"""Jackknife resample the sample. Only one-sample stats for now."""
|
44
|
+
n = sample.shape[-1]
|
45
|
+
batch_nominal = batch or n
|
46
|
+
|
47
|
+
for k in range(0, n, batch_nominal):
|
48
|
+
# col_start:col_end are the observations to remove
|
49
|
+
batch_actual = min(batch_nominal, n-k)
|
50
|
+
|
51
|
+
# jackknife - each row leaves out one observation
|
52
|
+
j = np.ones((batch_actual, n), dtype=bool)
|
53
|
+
np.fill_diagonal(j[:, k:k+batch_actual], False)
|
54
|
+
i = np.arange(n)
|
55
|
+
i = np.broadcast_to(i, (batch_actual, n))
|
56
|
+
i = i[j].reshape((batch_actual, n-1))
|
57
|
+
|
58
|
+
resamples = sample[..., i]
|
59
|
+
yield resamples
|
60
|
+
|
61
|
+
|
62
|
+
def _bootstrap_resample(sample, n_resamples=None, rng=None):
|
63
|
+
"""Bootstrap resample the sample."""
|
64
|
+
n = sample.shape[-1]
|
65
|
+
|
66
|
+
# bootstrap - each row is a random resample of original observations
|
67
|
+
i = rng_integers(rng, 0, n, (n_resamples, n))
|
68
|
+
|
69
|
+
resamples = sample[..., i]
|
70
|
+
return resamples
|
71
|
+
|
72
|
+
|
73
|
+
def _percentile_of_score(a, score, axis):
|
74
|
+
"""Vectorized, simplified `scipy.stats.percentileofscore`.
|
75
|
+
Uses logic of the 'mean' value of percentileofscore's kind parameter.
|
76
|
+
|
77
|
+
Unlike `stats.percentileofscore`, the percentile returned is a fraction
|
78
|
+
in [0, 1].
|
79
|
+
"""
|
80
|
+
B = a.shape[axis]
|
81
|
+
return ((a < score).sum(axis=axis) + (a <= score).sum(axis=axis)) / (2 * B)
|
82
|
+
|
83
|
+
|
84
|
+
def _percentile_along_axis(theta_hat_b, alpha):
|
85
|
+
"""`np.percentile` with different percentile for each slice."""
|
86
|
+
# the difference between _percentile_along_axis and np.percentile is that
|
87
|
+
# np.percentile gets _all_ the qs for each axis slice, whereas
|
88
|
+
# _percentile_along_axis gets the q corresponding with each axis slice
|
89
|
+
shape = theta_hat_b.shape[:-1]
|
90
|
+
alpha = np.broadcast_to(alpha, shape)
|
91
|
+
percentiles = np.zeros_like(alpha, dtype=np.float64)
|
92
|
+
for indices, alpha_i in np.ndenumerate(alpha):
|
93
|
+
if np.isnan(alpha_i):
|
94
|
+
# e.g. when bootstrap distribution has only one unique element
|
95
|
+
msg = (
|
96
|
+
"The BCa confidence interval cannot be calculated."
|
97
|
+
" This problem is known to occur when the distribution"
|
98
|
+
" is degenerate or the statistic is np.min."
|
99
|
+
)
|
100
|
+
warnings.warn(DegenerateDataWarning(msg), stacklevel=3)
|
101
|
+
percentiles[indices] = np.nan
|
102
|
+
else:
|
103
|
+
theta_hat_b_i = theta_hat_b[indices]
|
104
|
+
percentiles[indices] = np.percentile(theta_hat_b_i, alpha_i)
|
105
|
+
return percentiles[()] # return scalar instead of 0d array
|
106
|
+
|
107
|
+
|
108
|
+
def _bca_interval(data, statistic, axis, alpha, theta_hat_b, batch):
|
109
|
+
"""Bias-corrected and accelerated interval."""
|
110
|
+
# closely follows [1] 14.3 and 15.4 (Eq. 15.36)
|
111
|
+
|
112
|
+
# calculate z0_hat
|
113
|
+
theta_hat = np.asarray(statistic(*data, axis=axis))[..., None]
|
114
|
+
percentile = _percentile_of_score(theta_hat_b, theta_hat, axis=-1)
|
115
|
+
z0_hat = ndtri(percentile)
|
116
|
+
|
117
|
+
# calculate a_hat
|
118
|
+
theta_hat_ji = [] # j is for sample of data, i is for jackknife resample
|
119
|
+
for j, sample in enumerate(data):
|
120
|
+
# _jackknife_resample will add an axis prior to the last axis that
|
121
|
+
# corresponds with the different jackknife resamples. Do the same for
|
122
|
+
# each sample of the data to ensure broadcastability. We need to
|
123
|
+
# create a copy of the list containing the samples anyway, so do this
|
124
|
+
# in the loop to simplify the code. This is not the bottleneck...
|
125
|
+
samples = [np.expand_dims(sample, -2) for sample in data]
|
126
|
+
theta_hat_i = []
|
127
|
+
for jackknife_sample in _jackknife_resample(sample, batch):
|
128
|
+
samples[j] = jackknife_sample
|
129
|
+
broadcasted = _broadcast_arrays(samples, axis=-1)
|
130
|
+
theta_hat_i.append(statistic(*broadcasted, axis=-1))
|
131
|
+
theta_hat_ji.append(theta_hat_i)
|
132
|
+
|
133
|
+
theta_hat_ji = [np.concatenate(theta_hat_i, axis=-1)
|
134
|
+
for theta_hat_i in theta_hat_ji]
|
135
|
+
|
136
|
+
n_j = [theta_hat_i.shape[-1] for theta_hat_i in theta_hat_ji]
|
137
|
+
|
138
|
+
theta_hat_j_dot = [theta_hat_i.mean(axis=-1, keepdims=True)
|
139
|
+
for theta_hat_i in theta_hat_ji]
|
140
|
+
|
141
|
+
U_ji = [(n - 1) * (theta_hat_dot - theta_hat_i)
|
142
|
+
for theta_hat_dot, theta_hat_i, n
|
143
|
+
in zip(theta_hat_j_dot, theta_hat_ji, n_j)]
|
144
|
+
|
145
|
+
nums = [(U_i**3).sum(axis=-1)/n**3 for U_i, n in zip(U_ji, n_j)]
|
146
|
+
dens = [(U_i**2).sum(axis=-1)/n**2 for U_i, n in zip(U_ji, n_j)]
|
147
|
+
a_hat = 1/6 * sum(nums) / sum(dens)**(3/2)
|
148
|
+
|
149
|
+
# calculate alpha_1, alpha_2
|
150
|
+
z_alpha = ndtri(alpha)
|
151
|
+
z_1alpha = -z_alpha
|
152
|
+
num1 = z0_hat + z_alpha
|
153
|
+
alpha_1 = ndtr(z0_hat + num1/(1 - a_hat*num1))
|
154
|
+
num2 = z0_hat + z_1alpha
|
155
|
+
alpha_2 = ndtr(z0_hat + num2/(1 - a_hat*num2))
|
156
|
+
return alpha_1, alpha_2, a_hat # return a_hat for testing
|
157
|
+
|
158
|
+
|
159
|
+
def _bootstrap_iv(data, statistic, vectorized, paired, axis, confidence_level,
|
160
|
+
alternative, n_resamples, batch, method, bootstrap_result,
|
161
|
+
rng):
|
162
|
+
"""Input validation and standardization for `bootstrap`."""
|
163
|
+
|
164
|
+
if vectorized not in {True, False, None}:
|
165
|
+
raise ValueError("`vectorized` must be `True`, `False`, or `None`.")
|
166
|
+
|
167
|
+
if vectorized is None:
|
168
|
+
vectorized = 'axis' in inspect.signature(statistic).parameters
|
169
|
+
|
170
|
+
if not vectorized:
|
171
|
+
statistic = _vectorize_statistic(statistic)
|
172
|
+
|
173
|
+
axis_int = int(axis)
|
174
|
+
if axis != axis_int:
|
175
|
+
raise ValueError("`axis` must be an integer.")
|
176
|
+
|
177
|
+
n_samples = 0
|
178
|
+
try:
|
179
|
+
n_samples = len(data)
|
180
|
+
except TypeError:
|
181
|
+
raise ValueError("`data` must be a sequence of samples.")
|
182
|
+
|
183
|
+
if n_samples == 0:
|
184
|
+
raise ValueError("`data` must contain at least one sample.")
|
185
|
+
|
186
|
+
data = _broadcast_arrays(data, axis_int)
|
187
|
+
|
188
|
+
data_iv = []
|
189
|
+
for sample in data:
|
190
|
+
if sample.shape[axis_int] <= 1:
|
191
|
+
raise ValueError("each sample in `data` must contain two or more "
|
192
|
+
"observations along `axis`.")
|
193
|
+
sample = np.moveaxis(sample, axis_int, -1)
|
194
|
+
data_iv.append(sample)
|
195
|
+
|
196
|
+
if paired not in {True, False}:
|
197
|
+
raise ValueError("`paired` must be `True` or `False`.")
|
198
|
+
|
199
|
+
if paired:
|
200
|
+
n = data_iv[0].shape[-1]
|
201
|
+
for sample in data_iv[1:]:
|
202
|
+
if sample.shape[-1] != n:
|
203
|
+
message = ("When `paired is True`, all samples must have the "
|
204
|
+
"same length along `axis`")
|
205
|
+
raise ValueError(message)
|
206
|
+
|
207
|
+
# to generate the bootstrap distribution for paired-sample statistics,
|
208
|
+
# resample the indices of the observations
|
209
|
+
def statistic(i, axis=-1, data=data_iv, unpaired_statistic=statistic):
|
210
|
+
data = [sample[..., i] for sample in data]
|
211
|
+
return unpaired_statistic(*data, axis=axis)
|
212
|
+
|
213
|
+
data_iv = [np.arange(n)]
|
214
|
+
|
215
|
+
confidence_level_float = float(confidence_level)
|
216
|
+
|
217
|
+
alternative = alternative.lower()
|
218
|
+
alternatives = {'two-sided', 'less', 'greater'}
|
219
|
+
if alternative not in alternatives:
|
220
|
+
raise ValueError(f"`alternative` must be one of {alternatives}")
|
221
|
+
|
222
|
+
n_resamples_int = int(n_resamples)
|
223
|
+
if n_resamples != n_resamples_int or n_resamples_int < 0:
|
224
|
+
raise ValueError("`n_resamples` must be a non-negative integer.")
|
225
|
+
|
226
|
+
if batch is None:
|
227
|
+
batch_iv = batch
|
228
|
+
else:
|
229
|
+
batch_iv = int(batch)
|
230
|
+
if batch != batch_iv or batch_iv <= 0:
|
231
|
+
raise ValueError("`batch` must be a positive integer or None.")
|
232
|
+
|
233
|
+
methods = {'percentile', 'basic', 'bca'}
|
234
|
+
method = method.lower()
|
235
|
+
if method not in methods:
|
236
|
+
raise ValueError(f"`method` must be in {methods}")
|
237
|
+
|
238
|
+
message = "`bootstrap_result` must have attribute `bootstrap_distribution'"
|
239
|
+
if (bootstrap_result is not None
|
240
|
+
and not hasattr(bootstrap_result, "bootstrap_distribution")):
|
241
|
+
raise ValueError(message)
|
242
|
+
|
243
|
+
message = ("Either `bootstrap_result.bootstrap_distribution.size` or "
|
244
|
+
"`n_resamples` must be positive.")
|
245
|
+
if ((not bootstrap_result or
|
246
|
+
not bootstrap_result.bootstrap_distribution.size)
|
247
|
+
and n_resamples_int == 0):
|
248
|
+
raise ValueError(message)
|
249
|
+
|
250
|
+
rng = check_random_state(rng)
|
251
|
+
|
252
|
+
return (data_iv, statistic, vectorized, paired, axis_int,
|
253
|
+
confidence_level_float, alternative, n_resamples_int, batch_iv,
|
254
|
+
method, bootstrap_result, rng)
|
255
|
+
|
256
|
+
|
257
|
+
@dataclass
|
258
|
+
class BootstrapResult:
|
259
|
+
"""Result object returned by `scipy.stats.bootstrap`.
|
260
|
+
|
261
|
+
Attributes
|
262
|
+
----------
|
263
|
+
confidence_interval : ConfidenceInterval
|
264
|
+
The bootstrap confidence interval as an instance of
|
265
|
+
`collections.namedtuple` with attributes `low` and `high`.
|
266
|
+
bootstrap_distribution : ndarray
|
267
|
+
The bootstrap distribution, that is, the value of `statistic` for
|
268
|
+
each resample. The last dimension corresponds with the resamples
|
269
|
+
(e.g. ``res.bootstrap_distribution.shape[-1] == n_resamples``).
|
270
|
+
standard_error : float or ndarray
|
271
|
+
The bootstrap standard error, that is, the sample standard
|
272
|
+
deviation of the bootstrap distribution.
|
273
|
+
|
274
|
+
"""
|
275
|
+
confidence_interval: ConfidenceInterval
|
276
|
+
bootstrap_distribution: np.ndarray
|
277
|
+
standard_error: float | np.ndarray
|
278
|
+
|
279
|
+
|
280
|
+
@_transition_to_rng('random_state')
|
281
|
+
def bootstrap(data, statistic, *, n_resamples=9999, batch=None,
|
282
|
+
vectorized=None, paired=False, axis=0, confidence_level=0.95,
|
283
|
+
alternative='two-sided', method='BCa', bootstrap_result=None,
|
284
|
+
rng=None):
|
285
|
+
r"""
|
286
|
+
Compute a two-sided bootstrap confidence interval of a statistic.
|
287
|
+
|
288
|
+
When `method` is ``'percentile'`` and `alternative` is ``'two-sided'``,
|
289
|
+
a bootstrap confidence interval is computed according to the following
|
290
|
+
procedure.
|
291
|
+
|
292
|
+
1. Resample the data: for each sample in `data` and for each of
|
293
|
+
`n_resamples`, take a random sample of the original sample
|
294
|
+
(with replacement) of the same size as the original sample.
|
295
|
+
|
296
|
+
2. Compute the bootstrap distribution of the statistic: for each set of
|
297
|
+
resamples, compute the test statistic.
|
298
|
+
|
299
|
+
3. Determine the confidence interval: find the interval of the bootstrap
|
300
|
+
distribution that is
|
301
|
+
|
302
|
+
- symmetric about the median and
|
303
|
+
- contains `confidence_level` of the resampled statistic values.
|
304
|
+
|
305
|
+
While the ``'percentile'`` method is the most intuitive, it is rarely
|
306
|
+
used in practice. Two more common methods are available, ``'basic'``
|
307
|
+
('reverse percentile') and ``'BCa'`` ('bias-corrected and accelerated');
|
308
|
+
they differ in how step 3 is performed.
|
309
|
+
|
310
|
+
If the samples in `data` are taken at random from their respective
|
311
|
+
distributions :math:`n` times, the confidence interval returned by
|
312
|
+
`bootstrap` will contain the true value of the statistic for those
|
313
|
+
distributions approximately `confidence_level`:math:`\, \times \, n` times.
|
314
|
+
|
315
|
+
Parameters
|
316
|
+
----------
|
317
|
+
data : sequence of array-like
|
318
|
+
Each element of `data` is a sample containing scalar observations from an
|
319
|
+
underlying distribution. Elements of `data` must be broadcastable to the
|
320
|
+
same shape (with the possible exception of the dimension specified by `axis`).
|
321
|
+
statistic : callable
|
322
|
+
Statistic for which the confidence interval is to be calculated.
|
323
|
+
`statistic` must be a callable that accepts ``len(data)`` samples
|
324
|
+
as separate arguments and returns the resulting statistic.
|
325
|
+
If `vectorized` is set ``True``,
|
326
|
+
`statistic` must also accept a keyword argument `axis` and be
|
327
|
+
vectorized to compute the statistic along the provided `axis`.
|
328
|
+
n_resamples : int, default: ``9999``
|
329
|
+
The number of resamples performed to form the bootstrap distribution
|
330
|
+
of the statistic.
|
331
|
+
batch : int, optional
|
332
|
+
The number of resamples to process in each vectorized call to
|
333
|
+
`statistic`. Memory usage is O( `batch` * ``n`` ), where ``n`` is the
|
334
|
+
sample size. Default is ``None``, in which case ``batch = n_resamples``
|
335
|
+
(or ``batch = max(n_resamples, n)`` for ``method='BCa'``).
|
336
|
+
vectorized : bool, optional
|
337
|
+
If `vectorized` is set ``False``, `statistic` will not be passed
|
338
|
+
keyword argument `axis` and is expected to calculate the statistic
|
339
|
+
only for 1D samples. If ``True``, `statistic` will be passed keyword
|
340
|
+
argument `axis` and is expected to calculate the statistic along `axis`
|
341
|
+
when passed an ND sample array. If ``None`` (default), `vectorized`
|
342
|
+
will be set ``True`` if ``axis`` is a parameter of `statistic`. Use of
|
343
|
+
a vectorized statistic typically reduces computation time.
|
344
|
+
paired : bool, default: ``False``
|
345
|
+
Whether the statistic treats corresponding elements of the samples
|
346
|
+
in `data` as paired. If True, `bootstrap` resamples an array of
|
347
|
+
*indices* and uses the same indices for all arrays in `data`; otherwise,
|
348
|
+
`bootstrap` independently resamples the elements of each array.
|
349
|
+
axis : int, default: ``0``
|
350
|
+
The axis of the samples in `data` along which the `statistic` is
|
351
|
+
calculated.
|
352
|
+
confidence_level : float, default: ``0.95``
|
353
|
+
The confidence level of the confidence interval.
|
354
|
+
alternative : {'two-sided', 'less', 'greater'}, default: ``'two-sided'``
|
355
|
+
Choose ``'two-sided'`` (default) for a two-sided confidence interval,
|
356
|
+
``'less'`` for a one-sided confidence interval with the lower bound
|
357
|
+
at ``-np.inf``, and ``'greater'`` for a one-sided confidence interval
|
358
|
+
with the upper bound at ``np.inf``. The other bound of the one-sided
|
359
|
+
confidence intervals is the same as that of a two-sided confidence
|
360
|
+
interval with `confidence_level` twice as far from 1.0; e.g. the upper
|
361
|
+
bound of a 95% ``'less'`` confidence interval is the same as the upper
|
362
|
+
bound of a 90% ``'two-sided'`` confidence interval.
|
363
|
+
method : {'percentile', 'basic', 'bca'}, default: ``'BCa'``
|
364
|
+
Whether to return the 'percentile' bootstrap confidence interval
|
365
|
+
(``'percentile'``), the 'basic' (AKA 'reverse') bootstrap confidence
|
366
|
+
interval (``'basic'``), or the bias-corrected and accelerated bootstrap
|
367
|
+
confidence interval (``'BCa'``).
|
368
|
+
bootstrap_result : BootstrapResult, optional
|
369
|
+
Provide the result object returned by a previous call to `bootstrap`
|
370
|
+
to include the previous bootstrap distribution in the new bootstrap
|
371
|
+
distribution. This can be used, for example, to change
|
372
|
+
`confidence_level`, change `method`, or see the effect of performing
|
373
|
+
additional resampling without repeating computations.
|
374
|
+
rng : `numpy.random.Generator`, optional
|
375
|
+
Pseudorandom number generator state. When `rng` is None, a new
|
376
|
+
`numpy.random.Generator` is created using entropy from the
|
377
|
+
operating system. Types other than `numpy.random.Generator` are
|
378
|
+
passed to `numpy.random.default_rng` to instantiate a ``Generator``.
|
379
|
+
|
380
|
+
Returns
|
381
|
+
-------
|
382
|
+
res : BootstrapResult
|
383
|
+
An object with attributes:
|
384
|
+
|
385
|
+
confidence_interval : ConfidenceInterval
|
386
|
+
The bootstrap confidence interval as an instance of
|
387
|
+
`collections.namedtuple` with attributes `low` and `high`.
|
388
|
+
bootstrap_distribution : ndarray
|
389
|
+
The bootstrap distribution, that is, the value of `statistic` for
|
390
|
+
each resample. The last dimension corresponds with the resamples
|
391
|
+
(e.g. ``res.bootstrap_distribution.shape[-1] == n_resamples``).
|
392
|
+
standard_error : float or ndarray
|
393
|
+
The bootstrap standard error, that is, the sample standard
|
394
|
+
deviation of the bootstrap distribution.
|
395
|
+
|
396
|
+
Warns
|
397
|
+
-----
|
398
|
+
`~scipy.stats.DegenerateDataWarning`
|
399
|
+
Generated when ``method='BCa'`` and the bootstrap distribution is
|
400
|
+
degenerate (e.g. all elements are identical).
|
401
|
+
|
402
|
+
Notes
|
403
|
+
-----
|
404
|
+
Elements of the confidence interval may be NaN for ``method='BCa'`` if
|
405
|
+
the bootstrap distribution is degenerate (e.g. all elements are identical).
|
406
|
+
In this case, consider using another `method` or inspecting `data` for
|
407
|
+
indications that other analysis may be more appropriate (e.g. all
|
408
|
+
observations are identical).
|
409
|
+
|
410
|
+
References
|
411
|
+
----------
|
412
|
+
.. [1] B. Efron and R. J. Tibshirani, An Introduction to the Bootstrap,
|
413
|
+
Chapman & Hall/CRC, Boca Raton, FL, USA (1993)
|
414
|
+
.. [2] Nathaniel E. Helwig, "Bootstrap Confidence Intervals",
|
415
|
+
http://users.stat.umn.edu/~helwig/notes/bootci-Notes.pdf
|
416
|
+
.. [3] Bootstrapping (statistics), Wikipedia,
|
417
|
+
https://en.wikipedia.org/wiki/Bootstrapping_%28statistics%29
|
418
|
+
|
419
|
+
Examples
|
420
|
+
--------
|
421
|
+
Suppose we have sampled data from an unknown distribution.
|
422
|
+
|
423
|
+
>>> import numpy as np
|
424
|
+
>>> rng = np.random.default_rng()
|
425
|
+
>>> from scipy.stats import norm
|
426
|
+
>>> dist = norm(loc=2, scale=4) # our "unknown" distribution
|
427
|
+
>>> data = dist.rvs(size=100, random_state=rng)
|
428
|
+
|
429
|
+
We are interested in the standard deviation of the distribution.
|
430
|
+
|
431
|
+
>>> std_true = dist.std() # the true value of the statistic
|
432
|
+
>>> print(std_true)
|
433
|
+
4.0
|
434
|
+
>>> std_sample = np.std(data) # the sample statistic
|
435
|
+
>>> print(std_sample)
|
436
|
+
3.9460644295563863
|
437
|
+
|
438
|
+
The bootstrap is used to approximate the variability we would expect if we
|
439
|
+
were to repeatedly sample from the unknown distribution and calculate the
|
440
|
+
statistic of the sample each time. It does this by repeatedly resampling
|
441
|
+
values *from the original sample* with replacement and calculating the
|
442
|
+
statistic of each resample. This results in a "bootstrap distribution" of
|
443
|
+
the statistic.
|
444
|
+
|
445
|
+
>>> import matplotlib.pyplot as plt
|
446
|
+
>>> from scipy.stats import bootstrap
|
447
|
+
>>> data = (data,) # samples must be in a sequence
|
448
|
+
>>> res = bootstrap(data, np.std, confidence_level=0.9, rng=rng)
|
449
|
+
>>> fig, ax = plt.subplots()
|
450
|
+
>>> ax.hist(res.bootstrap_distribution, bins=25)
|
451
|
+
>>> ax.set_title('Bootstrap Distribution')
|
452
|
+
>>> ax.set_xlabel('statistic value')
|
453
|
+
>>> ax.set_ylabel('frequency')
|
454
|
+
>>> plt.show()
|
455
|
+
|
456
|
+
The standard error quantifies this variability. It is calculated as the
|
457
|
+
standard deviation of the bootstrap distribution.
|
458
|
+
|
459
|
+
>>> res.standard_error
|
460
|
+
0.24427002125829136
|
461
|
+
>>> res.standard_error == np.std(res.bootstrap_distribution, ddof=1)
|
462
|
+
True
|
463
|
+
|
464
|
+
The bootstrap distribution of the statistic is often approximately normal
|
465
|
+
with scale equal to the standard error.
|
466
|
+
|
467
|
+
>>> x = np.linspace(3, 5)
|
468
|
+
>>> pdf = norm.pdf(x, loc=std_sample, scale=res.standard_error)
|
469
|
+
>>> fig, ax = plt.subplots()
|
470
|
+
>>> ax.hist(res.bootstrap_distribution, bins=25, density=True)
|
471
|
+
>>> ax.plot(x, pdf)
|
472
|
+
>>> ax.set_title('Normal Approximation of the Bootstrap Distribution')
|
473
|
+
>>> ax.set_xlabel('statistic value')
|
474
|
+
>>> ax.set_ylabel('pdf')
|
475
|
+
>>> plt.show()
|
476
|
+
|
477
|
+
This suggests that we could construct a 90% confidence interval on the
|
478
|
+
statistic based on quantiles of this normal distribution.
|
479
|
+
|
480
|
+
>>> norm.interval(0.9, loc=std_sample, scale=res.standard_error)
|
481
|
+
(3.5442759991341726, 4.3478528599786)
|
482
|
+
|
483
|
+
Due to central limit theorem, this normal approximation is accurate for a
|
484
|
+
variety of statistics and distributions underlying the samples; however,
|
485
|
+
the approximation is not reliable in all cases. Because `bootstrap` is
|
486
|
+
designed to work with arbitrary underlying distributions and statistics,
|
487
|
+
it uses more advanced techniques to generate an accurate confidence
|
488
|
+
interval.
|
489
|
+
|
490
|
+
>>> print(res.confidence_interval)
|
491
|
+
ConfidenceInterval(low=3.57655333533867, high=4.382043696342881)
|
492
|
+
|
493
|
+
If we sample from the original distribution 100 times and form a bootstrap
|
494
|
+
confidence interval for each sample, the confidence interval
|
495
|
+
contains the true value of the statistic approximately 90% of the time.
|
496
|
+
|
497
|
+
>>> n_trials = 100
|
498
|
+
>>> ci_contains_true_std = 0
|
499
|
+
>>> for i in range(n_trials):
|
500
|
+
... data = (dist.rvs(size=100, random_state=rng),)
|
501
|
+
... res = bootstrap(data, np.std, confidence_level=0.9,
|
502
|
+
... n_resamples=999, rng=rng)
|
503
|
+
... ci = res.confidence_interval
|
504
|
+
... if ci[0] < std_true < ci[1]:
|
505
|
+
... ci_contains_true_std += 1
|
506
|
+
>>> print(ci_contains_true_std)
|
507
|
+
88
|
508
|
+
|
509
|
+
Rather than writing a loop, we can also determine the confidence intervals
|
510
|
+
for all 100 samples at once.
|
511
|
+
|
512
|
+
>>> data = (dist.rvs(size=(n_trials, 100), random_state=rng),)
|
513
|
+
>>> res = bootstrap(data, np.std, axis=-1, confidence_level=0.9,
|
514
|
+
... n_resamples=999, rng=rng)
|
515
|
+
>>> ci_l, ci_u = res.confidence_interval
|
516
|
+
|
517
|
+
Here, `ci_l` and `ci_u` contain the confidence interval for each of the
|
518
|
+
``n_trials = 100`` samples.
|
519
|
+
|
520
|
+
>>> print(ci_l[:5])
|
521
|
+
[3.86401283 3.33304394 3.52474647 3.54160981 3.80569252]
|
522
|
+
>>> print(ci_u[:5])
|
523
|
+
[4.80217409 4.18143252 4.39734707 4.37549713 4.72843584]
|
524
|
+
|
525
|
+
And again, approximately 90% contain the true value, ``std_true = 4``.
|
526
|
+
|
527
|
+
>>> print(np.sum((ci_l < std_true) & (std_true < ci_u)))
|
528
|
+
93
|
529
|
+
|
530
|
+
`bootstrap` can also be used to estimate confidence intervals of
|
531
|
+
multi-sample statistics. For example, to get a confidence interval
|
532
|
+
for the difference between means, we write a function that accepts
|
533
|
+
two sample arguments and returns only the statistic. The use of the
|
534
|
+
``axis`` argument ensures that all mean calculations are perform in
|
535
|
+
a single vectorized call, which is faster than looping over pairs
|
536
|
+
of resamples in Python.
|
537
|
+
|
538
|
+
>>> def my_statistic(sample1, sample2, axis=-1):
|
539
|
+
... mean1 = np.mean(sample1, axis=axis)
|
540
|
+
... mean2 = np.mean(sample2, axis=axis)
|
541
|
+
... return mean1 - mean2
|
542
|
+
|
543
|
+
Here, we use the 'percentile' method with the default 95% confidence level.
|
544
|
+
|
545
|
+
>>> sample1 = norm.rvs(scale=1, size=100, random_state=rng)
|
546
|
+
>>> sample2 = norm.rvs(scale=2, size=100, random_state=rng)
|
547
|
+
>>> data = (sample1, sample2)
|
548
|
+
>>> res = bootstrap(data, my_statistic, method='basic', rng=rng)
|
549
|
+
>>> print(my_statistic(sample1, sample2))
|
550
|
+
0.16661030792089523
|
551
|
+
>>> print(res.confidence_interval)
|
552
|
+
ConfidenceInterval(low=-0.29087973240818693, high=0.6371338699912273)
|
553
|
+
|
554
|
+
The bootstrap estimate of the standard error is also available.
|
555
|
+
|
556
|
+
>>> print(res.standard_error)
|
557
|
+
0.238323948262459
|
558
|
+
|
559
|
+
Paired-sample statistics work, too. For example, consider the Pearson
|
560
|
+
correlation coefficient.
|
561
|
+
|
562
|
+
>>> from scipy.stats import pearsonr
|
563
|
+
>>> n = 100
|
564
|
+
>>> x = np.linspace(0, 10, n)
|
565
|
+
>>> y = x + rng.uniform(size=n)
|
566
|
+
>>> print(pearsonr(x, y)[0]) # element 0 is the statistic
|
567
|
+
0.9954306665125647
|
568
|
+
|
569
|
+
We wrap `pearsonr` so that it returns only the statistic, ensuring
|
570
|
+
that we use the `axis` argument because it is available.
|
571
|
+
|
572
|
+
>>> def my_statistic(x, y, axis=-1):
|
573
|
+
... return pearsonr(x, y, axis=axis)[0]
|
574
|
+
|
575
|
+
We call `bootstrap` using ``paired=True``.
|
576
|
+
|
577
|
+
>>> res = bootstrap((x, y), my_statistic, paired=True, rng=rng)
|
578
|
+
>>> print(res.confidence_interval)
|
579
|
+
ConfidenceInterval(low=0.9941504301315878, high=0.996377412215445)
|
580
|
+
|
581
|
+
The result object can be passed back into `bootstrap` to perform additional
|
582
|
+
resampling:
|
583
|
+
|
584
|
+
>>> len(res.bootstrap_distribution)
|
585
|
+
9999
|
586
|
+
>>> res = bootstrap((x, y), my_statistic, paired=True,
|
587
|
+
... n_resamples=1000, rng=rng,
|
588
|
+
... bootstrap_result=res)
|
589
|
+
>>> len(res.bootstrap_distribution)
|
590
|
+
10999
|
591
|
+
|
592
|
+
or to change the confidence interval options:
|
593
|
+
|
594
|
+
>>> res2 = bootstrap((x, y), my_statistic, paired=True,
|
595
|
+
... n_resamples=0, rng=rng, bootstrap_result=res,
|
596
|
+
... method='percentile', confidence_level=0.9)
|
597
|
+
>>> np.testing.assert_equal(res2.bootstrap_distribution,
|
598
|
+
... res.bootstrap_distribution)
|
599
|
+
>>> res.confidence_interval
|
600
|
+
ConfidenceInterval(low=0.9941574828235082, high=0.9963781698210212)
|
601
|
+
|
602
|
+
without repeating computation of the original bootstrap distribution.
|
603
|
+
|
604
|
+
"""
|
605
|
+
# Input validation
|
606
|
+
args = _bootstrap_iv(data, statistic, vectorized, paired, axis,
|
607
|
+
confidence_level, alternative, n_resamples, batch,
|
608
|
+
method, bootstrap_result, rng)
|
609
|
+
(data, statistic, vectorized, paired, axis, confidence_level,
|
610
|
+
alternative, n_resamples, batch, method, bootstrap_result,
|
611
|
+
rng) = args
|
612
|
+
|
613
|
+
theta_hat_b = ([] if bootstrap_result is None
|
614
|
+
else [bootstrap_result.bootstrap_distribution])
|
615
|
+
|
616
|
+
batch_nominal = batch or n_resamples or 1
|
617
|
+
|
618
|
+
for k in range(0, n_resamples, batch_nominal):
|
619
|
+
batch_actual = min(batch_nominal, n_resamples-k)
|
620
|
+
# Generate resamples
|
621
|
+
resampled_data = []
|
622
|
+
for sample in data:
|
623
|
+
resample = _bootstrap_resample(sample, n_resamples=batch_actual,
|
624
|
+
rng=rng)
|
625
|
+
resampled_data.append(resample)
|
626
|
+
|
627
|
+
# Compute bootstrap distribution of statistic
|
628
|
+
theta_hat_b.append(statistic(*resampled_data, axis=-1))
|
629
|
+
theta_hat_b = np.concatenate(theta_hat_b, axis=-1)
|
630
|
+
|
631
|
+
# Calculate percentile interval
|
632
|
+
alpha = ((1 - confidence_level)/2 if alternative == 'two-sided'
|
633
|
+
else (1 - confidence_level))
|
634
|
+
if method == 'bca':
|
635
|
+
interval = _bca_interval(data, statistic, axis=-1, alpha=alpha,
|
636
|
+
theta_hat_b=theta_hat_b, batch=batch)[:2]
|
637
|
+
percentile_fun = _percentile_along_axis
|
638
|
+
else:
|
639
|
+
interval = alpha, 1-alpha
|
640
|
+
|
641
|
+
def percentile_fun(a, q):
|
642
|
+
return np.percentile(a=a, q=q, axis=-1)
|
643
|
+
|
644
|
+
# Calculate confidence interval of statistic
|
645
|
+
ci_l = percentile_fun(theta_hat_b, interval[0]*100)
|
646
|
+
ci_u = percentile_fun(theta_hat_b, interval[1]*100)
|
647
|
+
if method == 'basic': # see [3]
|
648
|
+
theta_hat = statistic(*data, axis=-1)
|
649
|
+
ci_l, ci_u = 2*theta_hat - ci_u, 2*theta_hat - ci_l
|
650
|
+
|
651
|
+
if alternative == 'less':
|
652
|
+
ci_l = np.full_like(ci_l, -np.inf)
|
653
|
+
elif alternative == 'greater':
|
654
|
+
ci_u = np.full_like(ci_u, np.inf)
|
655
|
+
|
656
|
+
return BootstrapResult(confidence_interval=ConfidenceInterval(ci_l, ci_u),
|
657
|
+
bootstrap_distribution=theta_hat_b,
|
658
|
+
standard_error=np.std(theta_hat_b, ddof=1, axis=-1))
|
659
|
+
|
660
|
+
|
661
|
+
def _monte_carlo_test_iv(data, rvs, statistic, vectorized, n_resamples,
|
662
|
+
batch, alternative, axis):
|
663
|
+
"""Input validation for `monte_carlo_test`."""
|
664
|
+
axis_int = int(axis)
|
665
|
+
if axis != axis_int:
|
666
|
+
raise ValueError("`axis` must be an integer.")
|
667
|
+
|
668
|
+
if vectorized not in {True, False, None}:
|
669
|
+
raise ValueError("`vectorized` must be `True`, `False`, or `None`.")
|
670
|
+
|
671
|
+
if not isinstance(rvs, Sequence):
|
672
|
+
rvs = (rvs,)
|
673
|
+
data = (data,)
|
674
|
+
for rvs_i in rvs:
|
675
|
+
if not callable(rvs_i):
|
676
|
+
raise TypeError("`rvs` must be callable or sequence of callables.")
|
677
|
+
|
678
|
+
# At this point, `data` should be a sequence
|
679
|
+
# If it isn't, the user passed a sequence for `rvs` but not `data`
|
680
|
+
message = "If `rvs` is a sequence, `len(rvs)` must equal `len(data)`."
|
681
|
+
try:
|
682
|
+
len(data)
|
683
|
+
except TypeError as e:
|
684
|
+
raise ValueError(message) from e
|
685
|
+
if not len(rvs) == len(data):
|
686
|
+
raise ValueError(message)
|
687
|
+
|
688
|
+
if not callable(statistic):
|
689
|
+
raise TypeError("`statistic` must be callable.")
|
690
|
+
|
691
|
+
if vectorized is None:
|
692
|
+
try:
|
693
|
+
signature = inspect.signature(statistic).parameters
|
694
|
+
except ValueError as e:
|
695
|
+
message = (f"Signature inspection of {statistic=} failed; "
|
696
|
+
"pass `vectorize` explicitly.")
|
697
|
+
raise ValueError(message) from e
|
698
|
+
vectorized = 'axis' in signature
|
699
|
+
|
700
|
+
xp = array_namespace(*data)
|
701
|
+
dtype = xp_result_type(*data, force_floating=True, xp=xp)
|
702
|
+
|
703
|
+
if not vectorized:
|
704
|
+
if is_numpy(xp):
|
705
|
+
statistic_vectorized = _vectorize_statistic(statistic)
|
706
|
+
else:
|
707
|
+
message = ("`statistic` must be vectorized (i.e. support an `axis` "
|
708
|
+
f"argument) when `data` contains {xp.__name__} arrays.")
|
709
|
+
raise ValueError(message)
|
710
|
+
else:
|
711
|
+
statistic_vectorized = statistic
|
712
|
+
|
713
|
+
data = _broadcast_arrays(data, axis, xp=xp)
|
714
|
+
data_iv = []
|
715
|
+
for sample in data:
|
716
|
+
sample = xp.broadcast_to(sample, (1,)) if sample.ndim == 0 else sample
|
717
|
+
sample = xp.moveaxis(sample, axis_int, -1)
|
718
|
+
data_iv.append(sample)
|
719
|
+
|
720
|
+
n_resamples_int = int(n_resamples)
|
721
|
+
if n_resamples != n_resamples_int or n_resamples_int <= 0:
|
722
|
+
raise ValueError("`n_resamples` must be a positive integer.")
|
723
|
+
|
724
|
+
if batch is None:
|
725
|
+
batch_iv = batch
|
726
|
+
else:
|
727
|
+
batch_iv = int(batch)
|
728
|
+
if batch != batch_iv or batch_iv <= 0:
|
729
|
+
raise ValueError("`batch` must be a positive integer or None.")
|
730
|
+
|
731
|
+
alternatives = {'two-sided', 'greater', 'less'}
|
732
|
+
alternative = alternative.lower()
|
733
|
+
if alternative not in alternatives:
|
734
|
+
raise ValueError(f"`alternative` must be in {alternatives}")
|
735
|
+
|
736
|
+
return (data_iv, rvs, statistic_vectorized, vectorized, n_resamples_int,
|
737
|
+
batch_iv, alternative, axis_int, dtype, xp)
|
738
|
+
|
739
|
+
|
740
|
+
@dataclass
|
741
|
+
class MonteCarloTestResult:
|
742
|
+
"""Result object returned by `scipy.stats.monte_carlo_test`.
|
743
|
+
|
744
|
+
Attributes
|
745
|
+
----------
|
746
|
+
statistic : float or ndarray
|
747
|
+
The observed test statistic of the sample.
|
748
|
+
pvalue : float or ndarray
|
749
|
+
The p-value for the given alternative.
|
750
|
+
null_distribution : ndarray
|
751
|
+
The values of the test statistic generated under the null
|
752
|
+
hypothesis.
|
753
|
+
"""
|
754
|
+
statistic: float | np.ndarray
|
755
|
+
pvalue: float | np.ndarray
|
756
|
+
null_distribution: np.ndarray
|
757
|
+
|
758
|
+
|
759
|
+
@_rename_parameter('sample', 'data')
|
760
|
+
def monte_carlo_test(data, rvs, statistic, *, vectorized=None,
|
761
|
+
n_resamples=9999, batch=None, alternative="two-sided",
|
762
|
+
axis=0):
|
763
|
+
r"""Perform a Monte Carlo hypothesis test.
|
764
|
+
|
765
|
+
`data` contains a sample or a sequence of one or more samples. `rvs`
|
766
|
+
specifies the distribution(s) of the sample(s) in `data` under the null
|
767
|
+
hypothesis. The value of `statistic` for the given `data` is compared
|
768
|
+
against a Monte Carlo null distribution: the value of the statistic for
|
769
|
+
each of `n_resamples` sets of samples generated using `rvs`. This gives
|
770
|
+
the p-value, the probability of observing such an extreme value of the
|
771
|
+
test statistic under the null hypothesis.
|
772
|
+
|
773
|
+
Parameters
|
774
|
+
----------
|
775
|
+
data : array-like or sequence of array-like
|
776
|
+
An array or sequence of arrays of observations.
|
777
|
+
rvs : callable or tuple of callables
|
778
|
+
A callable or sequence of callables that generates random variates
|
779
|
+
under the null hypothesis. Each element of `rvs` must be a callable
|
780
|
+
that accepts keyword argument ``size`` (e.g. ``rvs(size=(m, n))``) and
|
781
|
+
returns an N-d array sample of that shape. If `rvs` is a sequence, the
|
782
|
+
number of callables in `rvs` must match the number of samples in
|
783
|
+
`data`, i.e. ``len(rvs) == len(data)``. If `rvs` is a single callable,
|
784
|
+
`data` is treated as a single sample.
|
785
|
+
statistic : callable
|
786
|
+
Statistic for which the p-value of the hypothesis test is to be
|
787
|
+
calculated. `statistic` must be a callable that accepts a sample
|
788
|
+
(e.g. ``statistic(sample)``) or ``len(rvs)`` separate samples (e.g.
|
789
|
+
``statistic(samples1, sample2)`` if `rvs` contains two callables and
|
790
|
+
`data` contains two samples) and returns the resulting statistic.
|
791
|
+
If `vectorized` is set ``True``, `statistic` must also accept a keyword
|
792
|
+
argument `axis` and be vectorized to compute the statistic along the
|
793
|
+
provided `axis` of the samples in `data`.
|
794
|
+
vectorized : bool, optional
|
795
|
+
If `vectorized` is set ``False``, `statistic` will not be passed
|
796
|
+
keyword argument `axis` and is expected to calculate the statistic
|
797
|
+
only for 1D samples. If ``True``, `statistic` will be passed keyword
|
798
|
+
argument `axis` and is expected to calculate the statistic along `axis`
|
799
|
+
when passed ND sample arrays. If ``None`` (default), `vectorized`
|
800
|
+
will be set ``True`` if ``axis`` is a parameter of `statistic`. Use of
|
801
|
+
a vectorized statistic typically reduces computation time.
|
802
|
+
n_resamples : int, default: 9999
|
803
|
+
Number of samples drawn from each of the callables of `rvs`.
|
804
|
+
Equivalently, the number statistic values under the null hypothesis
|
805
|
+
used as the Monte Carlo null distribution.
|
806
|
+
batch : int, optional
|
807
|
+
The number of Monte Carlo samples to process in each call to
|
808
|
+
`statistic`. Memory usage is O( `batch` * ``sample.size[axis]`` ). Default
|
809
|
+
is ``None``, in which case `batch` equals `n_resamples`.
|
810
|
+
alternative : {'two-sided', 'less', 'greater'}
|
811
|
+
The alternative hypothesis for which the p-value is calculated.
|
812
|
+
For each alternative, the p-value is defined as follows.
|
813
|
+
|
814
|
+
- ``'greater'`` : the percentage of the null distribution that is
|
815
|
+
greater than or equal to the observed value of the test statistic.
|
816
|
+
- ``'less'`` : the percentage of the null distribution that is
|
817
|
+
less than or equal to the observed value of the test statistic.
|
818
|
+
- ``'two-sided'`` : twice the smaller of the p-values above.
|
819
|
+
|
820
|
+
axis : int, default: 0
|
821
|
+
The axis of `data` (or each sample within `data`) over which to
|
822
|
+
calculate the statistic.
|
823
|
+
|
824
|
+
Returns
|
825
|
+
-------
|
826
|
+
res : MonteCarloTestResult
|
827
|
+
An object with attributes:
|
828
|
+
|
829
|
+
statistic : float or ndarray
|
830
|
+
The test statistic of the observed `data`.
|
831
|
+
pvalue : float or ndarray
|
832
|
+
The p-value for the given alternative.
|
833
|
+
null_distribution : ndarray
|
834
|
+
The values of the test statistic generated under the null
|
835
|
+
hypothesis.
|
836
|
+
|
837
|
+
.. warning::
|
838
|
+
The p-value is calculated by counting the elements of the null
|
839
|
+
distribution that are as extreme or more extreme than the observed
|
840
|
+
value of the statistic. Due to the use of finite precision arithmetic,
|
841
|
+
some statistic functions return numerically distinct values when the
|
842
|
+
theoretical values would be exactly equal. In some cases, this could
|
843
|
+
lead to a large error in the calculated p-value. `monte_carlo_test`
|
844
|
+
guards against this by considering elements in the null distribution
|
845
|
+
that are "close" (within a relative tolerance of 100 times the
|
846
|
+
floating point epsilon of inexact dtypes) to the observed
|
847
|
+
value of the test statistic as equal to the observed value of the
|
848
|
+
test statistic. However, the user is advised to inspect the null
|
849
|
+
distribution to assess whether this method of comparison is
|
850
|
+
appropriate, and if not, calculate the p-value manually.
|
851
|
+
|
852
|
+
References
|
853
|
+
----------
|
854
|
+
|
855
|
+
.. [1] B. Phipson and G. K. Smyth. "Permutation P-values Should Never Be
|
856
|
+
Zero: Calculating Exact P-values When Permutations Are Randomly Drawn."
|
857
|
+
Statistical Applications in Genetics and Molecular Biology 9.1 (2010).
|
858
|
+
|
859
|
+
Examples
|
860
|
+
--------
|
861
|
+
|
862
|
+
Suppose we wish to test whether a small sample has been drawn from a normal
|
863
|
+
distribution. We decide that we will use the skew of the sample as a
|
864
|
+
test statistic, and we will consider a p-value of 0.05 to be statistically
|
865
|
+
significant.
|
866
|
+
|
867
|
+
>>> import numpy as np
|
868
|
+
>>> from scipy import stats
|
869
|
+
>>> def statistic(x, axis):
|
870
|
+
... return stats.skew(x, axis)
|
871
|
+
|
872
|
+
After collecting our data, we calculate the observed value of the test
|
873
|
+
statistic.
|
874
|
+
|
875
|
+
>>> rng = np.random.default_rng()
|
876
|
+
>>> x = stats.skewnorm.rvs(a=1, size=50, random_state=rng)
|
877
|
+
>>> statistic(x, axis=0)
|
878
|
+
0.12457412450240658
|
879
|
+
|
880
|
+
To determine the probability of observing such an extreme value of the
|
881
|
+
skewness by chance if the sample were drawn from the normal distribution,
|
882
|
+
we can perform a Monte Carlo hypothesis test. The test will draw many
|
883
|
+
samples at random from their normal distribution, calculate the skewness
|
884
|
+
of each sample, and compare our original skewness against this
|
885
|
+
distribution to determine an approximate p-value.
|
886
|
+
|
887
|
+
>>> from scipy.stats import monte_carlo_test
|
888
|
+
>>> # because our statistic is vectorized, we pass `vectorized=True`
|
889
|
+
>>> rvs = lambda size: stats.norm.rvs(size=size, random_state=rng)
|
890
|
+
>>> res = monte_carlo_test(x, rvs, statistic, vectorized=True)
|
891
|
+
>>> print(res.statistic)
|
892
|
+
0.12457412450240658
|
893
|
+
>>> print(res.pvalue)
|
894
|
+
0.7012
|
895
|
+
|
896
|
+
The probability of obtaining a test statistic less than or equal to the
|
897
|
+
observed value under the null hypothesis is ~70%. This is greater than
|
898
|
+
our chosen threshold of 5%, so we cannot consider this to be significant
|
899
|
+
evidence against the null hypothesis.
|
900
|
+
|
901
|
+
Note that this p-value essentially matches that of
|
902
|
+
`scipy.stats.skewtest`, which relies on an asymptotic distribution of a
|
903
|
+
test statistic based on the sample skewness.
|
904
|
+
|
905
|
+
>>> stats.skewtest(x).pvalue
|
906
|
+
0.6892046027110614
|
907
|
+
|
908
|
+
This asymptotic approximation is not valid for small sample sizes, but
|
909
|
+
`monte_carlo_test` can be used with samples of any size.
|
910
|
+
|
911
|
+
>>> x = stats.skewnorm.rvs(a=1, size=7, random_state=rng)
|
912
|
+
>>> # stats.skewtest(x) would produce an error due to small sample
|
913
|
+
>>> res = monte_carlo_test(x, rvs, statistic, vectorized=True)
|
914
|
+
|
915
|
+
The Monte Carlo distribution of the test statistic is provided for
|
916
|
+
further investigation.
|
917
|
+
|
918
|
+
>>> import matplotlib.pyplot as plt
|
919
|
+
>>> fig, ax = plt.subplots()
|
920
|
+
>>> ax.hist(res.null_distribution, bins=50)
|
921
|
+
>>> ax.set_title("Monte Carlo distribution of test statistic")
|
922
|
+
>>> ax.set_xlabel("Value of Statistic")
|
923
|
+
>>> ax.set_ylabel("Frequency")
|
924
|
+
>>> plt.show()
|
925
|
+
|
926
|
+
"""
|
927
|
+
args = _monte_carlo_test_iv(data, rvs, statistic, vectorized,
|
928
|
+
n_resamples, batch, alternative, axis)
|
929
|
+
(data, rvs, statistic, vectorized, n_resamples,
|
930
|
+
batch, alternative, axis, dtype, xp) = args
|
931
|
+
|
932
|
+
# Some statistics return plain floats; ensure they're at least a NumPy float
|
933
|
+
observed = xp.asarray(statistic(*data, axis=-1))
|
934
|
+
observed = observed[()] if observed.ndim == 0 else observed
|
935
|
+
|
936
|
+
n_observations = [sample.shape[-1] for sample in data]
|
937
|
+
batch_nominal = batch or n_resamples
|
938
|
+
null_distribution = []
|
939
|
+
for k in range(0, n_resamples, batch_nominal):
|
940
|
+
batch_actual = min(batch_nominal, n_resamples - k)
|
941
|
+
resamples = [rvs_i(size=(batch_actual, n_observations_i))
|
942
|
+
for rvs_i, n_observations_i in zip(rvs, n_observations)]
|
943
|
+
null_distribution.append(statistic(*resamples, axis=-1))
|
944
|
+
null_distribution = xp.concat(null_distribution)
|
945
|
+
null_distribution = xp.reshape(null_distribution, (-1,) + (1,)*observed.ndim)
|
946
|
+
|
947
|
+
# relative tolerance for detecting numerically distinct but
|
948
|
+
# theoretically equal values in the null distribution
|
949
|
+
eps = (0 if not xp.isdtype(observed.dtype, ('real floating'))
|
950
|
+
else xp.finfo(observed.dtype).eps*100)
|
951
|
+
gamma = xp.abs(eps * observed)
|
952
|
+
|
953
|
+
def less(null_distribution, observed):
|
954
|
+
cmps = null_distribution <= observed + gamma
|
955
|
+
cmps = xp.asarray(cmps, dtype=dtype)
|
956
|
+
pvalues = (xp.sum(cmps, axis=0, dtype=dtype) + 1.) / (n_resamples + 1.)
|
957
|
+
return pvalues
|
958
|
+
|
959
|
+
def greater(null_distribution, observed):
|
960
|
+
cmps = null_distribution >= observed - gamma
|
961
|
+
cmps = xp.asarray(cmps, dtype=dtype)
|
962
|
+
pvalues = (xp.sum(cmps, axis=0, dtype=dtype) + 1.) / (n_resamples + 1.)
|
963
|
+
return pvalues
|
964
|
+
|
965
|
+
def two_sided(null_distribution, observed):
|
966
|
+
pvalues_less = less(null_distribution, observed)
|
967
|
+
pvalues_greater = greater(null_distribution, observed)
|
968
|
+
pvalues = xp.minimum(pvalues_less, pvalues_greater) * 2
|
969
|
+
return pvalues
|
970
|
+
|
971
|
+
compare = {"less": less,
|
972
|
+
"greater": greater,
|
973
|
+
"two-sided": two_sided}
|
974
|
+
|
975
|
+
pvalues = compare[alternative](null_distribution, observed)
|
976
|
+
pvalues = xp.clip(pvalues, 0., 1.)
|
977
|
+
|
978
|
+
return MonteCarloTestResult(observed, pvalues, null_distribution)
|
979
|
+
|
980
|
+
|
981
|
+
@dataclass
|
982
|
+
class PowerResult:
|
983
|
+
"""Result object returned by `scipy.stats.power`.
|
984
|
+
|
985
|
+
Attributes
|
986
|
+
----------
|
987
|
+
power : float or ndarray
|
988
|
+
The estimated power.
|
989
|
+
pvalues : float or ndarray
|
990
|
+
The simulated p-values.
|
991
|
+
"""
|
992
|
+
power: float | np.ndarray
|
993
|
+
pvalues: float | np.ndarray
|
994
|
+
|
995
|
+
|
996
|
+
def _wrap_kwargs(fun):
|
997
|
+
"""Wrap callable to accept arbitrary kwargs and ignore unused ones"""
|
998
|
+
|
999
|
+
try:
|
1000
|
+
keys = set(inspect.signature(fun).parameters.keys())
|
1001
|
+
except ValueError:
|
1002
|
+
# NumPy Generator methods can't be inspected
|
1003
|
+
keys = {'size'}
|
1004
|
+
|
1005
|
+
# Set keys=keys/fun=fun to avoid late binding gotcha
|
1006
|
+
def wrapped_rvs_i(*args, keys=keys, fun=fun, **all_kwargs):
|
1007
|
+
kwargs = {key: val for key, val in all_kwargs.items()
|
1008
|
+
if key in keys}
|
1009
|
+
return fun(*args, **kwargs)
|
1010
|
+
return wrapped_rvs_i
|
1011
|
+
|
1012
|
+
|
1013
|
+
def _power_iv(rvs, test, n_observations, significance, vectorized,
|
1014
|
+
n_resamples, batch, kwargs):
|
1015
|
+
"""Input validation for `monte_carlo_test`."""
|
1016
|
+
|
1017
|
+
if vectorized not in {True, False, None}:
|
1018
|
+
raise ValueError("`vectorized` must be `True`, `False`, or `None`.")
|
1019
|
+
|
1020
|
+
if not isinstance(rvs, Sequence):
|
1021
|
+
rvs = (rvs,)
|
1022
|
+
n_observations = (n_observations,)
|
1023
|
+
for rvs_i in rvs:
|
1024
|
+
if not callable(rvs_i):
|
1025
|
+
raise TypeError("`rvs` must be callable or sequence of callables.")
|
1026
|
+
|
1027
|
+
if not len(rvs) == len(n_observations):
|
1028
|
+
message = ("If `rvs` is a sequence, `len(rvs)` "
|
1029
|
+
"must equal `len(n_observations)`.")
|
1030
|
+
raise ValueError(message)
|
1031
|
+
|
1032
|
+
significance = np.asarray(significance)[()]
|
1033
|
+
if (not np.issubdtype(significance.dtype, np.floating)
|
1034
|
+
or np.min(significance) < 0 or np.max(significance) > 1):
|
1035
|
+
raise ValueError("`significance` must contain floats between 0 and 1.")
|
1036
|
+
|
1037
|
+
kwargs = dict() if kwargs is None else kwargs
|
1038
|
+
if not isinstance(kwargs, dict):
|
1039
|
+
raise TypeError("`kwargs` must be a dictionary that maps keywords to arrays.")
|
1040
|
+
|
1041
|
+
vals = kwargs.values()
|
1042
|
+
keys = kwargs.keys()
|
1043
|
+
|
1044
|
+
# Wrap callables to ignore unused keyword arguments
|
1045
|
+
wrapped_rvs = [_wrap_kwargs(rvs_i) for rvs_i in rvs]
|
1046
|
+
|
1047
|
+
# Broadcast, then ravel nobs/kwarg combinations. In the end,
|
1048
|
+
# `nobs` and `vals` have shape (# of combinations, number of variables)
|
1049
|
+
tmp = np.asarray(np.broadcast_arrays(*n_observations, *vals))
|
1050
|
+
shape = tmp.shape
|
1051
|
+
if tmp.ndim == 1:
|
1052
|
+
tmp = tmp[np.newaxis, :]
|
1053
|
+
else:
|
1054
|
+
tmp = tmp.reshape((shape[0], -1)).T
|
1055
|
+
nobs, vals = tmp[:, :len(rvs)], tmp[:, len(rvs):]
|
1056
|
+
nobs = nobs.astype(int)
|
1057
|
+
|
1058
|
+
if not callable(test):
|
1059
|
+
raise TypeError("`test` must be callable.")
|
1060
|
+
|
1061
|
+
if vectorized is None:
|
1062
|
+
vectorized = 'axis' in inspect.signature(test).parameters
|
1063
|
+
|
1064
|
+
if not vectorized:
|
1065
|
+
test_vectorized = _vectorize_statistic(test)
|
1066
|
+
else:
|
1067
|
+
test_vectorized = test
|
1068
|
+
# Wrap `test` function to ignore unused kwargs
|
1069
|
+
test_vectorized = _wrap_kwargs(test_vectorized)
|
1070
|
+
|
1071
|
+
n_resamples_int = int(n_resamples)
|
1072
|
+
if n_resamples != n_resamples_int or n_resamples_int <= 0:
|
1073
|
+
raise ValueError("`n_resamples` must be a positive integer.")
|
1074
|
+
|
1075
|
+
if batch is None:
|
1076
|
+
batch_iv = batch
|
1077
|
+
else:
|
1078
|
+
batch_iv = int(batch)
|
1079
|
+
if batch != batch_iv or batch_iv <= 0:
|
1080
|
+
raise ValueError("`batch` must be a positive integer or None.")
|
1081
|
+
|
1082
|
+
return (wrapped_rvs, test_vectorized, nobs, significance, vectorized,
|
1083
|
+
n_resamples_int, batch_iv, vals, keys, shape[1:])
|
1084
|
+
|
1085
|
+
|
1086
|
+
def power(test, rvs, n_observations, *, significance=0.01, vectorized=None,
|
1087
|
+
n_resamples=10000, batch=None, kwargs=None):
|
1088
|
+
r"""Simulate the power of a hypothesis test under an alternative hypothesis.
|
1089
|
+
|
1090
|
+
Parameters
|
1091
|
+
----------
|
1092
|
+
test : callable
|
1093
|
+
Hypothesis test for which the power is to be simulated.
|
1094
|
+
`test` must be a callable that accepts a sample (e.g. ``test(sample)``)
|
1095
|
+
or ``len(rvs)`` separate samples (e.g. ``test(samples1, sample2)`` if
|
1096
|
+
`rvs` contains two callables and `n_observations` contains two values)
|
1097
|
+
and returns the p-value of the test.
|
1098
|
+
If `vectorized` is set to ``True``, `test` must also accept a keyword
|
1099
|
+
argument `axis` and be vectorized to perform the test along the
|
1100
|
+
provided `axis` of the samples.
|
1101
|
+
Any callable from `scipy.stats` with an `axis` argument that returns an
|
1102
|
+
object with a `pvalue` attribute is also acceptable.
|
1103
|
+
rvs : callable or tuple of callables
|
1104
|
+
A callable or sequence of callables that generate(s) random variates
|
1105
|
+
under the alternative hypothesis. Each element of `rvs` must accept
|
1106
|
+
keyword argument ``size`` (e.g. ``rvs(size=(m, n))``) and return an
|
1107
|
+
N-d array of that shape. If `rvs` is a sequence, the number of callables
|
1108
|
+
in `rvs` must match the number of elements of `n_observations`, i.e.
|
1109
|
+
``len(rvs) == len(n_observations)``. If `rvs` is a single callable,
|
1110
|
+
`n_observations` is treated as a single element.
|
1111
|
+
n_observations : tuple of ints or tuple of integer arrays
|
1112
|
+
If a sequence of ints, each is the sizes of a sample to be passed to `test`.
|
1113
|
+
If a sequence of integer arrays, the power is simulated for each
|
1114
|
+
set of corresponding sample sizes. See Examples.
|
1115
|
+
significance : float or array_like of floats, default: 0.01
|
1116
|
+
The threshold for significance; i.e., the p-value below which the
|
1117
|
+
hypothesis test results will be considered as evidence against the null
|
1118
|
+
hypothesis. Equivalently, the acceptable rate of Type I error under
|
1119
|
+
the null hypothesis. If an array, the power is simulated for each
|
1120
|
+
significance threshold.
|
1121
|
+
kwargs : dict, optional
|
1122
|
+
Keyword arguments to be passed to `rvs` and/or `test` callables.
|
1123
|
+
Introspection is used to determine which keyword arguments may be
|
1124
|
+
passed to each callable.
|
1125
|
+
The value corresponding with each keyword must be an array.
|
1126
|
+
Arrays must be broadcastable with one another and with each array in
|
1127
|
+
`n_observations`. The power is simulated for each set of corresponding
|
1128
|
+
sample sizes and arguments. See Examples.
|
1129
|
+
vectorized : bool, optional
|
1130
|
+
If `vectorized` is set to ``False``, `test` will not be passed keyword
|
1131
|
+
argument `axis` and is expected to perform the test only for 1D samples.
|
1132
|
+
If ``True``, `test` will be passed keyword argument `axis` and is
|
1133
|
+
expected to perform the test along `axis` when passed N-D sample arrays.
|
1134
|
+
If ``None`` (default), `vectorized` will be set ``True`` if ``axis`` is
|
1135
|
+
a parameter of `test`. Use of a vectorized test typically reduces
|
1136
|
+
computation time.
|
1137
|
+
n_resamples : int, default: 10000
|
1138
|
+
Number of samples drawn from each of the callables of `rvs`.
|
1139
|
+
Equivalently, the number tests performed under the alternative
|
1140
|
+
hypothesis to approximate the power.
|
1141
|
+
batch : int, optional
|
1142
|
+
The number of samples to process in each call to `test`. Memory usage is
|
1143
|
+
proportional to the product of `batch` and the largest sample size. Default
|
1144
|
+
is ``None``, in which case `batch` equals `n_resamples`.
|
1145
|
+
|
1146
|
+
Returns
|
1147
|
+
-------
|
1148
|
+
res : PowerResult
|
1149
|
+
An object with attributes:
|
1150
|
+
|
1151
|
+
power : float or ndarray
|
1152
|
+
The estimated power against the alternative.
|
1153
|
+
pvalues : ndarray
|
1154
|
+
The p-values observed under the alternative hypothesis.
|
1155
|
+
|
1156
|
+
Notes
|
1157
|
+
-----
|
1158
|
+
The power is simulated as follows:
|
1159
|
+
|
1160
|
+
- Draw many random samples (or sets of samples), each of the size(s)
|
1161
|
+
specified by `n_observations`, under the alternative specified by
|
1162
|
+
`rvs`.
|
1163
|
+
- For each sample (or set of samples), compute the p-value according to
|
1164
|
+
`test`. These p-values are recorded in the ``pvalues`` attribute of
|
1165
|
+
the result object.
|
1166
|
+
- Compute the proportion of p-values that are less than the `significance`
|
1167
|
+
level. This is the power recorded in the ``power`` attribute of the
|
1168
|
+
result object.
|
1169
|
+
|
1170
|
+
Suppose that `significance` is an array with shape ``shape1``, the elements
|
1171
|
+
of `kwargs` and `n_observations` are mutually broadcastable to shape ``shape2``,
|
1172
|
+
and `test` returns an array of p-values of shape ``shape3``. Then the result
|
1173
|
+
object ``power`` attribute will be of shape ``shape1 + shape2 + shape3``, and
|
1174
|
+
the ``pvalues`` attribute will be of shape ``shape2 + shape3 + (n_resamples,)``.
|
1175
|
+
|
1176
|
+
Examples
|
1177
|
+
--------
|
1178
|
+
Suppose we wish to simulate the power of the independent sample t-test
|
1179
|
+
under the following conditions:
|
1180
|
+
|
1181
|
+
- The first sample has 10 observations drawn from a normal distribution
|
1182
|
+
with mean 0.
|
1183
|
+
- The second sample has 12 observations drawn from a normal distribution
|
1184
|
+
with mean 1.0.
|
1185
|
+
- The threshold on p-values for significance is 0.05.
|
1186
|
+
|
1187
|
+
>>> import numpy as np
|
1188
|
+
>>> from scipy import stats
|
1189
|
+
>>> rng = np.random.default_rng(2549598345528)
|
1190
|
+
>>>
|
1191
|
+
>>> test = stats.ttest_ind
|
1192
|
+
>>> n_observations = (10, 12)
|
1193
|
+
>>> rvs1 = rng.normal
|
1194
|
+
>>> rvs2 = lambda size: rng.normal(loc=1, size=size)
|
1195
|
+
>>> rvs = (rvs1, rvs2)
|
1196
|
+
>>> res = stats.power(test, rvs, n_observations, significance=0.05)
|
1197
|
+
>>> res.power
|
1198
|
+
0.6116
|
1199
|
+
|
1200
|
+
With samples of size 10 and 12, respectively, the power of the t-test
|
1201
|
+
with a significance threshold of 0.05 is approximately 60% under the chosen
|
1202
|
+
alternative. We can investigate the effect of sample size on the power
|
1203
|
+
by passing sample size arrays.
|
1204
|
+
|
1205
|
+
>>> import matplotlib.pyplot as plt
|
1206
|
+
>>> nobs_x = np.arange(5, 21)
|
1207
|
+
>>> nobs_y = nobs_x
|
1208
|
+
>>> n_observations = (nobs_x, nobs_y)
|
1209
|
+
>>> res = stats.power(test, rvs, n_observations, significance=0.05)
|
1210
|
+
>>> ax = plt.subplot()
|
1211
|
+
>>> ax.plot(nobs_x, res.power)
|
1212
|
+
>>> ax.set_xlabel('Sample Size')
|
1213
|
+
>>> ax.set_ylabel('Simulated Power')
|
1214
|
+
>>> ax.set_title('Simulated Power of `ttest_ind` with Equal Sample Sizes')
|
1215
|
+
>>> plt.show()
|
1216
|
+
|
1217
|
+
Alternatively, we can investigate the impact that effect size has on the power.
|
1218
|
+
In this case, the effect size is the location of the distribution underlying
|
1219
|
+
the second sample.
|
1220
|
+
|
1221
|
+
>>> n_observations = (10, 12)
|
1222
|
+
>>> loc = np.linspace(0, 1, 20)
|
1223
|
+
>>> rvs2 = lambda size, loc: rng.normal(loc=loc, size=size)
|
1224
|
+
>>> rvs = (rvs1, rvs2)
|
1225
|
+
>>> res = stats.power(test, rvs, n_observations, significance=0.05,
|
1226
|
+
... kwargs={'loc': loc})
|
1227
|
+
>>> ax = plt.subplot()
|
1228
|
+
>>> ax.plot(loc, res.power)
|
1229
|
+
>>> ax.set_xlabel('Effect Size')
|
1230
|
+
>>> ax.set_ylabel('Simulated Power')
|
1231
|
+
>>> ax.set_title('Simulated Power of `ttest_ind`, Varying Effect Size')
|
1232
|
+
>>> plt.show()
|
1233
|
+
|
1234
|
+
We can also use `power` to estimate the Type I error rate (also referred to by the
|
1235
|
+
ambiguous term "size") of a test and assess whether it matches the nominal level.
|
1236
|
+
For example, the null hypothesis of `jarque_bera` is that the sample was drawn from
|
1237
|
+
a distribution with the same skewness and kurtosis as the normal distribution. To
|
1238
|
+
estimate the Type I error rate, we can consider the null hypothesis to be a true
|
1239
|
+
*alternative* hypothesis and calculate the power.
|
1240
|
+
|
1241
|
+
>>> test = stats.jarque_bera
|
1242
|
+
>>> n_observations = 10
|
1243
|
+
>>> rvs = rng.normal
|
1244
|
+
>>> significance = np.linspace(0.0001, 0.1, 1000)
|
1245
|
+
>>> res = stats.power(test, rvs, n_observations, significance=significance)
|
1246
|
+
>>> size = res.power
|
1247
|
+
|
1248
|
+
As shown below, the Type I error rate of the test is far below the nominal level
|
1249
|
+
for such a small sample, as mentioned in its documentation.
|
1250
|
+
|
1251
|
+
>>> ax = plt.subplot()
|
1252
|
+
>>> ax.plot(significance, size)
|
1253
|
+
>>> ax.plot([0, 0.1], [0, 0.1], '--')
|
1254
|
+
>>> ax.set_xlabel('nominal significance level')
|
1255
|
+
>>> ax.set_ylabel('estimated test size (Type I error rate)')
|
1256
|
+
>>> ax.set_title('Estimated test size vs nominal significance level')
|
1257
|
+
>>> ax.set_aspect('equal', 'box')
|
1258
|
+
>>> ax.legend(('`ttest_1samp`', 'ideal test'))
|
1259
|
+
>>> plt.show()
|
1260
|
+
|
1261
|
+
As one might expect from such a conservative test, the power is quite low with
|
1262
|
+
respect to some alternatives. For example, the power of the test under the
|
1263
|
+
alternative that the sample was drawn from the Laplace distribution may not
|
1264
|
+
be much greater than the Type I error rate.
|
1265
|
+
|
1266
|
+
>>> rvs = rng.laplace
|
1267
|
+
>>> significance = np.linspace(0.0001, 0.1, 1000)
|
1268
|
+
>>> res = stats.power(test, rvs, n_observations, significance=0.05)
|
1269
|
+
>>> print(res.power)
|
1270
|
+
0.0587
|
1271
|
+
|
1272
|
+
This is not a mistake in SciPy's implementation; it is simply due to the fact
|
1273
|
+
that the null distribution of the test statistic is derived under the assumption
|
1274
|
+
that the sample size is large (i.e. approaches infinity), and this asymptotic
|
1275
|
+
approximation is not accurate for small samples. In such cases, resampling
|
1276
|
+
and Monte Carlo methods (e.g. `permutation_test`, `goodness_of_fit`,
|
1277
|
+
`monte_carlo_test`) may be more appropriate.
|
1278
|
+
|
1279
|
+
"""
|
1280
|
+
tmp = _power_iv(rvs, test, n_observations, significance,
|
1281
|
+
vectorized, n_resamples, batch, kwargs)
|
1282
|
+
(rvs, test, nobs, significance,
|
1283
|
+
vectorized, n_resamples, batch, args, kwds, shape)= tmp
|
1284
|
+
|
1285
|
+
batch_nominal = batch or n_resamples
|
1286
|
+
pvalues = [] # results of various nobs/kwargs combinations
|
1287
|
+
for nobs_i, args_i in zip(nobs, args):
|
1288
|
+
kwargs_i = dict(zip(kwds, args_i))
|
1289
|
+
pvalues_i = [] # results of batches; fixed nobs/kwargs combination
|
1290
|
+
for k in range(0, n_resamples, batch_nominal):
|
1291
|
+
batch_actual = min(batch_nominal, n_resamples - k)
|
1292
|
+
resamples = [rvs_j(size=(batch_actual, nobs_ij), **kwargs_i)
|
1293
|
+
for rvs_j, nobs_ij in zip(rvs, nobs_i)]
|
1294
|
+
res = test(*resamples, **kwargs_i, axis=-1)
|
1295
|
+
p = getattr(res, 'pvalue', res)
|
1296
|
+
pvalues_i.append(p)
|
1297
|
+
# Concatenate results from batches
|
1298
|
+
pvalues_i = np.concatenate(pvalues_i, axis=-1)
|
1299
|
+
pvalues.append(pvalues_i)
|
1300
|
+
# `test` can return result with array of p-values
|
1301
|
+
shape += pvalues_i.shape[:-1]
|
1302
|
+
# Concatenate results from various nobs/kwargs combinations
|
1303
|
+
pvalues = np.concatenate(pvalues, axis=0)
|
1304
|
+
# nobs/kwargs arrays were raveled to single axis; unravel
|
1305
|
+
pvalues = pvalues.reshape(shape + (-1,))
|
1306
|
+
if significance.ndim > 0:
|
1307
|
+
newdims = tuple(range(significance.ndim, pvalues.ndim + significance.ndim))
|
1308
|
+
significance = np.expand_dims(significance, newdims)
|
1309
|
+
powers = np.mean(pvalues < significance, axis=-1)
|
1310
|
+
|
1311
|
+
return PowerResult(power=powers, pvalues=pvalues)
|
1312
|
+
|
1313
|
+
|
1314
|
+
@dataclass
|
1315
|
+
class PermutationTestResult:
|
1316
|
+
"""Result object returned by `scipy.stats.permutation_test`.
|
1317
|
+
|
1318
|
+
Attributes
|
1319
|
+
----------
|
1320
|
+
statistic : float or ndarray
|
1321
|
+
The observed test statistic of the data.
|
1322
|
+
pvalue : float or ndarray
|
1323
|
+
The p-value for the given alternative.
|
1324
|
+
null_distribution : ndarray
|
1325
|
+
The values of the test statistic generated under the null
|
1326
|
+
hypothesis.
|
1327
|
+
"""
|
1328
|
+
statistic: float | np.ndarray
|
1329
|
+
pvalue: float | np.ndarray
|
1330
|
+
null_distribution: np.ndarray
|
1331
|
+
|
1332
|
+
|
1333
|
+
def _all_partitions_concatenated(ns):
|
1334
|
+
"""
|
1335
|
+
Generate all partitions of indices of groups of given sizes, concatenated
|
1336
|
+
|
1337
|
+
`ns` is an iterable of ints.
|
1338
|
+
"""
|
1339
|
+
def all_partitions(z, n):
|
1340
|
+
for c in combinations(z, n):
|
1341
|
+
x0 = set(c)
|
1342
|
+
x1 = z - x0
|
1343
|
+
yield [x0, x1]
|
1344
|
+
|
1345
|
+
def all_partitions_n(z, ns):
|
1346
|
+
if len(ns) == 0:
|
1347
|
+
yield [z]
|
1348
|
+
return
|
1349
|
+
for c in all_partitions(z, ns[0]):
|
1350
|
+
for d in all_partitions_n(c[1], ns[1:]):
|
1351
|
+
yield c[0:1] + d
|
1352
|
+
|
1353
|
+
z = set(range(np.sum(ns)))
|
1354
|
+
for partitioning in all_partitions_n(z, ns[:]):
|
1355
|
+
x = np.concatenate([list(partition)
|
1356
|
+
for partition in partitioning]).astype(int)
|
1357
|
+
yield x
|
1358
|
+
|
1359
|
+
|
1360
|
+
def _batch_generator(iterable, batch):
|
1361
|
+
"""A generator that yields batches of elements from an iterable"""
|
1362
|
+
iterator = iter(iterable)
|
1363
|
+
if batch <= 0:
|
1364
|
+
raise ValueError("`batch` must be positive.")
|
1365
|
+
z = [item for i, item in zip(range(batch), iterator)]
|
1366
|
+
while z: # we don't want StopIteration without yielding an empty list
|
1367
|
+
yield z
|
1368
|
+
z = [item for i, item in zip(range(batch), iterator)]
|
1369
|
+
|
1370
|
+
|
1371
|
+
def _pairings_permutations_gen(n_permutations, n_samples, n_obs_sample, batch,
|
1372
|
+
rng):
|
1373
|
+
# Returns a generator that yields arrays of size
|
1374
|
+
# `(batch, n_samples, n_obs_sample)`.
|
1375
|
+
# Each row is an independent permutation of indices 0 to `n_obs_sample`.
|
1376
|
+
batch = min(batch, n_permutations)
|
1377
|
+
|
1378
|
+
if hasattr(rng, 'permuted'):
|
1379
|
+
def batched_perm_generator():
|
1380
|
+
indices = np.arange(n_obs_sample)
|
1381
|
+
indices = np.tile(indices, (batch, n_samples, 1))
|
1382
|
+
for k in range(0, n_permutations, batch):
|
1383
|
+
batch_actual = min(batch, n_permutations-k)
|
1384
|
+
# Don't permute in place, otherwise results depend on `batch`
|
1385
|
+
permuted_indices = rng.permuted(indices, axis=-1)
|
1386
|
+
yield permuted_indices[:batch_actual]
|
1387
|
+
else: # RandomState and early Generators don't have `permuted`
|
1388
|
+
def batched_perm_generator():
|
1389
|
+
for k in range(0, n_permutations, batch):
|
1390
|
+
batch_actual = min(batch, n_permutations-k)
|
1391
|
+
size = (batch_actual, n_samples, n_obs_sample)
|
1392
|
+
x = rng.random(size=size)
|
1393
|
+
yield np.argsort(x, axis=-1)[:batch_actual]
|
1394
|
+
|
1395
|
+
return batched_perm_generator()
|
1396
|
+
|
1397
|
+
|
1398
|
+
def _calculate_null_both(data, statistic, n_permutations, batch,
|
1399
|
+
rng=None):
|
1400
|
+
"""
|
1401
|
+
Calculate null distribution for independent sample tests.
|
1402
|
+
"""
|
1403
|
+
n_samples = len(data)
|
1404
|
+
|
1405
|
+
# compute number of permutations
|
1406
|
+
# (distinct partitions of data into samples of these sizes)
|
1407
|
+
n_obs_i = [sample.shape[-1] for sample in data] # observations per sample
|
1408
|
+
n_obs_ic = np.cumsum(n_obs_i)
|
1409
|
+
n_obs = n_obs_ic[-1] # total number of observations
|
1410
|
+
n_max = np.prod([comb(n_obs_ic[i], n_obs_ic[i-1])
|
1411
|
+
for i in range(n_samples-1, 0, -1)])
|
1412
|
+
|
1413
|
+
# perm_generator is an iterator that produces permutations of indices
|
1414
|
+
# from 0 to n_obs. We'll concatenate the samples, use these indices to
|
1415
|
+
# permute the data, then split the samples apart again.
|
1416
|
+
if n_permutations >= n_max:
|
1417
|
+
exact_test = True
|
1418
|
+
n_permutations = n_max
|
1419
|
+
perm_generator = _all_partitions_concatenated(n_obs_i)
|
1420
|
+
else:
|
1421
|
+
exact_test = False
|
1422
|
+
# Neither RandomState.permutation nor Generator.permutation
|
1423
|
+
# can permute axis-slices independently. If this feature is
|
1424
|
+
# added in the future, batches of the desired size should be
|
1425
|
+
# generated in a single call.
|
1426
|
+
perm_generator = (rng.permutation(n_obs)
|
1427
|
+
for i in range(n_permutations))
|
1428
|
+
|
1429
|
+
batch = batch or int(n_permutations)
|
1430
|
+
null_distribution = []
|
1431
|
+
|
1432
|
+
# First, concatenate all the samples. In batches, permute samples with
|
1433
|
+
# indices produced by the `perm_generator`, split them into new samples of
|
1434
|
+
# the original sizes, compute the statistic for each batch, and add these
|
1435
|
+
# statistic values to the null distribution.
|
1436
|
+
data = np.concatenate(data, axis=-1)
|
1437
|
+
for indices in _batch_generator(perm_generator, batch=batch):
|
1438
|
+
indices = np.array(indices)
|
1439
|
+
|
1440
|
+
# `indices` is 2D: each row is a permutation of the indices.
|
1441
|
+
# We use it to index `data` along its last axis, which corresponds
|
1442
|
+
# with observations.
|
1443
|
+
# After indexing, the second to last axis of `data_batch` corresponds
|
1444
|
+
# with permutations, and the last axis corresponds with observations.
|
1445
|
+
data_batch = data[..., indices]
|
1446
|
+
|
1447
|
+
# Move the permutation axis to the front: we'll concatenate a list
|
1448
|
+
# of batched statistic values along this zeroth axis to form the
|
1449
|
+
# null distribution.
|
1450
|
+
data_batch = np.moveaxis(data_batch, -2, 0)
|
1451
|
+
data_batch = np.split(data_batch, n_obs_ic[:-1], axis=-1)
|
1452
|
+
null_distribution.append(statistic(*data_batch, axis=-1))
|
1453
|
+
null_distribution = np.concatenate(null_distribution, axis=0)
|
1454
|
+
|
1455
|
+
return null_distribution, n_permutations, exact_test
|
1456
|
+
|
1457
|
+
|
1458
|
+
def _calculate_null_pairings(data, statistic, n_permutations, batch,
|
1459
|
+
rng=None):
|
1460
|
+
"""
|
1461
|
+
Calculate null distribution for association tests.
|
1462
|
+
"""
|
1463
|
+
n_samples = len(data)
|
1464
|
+
|
1465
|
+
# compute number of permutations (factorial(n) permutations of each sample)
|
1466
|
+
n_obs_sample = data[0].shape[-1] # observations per sample; same for each
|
1467
|
+
n_max = factorial(n_obs_sample)**n_samples
|
1468
|
+
|
1469
|
+
# `perm_generator` is an iterator that produces a list of permutations of
|
1470
|
+
# indices from 0 to n_obs_sample, one for each sample.
|
1471
|
+
if n_permutations >= n_max:
|
1472
|
+
exact_test = True
|
1473
|
+
n_permutations = n_max
|
1474
|
+
batch = batch or int(n_permutations)
|
1475
|
+
# Cartesian product of the sets of all permutations of indices
|
1476
|
+
perm_generator = product(*(permutations(range(n_obs_sample))
|
1477
|
+
for i in range(n_samples)))
|
1478
|
+
batched_perm_generator = _batch_generator(perm_generator, batch=batch)
|
1479
|
+
else:
|
1480
|
+
exact_test = False
|
1481
|
+
batch = batch or int(n_permutations)
|
1482
|
+
# Separate random permutations of indices for each sample.
|
1483
|
+
# Again, it would be nice if RandomState/Generator.permutation
|
1484
|
+
# could permute each axis-slice separately.
|
1485
|
+
args = n_permutations, n_samples, n_obs_sample, batch, rng
|
1486
|
+
batched_perm_generator = _pairings_permutations_gen(*args)
|
1487
|
+
|
1488
|
+
null_distribution = []
|
1489
|
+
|
1490
|
+
for indices in batched_perm_generator:
|
1491
|
+
indices = np.array(indices)
|
1492
|
+
|
1493
|
+
# `indices` is 3D: the zeroth axis is for permutations, the next is
|
1494
|
+
# for samples, and the last is for observations. Swap the first two
|
1495
|
+
# to make the zeroth axis correspond with samples, as it does for
|
1496
|
+
# `data`.
|
1497
|
+
indices = np.swapaxes(indices, 0, 1)
|
1498
|
+
|
1499
|
+
# When we're done, `data_batch` will be a list of length `n_samples`.
|
1500
|
+
# Each element will be a batch of random permutations of one sample.
|
1501
|
+
# The zeroth axis of each batch will correspond with permutations,
|
1502
|
+
# and the last will correspond with observations. (This makes it
|
1503
|
+
# easy to pass into `statistic`.)
|
1504
|
+
data_batch = [None]*n_samples
|
1505
|
+
for i in range(n_samples):
|
1506
|
+
data_batch[i] = data[i][..., indices[i]]
|
1507
|
+
data_batch[i] = np.moveaxis(data_batch[i], -2, 0)
|
1508
|
+
|
1509
|
+
null_distribution.append(statistic(*data_batch, axis=-1))
|
1510
|
+
null_distribution = np.concatenate(null_distribution, axis=0)
|
1511
|
+
|
1512
|
+
return null_distribution, n_permutations, exact_test
|
1513
|
+
|
1514
|
+
|
1515
|
+
def _calculate_null_samples(data, statistic, n_permutations, batch,
|
1516
|
+
rng=None):
|
1517
|
+
"""
|
1518
|
+
Calculate null distribution for paired-sample tests.
|
1519
|
+
"""
|
1520
|
+
n_samples = len(data)
|
1521
|
+
|
1522
|
+
# By convention, the meaning of the "samples" permutations type for
|
1523
|
+
# data with only one sample is to flip the sign of the observations.
|
1524
|
+
# Achieve this by adding a second sample - the negative of the original.
|
1525
|
+
if n_samples == 1:
|
1526
|
+
data = [data[0], -data[0]]
|
1527
|
+
|
1528
|
+
# The "samples" permutation strategy is the same as the "pairings"
|
1529
|
+
# strategy except the roles of samples and observations are flipped.
|
1530
|
+
# So swap these axes, then we'll use the function for the "pairings"
|
1531
|
+
# strategy to do all the work!
|
1532
|
+
data = np.swapaxes(data, 0, -1)
|
1533
|
+
|
1534
|
+
# (Of course, the user's statistic doesn't know what we've done here,
|
1535
|
+
# so we need to pass it what it's expecting.)
|
1536
|
+
def statistic_wrapped(*data, axis):
|
1537
|
+
data = np.swapaxes(data, 0, -1)
|
1538
|
+
if n_samples == 1:
|
1539
|
+
data = data[0:1]
|
1540
|
+
return statistic(*data, axis=axis)
|
1541
|
+
|
1542
|
+
return _calculate_null_pairings(data, statistic_wrapped, n_permutations,
|
1543
|
+
batch, rng)
|
1544
|
+
|
1545
|
+
|
1546
|
+
def _permutation_test_iv(data, statistic, permutation_type, vectorized,
|
1547
|
+
n_resamples, batch, alternative, axis, rng):
|
1548
|
+
"""Input validation for `permutation_test`."""
|
1549
|
+
|
1550
|
+
axis_int = int(axis)
|
1551
|
+
if axis != axis_int:
|
1552
|
+
raise ValueError("`axis` must be an integer.")
|
1553
|
+
|
1554
|
+
permutation_types = {'samples', 'pairings', 'independent'}
|
1555
|
+
permutation_type = permutation_type.lower()
|
1556
|
+
if permutation_type not in permutation_types:
|
1557
|
+
raise ValueError(f"`permutation_type` must be in {permutation_types}.")
|
1558
|
+
|
1559
|
+
if vectorized not in {True, False, None}:
|
1560
|
+
raise ValueError("`vectorized` must be `True`, `False`, or `None`.")
|
1561
|
+
|
1562
|
+
if vectorized is None:
|
1563
|
+
vectorized = 'axis' in inspect.signature(statistic).parameters
|
1564
|
+
|
1565
|
+
if not vectorized:
|
1566
|
+
statistic = _vectorize_statistic(statistic)
|
1567
|
+
|
1568
|
+
message = "`data` must be a tuple containing at least two samples"
|
1569
|
+
try:
|
1570
|
+
if len(data) < 2 and permutation_type == 'independent':
|
1571
|
+
raise ValueError(message)
|
1572
|
+
except TypeError:
|
1573
|
+
raise TypeError(message)
|
1574
|
+
|
1575
|
+
data = _broadcast_arrays(data, axis)
|
1576
|
+
data_iv = []
|
1577
|
+
for sample in data:
|
1578
|
+
sample = np.atleast_1d(sample)
|
1579
|
+
if sample.shape[axis] <= 1:
|
1580
|
+
raise ValueError("each sample in `data` must contain two or more "
|
1581
|
+
"observations along `axis`.")
|
1582
|
+
sample = np.moveaxis(sample, axis_int, -1)
|
1583
|
+
data_iv.append(sample)
|
1584
|
+
|
1585
|
+
n_resamples_int = (int(n_resamples) if not np.isinf(n_resamples)
|
1586
|
+
else np.inf)
|
1587
|
+
if n_resamples != n_resamples_int or n_resamples_int <= 0:
|
1588
|
+
raise ValueError("`n_resamples` must be a positive integer.")
|
1589
|
+
|
1590
|
+
if batch is None:
|
1591
|
+
batch_iv = batch
|
1592
|
+
else:
|
1593
|
+
batch_iv = int(batch)
|
1594
|
+
if batch != batch_iv or batch_iv <= 0:
|
1595
|
+
raise ValueError("`batch` must be a positive integer or None.")
|
1596
|
+
|
1597
|
+
alternatives = {'two-sided', 'greater', 'less'}
|
1598
|
+
alternative = alternative.lower()
|
1599
|
+
if alternative not in alternatives:
|
1600
|
+
raise ValueError(f"`alternative` must be in {alternatives}")
|
1601
|
+
|
1602
|
+
rng = check_random_state(rng)
|
1603
|
+
|
1604
|
+
return (data_iv, statistic, permutation_type, vectorized, n_resamples_int,
|
1605
|
+
batch_iv, alternative, axis_int, rng)
|
1606
|
+
|
1607
|
+
|
1608
|
+
@_transition_to_rng('random_state')
|
1609
|
+
def permutation_test(data, statistic, *, permutation_type='independent',
|
1610
|
+
vectorized=None, n_resamples=9999, batch=None,
|
1611
|
+
alternative="two-sided", axis=0, rng=None):
|
1612
|
+
r"""
|
1613
|
+
Performs a permutation test of a given statistic on provided data.
|
1614
|
+
|
1615
|
+
For independent sample statistics, the null hypothesis is that the data are
|
1616
|
+
randomly sampled from the same distribution.
|
1617
|
+
For paired sample statistics, two null hypothesis can be tested:
|
1618
|
+
that the data are paired at random or that the data are assigned to samples
|
1619
|
+
at random.
|
1620
|
+
|
1621
|
+
Parameters
|
1622
|
+
----------
|
1623
|
+
data : iterable of array-like
|
1624
|
+
Contains the samples, each of which is an array of observations.
|
1625
|
+
Dimensions of sample arrays must be compatible for broadcasting except
|
1626
|
+
along `axis`.
|
1627
|
+
statistic : callable
|
1628
|
+
Statistic for which the p-value of the hypothesis test is to be
|
1629
|
+
calculated. `statistic` must be a callable that accepts samples
|
1630
|
+
as separate arguments (e.g. ``statistic(*data)``) and returns the
|
1631
|
+
resulting statistic.
|
1632
|
+
If `vectorized` is set ``True``, `statistic` must also accept a keyword
|
1633
|
+
argument `axis` and be vectorized to compute the statistic along the
|
1634
|
+
provided `axis` of the sample arrays.
|
1635
|
+
permutation_type : {'independent', 'samples', 'pairings'}, optional
|
1636
|
+
The type of permutations to be performed, in accordance with the
|
1637
|
+
null hypothesis. The first two permutation types are for paired sample
|
1638
|
+
statistics, in which all samples contain the same number of
|
1639
|
+
observations and observations with corresponding indices along `axis`
|
1640
|
+
are considered to be paired; the third is for independent sample
|
1641
|
+
statistics.
|
1642
|
+
|
1643
|
+
- ``'samples'`` : observations are assigned to different samples
|
1644
|
+
but remain paired with the same observations from other samples.
|
1645
|
+
This permutation type is appropriate for paired sample hypothesis
|
1646
|
+
tests such as the Wilcoxon signed-rank test and the paired t-test.
|
1647
|
+
- ``'pairings'`` : observations are paired with different observations,
|
1648
|
+
but they remain within the same sample. This permutation type is
|
1649
|
+
appropriate for association/correlation tests with statistics such
|
1650
|
+
as Spearman's :math:`\rho`, Kendall's :math:`\tau`, and Pearson's
|
1651
|
+
:math:`r`.
|
1652
|
+
- ``'independent'`` (default) : observations are assigned to different
|
1653
|
+
samples. Samples may contain different numbers of observations. This
|
1654
|
+
permutation type is appropriate for independent sample hypothesis
|
1655
|
+
tests such as the Mann-Whitney :math:`U` test and the independent
|
1656
|
+
sample t-test.
|
1657
|
+
|
1658
|
+
Please see the Notes section below for more detailed descriptions
|
1659
|
+
of the permutation types.
|
1660
|
+
|
1661
|
+
vectorized : bool, optional
|
1662
|
+
If `vectorized` is set ``False``, `statistic` will not be passed
|
1663
|
+
keyword argument `axis` and is expected to calculate the statistic
|
1664
|
+
only for 1D samples. If ``True``, `statistic` will be passed keyword
|
1665
|
+
argument `axis` and is expected to calculate the statistic along `axis`
|
1666
|
+
when passed an ND sample array. If ``None`` (default), `vectorized`
|
1667
|
+
will be set ``True`` if ``axis`` is a parameter of `statistic`. Use
|
1668
|
+
of a vectorized statistic typically reduces computation time.
|
1669
|
+
n_resamples : int or np.inf, default: 9999
|
1670
|
+
Number of random permutations (resamples) used to approximate the null
|
1671
|
+
distribution. If greater than or equal to the number of distinct
|
1672
|
+
permutations, the exact null distribution will be computed.
|
1673
|
+
Note that the number of distinct permutations grows very rapidly with
|
1674
|
+
the sizes of samples, so exact tests are feasible only for very small
|
1675
|
+
data sets.
|
1676
|
+
batch : int, optional
|
1677
|
+
The number of permutations to process in each call to `statistic`.
|
1678
|
+
Memory usage is O( `batch` * ``n`` ), where ``n`` is the total size
|
1679
|
+
of all samples, regardless of the value of `vectorized`. Default is
|
1680
|
+
``None``, in which case ``batch`` is the number of permutations.
|
1681
|
+
alternative : {'two-sided', 'less', 'greater'}, optional
|
1682
|
+
The alternative hypothesis for which the p-value is calculated.
|
1683
|
+
For each alternative, the p-value is defined for exact tests as
|
1684
|
+
follows.
|
1685
|
+
|
1686
|
+
- ``'greater'`` : the percentage of the null distribution that is
|
1687
|
+
greater than or equal to the observed value of the test statistic.
|
1688
|
+
- ``'less'`` : the percentage of the null distribution that is
|
1689
|
+
less than or equal to the observed value of the test statistic.
|
1690
|
+
- ``'two-sided'`` (default) : twice the smaller of the p-values above.
|
1691
|
+
|
1692
|
+
Note that p-values for randomized tests are calculated according to the
|
1693
|
+
conservative (over-estimated) approximation suggested in [2]_ and [3]_
|
1694
|
+
rather than the unbiased estimator suggested in [4]_. That is, when
|
1695
|
+
calculating the proportion of the randomized null distribution that is
|
1696
|
+
as extreme as the observed value of the test statistic, the values in
|
1697
|
+
the numerator and denominator are both increased by one. An
|
1698
|
+
interpretation of this adjustment is that the observed value of the
|
1699
|
+
test statistic is always included as an element of the randomized
|
1700
|
+
null distribution.
|
1701
|
+
The convention used for two-sided p-values is not universal;
|
1702
|
+
the observed test statistic and null distribution are returned in
|
1703
|
+
case a different definition is preferred.
|
1704
|
+
|
1705
|
+
axis : int, default: 0
|
1706
|
+
The axis of the (broadcasted) samples over which to calculate the
|
1707
|
+
statistic. If samples have a different number of dimensions,
|
1708
|
+
singleton dimensions are prepended to samples with fewer dimensions
|
1709
|
+
before `axis` is considered.
|
1710
|
+
rng : `numpy.random.Generator`, optional
|
1711
|
+
Pseudorandom number generator state. When `rng` is None, a new
|
1712
|
+
`numpy.random.Generator` is created using entropy from the
|
1713
|
+
operating system. Types other than `numpy.random.Generator` are
|
1714
|
+
passed to `numpy.random.default_rng` to instantiate a ``Generator``.
|
1715
|
+
|
1716
|
+
Returns
|
1717
|
+
-------
|
1718
|
+
res : PermutationTestResult
|
1719
|
+
An object with attributes:
|
1720
|
+
|
1721
|
+
statistic : float or ndarray
|
1722
|
+
The observed test statistic of the data.
|
1723
|
+
pvalue : float or ndarray
|
1724
|
+
The p-value for the given alternative.
|
1725
|
+
null_distribution : ndarray
|
1726
|
+
The values of the test statistic generated under the null
|
1727
|
+
hypothesis.
|
1728
|
+
|
1729
|
+
Notes
|
1730
|
+
-----
|
1731
|
+
|
1732
|
+
The three types of permutation tests supported by this function are
|
1733
|
+
described below.
|
1734
|
+
|
1735
|
+
**Unpaired statistics** (``permutation_type='independent'``):
|
1736
|
+
|
1737
|
+
The null hypothesis associated with this permutation type is that all
|
1738
|
+
observations are sampled from the same underlying distribution and that
|
1739
|
+
they have been assigned to one of the samples at random.
|
1740
|
+
|
1741
|
+
Suppose ``data`` contains two samples; e.g. ``a, b = data``.
|
1742
|
+
When ``1 < n_resamples < binom(n, k)``, where
|
1743
|
+
|
1744
|
+
* ``k`` is the number of observations in ``a``,
|
1745
|
+
* ``n`` is the total number of observations in ``a`` and ``b``, and
|
1746
|
+
* ``binom(n, k)`` is the binomial coefficient (``n`` choose ``k``),
|
1747
|
+
|
1748
|
+
the data are pooled (concatenated), randomly assigned to either the first
|
1749
|
+
or second sample, and the statistic is calculated. This process is
|
1750
|
+
performed repeatedly, `permutation` times, generating a distribution of the
|
1751
|
+
statistic under the null hypothesis. The statistic of the original
|
1752
|
+
data is compared to this distribution to determine the p-value.
|
1753
|
+
|
1754
|
+
When ``n_resamples >= binom(n, k)``, an exact test is performed: the data
|
1755
|
+
are *partitioned* between the samples in each distinct way exactly once,
|
1756
|
+
and the exact null distribution is formed.
|
1757
|
+
Note that for a given partitioning of the data between the samples,
|
1758
|
+
only one ordering/permutation of the data *within* each sample is
|
1759
|
+
considered. For statistics that do not depend on the order of the data
|
1760
|
+
within samples, this dramatically reduces computational cost without
|
1761
|
+
affecting the shape of the null distribution (because the frequency/count
|
1762
|
+
of each value is affected by the same factor).
|
1763
|
+
|
1764
|
+
For ``a = [a1, a2, a3, a4]`` and ``b = [b1, b2, b3]``, an example of this
|
1765
|
+
permutation type is ``x = [b3, a1, a2, b2]`` and ``y = [a4, b1, a3]``.
|
1766
|
+
Because only one ordering/permutation of the data *within* each sample
|
1767
|
+
is considered in an exact test, a resampling like ``x = [b3, a1, b2, a2]``
|
1768
|
+
and ``y = [a4, a3, b1]`` would *not* be considered distinct from the
|
1769
|
+
example above.
|
1770
|
+
|
1771
|
+
``permutation_type='independent'`` does not support one-sample statistics,
|
1772
|
+
but it can be applied to statistics with more than two samples. In this
|
1773
|
+
case, if ``n`` is an array of the number of observations within each
|
1774
|
+
sample, the number of distinct partitions is::
|
1775
|
+
|
1776
|
+
np.prod([binom(sum(n[i:]), sum(n[i+1:])) for i in range(len(n)-1)])
|
1777
|
+
|
1778
|
+
**Paired statistics, permute pairings** (``permutation_type='pairings'``):
|
1779
|
+
|
1780
|
+
The null hypothesis associated with this permutation type is that
|
1781
|
+
observations within each sample are drawn from the same underlying
|
1782
|
+
distribution and that pairings with elements of other samples are
|
1783
|
+
assigned at random.
|
1784
|
+
|
1785
|
+
Suppose ``data`` contains only one sample; e.g. ``a, = data``, and we
|
1786
|
+
wish to consider all possible pairings of elements of ``a`` with elements
|
1787
|
+
of a second sample, ``b``. Let ``n`` be the number of observations in
|
1788
|
+
``a``, which must also equal the number of observations in ``b``.
|
1789
|
+
|
1790
|
+
When ``1 < n_resamples < factorial(n)``, the elements of ``a`` are
|
1791
|
+
randomly permuted. The user-supplied statistic accepts one data argument,
|
1792
|
+
say ``a_perm``, and calculates the statistic considering ``a_perm`` and
|
1793
|
+
``b``. This process is performed repeatedly, `permutation` times,
|
1794
|
+
generating a distribution of the statistic under the null hypothesis.
|
1795
|
+
The statistic of the original data is compared to this distribution to
|
1796
|
+
determine the p-value.
|
1797
|
+
|
1798
|
+
When ``n_resamples >= factorial(n)``, an exact test is performed:
|
1799
|
+
``a`` is permuted in each distinct way exactly once. Therefore, the
|
1800
|
+
`statistic` is computed for each unique pairing of samples between ``a``
|
1801
|
+
and ``b`` exactly once.
|
1802
|
+
|
1803
|
+
For ``a = [a1, a2, a3]`` and ``b = [b1, b2, b3]``, an example of this
|
1804
|
+
permutation type is ``a_perm = [a3, a1, a2]`` while ``b`` is left
|
1805
|
+
in its original order.
|
1806
|
+
|
1807
|
+
``permutation_type='pairings'`` supports ``data`` containing any number
|
1808
|
+
of samples, each of which must contain the same number of observations.
|
1809
|
+
All samples provided in ``data`` are permuted *independently*. Therefore,
|
1810
|
+
if ``m`` is the number of samples and ``n`` is the number of observations
|
1811
|
+
within each sample, then the number of permutations in an exact test is::
|
1812
|
+
|
1813
|
+
factorial(n)**m
|
1814
|
+
|
1815
|
+
Note that if a two-sample statistic, for example, does not inherently
|
1816
|
+
depend on the order in which observations are provided - only on the
|
1817
|
+
*pairings* of observations - then only one of the two samples should be
|
1818
|
+
provided in ``data``. This dramatically reduces computational cost without
|
1819
|
+
affecting the shape of the null distribution (because the frequency/count
|
1820
|
+
of each value is affected by the same factor).
|
1821
|
+
|
1822
|
+
**Paired statistics, permute samples** (``permutation_type='samples'``):
|
1823
|
+
|
1824
|
+
The null hypothesis associated with this permutation type is that
|
1825
|
+
observations within each pair are drawn from the same underlying
|
1826
|
+
distribution and that the sample to which they are assigned is random.
|
1827
|
+
|
1828
|
+
Suppose ``data`` contains two samples; e.g. ``a, b = data``.
|
1829
|
+
Let ``n`` be the number of observations in ``a``, which must also equal
|
1830
|
+
the number of observations in ``b``.
|
1831
|
+
|
1832
|
+
When ``1 < n_resamples < 2**n``, the elements of ``a`` are ``b`` are
|
1833
|
+
randomly swapped between samples (maintaining their pairings) and the
|
1834
|
+
statistic is calculated. This process is performed repeatedly,
|
1835
|
+
`permutation` times, generating a distribution of the statistic under the
|
1836
|
+
null hypothesis. The statistic of the original data is compared to this
|
1837
|
+
distribution to determine the p-value.
|
1838
|
+
|
1839
|
+
When ``n_resamples >= 2**n``, an exact test is performed: the observations
|
1840
|
+
are assigned to the two samples in each distinct way (while maintaining
|
1841
|
+
pairings) exactly once.
|
1842
|
+
|
1843
|
+
For ``a = [a1, a2, a3]`` and ``b = [b1, b2, b3]``, an example of this
|
1844
|
+
permutation type is ``x = [b1, a2, b3]`` and ``y = [a1, b2, a3]``.
|
1845
|
+
|
1846
|
+
``permutation_type='samples'`` supports ``data`` containing any number
|
1847
|
+
of samples, each of which must contain the same number of observations.
|
1848
|
+
If ``data`` contains more than one sample, paired observations within
|
1849
|
+
``data`` are exchanged between samples *independently*. Therefore, if ``m``
|
1850
|
+
is the number of samples and ``n`` is the number of observations within
|
1851
|
+
each sample, then the number of permutations in an exact test is::
|
1852
|
+
|
1853
|
+
factorial(m)**n
|
1854
|
+
|
1855
|
+
Several paired-sample statistical tests, such as the Wilcoxon signed rank
|
1856
|
+
test and paired-sample t-test, can be performed considering only the
|
1857
|
+
*difference* between two paired elements. Accordingly, if ``data`` contains
|
1858
|
+
only one sample, then the null distribution is formed by independently
|
1859
|
+
changing the *sign* of each observation.
|
1860
|
+
|
1861
|
+
.. warning::
|
1862
|
+
The p-value is calculated by counting the elements of the null
|
1863
|
+
distribution that are as extreme or more extreme than the observed
|
1864
|
+
value of the statistic. Due to the use of finite precision arithmetic,
|
1865
|
+
some statistic functions return numerically distinct values when the
|
1866
|
+
theoretical values would be exactly equal. In some cases, this could
|
1867
|
+
lead to a large error in the calculated p-value. `permutation_test`
|
1868
|
+
guards against this by considering elements in the null distribution
|
1869
|
+
that are "close" (within a relative tolerance of 100 times the
|
1870
|
+
floating point epsilon of inexact dtypes) to the observed
|
1871
|
+
value of the test statistic as equal to the observed value of the
|
1872
|
+
test statistic. However, the user is advised to inspect the null
|
1873
|
+
distribution to assess whether this method of comparison is
|
1874
|
+
appropriate, and if not, calculate the p-value manually. See example
|
1875
|
+
below.
|
1876
|
+
|
1877
|
+
References
|
1878
|
+
----------
|
1879
|
+
|
1880
|
+
.. [1] R. A. Fisher. The Design of Experiments, 6th Ed (1951).
|
1881
|
+
.. [2] B. Phipson and G. K. Smyth. "Permutation P-values Should Never Be
|
1882
|
+
Zero: Calculating Exact P-values When Permutations Are Randomly Drawn."
|
1883
|
+
Statistical Applications in Genetics and Molecular Biology 9.1 (2010).
|
1884
|
+
.. [3] M. D. Ernst. "Permutation Methods: A Basis for Exact Inference".
|
1885
|
+
Statistical Science (2004).
|
1886
|
+
.. [4] B. Efron and R. J. Tibshirani. An Introduction to the Bootstrap
|
1887
|
+
(1993).
|
1888
|
+
|
1889
|
+
Examples
|
1890
|
+
--------
|
1891
|
+
|
1892
|
+
Suppose we wish to test whether two samples are drawn from the same
|
1893
|
+
distribution. Assume that the underlying distributions are unknown to us,
|
1894
|
+
and that before observing the data, we hypothesized that the mean of the
|
1895
|
+
first sample would be less than that of the second sample. We decide that
|
1896
|
+
we will use the difference between the sample means as a test statistic,
|
1897
|
+
and we will consider a p-value of 0.05 to be statistically significant.
|
1898
|
+
|
1899
|
+
For efficiency, we write the function defining the test statistic in a
|
1900
|
+
vectorized fashion: the samples ``x`` and ``y`` can be ND arrays, and the
|
1901
|
+
statistic will be calculated for each axis-slice along `axis`.
|
1902
|
+
|
1903
|
+
>>> import numpy as np
|
1904
|
+
>>> def statistic(x, y, axis):
|
1905
|
+
... return np.mean(x, axis=axis) - np.mean(y, axis=axis)
|
1906
|
+
|
1907
|
+
After collecting our data, we calculate the observed value of the test
|
1908
|
+
statistic.
|
1909
|
+
|
1910
|
+
>>> from scipy.stats import norm
|
1911
|
+
>>> rng = np.random.default_rng()
|
1912
|
+
>>> x = norm.rvs(size=5, random_state=rng)
|
1913
|
+
>>> y = norm.rvs(size=6, loc = 3, random_state=rng)
|
1914
|
+
>>> statistic(x, y, 0)
|
1915
|
+
-3.5411688580987266
|
1916
|
+
|
1917
|
+
Indeed, the test statistic is negative, suggesting that the true mean of
|
1918
|
+
the distribution underlying ``x`` is less than that of the distribution
|
1919
|
+
underlying ``y``. To determine the probability of this occurring by chance
|
1920
|
+
if the two samples were drawn from the same distribution, we perform
|
1921
|
+
a permutation test.
|
1922
|
+
|
1923
|
+
>>> from scipy.stats import permutation_test
|
1924
|
+
>>> # because our statistic is vectorized, we pass `vectorized=True`
|
1925
|
+
>>> # `n_resamples=np.inf` indicates that an exact test is to be performed
|
1926
|
+
>>> res = permutation_test((x, y), statistic, vectorized=True,
|
1927
|
+
... n_resamples=np.inf, alternative='less')
|
1928
|
+
>>> print(res.statistic)
|
1929
|
+
-3.5411688580987266
|
1930
|
+
>>> print(res.pvalue)
|
1931
|
+
0.004329004329004329
|
1932
|
+
|
1933
|
+
The probability of obtaining a test statistic less than or equal to the
|
1934
|
+
observed value under the null hypothesis is 0.4329%. This is less than our
|
1935
|
+
chosen threshold of 5%, so we consider this to be significant evidence
|
1936
|
+
against the null hypothesis in favor of the alternative.
|
1937
|
+
|
1938
|
+
Because the size of the samples above was small, `permutation_test` could
|
1939
|
+
perform an exact test. For larger samples, we resort to a randomized
|
1940
|
+
permutation test.
|
1941
|
+
|
1942
|
+
>>> x = norm.rvs(size=100, random_state=rng)
|
1943
|
+
>>> y = norm.rvs(size=120, loc=0.2, random_state=rng)
|
1944
|
+
>>> res = permutation_test((x, y), statistic, n_resamples=9999,
|
1945
|
+
... vectorized=True, alternative='less',
|
1946
|
+
... rng=rng)
|
1947
|
+
>>> print(res.statistic)
|
1948
|
+
-0.4230459671240913
|
1949
|
+
>>> print(res.pvalue)
|
1950
|
+
0.0015
|
1951
|
+
|
1952
|
+
The approximate probability of obtaining a test statistic less than or
|
1953
|
+
equal to the observed value under the null hypothesis is 0.0225%. This is
|
1954
|
+
again less than our chosen threshold of 5%, so again we have significant
|
1955
|
+
evidence to reject the null hypothesis in favor of the alternative.
|
1956
|
+
|
1957
|
+
For large samples and number of permutations, the result is comparable to
|
1958
|
+
that of the corresponding asymptotic test, the independent sample t-test.
|
1959
|
+
|
1960
|
+
>>> from scipy.stats import ttest_ind
|
1961
|
+
>>> res_asymptotic = ttest_ind(x, y, alternative='less')
|
1962
|
+
>>> print(res_asymptotic.pvalue)
|
1963
|
+
0.0014669545224902675
|
1964
|
+
|
1965
|
+
The permutation distribution of the test statistic is provided for
|
1966
|
+
further investigation.
|
1967
|
+
|
1968
|
+
>>> import matplotlib.pyplot as plt
|
1969
|
+
>>> plt.hist(res.null_distribution, bins=50)
|
1970
|
+
>>> plt.title("Permutation distribution of test statistic")
|
1971
|
+
>>> plt.xlabel("Value of Statistic")
|
1972
|
+
>>> plt.ylabel("Frequency")
|
1973
|
+
>>> plt.show()
|
1974
|
+
|
1975
|
+
Inspection of the null distribution is essential if the statistic suffers
|
1976
|
+
from inaccuracy due to limited machine precision. Consider the following
|
1977
|
+
case:
|
1978
|
+
|
1979
|
+
>>> from scipy.stats import pearsonr
|
1980
|
+
>>> x = [1, 2, 4, 3]
|
1981
|
+
>>> y = [2, 4, 6, 8]
|
1982
|
+
>>> def statistic(x, y, axis=-1):
|
1983
|
+
... return pearsonr(x, y, axis=axis).statistic
|
1984
|
+
>>> res = permutation_test((x, y), statistic, vectorized=True,
|
1985
|
+
... permutation_type='pairings',
|
1986
|
+
... alternative='greater')
|
1987
|
+
>>> r, pvalue, null = res.statistic, res.pvalue, res.null_distribution
|
1988
|
+
|
1989
|
+
In this case, some elements of the null distribution differ from the
|
1990
|
+
observed value of the correlation coefficient ``r`` due to numerical noise.
|
1991
|
+
We manually inspect the elements of the null distribution that are nearly
|
1992
|
+
the same as the observed value of the test statistic.
|
1993
|
+
|
1994
|
+
>>> r
|
1995
|
+
0.7999999999999999
|
1996
|
+
>>> unique = np.unique(null)
|
1997
|
+
>>> unique
|
1998
|
+
array([-1. , -1. , -0.8, -0.8, -0.8, -0.6, -0.4, -0.4, -0.2, -0.2, -0.2,
|
1999
|
+
0. , 0.2, 0.2, 0.2, 0.4, 0.4, 0.6, 0.8, 0.8, 0.8, 1. ,
|
2000
|
+
1. ]) # may vary
|
2001
|
+
>>> unique[np.isclose(r, unique)].tolist()
|
2002
|
+
[0.7999999999999998, 0.7999999999999999, 0.8] # may vary
|
2003
|
+
|
2004
|
+
If `permutation_test` were to perform the comparison naively, the
|
2005
|
+
elements of the null distribution with value ``0.7999999999999998`` would
|
2006
|
+
not be considered as extreme or more extreme as the observed value of the
|
2007
|
+
statistic, so the calculated p-value would be too small.
|
2008
|
+
|
2009
|
+
>>> incorrect_pvalue = np.count_nonzero(null >= r) / len(null)
|
2010
|
+
>>> incorrect_pvalue
|
2011
|
+
0.14583333333333334 # may vary
|
2012
|
+
|
2013
|
+
Instead, `permutation_test` treats elements of the null distribution that
|
2014
|
+
are within ``max(1e-14, abs(r)*1e-14)`` of the observed value of the
|
2015
|
+
statistic ``r`` to be equal to ``r``.
|
2016
|
+
|
2017
|
+
>>> correct_pvalue = np.count_nonzero(null >= r - 1e-14) / len(null)
|
2018
|
+
>>> correct_pvalue
|
2019
|
+
0.16666666666666666
|
2020
|
+
>>> res.pvalue == correct_pvalue
|
2021
|
+
True
|
2022
|
+
|
2023
|
+
This method of comparison is expected to be accurate in most practical
|
2024
|
+
situations, but the user is advised to assess this by inspecting the
|
2025
|
+
elements of the null distribution that are close to the observed value
|
2026
|
+
of the statistic. Also, consider the use of statistics that can be
|
2027
|
+
calculated using exact arithmetic (e.g. integer statistics).
|
2028
|
+
|
2029
|
+
"""
|
2030
|
+
args = _permutation_test_iv(data, statistic, permutation_type, vectorized,
|
2031
|
+
n_resamples, batch, alternative, axis,
|
2032
|
+
rng)
|
2033
|
+
(data, statistic, permutation_type, vectorized, n_resamples, batch,
|
2034
|
+
alternative, axis, rng) = args
|
2035
|
+
|
2036
|
+
observed = statistic(*data, axis=-1)
|
2037
|
+
|
2038
|
+
null_calculators = {"pairings": _calculate_null_pairings,
|
2039
|
+
"samples": _calculate_null_samples,
|
2040
|
+
"independent": _calculate_null_both}
|
2041
|
+
null_calculator_args = (data, statistic, n_resamples,
|
2042
|
+
batch, rng)
|
2043
|
+
calculate_null = null_calculators[permutation_type]
|
2044
|
+
null_distribution, n_resamples, exact_test = (
|
2045
|
+
calculate_null(*null_calculator_args))
|
2046
|
+
|
2047
|
+
# See References [2] and [3]
|
2048
|
+
adjustment = 0 if exact_test else 1
|
2049
|
+
|
2050
|
+
# relative tolerance for detecting numerically distinct but
|
2051
|
+
# theoretically equal values in the null distribution
|
2052
|
+
eps = (0 if not np.issubdtype(observed.dtype, np.inexact)
|
2053
|
+
else np.finfo(observed.dtype).eps*100)
|
2054
|
+
gamma = np.abs(eps * observed)
|
2055
|
+
|
2056
|
+
def less(null_distribution, observed):
|
2057
|
+
cmps = null_distribution <= observed + gamma
|
2058
|
+
pvalues = (cmps.sum(axis=0) + adjustment) / (n_resamples + adjustment)
|
2059
|
+
return pvalues
|
2060
|
+
|
2061
|
+
def greater(null_distribution, observed):
|
2062
|
+
cmps = null_distribution >= observed - gamma
|
2063
|
+
pvalues = (cmps.sum(axis=0) + adjustment) / (n_resamples + adjustment)
|
2064
|
+
return pvalues
|
2065
|
+
|
2066
|
+
def two_sided(null_distribution, observed):
|
2067
|
+
pvalues_less = less(null_distribution, observed)
|
2068
|
+
pvalues_greater = greater(null_distribution, observed)
|
2069
|
+
pvalues = np.minimum(pvalues_less, pvalues_greater) * 2
|
2070
|
+
return pvalues
|
2071
|
+
|
2072
|
+
compare = {"less": less,
|
2073
|
+
"greater": greater,
|
2074
|
+
"two-sided": two_sided}
|
2075
|
+
|
2076
|
+
pvalues = compare[alternative](null_distribution, observed)
|
2077
|
+
pvalues = np.clip(pvalues, 0, 1)
|
2078
|
+
|
2079
|
+
return PermutationTestResult(observed, pvalues, null_distribution)
|
2080
|
+
|
2081
|
+
|
2082
|
+
@dataclass
|
2083
|
+
class ResamplingMethod:
|
2084
|
+
"""Configuration information for a statistical resampling method.
|
2085
|
+
|
2086
|
+
Instances of this class can be passed into the `method` parameter of some
|
2087
|
+
hypothesis test functions to perform a resampling or Monte Carlo version
|
2088
|
+
of the hypothesis test.
|
2089
|
+
|
2090
|
+
Attributes
|
2091
|
+
----------
|
2092
|
+
n_resamples : int
|
2093
|
+
The number of resamples to perform or Monte Carlo samples to draw.
|
2094
|
+
batch : int, optional
|
2095
|
+
The number of resamples to process in each vectorized call to
|
2096
|
+
the statistic. Batch sizes >>1 tend to be faster when the statistic
|
2097
|
+
is vectorized, but memory usage scales linearly with the batch size.
|
2098
|
+
Default is ``None``, which processes all resamples in a single batch.
|
2099
|
+
|
2100
|
+
"""
|
2101
|
+
n_resamples: int = 9999
|
2102
|
+
batch: int = None # type: ignore[assignment]
|
2103
|
+
|
2104
|
+
|
2105
|
+
@dataclass
|
2106
|
+
class MonteCarloMethod(ResamplingMethod):
|
2107
|
+
"""Configuration information for a Monte Carlo hypothesis test.
|
2108
|
+
|
2109
|
+
Instances of this class can be passed into the `method` parameter of some
|
2110
|
+
hypothesis test functions to perform a Monte Carlo version of the
|
2111
|
+
hypothesis tests.
|
2112
|
+
|
2113
|
+
Attributes
|
2114
|
+
----------
|
2115
|
+
n_resamples : int, optional
|
2116
|
+
The number of Monte Carlo samples to draw. Default is 9999.
|
2117
|
+
batch : int, optional
|
2118
|
+
The number of Monte Carlo samples to process in each vectorized call to
|
2119
|
+
the statistic. Batch sizes >>1 tend to be faster when the statistic
|
2120
|
+
is vectorized, but memory usage scales linearly with the batch size.
|
2121
|
+
Default is ``None``, which processes all samples in a single batch.
|
2122
|
+
rvs : callable or tuple of callables, optional
|
2123
|
+
A callable or sequence of callables that generates random variates
|
2124
|
+
under the null hypothesis. Each element of `rvs` must be a callable
|
2125
|
+
that accepts keyword argument ``size`` (e.g. ``rvs(size=(m, n))``) and
|
2126
|
+
returns an N-d array sample of that shape. If `rvs` is a sequence, the
|
2127
|
+
number of callables in `rvs` must match the number of samples passed
|
2128
|
+
to the hypothesis test in which the `MonteCarloMethod` is used. Default
|
2129
|
+
is ``None``, in which case the hypothesis test function chooses values
|
2130
|
+
to match the standard version of the hypothesis test. For example,
|
2131
|
+
the null hypothesis of `scipy.stats.pearsonr` is typically that the
|
2132
|
+
samples are drawn from the standard normal distribution, so
|
2133
|
+
``rvs = (rng.normal, rng.normal)`` where
|
2134
|
+
``rng = np.random.default_rng()``.
|
2135
|
+
rng : `numpy.random.Generator`, optional
|
2136
|
+
Pseudorandom number generator state. When `rng` is None, a new
|
2137
|
+
`numpy.random.Generator` is created using entropy from the
|
2138
|
+
operating system. Types other than `numpy.random.Generator` are
|
2139
|
+
passed to `numpy.random.default_rng` to instantiate a ``Generator``.
|
2140
|
+
|
2141
|
+
"""
|
2142
|
+
rvs: object = None
|
2143
|
+
rng: object = None
|
2144
|
+
|
2145
|
+
def __init__(self, n_resamples=9999, batch=None, rvs=None, rng=None):
|
2146
|
+
if (rvs is not None) and (rng is not None):
|
2147
|
+
message = 'Use of `rvs` and `rng` are mutually exclusive.'
|
2148
|
+
raise ValueError(message)
|
2149
|
+
|
2150
|
+
self.n_resamples = n_resamples
|
2151
|
+
self.batch = batch
|
2152
|
+
self.rvs = rvs
|
2153
|
+
self.rng = rng
|
2154
|
+
|
2155
|
+
def _asdict(self):
|
2156
|
+
# `dataclasses.asdict` deepcopies; we don't want that.
|
2157
|
+
return dict(n_resamples=self.n_resamples, batch=self.batch,
|
2158
|
+
rvs=self.rvs, rng=self.rng)
|
2159
|
+
|
2160
|
+
|
2161
|
+
_rs_deprecation = ("Use of attribute `random_state` is deprecated and replaced by "
|
2162
|
+
"`rng`. Support for `random_state` will be removed in SciPy 1.19.0. "
|
2163
|
+
"To silence this warning and ensure consistent behavior in SciPy "
|
2164
|
+
"1.19.0, control the RNG using attribute `rng`. Values set using "
|
2165
|
+
"attribute `rng` will be validated by `np.random.default_rng`, so "
|
2166
|
+
"the behavior corresponding with a given value may change compared "
|
2167
|
+
"to use of `random_state`. For example, 1) `None` will result in "
|
2168
|
+
"unpredictable random numbers, 2) an integer will result in a "
|
2169
|
+
"different stream of random numbers, (with the same distribution), "
|
2170
|
+
"and 3) `np.random` or `RandomState` instances will result in an "
|
2171
|
+
"error. See the documentation of `default_rng` for more "
|
2172
|
+
"information.")
|
2173
|
+
|
2174
|
+
|
2175
|
+
@dataclass
|
2176
|
+
class PermutationMethod(ResamplingMethod):
|
2177
|
+
"""Configuration information for a permutation hypothesis test.
|
2178
|
+
|
2179
|
+
Instances of this class can be passed into the `method` parameter of some
|
2180
|
+
hypothesis test functions to perform a permutation version of the
|
2181
|
+
hypothesis tests.
|
2182
|
+
|
2183
|
+
Attributes
|
2184
|
+
----------
|
2185
|
+
n_resamples : int, optional
|
2186
|
+
The number of resamples to perform. Default is 9999.
|
2187
|
+
batch : int, optional
|
2188
|
+
The number of resamples to process in each vectorized call to
|
2189
|
+
the statistic. Batch sizes >>1 tend to be faster when the statistic
|
2190
|
+
is vectorized, but memory usage scales linearly with the batch size.
|
2191
|
+
Default is ``None``, which processes all resamples in a single batch.
|
2192
|
+
rng : `numpy.random.Generator`, optional
|
2193
|
+
Pseudorandom number generator used to perform resampling.
|
2194
|
+
|
2195
|
+
If `rng` is passed by keyword to the initializer or the `rng` attribute is used
|
2196
|
+
directly, types other than `numpy.random.Generator` are passed to
|
2197
|
+
`numpy.random.default_rng` to instantiate a ``Generator`` before use.
|
2198
|
+
If `rng` is already a ``Generator`` instance, then the provided instance is
|
2199
|
+
used. Specify `rng` for repeatable behavior.
|
2200
|
+
|
2201
|
+
If this argument is passed by position, if `random_state` is passed by keyword
|
2202
|
+
into the initializer, or if the `random_state` attribute is used directly,
|
2203
|
+
legacy behavior for `random_state` applies:
|
2204
|
+
|
2205
|
+
- If `random_state` is None (or `numpy.random`), the `numpy.random.RandomState`
|
2206
|
+
singleton is used.
|
2207
|
+
- If `random_state` is an int, a new ``RandomState`` instance is used,
|
2208
|
+
seeded with `random_state`.
|
2209
|
+
- If `random_state` is already a ``Generator`` or ``RandomState`` instance then
|
2210
|
+
that instance is used.
|
2211
|
+
|
2212
|
+
.. versionchanged:: 1.15.0
|
2213
|
+
|
2214
|
+
As part of the `SPEC-007 <https://scientific-python.org/specs/spec-0007/>`_
|
2215
|
+
transition from use of `numpy.random.RandomState` to
|
2216
|
+
`numpy.random.Generator`, this attribute name was changed from
|
2217
|
+
`random_state` to `rng`. For an interim period, both names will continue to
|
2218
|
+
work, although only one may be specified at a time. After the interim
|
2219
|
+
period, uses of `random_state` will emit warnings. The behavior of both
|
2220
|
+
`random_state` and `rng` are outlined above, but only `rng` should be used
|
2221
|
+
in new code.
|
2222
|
+
|
2223
|
+
"""
|
2224
|
+
rng: object # type: ignore[misc]
|
2225
|
+
_rng: object = field(init=False, repr=False, default=None) # type: ignore[assignment]
|
2226
|
+
|
2227
|
+
@property
|
2228
|
+
def random_state(self):
|
2229
|
+
# Uncomment in SciPy 1.17.0
|
2230
|
+
# warnings.warn(_rs_deprecation, DeprecationWarning, stacklevel=2)
|
2231
|
+
return self._random_state
|
2232
|
+
|
2233
|
+
@random_state.setter
|
2234
|
+
def random_state(self, val):
|
2235
|
+
# Uncomment in SciPy 1.17.0
|
2236
|
+
# warnings.warn(_rs_deprecation, DeprecationWarning, stacklevel=2)
|
2237
|
+
self._random_state = val
|
2238
|
+
|
2239
|
+
@property # type: ignore[no-redef]
|
2240
|
+
def rng(self): # noqa: F811
|
2241
|
+
return self._rng
|
2242
|
+
|
2243
|
+
def __init__(self, n_resamples=9999, batch=None, random_state=None, *, rng=None):
|
2244
|
+
# Uncomment in SciPy 1.17.0
|
2245
|
+
# warnings.warn(_rs_deprecation.replace('attribute', 'argument'),
|
2246
|
+
# DeprecationWarning, stacklevel=2)
|
2247
|
+
self._rng = rng
|
2248
|
+
self._random_state = random_state
|
2249
|
+
super().__init__(n_resamples=n_resamples, batch=batch)
|
2250
|
+
|
2251
|
+
def _asdict(self):
|
2252
|
+
# `dataclasses.asdict` deepcopies; we don't want that.
|
2253
|
+
d = dict(n_resamples=self.n_resamples, batch=self.batch)
|
2254
|
+
if self.rng is not None:
|
2255
|
+
d['rng'] = self.rng
|
2256
|
+
if self.random_state is not None:
|
2257
|
+
d['random_state'] = self.random_state
|
2258
|
+
return d
|
2259
|
+
|
2260
|
+
|
2261
|
+
@dataclass
|
2262
|
+
class BootstrapMethod(ResamplingMethod):
|
2263
|
+
"""Configuration information for a bootstrap confidence interval.
|
2264
|
+
|
2265
|
+
Instances of this class can be passed into the `method` parameter of some
|
2266
|
+
confidence interval methods to generate a bootstrap confidence interval.
|
2267
|
+
|
2268
|
+
Attributes
|
2269
|
+
----------
|
2270
|
+
n_resamples : int, optional
|
2271
|
+
The number of resamples to perform. Default is 9999.
|
2272
|
+
batch : int, optional
|
2273
|
+
The number of resamples to process in each vectorized call to
|
2274
|
+
the statistic. Batch sizes >>1 tend to be faster when the statistic
|
2275
|
+
is vectorized, but memory usage scales linearly with the batch size.
|
2276
|
+
Default is ``None``, which processes all resamples in a single batch.
|
2277
|
+
rng : `numpy.random.Generator`, optional
|
2278
|
+
Pseudorandom number generator used to perform resampling.
|
2279
|
+
|
2280
|
+
If `rng` is passed by keyword to the initializer or the `rng` attribute is used
|
2281
|
+
directly, types other than `numpy.random.Generator` are passed to
|
2282
|
+
`numpy.random.default_rng` to instantiate a ``Generator`` before use.
|
2283
|
+
If `rng` is already a ``Generator`` instance, then the provided instance is
|
2284
|
+
used. Specify `rng` for repeatable behavior.
|
2285
|
+
|
2286
|
+
If this argument is passed by position, if `random_state` is passed by keyword
|
2287
|
+
into the initializer, or if the `random_state` attribute is used directly,
|
2288
|
+
legacy behavior for `random_state` applies:
|
2289
|
+
|
2290
|
+
- If `random_state` is None (or `numpy.random`), the `numpy.random.RandomState`
|
2291
|
+
singleton is used.
|
2292
|
+
- If `random_state` is an int, a new ``RandomState`` instance is used,
|
2293
|
+
seeded with `random_state`.
|
2294
|
+
- If `random_state` is already a ``Generator`` or ``RandomState`` instance then
|
2295
|
+
that instance is used.
|
2296
|
+
|
2297
|
+
.. versionchanged:: 1.15.0
|
2298
|
+
|
2299
|
+
As part of the `SPEC-007 <https://scientific-python.org/specs/spec-0007/>`_
|
2300
|
+
transition from use of `numpy.random.RandomState` to
|
2301
|
+
`numpy.random.Generator`, this attribute name was changed from
|
2302
|
+
`random_state` to `rng`. For an interim period, both names will continue to
|
2303
|
+
work, although only one may be specified at a time. After the interim
|
2304
|
+
period, uses of `random_state` will emit warnings. The behavior of both
|
2305
|
+
`random_state` and `rng` are outlined above, but only `rng` should be used
|
2306
|
+
in new code.
|
2307
|
+
|
2308
|
+
method : {'BCa', 'percentile', 'basic'}
|
2309
|
+
Whether to use the 'percentile' bootstrap ('percentile'), the 'basic'
|
2310
|
+
(AKA 'reverse') bootstrap ('basic'), or the bias-corrected and
|
2311
|
+
accelerated bootstrap ('BCa', default).
|
2312
|
+
|
2313
|
+
"""
|
2314
|
+
rng: object # type: ignore[misc]
|
2315
|
+
_rng: object = field(init=False, repr=False, default=None) # type: ignore[assignment]
|
2316
|
+
method: str = 'BCa'
|
2317
|
+
|
2318
|
+
@property
|
2319
|
+
def random_state(self):
|
2320
|
+
# Uncomment in SciPy 1.17.0
|
2321
|
+
# warnings.warn(_rs_deprecation, DeprecationWarning, stacklevel=2)
|
2322
|
+
return self._random_state
|
2323
|
+
|
2324
|
+
@random_state.setter
|
2325
|
+
def random_state(self, val):
|
2326
|
+
# Uncomment in SciPy 1.17.0
|
2327
|
+
# warnings.warn(_rs_deprecation, DeprecationWarning, stacklevel=2)
|
2328
|
+
self._random_state = val
|
2329
|
+
|
2330
|
+
@property # type: ignore[no-redef]
|
2331
|
+
def rng(self): # noqa: F811
|
2332
|
+
return self._rng
|
2333
|
+
|
2334
|
+
def __init__(self, n_resamples=9999, batch=None, random_state=None,
|
2335
|
+
method='BCa', *, rng=None):
|
2336
|
+
# Uncomment in SciPy 1.17.0
|
2337
|
+
# warnings.warn(_rs_deprecation.replace('attribute', 'argument'),
|
2338
|
+
# DeprecationWarning, stacklevel=2)
|
2339
|
+
self._rng = rng # don't validate with `default_rng`
|
2340
|
+
self._random_state = random_state
|
2341
|
+
self.method = method
|
2342
|
+
super().__init__(n_resamples=n_resamples, batch=batch)
|
2343
|
+
|
2344
|
+
def _asdict(self):
|
2345
|
+
# `dataclasses.asdict` deepcopies; we don't want that.
|
2346
|
+
d = dict(n_resamples=self.n_resamples, batch=self.batch,
|
2347
|
+
method=self.method)
|
2348
|
+
if self.rng is not None:
|
2349
|
+
d['rng'] = self.rng
|
2350
|
+
if self.random_state is not None:
|
2351
|
+
d['random_state'] = self.random_state
|
2352
|
+
return d
|