Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy-1.15.3.dist-info/INSTALLER +1 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy-1.15.3.dist-info/LICENSE.txt +934 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy-1.15.3.dist-info/METADATA +1082 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy-1.15.3.dist-info/RECORD +0 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy-1.15.3.dist-info/WHEEL +6 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/hyperg.h +361 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/i0.h +149 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/i1.h +158 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/igam.h +421 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/igam_asymp_coeff.h +195 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/igami.h +313 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/j0.h +225 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/j1.h +198 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/jv.h +715 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/k0.h +164 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/k1.h +163 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/kn.h +243 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/lanczos.h +112 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/ndtr.h +275 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/poch.h +85 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/polevl.h +167 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/psi.h +194 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/rgamma.h +111 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/scipy_iv.h +811 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/shichi.h +248 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/sici.h +224 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/sindg.h +221 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/tandg.h +139 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/trig.h +58 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/unity.h +186 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/zeta.h +172 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/stats/__init__.py +667 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/stats/_axis_nan_policy.py +699 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/stats/_biasedurn.pxd +27 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/stats/_binned_statistic.py +795 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/stats/_binomtest.py +375 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/stats/_bws_test.py +177 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/stats/_censored_data.py +459 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/stats/_common.py +5 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/stats/_constants.py +42 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/stats/_continuous_distns.py +0 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/stats/_correlation.py +210 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/stats/_covariance.py +633 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/stats/_crosstab.py +204 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/stats/_discrete_distns.py +2091 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/stats/_distn_infrastructure.py +0 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/stats/_distr_params.py +299 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/stats/_distribution_infrastructure.py +0 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/stats/_entropy.py +429 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/stats/_fit.py +1351 -0
miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy-1.15.3.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
pip
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy-1.15.3.dist-info/LICENSE.txt
ADDED
|
@@ -0,0 +1,934 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright (c) 2001-2002 Enthought, Inc. 2003-2024, SciPy Developers.
|
| 2 |
+
All rights reserved.
|
| 3 |
+
|
| 4 |
+
Redistribution and use in source and binary forms, with or without
|
| 5 |
+
modification, are permitted provided that the following conditions
|
| 6 |
+
are met:
|
| 7 |
+
|
| 8 |
+
1. Redistributions of source code must retain the above copyright
|
| 9 |
+
notice, this list of conditions and the following disclaimer.
|
| 10 |
+
|
| 11 |
+
2. Redistributions in binary form must reproduce the above
|
| 12 |
+
copyright notice, this list of conditions and the following
|
| 13 |
+
disclaimer in the documentation and/or other materials provided
|
| 14 |
+
with the distribution.
|
| 15 |
+
|
| 16 |
+
3. Neither the name of the copyright holder nor the names of its
|
| 17 |
+
contributors may be used to endorse or promote products derived
|
| 18 |
+
from this software without specific prior written permission.
|
| 19 |
+
|
| 20 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 21 |
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 22 |
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| 23 |
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| 24 |
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| 25 |
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| 26 |
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| 27 |
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| 28 |
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 29 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 30 |
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 31 |
+
|
| 32 |
+
----
|
| 33 |
+
|
| 34 |
+
This binary distribution of SciPy can also bundle the following software
|
| 35 |
+
(depending on the build):
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
Name: OpenBLAS
|
| 39 |
+
Files: scipy.libs/libscipy_openblas*.so
|
| 40 |
+
Description: bundled as a dynamically linked library
|
| 41 |
+
Availability: https://github.com/OpenMathLib/OpenBLAS/
|
| 42 |
+
License: BSD-3-Clause-Attribution
|
| 43 |
+
Copyright (c) 2011-2014, The OpenBLAS Project
|
| 44 |
+
All rights reserved.
|
| 45 |
+
|
| 46 |
+
Redistribution and use in source and binary forms, with or without
|
| 47 |
+
modification, are permitted provided that the following conditions are
|
| 48 |
+
met:
|
| 49 |
+
|
| 50 |
+
1. Redistributions of source code must retain the above copyright
|
| 51 |
+
notice, this list of conditions and the following disclaimer.
|
| 52 |
+
|
| 53 |
+
2. Redistributions in binary form must reproduce the above copyright
|
| 54 |
+
notice, this list of conditions and the following disclaimer in
|
| 55 |
+
the documentation and/or other materials provided with the
|
| 56 |
+
distribution.
|
| 57 |
+
3. Neither the name of the OpenBLAS project nor the names of
|
| 58 |
+
its contributors may be used to endorse or promote products
|
| 59 |
+
derived from this software without specific prior written
|
| 60 |
+
permission.
|
| 61 |
+
|
| 62 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 63 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 64 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 65 |
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
| 66 |
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
| 67 |
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
| 68 |
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
| 69 |
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
| 70 |
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
| 71 |
+
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
Name: LAPACK
|
| 75 |
+
Files: scipy.libs/libscipy_openblas*.so
|
| 76 |
+
Description: bundled in OpenBLAS
|
| 77 |
+
Availability: https://github.com/OpenMathLib/OpenBLAS/
|
| 78 |
+
License: BSD-3-Clause-Attribution
|
| 79 |
+
Copyright (c) 1992-2013 The University of Tennessee and The University
|
| 80 |
+
of Tennessee Research Foundation. All rights
|
| 81 |
+
reserved.
|
| 82 |
+
Copyright (c) 2000-2013 The University of California Berkeley. All
|
| 83 |
+
rights reserved.
|
| 84 |
+
Copyright (c) 2006-2013 The University of Colorado Denver. All rights
|
| 85 |
+
reserved.
|
| 86 |
+
|
| 87 |
+
$COPYRIGHT$
|
| 88 |
+
|
| 89 |
+
Additional copyrights may follow
|
| 90 |
+
|
| 91 |
+
$HEADER$
|
| 92 |
+
|
| 93 |
+
Redistribution and use in source and binary forms, with or without
|
| 94 |
+
modification, are permitted provided that the following conditions are
|
| 95 |
+
met:
|
| 96 |
+
|
| 97 |
+
- Redistributions of source code must retain the above copyright
|
| 98 |
+
notice, this list of conditions and the following disclaimer.
|
| 99 |
+
|
| 100 |
+
- Redistributions in binary form must reproduce the above copyright
|
| 101 |
+
notice, this list of conditions and the following disclaimer listed
|
| 102 |
+
in this license in the documentation and/or other materials
|
| 103 |
+
provided with the distribution.
|
| 104 |
+
|
| 105 |
+
- Neither the name of the copyright holders nor the names of its
|
| 106 |
+
contributors may be used to endorse or promote products derived from
|
| 107 |
+
this software without specific prior written permission.
|
| 108 |
+
|
| 109 |
+
The copyright holders provide no reassurances that the source code
|
| 110 |
+
provided does not infringe any patent, copyright, or any other
|
| 111 |
+
intellectual property rights of third parties. The copyright holders
|
| 112 |
+
disclaim any liability to any recipient for claims brought against
|
| 113 |
+
recipient by any third party for infringement of that parties
|
| 114 |
+
intellectual property rights.
|
| 115 |
+
|
| 116 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 117 |
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 118 |
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| 119 |
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| 120 |
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| 121 |
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| 122 |
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| 123 |
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| 124 |
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 125 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 126 |
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
Name: GCC runtime library
|
| 130 |
+
Files: scipy.libs/libgfortran*.so
|
| 131 |
+
Description: dynamically linked to files compiled with gcc
|
| 132 |
+
Availability: https://gcc.gnu.org/git/?p=gcc.git;a=tree;f=libgfortran
|
| 133 |
+
License: GPL-3.0-with-GCC-exception
|
| 134 |
+
Copyright (C) 2002-2017 Free Software Foundation, Inc.
|
| 135 |
+
|
| 136 |
+
Libgfortran is free software; you can redistribute it and/or modify
|
| 137 |
+
it under the terms of the GNU General Public License as published by
|
| 138 |
+
the Free Software Foundation; either version 3, or (at your option)
|
| 139 |
+
any later version.
|
| 140 |
+
|
| 141 |
+
Libgfortran is distributed in the hope that it will be useful,
|
| 142 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 143 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 144 |
+
GNU General Public License for more details.
|
| 145 |
+
|
| 146 |
+
Under Section 7 of GPL version 3, you are granted additional
|
| 147 |
+
permissions described in the GCC Runtime Library Exception, version
|
| 148 |
+
3.1, as published by the Free Software Foundation.
|
| 149 |
+
|
| 150 |
+
You should have received a copy of the GNU General Public License and
|
| 151 |
+
a copy of the GCC Runtime Library Exception along with this program;
|
| 152 |
+
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
| 153 |
+
<http://www.gnu.org/licenses/>.
|
| 154 |
+
|
| 155 |
+
----
|
| 156 |
+
|
| 157 |
+
Full text of license texts referred to above follows (that they are
|
| 158 |
+
listed below does not necessarily imply the conditions apply to the
|
| 159 |
+
present binary release):
|
| 160 |
+
|
| 161 |
+
----
|
| 162 |
+
|
| 163 |
+
GCC RUNTIME LIBRARY EXCEPTION
|
| 164 |
+
|
| 165 |
+
Version 3.1, 31 March 2009
|
| 166 |
+
|
| 167 |
+
Copyright (C) 2009 Free Software Foundation, Inc. <http://fsf.org/>
|
| 168 |
+
|
| 169 |
+
Everyone is permitted to copy and distribute verbatim copies of this
|
| 170 |
+
license document, but changing it is not allowed.
|
| 171 |
+
|
| 172 |
+
This GCC Runtime Library Exception ("Exception") is an additional
|
| 173 |
+
permission under section 7 of the GNU General Public License, version
|
| 174 |
+
3 ("GPLv3"). It applies to a given file (the "Runtime Library") that
|
| 175 |
+
bears a notice placed by the copyright holder of the file stating that
|
| 176 |
+
the file is governed by GPLv3 along with this Exception.
|
| 177 |
+
|
| 178 |
+
When you use GCC to compile a program, GCC may combine portions of
|
| 179 |
+
certain GCC header files and runtime libraries with the compiled
|
| 180 |
+
program. The purpose of this Exception is to allow compilation of
|
| 181 |
+
non-GPL (including proprietary) programs to use, in this way, the
|
| 182 |
+
header files and runtime libraries covered by this Exception.
|
| 183 |
+
|
| 184 |
+
0. Definitions.
|
| 185 |
+
|
| 186 |
+
A file is an "Independent Module" if it either requires the Runtime
|
| 187 |
+
Library for execution after a Compilation Process, or makes use of an
|
| 188 |
+
interface provided by the Runtime Library, but is not otherwise based
|
| 189 |
+
on the Runtime Library.
|
| 190 |
+
|
| 191 |
+
"GCC" means a version of the GNU Compiler Collection, with or without
|
| 192 |
+
modifications, governed by version 3 (or a specified later version) of
|
| 193 |
+
the GNU General Public License (GPL) with the option of using any
|
| 194 |
+
subsequent versions published by the FSF.
|
| 195 |
+
|
| 196 |
+
"GPL-compatible Software" is software whose conditions of propagation,
|
| 197 |
+
modification and use would permit combination with GCC in accord with
|
| 198 |
+
the license of GCC.
|
| 199 |
+
|
| 200 |
+
"Target Code" refers to output from any compiler for a real or virtual
|
| 201 |
+
target processor architecture, in executable form or suitable for
|
| 202 |
+
input to an assembler, loader, linker and/or execution
|
| 203 |
+
phase. Notwithstanding that, Target Code does not include data in any
|
| 204 |
+
format that is used as a compiler intermediate representation, or used
|
| 205 |
+
for producing a compiler intermediate representation.
|
| 206 |
+
|
| 207 |
+
The "Compilation Process" transforms code entirely represented in
|
| 208 |
+
non-intermediate languages designed for human-written code, and/or in
|
| 209 |
+
Java Virtual Machine byte code, into Target Code. Thus, for example,
|
| 210 |
+
use of source code generators and preprocessors need not be considered
|
| 211 |
+
part of the Compilation Process, since the Compilation Process can be
|
| 212 |
+
understood as starting with the output of the generators or
|
| 213 |
+
preprocessors.
|
| 214 |
+
|
| 215 |
+
A Compilation Process is "Eligible" if it is done using GCC, alone or
|
| 216 |
+
with other GPL-compatible software, or if it is done without using any
|
| 217 |
+
work based on GCC. For example, using non-GPL-compatible Software to
|
| 218 |
+
optimize any GCC intermediate representations would not qualify as an
|
| 219 |
+
Eligible Compilation Process.
|
| 220 |
+
|
| 221 |
+
1. Grant of Additional Permission.
|
| 222 |
+
|
| 223 |
+
You have permission to propagate a work of Target Code formed by
|
| 224 |
+
combining the Runtime Library with Independent Modules, even if such
|
| 225 |
+
propagation would otherwise violate the terms of GPLv3, provided that
|
| 226 |
+
all Target Code was generated by Eligible Compilation Processes. You
|
| 227 |
+
may then convey such a combination under terms of your choice,
|
| 228 |
+
consistent with the licensing of the Independent Modules.
|
| 229 |
+
|
| 230 |
+
2. No Weakening of GCC Copyleft.
|
| 231 |
+
|
| 232 |
+
The availability of this Exception does not imply any general
|
| 233 |
+
presumption that third-party software is unaffected by the copyleft
|
| 234 |
+
requirements of the license of GCC.
|
| 235 |
+
|
| 236 |
+
----
|
| 237 |
+
|
| 238 |
+
GNU GENERAL PUBLIC LICENSE
|
| 239 |
+
Version 3, 29 June 2007
|
| 240 |
+
|
| 241 |
+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
| 242 |
+
Everyone is permitted to copy and distribute verbatim copies
|
| 243 |
+
of this license document, but changing it is not allowed.
|
| 244 |
+
|
| 245 |
+
Preamble
|
| 246 |
+
|
| 247 |
+
The GNU General Public License is a free, copyleft license for
|
| 248 |
+
software and other kinds of works.
|
| 249 |
+
|
| 250 |
+
The licenses for most software and other practical works are designed
|
| 251 |
+
to take away your freedom to share and change the works. By contrast,
|
| 252 |
+
the GNU General Public License is intended to guarantee your freedom to
|
| 253 |
+
share and change all versions of a program--to make sure it remains free
|
| 254 |
+
software for all its users. We, the Free Software Foundation, use the
|
| 255 |
+
GNU General Public License for most of our software; it applies also to
|
| 256 |
+
any other work released this way by its authors. You can apply it to
|
| 257 |
+
your programs, too.
|
| 258 |
+
|
| 259 |
+
When we speak of free software, we are referring to freedom, not
|
| 260 |
+
price. Our General Public Licenses are designed to make sure that you
|
| 261 |
+
have the freedom to distribute copies of free software (and charge for
|
| 262 |
+
them if you wish), that you receive source code or can get it if you
|
| 263 |
+
want it, that you can change the software or use pieces of it in new
|
| 264 |
+
free programs, and that you know you can do these things.
|
| 265 |
+
|
| 266 |
+
To protect your rights, we need to prevent others from denying you
|
| 267 |
+
these rights or asking you to surrender the rights. Therefore, you have
|
| 268 |
+
certain responsibilities if you distribute copies of the software, or if
|
| 269 |
+
you modify it: responsibilities to respect the freedom of others.
|
| 270 |
+
|
| 271 |
+
For example, if you distribute copies of such a program, whether
|
| 272 |
+
gratis or for a fee, you must pass on to the recipients the same
|
| 273 |
+
freedoms that you received. You must make sure that they, too, receive
|
| 274 |
+
or can get the source code. And you must show them these terms so they
|
| 275 |
+
know their rights.
|
| 276 |
+
|
| 277 |
+
Developers that use the GNU GPL protect your rights with two steps:
|
| 278 |
+
(1) assert copyright on the software, and (2) offer you this License
|
| 279 |
+
giving you legal permission to copy, distribute and/or modify it.
|
| 280 |
+
|
| 281 |
+
For the developers' and authors' protection, the GPL clearly explains
|
| 282 |
+
that there is no warranty for this free software. For both users' and
|
| 283 |
+
authors' sake, the GPL requires that modified versions be marked as
|
| 284 |
+
changed, so that their problems will not be attributed erroneously to
|
| 285 |
+
authors of previous versions.
|
| 286 |
+
|
| 287 |
+
Some devices are designed to deny users access to install or run
|
| 288 |
+
modified versions of the software inside them, although the manufacturer
|
| 289 |
+
can do so. This is fundamentally incompatible with the aim of
|
| 290 |
+
protecting users' freedom to change the software. The systematic
|
| 291 |
+
pattern of such abuse occurs in the area of products for individuals to
|
| 292 |
+
use, which is precisely where it is most unacceptable. Therefore, we
|
| 293 |
+
have designed this version of the GPL to prohibit the practice for those
|
| 294 |
+
products. If such problems arise substantially in other domains, we
|
| 295 |
+
stand ready to extend this provision to those domains in future versions
|
| 296 |
+
of the GPL, as needed to protect the freedom of users.
|
| 297 |
+
|
| 298 |
+
Finally, every program is threatened constantly by software patents.
|
| 299 |
+
States should not allow patents to restrict development and use of
|
| 300 |
+
software on general-purpose computers, but in those that do, we wish to
|
| 301 |
+
avoid the special danger that patents applied to a free program could
|
| 302 |
+
make it effectively proprietary. To prevent this, the GPL assures that
|
| 303 |
+
patents cannot be used to render the program non-free.
|
| 304 |
+
|
| 305 |
+
The precise terms and conditions for copying, distribution and
|
| 306 |
+
modification follow.
|
| 307 |
+
|
| 308 |
+
TERMS AND CONDITIONS
|
| 309 |
+
|
| 310 |
+
0. Definitions.
|
| 311 |
+
|
| 312 |
+
"This License" refers to version 3 of the GNU General Public License.
|
| 313 |
+
|
| 314 |
+
"Copyright" also means copyright-like laws that apply to other kinds of
|
| 315 |
+
works, such as semiconductor masks.
|
| 316 |
+
|
| 317 |
+
"The Program" refers to any copyrightable work licensed under this
|
| 318 |
+
License. Each licensee is addressed as "you". "Licensees" and
|
| 319 |
+
"recipients" may be individuals or organizations.
|
| 320 |
+
|
| 321 |
+
To "modify" a work means to copy from or adapt all or part of the work
|
| 322 |
+
in a fashion requiring copyright permission, other than the making of an
|
| 323 |
+
exact copy. The resulting work is called a "modified version" of the
|
| 324 |
+
earlier work or a work "based on" the earlier work.
|
| 325 |
+
|
| 326 |
+
A "covered work" means either the unmodified Program or a work based
|
| 327 |
+
on the Program.
|
| 328 |
+
|
| 329 |
+
To "propagate" a work means to do anything with it that, without
|
| 330 |
+
permission, would make you directly or secondarily liable for
|
| 331 |
+
infringement under applicable copyright law, except executing it on a
|
| 332 |
+
computer or modifying a private copy. Propagation includes copying,
|
| 333 |
+
distribution (with or without modification), making available to the
|
| 334 |
+
public, and in some countries other activities as well.
|
| 335 |
+
|
| 336 |
+
To "convey" a work means any kind of propagation that enables other
|
| 337 |
+
parties to make or receive copies. Mere interaction with a user through
|
| 338 |
+
a computer network, with no transfer of a copy, is not conveying.
|
| 339 |
+
|
| 340 |
+
An interactive user interface displays "Appropriate Legal Notices"
|
| 341 |
+
to the extent that it includes a convenient and prominently visible
|
| 342 |
+
feature that (1) displays an appropriate copyright notice, and (2)
|
| 343 |
+
tells the user that there is no warranty for the work (except to the
|
| 344 |
+
extent that warranties are provided), that licensees may convey the
|
| 345 |
+
work under this License, and how to view a copy of this License. If
|
| 346 |
+
the interface presents a list of user commands or options, such as a
|
| 347 |
+
menu, a prominent item in the list meets this criterion.
|
| 348 |
+
|
| 349 |
+
1. Source Code.
|
| 350 |
+
|
| 351 |
+
The "source code" for a work means the preferred form of the work
|
| 352 |
+
for making modifications to it. "Object code" means any non-source
|
| 353 |
+
form of a work.
|
| 354 |
+
|
| 355 |
+
A "Standard Interface" means an interface that either is an official
|
| 356 |
+
standard defined by a recognized standards body, or, in the case of
|
| 357 |
+
interfaces specified for a particular programming language, one that
|
| 358 |
+
is widely used among developers working in that language.
|
| 359 |
+
|
| 360 |
+
The "System Libraries" of an executable work include anything, other
|
| 361 |
+
than the work as a whole, that (a) is included in the normal form of
|
| 362 |
+
packaging a Major Component, but which is not part of that Major
|
| 363 |
+
Component, and (b) serves only to enable use of the work with that
|
| 364 |
+
Major Component, or to implement a Standard Interface for which an
|
| 365 |
+
implementation is available to the public in source code form. A
|
| 366 |
+
"Major Component", in this context, means a major essential component
|
| 367 |
+
(kernel, window system, and so on) of the specific operating system
|
| 368 |
+
(if any) on which the executable work runs, or a compiler used to
|
| 369 |
+
produce the work, or an object code interpreter used to run it.
|
| 370 |
+
|
| 371 |
+
The "Corresponding Source" for a work in object code form means all
|
| 372 |
+
the source code needed to generate, install, and (for an executable
|
| 373 |
+
work) run the object code and to modify the work, including scripts to
|
| 374 |
+
control those activities. However, it does not include the work's
|
| 375 |
+
System Libraries, or general-purpose tools or generally available free
|
| 376 |
+
programs which are used unmodified in performing those activities but
|
| 377 |
+
which are not part of the work. For example, Corresponding Source
|
| 378 |
+
includes interface definition files associated with source files for
|
| 379 |
+
the work, and the source code for shared libraries and dynamically
|
| 380 |
+
linked subprograms that the work is specifically designed to require,
|
| 381 |
+
such as by intimate data communication or control flow between those
|
| 382 |
+
subprograms and other parts of the work.
|
| 383 |
+
|
| 384 |
+
The Corresponding Source need not include anything that users
|
| 385 |
+
can regenerate automatically from other parts of the Corresponding
|
| 386 |
+
Source.
|
| 387 |
+
|
| 388 |
+
The Corresponding Source for a work in source code form is that
|
| 389 |
+
same work.
|
| 390 |
+
|
| 391 |
+
2. Basic Permissions.
|
| 392 |
+
|
| 393 |
+
All rights granted under this License are granted for the term of
|
| 394 |
+
copyright on the Program, and are irrevocable provided the stated
|
| 395 |
+
conditions are met. This License explicitly affirms your unlimited
|
| 396 |
+
permission to run the unmodified Program. The output from running a
|
| 397 |
+
covered work is covered by this License only if the output, given its
|
| 398 |
+
content, constitutes a covered work. This License acknowledges your
|
| 399 |
+
rights of fair use or other equivalent, as provided by copyright law.
|
| 400 |
+
|
| 401 |
+
You may make, run and propagate covered works that you do not
|
| 402 |
+
convey, without conditions so long as your license otherwise remains
|
| 403 |
+
in force. You may convey covered works to others for the sole purpose
|
| 404 |
+
of having them make modifications exclusively for you, or provide you
|
| 405 |
+
with facilities for running those works, provided that you comply with
|
| 406 |
+
the terms of this License in conveying all material for which you do
|
| 407 |
+
not control copyright. Those thus making or running the covered works
|
| 408 |
+
for you must do so exclusively on your behalf, under your direction
|
| 409 |
+
and control, on terms that prohibit them from making any copies of
|
| 410 |
+
your copyrighted material outside their relationship with you.
|
| 411 |
+
|
| 412 |
+
Conveying under any other circumstances is permitted solely under
|
| 413 |
+
the conditions stated below. Sublicensing is not allowed; section 10
|
| 414 |
+
makes it unnecessary.
|
| 415 |
+
|
| 416 |
+
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
| 417 |
+
|
| 418 |
+
No covered work shall be deemed part of an effective technological
|
| 419 |
+
measure under any applicable law fulfilling obligations under article
|
| 420 |
+
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
| 421 |
+
similar laws prohibiting or restricting circumvention of such
|
| 422 |
+
measures.
|
| 423 |
+
|
| 424 |
+
When you convey a covered work, you waive any legal power to forbid
|
| 425 |
+
circumvention of technological measures to the extent such circumvention
|
| 426 |
+
is effected by exercising rights under this License with respect to
|
| 427 |
+
the covered work, and you disclaim any intention to limit operation or
|
| 428 |
+
modification of the work as a means of enforcing, against the work's
|
| 429 |
+
users, your or third parties' legal rights to forbid circumvention of
|
| 430 |
+
technological measures.
|
| 431 |
+
|
| 432 |
+
4. Conveying Verbatim Copies.
|
| 433 |
+
|
| 434 |
+
You may convey verbatim copies of the Program's source code as you
|
| 435 |
+
receive it, in any medium, provided that you conspicuously and
|
| 436 |
+
appropriately publish on each copy an appropriate copyright notice;
|
| 437 |
+
keep intact all notices stating that this License and any
|
| 438 |
+
non-permissive terms added in accord with section 7 apply to the code;
|
| 439 |
+
keep intact all notices of the absence of any warranty; and give all
|
| 440 |
+
recipients a copy of this License along with the Program.
|
| 441 |
+
|
| 442 |
+
You may charge any price or no price for each copy that you convey,
|
| 443 |
+
and you may offer support or warranty protection for a fee.
|
| 444 |
+
|
| 445 |
+
5. Conveying Modified Source Versions.
|
| 446 |
+
|
| 447 |
+
You may convey a work based on the Program, or the modifications to
|
| 448 |
+
produce it from the Program, in the form of source code under the
|
| 449 |
+
terms of section 4, provided that you also meet all of these conditions:
|
| 450 |
+
|
| 451 |
+
a) The work must carry prominent notices stating that you modified
|
| 452 |
+
it, and giving a relevant date.
|
| 453 |
+
|
| 454 |
+
b) The work must carry prominent notices stating that it is
|
| 455 |
+
released under this License and any conditions added under section
|
| 456 |
+
7. This requirement modifies the requirement in section 4 to
|
| 457 |
+
"keep intact all notices".
|
| 458 |
+
|
| 459 |
+
c) You must license the entire work, as a whole, under this
|
| 460 |
+
License to anyone who comes into possession of a copy. This
|
| 461 |
+
License will therefore apply, along with any applicable section 7
|
| 462 |
+
additional terms, to the whole of the work, and all its parts,
|
| 463 |
+
regardless of how they are packaged. This License gives no
|
| 464 |
+
permission to license the work in any other way, but it does not
|
| 465 |
+
invalidate such permission if you have separately received it.
|
| 466 |
+
|
| 467 |
+
d) If the work has interactive user interfaces, each must display
|
| 468 |
+
Appropriate Legal Notices; however, if the Program has interactive
|
| 469 |
+
interfaces that do not display Appropriate Legal Notices, your
|
| 470 |
+
work need not make them do so.
|
| 471 |
+
|
| 472 |
+
A compilation of a covered work with other separate and independent
|
| 473 |
+
works, which are not by their nature extensions of the covered work,
|
| 474 |
+
and which are not combined with it such as to form a larger program,
|
| 475 |
+
in or on a volume of a storage or distribution medium, is called an
|
| 476 |
+
"aggregate" if the compilation and its resulting copyright are not
|
| 477 |
+
used to limit the access or legal rights of the compilation's users
|
| 478 |
+
beyond what the individual works permit. Inclusion of a covered work
|
| 479 |
+
in an aggregate does not cause this License to apply to the other
|
| 480 |
+
parts of the aggregate.
|
| 481 |
+
|
| 482 |
+
6. Conveying Non-Source Forms.
|
| 483 |
+
|
| 484 |
+
You may convey a covered work in object code form under the terms
|
| 485 |
+
of sections 4 and 5, provided that you also convey the
|
| 486 |
+
machine-readable Corresponding Source under the terms of this License,
|
| 487 |
+
in one of these ways:
|
| 488 |
+
|
| 489 |
+
a) Convey the object code in, or embodied in, a physical product
|
| 490 |
+
(including a physical distribution medium), accompanied by the
|
| 491 |
+
Corresponding Source fixed on a durable physical medium
|
| 492 |
+
customarily used for software interchange.
|
| 493 |
+
|
| 494 |
+
b) Convey the object code in, or embodied in, a physical product
|
| 495 |
+
(including a physical distribution medium), accompanied by a
|
| 496 |
+
written offer, valid for at least three years and valid for as
|
| 497 |
+
long as you offer spare parts or customer support for that product
|
| 498 |
+
model, to give anyone who possesses the object code either (1) a
|
| 499 |
+
copy of the Corresponding Source for all the software in the
|
| 500 |
+
product that is covered by this License, on a durable physical
|
| 501 |
+
medium customarily used for software interchange, for a price no
|
| 502 |
+
more than your reasonable cost of physically performing this
|
| 503 |
+
conveying of source, or (2) access to copy the
|
| 504 |
+
Corresponding Source from a network server at no charge.
|
| 505 |
+
|
| 506 |
+
c) Convey individual copies of the object code with a copy of the
|
| 507 |
+
written offer to provide the Corresponding Source. This
|
| 508 |
+
alternative is allowed only occasionally and noncommercially, and
|
| 509 |
+
only if you received the object code with such an offer, in accord
|
| 510 |
+
with subsection 6b.
|
| 511 |
+
|
| 512 |
+
d) Convey the object code by offering access from a designated
|
| 513 |
+
place (gratis or for a charge), and offer equivalent access to the
|
| 514 |
+
Corresponding Source in the same way through the same place at no
|
| 515 |
+
further charge. You need not require recipients to copy the
|
| 516 |
+
Corresponding Source along with the object code. If the place to
|
| 517 |
+
copy the object code is a network server, the Corresponding Source
|
| 518 |
+
may be on a different server (operated by you or a third party)
|
| 519 |
+
that supports equivalent copying facilities, provided you maintain
|
| 520 |
+
clear directions next to the object code saying where to find the
|
| 521 |
+
Corresponding Source. Regardless of what server hosts the
|
| 522 |
+
Corresponding Source, you remain obligated to ensure that it is
|
| 523 |
+
available for as long as needed to satisfy these requirements.
|
| 524 |
+
|
| 525 |
+
e) Convey the object code using peer-to-peer transmission, provided
|
| 526 |
+
you inform other peers where the object code and Corresponding
|
| 527 |
+
Source of the work are being offered to the general public at no
|
| 528 |
+
charge under subsection 6d.
|
| 529 |
+
|
| 530 |
+
A separable portion of the object code, whose source code is excluded
|
| 531 |
+
from the Corresponding Source as a System Library, need not be
|
| 532 |
+
included in conveying the object code work.
|
| 533 |
+
|
| 534 |
+
A "User Product" is either (1) a "consumer product", which means any
|
| 535 |
+
tangible personal property which is normally used for personal, family,
|
| 536 |
+
or household purposes, or (2) anything designed or sold for incorporation
|
| 537 |
+
into a dwelling. In determining whether a product is a consumer product,
|
| 538 |
+
doubtful cases shall be resolved in favor of coverage. For a particular
|
| 539 |
+
product received by a particular user, "normally used" refers to a
|
| 540 |
+
typical or common use of that class of product, regardless of the status
|
| 541 |
+
of the particular user or of the way in which the particular user
|
| 542 |
+
actually uses, or expects or is expected to use, the product. A product
|
| 543 |
+
is a consumer product regardless of whether the product has substantial
|
| 544 |
+
commercial, industrial or non-consumer uses, unless such uses represent
|
| 545 |
+
the only significant mode of use of the product.
|
| 546 |
+
|
| 547 |
+
"Installation Information" for a User Product means any methods,
|
| 548 |
+
procedures, authorization keys, or other information required to install
|
| 549 |
+
and execute modified versions of a covered work in that User Product from
|
| 550 |
+
a modified version of its Corresponding Source. The information must
|
| 551 |
+
suffice to ensure that the continued functioning of the modified object
|
| 552 |
+
code is in no case prevented or interfered with solely because
|
| 553 |
+
modification has been made.
|
| 554 |
+
|
| 555 |
+
If you convey an object code work under this section in, or with, or
|
| 556 |
+
specifically for use in, a User Product, and the conveying occurs as
|
| 557 |
+
part of a transaction in which the right of possession and use of the
|
| 558 |
+
User Product is transferred to the recipient in perpetuity or for a
|
| 559 |
+
fixed term (regardless of how the transaction is characterized), the
|
| 560 |
+
Corresponding Source conveyed under this section must be accompanied
|
| 561 |
+
by the Installation Information. But this requirement does not apply
|
| 562 |
+
if neither you nor any third party retains the ability to install
|
| 563 |
+
modified object code on the User Product (for example, the work has
|
| 564 |
+
been installed in ROM).
|
| 565 |
+
|
| 566 |
+
The requirement to provide Installation Information does not include a
|
| 567 |
+
requirement to continue to provide support service, warranty, or updates
|
| 568 |
+
for a work that has been modified or installed by the recipient, or for
|
| 569 |
+
the User Product in which it has been modified or installed. Access to a
|
| 570 |
+
network may be denied when the modification itself materially and
|
| 571 |
+
adversely affects the operation of the network or violates the rules and
|
| 572 |
+
protocols for communication across the network.
|
| 573 |
+
|
| 574 |
+
Corresponding Source conveyed, and Installation Information provided,
|
| 575 |
+
in accord with this section must be in a format that is publicly
|
| 576 |
+
documented (and with an implementation available to the public in
|
| 577 |
+
source code form), and must require no special password or key for
|
| 578 |
+
unpacking, reading or copying.
|
| 579 |
+
|
| 580 |
+
7. Additional Terms.
|
| 581 |
+
|
| 582 |
+
"Additional permissions" are terms that supplement the terms of this
|
| 583 |
+
License by making exceptions from one or more of its conditions.
|
| 584 |
+
Additional permissions that are applicable to the entire Program shall
|
| 585 |
+
be treated as though they were included in this License, to the extent
|
| 586 |
+
that they are valid under applicable law. If additional permissions
|
| 587 |
+
apply only to part of the Program, that part may be used separately
|
| 588 |
+
under those permissions, but the entire Program remains governed by
|
| 589 |
+
this License without regard to the additional permissions.
|
| 590 |
+
|
| 591 |
+
When you convey a copy of a covered work, you may at your option
|
| 592 |
+
remove any additional permissions from that copy, or from any part of
|
| 593 |
+
it. (Additional permissions may be written to require their own
|
| 594 |
+
removal in certain cases when you modify the work.) You may place
|
| 595 |
+
additional permissions on material, added by you to a covered work,
|
| 596 |
+
for which you have or can give appropriate copyright permission.
|
| 597 |
+
|
| 598 |
+
Notwithstanding any other provision of this License, for material you
|
| 599 |
+
add to a covered work, you may (if authorized by the copyright holders of
|
| 600 |
+
that material) supplement the terms of this License with terms:
|
| 601 |
+
|
| 602 |
+
a) Disclaiming warranty or limiting liability differently from the
|
| 603 |
+
terms of sections 15 and 16 of this License; or
|
| 604 |
+
|
| 605 |
+
b) Requiring preservation of specified reasonable legal notices or
|
| 606 |
+
author attributions in that material or in the Appropriate Legal
|
| 607 |
+
Notices displayed by works containing it; or
|
| 608 |
+
|
| 609 |
+
c) Prohibiting misrepresentation of the origin of that material, or
|
| 610 |
+
requiring that modified versions of such material be marked in
|
| 611 |
+
reasonable ways as different from the original version; or
|
| 612 |
+
|
| 613 |
+
d) Limiting the use for publicity purposes of names of licensors or
|
| 614 |
+
authors of the material; or
|
| 615 |
+
|
| 616 |
+
e) Declining to grant rights under trademark law for use of some
|
| 617 |
+
trade names, trademarks, or service marks; or
|
| 618 |
+
|
| 619 |
+
f) Requiring indemnification of licensors and authors of that
|
| 620 |
+
material by anyone who conveys the material (or modified versions of
|
| 621 |
+
it) with contractual assumptions of liability to the recipient, for
|
| 622 |
+
any liability that these contractual assumptions directly impose on
|
| 623 |
+
those licensors and authors.
|
| 624 |
+
|
| 625 |
+
All other non-permissive additional terms are considered "further
|
| 626 |
+
restrictions" within the meaning of section 10. If the Program as you
|
| 627 |
+
received it, or any part of it, contains a notice stating that it is
|
| 628 |
+
governed by this License along with a term that is a further
|
| 629 |
+
restriction, you may remove that term. If a license document contains
|
| 630 |
+
a further restriction but permits relicensing or conveying under this
|
| 631 |
+
License, you may add to a covered work material governed by the terms
|
| 632 |
+
of that license document, provided that the further restriction does
|
| 633 |
+
not survive such relicensing or conveying.
|
| 634 |
+
|
| 635 |
+
If you add terms to a covered work in accord with this section, you
|
| 636 |
+
must place, in the relevant source files, a statement of the
|
| 637 |
+
additional terms that apply to those files, or a notice indicating
|
| 638 |
+
where to find the applicable terms.
|
| 639 |
+
|
| 640 |
+
Additional terms, permissive or non-permissive, may be stated in the
|
| 641 |
+
form of a separately written license, or stated as exceptions;
|
| 642 |
+
the above requirements apply either way.
|
| 643 |
+
|
| 644 |
+
8. Termination.
|
| 645 |
+
|
| 646 |
+
You may not propagate or modify a covered work except as expressly
|
| 647 |
+
provided under this License. Any attempt otherwise to propagate or
|
| 648 |
+
modify it is void, and will automatically terminate your rights under
|
| 649 |
+
this License (including any patent licenses granted under the third
|
| 650 |
+
paragraph of section 11).
|
| 651 |
+
|
| 652 |
+
However, if you cease all violation of this License, then your
|
| 653 |
+
license from a particular copyright holder is reinstated (a)
|
| 654 |
+
provisionally, unless and until the copyright holder explicitly and
|
| 655 |
+
finally terminates your license, and (b) permanently, if the copyright
|
| 656 |
+
holder fails to notify you of the violation by some reasonable means
|
| 657 |
+
prior to 60 days after the cessation.
|
| 658 |
+
|
| 659 |
+
Moreover, your license from a particular copyright holder is
|
| 660 |
+
reinstated permanently if the copyright holder notifies you of the
|
| 661 |
+
violation by some reasonable means, this is the first time you have
|
| 662 |
+
received notice of violation of this License (for any work) from that
|
| 663 |
+
copyright holder, and you cure the violation prior to 30 days after
|
| 664 |
+
your receipt of the notice.
|
| 665 |
+
|
| 666 |
+
Termination of your rights under this section does not terminate the
|
| 667 |
+
licenses of parties who have received copies or rights from you under
|
| 668 |
+
this License. If your rights have been terminated and not permanently
|
| 669 |
+
reinstated, you do not qualify to receive new licenses for the same
|
| 670 |
+
material under section 10.
|
| 671 |
+
|
| 672 |
+
9. Acceptance Not Required for Having Copies.
|
| 673 |
+
|
| 674 |
+
You are not required to accept this License in order to receive or
|
| 675 |
+
run a copy of the Program. Ancillary propagation of a covered work
|
| 676 |
+
occurring solely as a consequence of using peer-to-peer transmission
|
| 677 |
+
to receive a copy likewise does not require acceptance. However,
|
| 678 |
+
nothing other than this License grants you permission to propagate or
|
| 679 |
+
modify any covered work. These actions infringe copyright if you do
|
| 680 |
+
not accept this License. Therefore, by modifying or propagating a
|
| 681 |
+
covered work, you indicate your acceptance of this License to do so.
|
| 682 |
+
|
| 683 |
+
10. Automatic Licensing of Downstream Recipients.
|
| 684 |
+
|
| 685 |
+
Each time you convey a covered work, the recipient automatically
|
| 686 |
+
receives a license from the original licensors, to run, modify and
|
| 687 |
+
propagate that work, subject to this License. You are not responsible
|
| 688 |
+
for enforcing compliance by third parties with this License.
|
| 689 |
+
|
| 690 |
+
An "entity transaction" is a transaction transferring control of an
|
| 691 |
+
organization, or substantially all assets of one, or subdividing an
|
| 692 |
+
organization, or merging organizations. If propagation of a covered
|
| 693 |
+
work results from an entity transaction, each party to that
|
| 694 |
+
transaction who receives a copy of the work also receives whatever
|
| 695 |
+
licenses to the work the party's predecessor in interest had or could
|
| 696 |
+
give under the previous paragraph, plus a right to possession of the
|
| 697 |
+
Corresponding Source of the work from the predecessor in interest, if
|
| 698 |
+
the predecessor has it or can get it with reasonable efforts.
|
| 699 |
+
|
| 700 |
+
You may not impose any further restrictions on the exercise of the
|
| 701 |
+
rights granted or affirmed under this License. For example, you may
|
| 702 |
+
not impose a license fee, royalty, or other charge for exercise of
|
| 703 |
+
rights granted under this License, and you may not initiate litigation
|
| 704 |
+
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
| 705 |
+
any patent claim is infringed by making, using, selling, offering for
|
| 706 |
+
sale, or importing the Program or any portion of it.
|
| 707 |
+
|
| 708 |
+
11. Patents.
|
| 709 |
+
|
| 710 |
+
A "contributor" is a copyright holder who authorizes use under this
|
| 711 |
+
License of the Program or a work on which the Program is based. The
|
| 712 |
+
work thus licensed is called the contributor's "contributor version".
|
| 713 |
+
|
| 714 |
+
A contributor's "essential patent claims" are all patent claims
|
| 715 |
+
owned or controlled by the contributor, whether already acquired or
|
| 716 |
+
hereafter acquired, that would be infringed by some manner, permitted
|
| 717 |
+
by this License, of making, using, or selling its contributor version,
|
| 718 |
+
but do not include claims that would be infringed only as a
|
| 719 |
+
consequence of further modification of the contributor version. For
|
| 720 |
+
purposes of this definition, "control" includes the right to grant
|
| 721 |
+
patent sublicenses in a manner consistent with the requirements of
|
| 722 |
+
this License.
|
| 723 |
+
|
| 724 |
+
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
| 725 |
+
patent license under the contributor's essential patent claims, to
|
| 726 |
+
make, use, sell, offer for sale, import and otherwise run, modify and
|
| 727 |
+
propagate the contents of its contributor version.
|
| 728 |
+
|
| 729 |
+
In the following three paragraphs, a "patent license" is any express
|
| 730 |
+
agreement or commitment, however denominated, not to enforce a patent
|
| 731 |
+
(such as an express permission to practice a patent or covenant not to
|
| 732 |
+
sue for patent infringement). To "grant" such a patent license to a
|
| 733 |
+
party means to make such an agreement or commitment not to enforce a
|
| 734 |
+
patent against the party.
|
| 735 |
+
|
| 736 |
+
If you convey a covered work, knowingly relying on a patent license,
|
| 737 |
+
and the Corresponding Source of the work is not available for anyone
|
| 738 |
+
to copy, free of charge and under the terms of this License, through a
|
| 739 |
+
publicly available network server or other readily accessible means,
|
| 740 |
+
then you must either (1) cause the Corresponding Source to be so
|
| 741 |
+
available, or (2) arrange to deprive yourself of the benefit of the
|
| 742 |
+
patent license for this particular work, or (3) arrange, in a manner
|
| 743 |
+
consistent with the requirements of this License, to extend the patent
|
| 744 |
+
license to downstream recipients. "Knowingly relying" means you have
|
| 745 |
+
actual knowledge that, but for the patent license, your conveying the
|
| 746 |
+
covered work in a country, or your recipient's use of the covered work
|
| 747 |
+
in a country, would infringe one or more identifiable patents in that
|
| 748 |
+
country that you have reason to believe are valid.
|
| 749 |
+
|
| 750 |
+
If, pursuant to or in connection with a single transaction or
|
| 751 |
+
arrangement, you convey, or propagate by procuring conveyance of, a
|
| 752 |
+
covered work, and grant a patent license to some of the parties
|
| 753 |
+
receiving the covered work authorizing them to use, propagate, modify
|
| 754 |
+
or convey a specific copy of the covered work, then the patent license
|
| 755 |
+
you grant is automatically extended to all recipients of the covered
|
| 756 |
+
work and works based on it.
|
| 757 |
+
|
| 758 |
+
A patent license is "discriminatory" if it does not include within
|
| 759 |
+
the scope of its coverage, prohibits the exercise of, or is
|
| 760 |
+
conditioned on the non-exercise of one or more of the rights that are
|
| 761 |
+
specifically granted under this License. You may not convey a covered
|
| 762 |
+
work if you are a party to an arrangement with a third party that is
|
| 763 |
+
in the business of distributing software, under which you make payment
|
| 764 |
+
to the third party based on the extent of your activity of conveying
|
| 765 |
+
the work, and under which the third party grants, to any of the
|
| 766 |
+
parties who would receive the covered work from you, a discriminatory
|
| 767 |
+
patent license (a) in connection with copies of the covered work
|
| 768 |
+
conveyed by you (or copies made from those copies), or (b) primarily
|
| 769 |
+
for and in connection with specific products or compilations that
|
| 770 |
+
contain the covered work, unless you entered into that arrangement,
|
| 771 |
+
or that patent license was granted, prior to 28 March 2007.
|
| 772 |
+
|
| 773 |
+
Nothing in this License shall be construed as excluding or limiting
|
| 774 |
+
any implied license or other defenses to infringement that may
|
| 775 |
+
otherwise be available to you under applicable patent law.
|
| 776 |
+
|
| 777 |
+
12. No Surrender of Others' Freedom.
|
| 778 |
+
|
| 779 |
+
If conditions are imposed on you (whether by court order, agreement or
|
| 780 |
+
otherwise) that contradict the conditions of this License, they do not
|
| 781 |
+
excuse you from the conditions of this License. If you cannot convey a
|
| 782 |
+
covered work so as to satisfy simultaneously your obligations under this
|
| 783 |
+
License and any other pertinent obligations, then as a consequence you may
|
| 784 |
+
not convey it at all. For example, if you agree to terms that obligate you
|
| 785 |
+
to collect a royalty for further conveying from those to whom you convey
|
| 786 |
+
the Program, the only way you could satisfy both those terms and this
|
| 787 |
+
License would be to refrain entirely from conveying the Program.
|
| 788 |
+
|
| 789 |
+
13. Use with the GNU Affero General Public License.
|
| 790 |
+
|
| 791 |
+
Notwithstanding any other provision of this License, you have
|
| 792 |
+
permission to link or combine any covered work with a work licensed
|
| 793 |
+
under version 3 of the GNU Affero General Public License into a single
|
| 794 |
+
combined work, and to convey the resulting work. The terms of this
|
| 795 |
+
License will continue to apply to the part which is the covered work,
|
| 796 |
+
but the special requirements of the GNU Affero General Public License,
|
| 797 |
+
section 13, concerning interaction through a network will apply to the
|
| 798 |
+
combination as such.
|
| 799 |
+
|
| 800 |
+
14. Revised Versions of this License.
|
| 801 |
+
|
| 802 |
+
The Free Software Foundation may publish revised and/or new versions of
|
| 803 |
+
the GNU General Public License from time to time. Such new versions will
|
| 804 |
+
be similar in spirit to the present version, but may differ in detail to
|
| 805 |
+
address new problems or concerns.
|
| 806 |
+
|
| 807 |
+
Each version is given a distinguishing version number. If the
|
| 808 |
+
Program specifies that a certain numbered version of the GNU General
|
| 809 |
+
Public License "or any later version" applies to it, you have the
|
| 810 |
+
option of following the terms and conditions either of that numbered
|
| 811 |
+
version or of any later version published by the Free Software
|
| 812 |
+
Foundation. If the Program does not specify a version number of the
|
| 813 |
+
GNU General Public License, you may choose any version ever published
|
| 814 |
+
by the Free Software Foundation.
|
| 815 |
+
|
| 816 |
+
If the Program specifies that a proxy can decide which future
|
| 817 |
+
versions of the GNU General Public License can be used, that proxy's
|
| 818 |
+
public statement of acceptance of a version permanently authorizes you
|
| 819 |
+
to choose that version for the Program.
|
| 820 |
+
|
| 821 |
+
Later license versions may give you additional or different
|
| 822 |
+
permissions. However, no additional obligations are imposed on any
|
| 823 |
+
author or copyright holder as a result of your choosing to follow a
|
| 824 |
+
later version.
|
| 825 |
+
|
| 826 |
+
15. Disclaimer of Warranty.
|
| 827 |
+
|
| 828 |
+
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
| 829 |
+
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
| 830 |
+
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
| 831 |
+
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
| 832 |
+
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
| 833 |
+
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
| 834 |
+
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
| 835 |
+
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
| 836 |
+
|
| 837 |
+
16. Limitation of Liability.
|
| 838 |
+
|
| 839 |
+
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
| 840 |
+
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
| 841 |
+
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
| 842 |
+
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
| 843 |
+
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
| 844 |
+
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
| 845 |
+
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
| 846 |
+
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
| 847 |
+
SUCH DAMAGES.
|
| 848 |
+
|
| 849 |
+
17. Interpretation of Sections 15 and 16.
|
| 850 |
+
|
| 851 |
+
If the disclaimer of warranty and limitation of liability provided
|
| 852 |
+
above cannot be given local legal effect according to their terms,
|
| 853 |
+
reviewing courts shall apply local law that most closely approximates
|
| 854 |
+
an absolute waiver of all civil liability in connection with the
|
| 855 |
+
Program, unless a warranty or assumption of liability accompanies a
|
| 856 |
+
copy of the Program in return for a fee.
|
| 857 |
+
|
| 858 |
+
END OF TERMS AND CONDITIONS
|
| 859 |
+
|
| 860 |
+
How to Apply These Terms to Your New Programs
|
| 861 |
+
|
| 862 |
+
If you develop a new program, and you want it to be of the greatest
|
| 863 |
+
possible use to the public, the best way to achieve this is to make it
|
| 864 |
+
free software which everyone can redistribute and change under these terms.
|
| 865 |
+
|
| 866 |
+
To do so, attach the following notices to the program. It is safest
|
| 867 |
+
to attach them to the start of each source file to most effectively
|
| 868 |
+
state the exclusion of warranty; and each file should have at least
|
| 869 |
+
the "copyright" line and a pointer to where the full notice is found.
|
| 870 |
+
|
| 871 |
+
<one line to give the program's name and a brief idea of what it does.>
|
| 872 |
+
Copyright (C) <year> <name of author>
|
| 873 |
+
|
| 874 |
+
This program is free software: you can redistribute it and/or modify
|
| 875 |
+
it under the terms of the GNU General Public License as published by
|
| 876 |
+
the Free Software Foundation, either version 3 of the License, or
|
| 877 |
+
(at your option) any later version.
|
| 878 |
+
|
| 879 |
+
This program is distributed in the hope that it will be useful,
|
| 880 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 881 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 882 |
+
GNU General Public License for more details.
|
| 883 |
+
|
| 884 |
+
You should have received a copy of the GNU General Public License
|
| 885 |
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 886 |
+
|
| 887 |
+
Also add information on how to contact you by electronic and paper mail.
|
| 888 |
+
|
| 889 |
+
If the program does terminal interaction, make it output a short
|
| 890 |
+
notice like this when it starts in an interactive mode:
|
| 891 |
+
|
| 892 |
+
<program> Copyright (C) <year> <name of author>
|
| 893 |
+
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
| 894 |
+
This is free software, and you are welcome to redistribute it
|
| 895 |
+
under certain conditions; type `show c' for details.
|
| 896 |
+
|
| 897 |
+
The hypothetical commands `show w' and `show c' should show the appropriate
|
| 898 |
+
parts of the General Public License. Of course, your program's commands
|
| 899 |
+
might be different; for a GUI interface, you would use an "about box".
|
| 900 |
+
|
| 901 |
+
You should also get your employer (if you work as a programmer) or school,
|
| 902 |
+
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
| 903 |
+
For more information on this, and how to apply and follow the GNU GPL, see
|
| 904 |
+
<http://www.gnu.org/licenses/>.
|
| 905 |
+
|
| 906 |
+
The GNU General Public License does not permit incorporating your program
|
| 907 |
+
into proprietary programs. If your program is a subroutine library, you
|
| 908 |
+
may consider it more useful to permit linking proprietary applications with
|
| 909 |
+
the library. If this is what you want to do, use the GNU Lesser General
|
| 910 |
+
Public License instead of this License. But first, please read
|
| 911 |
+
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
| 912 |
+
|
| 913 |
+
|
| 914 |
+
Name: libquadmath
|
| 915 |
+
Files: scipy.libs/libquadmath*.so
|
| 916 |
+
Description: dynamically linked to files compiled with gcc
|
| 917 |
+
Availability: https://gcc.gnu.org/git/?p=gcc.git;a=tree;f=libquadmath
|
| 918 |
+
License: LGPL-2.1-or-later
|
| 919 |
+
|
| 920 |
+
GCC Quad-Precision Math Library
|
| 921 |
+
Copyright (C) 2010-2019 Free Software Foundation, Inc.
|
| 922 |
+
Written by Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
|
| 923 |
+
|
| 924 |
+
This file is part of the libquadmath library.
|
| 925 |
+
Libquadmath is free software; you can redistribute it and/or
|
| 926 |
+
modify it under the terms of the GNU Library General Public
|
| 927 |
+
License as published by the Free Software Foundation; either
|
| 928 |
+
version 2.1 of the License, or (at your option) any later version.
|
| 929 |
+
|
| 930 |
+
Libquadmath is distributed in the hope that it will be useful,
|
| 931 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 932 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 933 |
+
Lesser General Public License for more details.
|
| 934 |
+
https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy-1.15.3.dist-info/METADATA
ADDED
|
@@ -0,0 +1,1082 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.1
|
| 2 |
+
Name: scipy
|
| 3 |
+
Version: 1.15.3
|
| 4 |
+
Summary: Fundamental algorithms for scientific computing in Python
|
| 5 |
+
Maintainer-Email: SciPy Developers <scipy-dev@python.org>
|
| 6 |
+
License: Copyright (c) 2001-2002 Enthought, Inc. 2003-2024, SciPy Developers.
|
| 7 |
+
All rights reserved.
|
| 8 |
+
|
| 9 |
+
Redistribution and use in source and binary forms, with or without
|
| 10 |
+
modification, are permitted provided that the following conditions
|
| 11 |
+
are met:
|
| 12 |
+
|
| 13 |
+
1. Redistributions of source code must retain the above copyright
|
| 14 |
+
notice, this list of conditions and the following disclaimer.
|
| 15 |
+
|
| 16 |
+
2. Redistributions in binary form must reproduce the above
|
| 17 |
+
copyright notice, this list of conditions and the following
|
| 18 |
+
disclaimer in the documentation and/or other materials provided
|
| 19 |
+
with the distribution.
|
| 20 |
+
|
| 21 |
+
3. Neither the name of the copyright holder nor the names of its
|
| 22 |
+
contributors may be used to endorse or promote products derived
|
| 23 |
+
from this software without specific prior written permission.
|
| 24 |
+
|
| 25 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 26 |
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 27 |
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| 28 |
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| 29 |
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| 30 |
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| 31 |
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| 32 |
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| 33 |
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 34 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 35 |
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 36 |
+
|
| 37 |
+
----
|
| 38 |
+
|
| 39 |
+
This binary distribution of SciPy can also bundle the following software
|
| 40 |
+
(depending on the build):
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
Name: OpenBLAS
|
| 44 |
+
Files: scipy.libs/libscipy_openblas*.so
|
| 45 |
+
Description: bundled as a dynamically linked library
|
| 46 |
+
Availability: https://github.com/OpenMathLib/OpenBLAS/
|
| 47 |
+
License: BSD-3-Clause-Attribution
|
| 48 |
+
Copyright (c) 2011-2014, The OpenBLAS Project
|
| 49 |
+
All rights reserved.
|
| 50 |
+
|
| 51 |
+
Redistribution and use in source and binary forms, with or without
|
| 52 |
+
modification, are permitted provided that the following conditions are
|
| 53 |
+
met:
|
| 54 |
+
|
| 55 |
+
1. Redistributions of source code must retain the above copyright
|
| 56 |
+
notice, this list of conditions and the following disclaimer.
|
| 57 |
+
|
| 58 |
+
2. Redistributions in binary form must reproduce the above copyright
|
| 59 |
+
notice, this list of conditions and the following disclaimer in
|
| 60 |
+
the documentation and/or other materials provided with the
|
| 61 |
+
distribution.
|
| 62 |
+
3. Neither the name of the OpenBLAS project nor the names of
|
| 63 |
+
its contributors may be used to endorse or promote products
|
| 64 |
+
derived from this software without specific prior written
|
| 65 |
+
permission.
|
| 66 |
+
|
| 67 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 68 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 69 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 70 |
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
| 71 |
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
| 72 |
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
| 73 |
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
| 74 |
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
| 75 |
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
| 76 |
+
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
Name: LAPACK
|
| 80 |
+
Files: scipy.libs/libscipy_openblas*.so
|
| 81 |
+
Description: bundled in OpenBLAS
|
| 82 |
+
Availability: https://github.com/OpenMathLib/OpenBLAS/
|
| 83 |
+
License: BSD-3-Clause-Attribution
|
| 84 |
+
Copyright (c) 1992-2013 The University of Tennessee and The University
|
| 85 |
+
of Tennessee Research Foundation. All rights
|
| 86 |
+
reserved.
|
| 87 |
+
Copyright (c) 2000-2013 The University of California Berkeley. All
|
| 88 |
+
rights reserved.
|
| 89 |
+
Copyright (c) 2006-2013 The University of Colorado Denver. All rights
|
| 90 |
+
reserved.
|
| 91 |
+
|
| 92 |
+
$COPYRIGHT$
|
| 93 |
+
|
| 94 |
+
Additional copyrights may follow
|
| 95 |
+
|
| 96 |
+
$HEADER$
|
| 97 |
+
|
| 98 |
+
Redistribution and use in source and binary forms, with or without
|
| 99 |
+
modification, are permitted provided that the following conditions are
|
| 100 |
+
met:
|
| 101 |
+
|
| 102 |
+
- Redistributions of source code must retain the above copyright
|
| 103 |
+
notice, this list of conditions and the following disclaimer.
|
| 104 |
+
|
| 105 |
+
- Redistributions in binary form must reproduce the above copyright
|
| 106 |
+
notice, this list of conditions and the following disclaimer listed
|
| 107 |
+
in this license in the documentation and/or other materials
|
| 108 |
+
provided with the distribution.
|
| 109 |
+
|
| 110 |
+
- Neither the name of the copyright holders nor the names of its
|
| 111 |
+
contributors may be used to endorse or promote products derived from
|
| 112 |
+
this software without specific prior written permission.
|
| 113 |
+
|
| 114 |
+
The copyright holders provide no reassurances that the source code
|
| 115 |
+
provided does not infringe any patent, copyright, or any other
|
| 116 |
+
intellectual property rights of third parties. The copyright holders
|
| 117 |
+
disclaim any liability to any recipient for claims brought against
|
| 118 |
+
recipient by any third party for infringement of that parties
|
| 119 |
+
intellectual property rights.
|
| 120 |
+
|
| 121 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 122 |
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 123 |
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| 124 |
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| 125 |
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| 126 |
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| 127 |
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| 128 |
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| 129 |
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 130 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 131 |
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
Name: GCC runtime library
|
| 135 |
+
Files: scipy.libs/libgfortran*.so
|
| 136 |
+
Description: dynamically linked to files compiled with gcc
|
| 137 |
+
Availability: https://gcc.gnu.org/git/?p=gcc.git;a=tree;f=libgfortran
|
| 138 |
+
License: GPL-3.0-with-GCC-exception
|
| 139 |
+
Copyright (C) 2002-2017 Free Software Foundation, Inc.
|
| 140 |
+
|
| 141 |
+
Libgfortran is free software; you can redistribute it and/or modify
|
| 142 |
+
it under the terms of the GNU General Public License as published by
|
| 143 |
+
the Free Software Foundation; either version 3, or (at your option)
|
| 144 |
+
any later version.
|
| 145 |
+
|
| 146 |
+
Libgfortran is distributed in the hope that it will be useful,
|
| 147 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 148 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 149 |
+
GNU General Public License for more details.
|
| 150 |
+
|
| 151 |
+
Under Section 7 of GPL version 3, you are granted additional
|
| 152 |
+
permissions described in the GCC Runtime Library Exception, version
|
| 153 |
+
3.1, as published by the Free Software Foundation.
|
| 154 |
+
|
| 155 |
+
You should have received a copy of the GNU General Public License and
|
| 156 |
+
a copy of the GCC Runtime Library Exception along with this program;
|
| 157 |
+
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
| 158 |
+
<http://www.gnu.org/licenses/>.
|
| 159 |
+
|
| 160 |
+
----
|
| 161 |
+
|
| 162 |
+
Full text of license texts referred to above follows (that they are
|
| 163 |
+
listed below does not necessarily imply the conditions apply to the
|
| 164 |
+
present binary release):
|
| 165 |
+
|
| 166 |
+
----
|
| 167 |
+
|
| 168 |
+
GCC RUNTIME LIBRARY EXCEPTION
|
| 169 |
+
|
| 170 |
+
Version 3.1, 31 March 2009
|
| 171 |
+
|
| 172 |
+
Copyright (C) 2009 Free Software Foundation, Inc. <http://fsf.org/>
|
| 173 |
+
|
| 174 |
+
Everyone is permitted to copy and distribute verbatim copies of this
|
| 175 |
+
license document, but changing it is not allowed.
|
| 176 |
+
|
| 177 |
+
This GCC Runtime Library Exception ("Exception") is an additional
|
| 178 |
+
permission under section 7 of the GNU General Public License, version
|
| 179 |
+
3 ("GPLv3"). It applies to a given file (the "Runtime Library") that
|
| 180 |
+
bears a notice placed by the copyright holder of the file stating that
|
| 181 |
+
the file is governed by GPLv3 along with this Exception.
|
| 182 |
+
|
| 183 |
+
When you use GCC to compile a program, GCC may combine portions of
|
| 184 |
+
certain GCC header files and runtime libraries with the compiled
|
| 185 |
+
program. The purpose of this Exception is to allow compilation of
|
| 186 |
+
non-GPL (including proprietary) programs to use, in this way, the
|
| 187 |
+
header files and runtime libraries covered by this Exception.
|
| 188 |
+
|
| 189 |
+
0. Definitions.
|
| 190 |
+
|
| 191 |
+
A file is an "Independent Module" if it either requires the Runtime
|
| 192 |
+
Library for execution after a Compilation Process, or makes use of an
|
| 193 |
+
interface provided by the Runtime Library, but is not otherwise based
|
| 194 |
+
on the Runtime Library.
|
| 195 |
+
|
| 196 |
+
"GCC" means a version of the GNU Compiler Collection, with or without
|
| 197 |
+
modifications, governed by version 3 (or a specified later version) of
|
| 198 |
+
the GNU General Public License (GPL) with the option of using any
|
| 199 |
+
subsequent versions published by the FSF.
|
| 200 |
+
|
| 201 |
+
"GPL-compatible Software" is software whose conditions of propagation,
|
| 202 |
+
modification and use would permit combination with GCC in accord with
|
| 203 |
+
the license of GCC.
|
| 204 |
+
|
| 205 |
+
"Target Code" refers to output from any compiler for a real or virtual
|
| 206 |
+
target processor architecture, in executable form or suitable for
|
| 207 |
+
input to an assembler, loader, linker and/or execution
|
| 208 |
+
phase. Notwithstanding that, Target Code does not include data in any
|
| 209 |
+
format that is used as a compiler intermediate representation, or used
|
| 210 |
+
for producing a compiler intermediate representation.
|
| 211 |
+
|
| 212 |
+
The "Compilation Process" transforms code entirely represented in
|
| 213 |
+
non-intermediate languages designed for human-written code, and/or in
|
| 214 |
+
Java Virtual Machine byte code, into Target Code. Thus, for example,
|
| 215 |
+
use of source code generators and preprocessors need not be considered
|
| 216 |
+
part of the Compilation Process, since the Compilation Process can be
|
| 217 |
+
understood as starting with the output of the generators or
|
| 218 |
+
preprocessors.
|
| 219 |
+
|
| 220 |
+
A Compilation Process is "Eligible" if it is done using GCC, alone or
|
| 221 |
+
with other GPL-compatible software, or if it is done without using any
|
| 222 |
+
work based on GCC. For example, using non-GPL-compatible Software to
|
| 223 |
+
optimize any GCC intermediate representations would not qualify as an
|
| 224 |
+
Eligible Compilation Process.
|
| 225 |
+
|
| 226 |
+
1. Grant of Additional Permission.
|
| 227 |
+
|
| 228 |
+
You have permission to propagate a work of Target Code formed by
|
| 229 |
+
combining the Runtime Library with Independent Modules, even if such
|
| 230 |
+
propagation would otherwise violate the terms of GPLv3, provided that
|
| 231 |
+
all Target Code was generated by Eligible Compilation Processes. You
|
| 232 |
+
may then convey such a combination under terms of your choice,
|
| 233 |
+
consistent with the licensing of the Independent Modules.
|
| 234 |
+
|
| 235 |
+
2. No Weakening of GCC Copyleft.
|
| 236 |
+
|
| 237 |
+
The availability of this Exception does not imply any general
|
| 238 |
+
presumption that third-party software is unaffected by the copyleft
|
| 239 |
+
requirements of the license of GCC.
|
| 240 |
+
|
| 241 |
+
----
|
| 242 |
+
|
| 243 |
+
GNU GENERAL PUBLIC LICENSE
|
| 244 |
+
Version 3, 29 June 2007
|
| 245 |
+
|
| 246 |
+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
| 247 |
+
Everyone is permitted to copy and distribute verbatim copies
|
| 248 |
+
of this license document, but changing it is not allowed.
|
| 249 |
+
|
| 250 |
+
Preamble
|
| 251 |
+
|
| 252 |
+
The GNU General Public License is a free, copyleft license for
|
| 253 |
+
software and other kinds of works.
|
| 254 |
+
|
| 255 |
+
The licenses for most software and other practical works are designed
|
| 256 |
+
to take away your freedom to share and change the works. By contrast,
|
| 257 |
+
the GNU General Public License is intended to guarantee your freedom to
|
| 258 |
+
share and change all versions of a program--to make sure it remains free
|
| 259 |
+
software for all its users. We, the Free Software Foundation, use the
|
| 260 |
+
GNU General Public License for most of our software; it applies also to
|
| 261 |
+
any other work released this way by its authors. You can apply it to
|
| 262 |
+
your programs, too.
|
| 263 |
+
|
| 264 |
+
When we speak of free software, we are referring to freedom, not
|
| 265 |
+
price. Our General Public Licenses are designed to make sure that you
|
| 266 |
+
have the freedom to distribute copies of free software (and charge for
|
| 267 |
+
them if you wish), that you receive source code or can get it if you
|
| 268 |
+
want it, that you can change the software or use pieces of it in new
|
| 269 |
+
free programs, and that you know you can do these things.
|
| 270 |
+
|
| 271 |
+
To protect your rights, we need to prevent others from denying you
|
| 272 |
+
these rights or asking you to surrender the rights. Therefore, you have
|
| 273 |
+
certain responsibilities if you distribute copies of the software, or if
|
| 274 |
+
you modify it: responsibilities to respect the freedom of others.
|
| 275 |
+
|
| 276 |
+
For example, if you distribute copies of such a program, whether
|
| 277 |
+
gratis or for a fee, you must pass on to the recipients the same
|
| 278 |
+
freedoms that you received. You must make sure that they, too, receive
|
| 279 |
+
or can get the source code. And you must show them these terms so they
|
| 280 |
+
know their rights.
|
| 281 |
+
|
| 282 |
+
Developers that use the GNU GPL protect your rights with two steps:
|
| 283 |
+
(1) assert copyright on the software, and (2) offer you this License
|
| 284 |
+
giving you legal permission to copy, distribute and/or modify it.
|
| 285 |
+
|
| 286 |
+
For the developers' and authors' protection, the GPL clearly explains
|
| 287 |
+
that there is no warranty for this free software. For both users' and
|
| 288 |
+
authors' sake, the GPL requires that modified versions be marked as
|
| 289 |
+
changed, so that their problems will not be attributed erroneously to
|
| 290 |
+
authors of previous versions.
|
| 291 |
+
|
| 292 |
+
Some devices are designed to deny users access to install or run
|
| 293 |
+
modified versions of the software inside them, although the manufacturer
|
| 294 |
+
can do so. This is fundamentally incompatible with the aim of
|
| 295 |
+
protecting users' freedom to change the software. The systematic
|
| 296 |
+
pattern of such abuse occurs in the area of products for individuals to
|
| 297 |
+
use, which is precisely where it is most unacceptable. Therefore, we
|
| 298 |
+
have designed this version of the GPL to prohibit the practice for those
|
| 299 |
+
products. If such problems arise substantially in other domains, we
|
| 300 |
+
stand ready to extend this provision to those domains in future versions
|
| 301 |
+
of the GPL, as needed to protect the freedom of users.
|
| 302 |
+
|
| 303 |
+
Finally, every program is threatened constantly by software patents.
|
| 304 |
+
States should not allow patents to restrict development and use of
|
| 305 |
+
software on general-purpose computers, but in those that do, we wish to
|
| 306 |
+
avoid the special danger that patents applied to a free program could
|
| 307 |
+
make it effectively proprietary. To prevent this, the GPL assures that
|
| 308 |
+
patents cannot be used to render the program non-free.
|
| 309 |
+
|
| 310 |
+
The precise terms and conditions for copying, distribution and
|
| 311 |
+
modification follow.
|
| 312 |
+
|
| 313 |
+
TERMS AND CONDITIONS
|
| 314 |
+
|
| 315 |
+
0. Definitions.
|
| 316 |
+
|
| 317 |
+
"This License" refers to version 3 of the GNU General Public License.
|
| 318 |
+
|
| 319 |
+
"Copyright" also means copyright-like laws that apply to other kinds of
|
| 320 |
+
works, such as semiconductor masks.
|
| 321 |
+
|
| 322 |
+
"The Program" refers to any copyrightable work licensed under this
|
| 323 |
+
License. Each licensee is addressed as "you". "Licensees" and
|
| 324 |
+
"recipients" may be individuals or organizations.
|
| 325 |
+
|
| 326 |
+
To "modify" a work means to copy from or adapt all or part of the work
|
| 327 |
+
in a fashion requiring copyright permission, other than the making of an
|
| 328 |
+
exact copy. The resulting work is called a "modified version" of the
|
| 329 |
+
earlier work or a work "based on" the earlier work.
|
| 330 |
+
|
| 331 |
+
A "covered work" means either the unmodified Program or a work based
|
| 332 |
+
on the Program.
|
| 333 |
+
|
| 334 |
+
To "propagate" a work means to do anything with it that, without
|
| 335 |
+
permission, would make you directly or secondarily liable for
|
| 336 |
+
infringement under applicable copyright law, except executing it on a
|
| 337 |
+
computer or modifying a private copy. Propagation includes copying,
|
| 338 |
+
distribution (with or without modification), making available to the
|
| 339 |
+
public, and in some countries other activities as well.
|
| 340 |
+
|
| 341 |
+
To "convey" a work means any kind of propagation that enables other
|
| 342 |
+
parties to make or receive copies. Mere interaction with a user through
|
| 343 |
+
a computer network, with no transfer of a copy, is not conveying.
|
| 344 |
+
|
| 345 |
+
An interactive user interface displays "Appropriate Legal Notices"
|
| 346 |
+
to the extent that it includes a convenient and prominently visible
|
| 347 |
+
feature that (1) displays an appropriate copyright notice, and (2)
|
| 348 |
+
tells the user that there is no warranty for the work (except to the
|
| 349 |
+
extent that warranties are provided), that licensees may convey the
|
| 350 |
+
work under this License, and how to view a copy of this License. If
|
| 351 |
+
the interface presents a list of user commands or options, such as a
|
| 352 |
+
menu, a prominent item in the list meets this criterion.
|
| 353 |
+
|
| 354 |
+
1. Source Code.
|
| 355 |
+
|
| 356 |
+
The "source code" for a work means the preferred form of the work
|
| 357 |
+
for making modifications to it. "Object code" means any non-source
|
| 358 |
+
form of a work.
|
| 359 |
+
|
| 360 |
+
A "Standard Interface" means an interface that either is an official
|
| 361 |
+
standard defined by a recognized standards body, or, in the case of
|
| 362 |
+
interfaces specified for a particular programming language, one that
|
| 363 |
+
is widely used among developers working in that language.
|
| 364 |
+
|
| 365 |
+
The "System Libraries" of an executable work include anything, other
|
| 366 |
+
than the work as a whole, that (a) is included in the normal form of
|
| 367 |
+
packaging a Major Component, but which is not part of that Major
|
| 368 |
+
Component, and (b) serves only to enable use of the work with that
|
| 369 |
+
Major Component, or to implement a Standard Interface for which an
|
| 370 |
+
implementation is available to the public in source code form. A
|
| 371 |
+
"Major Component", in this context, means a major essential component
|
| 372 |
+
(kernel, window system, and so on) of the specific operating system
|
| 373 |
+
(if any) on which the executable work runs, or a compiler used to
|
| 374 |
+
produce the work, or an object code interpreter used to run it.
|
| 375 |
+
|
| 376 |
+
The "Corresponding Source" for a work in object code form means all
|
| 377 |
+
the source code needed to generate, install, and (for an executable
|
| 378 |
+
work) run the object code and to modify the work, including scripts to
|
| 379 |
+
control those activities. However, it does not include the work's
|
| 380 |
+
System Libraries, or general-purpose tools or generally available free
|
| 381 |
+
programs which are used unmodified in performing those activities but
|
| 382 |
+
which are not part of the work. For example, Corresponding Source
|
| 383 |
+
includes interface definition files associated with source files for
|
| 384 |
+
the work, and the source code for shared libraries and dynamically
|
| 385 |
+
linked subprograms that the work is specifically designed to require,
|
| 386 |
+
such as by intimate data communication or control flow between those
|
| 387 |
+
subprograms and other parts of the work.
|
| 388 |
+
|
| 389 |
+
The Corresponding Source need not include anything that users
|
| 390 |
+
can regenerate automatically from other parts of the Corresponding
|
| 391 |
+
Source.
|
| 392 |
+
|
| 393 |
+
The Corresponding Source for a work in source code form is that
|
| 394 |
+
same work.
|
| 395 |
+
|
| 396 |
+
2. Basic Permissions.
|
| 397 |
+
|
| 398 |
+
All rights granted under this License are granted for the term of
|
| 399 |
+
copyright on the Program, and are irrevocable provided the stated
|
| 400 |
+
conditions are met. This License explicitly affirms your unlimited
|
| 401 |
+
permission to run the unmodified Program. The output from running a
|
| 402 |
+
covered work is covered by this License only if the output, given its
|
| 403 |
+
content, constitutes a covered work. This License acknowledges your
|
| 404 |
+
rights of fair use or other equivalent, as provided by copyright law.
|
| 405 |
+
|
| 406 |
+
You may make, run and propagate covered works that you do not
|
| 407 |
+
convey, without conditions so long as your license otherwise remains
|
| 408 |
+
in force. You may convey covered works to others for the sole purpose
|
| 409 |
+
of having them make modifications exclusively for you, or provide you
|
| 410 |
+
with facilities for running those works, provided that you comply with
|
| 411 |
+
the terms of this License in conveying all material for which you do
|
| 412 |
+
not control copyright. Those thus making or running the covered works
|
| 413 |
+
for you must do so exclusively on your behalf, under your direction
|
| 414 |
+
and control, on terms that prohibit them from making any copies of
|
| 415 |
+
your copyrighted material outside their relationship with you.
|
| 416 |
+
|
| 417 |
+
Conveying under any other circumstances is permitted solely under
|
| 418 |
+
the conditions stated below. Sublicensing is not allowed; section 10
|
| 419 |
+
makes it unnecessary.
|
| 420 |
+
|
| 421 |
+
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
| 422 |
+
|
| 423 |
+
No covered work shall be deemed part of an effective technological
|
| 424 |
+
measure under any applicable law fulfilling obligations under article
|
| 425 |
+
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
| 426 |
+
similar laws prohibiting or restricting circumvention of such
|
| 427 |
+
measures.
|
| 428 |
+
|
| 429 |
+
When you convey a covered work, you waive any legal power to forbid
|
| 430 |
+
circumvention of technological measures to the extent such circumvention
|
| 431 |
+
is effected by exercising rights under this License with respect to
|
| 432 |
+
the covered work, and you disclaim any intention to limit operation or
|
| 433 |
+
modification of the work as a means of enforcing, against the work's
|
| 434 |
+
users, your or third parties' legal rights to forbid circumvention of
|
| 435 |
+
technological measures.
|
| 436 |
+
|
| 437 |
+
4. Conveying Verbatim Copies.
|
| 438 |
+
|
| 439 |
+
You may convey verbatim copies of the Program's source code as you
|
| 440 |
+
receive it, in any medium, provided that you conspicuously and
|
| 441 |
+
appropriately publish on each copy an appropriate copyright notice;
|
| 442 |
+
keep intact all notices stating that this License and any
|
| 443 |
+
non-permissive terms added in accord with section 7 apply to the code;
|
| 444 |
+
keep intact all notices of the absence of any warranty; and give all
|
| 445 |
+
recipients a copy of this License along with the Program.
|
| 446 |
+
|
| 447 |
+
You may charge any price or no price for each copy that you convey,
|
| 448 |
+
and you may offer support or warranty protection for a fee.
|
| 449 |
+
|
| 450 |
+
5. Conveying Modified Source Versions.
|
| 451 |
+
|
| 452 |
+
You may convey a work based on the Program, or the modifications to
|
| 453 |
+
produce it from the Program, in the form of source code under the
|
| 454 |
+
terms of section 4, provided that you also meet all of these conditions:
|
| 455 |
+
|
| 456 |
+
a) The work must carry prominent notices stating that you modified
|
| 457 |
+
it, and giving a relevant date.
|
| 458 |
+
|
| 459 |
+
b) The work must carry prominent notices stating that it is
|
| 460 |
+
released under this License and any conditions added under section
|
| 461 |
+
7. This requirement modifies the requirement in section 4 to
|
| 462 |
+
"keep intact all notices".
|
| 463 |
+
|
| 464 |
+
c) You must license the entire work, as a whole, under this
|
| 465 |
+
License to anyone who comes into possession of a copy. This
|
| 466 |
+
License will therefore apply, along with any applicable section 7
|
| 467 |
+
additional terms, to the whole of the work, and all its parts,
|
| 468 |
+
regardless of how they are packaged. This License gives no
|
| 469 |
+
permission to license the work in any other way, but it does not
|
| 470 |
+
invalidate such permission if you have separately received it.
|
| 471 |
+
|
| 472 |
+
d) If the work has interactive user interfaces, each must display
|
| 473 |
+
Appropriate Legal Notices; however, if the Program has interactive
|
| 474 |
+
interfaces that do not display Appropriate Legal Notices, your
|
| 475 |
+
work need not make them do so.
|
| 476 |
+
|
| 477 |
+
A compilation of a covered work with other separate and independent
|
| 478 |
+
works, which are not by their nature extensions of the covered work,
|
| 479 |
+
and which are not combined with it such as to form a larger program,
|
| 480 |
+
in or on a volume of a storage or distribution medium, is called an
|
| 481 |
+
"aggregate" if the compilation and its resulting copyright are not
|
| 482 |
+
used to limit the access or legal rights of the compilation's users
|
| 483 |
+
beyond what the individual works permit. Inclusion of a covered work
|
| 484 |
+
in an aggregate does not cause this License to apply to the other
|
| 485 |
+
parts of the aggregate.
|
| 486 |
+
|
| 487 |
+
6. Conveying Non-Source Forms.
|
| 488 |
+
|
| 489 |
+
You may convey a covered work in object code form under the terms
|
| 490 |
+
of sections 4 and 5, provided that you also convey the
|
| 491 |
+
machine-readable Corresponding Source under the terms of this License,
|
| 492 |
+
in one of these ways:
|
| 493 |
+
|
| 494 |
+
a) Convey the object code in, or embodied in, a physical product
|
| 495 |
+
(including a physical distribution medium), accompanied by the
|
| 496 |
+
Corresponding Source fixed on a durable physical medium
|
| 497 |
+
customarily used for software interchange.
|
| 498 |
+
|
| 499 |
+
b) Convey the object code in, or embodied in, a physical product
|
| 500 |
+
(including a physical distribution medium), accompanied by a
|
| 501 |
+
written offer, valid for at least three years and valid for as
|
| 502 |
+
long as you offer spare parts or customer support for that product
|
| 503 |
+
model, to give anyone who possesses the object code either (1) a
|
| 504 |
+
copy of the Corresponding Source for all the software in the
|
| 505 |
+
product that is covered by this License, on a durable physical
|
| 506 |
+
medium customarily used for software interchange, for a price no
|
| 507 |
+
more than your reasonable cost of physically performing this
|
| 508 |
+
conveying of source, or (2) access to copy the
|
| 509 |
+
Corresponding Source from a network server at no charge.
|
| 510 |
+
|
| 511 |
+
c) Convey individual copies of the object code with a copy of the
|
| 512 |
+
written offer to provide the Corresponding Source. This
|
| 513 |
+
alternative is allowed only occasionally and noncommercially, and
|
| 514 |
+
only if you received the object code with such an offer, in accord
|
| 515 |
+
with subsection 6b.
|
| 516 |
+
|
| 517 |
+
d) Convey the object code by offering access from a designated
|
| 518 |
+
place (gratis or for a charge), and offer equivalent access to the
|
| 519 |
+
Corresponding Source in the same way through the same place at no
|
| 520 |
+
further charge. You need not require recipients to copy the
|
| 521 |
+
Corresponding Source along with the object code. If the place to
|
| 522 |
+
copy the object code is a network server, the Corresponding Source
|
| 523 |
+
may be on a different server (operated by you or a third party)
|
| 524 |
+
that supports equivalent copying facilities, provided you maintain
|
| 525 |
+
clear directions next to the object code saying where to find the
|
| 526 |
+
Corresponding Source. Regardless of what server hosts the
|
| 527 |
+
Corresponding Source, you remain obligated to ensure that it is
|
| 528 |
+
available for as long as needed to satisfy these requirements.
|
| 529 |
+
|
| 530 |
+
e) Convey the object code using peer-to-peer transmission, provided
|
| 531 |
+
you inform other peers where the object code and Corresponding
|
| 532 |
+
Source of the work are being offered to the general public at no
|
| 533 |
+
charge under subsection 6d.
|
| 534 |
+
|
| 535 |
+
A separable portion of the object code, whose source code is excluded
|
| 536 |
+
from the Corresponding Source as a System Library, need not be
|
| 537 |
+
included in conveying the object code work.
|
| 538 |
+
|
| 539 |
+
A "User Product" is either (1) a "consumer product", which means any
|
| 540 |
+
tangible personal property which is normally used for personal, family,
|
| 541 |
+
or household purposes, or (2) anything designed or sold for incorporation
|
| 542 |
+
into a dwelling. In determining whether a product is a consumer product,
|
| 543 |
+
doubtful cases shall be resolved in favor of coverage. For a particular
|
| 544 |
+
product received by a particular user, "normally used" refers to a
|
| 545 |
+
typical or common use of that class of product, regardless of the status
|
| 546 |
+
of the particular user or of the way in which the particular user
|
| 547 |
+
actually uses, or expects or is expected to use, the product. A product
|
| 548 |
+
is a consumer product regardless of whether the product has substantial
|
| 549 |
+
commercial, industrial or non-consumer uses, unless such uses represent
|
| 550 |
+
the only significant mode of use of the product.
|
| 551 |
+
|
| 552 |
+
"Installation Information" for a User Product means any methods,
|
| 553 |
+
procedures, authorization keys, or other information required to install
|
| 554 |
+
and execute modified versions of a covered work in that User Product from
|
| 555 |
+
a modified version of its Corresponding Source. The information must
|
| 556 |
+
suffice to ensure that the continued functioning of the modified object
|
| 557 |
+
code is in no case prevented or interfered with solely because
|
| 558 |
+
modification has been made.
|
| 559 |
+
|
| 560 |
+
If you convey an object code work under this section in, or with, or
|
| 561 |
+
specifically for use in, a User Product, and the conveying occurs as
|
| 562 |
+
part of a transaction in which the right of possession and use of the
|
| 563 |
+
User Product is transferred to the recipient in perpetuity or for a
|
| 564 |
+
fixed term (regardless of how the transaction is characterized), the
|
| 565 |
+
Corresponding Source conveyed under this section must be accompanied
|
| 566 |
+
by the Installation Information. But this requirement does not apply
|
| 567 |
+
if neither you nor any third party retains the ability to install
|
| 568 |
+
modified object code on the User Product (for example, the work has
|
| 569 |
+
been installed in ROM).
|
| 570 |
+
|
| 571 |
+
The requirement to provide Installation Information does not include a
|
| 572 |
+
requirement to continue to provide support service, warranty, or updates
|
| 573 |
+
for a work that has been modified or installed by the recipient, or for
|
| 574 |
+
the User Product in which it has been modified or installed. Access to a
|
| 575 |
+
network may be denied when the modification itself materially and
|
| 576 |
+
adversely affects the operation of the network or violates the rules and
|
| 577 |
+
protocols for communication across the network.
|
| 578 |
+
|
| 579 |
+
Corresponding Source conveyed, and Installation Information provided,
|
| 580 |
+
in accord with this section must be in a format that is publicly
|
| 581 |
+
documented (and with an implementation available to the public in
|
| 582 |
+
source code form), and must require no special password or key for
|
| 583 |
+
unpacking, reading or copying.
|
| 584 |
+
|
| 585 |
+
7. Additional Terms.
|
| 586 |
+
|
| 587 |
+
"Additional permissions" are terms that supplement the terms of this
|
| 588 |
+
License by making exceptions from one or more of its conditions.
|
| 589 |
+
Additional permissions that are applicable to the entire Program shall
|
| 590 |
+
be treated as though they were included in this License, to the extent
|
| 591 |
+
that they are valid under applicable law. If additional permissions
|
| 592 |
+
apply only to part of the Program, that part may be used separately
|
| 593 |
+
under those permissions, but the entire Program remains governed by
|
| 594 |
+
this License without regard to the additional permissions.
|
| 595 |
+
|
| 596 |
+
When you convey a copy of a covered work, you may at your option
|
| 597 |
+
remove any additional permissions from that copy, or from any part of
|
| 598 |
+
it. (Additional permissions may be written to require their own
|
| 599 |
+
removal in certain cases when you modify the work.) You may place
|
| 600 |
+
additional permissions on material, added by you to a covered work,
|
| 601 |
+
for which you have or can give appropriate copyright permission.
|
| 602 |
+
|
| 603 |
+
Notwithstanding any other provision of this License, for material you
|
| 604 |
+
add to a covered work, you may (if authorized by the copyright holders of
|
| 605 |
+
that material) supplement the terms of this License with terms:
|
| 606 |
+
|
| 607 |
+
a) Disclaiming warranty or limiting liability differently from the
|
| 608 |
+
terms of sections 15 and 16 of this License; or
|
| 609 |
+
|
| 610 |
+
b) Requiring preservation of specified reasonable legal notices or
|
| 611 |
+
author attributions in that material or in the Appropriate Legal
|
| 612 |
+
Notices displayed by works containing it; or
|
| 613 |
+
|
| 614 |
+
c) Prohibiting misrepresentation of the origin of that material, or
|
| 615 |
+
requiring that modified versions of such material be marked in
|
| 616 |
+
reasonable ways as different from the original version; or
|
| 617 |
+
|
| 618 |
+
d) Limiting the use for publicity purposes of names of licensors or
|
| 619 |
+
authors of the material; or
|
| 620 |
+
|
| 621 |
+
e) Declining to grant rights under trademark law for use of some
|
| 622 |
+
trade names, trademarks, or service marks; or
|
| 623 |
+
|
| 624 |
+
f) Requiring indemnification of licensors and authors of that
|
| 625 |
+
material by anyone who conveys the material (or modified versions of
|
| 626 |
+
it) with contractual assumptions of liability to the recipient, for
|
| 627 |
+
any liability that these contractual assumptions directly impose on
|
| 628 |
+
those licensors and authors.
|
| 629 |
+
|
| 630 |
+
All other non-permissive additional terms are considered "further
|
| 631 |
+
restrictions" within the meaning of section 10. If the Program as you
|
| 632 |
+
received it, or any part of it, contains a notice stating that it is
|
| 633 |
+
governed by this License along with a term that is a further
|
| 634 |
+
restriction, you may remove that term. If a license document contains
|
| 635 |
+
a further restriction but permits relicensing or conveying under this
|
| 636 |
+
License, you may add to a covered work material governed by the terms
|
| 637 |
+
of that license document, provided that the further restriction does
|
| 638 |
+
not survive such relicensing or conveying.
|
| 639 |
+
|
| 640 |
+
If you add terms to a covered work in accord with this section, you
|
| 641 |
+
must place, in the relevant source files, a statement of the
|
| 642 |
+
additional terms that apply to those files, or a notice indicating
|
| 643 |
+
where to find the applicable terms.
|
| 644 |
+
|
| 645 |
+
Additional terms, permissive or non-permissive, may be stated in the
|
| 646 |
+
form of a separately written license, or stated as exceptions;
|
| 647 |
+
the above requirements apply either way.
|
| 648 |
+
|
| 649 |
+
8. Termination.
|
| 650 |
+
|
| 651 |
+
You may not propagate or modify a covered work except as expressly
|
| 652 |
+
provided under this License. Any attempt otherwise to propagate or
|
| 653 |
+
modify it is void, and will automatically terminate your rights under
|
| 654 |
+
this License (including any patent licenses granted under the third
|
| 655 |
+
paragraph of section 11).
|
| 656 |
+
|
| 657 |
+
However, if you cease all violation of this License, then your
|
| 658 |
+
license from a particular copyright holder is reinstated (a)
|
| 659 |
+
provisionally, unless and until the copyright holder explicitly and
|
| 660 |
+
finally terminates your license, and (b) permanently, if the copyright
|
| 661 |
+
holder fails to notify you of the violation by some reasonable means
|
| 662 |
+
prior to 60 days after the cessation.
|
| 663 |
+
|
| 664 |
+
Moreover, your license from a particular copyright holder is
|
| 665 |
+
reinstated permanently if the copyright holder notifies you of the
|
| 666 |
+
violation by some reasonable means, this is the first time you have
|
| 667 |
+
received notice of violation of this License (for any work) from that
|
| 668 |
+
copyright holder, and you cure the violation prior to 30 days after
|
| 669 |
+
your receipt of the notice.
|
| 670 |
+
|
| 671 |
+
Termination of your rights under this section does not terminate the
|
| 672 |
+
licenses of parties who have received copies or rights from you under
|
| 673 |
+
this License. If your rights have been terminated and not permanently
|
| 674 |
+
reinstated, you do not qualify to receive new licenses for the same
|
| 675 |
+
material under section 10.
|
| 676 |
+
|
| 677 |
+
9. Acceptance Not Required for Having Copies.
|
| 678 |
+
|
| 679 |
+
You are not required to accept this License in order to receive or
|
| 680 |
+
run a copy of the Program. Ancillary propagation of a covered work
|
| 681 |
+
occurring solely as a consequence of using peer-to-peer transmission
|
| 682 |
+
to receive a copy likewise does not require acceptance. However,
|
| 683 |
+
nothing other than this License grants you permission to propagate or
|
| 684 |
+
modify any covered work. These actions infringe copyright if you do
|
| 685 |
+
not accept this License. Therefore, by modifying or propagating a
|
| 686 |
+
covered work, you indicate your acceptance of this License to do so.
|
| 687 |
+
|
| 688 |
+
10. Automatic Licensing of Downstream Recipients.
|
| 689 |
+
|
| 690 |
+
Each time you convey a covered work, the recipient automatically
|
| 691 |
+
receives a license from the original licensors, to run, modify and
|
| 692 |
+
propagate that work, subject to this License. You are not responsible
|
| 693 |
+
for enforcing compliance by third parties with this License.
|
| 694 |
+
|
| 695 |
+
An "entity transaction" is a transaction transferring control of an
|
| 696 |
+
organization, or substantially all assets of one, or subdividing an
|
| 697 |
+
organization, or merging organizations. If propagation of a covered
|
| 698 |
+
work results from an entity transaction, each party to that
|
| 699 |
+
transaction who receives a copy of the work also receives whatever
|
| 700 |
+
licenses to the work the party's predecessor in interest had or could
|
| 701 |
+
give under the previous paragraph, plus a right to possession of the
|
| 702 |
+
Corresponding Source of the work from the predecessor in interest, if
|
| 703 |
+
the predecessor has it or can get it with reasonable efforts.
|
| 704 |
+
|
| 705 |
+
You may not impose any further restrictions on the exercise of the
|
| 706 |
+
rights granted or affirmed under this License. For example, you may
|
| 707 |
+
not impose a license fee, royalty, or other charge for exercise of
|
| 708 |
+
rights granted under this License, and you may not initiate litigation
|
| 709 |
+
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
| 710 |
+
any patent claim is infringed by making, using, selling, offering for
|
| 711 |
+
sale, or importing the Program or any portion of it.
|
| 712 |
+
|
| 713 |
+
11. Patents.
|
| 714 |
+
|
| 715 |
+
A "contributor" is a copyright holder who authorizes use under this
|
| 716 |
+
License of the Program or a work on which the Program is based. The
|
| 717 |
+
work thus licensed is called the contributor's "contributor version".
|
| 718 |
+
|
| 719 |
+
A contributor's "essential patent claims" are all patent claims
|
| 720 |
+
owned or controlled by the contributor, whether already acquired or
|
| 721 |
+
hereafter acquired, that would be infringed by some manner, permitted
|
| 722 |
+
by this License, of making, using, or selling its contributor version,
|
| 723 |
+
but do not include claims that would be infringed only as a
|
| 724 |
+
consequence of further modification of the contributor version. For
|
| 725 |
+
purposes of this definition, "control" includes the right to grant
|
| 726 |
+
patent sublicenses in a manner consistent with the requirements of
|
| 727 |
+
this License.
|
| 728 |
+
|
| 729 |
+
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
| 730 |
+
patent license under the contributor's essential patent claims, to
|
| 731 |
+
make, use, sell, offer for sale, import and otherwise run, modify and
|
| 732 |
+
propagate the contents of its contributor version.
|
| 733 |
+
|
| 734 |
+
In the following three paragraphs, a "patent license" is any express
|
| 735 |
+
agreement or commitment, however denominated, not to enforce a patent
|
| 736 |
+
(such as an express permission to practice a patent or covenant not to
|
| 737 |
+
sue for patent infringement). To "grant" such a patent license to a
|
| 738 |
+
party means to make such an agreement or commitment not to enforce a
|
| 739 |
+
patent against the party.
|
| 740 |
+
|
| 741 |
+
If you convey a covered work, knowingly relying on a patent license,
|
| 742 |
+
and the Corresponding Source of the work is not available for anyone
|
| 743 |
+
to copy, free of charge and under the terms of this License, through a
|
| 744 |
+
publicly available network server or other readily accessible means,
|
| 745 |
+
then you must either (1) cause the Corresponding Source to be so
|
| 746 |
+
available, or (2) arrange to deprive yourself of the benefit of the
|
| 747 |
+
patent license for this particular work, or (3) arrange, in a manner
|
| 748 |
+
consistent with the requirements of this License, to extend the patent
|
| 749 |
+
license to downstream recipients. "Knowingly relying" means you have
|
| 750 |
+
actual knowledge that, but for the patent license, your conveying the
|
| 751 |
+
covered work in a country, or your recipient's use of the covered work
|
| 752 |
+
in a country, would infringe one or more identifiable patents in that
|
| 753 |
+
country that you have reason to believe are valid.
|
| 754 |
+
|
| 755 |
+
If, pursuant to or in connection with a single transaction or
|
| 756 |
+
arrangement, you convey, or propagate by procuring conveyance of, a
|
| 757 |
+
covered work, and grant a patent license to some of the parties
|
| 758 |
+
receiving the covered work authorizing them to use, propagate, modify
|
| 759 |
+
or convey a specific copy of the covered work, then the patent license
|
| 760 |
+
you grant is automatically extended to all recipients of the covered
|
| 761 |
+
work and works based on it.
|
| 762 |
+
|
| 763 |
+
A patent license is "discriminatory" if it does not include within
|
| 764 |
+
the scope of its coverage, prohibits the exercise of, or is
|
| 765 |
+
conditioned on the non-exercise of one or more of the rights that are
|
| 766 |
+
specifically granted under this License. You may not convey a covered
|
| 767 |
+
work if you are a party to an arrangement with a third party that is
|
| 768 |
+
in the business of distributing software, under which you make payment
|
| 769 |
+
to the third party based on the extent of your activity of conveying
|
| 770 |
+
the work, and under which the third party grants, to any of the
|
| 771 |
+
parties who would receive the covered work from you, a discriminatory
|
| 772 |
+
patent license (a) in connection with copies of the covered work
|
| 773 |
+
conveyed by you (or copies made from those copies), or (b) primarily
|
| 774 |
+
for and in connection with specific products or compilations that
|
| 775 |
+
contain the covered work, unless you entered into that arrangement,
|
| 776 |
+
or that patent license was granted, prior to 28 March 2007.
|
| 777 |
+
|
| 778 |
+
Nothing in this License shall be construed as excluding or limiting
|
| 779 |
+
any implied license or other defenses to infringement that may
|
| 780 |
+
otherwise be available to you under applicable patent law.
|
| 781 |
+
|
| 782 |
+
12. No Surrender of Others' Freedom.
|
| 783 |
+
|
| 784 |
+
If conditions are imposed on you (whether by court order, agreement or
|
| 785 |
+
otherwise) that contradict the conditions of this License, they do not
|
| 786 |
+
excuse you from the conditions of this License. If you cannot convey a
|
| 787 |
+
covered work so as to satisfy simultaneously your obligations under this
|
| 788 |
+
License and any other pertinent obligations, then as a consequence you may
|
| 789 |
+
not convey it at all. For example, if you agree to terms that obligate you
|
| 790 |
+
to collect a royalty for further conveying from those to whom you convey
|
| 791 |
+
the Program, the only way you could satisfy both those terms and this
|
| 792 |
+
License would be to refrain entirely from conveying the Program.
|
| 793 |
+
|
| 794 |
+
13. Use with the GNU Affero General Public License.
|
| 795 |
+
|
| 796 |
+
Notwithstanding any other provision of this License, you have
|
| 797 |
+
permission to link or combine any covered work with a work licensed
|
| 798 |
+
under version 3 of the GNU Affero General Public License into a single
|
| 799 |
+
combined work, and to convey the resulting work. The terms of this
|
| 800 |
+
License will continue to apply to the part which is the covered work,
|
| 801 |
+
but the special requirements of the GNU Affero General Public License,
|
| 802 |
+
section 13, concerning interaction through a network will apply to the
|
| 803 |
+
combination as such.
|
| 804 |
+
|
| 805 |
+
14. Revised Versions of this License.
|
| 806 |
+
|
| 807 |
+
The Free Software Foundation may publish revised and/or new versions of
|
| 808 |
+
the GNU General Public License from time to time. Such new versions will
|
| 809 |
+
be similar in spirit to the present version, but may differ in detail to
|
| 810 |
+
address new problems or concerns.
|
| 811 |
+
|
| 812 |
+
Each version is given a distinguishing version number. If the
|
| 813 |
+
Program specifies that a certain numbered version of the GNU General
|
| 814 |
+
Public License "or any later version" applies to it, you have the
|
| 815 |
+
option of following the terms and conditions either of that numbered
|
| 816 |
+
version or of any later version published by the Free Software
|
| 817 |
+
Foundation. If the Program does not specify a version number of the
|
| 818 |
+
GNU General Public License, you may choose any version ever published
|
| 819 |
+
by the Free Software Foundation.
|
| 820 |
+
|
| 821 |
+
If the Program specifies that a proxy can decide which future
|
| 822 |
+
versions of the GNU General Public License can be used, that proxy's
|
| 823 |
+
public statement of acceptance of a version permanently authorizes you
|
| 824 |
+
to choose that version for the Program.
|
| 825 |
+
|
| 826 |
+
Later license versions may give you additional or different
|
| 827 |
+
permissions. However, no additional obligations are imposed on any
|
| 828 |
+
author or copyright holder as a result of your choosing to follow a
|
| 829 |
+
later version.
|
| 830 |
+
|
| 831 |
+
15. Disclaimer of Warranty.
|
| 832 |
+
|
| 833 |
+
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
| 834 |
+
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
| 835 |
+
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
| 836 |
+
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
| 837 |
+
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
| 838 |
+
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
| 839 |
+
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
| 840 |
+
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
| 841 |
+
|
| 842 |
+
16. Limitation of Liability.
|
| 843 |
+
|
| 844 |
+
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
| 845 |
+
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
| 846 |
+
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
| 847 |
+
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
| 848 |
+
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
| 849 |
+
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
| 850 |
+
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
| 851 |
+
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
| 852 |
+
SUCH DAMAGES.
|
| 853 |
+
|
| 854 |
+
17. Interpretation of Sections 15 and 16.
|
| 855 |
+
|
| 856 |
+
If the disclaimer of warranty and limitation of liability provided
|
| 857 |
+
above cannot be given local legal effect according to their terms,
|
| 858 |
+
reviewing courts shall apply local law that most closely approximates
|
| 859 |
+
an absolute waiver of all civil liability in connection with the
|
| 860 |
+
Program, unless a warranty or assumption of liability accompanies a
|
| 861 |
+
copy of the Program in return for a fee.
|
| 862 |
+
|
| 863 |
+
END OF TERMS AND CONDITIONS
|
| 864 |
+
|
| 865 |
+
How to Apply These Terms to Your New Programs
|
| 866 |
+
|
| 867 |
+
If you develop a new program, and you want it to be of the greatest
|
| 868 |
+
possible use to the public, the best way to achieve this is to make it
|
| 869 |
+
free software which everyone can redistribute and change under these terms.
|
| 870 |
+
|
| 871 |
+
To do so, attach the following notices to the program. It is safest
|
| 872 |
+
to attach them to the start of each source file to most effectively
|
| 873 |
+
state the exclusion of warranty; and each file should have at least
|
| 874 |
+
the "copyright" line and a pointer to where the full notice is found.
|
| 875 |
+
|
| 876 |
+
<one line to give the program's name and a brief idea of what it does.>
|
| 877 |
+
Copyright (C) <year> <name of author>
|
| 878 |
+
|
| 879 |
+
This program is free software: you can redistribute it and/or modify
|
| 880 |
+
it under the terms of the GNU General Public License as published by
|
| 881 |
+
the Free Software Foundation, either version 3 of the License, or
|
| 882 |
+
(at your option) any later version.
|
| 883 |
+
|
| 884 |
+
This program is distributed in the hope that it will be useful,
|
| 885 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 886 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 887 |
+
GNU General Public License for more details.
|
| 888 |
+
|
| 889 |
+
You should have received a copy of the GNU General Public License
|
| 890 |
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 891 |
+
|
| 892 |
+
Also add information on how to contact you by electronic and paper mail.
|
| 893 |
+
|
| 894 |
+
If the program does terminal interaction, make it output a short
|
| 895 |
+
notice like this when it starts in an interactive mode:
|
| 896 |
+
|
| 897 |
+
<program> Copyright (C) <year> <name of author>
|
| 898 |
+
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
| 899 |
+
This is free software, and you are welcome to redistribute it
|
| 900 |
+
under certain conditions; type `show c' for details.
|
| 901 |
+
|
| 902 |
+
The hypothetical commands `show w' and `show c' should show the appropriate
|
| 903 |
+
parts of the General Public License. Of course, your program's commands
|
| 904 |
+
might be different; for a GUI interface, you would use an "about box".
|
| 905 |
+
|
| 906 |
+
You should also get your employer (if you work as a programmer) or school,
|
| 907 |
+
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
| 908 |
+
For more information on this, and how to apply and follow the GNU GPL, see
|
| 909 |
+
<http://www.gnu.org/licenses/>.
|
| 910 |
+
|
| 911 |
+
The GNU General Public License does not permit incorporating your program
|
| 912 |
+
into proprietary programs. If your program is a subroutine library, you
|
| 913 |
+
may consider it more useful to permit linking proprietary applications with
|
| 914 |
+
the library. If this is what you want to do, use the GNU Lesser General
|
| 915 |
+
Public License instead of this License. But first, please read
|
| 916 |
+
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
| 917 |
+
|
| 918 |
+
|
| 919 |
+
Name: libquadmath
|
| 920 |
+
Files: scipy.libs/libquadmath*.so
|
| 921 |
+
Description: dynamically linked to files compiled with gcc
|
| 922 |
+
Availability: https://gcc.gnu.org/git/?p=gcc.git;a=tree;f=libquadmath
|
| 923 |
+
License: LGPL-2.1-or-later
|
| 924 |
+
|
| 925 |
+
GCC Quad-Precision Math Library
|
| 926 |
+
Copyright (C) 2010-2019 Free Software Foundation, Inc.
|
| 927 |
+
Written by Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
|
| 928 |
+
|
| 929 |
+
This file is part of the libquadmath library.
|
| 930 |
+
Libquadmath is free software; you can redistribute it and/or
|
| 931 |
+
modify it under the terms of the GNU Library General Public
|
| 932 |
+
License as published by the Free Software Foundation; either
|
| 933 |
+
version 2.1 of the License, or (at your option) any later version.
|
| 934 |
+
|
| 935 |
+
Libquadmath is distributed in the hope that it will be useful,
|
| 936 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 937 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 938 |
+
Lesser General Public License for more details.
|
| 939 |
+
https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
|
| 940 |
+
|
| 941 |
+
Classifier: Development Status :: 5 - Production/Stable
|
| 942 |
+
Classifier: Intended Audience :: Science/Research
|
| 943 |
+
Classifier: Intended Audience :: Developers
|
| 944 |
+
Classifier: License :: OSI Approved :: BSD License
|
| 945 |
+
Classifier: Programming Language :: C
|
| 946 |
+
Classifier: Programming Language :: Python
|
| 947 |
+
Classifier: Programming Language :: Python :: 3
|
| 948 |
+
Classifier: Programming Language :: Python :: 3.10
|
| 949 |
+
Classifier: Programming Language :: Python :: 3.11
|
| 950 |
+
Classifier: Programming Language :: Python :: 3.12
|
| 951 |
+
Classifier: Programming Language :: Python :: 3.13
|
| 952 |
+
Classifier: Topic :: Software Development :: Libraries
|
| 953 |
+
Classifier: Topic :: Scientific/Engineering
|
| 954 |
+
Classifier: Operating System :: Microsoft :: Windows
|
| 955 |
+
Classifier: Operating System :: POSIX :: Linux
|
| 956 |
+
Classifier: Operating System :: POSIX
|
| 957 |
+
Classifier: Operating System :: Unix
|
| 958 |
+
Classifier: Operating System :: MacOS
|
| 959 |
+
Project-URL: homepage, https://scipy.org/
|
| 960 |
+
Project-URL: documentation, https://docs.scipy.org/doc/scipy/
|
| 961 |
+
Project-URL: source, https://github.com/scipy/scipy
|
| 962 |
+
Project-URL: download, https://github.com/scipy/scipy/releases
|
| 963 |
+
Project-URL: tracker, https://github.com/scipy/scipy/issues
|
| 964 |
+
Requires-Python: >=3.10
|
| 965 |
+
Requires-Dist: numpy<2.5,>=1.23.5
|
| 966 |
+
Provides-Extra: test
|
| 967 |
+
Requires-Dist: pytest; extra == "test"
|
| 968 |
+
Requires-Dist: pytest-cov; extra == "test"
|
| 969 |
+
Requires-Dist: pytest-timeout; extra == "test"
|
| 970 |
+
Requires-Dist: pytest-xdist; extra == "test"
|
| 971 |
+
Requires-Dist: asv; extra == "test"
|
| 972 |
+
Requires-Dist: mpmath; extra == "test"
|
| 973 |
+
Requires-Dist: gmpy2; extra == "test"
|
| 974 |
+
Requires-Dist: threadpoolctl; extra == "test"
|
| 975 |
+
Requires-Dist: scikit-umfpack; extra == "test"
|
| 976 |
+
Requires-Dist: pooch; extra == "test"
|
| 977 |
+
Requires-Dist: hypothesis>=6.30; extra == "test"
|
| 978 |
+
Requires-Dist: array-api-strict<2.1.1,>=2.0; extra == "test"
|
| 979 |
+
Requires-Dist: Cython; extra == "test"
|
| 980 |
+
Requires-Dist: meson; extra == "test"
|
| 981 |
+
Requires-Dist: ninja; sys_platform != "emscripten" and extra == "test"
|
| 982 |
+
Provides-Extra: doc
|
| 983 |
+
Requires-Dist: sphinx<8.0.0,>=5.0.0; extra == "doc"
|
| 984 |
+
Requires-Dist: intersphinx_registry; extra == "doc"
|
| 985 |
+
Requires-Dist: pydata-sphinx-theme>=0.15.2; extra == "doc"
|
| 986 |
+
Requires-Dist: sphinx-copybutton; extra == "doc"
|
| 987 |
+
Requires-Dist: sphinx-design>=0.4.0; extra == "doc"
|
| 988 |
+
Requires-Dist: matplotlib>=3.5; extra == "doc"
|
| 989 |
+
Requires-Dist: numpydoc; extra == "doc"
|
| 990 |
+
Requires-Dist: jupytext; extra == "doc"
|
| 991 |
+
Requires-Dist: myst-nb; extra == "doc"
|
| 992 |
+
Requires-Dist: pooch; extra == "doc"
|
| 993 |
+
Requires-Dist: jupyterlite-sphinx>=0.19.1; extra == "doc"
|
| 994 |
+
Requires-Dist: jupyterlite-pyodide-kernel; extra == "doc"
|
| 995 |
+
Provides-Extra: dev
|
| 996 |
+
Requires-Dist: mypy==1.10.0; extra == "dev"
|
| 997 |
+
Requires-Dist: typing_extensions; extra == "dev"
|
| 998 |
+
Requires-Dist: types-psutil; extra == "dev"
|
| 999 |
+
Requires-Dist: pycodestyle; extra == "dev"
|
| 1000 |
+
Requires-Dist: ruff>=0.0.292; extra == "dev"
|
| 1001 |
+
Requires-Dist: cython-lint>=0.12.2; extra == "dev"
|
| 1002 |
+
Requires-Dist: rich-click; extra == "dev"
|
| 1003 |
+
Requires-Dist: doit>=0.36.0; extra == "dev"
|
| 1004 |
+
Requires-Dist: pydevtool; extra == "dev"
|
| 1005 |
+
Description-Content-Type: text/x-rst
|
| 1006 |
+
|
| 1007 |
+
.. image:: https://raw.githubusercontent.com/scipy/scipy/main/doc/source/_static/logo.svg
|
| 1008 |
+
:target: https://scipy.org
|
| 1009 |
+
:width: 110
|
| 1010 |
+
:height: 110
|
| 1011 |
+
:align: left
|
| 1012 |
+
|
| 1013 |
+
.. image:: https://img.shields.io/badge/powered%20by-NumFOCUS-orange.svg?style=flat&colorA=E1523D&colorB=007D8A
|
| 1014 |
+
:target: https://numfocus.org
|
| 1015 |
+
|
| 1016 |
+
.. image:: https://img.shields.io/pypi/dm/scipy.svg?label=Pypi%20downloads
|
| 1017 |
+
:target: https://pypi.org/project/scipy/
|
| 1018 |
+
|
| 1019 |
+
.. image:: https://img.shields.io/conda/dn/conda-forge/scipy.svg?label=Conda%20downloads
|
| 1020 |
+
:target: https://anaconda.org/conda-forge/scipy
|
| 1021 |
+
|
| 1022 |
+
.. image:: https://img.shields.io/badge/stackoverflow-Ask%20questions-blue.svg
|
| 1023 |
+
:target: https://stackoverflow.com/questions/tagged/scipy
|
| 1024 |
+
|
| 1025 |
+
.. image:: https://img.shields.io/badge/DOI-10.1038%2Fs41592--019--0686--2-blue.svg
|
| 1026 |
+
:target: https://www.nature.com/articles/s41592-019-0686-2
|
| 1027 |
+
|
| 1028 |
+
SciPy (pronounced "Sigh Pie") is an open-source software for mathematics,
|
| 1029 |
+
science, and engineering. It includes modules for statistics, optimization,
|
| 1030 |
+
integration, linear algebra, Fourier transforms, signal and image processing,
|
| 1031 |
+
ODE solvers, and more.
|
| 1032 |
+
|
| 1033 |
+
- **Website:** https://scipy.org
|
| 1034 |
+
- **Documentation:** https://docs.scipy.org/doc/scipy/
|
| 1035 |
+
- **Development version of the documentation:** https://scipy.github.io/devdocs
|
| 1036 |
+
- **SciPy development forum:** https://discuss.scientific-python.org/c/contributor/scipy
|
| 1037 |
+
- **Stack Overflow:** https://stackoverflow.com/questions/tagged/scipy
|
| 1038 |
+
- **Source code:** https://github.com/scipy/scipy
|
| 1039 |
+
- **Contributing:** https://scipy.github.io/devdocs/dev/index.html
|
| 1040 |
+
- **Bug reports:** https://github.com/scipy/scipy/issues
|
| 1041 |
+
- **Code of Conduct:** https://docs.scipy.org/doc/scipy/dev/conduct/code_of_conduct.html
|
| 1042 |
+
- **Report a security vulnerability:** https://tidelift.com/docs/security
|
| 1043 |
+
- **Citing in your work:** https://www.scipy.org/citing-scipy/
|
| 1044 |
+
|
| 1045 |
+
SciPy is built to work with
|
| 1046 |
+
NumPy arrays, and provides many user-friendly and efficient numerical routines,
|
| 1047 |
+
such as routines for numerical integration and optimization. Together, they
|
| 1048 |
+
run on all popular operating systems, are quick to install, and are free of
|
| 1049 |
+
charge. NumPy and SciPy are easy to use, but powerful enough to be depended
|
| 1050 |
+
upon by some of the world's leading scientists and engineers. If you need to
|
| 1051 |
+
manipulate numbers on a computer and display or publish the results, give
|
| 1052 |
+
SciPy a try!
|
| 1053 |
+
|
| 1054 |
+
For the installation instructions, see `our install
|
| 1055 |
+
guide <https://scipy.org/install/>`__.
|
| 1056 |
+
|
| 1057 |
+
|
| 1058 |
+
Call for Contributions
|
| 1059 |
+
----------------------
|
| 1060 |
+
|
| 1061 |
+
We appreciate and welcome contributions. Small improvements or fixes are always appreciated; issues labeled as "good
|
| 1062 |
+
first issue" may be a good starting point. Have a look at `our contributing
|
| 1063 |
+
guide <https://scipy.github.io/devdocs/dev/index.html>`__.
|
| 1064 |
+
|
| 1065 |
+
Writing code isn’t the only way to contribute to SciPy. You can also:
|
| 1066 |
+
|
| 1067 |
+
- review pull requests
|
| 1068 |
+
- triage issues
|
| 1069 |
+
- develop tutorials, presentations, and other educational materials
|
| 1070 |
+
- maintain and improve `our website <https://github.com/scipy/scipy.org>`__
|
| 1071 |
+
- develop graphic design for our brand assets and promotional materials
|
| 1072 |
+
- help with outreach and onboard new contributors
|
| 1073 |
+
- write grant proposals and help with other fundraising efforts
|
| 1074 |
+
|
| 1075 |
+
If you’re unsure where to start or how your skills fit in, reach out! You can
|
| 1076 |
+
ask on the `forum <https://discuss.scientific-python.org/c/contributor/scipy>`__
|
| 1077 |
+
or here, on GitHub, by leaving a comment on a relevant issue that is already
|
| 1078 |
+
open.
|
| 1079 |
+
|
| 1080 |
+
If you are new to contributing to open source, `this
|
| 1081 |
+
guide <https://opensource.guide/how-to-contribute/>`__ helps explain why, what,
|
| 1082 |
+
and how to get involved.
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy-1.15.3.dist-info/RECORD
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy-1.15.3.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: meson
|
| 3 |
+
Root-Is-Purelib: false
|
| 4 |
+
Tag: cp310-cp310-manylinux_2_17_x86_64
|
| 5 |
+
Tag: cp310-cp310-manylinux2014_x86_64
|
| 6 |
+
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/hyperg.h
ADDED
|
@@ -0,0 +1,361 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Translated into C++ by SciPy developers in 2024.
|
| 2 |
+
* Original header with Copyright information appears below.
|
| 3 |
+
*/
|
| 4 |
+
|
| 5 |
+
/* hyperg.c
|
| 6 |
+
*
|
| 7 |
+
* Confluent hypergeometric function
|
| 8 |
+
*
|
| 9 |
+
*
|
| 10 |
+
*
|
| 11 |
+
* SYNOPSIS:
|
| 12 |
+
*
|
| 13 |
+
* double a, b, x, y, hyperg();
|
| 14 |
+
*
|
| 15 |
+
* y = hyperg( a, b, x );
|
| 16 |
+
*
|
| 17 |
+
*
|
| 18 |
+
*
|
| 19 |
+
* DESCRIPTION:
|
| 20 |
+
*
|
| 21 |
+
* Computes the confluent hypergeometric function
|
| 22 |
+
*
|
| 23 |
+
* 1 2
|
| 24 |
+
* a x a(a+1) x
|
| 25 |
+
* F ( a,b;x ) = 1 + ---- + --------- + ...
|
| 26 |
+
* 1 1 b 1! b(b+1) 2!
|
| 27 |
+
*
|
| 28 |
+
* Many higher transcendental functions are special cases of
|
| 29 |
+
* this power series.
|
| 30 |
+
*
|
| 31 |
+
* As is evident from the formula, b must not be a negative
|
| 32 |
+
* integer or zero unless a is an integer with 0 >= a > b.
|
| 33 |
+
*
|
| 34 |
+
* The routine attempts both a direct summation of the series
|
| 35 |
+
* and an asymptotic expansion. In each case error due to
|
| 36 |
+
* roundoff, cancellation, and nonconvergence is estimated.
|
| 37 |
+
* The result with smaller estimated error is returned.
|
| 38 |
+
*
|
| 39 |
+
*
|
| 40 |
+
*
|
| 41 |
+
* ACCURACY:
|
| 42 |
+
*
|
| 43 |
+
* Tested at random points (a, b, x), all three variables
|
| 44 |
+
* ranging from 0 to 30.
|
| 45 |
+
* Relative error:
|
| 46 |
+
* arithmetic domain # trials peak rms
|
| 47 |
+
* IEEE 0,30 30000 1.8e-14 1.1e-15
|
| 48 |
+
*
|
| 49 |
+
* Larger errors can be observed when b is near a negative
|
| 50 |
+
* integer or zero. Certain combinations of arguments yield
|
| 51 |
+
* serious cancellation error in the power series summation
|
| 52 |
+
* and also are not in the region of near convergence of the
|
| 53 |
+
* asymptotic series. An error message is printed if the
|
| 54 |
+
* self-estimated relative error is greater than 1.0e-12.
|
| 55 |
+
*
|
| 56 |
+
*/
|
| 57 |
+
|
| 58 |
+
/*
|
| 59 |
+
* Cephes Math Library Release 2.8: June, 2000
|
| 60 |
+
* Copyright 1984, 1987, 1988, 2000 by Stephen L. Moshier
|
| 61 |
+
*/
|
| 62 |
+
|
| 63 |
+
#pragma once
|
| 64 |
+
|
| 65 |
+
#include "../config.h"
|
| 66 |
+
#include "../error.h"
|
| 67 |
+
|
| 68 |
+
#include "const.h"
|
| 69 |
+
#include "gamma.h"
|
| 70 |
+
#include "rgamma.h"
|
| 71 |
+
|
| 72 |
+
namespace xsf {
|
| 73 |
+
namespace cephes {
|
| 74 |
+
|
| 75 |
+
namespace detail {
|
| 76 |
+
|
| 77 |
+
/* the `type` parameter determines what converging factor to use */
|
| 78 |
+
XSF_HOST_DEVICE inline double hyp2f0(double a, double b, double x, int type, double *err) {
|
| 79 |
+
double a0, alast, t, tlast, maxt;
|
| 80 |
+
double n, an, bn, u, sum, temp;
|
| 81 |
+
|
| 82 |
+
an = a;
|
| 83 |
+
bn = b;
|
| 84 |
+
a0 = 1.0e0;
|
| 85 |
+
alast = 1.0e0;
|
| 86 |
+
sum = 0.0;
|
| 87 |
+
n = 1.0e0;
|
| 88 |
+
t = 1.0e0;
|
| 89 |
+
tlast = 1.0e9;
|
| 90 |
+
maxt = 0.0;
|
| 91 |
+
|
| 92 |
+
do {
|
| 93 |
+
if (an == 0)
|
| 94 |
+
goto pdone;
|
| 95 |
+
if (bn == 0)
|
| 96 |
+
goto pdone;
|
| 97 |
+
|
| 98 |
+
u = an * (bn * x / n);
|
| 99 |
+
|
| 100 |
+
/* check for blowup */
|
| 101 |
+
temp = std::abs(u);
|
| 102 |
+
if ((temp > 1.0) && (maxt > (std::numeric_limits<double>::max() / temp)))
|
| 103 |
+
goto error;
|
| 104 |
+
|
| 105 |
+
a0 *= u;
|
| 106 |
+
t = std::abs(a0);
|
| 107 |
+
|
| 108 |
+
/* terminating condition for asymptotic series:
|
| 109 |
+
* the series is divergent (if a or b is not a negative integer),
|
| 110 |
+
* but its leading part can be used as an asymptotic expansion
|
| 111 |
+
*/
|
| 112 |
+
if (t > tlast)
|
| 113 |
+
goto ndone;
|
| 114 |
+
|
| 115 |
+
tlast = t;
|
| 116 |
+
sum += alast; /* the sum is one term behind */
|
| 117 |
+
alast = a0;
|
| 118 |
+
|
| 119 |
+
if (n > 200)
|
| 120 |
+
goto ndone;
|
| 121 |
+
|
| 122 |
+
an += 1.0e0;
|
| 123 |
+
bn += 1.0e0;
|
| 124 |
+
n += 1.0e0;
|
| 125 |
+
if (t > maxt)
|
| 126 |
+
maxt = t;
|
| 127 |
+
} while (t > MACHEP);
|
| 128 |
+
|
| 129 |
+
pdone: /* series converged! */
|
| 130 |
+
|
| 131 |
+
/* estimate error due to roundoff and cancellation */
|
| 132 |
+
*err = std::abs(MACHEP * (n + maxt));
|
| 133 |
+
|
| 134 |
+
alast = a0;
|
| 135 |
+
goto done;
|
| 136 |
+
|
| 137 |
+
ndone: /* series did not converge */
|
| 138 |
+
|
| 139 |
+
/* The following "Converging factors" are supposed to improve accuracy,
|
| 140 |
+
* but do not actually seem to accomplish very much. */
|
| 141 |
+
|
| 142 |
+
n -= 1.0;
|
| 143 |
+
x = 1.0 / x;
|
| 144 |
+
|
| 145 |
+
switch (type) { /* "type" given as subroutine argument */
|
| 146 |
+
case 1:
|
| 147 |
+
alast *= (0.5 + (0.125 + 0.25 * b - 0.5 * a + 0.25 * x - 0.25 * n) / x);
|
| 148 |
+
break;
|
| 149 |
+
|
| 150 |
+
case 2:
|
| 151 |
+
alast *= 2.0 / 3.0 - b + 2.0 * a + x - n;
|
| 152 |
+
break;
|
| 153 |
+
|
| 154 |
+
default:;
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
/* estimate error due to roundoff, cancellation, and nonconvergence */
|
| 158 |
+
*err = MACHEP * (n + maxt) + std::abs(a0);
|
| 159 |
+
|
| 160 |
+
done:
|
| 161 |
+
sum += alast;
|
| 162 |
+
return (sum);
|
| 163 |
+
|
| 164 |
+
/* series blew up: */
|
| 165 |
+
error:
|
| 166 |
+
*err = std::numeric_limits<double>::infinity();
|
| 167 |
+
set_error("hyperg", SF_ERROR_NO_RESULT, NULL);
|
| 168 |
+
return (sum);
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
/* asymptotic formula for hypergeometric function:
|
| 172 |
+
*
|
| 173 |
+
* ( -a
|
| 174 |
+
* -- ( |z|
|
| 175 |
+
* | (b) ( -------- 2f0( a, 1+a-b, -1/x )
|
| 176 |
+
* ( --
|
| 177 |
+
* ( | (b-a)
|
| 178 |
+
*
|
| 179 |
+
*
|
| 180 |
+
* x a-b )
|
| 181 |
+
* e |x| )
|
| 182 |
+
* + -------- 2f0( b-a, 1-a, 1/x ) )
|
| 183 |
+
* -- )
|
| 184 |
+
* | (a) )
|
| 185 |
+
*/
|
| 186 |
+
|
| 187 |
+
XSF_HOST_DEVICE inline double hy1f1a(double a, double b, double x, double *err) {
|
| 188 |
+
double h1, h2, t, u, temp, acanc, asum, err1, err2;
|
| 189 |
+
|
| 190 |
+
if (x == 0) {
|
| 191 |
+
acanc = 1.0;
|
| 192 |
+
asum = std::numeric_limits<double>::infinity();
|
| 193 |
+
goto adone;
|
| 194 |
+
}
|
| 195 |
+
temp = std::log(std::abs(x));
|
| 196 |
+
t = x + temp * (a - b);
|
| 197 |
+
u = -temp * a;
|
| 198 |
+
|
| 199 |
+
if (b > 0) {
|
| 200 |
+
temp = xsf::cephes::lgam(b);
|
| 201 |
+
t += temp;
|
| 202 |
+
u += temp;
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
h1 = hyp2f0(a, a - b + 1, -1.0 / x, 1, &err1);
|
| 206 |
+
|
| 207 |
+
temp = std::exp(u) * xsf::cephes::rgamma(b - a);
|
| 208 |
+
h1 *= temp;
|
| 209 |
+
err1 *= temp;
|
| 210 |
+
|
| 211 |
+
h2 = hyp2f0(b - a, 1.0 - a, 1.0 / x, 2, &err2);
|
| 212 |
+
|
| 213 |
+
if (a < 0)
|
| 214 |
+
temp = std::exp(t) * xsf::cephes::rgamma(a);
|
| 215 |
+
else
|
| 216 |
+
temp = std::exp(t - xsf::cephes::lgam(a));
|
| 217 |
+
|
| 218 |
+
h2 *= temp;
|
| 219 |
+
err2 *= temp;
|
| 220 |
+
|
| 221 |
+
if (x < 0.0)
|
| 222 |
+
asum = h1;
|
| 223 |
+
else
|
| 224 |
+
asum = h2;
|
| 225 |
+
|
| 226 |
+
acanc = std::abs(err1) + std::abs(err2);
|
| 227 |
+
|
| 228 |
+
if (b < 0) {
|
| 229 |
+
temp = xsf::cephes::Gamma(b);
|
| 230 |
+
asum *= temp;
|
| 231 |
+
acanc *= std::abs(temp);
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
if (asum != 0.0)
|
| 235 |
+
acanc /= std::abs(asum);
|
| 236 |
+
|
| 237 |
+
if (acanc != acanc)
|
| 238 |
+
/* nan */
|
| 239 |
+
acanc = 1.0;
|
| 240 |
+
|
| 241 |
+
if (std::isinf(asum))
|
| 242 |
+
/* infinity */
|
| 243 |
+
acanc = 0;
|
| 244 |
+
|
| 245 |
+
acanc *= 30.0; /* fudge factor, since error of asymptotic formula
|
| 246 |
+
* often seems this much larger than advertised */
|
| 247 |
+
adone:
|
| 248 |
+
*err = acanc;
|
| 249 |
+
return (asum);
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
/* Power series summation for confluent hypergeometric function */
|
| 253 |
+
XSF_HOST_DEVICE inline double hy1f1p(double a, double b, double x, double *err) {
|
| 254 |
+
double n, a0, sum, t, u, temp, maxn;
|
| 255 |
+
double an, bn, maxt;
|
| 256 |
+
double y, c, sumc;
|
| 257 |
+
|
| 258 |
+
/* set up for power series summation */
|
| 259 |
+
an = a;
|
| 260 |
+
bn = b;
|
| 261 |
+
a0 = 1.0;
|
| 262 |
+
sum = 1.0;
|
| 263 |
+
c = 0.0;
|
| 264 |
+
n = 1.0;
|
| 265 |
+
t = 1.0;
|
| 266 |
+
maxt = 0.0;
|
| 267 |
+
*err = 1.0;
|
| 268 |
+
|
| 269 |
+
maxn = 200.0 + 2 * fabs(a) + 2 * fabs(b);
|
| 270 |
+
|
| 271 |
+
while (t > MACHEP) {
|
| 272 |
+
if (bn == 0) { /* check bn first since if both */
|
| 273 |
+
sf_error("hyperg", SF_ERROR_SINGULAR, NULL);
|
| 274 |
+
return (std::numeric_limits<double>::infinity()); /* an and bn are zero it is */
|
| 275 |
+
}
|
| 276 |
+
if (an == 0) /* a singularity */
|
| 277 |
+
return (sum);
|
| 278 |
+
if (n > maxn) {
|
| 279 |
+
/* too many terms; take the last one as error estimate */
|
| 280 |
+
c = std::abs(c) + std::abs(t) * 50.0;
|
| 281 |
+
goto pdone;
|
| 282 |
+
}
|
| 283 |
+
u = x * (an / (bn * n));
|
| 284 |
+
|
| 285 |
+
/* check for blowup */
|
| 286 |
+
temp = std::abs(u);
|
| 287 |
+
if ((temp > 1.0) && (maxt > (std::numeric_limits<double>::max() / temp))) {
|
| 288 |
+
*err = 1.0; /* blowup: estimate 100% error */
|
| 289 |
+
return sum;
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
a0 *= u;
|
| 293 |
+
|
| 294 |
+
y = a0 - c;
|
| 295 |
+
sumc = sum + y;
|
| 296 |
+
c = (sumc - sum) - y;
|
| 297 |
+
sum = sumc;
|
| 298 |
+
|
| 299 |
+
t = std::abs(a0);
|
| 300 |
+
|
| 301 |
+
an += 1.0;
|
| 302 |
+
bn += 1.0;
|
| 303 |
+
n += 1.0;
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
pdone:
|
| 307 |
+
|
| 308 |
+
/* estimate error due to roundoff and cancellation */
|
| 309 |
+
if (sum != 0.0) {
|
| 310 |
+
*err = std::abs(c / sum);
|
| 311 |
+
} else {
|
| 312 |
+
*err = std::abs(c);
|
| 313 |
+
}
|
| 314 |
+
|
| 315 |
+
if (*err != *err) {
|
| 316 |
+
/* nan */
|
| 317 |
+
*err = 1.0;
|
| 318 |
+
}
|
| 319 |
+
|
| 320 |
+
return (sum);
|
| 321 |
+
}
|
| 322 |
+
|
| 323 |
+
} // namespace detail
|
| 324 |
+
|
| 325 |
+
XSF_HOST_DEVICE inline double hyperg(double a, double b, double x) {
|
| 326 |
+
double asum, psum, acanc, pcanc, temp;
|
| 327 |
+
|
| 328 |
+
/* See if a Kummer transformation will help */
|
| 329 |
+
temp = b - a;
|
| 330 |
+
if (std::abs(temp) < 0.001 * std::abs(a))
|
| 331 |
+
return (exp(x) * hyperg(temp, b, -x));
|
| 332 |
+
|
| 333 |
+
/* Try power & asymptotic series, starting from the one that is likely OK */
|
| 334 |
+
if (std::abs(x) < 10 + std::abs(a) + std::abs(b)) {
|
| 335 |
+
psum = detail::hy1f1p(a, b, x, &pcanc);
|
| 336 |
+
if (pcanc < 1.0e-15)
|
| 337 |
+
goto done;
|
| 338 |
+
asum = detail::hy1f1a(a, b, x, &acanc);
|
| 339 |
+
} else {
|
| 340 |
+
psum = detail::hy1f1a(a, b, x, &pcanc);
|
| 341 |
+
if (pcanc < 1.0e-15)
|
| 342 |
+
goto done;
|
| 343 |
+
asum = detail::hy1f1p(a, b, x, &acanc);
|
| 344 |
+
}
|
| 345 |
+
|
| 346 |
+
/* Pick the result with less estimated error */
|
| 347 |
+
|
| 348 |
+
if (acanc < pcanc) {
|
| 349 |
+
pcanc = acanc;
|
| 350 |
+
psum = asum;
|
| 351 |
+
}
|
| 352 |
+
|
| 353 |
+
done:
|
| 354 |
+
if (pcanc > 1.0e-12)
|
| 355 |
+
set_error("hyperg", SF_ERROR_LOSS, NULL);
|
| 356 |
+
|
| 357 |
+
return (psum);
|
| 358 |
+
}
|
| 359 |
+
|
| 360 |
+
} // namespace cephes
|
| 361 |
+
} // namespace xsf
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/i0.h
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Translated into C++ by SciPy developers in 2024.
|
| 2 |
+
* Original header with Copyright information appears below.
|
| 3 |
+
*/
|
| 4 |
+
|
| 5 |
+
/* i0.c
|
| 6 |
+
*
|
| 7 |
+
* Modified Bessel function of order zero
|
| 8 |
+
*
|
| 9 |
+
*
|
| 10 |
+
*
|
| 11 |
+
* SYNOPSIS:
|
| 12 |
+
*
|
| 13 |
+
* double x, y, i0();
|
| 14 |
+
*
|
| 15 |
+
* y = i0( x );
|
| 16 |
+
*
|
| 17 |
+
*
|
| 18 |
+
*
|
| 19 |
+
* DESCRIPTION:
|
| 20 |
+
*
|
| 21 |
+
* Returns modified Bessel function of order zero of the
|
| 22 |
+
* argument.
|
| 23 |
+
*
|
| 24 |
+
* The function is defined as i0(x) = j0( ix ).
|
| 25 |
+
*
|
| 26 |
+
* The range is partitioned into the two intervals [0,8] and
|
| 27 |
+
* (8, infinity). Chebyshev polynomial expansions are employed
|
| 28 |
+
* in each interval.
|
| 29 |
+
*
|
| 30 |
+
*
|
| 31 |
+
*
|
| 32 |
+
* ACCURACY:
|
| 33 |
+
*
|
| 34 |
+
* Relative error:
|
| 35 |
+
* arithmetic domain # trials peak rms
|
| 36 |
+
* IEEE 0,30 30000 5.8e-16 1.4e-16
|
| 37 |
+
*
|
| 38 |
+
*/
|
| 39 |
+
/* i0e.c
|
| 40 |
+
*
|
| 41 |
+
* Modified Bessel function of order zero,
|
| 42 |
+
* exponentially scaled
|
| 43 |
+
*
|
| 44 |
+
*
|
| 45 |
+
*
|
| 46 |
+
* SYNOPSIS:
|
| 47 |
+
*
|
| 48 |
+
* double x, y, i0e();
|
| 49 |
+
*
|
| 50 |
+
* y = i0e( x );
|
| 51 |
+
*
|
| 52 |
+
*
|
| 53 |
+
*
|
| 54 |
+
* DESCRIPTION:
|
| 55 |
+
*
|
| 56 |
+
* Returns exponentially scaled modified Bessel function
|
| 57 |
+
* of order zero of the argument.
|
| 58 |
+
*
|
| 59 |
+
* The function is defined as i0e(x) = exp(-|x|) j0( ix ).
|
| 60 |
+
*
|
| 61 |
+
*
|
| 62 |
+
*
|
| 63 |
+
* ACCURACY:
|
| 64 |
+
*
|
| 65 |
+
* Relative error:
|
| 66 |
+
* arithmetic domain # trials peak rms
|
| 67 |
+
* IEEE 0,30 30000 5.4e-16 1.2e-16
|
| 68 |
+
* See i0().
|
| 69 |
+
*
|
| 70 |
+
*/
|
| 71 |
+
|
| 72 |
+
/* i0.c */
|
| 73 |
+
|
| 74 |
+
/*
|
| 75 |
+
* Cephes Math Library Release 2.8: June, 2000
|
| 76 |
+
* Copyright 1984, 1987, 2000 by Stephen L. Moshier
|
| 77 |
+
*/
|
| 78 |
+
#pragma once
|
| 79 |
+
|
| 80 |
+
#include "../config.h"
|
| 81 |
+
#include "chbevl.h"
|
| 82 |
+
|
| 83 |
+
namespace xsf {
|
| 84 |
+
namespace cephes {
|
| 85 |
+
|
| 86 |
+
namespace detail {
|
| 87 |
+
|
| 88 |
+
/* Chebyshev coefficients for exp(-x) I0(x)
|
| 89 |
+
* in the interval [0,8].
|
| 90 |
+
*
|
| 91 |
+
* lim(x->0){ exp(-x) I0(x) } = 1.
|
| 92 |
+
*/
|
| 93 |
+
constexpr double i0_A[] = {
|
| 94 |
+
-4.41534164647933937950E-18, 3.33079451882223809783E-17, -2.43127984654795469359E-16,
|
| 95 |
+
1.71539128555513303061E-15, -1.16853328779934516808E-14, 7.67618549860493561688E-14,
|
| 96 |
+
-4.85644678311192946090E-13, 2.95505266312963983461E-12, -1.72682629144155570723E-11,
|
| 97 |
+
9.67580903537323691224E-11, -5.18979560163526290666E-10, 2.65982372468238665035E-9,
|
| 98 |
+
-1.30002500998624804212E-8, 6.04699502254191894932E-8, -2.67079385394061173391E-7,
|
| 99 |
+
1.11738753912010371815E-6, -4.41673835845875056359E-6, 1.64484480707288970893E-5,
|
| 100 |
+
-5.75419501008210370398E-5, 1.88502885095841655729E-4, -5.76375574538582365885E-4,
|
| 101 |
+
1.63947561694133579842E-3, -4.32430999505057594430E-3, 1.05464603945949983183E-2,
|
| 102 |
+
-2.37374148058994688156E-2, 4.93052842396707084878E-2, -9.49010970480476444210E-2,
|
| 103 |
+
1.71620901522208775349E-1, -3.04682672343198398683E-1, 6.76795274409476084995E-1};
|
| 104 |
+
|
| 105 |
+
/* Chebyshev coefficients for exp(-x) sqrt(x) I0(x)
|
| 106 |
+
* in the inverted interval [8,infinity].
|
| 107 |
+
*
|
| 108 |
+
* lim(x->inf){ exp(-x) sqrt(x) I0(x) } = 1/sqrt(2pi).
|
| 109 |
+
*/
|
| 110 |
+
constexpr double i0_B[] = {
|
| 111 |
+
-7.23318048787475395456E-18, -4.83050448594418207126E-18, 4.46562142029675999901E-17,
|
| 112 |
+
3.46122286769746109310E-17, -2.82762398051658348494E-16, -3.42548561967721913462E-16,
|
| 113 |
+
1.77256013305652638360E-15, 3.81168066935262242075E-15, -9.55484669882830764870E-15,
|
| 114 |
+
-4.15056934728722208663E-14, 1.54008621752140982691E-14, 3.85277838274214270114E-13,
|
| 115 |
+
7.18012445138366623367E-13, -1.79417853150680611778E-12, -1.32158118404477131188E-11,
|
| 116 |
+
-3.14991652796324136454E-11, 1.18891471078464383424E-11, 4.94060238822496958910E-10,
|
| 117 |
+
3.39623202570838634515E-9, 2.26666899049817806459E-8, 2.04891858946906374183E-7,
|
| 118 |
+
2.89137052083475648297E-6, 6.88975834691682398426E-5, 3.36911647825569408990E-3,
|
| 119 |
+
8.04490411014108831608E-1};
|
| 120 |
+
} // namespace detail
|
| 121 |
+
|
| 122 |
+
XSF_HOST_DEVICE inline double i0(double x) {
|
| 123 |
+
double y;
|
| 124 |
+
|
| 125 |
+
if (x < 0)
|
| 126 |
+
x = -x;
|
| 127 |
+
if (x <= 8.0) {
|
| 128 |
+
y = (x / 2.0) - 2.0;
|
| 129 |
+
return (std::exp(x) * chbevl(y, detail::i0_A, 30));
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
return (std::exp(x) * chbevl(32.0 / x - 2.0, detail::i0_B, 25) / sqrt(x));
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
XSF_HOST_DEVICE inline double i0e(double x) {
|
| 136 |
+
double y;
|
| 137 |
+
|
| 138 |
+
if (x < 0)
|
| 139 |
+
x = -x;
|
| 140 |
+
if (x <= 8.0) {
|
| 141 |
+
y = (x / 2.0) - 2.0;
|
| 142 |
+
return (chbevl(y, detail::i0_A, 30));
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
return (chbevl(32.0 / x - 2.0, detail::i0_B, 25) / std::sqrt(x));
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
} // namespace cephes
|
| 149 |
+
} // namespace xsf
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/i1.h
ADDED
|
@@ -0,0 +1,158 @@
|
|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 4 |
+
|
| 5 |
+
/* i1.c
|
| 6 |
+
*
|
| 7 |
+
* Modified Bessel function of order one
|
| 8 |
+
*
|
| 9 |
+
*
|
| 10 |
+
*
|
| 11 |
+
* SYNOPSIS:
|
| 12 |
+
*
|
| 13 |
+
* double x, y, i1();
|
| 14 |
+
*
|
| 15 |
+
* y = i1( x );
|
| 16 |
+
*
|
| 17 |
+
*
|
| 18 |
+
*
|
| 19 |
+
* DESCRIPTION:
|
| 20 |
+
*
|
| 21 |
+
* Returns modified Bessel function of order one of the
|
| 22 |
+
* argument.
|
| 23 |
+
*
|
| 24 |
+
* The function is defined as i1(x) = -i j1( ix ).
|
| 25 |
+
*
|
| 26 |
+
* The range is partitioned into the two intervals [0,8] and
|
| 27 |
+
* (8, infinity). Chebyshev polynomial expansions are employed
|
| 28 |
+
* in each interval.
|
| 29 |
+
*
|
| 30 |
+
*
|
| 31 |
+
*
|
| 32 |
+
* ACCURACY:
|
| 33 |
+
*
|
| 34 |
+
* Relative error:
|
| 35 |
+
* arithmetic domain # trials peak rms
|
| 36 |
+
* IEEE 0, 30 30000 1.9e-15 2.1e-16
|
| 37 |
+
*
|
| 38 |
+
*
|
| 39 |
+
*/
|
| 40 |
+
/* i1e.c
|
| 41 |
+
*
|
| 42 |
+
* Modified Bessel function of order one,
|
| 43 |
+
* exponentially scaled
|
| 44 |
+
*
|
| 45 |
+
*
|
| 46 |
+
*
|
| 47 |
+
* SYNOPSIS:
|
| 48 |
+
*
|
| 49 |
+
* double x, y, i1e();
|
| 50 |
+
*
|
| 51 |
+
* y = i1e( x );
|
| 52 |
+
*
|
| 53 |
+
*
|
| 54 |
+
*
|
| 55 |
+
* DESCRIPTION:
|
| 56 |
+
*
|
| 57 |
+
* Returns exponentially scaled modified Bessel function
|
| 58 |
+
* of order one of the argument.
|
| 59 |
+
*
|
| 60 |
+
* The function is defined as i1(x) = -i exp(-|x|) j1( ix ).
|
| 61 |
+
*
|
| 62 |
+
*
|
| 63 |
+
*
|
| 64 |
+
* ACCURACY:
|
| 65 |
+
*
|
| 66 |
+
* Relative error:
|
| 67 |
+
* arithmetic domain # trials peak rms
|
| 68 |
+
* IEEE 0, 30 30000 2.0e-15 2.0e-16
|
| 69 |
+
* See i1().
|
| 70 |
+
*
|
| 71 |
+
*/
|
| 72 |
+
|
| 73 |
+
/* i1.c 2 */
|
| 74 |
+
|
| 75 |
+
/*
|
| 76 |
+
* Cephes Math Library Release 2.8: June, 2000
|
| 77 |
+
* Copyright 1985, 1987, 2000 by Stephen L. Moshier
|
| 78 |
+
*/
|
| 79 |
+
#pragma once
|
| 80 |
+
|
| 81 |
+
#include "../config.h"
|
| 82 |
+
#include "chbevl.h"
|
| 83 |
+
|
| 84 |
+
namespace xsf {
|
| 85 |
+
namespace cephes {
|
| 86 |
+
|
| 87 |
+
namespace detail {
|
| 88 |
+
|
| 89 |
+
/* Chebyshev coefficients for exp(-x) I1(x) / x
|
| 90 |
+
* in the interval [0,8].
|
| 91 |
+
*
|
| 92 |
+
* lim(x->0){ exp(-x) I1(x) / x } = 1/2.
|
| 93 |
+
*/
|
| 94 |
+
|
| 95 |
+
constexpr double i1_A[] = {
|
| 96 |
+
2.77791411276104639959E-18, -2.11142121435816608115E-17, 1.55363195773620046921E-16,
|
| 97 |
+
-1.10559694773538630805E-15, 7.60068429473540693410E-15, -5.04218550472791168711E-14,
|
| 98 |
+
3.22379336594557470981E-13, -1.98397439776494371520E-12, 1.17361862988909016308E-11,
|
| 99 |
+
-6.66348972350202774223E-11, 3.62559028155211703701E-10, -1.88724975172282928790E-9,
|
| 100 |
+
9.38153738649577178388E-9, -4.44505912879632808065E-8, 2.00329475355213526229E-7,
|
| 101 |
+
-8.56872026469545474066E-7, 3.47025130813767847674E-6, -1.32731636560394358279E-5,
|
| 102 |
+
4.78156510755005422638E-5, -1.61760815825896745588E-4, 5.12285956168575772895E-4,
|
| 103 |
+
-1.51357245063125314899E-3, 4.15642294431288815669E-3, -1.05640848946261981558E-2,
|
| 104 |
+
2.47264490306265168283E-2, -5.29459812080949914269E-2, 1.02643658689847095384E-1,
|
| 105 |
+
-1.76416518357834055153E-1, 2.52587186443633654823E-1};
|
| 106 |
+
|
| 107 |
+
/* Chebyshev coefficients for exp(-x) sqrt(x) I1(x)
|
| 108 |
+
* in the inverted interval [8,infinity].
|
| 109 |
+
*
|
| 110 |
+
* lim(x->inf){ exp(-x) sqrt(x) I1(x) } = 1/sqrt(2pi).
|
| 111 |
+
*/
|
| 112 |
+
constexpr double i1_B[] = {
|
| 113 |
+
7.51729631084210481353E-18, 4.41434832307170791151E-18, -4.65030536848935832153E-17,
|
| 114 |
+
-3.20952592199342395980E-17, 2.96262899764595013876E-16, 3.30820231092092828324E-16,
|
| 115 |
+
-1.88035477551078244854E-15, -3.81440307243700780478E-15, 1.04202769841288027642E-14,
|
| 116 |
+
4.27244001671195135429E-14, -2.10154184277266431302E-14, -4.08355111109219731823E-13,
|
| 117 |
+
-7.19855177624590851209E-13, 2.03562854414708950722E-12, 1.41258074366137813316E-11,
|
| 118 |
+
3.25260358301548823856E-11, -1.89749581235054123450E-11, -5.58974346219658380687E-10,
|
| 119 |
+
-3.83538038596423702205E-9, -2.63146884688951950684E-8, -2.51223623787020892529E-7,
|
| 120 |
+
-3.88256480887769039346E-6, -1.10588938762623716291E-4, -9.76109749136146840777E-3,
|
| 121 |
+
7.78576235018280120474E-1};
|
| 122 |
+
|
| 123 |
+
} // namespace detail
|
| 124 |
+
|
| 125 |
+
XSF_HOST_DEVICE inline double i1(double x) {
|
| 126 |
+
double y, z;
|
| 127 |
+
|
| 128 |
+
z = std::abs(x);
|
| 129 |
+
if (z <= 8.0) {
|
| 130 |
+
y = (z / 2.0) - 2.0;
|
| 131 |
+
z = chbevl(y, detail::i1_A, 29) * z * std::exp(z);
|
| 132 |
+
} else {
|
| 133 |
+
z = std::exp(z) * chbevl(32.0 / z - 2.0, detail::i1_B, 25) / std::sqrt(z);
|
| 134 |
+
}
|
| 135 |
+
if (x < 0.0)
|
| 136 |
+
z = -z;
|
| 137 |
+
return (z);
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
/* i1e() */
|
| 141 |
+
|
| 142 |
+
XSF_HOST_DEVICE inline double i1e(double x) {
|
| 143 |
+
double y, z;
|
| 144 |
+
|
| 145 |
+
z = std::abs(x);
|
| 146 |
+
if (z <= 8.0) {
|
| 147 |
+
y = (z / 2.0) - 2.0;
|
| 148 |
+
z = chbevl(y, detail::i1_A, 29) * z;
|
| 149 |
+
} else {
|
| 150 |
+
z = chbevl(32.0 / z - 2.0, detail::i1_B, 25) / std::sqrt(z);
|
| 151 |
+
}
|
| 152 |
+
if (x < 0.0)
|
| 153 |
+
z = -z;
|
| 154 |
+
return (z);
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
} // namespace cephes
|
| 158 |
+
} // namespace xsf
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/igam.h
ADDED
|
@@ -0,0 +1,421 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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original header with Copyright information appears below.
|
| 3 |
+
*/
|
| 4 |
+
|
| 5 |
+
/* igam.c
|
| 6 |
+
*
|
| 7 |
+
* Incomplete Gamma integral
|
| 8 |
+
*
|
| 9 |
+
*
|
| 10 |
+
*
|
| 11 |
+
* SYNOPSIS:
|
| 12 |
+
*
|
| 13 |
+
* double a, x, y, igam();
|
| 14 |
+
*
|
| 15 |
+
* y = igam( a, x );
|
| 16 |
+
*
|
| 17 |
+
* DESCRIPTION:
|
| 18 |
+
*
|
| 19 |
+
* The function is defined by
|
| 20 |
+
*
|
| 21 |
+
* x
|
| 22 |
+
* -
|
| 23 |
+
* 1 | | -t a-1
|
| 24 |
+
* igam(a,x) = ----- | e t dt.
|
| 25 |
+
* - | |
|
| 26 |
+
* | (a) -
|
| 27 |
+
* 0
|
| 28 |
+
*
|
| 29 |
+
*
|
| 30 |
+
* In this implementation both arguments must be positive.
|
| 31 |
+
* The integral is evaluated by either a power series or
|
| 32 |
+
* continued fraction expansion, depending on the relative
|
| 33 |
+
* values of a and x.
|
| 34 |
+
*
|
| 35 |
+
* ACCURACY:
|
| 36 |
+
*
|
| 37 |
+
* Relative error:
|
| 38 |
+
* arithmetic domain # trials peak rms
|
| 39 |
+
* IEEE 0,30 200000 3.6e-14 2.9e-15
|
| 40 |
+
* IEEE 0,100 300000 9.9e-14 1.5e-14
|
| 41 |
+
*/
|
| 42 |
+
/* igamc()
|
| 43 |
+
*
|
| 44 |
+
* Complemented incomplete Gamma integral
|
| 45 |
+
*
|
| 46 |
+
*
|
| 47 |
+
*
|
| 48 |
+
* SYNOPSIS:
|
| 49 |
+
*
|
| 50 |
+
* double a, x, y, igamc();
|
| 51 |
+
*
|
| 52 |
+
* y = igamc( a, x );
|
| 53 |
+
*
|
| 54 |
+
* DESCRIPTION:
|
| 55 |
+
*
|
| 56 |
+
* The function is defined by
|
| 57 |
+
*
|
| 58 |
+
*
|
| 59 |
+
* igamc(a,x) = 1 - igam(a,x)
|
| 60 |
+
*
|
| 61 |
+
* inf.
|
| 62 |
+
* -
|
| 63 |
+
* 1 | | -t a-1
|
| 64 |
+
* = ----- | e t dt.
|
| 65 |
+
* - | |
|
| 66 |
+
* | (a) -
|
| 67 |
+
* x
|
| 68 |
+
*
|
| 69 |
+
*
|
| 70 |
+
* In this implementation both arguments must be positive.
|
| 71 |
+
* The integral is evaluated by either a power series or
|
| 72 |
+
* continued fraction expansion, depending on the relative
|
| 73 |
+
* values of a and x.
|
| 74 |
+
*
|
| 75 |
+
* ACCURACY:
|
| 76 |
+
*
|
| 77 |
+
* Tested at random a, x.
|
| 78 |
+
* a x Relative error:
|
| 79 |
+
* arithmetic domain domain # trials peak rms
|
| 80 |
+
* IEEE 0.5,100 0,100 200000 1.9e-14 1.7e-15
|
| 81 |
+
* IEEE 0.01,0.5 0,100 200000 1.4e-13 1.6e-15
|
| 82 |
+
*/
|
| 83 |
+
|
| 84 |
+
/*
|
| 85 |
+
* Cephes Math Library Release 2.0: April, 1987
|
| 86 |
+
* Copyright 1985, 1987 by Stephen L. Moshier
|
| 87 |
+
* Direct inquiries to 30 Frost Street, Cambridge, MA 02140
|
| 88 |
+
*/
|
| 89 |
+
|
| 90 |
+
/* Sources
|
| 91 |
+
* [1] "The Digital Library of Mathematical Functions", dlmf.nist.gov
|
| 92 |
+
* [2] Maddock et. al., "Incomplete Gamma Functions",
|
| 93 |
+
* https://www.boost.org/doc/libs/1_61_0/libs/math/doc/html/math_toolkit/sf_gamma/igamma.html
|
| 94 |
+
*/
|
| 95 |
+
|
| 96 |
+
/* Scipy changes:
|
| 97 |
+
* - 05-01-2016: added asymptotic expansion for igam to improve the
|
| 98 |
+
* a ~ x regime.
|
| 99 |
+
* - 06-19-2016: additional series expansion added for igamc to
|
| 100 |
+
* improve accuracy at small arguments.
|
| 101 |
+
* - 06-24-2016: better choice of domain for the asymptotic series;
|
| 102 |
+
* improvements in accuracy for the asymptotic series when a and x
|
| 103 |
+
* are very close.
|
| 104 |
+
*/
|
| 105 |
+
#pragma once
|
| 106 |
+
|
| 107 |
+
#include "../config.h"
|
| 108 |
+
#include "../error.h"
|
| 109 |
+
|
| 110 |
+
#include "const.h"
|
| 111 |
+
#include "gamma.h"
|
| 112 |
+
#include "igam_asymp_coeff.h"
|
| 113 |
+
#include "lanczos.h"
|
| 114 |
+
#include "ndtr.h"
|
| 115 |
+
#include "unity.h"
|
| 116 |
+
|
| 117 |
+
namespace xsf {
|
| 118 |
+
namespace cephes {
|
| 119 |
+
|
| 120 |
+
namespace detail {
|
| 121 |
+
|
| 122 |
+
constexpr int igam_MAXITER = 2000;
|
| 123 |
+
constexpr int IGAM = 1;
|
| 124 |
+
constexpr int IGAMC = 0;
|
| 125 |
+
constexpr double igam_SMALL = 20;
|
| 126 |
+
constexpr double igam_LARGE = 200;
|
| 127 |
+
constexpr double igam_SMALLRATIO = 0.3;
|
| 128 |
+
constexpr double igam_LARGERATIO = 4.5;
|
| 129 |
+
|
| 130 |
+
constexpr double igam_big = 4.503599627370496e15;
|
| 131 |
+
constexpr double igam_biginv = 2.22044604925031308085e-16;
|
| 132 |
+
|
| 133 |
+
/* Compute
|
| 134 |
+
*
|
| 135 |
+
* x^a * exp(-x) / gamma(a)
|
| 136 |
+
*
|
| 137 |
+
* corrected from (15) and (16) in [2] by replacing exp(x - a) with
|
| 138 |
+
* exp(a - x).
|
| 139 |
+
*/
|
| 140 |
+
XSF_HOST_DEVICE inline double igam_fac(double a, double x) {
|
| 141 |
+
double ax, fac, res, num;
|
| 142 |
+
|
| 143 |
+
if (std::abs(a - x) > 0.4 * std::abs(a)) {
|
| 144 |
+
ax = a * std::log(x) - x - xsf::cephes::lgam(a);
|
| 145 |
+
if (ax < -MAXLOG) {
|
| 146 |
+
set_error("igam", SF_ERROR_UNDERFLOW, NULL);
|
| 147 |
+
return 0.0;
|
| 148 |
+
}
|
| 149 |
+
return std::exp(ax);
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
fac = a + xsf::cephes::lanczos_g - 0.5;
|
| 153 |
+
res = std::sqrt(fac / std::exp(1)) / xsf::cephes::lanczos_sum_expg_scaled(a);
|
| 154 |
+
|
| 155 |
+
if ((a < 200) && (x < 200)) {
|
| 156 |
+
res *= std::exp(a - x) * std::pow(x / fac, a);
|
| 157 |
+
} else {
|
| 158 |
+
num = x - a - xsf::cephes::lanczos_g + 0.5;
|
| 159 |
+
res *= std::exp(a * xsf::cephes::log1pmx(num / fac) + x * (0.5 - xsf::cephes::lanczos_g) / fac);
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
return res;
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
/* Compute igamc using DLMF 8.9.2. */
|
| 166 |
+
XSF_HOST_DEVICE inline double igamc_continued_fraction(double a, double x) {
|
| 167 |
+
int i;
|
| 168 |
+
double ans, ax, c, yc, r, t, y, z;
|
| 169 |
+
double pk, pkm1, pkm2, qk, qkm1, qkm2;
|
| 170 |
+
|
| 171 |
+
ax = igam_fac(a, x);
|
| 172 |
+
if (ax == 0.0) {
|
| 173 |
+
return 0.0;
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
/* continued fraction */
|
| 177 |
+
y = 1.0 - a;
|
| 178 |
+
z = x + y + 1.0;
|
| 179 |
+
c = 0.0;
|
| 180 |
+
pkm2 = 1.0;
|
| 181 |
+
qkm2 = x;
|
| 182 |
+
pkm1 = x + 1.0;
|
| 183 |
+
qkm1 = z * x;
|
| 184 |
+
ans = pkm1 / qkm1;
|
| 185 |
+
|
| 186 |
+
for (i = 0; i < igam_MAXITER; i++) {
|
| 187 |
+
c += 1.0;
|
| 188 |
+
y += 1.0;
|
| 189 |
+
z += 2.0;
|
| 190 |
+
yc = y * c;
|
| 191 |
+
pk = pkm1 * z - pkm2 * yc;
|
| 192 |
+
qk = qkm1 * z - qkm2 * yc;
|
| 193 |
+
if (qk != 0) {
|
| 194 |
+
r = pk / qk;
|
| 195 |
+
t = std::abs((ans - r) / r);
|
| 196 |
+
ans = r;
|
| 197 |
+
} else
|
| 198 |
+
t = 1.0;
|
| 199 |
+
pkm2 = pkm1;
|
| 200 |
+
pkm1 = pk;
|
| 201 |
+
qkm2 = qkm1;
|
| 202 |
+
qkm1 = qk;
|
| 203 |
+
if (std::abs(pk) > igam_big) {
|
| 204 |
+
pkm2 *= igam_biginv;
|
| 205 |
+
pkm1 *= igam_biginv;
|
| 206 |
+
qkm2 *= igam_biginv;
|
| 207 |
+
qkm1 *= igam_biginv;
|
| 208 |
+
}
|
| 209 |
+
if (t <= MACHEP) {
|
| 210 |
+
break;
|
| 211 |
+
}
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
return (ans * ax);
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
/* Compute igam using DLMF 8.11.4. */
|
| 218 |
+
XSF_HOST_DEVICE inline double igam_series(double a, double x) {
|
| 219 |
+
int i;
|
| 220 |
+
double ans, ax, c, r;
|
| 221 |
+
|
| 222 |
+
ax = igam_fac(a, x);
|
| 223 |
+
if (ax == 0.0) {
|
| 224 |
+
return 0.0;
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
/* power series */
|
| 228 |
+
r = a;
|
| 229 |
+
c = 1.0;
|
| 230 |
+
ans = 1.0;
|
| 231 |
+
|
| 232 |
+
for (i = 0; i < igam_MAXITER; i++) {
|
| 233 |
+
r += 1.0;
|
| 234 |
+
c *= x / r;
|
| 235 |
+
ans += c;
|
| 236 |
+
if (c <= MACHEP * ans) {
|
| 237 |
+
break;
|
| 238 |
+
}
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
return (ans * ax / a);
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
/* Compute igamc using DLMF 8.7.3. This is related to the series in
|
| 245 |
+
* igam_series but extra care is taken to avoid cancellation.
|
| 246 |
+
*/
|
| 247 |
+
XSF_HOST_DEVICE inline double igamc_series(double a, double x) {
|
| 248 |
+
int n;
|
| 249 |
+
double fac = 1;
|
| 250 |
+
double sum = 0;
|
| 251 |
+
double term, logx;
|
| 252 |
+
|
| 253 |
+
for (n = 1; n < igam_MAXITER; n++) {
|
| 254 |
+
fac *= -x / n;
|
| 255 |
+
term = fac / (a + n);
|
| 256 |
+
sum += term;
|
| 257 |
+
if (std::abs(term) <= MACHEP * std::abs(sum)) {
|
| 258 |
+
break;
|
| 259 |
+
}
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
logx = std::log(x);
|
| 263 |
+
term = -xsf::cephes::expm1(a * logx - xsf::cephes::lgam1p(a));
|
| 264 |
+
return term - std::exp(a * logx - xsf::cephes::lgam(a)) * sum;
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
/* Compute igam/igamc using DLMF 8.12.3/8.12.4. */
|
| 268 |
+
XSF_HOST_DEVICE inline double asymptotic_series(double a, double x, int func) {
|
| 269 |
+
int k, n, sgn;
|
| 270 |
+
int maxpow = 0;
|
| 271 |
+
double lambda = x / a;
|
| 272 |
+
double sigma = (x - a) / a;
|
| 273 |
+
double eta, res, ck, ckterm, term, absterm;
|
| 274 |
+
double absoldterm = std::numeric_limits<double>::infinity();
|
| 275 |
+
double etapow[detail::igam_asymp_coeff_N] = {1};
|
| 276 |
+
double sum = 0;
|
| 277 |
+
double afac = 1;
|
| 278 |
+
|
| 279 |
+
if (func == detail::IGAM) {
|
| 280 |
+
sgn = -1;
|
| 281 |
+
} else {
|
| 282 |
+
sgn = 1;
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
if (lambda > 1) {
|
| 286 |
+
eta = std::sqrt(-2 * xsf::cephes::log1pmx(sigma));
|
| 287 |
+
} else if (lambda < 1) {
|
| 288 |
+
eta = -std::sqrt(-2 * xsf::cephes::log1pmx(sigma));
|
| 289 |
+
} else {
|
| 290 |
+
eta = 0;
|
| 291 |
+
}
|
| 292 |
+
res = 0.5 * xsf::cephes::erfc(sgn * eta * std::sqrt(a / 2));
|
| 293 |
+
|
| 294 |
+
for (k = 0; k < igam_asymp_coeff_K; k++) {
|
| 295 |
+
ck = igam_asymp_coeff_d[k][0];
|
| 296 |
+
for (n = 1; n < igam_asymp_coeff_N; n++) {
|
| 297 |
+
if (n > maxpow) {
|
| 298 |
+
etapow[n] = eta * etapow[n - 1];
|
| 299 |
+
maxpow += 1;
|
| 300 |
+
}
|
| 301 |
+
ckterm = igam_asymp_coeff_d[k][n] * etapow[n];
|
| 302 |
+
ck += ckterm;
|
| 303 |
+
if (std::abs(ckterm) < MACHEP * std::abs(ck)) {
|
| 304 |
+
break;
|
| 305 |
+
}
|
| 306 |
+
}
|
| 307 |
+
term = ck * afac;
|
| 308 |
+
absterm = std::abs(term);
|
| 309 |
+
if (absterm > absoldterm) {
|
| 310 |
+
break;
|
| 311 |
+
}
|
| 312 |
+
sum += term;
|
| 313 |
+
if (absterm < MACHEP * std::abs(sum)) {
|
| 314 |
+
break;
|
| 315 |
+
}
|
| 316 |
+
absoldterm = absterm;
|
| 317 |
+
afac /= a;
|
| 318 |
+
}
|
| 319 |
+
res += sgn * std::exp(-0.5 * a * eta * eta) * sum / std::sqrt(2 * M_PI * a);
|
| 320 |
+
|
| 321 |
+
return res;
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
} // namespace detail
|
| 325 |
+
|
| 326 |
+
XSF_HOST_DEVICE inline double igamc(double a, double x);
|
| 327 |
+
|
| 328 |
+
XSF_HOST_DEVICE inline double igam(double a, double x) {
|
| 329 |
+
double absxma_a;
|
| 330 |
+
|
| 331 |
+
if (x < 0 || a < 0) {
|
| 332 |
+
set_error("gammainc", SF_ERROR_DOMAIN, NULL);
|
| 333 |
+
return std::numeric_limits<double>::quiet_NaN();
|
| 334 |
+
} else if (a == 0) {
|
| 335 |
+
if (x > 0) {
|
| 336 |
+
return 1;
|
| 337 |
+
} else {
|
| 338 |
+
return std::numeric_limits<double>::quiet_NaN();
|
| 339 |
+
}
|
| 340 |
+
} else if (x == 0) {
|
| 341 |
+
/* Zero integration limit */
|
| 342 |
+
return 0;
|
| 343 |
+
} else if (std::isinf(a)) {
|
| 344 |
+
if (std::isinf(x)) {
|
| 345 |
+
return std::numeric_limits<double>::quiet_NaN();
|
| 346 |
+
}
|
| 347 |
+
return 0;
|
| 348 |
+
} else if (std::isinf(x)) {
|
| 349 |
+
return 1;
|
| 350 |
+
}
|
| 351 |
+
|
| 352 |
+
/* Asymptotic regime where a ~ x; see [2]. */
|
| 353 |
+
absxma_a = std::abs(x - a) / a;
|
| 354 |
+
if ((a > detail::igam_SMALL) && (a < detail::igam_LARGE) && (absxma_a < detail::igam_SMALLRATIO)) {
|
| 355 |
+
return detail::asymptotic_series(a, x, detail::IGAM);
|
| 356 |
+
} else if ((a > detail::igam_LARGE) && (absxma_a < detail::igam_LARGERATIO / std::sqrt(a))) {
|
| 357 |
+
return detail::asymptotic_series(a, x, detail::IGAM);
|
| 358 |
+
}
|
| 359 |
+
|
| 360 |
+
if ((x > 1.0) && (x > a)) {
|
| 361 |
+
return (1.0 - igamc(a, x));
|
| 362 |
+
}
|
| 363 |
+
|
| 364 |
+
return detail::igam_series(a, x);
|
| 365 |
+
}
|
| 366 |
+
|
| 367 |
+
XSF_HOST_DEVICE double igamc(double a, double x) {
|
| 368 |
+
double absxma_a;
|
| 369 |
+
|
| 370 |
+
if (x < 0 || a < 0) {
|
| 371 |
+
set_error("gammaincc", SF_ERROR_DOMAIN, NULL);
|
| 372 |
+
return std::numeric_limits<double>::quiet_NaN();
|
| 373 |
+
} else if (a == 0) {
|
| 374 |
+
if (x > 0) {
|
| 375 |
+
return 0;
|
| 376 |
+
} else {
|
| 377 |
+
return std::numeric_limits<double>::quiet_NaN();
|
| 378 |
+
}
|
| 379 |
+
} else if (x == 0) {
|
| 380 |
+
return 1;
|
| 381 |
+
} else if (std::isinf(a)) {
|
| 382 |
+
if (std::isinf(x)) {
|
| 383 |
+
return std::numeric_limits<double>::quiet_NaN();
|
| 384 |
+
}
|
| 385 |
+
return 1;
|
| 386 |
+
} else if (std::isinf(x)) {
|
| 387 |
+
return 0;
|
| 388 |
+
}
|
| 389 |
+
|
| 390 |
+
/* Asymptotic regime where a ~ x; see [2]. */
|
| 391 |
+
absxma_a = std::abs(x - a) / a;
|
| 392 |
+
if ((a > detail::igam_SMALL) && (a < detail::igam_LARGE) && (absxma_a < detail::igam_SMALLRATIO)) {
|
| 393 |
+
return detail::asymptotic_series(a, x, detail::IGAMC);
|
| 394 |
+
} else if ((a > detail::igam_LARGE) && (absxma_a < detail::igam_LARGERATIO / std::sqrt(a))) {
|
| 395 |
+
return detail::asymptotic_series(a, x, detail::IGAMC);
|
| 396 |
+
}
|
| 397 |
+
|
| 398 |
+
/* Everywhere else; see [2]. */
|
| 399 |
+
if (x > 1.1) {
|
| 400 |
+
if (x < a) {
|
| 401 |
+
return 1.0 - detail::igam_series(a, x);
|
| 402 |
+
} else {
|
| 403 |
+
return detail::igamc_continued_fraction(a, x);
|
| 404 |
+
}
|
| 405 |
+
} else if (x <= 0.5) {
|
| 406 |
+
if (-0.4 / std::log(x) < a) {
|
| 407 |
+
return 1.0 - detail::igam_series(a, x);
|
| 408 |
+
} else {
|
| 409 |
+
return detail::igamc_series(a, x);
|
| 410 |
+
}
|
| 411 |
+
} else {
|
| 412 |
+
if (x * 1.1 < a) {
|
| 413 |
+
return 1.0 - detail::igam_series(a, x);
|
| 414 |
+
} else {
|
| 415 |
+
return detail::igamc_series(a, x);
|
| 416 |
+
}
|
| 417 |
+
}
|
| 418 |
+
}
|
| 419 |
+
|
| 420 |
+
} // namespace cephes
|
| 421 |
+
} // namespace xsf
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/igam_asymp_coeff.h
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
+
/* This file was automatically generated by _precomp/gammainc.py.
|
| 4 |
+
* Do not edit it manually!
|
| 5 |
+
*/
|
| 6 |
+
#pragma once
|
| 7 |
+
|
| 8 |
+
namespace xsf {
|
| 9 |
+
namespace cephes {
|
| 10 |
+
|
| 11 |
+
namespace detail {
|
| 12 |
+
|
| 13 |
+
constexpr int igam_asymp_coeff_K = 25;
|
| 14 |
+
constexpr int igam_asymp_coeff_N = 25;
|
| 15 |
+
|
| 16 |
+
static const double igam_asymp_coeff_d[igam_asymp_coeff_K][igam_asymp_coeff_N] = {
|
| 17 |
+
{-3.3333333333333333e-1, 8.3333333333333333e-2, -1.4814814814814815e-2, 1.1574074074074074e-3,
|
| 18 |
+
3.527336860670194e-4, -1.7875514403292181e-4, 3.9192631785224378e-5, -2.1854485106799922e-6,
|
| 19 |
+
-1.85406221071516e-6, 8.296711340953086e-7, -1.7665952736826079e-7, 6.7078535434014986e-9,
|
| 20 |
+
1.0261809784240308e-8, -4.3820360184533532e-9, 9.1476995822367902e-10, -2.551419399494625e-11,
|
| 21 |
+
-5.8307721325504251e-11, 2.4361948020667416e-11, -5.0276692801141756e-12, 1.1004392031956135e-13,
|
| 22 |
+
3.3717632624009854e-13, -1.3923887224181621e-13, 2.8534893807047443e-14, -5.1391118342425726e-16,
|
| 23 |
+
-1.9752288294349443e-15},
|
| 24 |
+
{-1.8518518518518519e-3, -3.4722222222222222e-3, 2.6455026455026455e-3, -9.9022633744855967e-4,
|
| 25 |
+
2.0576131687242798e-4, -4.0187757201646091e-7, -1.8098550334489978e-5, 7.6491609160811101e-6,
|
| 26 |
+
-1.6120900894563446e-6, 4.6471278028074343e-9, 1.378633446915721e-7, -5.752545603517705e-8,
|
| 27 |
+
1.1951628599778147e-8, -1.7543241719747648e-11, -1.0091543710600413e-9, 4.1627929918425826e-10,
|
| 28 |
+
-8.5639070264929806e-11, 6.0672151016047586e-14, 7.1624989648114854e-12, -2.9331866437714371e-12,
|
| 29 |
+
5.9966963656836887e-13, -2.1671786527323314e-16, -4.9783399723692616e-14, 2.0291628823713425e-14,
|
| 30 |
+
-4.13125571381061e-15},
|
| 31 |
+
{4.1335978835978836e-3, -2.6813271604938272e-3, 7.7160493827160494e-4, 2.0093878600823045e-6,
|
| 32 |
+
-1.0736653226365161e-4, 5.2923448829120125e-5, -1.2760635188618728e-5, 3.4235787340961381e-8,
|
| 33 |
+
1.3721957309062933e-6, -6.298992138380055e-7, 1.4280614206064242e-7, -2.0477098421990866e-10,
|
| 34 |
+
-1.4092529910867521e-8, 6.228974084922022e-9, -1.3670488396617113e-9, 9.4283561590146782e-13,
|
| 35 |
+
1.2872252400089318e-10, -5.5645956134363321e-11, 1.1975935546366981e-11, -4.1689782251838635e-15,
|
| 36 |
+
-1.0940640427884594e-12, 4.6622399463901357e-13, -9.905105763906906e-14, 1.8931876768373515e-17,
|
| 37 |
+
8.8592218725911273e-15},
|
| 38 |
+
{6.4943415637860082e-4, 2.2947209362139918e-4, -4.6918949439525571e-4, 2.6772063206283885e-4,
|
| 39 |
+
-7.5618016718839764e-5, -2.3965051138672967e-7, 1.1082654115347302e-5, -5.6749528269915966e-6,
|
| 40 |
+
1.4230900732435884e-6, -2.7861080291528142e-11, -1.6958404091930277e-7, 8.0994649053880824e-8,
|
| 41 |
+
-1.9111168485973654e-8, 2.3928620439808118e-12, 2.0620131815488798e-9, -9.4604966618551322e-10,
|
| 42 |
+
2.1541049775774908e-10, -1.388823336813903e-14, -2.1894761681963939e-11, 9.7909989511716851e-12,
|
| 43 |
+
-2.1782191880180962e-12, 6.2088195734079014e-17, 2.126978363279737e-13, -9.3446887915174333e-14,
|
| 44 |
+
2.0453671226782849e-14},
|
| 45 |
+
{-8.618882909167117e-4, 7.8403922172006663e-4, -2.9907248030319018e-4, -1.4638452578843418e-6,
|
| 46 |
+
6.6414982154651222e-5, -3.9683650471794347e-5, 1.1375726970678419e-5, 2.5074972262375328e-10,
|
| 47 |
+
-1.6954149536558306e-6, 8.9075075322053097e-7, -2.2929348340008049e-7, 2.956794137544049e-11,
|
| 48 |
+
2.8865829742708784e-8, -1.4189739437803219e-8, 3.4463580499464897e-9, -2.3024517174528067e-13,
|
| 49 |
+
-3.9409233028046405e-10, 1.8602338968504502e-10, -4.356323005056618e-11, 1.2786001016296231e-15,
|
| 50 |
+
4.6792750266579195e-12, -2.1492464706134829e-12, 4.9088156148096522e-13, -6.3385914848915603e-18,
|
| 51 |
+
-5.0453320690800944e-14},
|
| 52 |
+
{-3.3679855336635815e-4, -6.9728137583658578e-5, 2.7727532449593921e-4, -1.9932570516188848e-4,
|
| 53 |
+
6.7977804779372078e-5, 1.419062920643967e-7, -1.3594048189768693e-5, 8.0184702563342015e-6,
|
| 54 |
+
-2.2914811765080952e-6, -3.252473551298454e-10, 3.4652846491085265e-7, -1.8447187191171343e-7,
|
| 55 |
+
4.8240967037894181e-8, -1.7989466721743515e-14, -6.3061945000135234e-9, 3.1624176287745679e-9,
|
| 56 |
+
-7.8409242536974293e-10, 5.1926791652540407e-15, 9.3589442423067836e-11, -4.5134262161632782e-11,
|
| 57 |
+
1.0799129993116827e-11, -3.661886712685252e-17, -1.210902069055155e-12, 5.6807435849905643e-13,
|
| 58 |
+
-1.3249659916340829e-13},
|
| 59 |
+
{5.3130793646399222e-4, -5.9216643735369388e-4, 2.7087820967180448e-4, 7.9023532326603279e-7,
|
| 60 |
+
-8.1539693675619688e-5, 5.6116827531062497e-5, -1.8329116582843376e-5, -3.0796134506033048e-9,
|
| 61 |
+
3.4651553688036091e-6, -2.0291327396058604e-6, 5.7887928631490037e-7, 2.338630673826657e-13,
|
| 62 |
+
-8.8286007463304835e-8, 4.7435958880408128e-8, -1.2545415020710382e-8, 8.6496488580102925e-14,
|
| 63 |
+
1.6846058979264063e-9, -8.5754928235775947e-10, 2.1598224929232125e-10, -7.6132305204761539e-16,
|
| 64 |
+
-2.6639822008536144e-11, 1.3065700536611057e-11, -3.1799163902367977e-12, 4.7109761213674315e-18,
|
| 65 |
+
3.6902800842763467e-13},
|
| 66 |
+
{3.4436760689237767e-4, 5.1717909082605922e-5, -3.3493161081142236e-4, 2.812695154763237e-4,
|
| 67 |
+
-1.0976582244684731e-4, -1.2741009095484485e-7, 2.7744451511563644e-5, -1.8263488805711333e-5,
|
| 68 |
+
5.7876949497350524e-6, 4.9387589339362704e-10, -1.0595367014026043e-6, 6.1667143761104075e-7,
|
| 69 |
+
-1.7562973359060462e-7, -1.2974473287015439e-12, 2.695423606288966e-8, -1.4578352908731271e-8,
|
| 70 |
+
3.887645959386175e-9, -3.8810022510194121e-17, -5.3279941738772867e-10, 2.7437977643314845e-10,
|
| 71 |
+
-6.9957960920705679e-11, 2.5899863874868481e-17, 8.8566890996696381e-12, -4.403168815871311e-12,
|
| 72 |
+
1.0865561947091654e-12},
|
| 73 |
+
{-6.5262391859530942e-4, 8.3949872067208728e-4, -4.3829709854172101e-4, -6.969091458420552e-7,
|
| 74 |
+
1.6644846642067548e-4, -1.2783517679769219e-4, 4.6299532636913043e-5, 4.5579098679227077e-9,
|
| 75 |
+
-1.0595271125805195e-5, 6.7833429048651666e-6, -2.1075476666258804e-6, -1.7213731432817145e-11,
|
| 76 |
+
3.7735877416110979e-7, -2.1867506700122867e-7, 6.2202288040189269e-8, 6.5977038267330006e-16,
|
| 77 |
+
-9.5903864974256858e-9, 5.2132144922808078e-9, -1.3991589583935709e-9, 5.382058999060575e-16,
|
| 78 |
+
1.9484714275467745e-10, -1.0127287556389682e-10, 2.6077347197254926e-11, -5.0904186999932993e-18,
|
| 79 |
+
-3.3721464474854592e-12},
|
| 80 |
+
{-5.9676129019274625e-4, -7.2048954160200106e-5, 6.7823088376673284e-4, -6.4014752602627585e-4,
|
| 81 |
+
2.7750107634328704e-4, 1.8197008380465151e-7, -8.4795071170685032e-5, 6.105192082501531e-5,
|
| 82 |
+
-2.1073920183404862e-5, -8.8585890141255994e-10, 4.5284535953805377e-6, -2.8427815022504408e-6,
|
| 83 |
+
8.7082341778646412e-7, 3.6886101871706965e-12, -1.5344695190702061e-7, 8.862466778790695e-8,
|
| 84 |
+
-2.5184812301826817e-8, -1.0225912098215092e-14, 3.8969470758154777e-9, -2.1267304792235635e-9,
|
| 85 |
+
5.7370135528051385e-10, -1.887749850169741e-19, -8.0931538694657866e-11, 4.2382723283449199e-11,
|
| 86 |
+
-1.1002224534207726e-11},
|
| 87 |
+
{1.3324454494800656e-3, -1.9144384985654775e-3, 1.1089369134596637e-3, 9.932404122642299e-7,
|
| 88 |
+
-5.0874501293093199e-4, 4.2735056665392884e-4, -1.6858853767910799e-4, -8.1301893922784998e-9,
|
| 89 |
+
4.5284402370562147e-5, -3.127053674781734e-5, 1.044986828530338e-5, 4.8435226265680926e-11,
|
| 90 |
+
-2.1482565873456258e-6, 1.329369701097492e-6, -4.0295693092101029e-7, -1.7567877666323291e-13,
|
| 91 |
+
7.0145043163668257e-8, -4.040787734999483e-8, 1.1474026743371963e-8, 3.9642746853563325e-18,
|
| 92 |
+
-1.7804938269892714e-9, 9.7480262548731646e-10, -2.6405338676507616e-10, 5.794875163403742e-18,
|
| 93 |
+
3.7647749553543836e-11},
|
| 94 |
+
{1.579727660730835e-3, 1.6251626278391582e-4, -2.0633421035543276e-3, 2.1389686185689098e-3,
|
| 95 |
+
-1.0108559391263003e-3, -3.9912705529919201e-7, 3.6235025084764691e-4, -2.8143901463712154e-4,
|
| 96 |
+
1.0449513336495887e-4, 2.1211418491830297e-9, -2.5779417251947842e-5, 1.7281818956040463e-5,
|
| 97 |
+
-5.6413773872904282e-6, -1.1024320105776174e-11, 1.1223224418895175e-6, -6.8693396379526735e-7,
|
| 98 |
+
2.0653236975414887e-7, 4.6714772409838506e-14, -3.5609886164949055e-8, 2.0470855345905963e-8,
|
| 99 |
+
-5.8091738633283358e-9, -1.332821287582869e-16, 9.0354604391335133e-10, -4.9598782517330834e-10,
|
| 100 |
+
1.3481607129399749e-10},
|
| 101 |
+
{-4.0725121195140166e-3, 6.4033628338080698e-3, -4.0410161081676618e-3, -2.183732802866233e-6,
|
| 102 |
+
2.1740441801254639e-3, -1.9700440518418892e-3, 8.3595469747962458e-4, 1.9445447567109655e-8,
|
| 103 |
+
-2.5779387120421696e-4, 1.9009987368139304e-4, -6.7696499937438965e-5, -1.4440629666426572e-10,
|
| 104 |
+
1.5712512518742269e-5, -1.0304008744776893e-5, 3.304517767401387e-6, 7.9829760242325709e-13,
|
| 105 |
+
-6.4097794149313004e-7, 3.8894624761300056e-7, -1.1618347644948869e-7, -2.816808630596451e-15,
|
| 106 |
+
1.9878012911297093e-8, -1.1407719956357511e-8, 3.2355857064185555e-9, 4.1759468293455945e-20,
|
| 107 |
+
-5.0423112718105824e-10},
|
| 108 |
+
{-5.9475779383993003e-3, -5.4016476789260452e-4, 8.7910413550767898e-3, -9.8576315587856125e-3,
|
| 109 |
+
5.0134695031021538e-3, 1.2807521786221875e-6, -2.0626019342754683e-3, 1.7109128573523058e-3,
|
| 110 |
+
-6.7695312714133799e-4, -6.9011545676562133e-9, 1.8855128143995902e-4, -1.3395215663491969e-4,
|
| 111 |
+
4.6263183033528039e-5, 4.0034230613321351e-11, -1.0255652921494033e-5, 6.612086372797651e-6,
|
| 112 |
+
-2.0913022027253008e-6, -2.0951775649603837e-13, 3.9756029041993247e-7, -2.3956211978815887e-7,
|
| 113 |
+
7.1182883382145864e-8, 8.925574873053455e-16, -1.2101547235064676e-8, 6.9350618248334386e-9,
|
| 114 |
+
-1.9661464453856102e-9},
|
| 115 |
+
{1.7402027787522711e-2, -2.9527880945699121e-2, 2.0045875571402799e-2, 7.0289515966903407e-6,
|
| 116 |
+
-1.2375421071343148e-2, 1.1976293444235254e-2, -5.4156038466518525e-3, -6.3290893396418616e-8,
|
| 117 |
+
1.8855118129005065e-3, -1.473473274825001e-3, 5.5515810097708387e-4, 5.2406834412550662e-10,
|
| 118 |
+
-1.4357913535784836e-4, 9.9181293224943297e-5, -3.3460834749478311e-5, -3.5755837291098993e-12,
|
| 119 |
+
7.1560851960630076e-6, -4.5516802628155526e-6, 1.4236576649271475e-6, 1.8803149082089664e-14,
|
| 120 |
+
-2.6623403898929211e-7, 1.5950642189595716e-7, -4.7187514673841102e-8, -6.5107872958755177e-17,
|
| 121 |
+
7.9795091026746235e-9},
|
| 122 |
+
{3.0249124160905891e-2, 2.4817436002649977e-3, -4.9939134373457022e-2, 5.9915643009307869e-2,
|
| 123 |
+
-3.2483207601623391e-2, -5.7212968652103441e-6, 1.5085251778569354e-2, -1.3261324005088445e-2,
|
| 124 |
+
5.5515262632426148e-3, 3.0263182257030016e-8, -1.7229548406756723e-3, 1.2893570099929637e-3,
|
| 125 |
+
-4.6845138348319876e-4, -1.830259937893045e-10, 1.1449739014822654e-4, -7.7378565221244477e-5,
|
| 126 |
+
2.5625836246985201e-5, 1.0766165333192814e-12, -5.3246809282422621e-6, 3.349634863064464e-6,
|
| 127 |
+
-1.0381253128684018e-6, -5.608909920621128e-15, 1.9150821930676591e-7, -1.1418365800203486e-7,
|
| 128 |
+
3.3654425209171788e-8},
|
| 129 |
+
{-9.9051020880159045e-2, 1.7954011706123486e-1, -1.2989606383463778e-1, -3.1478872752284357e-5,
|
| 130 |
+
9.0510635276848131e-2, -9.2828824411184397e-2, 4.4412112839877808e-2, 2.7779236316835888e-7,
|
| 131 |
+
-1.7229543805449697e-2, 1.4182925050891573e-2, -5.6214161633747336e-3, -2.39598509186381e-9,
|
| 132 |
+
1.6029634366079908e-3, -1.1606784674435773e-3, 4.1001337768153873e-4, 1.8365800754090661e-11,
|
| 133 |
+
-9.5844256563655903e-5, 6.3643062337764708e-5, -2.076250624489065e-5, -1.1806020912804483e-13,
|
| 134 |
+
4.2131808239120649e-6, -2.6262241337012467e-6, 8.0770620494930662e-7, 6.0125912123632725e-16,
|
| 135 |
+
-1.4729737374018841e-7},
|
| 136 |
+
{-1.9994542198219728e-1, -1.5056113040026424e-2, 3.6470239469348489e-1, -4.6435192311733545e-1,
|
| 137 |
+
2.6640934719197893e-1, 3.4038266027147191e-5, -1.3784338709329624e-1, 1.276467178337056e-1,
|
| 138 |
+
-5.6213828755200985e-2, -1.753150885483011e-7, 1.9235592956768113e-2, -1.5088821281095315e-2,
|
| 139 |
+
5.7401854451350123e-3, 1.0622382710310225e-9, -1.5335082692563998e-3, 1.0819320643228214e-3,
|
| 140 |
+
-3.7372510193945659e-4, -6.6170909729031985e-12, 8.4263617380909628e-5, -5.5150706827483479e-5,
|
| 141 |
+
1.7769536448348069e-5, 3.8827923210205533e-14, -3.53513697488768e-6, 2.1865832130045269e-6,
|
| 142 |
+
-6.6812849447625594e-7},
|
| 143 |
+
{7.2438608504029431e-1, -1.3918010932653375, 1.0654143352413968, 1.876173868950258e-4,
|
| 144 |
+
-8.2705501176152696e-1, 8.9352433347828414e-1, -4.4971003995291339e-1, -1.6107401567546652e-6,
|
| 145 |
+
1.9235590165271091e-1, -1.6597702160042609e-1, 6.8882222681814333e-2, 1.3910091724608687e-8,
|
| 146 |
+
-2.146911561508663e-2, 1.6228980898865892e-2, -5.9796016172584256e-3, -1.1287469112826745e-10,
|
| 147 |
+
1.5167451119784857e-3, -1.0478634293553899e-3, 3.5539072889126421e-4, 8.1704322111801517e-13,
|
| 148 |
+
-7.7773013442452395e-5, 5.0291413897007722e-5, -1.6035083867000518e-5, 1.2469354315487605e-14,
|
| 149 |
+
3.1369106244517615e-6},
|
| 150 |
+
{1.6668949727276811, 1.165462765994632e-1, -3.3288393225018906, 4.4692325482864037,
|
| 151 |
+
-2.6977693045875807, -2.600667859891061e-4, 1.5389017615694539, -1.4937962361134612,
|
| 152 |
+
6.8881964633233148e-1, 1.3077482004552385e-6, -2.5762963325596288e-1, 2.1097676102125449e-1,
|
| 153 |
+
-8.3714408359219882e-2, -7.7920428881354753e-9, 2.4267923064833599e-2, -1.7813678334552311e-2,
|
| 154 |
+
6.3970330388900056e-3, 4.9430807090480523e-11, -1.5554602758465635e-3, 1.0561196919903214e-3,
|
| 155 |
+
-3.5277184460472902e-4, 9.3002334645022459e-14, 7.5285855026557172e-5, -4.8186515569156351e-5,
|
| 156 |
+
1.5227271505597605e-5},
|
| 157 |
+
{-6.6188298861372935, 1.3397985455142589e+1, -1.0789350606845146e+1, -1.4352254537875018e-3,
|
| 158 |
+
9.2333694596189809, -1.0456552819547769e+1, 5.5105526029033471, 1.2024439690716742e-5,
|
| 159 |
+
-2.5762961164755816, 2.3207442745387179, -1.0045728797216284, -1.0207833290021914e-7,
|
| 160 |
+
3.3975092171169466e-1, -2.6720517450757468e-1, 1.0235252851562706e-1, 8.4329730484871625e-10,
|
| 161 |
+
-2.7998284958442595e-2, 2.0066274144976813e-2, -7.0554368915086242e-3, 1.9402238183698188e-12,
|
| 162 |
+
1.6562888105449611e-3, -1.1082898580743683e-3, 3.654545161310169e-4, -5.1290032026971794e-11,
|
| 163 |
+
-7.6340103696869031e-5},
|
| 164 |
+
{-1.7112706061976095e+1, -1.1208044642899116, 3.7131966511885444e+1, -5.2298271025348962e+1,
|
| 165 |
+
3.3058589696624618e+1, 2.4791298976200222e-3, -2.061089403411526e+1, 2.088672775145582e+1,
|
| 166 |
+
-1.0045703956517752e+1, -1.2238783449063012e-5, 4.0770134274221141, -3.473667358470195,
|
| 167 |
+
1.4329352617312006, 7.1359914411879712e-8, -4.4797257159115612e-1, 3.4112666080644461e-1,
|
| 168 |
+
-1.2699786326594923e-1, -2.8953677269081528e-10, 3.3125776278259863e-2, -2.3274087021036101e-2,
|
| 169 |
+
8.0399993503648882e-3, -1.177805216235265e-9, -1.8321624891071668e-3, 1.2108282933588665e-3,
|
| 170 |
+
-3.9479941246822517e-4},
|
| 171 |
+
{7.389033153567425e+1, -1.5680141270402273e+2, 1.322177542759164e+2, 1.3692876877324546e-2,
|
| 172 |
+
-1.2366496885920151e+2, 1.4620689391062729e+2, -8.0365587724865346e+1, -1.1259851148881298e-4,
|
| 173 |
+
4.0770132196179938e+1, -3.8210340013273034e+1, 1.719522294277362e+1, 9.3519707955168356e-7,
|
| 174 |
+
-6.2716159907747034, 5.1168999071852637, -2.0319658112299095, -4.9507215582761543e-9,
|
| 175 |
+
5.9626397294332597e-1, -4.4220765337238094e-1, 1.6079998700166273e-1, -2.4733786203223402e-8,
|
| 176 |
+
-4.0307574759979762e-2, 2.7849050747097869e-2, -9.4751858992054221e-3, 6.419922235909132e-6,
|
| 177 |
+
2.1250180774699461e-3},
|
| 178 |
+
{2.1216837098382522e+2, 1.3107863022633868e+1, -4.9698285932871748e+2, 7.3121595266969204e+2,
|
| 179 |
+
-4.8213821720890847e+2, -2.8817248692894889e-2, 3.2616720302947102e+2, -3.4389340280087117e+2,
|
| 180 |
+
1.7195193870816232e+2, 1.4038077378096158e-4, -7.52594195897599e+1, 6.651969984520934e+1,
|
| 181 |
+
-2.8447519748152462e+1, -7.613702615875391e-7, 9.5402237105304373, -7.5175301113311376,
|
| 182 |
+
2.8943997568871961, -4.6612194999538201e-7, -8.0615149598794088e-1, 5.8483006570631029e-1,
|
| 183 |
+
-2.0845408972964956e-1, 1.4765818959305817e-4, 5.1000433863753019e-2, -3.3066252141883665e-2,
|
| 184 |
+
1.5109265210467774e-2},
|
| 185 |
+
{-9.8959643098322368e+2, 2.1925555360905233e+3, -1.9283586782723356e+3, -1.5925738122215253e-1,
|
| 186 |
+
1.9569985945919857e+3, -2.4072514765081556e+3, 1.3756149959336496e+3, 1.2920735237496668e-3,
|
| 187 |
+
-7.525941715948055e+2, 7.3171668742208716e+2, -3.4137023466220065e+2, -9.9857390260608043e-6,
|
| 188 |
+
1.3356313181291573e+2, -1.1276295161252794e+2, 4.6310396098204458e+1, -7.9237387133614756e-6,
|
| 189 |
+
-1.4510726927018646e+1, 1.1111771248100563e+1, -4.1690817945270892, 3.1008219800117808e-3,
|
| 190 |
+
1.1220095449981468, -7.6052379926149916e-1, 3.6262236505085254e-1, 2.216867741940747e-1,
|
| 191 |
+
4.8683443692930507e-1}};
|
| 192 |
+
|
| 193 |
+
} // namespace detail
|
| 194 |
+
} // namespace cephes
|
| 195 |
+
} // namespace xsf
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/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ification and distribution are subject to the
|
| 8 |
+
* Boost Software License, Version 1.0. (See accompanying file
|
| 9 |
+
* LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
|
| 10 |
+
*/
|
| 11 |
+
#pragma once
|
| 12 |
+
|
| 13 |
+
#include "../config.h"
|
| 14 |
+
#include "../error.h"
|
| 15 |
+
|
| 16 |
+
#include "const.h"
|
| 17 |
+
#include "gamma.h"
|
| 18 |
+
#include "igam.h"
|
| 19 |
+
#include "polevl.h"
|
| 20 |
+
|
| 21 |
+
namespace xsf {
|
| 22 |
+
namespace cephes {
|
| 23 |
+
|
| 24 |
+
namespace detail {
|
| 25 |
+
|
| 26 |
+
XSF_HOST_DEVICE double find_inverse_s(double p, double q) {
|
| 27 |
+
/*
|
| 28 |
+
* Computation of the Incomplete Gamma Function Ratios and their Inverse
|
| 29 |
+
* ARMIDO R. DIDONATO and ALFRED H. MORRIS, JR.
|
| 30 |
+
* ACM Transactions on Mathematical Software, Vol. 12, No. 4,
|
| 31 |
+
* December 1986, Pages 377-393.
|
| 32 |
+
*
|
| 33 |
+
* See equation 32.
|
| 34 |
+
*/
|
| 35 |
+
double s, t;
|
| 36 |
+
constexpr double a[4] = {0.213623493715853, 4.28342155967104, 11.6616720288968, 3.31125922108741};
|
| 37 |
+
constexpr double b[5] = {0.3611708101884203e-1, 1.27364489782223, 6.40691597760039, 6.61053765625462, 1};
|
| 38 |
+
|
| 39 |
+
if (p < 0.5) {
|
| 40 |
+
t = std::sqrt(-2 * std::log(p));
|
| 41 |
+
} else {
|
| 42 |
+
t = std::sqrt(-2 * std::log(q));
|
| 43 |
+
}
|
| 44 |
+
s = t - polevl(t, a, 3) / polevl(t, b, 4);
|
| 45 |
+
if (p < 0.5)
|
| 46 |
+
s = -s;
|
| 47 |
+
return s;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
XSF_HOST_DEVICE inline double didonato_SN(double a, double x, unsigned N, double tolerance) {
|
| 51 |
+
/*
|
| 52 |
+
* Computation of the Incomplete Gamma Function Ratios and their Inverse
|
| 53 |
+
* ARMIDO R. DIDONATO and ALFRED H. MORRIS, JR.
|
| 54 |
+
* ACM Transactions on Mathematical Software, Vol. 12, No. 4,
|
| 55 |
+
* December 1986, Pages 377-393.
|
| 56 |
+
*
|
| 57 |
+
* See equation 34.
|
| 58 |
+
*/
|
| 59 |
+
double sum = 1.0;
|
| 60 |
+
|
| 61 |
+
if (N >= 1) {
|
| 62 |
+
unsigned i;
|
| 63 |
+
double partial = x / (a + 1);
|
| 64 |
+
|
| 65 |
+
sum += partial;
|
| 66 |
+
for (i = 2; i <= N; ++i) {
|
| 67 |
+
partial *= x / (a + i);
|
| 68 |
+
sum += partial;
|
| 69 |
+
if (partial < tolerance) {
|
| 70 |
+
break;
|
| 71 |
+
}
|
| 72 |
+
}
|
| 73 |
+
}
|
| 74 |
+
return sum;
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
XSF_HOST_DEVICE inline double find_inverse_gamma(double a, double p, double q) {
|
| 78 |
+
/*
|
| 79 |
+
* In order to understand what's going on here, you will
|
| 80 |
+
* need to refer to:
|
| 81 |
+
*
|
| 82 |
+
* Computation of the Incomplete Gamma Function Ratios and their Inverse
|
| 83 |
+
* ARMIDO R. DIDONATO and ALFRED H. MORRIS, JR.
|
| 84 |
+
* ACM Transactions on Mathematical Software, Vol. 12, No. 4,
|
| 85 |
+
* December 1986, Pages 377-393.
|
| 86 |
+
*/
|
| 87 |
+
double result;
|
| 88 |
+
|
| 89 |
+
if (a == 1) {
|
| 90 |
+
if (q > 0.9) {
|
| 91 |
+
result = -std::log1p(-p);
|
| 92 |
+
} else {
|
| 93 |
+
result = -std::log(q);
|
| 94 |
+
}
|
| 95 |
+
} else if (a < 1) {
|
| 96 |
+
double g = xsf::cephes::Gamma(a);
|
| 97 |
+
double b = q * g;
|
| 98 |
+
|
| 99 |
+
if ((b > 0.6) || ((b >= 0.45) && (a >= 0.3))) {
|
| 100 |
+
/* DiDonato & Morris Eq 21:
|
| 101 |
+
*
|
| 102 |
+
* There is a slight variation from DiDonato and Morris here:
|
| 103 |
+
* the first form given here is unstable when p is close to 1,
|
| 104 |
+
* making it impossible to compute the inverse of Q(a,x) for small
|
| 105 |
+
* q. Fortunately the second form works perfectly well in this case.
|
| 106 |
+
*/
|
| 107 |
+
double u;
|
| 108 |
+
if ((b * q > 1e-8) && (q > 1e-5)) {
|
| 109 |
+
u = std::pow(p * g * a, 1 / a);
|
| 110 |
+
} else {
|
| 111 |
+
u = std::exp((-q / a) - SCIPY_EULER);
|
| 112 |
+
}
|
| 113 |
+
result = u / (1 - (u / (a + 1)));
|
| 114 |
+
} else if ((a < 0.3) && (b >= 0.35)) {
|
| 115 |
+
/* DiDonato & Morris Eq 22: */
|
| 116 |
+
double t = std::exp(-SCIPY_EULER - b);
|
| 117 |
+
double u = t * std::exp(t);
|
| 118 |
+
result = t * std::exp(u);
|
| 119 |
+
} else if ((b > 0.15) || (a >= 0.3)) {
|
| 120 |
+
/* DiDonato & Morris Eq 23: */
|
| 121 |
+
double y = -std::log(b);
|
| 122 |
+
double u = y - (1 - a) * std::log(y);
|
| 123 |
+
result = y - (1 - a) * std::log(u) - std::log(1 + (1 - a) / (1 + u));
|
| 124 |
+
} else if (b > 0.1) {
|
| 125 |
+
/* DiDonato & Morris Eq 24: */
|
| 126 |
+
double y = -std::log(b);
|
| 127 |
+
double u = y - (1 - a) * std::log(y);
|
| 128 |
+
result = y - (1 - a) * std::log(u) -
|
| 129 |
+
std::log((u * u + 2 * (3 - a) * u + (2 - a) * (3 - a)) / (u * u + (5 - a) * u + 2));
|
| 130 |
+
} else {
|
| 131 |
+
/* DiDonato & Morris Eq 25: */
|
| 132 |
+
double y = -std::log(b);
|
| 133 |
+
double c1 = (a - 1) * std::log(y);
|
| 134 |
+
double c1_2 = c1 * c1;
|
| 135 |
+
double c1_3 = c1_2 * c1;
|
| 136 |
+
double c1_4 = c1_2 * c1_2;
|
| 137 |
+
double a_2 = a * a;
|
| 138 |
+
double a_3 = a_2 * a;
|
| 139 |
+
|
| 140 |
+
double c2 = (a - 1) * (1 + c1);
|
| 141 |
+
double c3 = (a - 1) * (-(c1_2 / 2) + (a - 2) * c1 + (3 * a - 5) / 2);
|
| 142 |
+
double c4 = (a - 1) * ((c1_3 / 3) - (3 * a - 5) * c1_2 / 2 + (a_2 - 6 * a + 7) * c1 +
|
| 143 |
+
(11 * a_2 - 46 * a + 47) / 6);
|
| 144 |
+
double c5 = (a - 1) * (-(c1_4 / 4) + (11 * a - 17) * c1_3 / 6 + (-3 * a_2 + 13 * a - 13) * c1_2 +
|
| 145 |
+
(2 * a_3 - 25 * a_2 + 72 * a - 61) * c1 / 2 +
|
| 146 |
+
(25 * a_3 - 195 * a_2 + 477 * a - 379) / 12);
|
| 147 |
+
|
| 148 |
+
double y_2 = y * y;
|
| 149 |
+
double y_3 = y_2 * y;
|
| 150 |
+
double y_4 = y_2 * y_2;
|
| 151 |
+
result = y + c1 + (c2 / y) + (c3 / y_2) + (c4 / y_3) + (c5 / y_4);
|
| 152 |
+
}
|
| 153 |
+
} else {
|
| 154 |
+
/* DiDonato and Morris Eq 31: */
|
| 155 |
+
double s = find_inverse_s(p, q);
|
| 156 |
+
|
| 157 |
+
double s_2 = s * s;
|
| 158 |
+
double s_3 = s_2 * s;
|
| 159 |
+
double s_4 = s_2 * s_2;
|
| 160 |
+
double s_5 = s_4 * s;
|
| 161 |
+
double ra = std::sqrt(a);
|
| 162 |
+
|
| 163 |
+
double w = a + s * ra + (s_2 - 1) / 3;
|
| 164 |
+
w += (s_3 - 7 * s) / (36 * ra);
|
| 165 |
+
w -= (3 * s_4 + 7 * s_2 - 16) / (810 * a);
|
| 166 |
+
w += (9 * s_5 + 256 * s_3 - 433 * s) / (38880 * a * ra);
|
| 167 |
+
|
| 168 |
+
if ((a >= 500) && (std::abs(1 - w / a) < 1e-6)) {
|
| 169 |
+
result = w;
|
| 170 |
+
} else if (p > 0.5) {
|
| 171 |
+
if (w < 3 * a) {
|
| 172 |
+
result = w;
|
| 173 |
+
} else {
|
| 174 |
+
double D = std::fmax(2, a * (a - 1));
|
| 175 |
+
double lg = xsf::cephes::lgam(a);
|
| 176 |
+
double lb = std::log(q) + lg;
|
| 177 |
+
if (lb < -D * 2.3) {
|
| 178 |
+
/* DiDonato and Morris Eq 25: */
|
| 179 |
+
double y = -lb;
|
| 180 |
+
double c1 = (a - 1) * std::log(y);
|
| 181 |
+
double c1_2 = c1 * c1;
|
| 182 |
+
double c1_3 = c1_2 * c1;
|
| 183 |
+
double c1_4 = c1_2 * c1_2;
|
| 184 |
+
double a_2 = a * a;
|
| 185 |
+
double a_3 = a_2 * a;
|
| 186 |
+
|
| 187 |
+
double c2 = (a - 1) * (1 + c1);
|
| 188 |
+
double c3 = (a - 1) * (-(c1_2 / 2) + (a - 2) * c1 + (3 * a - 5) / 2);
|
| 189 |
+
double c4 = (a - 1) * ((c1_3 / 3) - (3 * a - 5) * c1_2 / 2 + (a_2 - 6 * a + 7) * c1 +
|
| 190 |
+
(11 * a_2 - 46 * a + 47) / 6);
|
| 191 |
+
double c5 =
|
| 192 |
+
(a - 1) * (-(c1_4 / 4) + (11 * a - 17) * c1_3 / 6 + (-3 * a_2 + 13 * a - 13) * c1_2 +
|
| 193 |
+
(2 * a_3 - 25 * a_2 + 72 * a - 61) * c1 / 2 +
|
| 194 |
+
(25 * a_3 - 195 * a_2 + 477 * a - 379) / 12);
|
| 195 |
+
|
| 196 |
+
double y_2 = y * y;
|
| 197 |
+
double y_3 = y_2 * y;
|
| 198 |
+
double y_4 = y_2 * y_2;
|
| 199 |
+
result = y + c1 + (c2 / y) + (c3 / y_2) + (c4 / y_3) + (c5 / y_4);
|
| 200 |
+
} else {
|
| 201 |
+
/* DiDonato and Morris Eq 33: */
|
| 202 |
+
double u = -lb + (a - 1) * std::log(w) - std::log(1 + (1 - a) / (1 + w));
|
| 203 |
+
result = -lb + (a - 1) * std::log(u) - std::log(1 + (1 - a) / (1 + u));
|
| 204 |
+
}
|
| 205 |
+
}
|
| 206 |
+
} else {
|
| 207 |
+
double z = w;
|
| 208 |
+
double ap1 = a + 1;
|
| 209 |
+
double ap2 = a + 2;
|
| 210 |
+
if (w < 0.15 * ap1) {
|
| 211 |
+
/* DiDonato and Morris Eq 35: */
|
| 212 |
+
double v = std::log(p) + xsf::cephes::lgam(ap1);
|
| 213 |
+
z = std::exp((v + w) / a);
|
| 214 |
+
s = std::log1p(z / ap1 * (1 + z / ap2));
|
| 215 |
+
z = std::exp((v + z - s) / a);
|
| 216 |
+
s = std::log1p(z / ap1 * (1 + z / ap2));
|
| 217 |
+
z = std::exp((v + z - s) / a);
|
| 218 |
+
s = std::log1p(z / ap1 * (1 + z / ap2 * (1 + z / (a + 3))));
|
| 219 |
+
z = std::exp((v + z - s) / a);
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
if ((z <= 0.01 * ap1) || (z > 0.7 * ap1)) {
|
| 223 |
+
result = z;
|
| 224 |
+
} else {
|
| 225 |
+
/* DiDonato and Morris Eq 36: */
|
| 226 |
+
double ls = std::log(didonato_SN(a, z, 100, 1e-4));
|
| 227 |
+
double v = std::log(p) + xsf::cephes::lgam(ap1);
|
| 228 |
+
z = std::exp((v + z - ls) / a);
|
| 229 |
+
result = z * (1 - (a * std::log(z) - z - v + ls) / (a - z));
|
| 230 |
+
}
|
| 231 |
+
}
|
| 232 |
+
}
|
| 233 |
+
return result;
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
} // namespace detail
|
| 237 |
+
|
| 238 |
+
XSF_HOST_DEVICE inline double igamci(double a, double q);
|
| 239 |
+
|
| 240 |
+
XSF_HOST_DEVICE inline double igami(double a, double p) {
|
| 241 |
+
int i;
|
| 242 |
+
double x, fac, f_fp, fpp_fp;
|
| 243 |
+
|
| 244 |
+
if (std::isnan(a) || std::isnan(p)) {
|
| 245 |
+
return std::numeric_limits<double>::quiet_NaN();
|
| 246 |
+
;
|
| 247 |
+
} else if ((a < 0) || (p < 0) || (p > 1)) {
|
| 248 |
+
set_error("gammaincinv", SF_ERROR_DOMAIN, NULL);
|
| 249 |
+
} else if (p == 0.0) {
|
| 250 |
+
return 0.0;
|
| 251 |
+
} else if (p == 1.0) {
|
| 252 |
+
return std::numeric_limits<double>::infinity();
|
| 253 |
+
} else if (p > 0.9) {
|
| 254 |
+
return igamci(a, 1 - p);
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
x = detail::find_inverse_gamma(a, p, 1 - p);
|
| 258 |
+
/* Halley's method */
|
| 259 |
+
for (i = 0; i < 3; i++) {
|
| 260 |
+
fac = detail::igam_fac(a, x);
|
| 261 |
+
if (fac == 0.0) {
|
| 262 |
+
return x;
|
| 263 |
+
}
|
| 264 |
+
f_fp = (igam(a, x) - p) * x / fac;
|
| 265 |
+
/* The ratio of the first and second derivatives simplifies */
|
| 266 |
+
fpp_fp = -1.0 + (a - 1) / x;
|
| 267 |
+
if (std::isinf(fpp_fp)) {
|
| 268 |
+
/* Resort to Newton's method in the case of overflow */
|
| 269 |
+
x = x - f_fp;
|
| 270 |
+
} else {
|
| 271 |
+
x = x - f_fp / (1.0 - 0.5 * f_fp * fpp_fp);
|
| 272 |
+
}
|
| 273 |
+
}
|
| 274 |
+
|
| 275 |
+
return x;
|
| 276 |
+
}
|
| 277 |
+
|
| 278 |
+
XSF_HOST_DEVICE inline double igamci(double a, double q) {
|
| 279 |
+
int i;
|
| 280 |
+
double x, fac, f_fp, fpp_fp;
|
| 281 |
+
|
| 282 |
+
if (std::isnan(a) || std::isnan(q)) {
|
| 283 |
+
return std::numeric_limits<double>::quiet_NaN();
|
| 284 |
+
} else if ((a < 0.0) || (q < 0.0) || (q > 1.0)) {
|
| 285 |
+
set_error("gammainccinv", SF_ERROR_DOMAIN, NULL);
|
| 286 |
+
} else if (q == 0.0) {
|
| 287 |
+
return std::numeric_limits<double>::infinity();
|
| 288 |
+
} else if (q == 1.0) {
|
| 289 |
+
return 0.0;
|
| 290 |
+
} else if (q > 0.9) {
|
| 291 |
+
return igami(a, 1 - q);
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
x = detail::find_inverse_gamma(a, 1 - q, q);
|
| 295 |
+
for (i = 0; i < 3; i++) {
|
| 296 |
+
fac = detail::igam_fac(a, x);
|
| 297 |
+
if (fac == 0.0) {
|
| 298 |
+
return x;
|
| 299 |
+
}
|
| 300 |
+
f_fp = (igamc(a, x) - q) * x / (-fac);
|
| 301 |
+
fpp_fp = -1.0 + (a - 1) / x;
|
| 302 |
+
if (std::isinf(fpp_fp)) {
|
| 303 |
+
x = x - f_fp;
|
| 304 |
+
} else {
|
| 305 |
+
x = x - f_fp / (1.0 - 0.5 * f_fp * fpp_fp);
|
| 306 |
+
}
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
return x;
|
| 310 |
+
}
|
| 311 |
+
|
| 312 |
+
} // namespace cephes
|
| 313 |
+
} // namespace xsf
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/j0.h
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
*
|
| 11 |
+
* SYNOPSIS:
|
| 12 |
+
*
|
| 13 |
+
* double x, y, j0();
|
| 14 |
+
*
|
| 15 |
+
* y = j0( x );
|
| 16 |
+
*
|
| 17 |
+
*
|
| 18 |
+
*
|
| 19 |
+
* DESCRIPTION:
|
| 20 |
+
*
|
| 21 |
+
* Returns Bessel function of order zero of the argument.
|
| 22 |
+
*
|
| 23 |
+
* The domain is divided into the intervals [0, 5] and
|
| 24 |
+
* (5, infinity). In the first interval the following rational
|
| 25 |
+
* approximation is used:
|
| 26 |
+
*
|
| 27 |
+
*
|
| 28 |
+
* 2 2
|
| 29 |
+
* (w - r ) (w - r ) P (w) / Q (w)
|
| 30 |
+
* 1 2 3 8
|
| 31 |
+
*
|
| 32 |
+
* 2
|
| 33 |
+
* where w = x and the two r's are zeros of the function.
|
| 34 |
+
*
|
| 35 |
+
* In the second interval, the Hankel asymptotic expansion
|
| 36 |
+
* is employed with two rational functions of degree 6/6
|
| 37 |
+
* and 7/7.
|
| 38 |
+
*
|
| 39 |
+
*
|
| 40 |
+
*
|
| 41 |
+
* ACCURACY:
|
| 42 |
+
*
|
| 43 |
+
* Absolute error:
|
| 44 |
+
* arithmetic domain # trials peak rms
|
| 45 |
+
* IEEE 0, 30 60000 4.2e-16 1.1e-16
|
| 46 |
+
*
|
| 47 |
+
*/
|
| 48 |
+
/* y0.c
|
| 49 |
+
*
|
| 50 |
+
* Bessel function of the second kind, order zero
|
| 51 |
+
*
|
| 52 |
+
*
|
| 53 |
+
*
|
| 54 |
+
* SYNOPSIS:
|
| 55 |
+
*
|
| 56 |
+
* double x, y, y0();
|
| 57 |
+
*
|
| 58 |
+
* y = y0( x );
|
| 59 |
+
*
|
| 60 |
+
*
|
| 61 |
+
*
|
| 62 |
+
* DESCRIPTION:
|
| 63 |
+
*
|
| 64 |
+
* Returns Bessel function of the second kind, of order
|
| 65 |
+
* zero, of the argument.
|
| 66 |
+
*
|
| 67 |
+
* The domain is divided into the intervals [0, 5] and
|
| 68 |
+
* (5, infinity). In the first interval a rational approximation
|
| 69 |
+
* R(x) is employed to compute
|
| 70 |
+
* y0(x) = R(x) + 2 * log(x) * j0(x) / M_PI.
|
| 71 |
+
* Thus a call to j0() is required.
|
| 72 |
+
*
|
| 73 |
+
* In the second interval, the Hankel asymptotic expansion
|
| 74 |
+
* is employed with two rational functions of degree 6/6
|
| 75 |
+
* and 7/7.
|
| 76 |
+
*
|
| 77 |
+
*
|
| 78 |
+
*
|
| 79 |
+
* ACCURACY:
|
| 80 |
+
*
|
| 81 |
+
* Absolute error, when y0(x) < 1; else relative error:
|
| 82 |
+
*
|
| 83 |
+
* arithmetic domain # trials peak rms
|
| 84 |
+
* IEEE 0, 30 30000 1.3e-15 1.6e-16
|
| 85 |
+
*
|
| 86 |
+
*/
|
| 87 |
+
|
| 88 |
+
/*
|
| 89 |
+
* Cephes Math Library Release 2.8: June, 2000
|
| 90 |
+
* Copyright 1984, 1987, 1989, 2000 by Stephen L. Moshier
|
| 91 |
+
*/
|
| 92 |
+
|
| 93 |
+
/* Note: all coefficients satisfy the relative error criterion
|
| 94 |
+
* except YP, YQ which are designed for absolute error. */
|
| 95 |
+
#pragma once
|
| 96 |
+
|
| 97 |
+
#include "../config.h"
|
| 98 |
+
#include "../error.h"
|
| 99 |
+
|
| 100 |
+
#include "const.h"
|
| 101 |
+
#include "polevl.h"
|
| 102 |
+
|
| 103 |
+
namespace xsf {
|
| 104 |
+
namespace cephes {
|
| 105 |
+
|
| 106 |
+
namespace detail {
|
| 107 |
+
|
| 108 |
+
constexpr double j0_PP[7] = {
|
| 109 |
+
7.96936729297347051624E-4, 8.28352392107440799803E-2, 1.23953371646414299388E0, 5.44725003058768775090E0,
|
| 110 |
+
8.74716500199817011941E0, 5.30324038235394892183E0, 9.99999999999999997821E-1,
|
| 111 |
+
};
|
| 112 |
+
|
| 113 |
+
constexpr double j0_PQ[7] = {
|
| 114 |
+
9.24408810558863637013E-4, 8.56288474354474431428E-2, 1.25352743901058953537E0, 5.47097740330417105182E0,
|
| 115 |
+
8.76190883237069594232E0, 5.30605288235394617618E0, 1.00000000000000000218E0,
|
| 116 |
+
};
|
| 117 |
+
|
| 118 |
+
constexpr double j0_QP[8] = {
|
| 119 |
+
-1.13663838898469149931E-2, -1.28252718670509318512E0, -1.95539544257735972385E1, -9.32060152123768231369E1,
|
| 120 |
+
-1.77681167980488050595E2, -1.47077505154951170175E2, -5.14105326766599330220E1, -6.05014350600728481186E0,
|
| 121 |
+
};
|
| 122 |
+
|
| 123 |
+
constexpr double j0_QQ[7] = {
|
| 124 |
+
/* 1.00000000000000000000E0, */
|
| 125 |
+
6.43178256118178023184E1, 8.56430025976980587198E2, 3.88240183605401609683E3, 7.24046774195652478189E3,
|
| 126 |
+
5.93072701187316984827E3, 2.06209331660327847417E3, 2.42005740240291393179E2,
|
| 127 |
+
};
|
| 128 |
+
|
| 129 |
+
constexpr double j0_YP[8] = {
|
| 130 |
+
1.55924367855235737965E4, -1.46639295903971606143E7, 5.43526477051876500413E9,
|
| 131 |
+
-9.82136065717911466409E11, 8.75906394395366999549E13, -3.46628303384729719441E15,
|
| 132 |
+
4.42733268572569800351E16, -1.84950800436986690637E16,
|
| 133 |
+
};
|
| 134 |
+
|
| 135 |
+
constexpr double j0_YQ[7] = {
|
| 136 |
+
/* 1.00000000000000000000E0, */
|
| 137 |
+
1.04128353664259848412E3, 6.26107330137134956842E5, 2.68919633393814121987E8, 8.64002487103935000337E10,
|
| 138 |
+
2.02979612750105546709E13, 3.17157752842975028269E15, 2.50596256172653059228E17,
|
| 139 |
+
};
|
| 140 |
+
|
| 141 |
+
/* 5.783185962946784521175995758455807035071 */
|
| 142 |
+
constexpr double j0_DR1 = 5.78318596294678452118E0;
|
| 143 |
+
|
| 144 |
+
/* 30.47126234366208639907816317502275584842 */
|
| 145 |
+
constexpr double j0_DR2 = 3.04712623436620863991E1;
|
| 146 |
+
|
| 147 |
+
constexpr double j0_RP[4] = {
|
| 148 |
+
-4.79443220978201773821E9,
|
| 149 |
+
1.95617491946556577543E12,
|
| 150 |
+
-2.49248344360967716204E14,
|
| 151 |
+
9.70862251047306323952E15,
|
| 152 |
+
};
|
| 153 |
+
|
| 154 |
+
constexpr double j0_RQ[8] = {
|
| 155 |
+
/* 1.00000000000000000000E0, */
|
| 156 |
+
4.99563147152651017219E2, 1.73785401676374683123E5, 4.84409658339962045305E7, 1.11855537045356834862E10,
|
| 157 |
+
2.11277520115489217587E12, 3.10518229857422583814E14, 3.18121955943204943306E16, 1.71086294081043136091E18,
|
| 158 |
+
};
|
| 159 |
+
|
| 160 |
+
} // namespace detail
|
| 161 |
+
|
| 162 |
+
XSF_HOST_DEVICE inline double j0(double x) {
|
| 163 |
+
double w, z, p, q, xn;
|
| 164 |
+
|
| 165 |
+
if (x < 0) {
|
| 166 |
+
x = -x;
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
if (x <= 5.0) {
|
| 170 |
+
z = x * x;
|
| 171 |
+
if (x < 1.0e-5) {
|
| 172 |
+
return (1.0 - z / 4.0);
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
p = (z - detail::j0_DR1) * (z - detail::j0_DR2);
|
| 176 |
+
p = p * polevl(z, detail::j0_RP, 3) / p1evl(z, detail::j0_RQ, 8);
|
| 177 |
+
return (p);
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
w = 5.0 / x;
|
| 181 |
+
q = 25.0 / (x * x);
|
| 182 |
+
p = polevl(q, detail::j0_PP, 6) / polevl(q, detail::j0_PQ, 6);
|
| 183 |
+
q = polevl(q, detail::j0_QP, 7) / p1evl(q, detail::j0_QQ, 7);
|
| 184 |
+
xn = x - M_PI_4;
|
| 185 |
+
p = p * std::cos(xn) - w * q * std::sin(xn);
|
| 186 |
+
return (p * detail::SQRT2OPI / std::sqrt(x));
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
/* y0() 2 */
|
| 190 |
+
/* Bessel function of second kind, order zero */
|
| 191 |
+
|
| 192 |
+
/* Rational approximation coefficients YP[], YQ[] are used here.
|
| 193 |
+
* The function computed is y0(x) - 2 * log(x) * j0(x) / M_PI,
|
| 194 |
+
* whose value at x = 0 is 2 * ( log(0.5) + EUL ) / M_PI
|
| 195 |
+
* = 0.073804295108687225.
|
| 196 |
+
*/
|
| 197 |
+
|
| 198 |
+
XSF_HOST_DEVICE inline double y0(double x) {
|
| 199 |
+
double w, z, p, q, xn;
|
| 200 |
+
|
| 201 |
+
if (x <= 5.0) {
|
| 202 |
+
if (x == 0.0) {
|
| 203 |
+
set_error("y0", SF_ERROR_SINGULAR, NULL);
|
| 204 |
+
return -std::numeric_limits<double>::infinity();
|
| 205 |
+
} else if (x < 0.0) {
|
| 206 |
+
set_error("y0", SF_ERROR_DOMAIN, NULL);
|
| 207 |
+
return std::numeric_limits<double>::quiet_NaN();
|
| 208 |
+
}
|
| 209 |
+
z = x * x;
|
| 210 |
+
w = polevl(z, detail::j0_YP, 7) / p1evl(z, detail::j0_YQ, 7);
|
| 211 |
+
w += M_2_PI * std::log(x) * j0(x);
|
| 212 |
+
return (w);
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
w = 5.0 / x;
|
| 216 |
+
z = 25.0 / (x * x);
|
| 217 |
+
p = polevl(z, detail::j0_PP, 6) / polevl(z, detail::j0_PQ, 6);
|
| 218 |
+
q = polevl(z, detail::j0_QP, 7) / p1evl(z, detail::j0_QQ, 7);
|
| 219 |
+
xn = x - M_PI_4;
|
| 220 |
+
p = p * std::sin(xn) + w * q * std::cos(xn);
|
| 221 |
+
return (p * detail::SQRT2OPI / std::sqrt(x));
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
} // namespace cephes
|
| 225 |
+
} // namespace xsf
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/j1.h
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Translated into C++ by SciPy developers in 2024.
|
| 2 |
+
* Original header with Copyright information appears below.
|
| 3 |
+
*/
|
| 4 |
+
|
| 5 |
+
/* j1.c
|
| 6 |
+
*
|
| 7 |
+
* Bessel function of order one
|
| 8 |
+
*
|
| 9 |
+
*
|
| 10 |
+
*
|
| 11 |
+
* SYNOPSIS:
|
| 12 |
+
*
|
| 13 |
+
* double x, y, j1();
|
| 14 |
+
*
|
| 15 |
+
* y = j1( x );
|
| 16 |
+
*
|
| 17 |
+
*
|
| 18 |
+
*
|
| 19 |
+
* DESCRIPTION:
|
| 20 |
+
*
|
| 21 |
+
* Returns Bessel function of order one of the argument.
|
| 22 |
+
*
|
| 23 |
+
* The domain is divided into the intervals [0, 8] and
|
| 24 |
+
* (8, infinity). In the first interval a 24 term Chebyshev
|
| 25 |
+
* expansion is used. In the second, the asymptotic
|
| 26 |
+
* trigonometric representation is employed using two
|
| 27 |
+
* rational functions of degree 5/5.
|
| 28 |
+
*
|
| 29 |
+
*
|
| 30 |
+
*
|
| 31 |
+
* ACCURACY:
|
| 32 |
+
*
|
| 33 |
+
* Absolute error:
|
| 34 |
+
* arithmetic domain # trials peak rms
|
| 35 |
+
* IEEE 0, 30 30000 2.6e-16 1.1e-16
|
| 36 |
+
*
|
| 37 |
+
*
|
| 38 |
+
*/
|
| 39 |
+
/* y1.c
|
| 40 |
+
*
|
| 41 |
+
* Bessel function of second kind of order one
|
| 42 |
+
*
|
| 43 |
+
*
|
| 44 |
+
*
|
| 45 |
+
* SYNOPSIS:
|
| 46 |
+
*
|
| 47 |
+
* double x, y, y1();
|
| 48 |
+
*
|
| 49 |
+
* y = y1( x );
|
| 50 |
+
*
|
| 51 |
+
*
|
| 52 |
+
*
|
| 53 |
+
* DESCRIPTION:
|
| 54 |
+
*
|
| 55 |
+
* Returns Bessel function of the second kind of order one
|
| 56 |
+
* of the argument.
|
| 57 |
+
*
|
| 58 |
+
* The domain is divided into the intervals [0, 8] and
|
| 59 |
+
* (8, infinity). In the first interval a 25 term Chebyshev
|
| 60 |
+
* expansion is used, and a call to j1() is required.
|
| 61 |
+
* In the second, the asymptotic trigonometric representation
|
| 62 |
+
* is employed using two rational functions of degree 5/5.
|
| 63 |
+
*
|
| 64 |
+
*
|
| 65 |
+
*
|
| 66 |
+
* ACCURACY:
|
| 67 |
+
*
|
| 68 |
+
* Absolute error:
|
| 69 |
+
* arithmetic domain # trials peak rms
|
| 70 |
+
* IEEE 0, 30 30000 1.0e-15 1.3e-16
|
| 71 |
+
*
|
| 72 |
+
* (error criterion relative when |y1| > 1).
|
| 73 |
+
*
|
| 74 |
+
*/
|
| 75 |
+
|
| 76 |
+
/*
|
| 77 |
+
* Cephes Math Library Release 2.8: June, 2000
|
| 78 |
+
* Copyright 1984, 1987, 1989, 2000 by Stephen L. Moshier
|
| 79 |
+
*/
|
| 80 |
+
|
| 81 |
+
/*
|
| 82 |
+
* #define PIO4 .78539816339744830962
|
| 83 |
+
* #define THPIO4 2.35619449019234492885
|
| 84 |
+
* #define SQ2OPI .79788456080286535588
|
| 85 |
+
*/
|
| 86 |
+
#pragma once
|
| 87 |
+
|
| 88 |
+
#include "../config.h"
|
| 89 |
+
#include "../error.h"
|
| 90 |
+
|
| 91 |
+
#include "const.h"
|
| 92 |
+
#include "polevl.h"
|
| 93 |
+
|
| 94 |
+
namespace xsf {
|
| 95 |
+
namespace cephes {
|
| 96 |
+
|
| 97 |
+
namespace detail {
|
| 98 |
+
constexpr double j1_RP[4] = {
|
| 99 |
+
-8.99971225705559398224E8,
|
| 100 |
+
4.52228297998194034323E11,
|
| 101 |
+
-7.27494245221818276015E13,
|
| 102 |
+
3.68295732863852883286E15,
|
| 103 |
+
};
|
| 104 |
+
|
| 105 |
+
constexpr double j1_RQ[8] = {
|
| 106 |
+
/* 1.00000000000000000000E0, */
|
| 107 |
+
6.20836478118054335476E2, 2.56987256757748830383E5, 8.35146791431949253037E7, 2.21511595479792499675E10,
|
| 108 |
+
4.74914122079991414898E12, 7.84369607876235854894E14, 8.95222336184627338078E16, 5.32278620332680085395E18,
|
| 109 |
+
};
|
| 110 |
+
|
| 111 |
+
constexpr double j1_PP[7] = {
|
| 112 |
+
7.62125616208173112003E-4, 7.31397056940917570436E-2, 1.12719608129684925192E0, 5.11207951146807644818E0,
|
| 113 |
+
8.42404590141772420927E0, 5.21451598682361504063E0, 1.00000000000000000254E0,
|
| 114 |
+
};
|
| 115 |
+
|
| 116 |
+
constexpr double j1_PQ[7] = {
|
| 117 |
+
5.71323128072548699714E-4, 6.88455908754495404082E-2, 1.10514232634061696926E0, 5.07386386128601488557E0,
|
| 118 |
+
8.39985554327604159757E0, 5.20982848682361821619E0, 9.99999999999999997461E-1,
|
| 119 |
+
};
|
| 120 |
+
|
| 121 |
+
constexpr double j1_QP[8] = {
|
| 122 |
+
5.10862594750176621635E-2, 4.98213872951233449420E0, 7.58238284132545283818E1, 3.66779609360150777800E2,
|
| 123 |
+
7.10856304998926107277E2, 5.97489612400613639965E2, 2.11688757100572135698E2, 2.52070205858023719784E1,
|
| 124 |
+
};
|
| 125 |
+
|
| 126 |
+
constexpr double j1_QQ[7] = {
|
| 127 |
+
/* 1.00000000000000000000E0, */
|
| 128 |
+
7.42373277035675149943E1, 1.05644886038262816351E3, 4.98641058337653607651E3, 9.56231892404756170795E3,
|
| 129 |
+
7.99704160447350683650E3, 2.82619278517639096600E3, 3.36093607810698293419E2,
|
| 130 |
+
};
|
| 131 |
+
|
| 132 |
+
constexpr double j1_YP[6] = {
|
| 133 |
+
1.26320474790178026440E9, -6.47355876379160291031E11, 1.14509511541823727583E14,
|
| 134 |
+
-8.12770255501325109621E15, 2.02439475713594898196E17, -7.78877196265950026825E17,
|
| 135 |
+
};
|
| 136 |
+
|
| 137 |
+
constexpr double j1_YQ[8] = {
|
| 138 |
+
/* 1.00000000000000000000E0, */
|
| 139 |
+
5.94301592346128195359E2, 2.35564092943068577943E5, 7.34811944459721705660E7, 1.87601316108706159478E10,
|
| 140 |
+
3.88231277496238566008E12, 6.20557727146953693363E14, 6.87141087355300489866E16, 3.97270608116560655612E18,
|
| 141 |
+
};
|
| 142 |
+
|
| 143 |
+
constexpr double j1_Z1 = 1.46819706421238932572E1;
|
| 144 |
+
constexpr double j1_Z2 = 4.92184563216946036703E1;
|
| 145 |
+
|
| 146 |
+
} // namespace detail
|
| 147 |
+
|
| 148 |
+
XSF_HOST_DEVICE inline double j1(double x) {
|
| 149 |
+
double w, z, p, q, xn;
|
| 150 |
+
|
| 151 |
+
w = x;
|
| 152 |
+
if (x < 0) {
|
| 153 |
+
return -j1(-x);
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
if (w <= 5.0) {
|
| 157 |
+
z = x * x;
|
| 158 |
+
w = polevl(z, detail::j1_RP, 3) / p1evl(z, detail::j1_RQ, 8);
|
| 159 |
+
w = w * x * (z - detail::j1_Z1) * (z - detail::j1_Z2);
|
| 160 |
+
return (w);
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
w = 5.0 / x;
|
| 164 |
+
z = w * w;
|
| 165 |
+
p = polevl(z, detail::j1_PP, 6) / polevl(z, detail::j1_PQ, 6);
|
| 166 |
+
q = polevl(z, detail::j1_QP, 7) / p1evl(z, detail::j1_QQ, 7);
|
| 167 |
+
xn = x - detail::THPIO4;
|
| 168 |
+
p = p * std::cos(xn) - w * q * std::sin(xn);
|
| 169 |
+
return (p * detail::SQRT2OPI / std::sqrt(x));
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
XSF_HOST_DEVICE inline double y1(double x) {
|
| 173 |
+
double w, z, p, q, xn;
|
| 174 |
+
|
| 175 |
+
if (x <= 5.0) {
|
| 176 |
+
if (x == 0.0) {
|
| 177 |
+
set_error("y1", SF_ERROR_SINGULAR, NULL);
|
| 178 |
+
return -std::numeric_limits<double>::infinity();
|
| 179 |
+
} else if (x <= 0.0) {
|
| 180 |
+
set_error("y1", SF_ERROR_DOMAIN, NULL);
|
| 181 |
+
return std::numeric_limits<double>::quiet_NaN();
|
| 182 |
+
}
|
| 183 |
+
z = x * x;
|
| 184 |
+
w = x * (polevl(z, detail::j1_YP, 5) / p1evl(z, detail::j1_YQ, 8));
|
| 185 |
+
w += M_2_PI * (j1(x) * std::log(x) - 1.0 / x);
|
| 186 |
+
return (w);
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
w = 5.0 / x;
|
| 190 |
+
z = w * w;
|
| 191 |
+
p = polevl(z, detail::j1_PP, 6) / polevl(z, detail::j1_PQ, 6);
|
| 192 |
+
q = polevl(z, detail::j1_QP, 7) / p1evl(z, detail::j1_QQ, 7);
|
| 193 |
+
xn = x - detail::THPIO4;
|
| 194 |
+
p = p * std::sin(xn) + w * q * std::cos(xn);
|
| 195 |
+
return (p * detail::SQRT2OPI / std::sqrt(x));
|
| 196 |
+
}
|
| 197 |
+
} // namespace cephes
|
| 198 |
+
} // namespace xsf
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/jv.h
ADDED
|
@@ -0,0 +1,715 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Translated into C++ by SciPy developers in 2024.
|
| 2 |
+
* Original header with Copyright information appears below.
|
| 3 |
+
*/
|
| 4 |
+
|
| 5 |
+
/* jv.c
|
| 6 |
+
*
|
| 7 |
+
* Bessel function of noninteger order
|
| 8 |
+
*
|
| 9 |
+
*
|
| 10 |
+
*
|
| 11 |
+
* SYNOPSIS:
|
| 12 |
+
*
|
| 13 |
+
* double v, x, y, jv();
|
| 14 |
+
*
|
| 15 |
+
* y = jv( v, x );
|
| 16 |
+
*
|
| 17 |
+
*
|
| 18 |
+
*
|
| 19 |
+
* DESCRIPTION:
|
| 20 |
+
*
|
| 21 |
+
* Returns Bessel function of order v of the argument,
|
| 22 |
+
* where v is real. Negative x is allowed if v is an integer.
|
| 23 |
+
*
|
| 24 |
+
* Several expansions are included: the ascending power
|
| 25 |
+
* series, the Hankel expansion, and two transitional
|
| 26 |
+
* expansions for large v. If v is not too large, it
|
| 27 |
+
* is reduced by recurrence to a region of best accuracy.
|
| 28 |
+
* The transitional expansions give 12D accuracy for v > 500.
|
| 29 |
+
*
|
| 30 |
+
*
|
| 31 |
+
*
|
| 32 |
+
* ACCURACY:
|
| 33 |
+
* Results for integer v are indicated by *, where x and v
|
| 34 |
+
* both vary from -125 to +125. Otherwise,
|
| 35 |
+
* x ranges from 0 to 125, v ranges as indicated by "domain."
|
| 36 |
+
* Error criterion is absolute, except relative when |jv()| > 1.
|
| 37 |
+
*
|
| 38 |
+
* arithmetic v domain x domain # trials peak rms
|
| 39 |
+
* IEEE 0,125 0,125 100000 4.6e-15 2.2e-16
|
| 40 |
+
* IEEE -125,0 0,125 40000 5.4e-11 3.7e-13
|
| 41 |
+
* IEEE 0,500 0,500 20000 4.4e-15 4.0e-16
|
| 42 |
+
* Integer v:
|
| 43 |
+
* IEEE -125,125 -125,125 50000 3.5e-15* 1.9e-16*
|
| 44 |
+
*
|
| 45 |
+
*/
|
| 46 |
+
|
| 47 |
+
/*
|
| 48 |
+
* Cephes Math Library Release 2.8: June, 2000
|
| 49 |
+
* Copyright 1984, 1987, 1989, 1992, 2000 by Stephen L. Moshier
|
| 50 |
+
*/
|
| 51 |
+
#pragma once
|
| 52 |
+
|
| 53 |
+
#include "../config.h"
|
| 54 |
+
#include "../error.h"
|
| 55 |
+
|
| 56 |
+
#include "airy.h"
|
| 57 |
+
#include "cbrt.h"
|
| 58 |
+
#include "rgamma.h"
|
| 59 |
+
#include "j0.h"
|
| 60 |
+
#include "j1.h"
|
| 61 |
+
#include "polevl.h"
|
| 62 |
+
|
| 63 |
+
namespace xsf {
|
| 64 |
+
namespace cephes {
|
| 65 |
+
|
| 66 |
+
namespace detail {
|
| 67 |
+
|
| 68 |
+
constexpr double jv_BIG = 1.44115188075855872E+17;
|
| 69 |
+
|
| 70 |
+
/* Reduce the order by backward recurrence.
|
| 71 |
+
* AMS55 #9.1.27 and 9.1.73.
|
| 72 |
+
*/
|
| 73 |
+
|
| 74 |
+
XSF_HOST_DEVICE inline double jv_recur(double *n, double x, double *newn, int cancel) {
|
| 75 |
+
double pkm2, pkm1, pk, qkm2, qkm1;
|
| 76 |
+
|
| 77 |
+
/* double pkp1; */
|
| 78 |
+
double k, ans, qk, xk, yk, r, t, kf;
|
| 79 |
+
constexpr double big = jv_BIG;
|
| 80 |
+
int nflag, ctr;
|
| 81 |
+
int miniter, maxiter;
|
| 82 |
+
|
| 83 |
+
/* Continued fraction for Jn(x)/Jn-1(x)
|
| 84 |
+
* AMS 9.1.73
|
| 85 |
+
*
|
| 86 |
+
* x -x^2 -x^2
|
| 87 |
+
* ------ --------- --------- ...
|
| 88 |
+
* 2 n + 2(n+1) + 2(n+2) +
|
| 89 |
+
*
|
| 90 |
+
* Compute it with the simplest possible algorithm.
|
| 91 |
+
*
|
| 92 |
+
* This continued fraction starts to converge when (|n| + m) > |x|.
|
| 93 |
+
* Hence, at least |x|-|n| iterations are necessary before convergence is
|
| 94 |
+
* achieved. There is a hard limit set below, m <= 30000, which is chosen
|
| 95 |
+
* so that no branch in `jv` requires more iterations to converge.
|
| 96 |
+
* The exact maximum number is (500/3.6)^2 - 500 ~ 19000
|
| 97 |
+
*/
|
| 98 |
+
|
| 99 |
+
maxiter = 22000;
|
| 100 |
+
miniter = std::abs(x) - std::abs(*n);
|
| 101 |
+
if (miniter < 1) {
|
| 102 |
+
miniter = 1;
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
if (*n < 0.0) {
|
| 106 |
+
nflag = 1;
|
| 107 |
+
} else {
|
| 108 |
+
nflag = 0;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
fstart:
|
| 112 |
+
pkm2 = 0.0;
|
| 113 |
+
qkm2 = 1.0;
|
| 114 |
+
pkm1 = x;
|
| 115 |
+
qkm1 = *n + *n;
|
| 116 |
+
xk = -x * x;
|
| 117 |
+
yk = qkm1;
|
| 118 |
+
ans = 0.0; /* ans=0.0 ensures that t=1.0 in the first iteration */
|
| 119 |
+
ctr = 0;
|
| 120 |
+
do {
|
| 121 |
+
yk += 2.0;
|
| 122 |
+
pk = pkm1 * yk + pkm2 * xk;
|
| 123 |
+
qk = qkm1 * yk + qkm2 * xk;
|
| 124 |
+
pkm2 = pkm1;
|
| 125 |
+
pkm1 = pk;
|
| 126 |
+
qkm2 = qkm1;
|
| 127 |
+
qkm1 = qk;
|
| 128 |
+
|
| 129 |
+
/* check convergence */
|
| 130 |
+
if (qk != 0 && ctr > miniter)
|
| 131 |
+
r = pk / qk;
|
| 132 |
+
else
|
| 133 |
+
r = 0.0;
|
| 134 |
+
|
| 135 |
+
if (r != 0) {
|
| 136 |
+
t = std::abs((ans - r) / r);
|
| 137 |
+
ans = r;
|
| 138 |
+
} else {
|
| 139 |
+
t = 1.0;
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
if (++ctr > maxiter) {
|
| 143 |
+
set_error("jv", SF_ERROR_UNDERFLOW, NULL);
|
| 144 |
+
goto done;
|
| 145 |
+
}
|
| 146 |
+
if (t < MACHEP) {
|
| 147 |
+
goto done;
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
/* renormalize coefficients */
|
| 151 |
+
if (std::abs(pk) > big) {
|
| 152 |
+
pkm2 /= big;
|
| 153 |
+
pkm1 /= big;
|
| 154 |
+
qkm2 /= big;
|
| 155 |
+
qkm1 /= big;
|
| 156 |
+
}
|
| 157 |
+
} while (t > MACHEP);
|
| 158 |
+
|
| 159 |
+
done:
|
| 160 |
+
if (ans == 0)
|
| 161 |
+
ans = 1.0;
|
| 162 |
+
|
| 163 |
+
/* Change n to n-1 if n < 0 and the continued fraction is small */
|
| 164 |
+
if (nflag > 0) {
|
| 165 |
+
if (std::abs(ans) < 0.125) {
|
| 166 |
+
nflag = -1;
|
| 167 |
+
*n = *n - 1.0;
|
| 168 |
+
goto fstart;
|
| 169 |
+
}
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
kf = *newn;
|
| 173 |
+
|
| 174 |
+
/* backward recurrence
|
| 175 |
+
* 2k
|
| 176 |
+
* J (x) = --- J (x) - J (x)
|
| 177 |
+
* k-1 x k k+1
|
| 178 |
+
*/
|
| 179 |
+
|
| 180 |
+
pk = 1.0;
|
| 181 |
+
pkm1 = 1.0 / ans;
|
| 182 |
+
k = *n - 1.0;
|
| 183 |
+
r = 2 * k;
|
| 184 |
+
do {
|
| 185 |
+
pkm2 = (pkm1 * r - pk * x) / x;
|
| 186 |
+
/* pkp1 = pk; */
|
| 187 |
+
pk = pkm1;
|
| 188 |
+
pkm1 = pkm2;
|
| 189 |
+
r -= 2.0;
|
| 190 |
+
/*
|
| 191 |
+
* t = fabs(pkp1) + fabs(pk);
|
| 192 |
+
* if( (k > (kf + 2.5)) && (fabs(pkm1) < 0.25*t) )
|
| 193 |
+
* {
|
| 194 |
+
* k -= 1.0;
|
| 195 |
+
* t = x*x;
|
| 196 |
+
* pkm2 = ( (r*(r+2.0)-t)*pk - r*x*pkp1 )/t;
|
| 197 |
+
* pkp1 = pk;
|
| 198 |
+
* pk = pkm1;
|
| 199 |
+
* pkm1 = pkm2;
|
| 200 |
+
* r -= 2.0;
|
| 201 |
+
* }
|
| 202 |
+
*/
|
| 203 |
+
k -= 1.0;
|
| 204 |
+
} while (k > (kf + 0.5));
|
| 205 |
+
|
| 206 |
+
/* Take the larger of the last two iterates
|
| 207 |
+
* on the theory that it may have less cancellation error.
|
| 208 |
+
*/
|
| 209 |
+
|
| 210 |
+
if (cancel) {
|
| 211 |
+
if ((kf >= 0.0) && (std::abs(pk) > std::abs(pkm1))) {
|
| 212 |
+
k += 1.0;
|
| 213 |
+
pkm2 = pk;
|
| 214 |
+
}
|
| 215 |
+
}
|
| 216 |
+
*newn = k;
|
| 217 |
+
return (pkm2);
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
/* Ascending power series for Jv(x).
|
| 221 |
+
* AMS55 #9.1.10.
|
| 222 |
+
*/
|
| 223 |
+
|
| 224 |
+
XSF_HOST_DEVICE inline double jv_jvs(double n, double x) {
|
| 225 |
+
double t, u, y, z, k;
|
| 226 |
+
int ex, sgngam;
|
| 227 |
+
|
| 228 |
+
z = -x * x / 4.0;
|
| 229 |
+
u = 1.0;
|
| 230 |
+
y = u;
|
| 231 |
+
k = 1.0;
|
| 232 |
+
t = 1.0;
|
| 233 |
+
|
| 234 |
+
while (t > MACHEP) {
|
| 235 |
+
u *= z / (k * (n + k));
|
| 236 |
+
y += u;
|
| 237 |
+
k += 1.0;
|
| 238 |
+
if (y != 0)
|
| 239 |
+
t = std::abs(u / y);
|
| 240 |
+
}
|
| 241 |
+
t = std::frexp(0.5 * x, &ex);
|
| 242 |
+
ex = ex * n;
|
| 243 |
+
if ((ex > -1023) && (ex < 1023) && (n > 0.0) && (n < (MAXGAM - 1.0))) {
|
| 244 |
+
t = std::pow(0.5 * x, n) * xsf::cephes::rgamma(n + 1.0);
|
| 245 |
+
y *= t;
|
| 246 |
+
} else {
|
| 247 |
+
t = n * std::log(0.5 * x) - lgam_sgn(n + 1.0, &sgngam);
|
| 248 |
+
if (y < 0) {
|
| 249 |
+
sgngam = -sgngam;
|
| 250 |
+
y = -y;
|
| 251 |
+
}
|
| 252 |
+
t += std::log(y);
|
| 253 |
+
if (t < -MAXLOG) {
|
| 254 |
+
return (0.0);
|
| 255 |
+
}
|
| 256 |
+
if (t > MAXLOG) {
|
| 257 |
+
set_error("Jv", SF_ERROR_OVERFLOW, NULL);
|
| 258 |
+
return (std::numeric_limits<double>::infinity());
|
| 259 |
+
}
|
| 260 |
+
y = sgngam * std::exp(t);
|
| 261 |
+
}
|
| 262 |
+
return (y);
|
| 263 |
+
}
|
| 264 |
+
|
| 265 |
+
/* Hankel's asymptotic expansion
|
| 266 |
+
* for large x.
|
| 267 |
+
* AMS55 #9.2.5.
|
| 268 |
+
*/
|
| 269 |
+
|
| 270 |
+
XSF_HOST_DEVICE inline double jv_hankel(double n, double x) {
|
| 271 |
+
double t, u, z, k, sign, conv;
|
| 272 |
+
double p, q, j, m, pp, qq;
|
| 273 |
+
int flag;
|
| 274 |
+
|
| 275 |
+
m = 4.0 * n * n;
|
| 276 |
+
j = 1.0;
|
| 277 |
+
z = 8.0 * x;
|
| 278 |
+
k = 1.0;
|
| 279 |
+
p = 1.0;
|
| 280 |
+
u = (m - 1.0) / z;
|
| 281 |
+
q = u;
|
| 282 |
+
sign = 1.0;
|
| 283 |
+
conv = 1.0;
|
| 284 |
+
flag = 0;
|
| 285 |
+
t = 1.0;
|
| 286 |
+
pp = 1.0e38;
|
| 287 |
+
qq = 1.0e38;
|
| 288 |
+
|
| 289 |
+
while (t > MACHEP) {
|
| 290 |
+
k += 2.0;
|
| 291 |
+
j += 1.0;
|
| 292 |
+
sign = -sign;
|
| 293 |
+
u *= (m - k * k) / (j * z);
|
| 294 |
+
p += sign * u;
|
| 295 |
+
k += 2.0;
|
| 296 |
+
j += 1.0;
|
| 297 |
+
u *= (m - k * k) / (j * z);
|
| 298 |
+
q += sign * u;
|
| 299 |
+
t = std::abs(u / p);
|
| 300 |
+
if (t < conv) {
|
| 301 |
+
conv = t;
|
| 302 |
+
qq = q;
|
| 303 |
+
pp = p;
|
| 304 |
+
flag = 1;
|
| 305 |
+
}
|
| 306 |
+
/* stop if the terms start getting larger */
|
| 307 |
+
if ((flag != 0) && (t > conv)) {
|
| 308 |
+
goto hank1;
|
| 309 |
+
}
|
| 310 |
+
}
|
| 311 |
+
|
| 312 |
+
hank1:
|
| 313 |
+
u = x - (0.5 * n + 0.25) * M_PI;
|
| 314 |
+
t = std::sqrt(2.0 / (M_PI * x)) * (pp * std::cos(u) - qq * std::sin(u));
|
| 315 |
+
return (t);
|
| 316 |
+
}
|
| 317 |
+
|
| 318 |
+
/* Asymptotic expansion for transition region,
|
| 319 |
+
* n large and x close to n.
|
| 320 |
+
* AMS55 #9.3.23.
|
| 321 |
+
*/
|
| 322 |
+
|
| 323 |
+
constexpr double jv_PF2[] = {-9.0000000000000000000e-2, 8.5714285714285714286e-2};
|
| 324 |
+
|
| 325 |
+
constexpr double jv_PF3[] = {1.3671428571428571429e-1, -5.4920634920634920635e-2, -4.4444444444444444444e-3};
|
| 326 |
+
|
| 327 |
+
constexpr double jv_PF4[] = {1.3500000000000000000e-3, -1.6036054421768707483e-1, 4.2590187590187590188e-2,
|
| 328 |
+
2.7330447330447330447e-3};
|
| 329 |
+
|
| 330 |
+
constexpr double jv_PG1[] = {-2.4285714285714285714e-1, 1.4285714285714285714e-2};
|
| 331 |
+
|
| 332 |
+
constexpr double jv_PG2[] = {-9.0000000000000000000e-3, 1.9396825396825396825e-1, -1.1746031746031746032e-2};
|
| 333 |
+
|
| 334 |
+
constexpr double jv_PG3[] = {1.9607142857142857143e-2, -1.5983694083694083694e-1, 6.3838383838383838384e-3};
|
| 335 |
+
|
| 336 |
+
XSF_HOST_DEVICE inline double jv_jnt(double n, double x) {
|
| 337 |
+
double z, zz, z3;
|
| 338 |
+
double cbn, n23, cbtwo;
|
| 339 |
+
double ai, aip, bi, bip; /* Airy functions */
|
| 340 |
+
double nk, fk, gk, pp, qq;
|
| 341 |
+
double F[5], G[4];
|
| 342 |
+
int k;
|
| 343 |
+
|
| 344 |
+
cbn = cbrt(n);
|
| 345 |
+
z = (x - n) / cbn;
|
| 346 |
+
cbtwo = cbrt(2.0);
|
| 347 |
+
|
| 348 |
+
/* Airy function */
|
| 349 |
+
zz = -cbtwo * z;
|
| 350 |
+
xsf::cephes::airy(zz, &ai, &aip, &bi, &bip);
|
| 351 |
+
|
| 352 |
+
/* polynomials in expansion */
|
| 353 |
+
zz = z * z;
|
| 354 |
+
z3 = zz * z;
|
| 355 |
+
F[0] = 1.0;
|
| 356 |
+
F[1] = -z / 5.0;
|
| 357 |
+
F[2] = xsf::cephes::polevl(z3, jv_PF2, 1) * zz;
|
| 358 |
+
F[3] = xsf::cephes::polevl(z3, jv_PF3, 2);
|
| 359 |
+
F[4] = xsf::cephes::polevl(z3, jv_PF4, 3) * z;
|
| 360 |
+
G[0] = 0.3 * zz;
|
| 361 |
+
G[1] = xsf::cephes::polevl(z3, jv_PG1, 1);
|
| 362 |
+
G[2] = xsf::cephes::polevl(z3, jv_PG2, 2) * z;
|
| 363 |
+
G[3] = xsf::cephes::polevl(z3, jv_PG3, 2) * zz;
|
| 364 |
+
|
| 365 |
+
pp = 0.0;
|
| 366 |
+
qq = 0.0;
|
| 367 |
+
nk = 1.0;
|
| 368 |
+
n23 = cbrt(n * n);
|
| 369 |
+
|
| 370 |
+
for (k = 0; k <= 4; k++) {
|
| 371 |
+
fk = F[k] * nk;
|
| 372 |
+
pp += fk;
|
| 373 |
+
if (k != 4) {
|
| 374 |
+
gk = G[k] * nk;
|
| 375 |
+
qq += gk;
|
| 376 |
+
}
|
| 377 |
+
nk /= n23;
|
| 378 |
+
}
|
| 379 |
+
|
| 380 |
+
fk = cbtwo * ai * pp / cbn + cbrt(4.0) * aip * qq / n;
|
| 381 |
+
return (fk);
|
| 382 |
+
}
|
| 383 |
+
|
| 384 |
+
/* Asymptotic expansion for large n.
|
| 385 |
+
* AMS55 #9.3.35.
|
| 386 |
+
*/
|
| 387 |
+
|
| 388 |
+
constexpr double jv_lambda[] = {1.0,
|
| 389 |
+
1.041666666666666666666667E-1,
|
| 390 |
+
8.355034722222222222222222E-2,
|
| 391 |
+
1.282265745563271604938272E-1,
|
| 392 |
+
2.918490264641404642489712E-1,
|
| 393 |
+
8.816272674437576524187671E-1,
|
| 394 |
+
3.321408281862767544702647E+0,
|
| 395 |
+
1.499576298686255465867237E+1,
|
| 396 |
+
7.892301301158651813848139E+1,
|
| 397 |
+
4.744515388682643231611949E+2,
|
| 398 |
+
3.207490090890661934704328E+3};
|
| 399 |
+
|
| 400 |
+
constexpr double jv_mu[] = {1.0,
|
| 401 |
+
-1.458333333333333333333333E-1,
|
| 402 |
+
-9.874131944444444444444444E-2,
|
| 403 |
+
-1.433120539158950617283951E-1,
|
| 404 |
+
-3.172272026784135480967078E-1,
|
| 405 |
+
-9.424291479571202491373028E-1,
|
| 406 |
+
-3.511203040826354261542798E+0,
|
| 407 |
+
-1.572726362036804512982712E+1,
|
| 408 |
+
-8.228143909718594444224656E+1,
|
| 409 |
+
-4.923553705236705240352022E+2,
|
| 410 |
+
-3.316218568547972508762102E+3};
|
| 411 |
+
|
| 412 |
+
constexpr double jv_P1[] = {-2.083333333333333333333333E-1, 1.250000000000000000000000E-1};
|
| 413 |
+
|
| 414 |
+
constexpr double jv_P2[] = {3.342013888888888888888889E-1, -4.010416666666666666666667E-1,
|
| 415 |
+
7.031250000000000000000000E-2};
|
| 416 |
+
|
| 417 |
+
constexpr double jv_P3[] = {-1.025812596450617283950617E+0, 1.846462673611111111111111E+0,
|
| 418 |
+
-8.912109375000000000000000E-1, 7.324218750000000000000000E-2};
|
| 419 |
+
|
| 420 |
+
constexpr double jv_P4[] = {4.669584423426247427983539E+0, -1.120700261622299382716049E+1,
|
| 421 |
+
8.789123535156250000000000E+0, -2.364086914062500000000000E+0,
|
| 422 |
+
1.121520996093750000000000E-1};
|
| 423 |
+
|
| 424 |
+
constexpr double jv_P5[] = {-2.8212072558200244877E1, 8.4636217674600734632E1, -9.1818241543240017361E1,
|
| 425 |
+
4.2534998745388454861E1, -7.3687943594796316964E0, 2.27108001708984375E-1};
|
| 426 |
+
|
| 427 |
+
constexpr double jv_P6[] = {2.1257013003921712286E2, -7.6525246814118164230E2, 1.0599904525279998779E3,
|
| 428 |
+
-6.9957962737613254123E2, 2.1819051174421159048E2, -2.6491430486951555525E1,
|
| 429 |
+
5.7250142097473144531E-1};
|
| 430 |
+
|
| 431 |
+
constexpr double jv_P7[] = {-1.9194576623184069963E3, 8.0617221817373093845E3, -1.3586550006434137439E4,
|
| 432 |
+
1.1655393336864533248E4, -5.3056469786134031084E3, 1.2009029132163524628E3,
|
| 433 |
+
-1.0809091978839465550E2, 1.7277275025844573975E0};
|
| 434 |
+
|
| 435 |
+
XSF_HOST_DEVICE inline double jv_jnx(double n, double x) {
|
| 436 |
+
double zeta, sqz, zz, zp, np;
|
| 437 |
+
double cbn, n23, t, z, sz;
|
| 438 |
+
double pp, qq, z32i, zzi;
|
| 439 |
+
double ak, bk, akl, bkl;
|
| 440 |
+
int sign, doa, dob, nflg, k, s, tk, tkp1, m;
|
| 441 |
+
double u[8];
|
| 442 |
+
double ai, aip, bi, bip;
|
| 443 |
+
|
| 444 |
+
/* Test for x very close to n. Use expansion for transition region if so. */
|
| 445 |
+
cbn = cbrt(n);
|
| 446 |
+
z = (x - n) / cbn;
|
| 447 |
+
if (std::abs(z) <= 0.7) {
|
| 448 |
+
return (jv_jnt(n, x));
|
| 449 |
+
}
|
| 450 |
+
|
| 451 |
+
z = x / n;
|
| 452 |
+
zz = 1.0 - z * z;
|
| 453 |
+
if (zz == 0.0) {
|
| 454 |
+
return (0.0);
|
| 455 |
+
}
|
| 456 |
+
|
| 457 |
+
if (zz > 0.0) {
|
| 458 |
+
sz = std::sqrt(zz);
|
| 459 |
+
t = 1.5 * (std::log((1.0 + sz) / z) - sz); /* zeta ** 3/2 */
|
| 460 |
+
zeta = cbrt(t * t);
|
| 461 |
+
nflg = 1;
|
| 462 |
+
} else {
|
| 463 |
+
sz = std::sqrt(-zz);
|
| 464 |
+
t = 1.5 * (sz - std::acos(1.0 / z));
|
| 465 |
+
zeta = -cbrt(t * t);
|
| 466 |
+
nflg = -1;
|
| 467 |
+
}
|
| 468 |
+
z32i = std::abs(1.0 / t);
|
| 469 |
+
sqz = cbrt(t);
|
| 470 |
+
|
| 471 |
+
/* Airy function */
|
| 472 |
+
n23 = cbrt(n * n);
|
| 473 |
+
t = n23 * zeta;
|
| 474 |
+
|
| 475 |
+
xsf::cephes::airy(t, &ai, &aip, &bi, &bip);
|
| 476 |
+
|
| 477 |
+
/* polynomials in expansion */
|
| 478 |
+
u[0] = 1.0;
|
| 479 |
+
zzi = 1.0 / zz;
|
| 480 |
+
u[1] = xsf::cephes::polevl(zzi, jv_P1, 1) / sz;
|
| 481 |
+
u[2] = xsf::cephes::polevl(zzi, jv_P2, 2) / zz;
|
| 482 |
+
u[3] = xsf::cephes::polevl(zzi, jv_P3, 3) / (sz * zz);
|
| 483 |
+
pp = zz * zz;
|
| 484 |
+
u[4] = xsf::cephes::polevl(zzi, jv_P4, 4) / pp;
|
| 485 |
+
u[5] = xsf::cephes::polevl(zzi, jv_P5, 5) / (pp * sz);
|
| 486 |
+
pp *= zz;
|
| 487 |
+
u[6] = xsf::cephes::polevl(zzi, jv_P6, 6) / pp;
|
| 488 |
+
u[7] = xsf::cephes::polevl(zzi, jv_P7, 7) / (pp * sz);
|
| 489 |
+
|
| 490 |
+
pp = 0.0;
|
| 491 |
+
qq = 0.0;
|
| 492 |
+
np = 1.0;
|
| 493 |
+
/* flags to stop when terms get larger */
|
| 494 |
+
doa = 1;
|
| 495 |
+
dob = 1;
|
| 496 |
+
akl = std::numeric_limits<double>::infinity();
|
| 497 |
+
bkl = std::numeric_limits<double>::infinity();
|
| 498 |
+
|
| 499 |
+
for (k = 0; k <= 3; k++) {
|
| 500 |
+
tk = 2 * k;
|
| 501 |
+
tkp1 = tk + 1;
|
| 502 |
+
zp = 1.0;
|
| 503 |
+
ak = 0.0;
|
| 504 |
+
bk = 0.0;
|
| 505 |
+
for (s = 0; s <= tk; s++) {
|
| 506 |
+
if (doa) {
|
| 507 |
+
if ((s & 3) > 1)
|
| 508 |
+
sign = nflg;
|
| 509 |
+
else
|
| 510 |
+
sign = 1;
|
| 511 |
+
ak += sign * jv_mu[s] * zp * u[tk - s];
|
| 512 |
+
}
|
| 513 |
+
|
| 514 |
+
if (dob) {
|
| 515 |
+
m = tkp1 - s;
|
| 516 |
+
if (((m + 1) & 3) > 1)
|
| 517 |
+
sign = nflg;
|
| 518 |
+
else
|
| 519 |
+
sign = 1;
|
| 520 |
+
bk += sign * jv_lambda[s] * zp * u[m];
|
| 521 |
+
}
|
| 522 |
+
zp *= z32i;
|
| 523 |
+
}
|
| 524 |
+
|
| 525 |
+
if (doa) {
|
| 526 |
+
ak *= np;
|
| 527 |
+
t = std::abs(ak);
|
| 528 |
+
if (t < akl) {
|
| 529 |
+
akl = t;
|
| 530 |
+
pp += ak;
|
| 531 |
+
} else
|
| 532 |
+
doa = 0;
|
| 533 |
+
}
|
| 534 |
+
|
| 535 |
+
if (dob) {
|
| 536 |
+
bk += jv_lambda[tkp1] * zp * u[0];
|
| 537 |
+
bk *= -np / sqz;
|
| 538 |
+
t = std::abs(bk);
|
| 539 |
+
if (t < bkl) {
|
| 540 |
+
bkl = t;
|
| 541 |
+
qq += bk;
|
| 542 |
+
} else
|
| 543 |
+
dob = 0;
|
| 544 |
+
}
|
| 545 |
+
if (np < MACHEP)
|
| 546 |
+
break;
|
| 547 |
+
np /= n * n;
|
| 548 |
+
}
|
| 549 |
+
|
| 550 |
+
/* normalizing factor ( 4*zeta/(1 - z**2) )**1/4 */
|
| 551 |
+
t = 4.0 * zeta / zz;
|
| 552 |
+
t = sqrt(sqrt(t));
|
| 553 |
+
|
| 554 |
+
t *= ai * pp / cbrt(n) + aip * qq / (n23 * n);
|
| 555 |
+
return (t);
|
| 556 |
+
}
|
| 557 |
+
|
| 558 |
+
} // namespace detail
|
| 559 |
+
|
| 560 |
+
XSF_HOST_DEVICE inline double jv(double n, double x) {
|
| 561 |
+
double k, q, t, y, an;
|
| 562 |
+
int i, sign, nint;
|
| 563 |
+
|
| 564 |
+
nint = 0; /* Flag for integer n */
|
| 565 |
+
sign = 1; /* Flag for sign inversion */
|
| 566 |
+
an = std::abs(n);
|
| 567 |
+
y = std::floor(an);
|
| 568 |
+
if (y == an) {
|
| 569 |
+
nint = 1;
|
| 570 |
+
i = an - 16384.0 * std::floor(an / 16384.0);
|
| 571 |
+
if (n < 0.0) {
|
| 572 |
+
if (i & 1)
|
| 573 |
+
sign = -sign;
|
| 574 |
+
n = an;
|
| 575 |
+
}
|
| 576 |
+
if (x < 0.0) {
|
| 577 |
+
if (i & 1)
|
| 578 |
+
sign = -sign;
|
| 579 |
+
x = -x;
|
| 580 |
+
}
|
| 581 |
+
if (n == 0.0)
|
| 582 |
+
return (j0(x));
|
| 583 |
+
if (n == 1.0)
|
| 584 |
+
return (sign * j1(x));
|
| 585 |
+
}
|
| 586 |
+
|
| 587 |
+
if ((x < 0.0) && (y != an)) {
|
| 588 |
+
set_error("Jv", SF_ERROR_DOMAIN, NULL);
|
| 589 |
+
y = std::numeric_limits<double>::quiet_NaN();
|
| 590 |
+
goto done;
|
| 591 |
+
}
|
| 592 |
+
|
| 593 |
+
if (x == 0 && n < 0 && !nint) {
|
| 594 |
+
set_error("Jv", SF_ERROR_OVERFLOW, NULL);
|
| 595 |
+
return std::numeric_limits<double>::infinity() * rgamma(n + 1);
|
| 596 |
+
}
|
| 597 |
+
|
| 598 |
+
y = std::abs(x);
|
| 599 |
+
|
| 600 |
+
if (y * y < std::abs(n + 1) * detail::MACHEP) {
|
| 601 |
+
return std::pow(0.5 * x, n) * rgamma(n + 1);
|
| 602 |
+
}
|
| 603 |
+
|
| 604 |
+
k = 3.6 * std::sqrt(y);
|
| 605 |
+
t = 3.6 * std::sqrt(an);
|
| 606 |
+
if ((y < t) && (an > 21.0)) {
|
| 607 |
+
return (sign * detail::jv_jvs(n, x));
|
| 608 |
+
}
|
| 609 |
+
if ((an < k) && (y > 21.0))
|
| 610 |
+
return (sign * detail::jv_hankel(n, x));
|
| 611 |
+
|
| 612 |
+
if (an < 500.0) {
|
| 613 |
+
/* Note: if x is too large, the continued fraction will fail; but then the
|
| 614 |
+
* Hankel expansion can be used. */
|
| 615 |
+
if (nint != 0) {
|
| 616 |
+
k = 0.0;
|
| 617 |
+
q = detail::jv_recur(&n, x, &k, 1);
|
| 618 |
+
if (k == 0.0) {
|
| 619 |
+
y = j0(x) / q;
|
| 620 |
+
goto done;
|
| 621 |
+
}
|
| 622 |
+
if (k == 1.0) {
|
| 623 |
+
y = j1(x) / q;
|
| 624 |
+
goto done;
|
| 625 |
+
}
|
| 626 |
+
}
|
| 627 |
+
|
| 628 |
+
if (an > 2.0 * y)
|
| 629 |
+
goto rlarger;
|
| 630 |
+
|
| 631 |
+
if ((n >= 0.0) && (n < 20.0) && (y > 6.0) && (y < 20.0)) {
|
| 632 |
+
/* Recur backwards from a larger value of n */
|
| 633 |
+
rlarger:
|
| 634 |
+
k = n;
|
| 635 |
+
|
| 636 |
+
y = y + an + 1.0;
|
| 637 |
+
if (y < 30.0)
|
| 638 |
+
y = 30.0;
|
| 639 |
+
y = n + std::floor(y - n);
|
| 640 |
+
q = detail::jv_recur(&y, x, &k, 0);
|
| 641 |
+
y = detail::jv_jvs(y, x) * q;
|
| 642 |
+
goto done;
|
| 643 |
+
}
|
| 644 |
+
|
| 645 |
+
if (k <= 30.0) {
|
| 646 |
+
k = 2.0;
|
| 647 |
+
} else if (k < 90.0) {
|
| 648 |
+
k = (3 * k) / 4;
|
| 649 |
+
}
|
| 650 |
+
if (an > (k + 3.0)) {
|
| 651 |
+
if (n < 0.0) {
|
| 652 |
+
k = -k;
|
| 653 |
+
}
|
| 654 |
+
q = n - std::floor(n);
|
| 655 |
+
k = std::floor(k) + q;
|
| 656 |
+
if (n > 0.0) {
|
| 657 |
+
q = detail::jv_recur(&n, x, &k, 1);
|
| 658 |
+
} else {
|
| 659 |
+
t = k;
|
| 660 |
+
k = n;
|
| 661 |
+
q = detail::jv_recur(&t, x, &k, 1);
|
| 662 |
+
k = t;
|
| 663 |
+
}
|
| 664 |
+
if (q == 0.0) {
|
| 665 |
+
y = 0.0;
|
| 666 |
+
goto done;
|
| 667 |
+
}
|
| 668 |
+
} else {
|
| 669 |
+
k = n;
|
| 670 |
+
q = 1.0;
|
| 671 |
+
}
|
| 672 |
+
|
| 673 |
+
/* boundary between convergence of
|
| 674 |
+
* power series and Hankel expansion
|
| 675 |
+
*/
|
| 676 |
+
y = std::abs(k);
|
| 677 |
+
if (y < 26.0)
|
| 678 |
+
t = (0.0083 * y + 0.09) * y + 12.9;
|
| 679 |
+
else
|
| 680 |
+
t = 0.9 * y;
|
| 681 |
+
|
| 682 |
+
if (x > t)
|
| 683 |
+
y = detail::jv_hankel(k, x);
|
| 684 |
+
else
|
| 685 |
+
y = detail::jv_jvs(k, x);
|
| 686 |
+
if (n > 0.0)
|
| 687 |
+
y /= q;
|
| 688 |
+
else
|
| 689 |
+
y *= q;
|
| 690 |
+
}
|
| 691 |
+
|
| 692 |
+
else {
|
| 693 |
+
/* For large n, use the uniform expansion or the transitional expansion.
|
| 694 |
+
* But if x is of the order of n**2, these may blow up, whereas the
|
| 695 |
+
* Hankel expansion will then work.
|
| 696 |
+
*/
|
| 697 |
+
if (n < 0.0) {
|
| 698 |
+
set_error("jv", SF_ERROR_LOSS, NULL);
|
| 699 |
+
y = std::numeric_limits<double>::quiet_NaN();
|
| 700 |
+
goto done;
|
| 701 |
+
}
|
| 702 |
+
t = x / n;
|
| 703 |
+
t /= n;
|
| 704 |
+
if (t > 0.3)
|
| 705 |
+
y = detail::jv_hankel(n, x);
|
| 706 |
+
else
|
| 707 |
+
y = detail::jv_jnx(n, x);
|
| 708 |
+
}
|
| 709 |
+
|
| 710 |
+
done:
|
| 711 |
+
return (sign * y);
|
| 712 |
+
}
|
| 713 |
+
|
| 714 |
+
} // namespace cephes
|
| 715 |
+
} // namespace xsf
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/k0.h
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Translated into C++ by SciPy developers in 2024.
|
| 2 |
+
* Original header with Copyright information appears below.
|
| 3 |
+
*/
|
| 4 |
+
|
| 5 |
+
/* k0.c
|
| 6 |
+
*
|
| 7 |
+
* Modified Bessel function, third kind, order zero
|
| 8 |
+
*
|
| 9 |
+
*
|
| 10 |
+
*
|
| 11 |
+
* SYNOPSIS:
|
| 12 |
+
*
|
| 13 |
+
* double x, y, k0();
|
| 14 |
+
*
|
| 15 |
+
* y = k0( x );
|
| 16 |
+
*
|
| 17 |
+
*
|
| 18 |
+
*
|
| 19 |
+
* DESCRIPTION:
|
| 20 |
+
*
|
| 21 |
+
* Returns modified Bessel function of the third kind
|
| 22 |
+
* of order zero of the argument.
|
| 23 |
+
*
|
| 24 |
+
* The range is partitioned into the two intervals [0,8] and
|
| 25 |
+
* (8, infinity). Chebyshev polynomial expansions are employed
|
| 26 |
+
* in each interval.
|
| 27 |
+
*
|
| 28 |
+
*
|
| 29 |
+
*
|
| 30 |
+
* ACCURACY:
|
| 31 |
+
*
|
| 32 |
+
* Tested at 2000 random points between 0 and 8. Peak absolute
|
| 33 |
+
* error (relative when K0 > 1) was 1.46e-14; rms, 4.26e-15.
|
| 34 |
+
* Relative error:
|
| 35 |
+
* arithmetic domain # trials peak rms
|
| 36 |
+
* IEEE 0, 30 30000 1.2e-15 1.6e-16
|
| 37 |
+
*
|
| 38 |
+
* ERROR MESSAGES:
|
| 39 |
+
*
|
| 40 |
+
* message condition value returned
|
| 41 |
+
* K0 domain x <= 0 INFINITY
|
| 42 |
+
*
|
| 43 |
+
*/
|
| 44 |
+
/* k0e()
|
| 45 |
+
*
|
| 46 |
+
* Modified Bessel function, third kind, order zero,
|
| 47 |
+
* exponentially scaled
|
| 48 |
+
*
|
| 49 |
+
*
|
| 50 |
+
*
|
| 51 |
+
* SYNOPSIS:
|
| 52 |
+
*
|
| 53 |
+
* double x, y, k0e();
|
| 54 |
+
*
|
| 55 |
+
* y = k0e( x );
|
| 56 |
+
*
|
| 57 |
+
*
|
| 58 |
+
*
|
| 59 |
+
* DESCRIPTION:
|
| 60 |
+
*
|
| 61 |
+
* Returns exponentially scaled modified Bessel function
|
| 62 |
+
* of the third kind of order zero of the argument.
|
| 63 |
+
*
|
| 64 |
+
*
|
| 65 |
+
*
|
| 66 |
+
* ACCURACY:
|
| 67 |
+
*
|
| 68 |
+
* Relative error:
|
| 69 |
+
* arithmetic domain # trials peak rms
|
| 70 |
+
* IEEE 0, 30 30000 1.4e-15 1.4e-16
|
| 71 |
+
* See k0().
|
| 72 |
+
*
|
| 73 |
+
*/
|
| 74 |
+
|
| 75 |
+
/*
|
| 76 |
+
* Cephes Math Library Release 2.8: June, 2000
|
| 77 |
+
* Copyright 1984, 1987, 2000 by Stephen L. Moshier
|
| 78 |
+
*/
|
| 79 |
+
#pragma once
|
| 80 |
+
|
| 81 |
+
#include "../config.h"
|
| 82 |
+
#include "../error.h"
|
| 83 |
+
|
| 84 |
+
#include "chbevl.h"
|
| 85 |
+
#include "i0.h"
|
| 86 |
+
|
| 87 |
+
namespace xsf {
|
| 88 |
+
namespace cephes {
|
| 89 |
+
|
| 90 |
+
namespace detail {
|
| 91 |
+
/* Chebyshev coefficients for K0(x) + log(x/2) I0(x)
|
| 92 |
+
* in the interval [0,2]. The odd order coefficients are all
|
| 93 |
+
* zero; only the even order coefficients are listed.
|
| 94 |
+
*
|
| 95 |
+
* lim(x->0){ K0(x) + log(x/2) I0(x) } = -EUL.
|
| 96 |
+
*/
|
| 97 |
+
|
| 98 |
+
constexpr double k0_A[] = {1.37446543561352307156E-16, 4.25981614279661018399E-14, 1.03496952576338420167E-11,
|
| 99 |
+
1.90451637722020886025E-9, 2.53479107902614945675E-7, 2.28621210311945178607E-5,
|
| 100 |
+
1.26461541144692592338E-3, 3.59799365153615016266E-2, 3.44289899924628486886E-1,
|
| 101 |
+
-5.35327393233902768720E-1};
|
| 102 |
+
|
| 103 |
+
/* Chebyshev coefficients for exp(x) sqrt(x) K0(x)
|
| 104 |
+
* in the inverted interval [2,infinity].
|
| 105 |
+
*
|
| 106 |
+
* lim(x->inf){ exp(x) sqrt(x) K0(x) } = sqrt(pi/2).
|
| 107 |
+
*/
|
| 108 |
+
constexpr double k0_B[] = {
|
| 109 |
+
5.30043377268626276149E-18, -1.64758043015242134646E-17, 5.21039150503902756861E-17,
|
| 110 |
+
-1.67823109680541210385E-16, 5.51205597852431940784E-16, -1.84859337734377901440E-15,
|
| 111 |
+
6.34007647740507060557E-15, -2.22751332699166985548E-14, 8.03289077536357521100E-14,
|
| 112 |
+
-2.98009692317273043925E-13, 1.14034058820847496303E-12, -4.51459788337394416547E-12,
|
| 113 |
+
1.85594911495471785253E-11, -7.95748924447710747776E-11, 3.57739728140030116597E-10,
|
| 114 |
+
-1.69753450938905987466E-9, 8.57403401741422608519E-9, -4.66048989768794782956E-8,
|
| 115 |
+
2.76681363944501510342E-7, -1.83175552271911948767E-6, 1.39498137188764993662E-5,
|
| 116 |
+
-1.28495495816278026384E-4, 1.56988388573005337491E-3, -3.14481013119645005427E-2,
|
| 117 |
+
2.44030308206595545468E0};
|
| 118 |
+
|
| 119 |
+
} // namespace detail
|
| 120 |
+
|
| 121 |
+
XSF_HOST_DEVICE inline double k0(double x) {
|
| 122 |
+
double y, z;
|
| 123 |
+
|
| 124 |
+
if (x == 0.0) {
|
| 125 |
+
set_error("k0", SF_ERROR_SINGULAR, NULL);
|
| 126 |
+
return std::numeric_limits<double>::infinity();
|
| 127 |
+
} else if (x < 0.0) {
|
| 128 |
+
set_error("k0", SF_ERROR_DOMAIN, NULL);
|
| 129 |
+
return std::numeric_limits<double>::quiet_NaN();
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
if (x <= 2.0) {
|
| 133 |
+
y = x * x - 2.0;
|
| 134 |
+
y = chbevl(y, detail::k0_A, 10) - std::log(0.5 * x) * i0(x);
|
| 135 |
+
return (y);
|
| 136 |
+
}
|
| 137 |
+
z = 8.0 / x - 2.0;
|
| 138 |
+
y = std::exp(-x) * chbevl(z, detail::k0_B, 25) / std::sqrt(x);
|
| 139 |
+
return (y);
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
XSF_HOST_DEVICE double inline k0e(double x) {
|
| 143 |
+
double y;
|
| 144 |
+
|
| 145 |
+
if (x == 0.0) {
|
| 146 |
+
set_error("k0e", SF_ERROR_SINGULAR, NULL);
|
| 147 |
+
return std::numeric_limits<double>::infinity();
|
| 148 |
+
} else if (x < 0.0) {
|
| 149 |
+
set_error("k0e", SF_ERROR_DOMAIN, NULL);
|
| 150 |
+
return std::numeric_limits<double>::quiet_NaN();
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
if (x <= 2.0) {
|
| 154 |
+
y = x * x - 2.0;
|
| 155 |
+
y = chbevl(y, detail::k0_A, 10) - std::log(0.5 * x) * i0(x);
|
| 156 |
+
return (y * exp(x));
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
y = chbevl(8.0 / x - 2.0, detail::k0_B, 25) / std::sqrt(x);
|
| 160 |
+
return (y);
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
} // namespace cephes
|
| 164 |
+
} // namespace xsf
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/k1.h
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Translated into C++ by SciPy developers in 2024.
|
| 2 |
+
* Original header with Copyright information appears below.
|
| 3 |
+
*/
|
| 4 |
+
|
| 5 |
+
/* k1.c
|
| 6 |
+
*
|
| 7 |
+
* Modified Bessel function, third kind, order one
|
| 8 |
+
*
|
| 9 |
+
*
|
| 10 |
+
*
|
| 11 |
+
* SYNOPSIS:
|
| 12 |
+
*
|
| 13 |
+
* double x, y, k1();
|
| 14 |
+
*
|
| 15 |
+
* y = k1( x );
|
| 16 |
+
*
|
| 17 |
+
*
|
| 18 |
+
*
|
| 19 |
+
* DESCRIPTION:
|
| 20 |
+
*
|
| 21 |
+
* Computes the modified Bessel function of the third kind
|
| 22 |
+
* of order one of the argument.
|
| 23 |
+
*
|
| 24 |
+
* The range is partitioned into the two intervals [0,2] and
|
| 25 |
+
* (2, infinity). Chebyshev polynomial expansions are employed
|
| 26 |
+
* in each interval.
|
| 27 |
+
*
|
| 28 |
+
*
|
| 29 |
+
*
|
| 30 |
+
* ACCURACY:
|
| 31 |
+
*
|
| 32 |
+
* Relative error:
|
| 33 |
+
* arithmetic domain # trials peak rms
|
| 34 |
+
* IEEE 0, 30 30000 1.2e-15 1.6e-16
|
| 35 |
+
*
|
| 36 |
+
* ERROR MESSAGES:
|
| 37 |
+
*
|
| 38 |
+
* message condition value returned
|
| 39 |
+
* k1 domain x <= 0 INFINITY
|
| 40 |
+
*
|
| 41 |
+
*/
|
| 42 |
+
/* k1e.c
|
| 43 |
+
*
|
| 44 |
+
* Modified Bessel function, third kind, order one,
|
| 45 |
+
* exponentially scaled
|
| 46 |
+
*
|
| 47 |
+
*
|
| 48 |
+
*
|
| 49 |
+
* SYNOPSIS:
|
| 50 |
+
*
|
| 51 |
+
* double x, y, k1e();
|
| 52 |
+
*
|
| 53 |
+
* y = k1e( x );
|
| 54 |
+
*
|
| 55 |
+
*
|
| 56 |
+
*
|
| 57 |
+
* DESCRIPTION:
|
| 58 |
+
*
|
| 59 |
+
* Returns exponentially scaled modified Bessel function
|
| 60 |
+
* of the third kind of order one of the argument:
|
| 61 |
+
*
|
| 62 |
+
* k1e(x) = exp(x) * k1(x).
|
| 63 |
+
*
|
| 64 |
+
*
|
| 65 |
+
*
|
| 66 |
+
* ACCURACY:
|
| 67 |
+
*
|
| 68 |
+
* Relative error:
|
| 69 |
+
* arithmetic domain # trials peak rms
|
| 70 |
+
* IEEE 0, 30 30000 7.8e-16 1.2e-16
|
| 71 |
+
* See k1().
|
| 72 |
+
*
|
| 73 |
+
*/
|
| 74 |
+
|
| 75 |
+
/*
|
| 76 |
+
* Cephes Math Library Release 2.8: June, 2000
|
| 77 |
+
* Copyright 1984, 1987, 2000 by Stephen L. Moshier
|
| 78 |
+
*/
|
| 79 |
+
#pragma once
|
| 80 |
+
|
| 81 |
+
#include "../config.h"
|
| 82 |
+
#include "../error.h"
|
| 83 |
+
|
| 84 |
+
#include "chbevl.h"
|
| 85 |
+
#include "const.h"
|
| 86 |
+
|
| 87 |
+
namespace xsf {
|
| 88 |
+
namespace cephes {
|
| 89 |
+
|
| 90 |
+
namespace detail {
|
| 91 |
+
/* Chebyshev coefficients for x(K1(x) - log(x/2) I1(x))
|
| 92 |
+
* in the interval [0,2].
|
| 93 |
+
*
|
| 94 |
+
* lim(x->0){ x(K1(x) - log(x/2) I1(x)) } = 1.
|
| 95 |
+
*/
|
| 96 |
+
|
| 97 |
+
constexpr double k1_A[] = {
|
| 98 |
+
-7.02386347938628759343E-18, -2.42744985051936593393E-15, -6.66690169419932900609E-13,
|
| 99 |
+
-1.41148839263352776110E-10, -2.21338763073472585583E-8, -2.43340614156596823496E-6,
|
| 100 |
+
-1.73028895751305206302E-4, -6.97572385963986435018E-3, -1.22611180822657148235E-1,
|
| 101 |
+
-3.53155960776544875667E-1, 1.52530022733894777053E0};
|
| 102 |
+
|
| 103 |
+
/* Chebyshev coefficients for exp(x) sqrt(x) K1(x)
|
| 104 |
+
* in the interval [2,infinity].
|
| 105 |
+
*
|
| 106 |
+
* lim(x->inf){ exp(x) sqrt(x) K1(x) } = sqrt(pi/2).
|
| 107 |
+
*/
|
| 108 |
+
constexpr double k1_B[] = {
|
| 109 |
+
-5.75674448366501715755E-18, 1.79405087314755922667E-17, -5.68946255844285935196E-17,
|
| 110 |
+
1.83809354436663880070E-16, -6.05704724837331885336E-16, 2.03870316562433424052E-15,
|
| 111 |
+
-7.01983709041831346144E-15, 2.47715442448130437068E-14, -8.97670518232499435011E-14,
|
| 112 |
+
3.34841966607842919884E-13, -1.28917396095102890680E-12, 5.13963967348173025100E-12,
|
| 113 |
+
-2.12996783842756842877E-11, 9.21831518760500529508E-11, -4.19035475934189648750E-10,
|
| 114 |
+
2.01504975519703286596E-9, -1.03457624656780970260E-8, 5.74108412545004946722E-8,
|
| 115 |
+
-3.50196060308781257119E-7, 2.40648494783721712015E-6, -1.93619797416608296024E-5,
|
| 116 |
+
1.95215518471351631108E-4, -2.85781685962277938680E-3, 1.03923736576817238437E-1,
|
| 117 |
+
2.72062619048444266945E0};
|
| 118 |
+
|
| 119 |
+
} // namespace detail
|
| 120 |
+
|
| 121 |
+
XSF_HOST_DEVICE inline double k1(double x) {
|
| 122 |
+
double y, z;
|
| 123 |
+
|
| 124 |
+
if (x == 0.0) {
|
| 125 |
+
set_error("k1", SF_ERROR_SINGULAR, NULL);
|
| 126 |
+
return std::numeric_limits<double>::infinity();
|
| 127 |
+
} else if (x < 0.0) {
|
| 128 |
+
set_error("k1", SF_ERROR_DOMAIN, NULL);
|
| 129 |
+
return std::numeric_limits<double>::quiet_NaN();
|
| 130 |
+
}
|
| 131 |
+
z = 0.5 * x;
|
| 132 |
+
|
| 133 |
+
if (x <= 2.0) {
|
| 134 |
+
y = x * x - 2.0;
|
| 135 |
+
y = std::log(z) * i1(x) + chbevl(y, detail::k1_A, 11) / x;
|
| 136 |
+
return (y);
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
return (std::exp(-x) * chbevl(8.0 / x - 2.0, detail::k1_B, 25) / std::sqrt(x));
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
XSF_HOST_DEVICE double k1e(double x) {
|
| 143 |
+
double y;
|
| 144 |
+
|
| 145 |
+
if (x == 0.0) {
|
| 146 |
+
set_error("k1e", SF_ERROR_SINGULAR, NULL);
|
| 147 |
+
return std::numeric_limits<double>::infinity();
|
| 148 |
+
} else if (x < 0.0) {
|
| 149 |
+
set_error("k1e", SF_ERROR_DOMAIN, NULL);
|
| 150 |
+
return std::numeric_limits<double>::quiet_NaN();
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
if (x <= 2.0) {
|
| 154 |
+
y = x * x - 2.0;
|
| 155 |
+
y = std::log(0.5 * x) * i1(x) + chbevl(y, detail::k1_A, 11) / x;
|
| 156 |
+
return (y * exp(x));
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
return (chbevl(8.0 / x - 2.0, detail::k1_B, 25) / std::sqrt(x));
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
} // namespace cephes
|
| 163 |
+
} // namespace xsf
|
miniconda3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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Translated into C++ by SciPy developers in 2024.
|
| 2 |
+
* Original header with Copyright information appears below.
|
| 3 |
+
*/
|
| 4 |
+
|
| 5 |
+
/* kn.c
|
| 6 |
+
*
|
| 7 |
+
* Modified Bessel function, third kind, integer order
|
| 8 |
+
*
|
| 9 |
+
*
|
| 10 |
+
*
|
| 11 |
+
* SYNOPSIS:
|
| 12 |
+
*
|
| 13 |
+
* double x, y, kn();
|
| 14 |
+
* int n;
|
| 15 |
+
*
|
| 16 |
+
* y = kn( n, x );
|
| 17 |
+
*
|
| 18 |
+
*
|
| 19 |
+
*
|
| 20 |
+
* DESCRIPTION:
|
| 21 |
+
*
|
| 22 |
+
* Returns modified Bessel function of the third kind
|
| 23 |
+
* of order n of the argument.
|
| 24 |
+
*
|
| 25 |
+
* The range is partitioned into the two intervals [0,9.55] and
|
| 26 |
+
* (9.55, infinity). An ascending power series is used in the
|
| 27 |
+
* low range, and an asymptotic expansion in the high range.
|
| 28 |
+
*
|
| 29 |
+
*
|
| 30 |
+
*
|
| 31 |
+
* ACCURACY:
|
| 32 |
+
*
|
| 33 |
+
* Relative error:
|
| 34 |
+
* arithmetic domain # trials peak rms
|
| 35 |
+
* IEEE 0,30 90000 1.8e-8 3.0e-10
|
| 36 |
+
*
|
| 37 |
+
* Error is high only near the crossover point x = 9.55
|
| 38 |
+
* between the two expansions used.
|
| 39 |
+
*/
|
| 40 |
+
|
| 41 |
+
/*
|
| 42 |
+
* Cephes Math Library Release 2.8: June, 2000
|
| 43 |
+
* Copyright 1984, 1987, 1988, 2000 by Stephen L. Moshier
|
| 44 |
+
*/
|
| 45 |
+
|
| 46 |
+
/*
|
| 47 |
+
* Algorithm for Kn.
|
| 48 |
+
* n-1
|
| 49 |
+
* -n - (n-k-1)! 2 k
|
| 50 |
+
* K (x) = 0.5 (x/2) > -------- (-x /4)
|
| 51 |
+
* n - k!
|
| 52 |
+
* k=0
|
| 53 |
+
*
|
| 54 |
+
* inf. 2 k
|
| 55 |
+
* n n - (x /4)
|
| 56 |
+
* + (-1) 0.5(x/2) > {p(k+1) + p(n+k+1) - 2log(x/2)} ---------
|
| 57 |
+
* - k! (n+k)!
|
| 58 |
+
* k=0
|
| 59 |
+
*
|
| 60 |
+
* where p(m) is the psi function: p(1) = -EUL and
|
| 61 |
+
*
|
| 62 |
+
* m-1
|
| 63 |
+
* -
|
| 64 |
+
* p(m) = -EUL + > 1/k
|
| 65 |
+
* -
|
| 66 |
+
* k=1
|
| 67 |
+
*
|
| 68 |
+
* For large x,
|
| 69 |
+
* 2 2 2
|
| 70 |
+
* u-1 (u-1 )(u-3 )
|
| 71 |
+
* K (z) = sqrt(pi/2z) exp(-z) { 1 + ------- + ------------ + ...}
|
| 72 |
+
* v 1 2
|
| 73 |
+
* 1! (8z) 2! (8z)
|
| 74 |
+
* asymptotically, where
|
| 75 |
+
*
|
| 76 |
+
* 2
|
| 77 |
+
* u = 4 v .
|
| 78 |
+
*
|
| 79 |
+
*/
|
| 80 |
+
#pragma once
|
| 81 |
+
|
| 82 |
+
#include "../config.h"
|
| 83 |
+
#include "../error.h"
|
| 84 |
+
|
| 85 |
+
#include "const.h"
|
| 86 |
+
|
| 87 |
+
namespace xsf {
|
| 88 |
+
namespace cephes {
|
| 89 |
+
|
| 90 |
+
namespace detail {
|
| 91 |
+
|
| 92 |
+
constexpr int kn_MAXFAC = 31;
|
| 93 |
+
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
XSF_HOST_DEVICE inline double kn(int nn, double x) {
|
| 97 |
+
double k, kf, nk1f, nkf, zn, t, s, z0, z;
|
| 98 |
+
double ans, fn, pn, pk, zmn, tlg, tox;
|
| 99 |
+
int i, n;
|
| 100 |
+
|
| 101 |
+
if (nn < 0)
|
| 102 |
+
n = -nn;
|
| 103 |
+
else
|
| 104 |
+
n = nn;
|
| 105 |
+
|
| 106 |
+
if (n > detail::kn_MAXFAC) {
|
| 107 |
+
overf:
|
| 108 |
+
set_error("kn", SF_ERROR_OVERFLOW, NULL);
|
| 109 |
+
return (std::numeric_limits<double>::infinity());
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
if (x <= 0.0) {
|
| 113 |
+
if (x < 0.0) {
|
| 114 |
+
set_error("kn", SF_ERROR_DOMAIN, NULL);
|
| 115 |
+
return std::numeric_limits<double>::quiet_NaN();
|
| 116 |
+
} else {
|
| 117 |
+
set_error("kn", SF_ERROR_SINGULAR, NULL);
|
| 118 |
+
return std::numeric_limits<double>::infinity();
|
| 119 |
+
}
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
if (x > 9.55)
|
| 123 |
+
goto asymp;
|
| 124 |
+
|
| 125 |
+
ans = 0.0;
|
| 126 |
+
z0 = 0.25 * x * x;
|
| 127 |
+
fn = 1.0;
|
| 128 |
+
pn = 0.0;
|
| 129 |
+
zmn = 1.0;
|
| 130 |
+
tox = 2.0 / x;
|
| 131 |
+
|
| 132 |
+
if (n > 0) {
|
| 133 |
+
/* compute factorial of n and psi(n) */
|
| 134 |
+
pn = -detail::SCIPY_EULER;
|
| 135 |
+
k = 1.0;
|
| 136 |
+
for (i = 1; i < n; i++) {
|
| 137 |
+
pn += 1.0 / k;
|
| 138 |
+
k += 1.0;
|
| 139 |
+
fn *= k;
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
zmn = tox;
|
| 143 |
+
|
| 144 |
+
if (n == 1) {
|
| 145 |
+
ans = 1.0 / x;
|
| 146 |
+
} else {
|
| 147 |
+
nk1f = fn / n;
|
| 148 |
+
kf = 1.0;
|
| 149 |
+
s = nk1f;
|
| 150 |
+
z = -z0;
|
| 151 |
+
zn = 1.0;
|
| 152 |
+
for (i = 1; i < n; i++) {
|
| 153 |
+
nk1f = nk1f / (n - i);
|
| 154 |
+
kf = kf * i;
|
| 155 |
+
zn *= z;
|
| 156 |
+
t = nk1f * zn / kf;
|
| 157 |
+
s += t;
|
| 158 |
+
if ((std::numeric_limits<double>::max() - std::abs(t)) < std::abs(s)) {
|
| 159 |
+
goto overf;
|
| 160 |
+
}
|
| 161 |
+
if ((tox > 1.0) && ((std::numeric_limits<double>::max() / tox) < zmn)) {
|
| 162 |
+
goto overf;
|
| 163 |
+
}
|
| 164 |
+
zmn *= tox;
|
| 165 |
+
}
|
| 166 |
+
s *= 0.5;
|
| 167 |
+
t = std::abs(s);
|
| 168 |
+
if ((zmn > 1.0) && ((std::numeric_limits<double>::max() / zmn) < t)) {
|
| 169 |
+
goto overf;
|
| 170 |
+
}
|
| 171 |
+
if ((t > 1.0) && ((std::numeric_limits<double>::max() / t) < zmn)) {
|
| 172 |
+
goto overf;
|
| 173 |
+
}
|
| 174 |
+
ans = s * zmn;
|
| 175 |
+
}
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
tlg = 2.0 * log(0.5 * x);
|
| 179 |
+
pk = -detail::SCIPY_EULER;
|
| 180 |
+
if (n == 0) {
|
| 181 |
+
pn = pk;
|
| 182 |
+
t = 1.0;
|
| 183 |
+
} else {
|
| 184 |
+
pn = pn + 1.0 / n;
|
| 185 |
+
t = 1.0 / fn;
|
| 186 |
+
}
|
| 187 |
+
s = (pk + pn - tlg) * t;
|
| 188 |
+
k = 1.0;
|
| 189 |
+
do {
|
| 190 |
+
t *= z0 / (k * (k + n));
|
| 191 |
+
pk += 1.0 / k;
|
| 192 |
+
pn += 1.0 / (k + n);
|
| 193 |
+
s += (pk + pn - tlg) * t;
|
| 194 |
+
k += 1.0;
|
| 195 |
+
} while (fabs(t / s) > detail::MACHEP);
|
| 196 |
+
|
| 197 |
+
s = 0.5 * s / zmn;
|
| 198 |
+
if (n & 1) {
|
| 199 |
+
s = -s;
|
| 200 |
+
}
|
| 201 |
+
ans += s;
|
| 202 |
+
|
| 203 |
+
return (ans);
|
| 204 |
+
|
| 205 |
+
/* Asymptotic expansion for Kn(x) */
|
| 206 |
+
/* Converges to 1.4e-17 for x > 18.4 */
|
| 207 |
+
|
| 208 |
+
asymp:
|
| 209 |
+
|
| 210 |
+
if (x > detail::MAXLOG) {
|
| 211 |
+
set_error("kn", SF_ERROR_UNDERFLOW, NULL);
|
| 212 |
+
return (0.0);
|
| 213 |
+
}
|
| 214 |
+
k = n;
|
| 215 |
+
pn = 4.0 * k * k;
|
| 216 |
+
pk = 1.0;
|
| 217 |
+
z0 = 8.0 * x;
|
| 218 |
+
fn = 1.0;
|
| 219 |
+
t = 1.0;
|
| 220 |
+
s = t;
|
| 221 |
+
nkf = std::numeric_limits<double>::infinity();
|
| 222 |
+
i = 0;
|
| 223 |
+
do {
|
| 224 |
+
z = pn - pk * pk;
|
| 225 |
+
t = t * z / (fn * z0);
|
| 226 |
+
nk1f = std::abs(t);
|
| 227 |
+
if ((i >= n) && (nk1f > nkf)) {
|
| 228 |
+
goto adone;
|
| 229 |
+
}
|
| 230 |
+
nkf = nk1f;
|
| 231 |
+
s += t;
|
| 232 |
+
fn += 1.0;
|
| 233 |
+
pk += 2.0;
|
| 234 |
+
i += 1;
|
| 235 |
+
} while (std::abs(t / s) > detail::MACHEP);
|
| 236 |
+
|
| 237 |
+
adone:
|
| 238 |
+
ans = std::exp(-x) * std::sqrt(M_PI / (2.0 * x)) * s;
|
| 239 |
+
return (ans);
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
} // namespace cephes
|
| 243 |
+
} // namespace xsf
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/lanczos.h
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* (C) Copyright John Maddock 2006.
|
| 2 |
+
* Use, modification and distribution are subject to the
|
| 3 |
+
* Boost Software License, Version 1.0. (See accompanying file
|
| 4 |
+
* LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
|
| 5 |
+
*/
|
| 6 |
+
|
| 7 |
+
/* Both lanczos.h and lanczos.c were formed from Boost's lanczos.hpp
|
| 8 |
+
*
|
| 9 |
+
* Scipy changes:
|
| 10 |
+
* - 06-22-2016: Removed all code not related to double precision and
|
| 11 |
+
* ported to c for use in Cephes. Note that the order of the
|
| 12 |
+
* coefficients is reversed to match the behavior of polevl.
|
| 13 |
+
*/
|
| 14 |
+
|
| 15 |
+
/*
|
| 16 |
+
* Optimal values for G for each N are taken from
|
| 17 |
+
* https://web.viu.ca/pughg/phdThesis/phdThesis.pdf,
|
| 18 |
+
* as are the theoretical error bounds.
|
| 19 |
+
*
|
| 20 |
+
* Constants calculated using the method described by Godfrey
|
| 21 |
+
* https://my.fit.edu/~gabdo/gamma.txt and elaborated by Toth at
|
| 22 |
+
* https://www.rskey.org/gamma.htm using NTL::RR at 1000 bit precision.
|
| 23 |
+
*/
|
| 24 |
+
|
| 25 |
+
/*
|
| 26 |
+
* Lanczos Coefficients for N=13 G=6.024680040776729583740234375
|
| 27 |
+
* Max experimental error (with arbitrary precision arithmetic) 1.196214e-17
|
| 28 |
+
* Generated with compiler: Microsoft Visual C++ version 8.0 on Win32 at Mar 23 2006
|
| 29 |
+
*
|
| 30 |
+
* Use for double precision.
|
| 31 |
+
*/
|
| 32 |
+
|
| 33 |
+
#pragma once
|
| 34 |
+
|
| 35 |
+
#include "../config.h"
|
| 36 |
+
#include "polevl.h"
|
| 37 |
+
|
| 38 |
+
namespace xsf {
|
| 39 |
+
namespace cephes {
|
| 40 |
+
|
| 41 |
+
namespace detail {
|
| 42 |
+
|
| 43 |
+
constexpr double lanczos_num[] = {
|
| 44 |
+
2.506628274631000270164908177133837338626, 210.8242777515793458725097339207133627117,
|
| 45 |
+
8071.672002365816210638002902272250613822, 186056.2653952234950402949897160456992822,
|
| 46 |
+
2876370.628935372441225409051620849613599, 31426415.58540019438061423162831820536287,
|
| 47 |
+
248874557.8620541565114603864132294232163, 1439720407.311721673663223072794912393972,
|
| 48 |
+
6039542586.35202800506429164430729792107, 17921034426.03720969991975575445893111267,
|
| 49 |
+
35711959237.35566804944018545154716670596, 42919803642.64909876895789904700198885093,
|
| 50 |
+
23531376880.41075968857200767445163675473};
|
| 51 |
+
|
| 52 |
+
constexpr double lanczos_denom[] = {1, 66, 1925, 32670, 357423, 2637558, 13339535,
|
| 53 |
+
45995730, 105258076, 150917976, 120543840, 39916800, 0};
|
| 54 |
+
|
| 55 |
+
constexpr double lanczos_sum_expg_scaled_num[] = {
|
| 56 |
+
0.006061842346248906525783753964555936883222, 0.5098416655656676188125178644804694509993,
|
| 57 |
+
19.51992788247617482847860966235652136208, 449.9445569063168119446858607650988409623,
|
| 58 |
+
6955.999602515376140356310115515198987526, 75999.29304014542649875303443598909137092,
|
| 59 |
+
601859.6171681098786670226533699352302507, 3481712.15498064590882071018964774556468,
|
| 60 |
+
14605578.08768506808414169982791359218571, 43338889.32467613834773723740590533316085,
|
| 61 |
+
86363131.28813859145546927288977868422342, 103794043.1163445451906271053616070238554,
|
| 62 |
+
56906521.91347156388090791033559122686859};
|
| 63 |
+
|
| 64 |
+
constexpr double lanczos_sum_expg_scaled_denom[] = {
|
| 65 |
+
1, 66, 1925, 32670, 357423, 2637558, 13339535, 45995730, 105258076, 150917976, 120543840, 39916800, 0};
|
| 66 |
+
|
| 67 |
+
constexpr double lanczos_sum_near_1_d[] = {
|
| 68 |
+
0.3394643171893132535170101292240837927725e-9, -0.2499505151487868335680273909354071938387e-8,
|
| 69 |
+
0.8690926181038057039526127422002498960172e-8, -0.1933117898880828348692541394841204288047e-7,
|
| 70 |
+
0.3075580174791348492737947340039992829546e-7, -0.2752907702903126466004207345038327818713e-7,
|
| 71 |
+
-0.1515973019871092388943437623825208095123e-5, 0.004785200610085071473880915854204301886437,
|
| 72 |
+
-0.1993758927614728757314233026257810172008, 1.483082862367253753040442933770164111678,
|
| 73 |
+
-3.327150580651624233553677113928873034916, 2.208709979316623790862569924861841433016};
|
| 74 |
+
|
| 75 |
+
constexpr double lanczos_sum_near_2_d[] = {
|
| 76 |
+
0.1009141566987569892221439918230042368112e-8, -0.7430396708998719707642735577238449585822e-8,
|
| 77 |
+
0.2583592566524439230844378948704262291927e-7, -0.5746670642147041587497159649318454348117e-7,
|
| 78 |
+
0.9142922068165324132060550591210267992072e-7, -0.8183698410724358930823737982119474130069e-7,
|
| 79 |
+
-0.4506604409707170077136555010018549819192e-5, 0.01422519127192419234315002746252160965831,
|
| 80 |
+
-0.5926941084905061794445733628891024027949, 4.408830289125943377923077727900630927902,
|
| 81 |
+
-9.8907772644920670589288081640128194231, 6.565936202082889535528455955485877361223};
|
| 82 |
+
|
| 83 |
+
XSF_HOST_DEVICE double lanczos_sum(double x) { return ratevl(x, lanczos_num, 12, lanczos_denom, 12); }
|
| 84 |
+
|
| 85 |
+
XSF_HOST_DEVICE double lanczos_sum_near_1(double dx) {
|
| 86 |
+
double result = 0;
|
| 87 |
+
unsigned k;
|
| 88 |
+
|
| 89 |
+
for (k = 1; k <= 12; ++k) {
|
| 90 |
+
result += (-lanczos_sum_near_1_d[k - 1] * dx) / (k * dx + k * k);
|
| 91 |
+
}
|
| 92 |
+
return result;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
XSF_HOST_DEVICE double lanczos_sum_near_2(double dx) {
|
| 96 |
+
double result = 0;
|
| 97 |
+
double x = dx + 2;
|
| 98 |
+
unsigned k;
|
| 99 |
+
|
| 100 |
+
for (k = 1; k <= 12; ++k) {
|
| 101 |
+
result += (-lanczos_sum_near_2_d[k - 1] * dx) / (x + k * x + k * k - 1);
|
| 102 |
+
}
|
| 103 |
+
return result;
|
| 104 |
+
}
|
| 105 |
+
} // namespace detail
|
| 106 |
+
|
| 107 |
+
constexpr double lanczos_g = 6.024680040776729583740234375;
|
| 108 |
+
XSF_HOST_DEVICE double lanczos_sum_expg_scaled(double x) {
|
| 109 |
+
return ratevl(x, detail::lanczos_sum_expg_scaled_num, 12, detail::lanczos_sum_expg_scaled_denom, 12);
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Translated into C++ by SciPy developers in 2024.
|
| 2 |
+
* Original header with Copyright information appears below.
|
| 3 |
+
*/
|
| 4 |
+
|
| 5 |
+
/* ndtr.c
|
| 6 |
+
*
|
| 7 |
+
* Normal distribution function
|
| 8 |
+
*
|
| 9 |
+
*
|
| 10 |
+
*
|
| 11 |
+
* SYNOPSIS:
|
| 12 |
+
*
|
| 13 |
+
* double x, y, ndtr();
|
| 14 |
+
*
|
| 15 |
+
* y = ndtr( x );
|
| 16 |
+
*
|
| 17 |
+
*
|
| 18 |
+
*
|
| 19 |
+
* DESCRIPTION:
|
| 20 |
+
*
|
| 21 |
+
* Returns the area under the Gaussian probability density
|
| 22 |
+
* function, integrated from minus infinity to x:
|
| 23 |
+
*
|
| 24 |
+
* x
|
| 25 |
+
* -
|
| 26 |
+
* 1 | | 2
|
| 27 |
+
* ndtr(x) = --------- | exp( - t /2 ) dt
|
| 28 |
+
* sqrt(2pi) | |
|
| 29 |
+
* -
|
| 30 |
+
* -inf.
|
| 31 |
+
*
|
| 32 |
+
* = ( 1 + erf(z) ) / 2
|
| 33 |
+
* = erfc(z) / 2
|
| 34 |
+
*
|
| 35 |
+
* where z = x/sqrt(2). Computation is via the functions
|
| 36 |
+
* erf and erfc.
|
| 37 |
+
*
|
| 38 |
+
*
|
| 39 |
+
* ACCURACY:
|
| 40 |
+
*
|
| 41 |
+
* Relative error:
|
| 42 |
+
* arithmetic domain # trials peak rms
|
| 43 |
+
* IEEE -13,0 30000 3.4e-14 6.7e-15
|
| 44 |
+
*
|
| 45 |
+
*
|
| 46 |
+
* ERROR MESSAGES:
|
| 47 |
+
*
|
| 48 |
+
* message condition value returned
|
| 49 |
+
* erfc underflow x > 37.519379347 0.0
|
| 50 |
+
*
|
| 51 |
+
*/
|
| 52 |
+
/* erf.c
|
| 53 |
+
*
|
| 54 |
+
* Error function
|
| 55 |
+
*
|
| 56 |
+
*
|
| 57 |
+
*
|
| 58 |
+
* SYNOPSIS:
|
| 59 |
+
*
|
| 60 |
+
* double x, y, erf();
|
| 61 |
+
*
|
| 62 |
+
* y = erf( x );
|
| 63 |
+
*
|
| 64 |
+
*
|
| 65 |
+
*
|
| 66 |
+
* DESCRIPTION:
|
| 67 |
+
*
|
| 68 |
+
* The integral is
|
| 69 |
+
*
|
| 70 |
+
* x
|
| 71 |
+
* -
|
| 72 |
+
* 2 | | 2
|
| 73 |
+
* erf(x) = -------- | exp( - t ) dt.
|
| 74 |
+
* sqrt(pi) | |
|
| 75 |
+
* -
|
| 76 |
+
* 0
|
| 77 |
+
*
|
| 78 |
+
* For 0 <= |x| < 1, erf(x) = x * P4(x**2)/Q5(x**2); otherwise
|
| 79 |
+
* erf(x) = 1 - erfc(x).
|
| 80 |
+
*
|
| 81 |
+
*
|
| 82 |
+
*
|
| 83 |
+
* ACCURACY:
|
| 84 |
+
*
|
| 85 |
+
* Relative error:
|
| 86 |
+
* arithmetic domain # trials peak rms
|
| 87 |
+
* IEEE 0,1 30000 3.7e-16 1.0e-16
|
| 88 |
+
*
|
| 89 |
+
*/
|
| 90 |
+
/* erfc.c
|
| 91 |
+
*
|
| 92 |
+
* Complementary error function
|
| 93 |
+
*
|
| 94 |
+
*
|
| 95 |
+
*
|
| 96 |
+
* SYNOPSIS:
|
| 97 |
+
*
|
| 98 |
+
* double x, y, erfc();
|
| 99 |
+
*
|
| 100 |
+
* y = erfc( x );
|
| 101 |
+
*
|
| 102 |
+
*
|
| 103 |
+
*
|
| 104 |
+
* DESCRIPTION:
|
| 105 |
+
*
|
| 106 |
+
*
|
| 107 |
+
* 1 - erf(x) =
|
| 108 |
+
*
|
| 109 |
+
* inf.
|
| 110 |
+
* -
|
| 111 |
+
* 2 | | 2
|
| 112 |
+
* erfc(x) = -------- | exp( - t ) dt
|
| 113 |
+
* sqrt(pi) | |
|
| 114 |
+
* -
|
| 115 |
+
* x
|
| 116 |
+
*
|
| 117 |
+
*
|
| 118 |
+
* For small x, erfc(x) = 1 - erf(x); otherwise rational
|
| 119 |
+
* approximations are computed.
|
| 120 |
+
*
|
| 121 |
+
*
|
| 122 |
+
*
|
| 123 |
+
* ACCURACY:
|
| 124 |
+
*
|
| 125 |
+
* Relative error:
|
| 126 |
+
* arithmetic domain # trials peak rms
|
| 127 |
+
* IEEE 0,26.6417 30000 5.7e-14 1.5e-14
|
| 128 |
+
*/
|
| 129 |
+
|
| 130 |
+
/*
|
| 131 |
+
* Cephes Math Library Release 2.2: June, 1992
|
| 132 |
+
* Copyright 1984, 1987, 1988, 1992 by Stephen L. Moshier
|
| 133 |
+
* Direct inquiries to 30 Frost Street, Cambridge, MA 02140
|
| 134 |
+
*/
|
| 135 |
+
#pragma once
|
| 136 |
+
|
| 137 |
+
#include "../config.h"
|
| 138 |
+
|
| 139 |
+
#include "const.h"
|
| 140 |
+
#include "polevl.h"
|
| 141 |
+
|
| 142 |
+
namespace xsf {
|
| 143 |
+
namespace cephes {
|
| 144 |
+
|
| 145 |
+
namespace detail {
|
| 146 |
+
|
| 147 |
+
constexpr double ndtr_P[] = {2.46196981473530512524E-10, 5.64189564831068821977E-1, 7.46321056442269912687E0,
|
| 148 |
+
4.86371970985681366614E1, 1.96520832956077098242E2, 5.26445194995477358631E2,
|
| 149 |
+
9.34528527171957607540E2, 1.02755188689515710272E3, 5.57535335369399327526E2};
|
| 150 |
+
|
| 151 |
+
constexpr double ndtr_Q[] = {
|
| 152 |
+
/* 1.00000000000000000000E0, */
|
| 153 |
+
1.32281951154744992508E1, 8.67072140885989742329E1, 3.54937778887819891062E2, 9.75708501743205489753E2,
|
| 154 |
+
1.82390916687909736289E3, 2.24633760818710981792E3, 1.65666309194161350182E3, 5.57535340817727675546E2};
|
| 155 |
+
|
| 156 |
+
constexpr double ndtr_R[] = {5.64189583547755073984E-1, 1.27536670759978104416E0, 5.01905042251180477414E0,
|
| 157 |
+
6.16021097993053585195E0, 7.40974269950448939160E0, 2.97886665372100240670E0};
|
| 158 |
+
|
| 159 |
+
constexpr double ndtr_S[] = {
|
| 160 |
+
/* 1.00000000000000000000E0, */
|
| 161 |
+
2.26052863220117276590E0, 9.39603524938001434673E0, 1.20489539808096656605E1,
|
| 162 |
+
1.70814450747565897222E1, 9.60896809063285878198E0, 3.36907645100081516050E0};
|
| 163 |
+
|
| 164 |
+
constexpr double ndtr_T[] = {9.60497373987051638749E0, 9.00260197203842689217E1, 2.23200534594684319226E3,
|
| 165 |
+
7.00332514112805075473E3, 5.55923013010394962768E4};
|
| 166 |
+
|
| 167 |
+
constexpr double ndtr_U[] = {
|
| 168 |
+
/* 1.00000000000000000000E0, */
|
| 169 |
+
3.35617141647503099647E1, 5.21357949780152679795E2, 4.59432382970980127987E3, 2.26290000613890934246E4,
|
| 170 |
+
4.92673942608635921086E4};
|
| 171 |
+
|
| 172 |
+
constexpr double ndtri_UTHRESH = 37.519379347;
|
| 173 |
+
|
| 174 |
+
} // namespace detail
|
| 175 |
+
|
| 176 |
+
XSF_HOST_DEVICE inline double erf(double x);
|
| 177 |
+
|
| 178 |
+
XSF_HOST_DEVICE inline double erfc(double a) {
|
| 179 |
+
double p, q, x, y, z;
|
| 180 |
+
|
| 181 |
+
if (std::isnan(a)) {
|
| 182 |
+
set_error("erfc", SF_ERROR_DOMAIN, NULL);
|
| 183 |
+
return std::numeric_limits<double>::quiet_NaN();
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
if (a < 0.0) {
|
| 187 |
+
x = -a;
|
| 188 |
+
} else {
|
| 189 |
+
x = a;
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
if (x < 1.0) {
|
| 193 |
+
return 1.0 - erf(a);
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
z = -a * a;
|
| 197 |
+
|
| 198 |
+
if (z < -detail::MAXLOG) {
|
| 199 |
+
goto under;
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
z = std::exp(z);
|
| 203 |
+
|
| 204 |
+
if (x < 8.0) {
|
| 205 |
+
p = polevl(x, detail::ndtr_P, 8);
|
| 206 |
+
q = p1evl(x, detail::ndtr_Q, 8);
|
| 207 |
+
} else {
|
| 208 |
+
p = polevl(x, detail::ndtr_R, 5);
|
| 209 |
+
q = p1evl(x, detail::ndtr_S, 6);
|
| 210 |
+
}
|
| 211 |
+
y = (z * p) / q;
|
| 212 |
+
|
| 213 |
+
if (a < 0) {
|
| 214 |
+
y = 2.0 - y;
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
if (y != 0.0) {
|
| 218 |
+
return y;
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
under:
|
| 222 |
+
set_error("erfc", SF_ERROR_UNDERFLOW, NULL);
|
| 223 |
+
if (a < 0) {
|
| 224 |
+
return 2.0;
|
| 225 |
+
} else {
|
| 226 |
+
return 0.0;
|
| 227 |
+
}
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
XSF_HOST_DEVICE inline double erf(double x) {
|
| 231 |
+
double y, z;
|
| 232 |
+
|
| 233 |
+
if (std::isnan(x)) {
|
| 234 |
+
set_error("erf", SF_ERROR_DOMAIN, NULL);
|
| 235 |
+
return std::numeric_limits<double>::quiet_NaN();
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
if (x < 0.0) {
|
| 239 |
+
return -erf(-x);
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
if (std::abs(x) > 1.0) {
|
| 243 |
+
return (1.0 - erfc(x));
|
| 244 |
+
}
|
| 245 |
+
z = x * x;
|
| 246 |
+
|
| 247 |
+
y = x * polevl(z, detail::ndtr_T, 4) / p1evl(z, detail::ndtr_U, 5);
|
| 248 |
+
return y;
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
XSF_HOST_DEVICE inline double ndtr(double a) {
|
| 252 |
+
double x, y, z;
|
| 253 |
+
|
| 254 |
+
if (std::isnan(a)) {
|
| 255 |
+
set_error("ndtr", SF_ERROR_DOMAIN, NULL);
|
| 256 |
+
return std::numeric_limits<double>::quiet_NaN();
|
| 257 |
+
}
|
| 258 |
+
|
| 259 |
+
x = a * M_SQRT1_2;
|
| 260 |
+
z = std::abs(x);
|
| 261 |
+
|
| 262 |
+
if (z < 1.0) {
|
| 263 |
+
y = 0.5 + 0.5 * erf(x);
|
| 264 |
+
} else {
|
| 265 |
+
y = 0.5 * erfc(z);
|
| 266 |
+
if (x > 0) {
|
| 267 |
+
y = 1.0 - y;
|
| 268 |
+
}
|
| 269 |
+
}
|
| 270 |
+
|
| 271 |
+
return y;
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
} // namespace cephes
|
| 275 |
+
} // namespace xsf
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/poch.h
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Pochhammer symbol (a)_m = gamma(a + m) / gamma(a)
|
| 3 |
+
*/
|
| 4 |
+
|
| 5 |
+
#pragma once
|
| 6 |
+
|
| 7 |
+
#include "../config.h"
|
| 8 |
+
#include "gamma.h"
|
| 9 |
+
|
| 10 |
+
namespace xsf {
|
| 11 |
+
namespace cephes {
|
| 12 |
+
|
| 13 |
+
namespace detail {
|
| 14 |
+
|
| 15 |
+
XSF_HOST_DEVICE inline double is_nonpos_int(double x) {
|
| 16 |
+
return x <= 0 && x == std::ceil(x) && std::abs(x) < 1e13;
|
| 17 |
+
}
|
| 18 |
+
} // namespace detail
|
| 19 |
+
|
| 20 |
+
XSF_HOST_DEVICE inline double poch(double a, double m) {
|
| 21 |
+
double r = 1.0;
|
| 22 |
+
|
| 23 |
+
/*
|
| 24 |
+
* 1. Reduce magnitude of `m` to |m| < 1 by using recurrence relations.
|
| 25 |
+
*
|
| 26 |
+
* This may end up in over/underflow, but then the function itself either
|
| 27 |
+
* diverges or goes to zero. In case the remainder goes to the opposite
|
| 28 |
+
* direction, we end up returning 0*INF = NAN, which is OK.
|
| 29 |
+
*/
|
| 30 |
+
|
| 31 |
+
/* Recurse down */
|
| 32 |
+
while (m >= 1.0) {
|
| 33 |
+
if (a + m == 1) {
|
| 34 |
+
break;
|
| 35 |
+
}
|
| 36 |
+
m -= 1.0;
|
| 37 |
+
r *= (a + m);
|
| 38 |
+
if (!std::isfinite(r) || r == 0) {
|
| 39 |
+
break;
|
| 40 |
+
}
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
/* Recurse up */
|
| 44 |
+
while (m <= -1.0) {
|
| 45 |
+
if (a + m == 0) {
|
| 46 |
+
break;
|
| 47 |
+
}
|
| 48 |
+
r /= (a + m);
|
| 49 |
+
m += 1.0;
|
| 50 |
+
if (!std::isfinite(r) || r == 0) {
|
| 51 |
+
break;
|
| 52 |
+
}
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
/*
|
| 56 |
+
* 2. Evaluate function with reduced `m`
|
| 57 |
+
*
|
| 58 |
+
* Now either `m` is not big, or the `r` product has over/underflown.
|
| 59 |
+
* If so, the function itself does similarly.
|
| 60 |
+
*/
|
| 61 |
+
|
| 62 |
+
if (m == 0) {
|
| 63 |
+
/* Easy case */
|
| 64 |
+
return r;
|
| 65 |
+
} else if (a > 1e4 && std::abs(m) <= 1) {
|
| 66 |
+
/* Avoid loss of precision */
|
| 67 |
+
return r * std::pow(a, m) *
|
| 68 |
+
(1 + m * (m - 1) / (2 * a) + m * (m - 1) * (m - 2) * (3 * m - 1) / (24 * a * a) +
|
| 69 |
+
m * m * (m - 1) * (m - 1) * (m - 2) * (m - 3) / (48 * a * a * a));
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
/* Check for infinity */
|
| 73 |
+
if (detail::is_nonpos_int(a + m) && !detail::is_nonpos_int(a) && a + m != m) {
|
| 74 |
+
return std::numeric_limits<double>::infinity();
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
/* Check for zero */
|
| 78 |
+
if (!detail::is_nonpos_int(a + m) && detail::is_nonpos_int(a)) {
|
| 79 |
+
return 0;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
return r * std::exp(lgam(a + m) - lgam(a)) * gammasgn(a + m) * gammasgn(a);
|
| 83 |
+
}
|
| 84 |
+
} // namespace cephes
|
| 85 |
+
} // namespace xsf
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/polevl.h
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Translated into C++ by SciPy developers in 2024.
|
| 2 |
+
* Original header with Copyright information appears below.
|
| 3 |
+
*/
|
| 4 |
+
|
| 5 |
+
/* polevl.c
|
| 6 |
+
* p1evl.c
|
| 7 |
+
*
|
| 8 |
+
* Evaluate polynomial
|
| 9 |
+
*
|
| 10 |
+
*
|
| 11 |
+
*
|
| 12 |
+
* SYNOPSIS:
|
| 13 |
+
*
|
| 14 |
+
* int N;
|
| 15 |
+
* double x, y, coef[N+1], polevl[];
|
| 16 |
+
*
|
| 17 |
+
* y = polevl( x, coef, N );
|
| 18 |
+
*
|
| 19 |
+
*
|
| 20 |
+
*
|
| 21 |
+
* DESCRIPTION:
|
| 22 |
+
*
|
| 23 |
+
* Evaluates polynomial of degree N:
|
| 24 |
+
*
|
| 25 |
+
* 2 N
|
| 26 |
+
* y = C + C x + C x +...+ C x
|
| 27 |
+
* 0 1 2 N
|
| 28 |
+
*
|
| 29 |
+
* Coefficients are stored in reverse order:
|
| 30 |
+
*
|
| 31 |
+
* coef[0] = C , ..., coef[N] = C .
|
| 32 |
+
* N 0
|
| 33 |
+
*
|
| 34 |
+
* The function p1evl() assumes that c_N = 1.0 so that coefficent
|
| 35 |
+
* is omitted from the array. Its calling arguments are
|
| 36 |
+
* otherwise the same as polevl().
|
| 37 |
+
*
|
| 38 |
+
*
|
| 39 |
+
* SPEED:
|
| 40 |
+
*
|
| 41 |
+
* In the interest of speed, there are no checks for out
|
| 42 |
+
* of bounds arithmetic. This routine is used by most of
|
| 43 |
+
* the functions in the library. Depending on available
|
| 44 |
+
* equipment features, the user may wish to rewrite the
|
| 45 |
+
* program in microcode or assembly language.
|
| 46 |
+
*
|
| 47 |
+
*/
|
| 48 |
+
|
| 49 |
+
/*
|
| 50 |
+
* Cephes Math Library Release 2.1: December, 1988
|
| 51 |
+
* Copyright 1984, 1987, 1988 by Stephen L. Moshier
|
| 52 |
+
* Direct inquiries to 30 Frost Street, Cambridge, MA 02140
|
| 53 |
+
*/
|
| 54 |
+
|
| 55 |
+
/* Sources:
|
| 56 |
+
* [1] Holin et. al., "Polynomial and Rational Function Evaluation",
|
| 57 |
+
* https://www.boost.org/doc/libs/1_61_0/libs/math/doc/html/math_toolkit/roots/rational.html
|
| 58 |
+
*/
|
| 59 |
+
|
| 60 |
+
/* Scipy changes:
|
| 61 |
+
* - 06-23-2016: add code for evaluating rational functions
|
| 62 |
+
*/
|
| 63 |
+
|
| 64 |
+
#pragma once
|
| 65 |
+
|
| 66 |
+
#include "../config.h"
|
| 67 |
+
|
| 68 |
+
namespace xsf {
|
| 69 |
+
namespace cephes {
|
| 70 |
+
XSF_HOST_DEVICE inline double polevl(double x, const double coef[], int N) {
|
| 71 |
+
double ans;
|
| 72 |
+
int i;
|
| 73 |
+
const double *p;
|
| 74 |
+
|
| 75 |
+
p = coef;
|
| 76 |
+
ans = *p++;
|
| 77 |
+
i = N;
|
| 78 |
+
|
| 79 |
+
do {
|
| 80 |
+
ans = ans * x + *p++;
|
| 81 |
+
} while (--i);
|
| 82 |
+
|
| 83 |
+
return (ans);
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
/* p1evl() */
|
| 87 |
+
/* N
|
| 88 |
+
* Evaluate polynomial when coefficient of x is 1.0.
|
| 89 |
+
* That is, C_{N} is assumed to be 1, and that coefficient
|
| 90 |
+
* is not included in the input array coef.
|
| 91 |
+
* coef must have length N and contain the polynomial coefficients
|
| 92 |
+
* stored as
|
| 93 |
+
* coef[0] = C_{N-1}
|
| 94 |
+
* coef[1] = C_{N-2}
|
| 95 |
+
* ...
|
| 96 |
+
* coef[N-2] = C_1
|
| 97 |
+
* coef[N-1] = C_0
|
| 98 |
+
* Otherwise same as polevl.
|
| 99 |
+
*/
|
| 100 |
+
|
| 101 |
+
XSF_HOST_DEVICE inline double p1evl(double x, const double coef[], int N) {
|
| 102 |
+
double ans;
|
| 103 |
+
const double *p;
|
| 104 |
+
int i;
|
| 105 |
+
|
| 106 |
+
p = coef;
|
| 107 |
+
ans = x + *p++;
|
| 108 |
+
i = N - 1;
|
| 109 |
+
|
| 110 |
+
do
|
| 111 |
+
ans = ans * x + *p++;
|
| 112 |
+
while (--i);
|
| 113 |
+
|
| 114 |
+
return (ans);
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
/* Evaluate a rational function. See [1]. */
|
| 118 |
+
|
| 119 |
+
/* The function ratevl is only used once in cephes/lanczos.h. */
|
| 120 |
+
XSF_HOST_DEVICE inline double ratevl(double x, const double num[], int M, const double denom[], int N) {
|
| 121 |
+
int i, dir;
|
| 122 |
+
double y, num_ans, denom_ans;
|
| 123 |
+
double absx = std::abs(x);
|
| 124 |
+
const double *p;
|
| 125 |
+
|
| 126 |
+
if (absx > 1) {
|
| 127 |
+
/* Evaluate as a polynomial in 1/x. */
|
| 128 |
+
dir = -1;
|
| 129 |
+
p = num + M;
|
| 130 |
+
y = 1 / x;
|
| 131 |
+
} else {
|
| 132 |
+
dir = 1;
|
| 133 |
+
p = num;
|
| 134 |
+
y = x;
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
/* Evaluate the numerator */
|
| 138 |
+
num_ans = *p;
|
| 139 |
+
p += dir;
|
| 140 |
+
for (i = 1; i <= M; i++) {
|
| 141 |
+
num_ans = num_ans * y + *p;
|
| 142 |
+
p += dir;
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
/* Evaluate the denominator */
|
| 146 |
+
if (absx > 1) {
|
| 147 |
+
p = denom + N;
|
| 148 |
+
} else {
|
| 149 |
+
p = denom;
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
denom_ans = *p;
|
| 153 |
+
p += dir;
|
| 154 |
+
for (i = 1; i <= N; i++) {
|
| 155 |
+
denom_ans = denom_ans * y + *p;
|
| 156 |
+
p += dir;
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
if (absx > 1) {
|
| 160 |
+
i = M - N;
|
| 161 |
+
return std::pow(x, i) * num_ans / denom_ans;
|
| 162 |
+
} else {
|
| 163 |
+
return num_ans / denom_ans;
|
| 164 |
+
}
|
| 165 |
+
}
|
| 166 |
+
} // namespace cephes
|
| 167 |
+
} // namespace xsf
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/psi.h
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Translated into C++ by SciPy developers in 2024.
|
| 2 |
+
* Original header with Copyright information appears below.
|
| 3 |
+
*/
|
| 4 |
+
|
| 5 |
+
/* psi.c
|
| 6 |
+
*
|
| 7 |
+
* Psi (digamma) function
|
| 8 |
+
*
|
| 9 |
+
*
|
| 10 |
+
* SYNOPSIS:
|
| 11 |
+
*
|
| 12 |
+
* double x, y, psi();
|
| 13 |
+
*
|
| 14 |
+
* y = psi( x );
|
| 15 |
+
*
|
| 16 |
+
*
|
| 17 |
+
* DESCRIPTION:
|
| 18 |
+
*
|
| 19 |
+
* d -
|
| 20 |
+
* psi(x) = -- ln | (x)
|
| 21 |
+
* dx
|
| 22 |
+
*
|
| 23 |
+
* is the logarithmic derivative of the gamma function.
|
| 24 |
+
* For integer x,
|
| 25 |
+
* n-1
|
| 26 |
+
* -
|
| 27 |
+
* psi(n) = -EUL + > 1/k.
|
| 28 |
+
* -
|
| 29 |
+
* k=1
|
| 30 |
+
*
|
| 31 |
+
* This formula is used for 0 < n <= 10. If x is negative, it
|
| 32 |
+
* is transformed to a positive argument by the reflection
|
| 33 |
+
* formula psi(1-x) = psi(x) + pi cot(pi x).
|
| 34 |
+
* For general positive x, the argument is made greater than 10
|
| 35 |
+
* using the recurrence psi(x+1) = psi(x) + 1/x.
|
| 36 |
+
* Then the following asymptotic expansion is applied:
|
| 37 |
+
*
|
| 38 |
+
* inf. B
|
| 39 |
+
* - 2k
|
| 40 |
+
* psi(x) = log(x) - 1/2x - > -------
|
| 41 |
+
* - 2k
|
| 42 |
+
* k=1 2k x
|
| 43 |
+
*
|
| 44 |
+
* where the B2k are Bernoulli numbers.
|
| 45 |
+
*
|
| 46 |
+
* ACCURACY:
|
| 47 |
+
* Relative error (except absolute when |psi| < 1):
|
| 48 |
+
* arithmetic domain # trials peak rms
|
| 49 |
+
* IEEE 0,30 30000 1.3e-15 1.4e-16
|
| 50 |
+
* IEEE -30,0 40000 1.5e-15 2.2e-16
|
| 51 |
+
*
|
| 52 |
+
* ERROR MESSAGES:
|
| 53 |
+
* message condition value returned
|
| 54 |
+
* psi singularity x integer <=0 INFINITY
|
| 55 |
+
*/
|
| 56 |
+
|
| 57 |
+
/*
|
| 58 |
+
* Cephes Math Library Release 2.8: June, 2000
|
| 59 |
+
* Copyright 1984, 1987, 1992, 2000 by Stephen L. Moshier
|
| 60 |
+
*/
|
| 61 |
+
|
| 62 |
+
/*
|
| 63 |
+
* Code for the rational approximation on [1, 2] is:
|
| 64 |
+
*
|
| 65 |
+
* (C) Copyright John Maddock 2006.
|
| 66 |
+
* Use, modification and distribution are subject to the
|
| 67 |
+
* Boost Software License, Version 1.0. (See accompanying file
|
| 68 |
+
* LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
|
| 69 |
+
*/
|
| 70 |
+
#pragma once
|
| 71 |
+
|
| 72 |
+
#include "../config.h"
|
| 73 |
+
#include "../error.h"
|
| 74 |
+
#include "const.h"
|
| 75 |
+
#include "polevl.h"
|
| 76 |
+
|
| 77 |
+
namespace xsf {
|
| 78 |
+
namespace cephes {
|
| 79 |
+
namespace detail {
|
| 80 |
+
constexpr double psi_A[] = {8.33333333333333333333E-2, -2.10927960927960927961E-2, 7.57575757575757575758E-3,
|
| 81 |
+
-4.16666666666666666667E-3, 3.96825396825396825397E-3, -8.33333333333333333333E-3,
|
| 82 |
+
8.33333333333333333333E-2};
|
| 83 |
+
|
| 84 |
+
constexpr float psi_Y = 0.99558162689208984f;
|
| 85 |
+
|
| 86 |
+
constexpr double psi_root1 = 1569415565.0 / 1073741824.0;
|
| 87 |
+
constexpr double psi_root2 = (381566830.0 / 1073741824.0) / 1073741824.0;
|
| 88 |
+
constexpr double psi_root3 = 0.9016312093258695918615325266959189453125e-19;
|
| 89 |
+
|
| 90 |
+
constexpr double psi_P[] = {-0.0020713321167745952, -0.045251321448739056, -0.28919126444774784,
|
| 91 |
+
-0.65031853770896507, -0.32555031186804491, 0.25479851061131551};
|
| 92 |
+
constexpr double psi_Q[] = {-0.55789841321675513e-6,
|
| 93 |
+
0.0021284987017821144,
|
| 94 |
+
0.054151797245674225,
|
| 95 |
+
0.43593529692665969,
|
| 96 |
+
1.4606242909763515,
|
| 97 |
+
2.0767117023730469,
|
| 98 |
+
1.0};
|
| 99 |
+
|
| 100 |
+
XSF_HOST_DEVICE double digamma_imp_1_2(double x) {
|
| 101 |
+
/*
|
| 102 |
+
* Rational approximation on [1, 2] taken from Boost.
|
| 103 |
+
*
|
| 104 |
+
* Now for the approximation, we use the form:
|
| 105 |
+
*
|
| 106 |
+
* digamma(x) = (x - root) * (Y + R(x-1))
|
| 107 |
+
*
|
| 108 |
+
* Where root is the location of the positive root of digamma,
|
| 109 |
+
* Y is a constant, and R is optimised for low absolute error
|
| 110 |
+
* compared to Y.
|
| 111 |
+
*
|
| 112 |
+
* Maximum Deviation Found: 1.466e-18
|
| 113 |
+
* At double precision, max error found: 2.452e-17
|
| 114 |
+
*/
|
| 115 |
+
double r, g;
|
| 116 |
+
|
| 117 |
+
g = x - psi_root1;
|
| 118 |
+
g -= psi_root2;
|
| 119 |
+
g -= psi_root3;
|
| 120 |
+
r = xsf::cephes::polevl(x - 1.0, psi_P, 5) / xsf::cephes::polevl(x - 1.0, psi_Q, 6);
|
| 121 |
+
|
| 122 |
+
return g * psi_Y + g * r;
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
XSF_HOST_DEVICE double psi_asy(double x) {
|
| 126 |
+
double y, z;
|
| 127 |
+
|
| 128 |
+
if (x < 1.0e17) {
|
| 129 |
+
z = 1.0 / (x * x);
|
| 130 |
+
y = z * xsf::cephes::polevl(z, psi_A, 6);
|
| 131 |
+
} else {
|
| 132 |
+
y = 0.0;
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
return std::log(x) - (0.5 / x) - y;
|
| 136 |
+
}
|
| 137 |
+
} // namespace detail
|
| 138 |
+
|
| 139 |
+
XSF_HOST_DEVICE double psi(double x) {
|
| 140 |
+
double y = 0.0;
|
| 141 |
+
double q, r;
|
| 142 |
+
int i, n;
|
| 143 |
+
|
| 144 |
+
if (std::isnan(x)) {
|
| 145 |
+
return x;
|
| 146 |
+
} else if (x == std::numeric_limits<double>::infinity()) {
|
| 147 |
+
return x;
|
| 148 |
+
} else if (x == -std::numeric_limits<double>::infinity()) {
|
| 149 |
+
return std::numeric_limits<double>::quiet_NaN();
|
| 150 |
+
} else if (x == 0) {
|
| 151 |
+
set_error("psi", SF_ERROR_SINGULAR, NULL);
|
| 152 |
+
return std::copysign(std::numeric_limits<double>::infinity(), -x);
|
| 153 |
+
} else if (x < 0.0) {
|
| 154 |
+
/* argument reduction before evaluating tan(pi * x) */
|
| 155 |
+
r = std::modf(x, &q);
|
| 156 |
+
if (r == 0.0) {
|
| 157 |
+
set_error("psi", SF_ERROR_SINGULAR, NULL);
|
| 158 |
+
return std::numeric_limits<double>::quiet_NaN();
|
| 159 |
+
}
|
| 160 |
+
y = -M_PI / std::tan(M_PI * r);
|
| 161 |
+
x = 1.0 - x;
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
/* check for positive integer up to 10 */
|
| 165 |
+
if ((x <= 10.0) && (x == std::floor(x))) {
|
| 166 |
+
n = static_cast<int>(x);
|
| 167 |
+
for (i = 1; i < n; i++) {
|
| 168 |
+
y += 1.0 / i;
|
| 169 |
+
}
|
| 170 |
+
y -= detail::SCIPY_EULER;
|
| 171 |
+
return y;
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
/* use the recurrence relation to move x into [1, 2] */
|
| 175 |
+
if (x < 1.0) {
|
| 176 |
+
y -= 1.0 / x;
|
| 177 |
+
x += 1.0;
|
| 178 |
+
} else if (x < 10.0) {
|
| 179 |
+
while (x > 2.0) {
|
| 180 |
+
x -= 1.0;
|
| 181 |
+
y += 1.0 / x;
|
| 182 |
+
}
|
| 183 |
+
}
|
| 184 |
+
if ((1.0 <= x) && (x <= 2.0)) {
|
| 185 |
+
y += detail::digamma_imp_1_2(x);
|
| 186 |
+
return y;
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
/* x is large, use the asymptotic series */
|
| 190 |
+
y += detail::psi_asy(x);
|
| 191 |
+
return y;
|
| 192 |
+
}
|
| 193 |
+
} // namespace cephes
|
| 194 |
+
} // namespace xsf
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/rgamma.h
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* rgamma.c
|
| 2 |
+
*
|
| 3 |
+
* Reciprocal Gamma function
|
| 4 |
+
*
|
| 5 |
+
*
|
| 6 |
+
*
|
| 7 |
+
* SYNOPSIS:
|
| 8 |
+
*
|
| 9 |
+
* double x, y, rgamma();
|
| 10 |
+
*
|
| 11 |
+
* y = rgamma( x );
|
| 12 |
+
*
|
| 13 |
+
*
|
| 14 |
+
*
|
| 15 |
+
* DESCRIPTION:
|
| 16 |
+
*
|
| 17 |
+
* Returns one divided by the Gamma function of the argument.
|
| 18 |
+
*
|
| 19 |
+
* The function is approximated by a Chebyshev expansion in
|
| 20 |
+
* the interval [0,1]. Range reduction is by recurrence
|
| 21 |
+
* for arguments between -34.034 and +34.84425627277176174.
|
| 22 |
+
* 0 is returned for positive arguments outside this
|
| 23 |
+
* range. For arguments less than -34.034 the cosecant
|
| 24 |
+
* reflection formula is applied; lograrithms are employed
|
| 25 |
+
* to avoid unnecessary overflow.
|
| 26 |
+
*
|
| 27 |
+
* The reciprocal Gamma function has no singularities,
|
| 28 |
+
* but overflow and underflow may occur for large arguments.
|
| 29 |
+
* These conditions return either INFINITY or 0 with
|
| 30 |
+
* appropriate sign.
|
| 31 |
+
*
|
| 32 |
+
* ACCURACY:
|
| 33 |
+
*
|
| 34 |
+
* Relative error:
|
| 35 |
+
* arithmetic domain # trials peak rms
|
| 36 |
+
* IEEE -30,+30 30000 1.1e-15 2.0e-16
|
| 37 |
+
* For arguments less than -34.034 the peak error is on the
|
| 38 |
+
* order of 5e-15 (DEC), excepting overflow or underflow.
|
| 39 |
+
*/
|
| 40 |
+
|
| 41 |
+
/*
|
| 42 |
+
* Cephes Math Library Release 2.0: April, 1987
|
| 43 |
+
* Copyright 1985, 1987 by Stephen L. Moshier
|
| 44 |
+
* Direct inquiries to 30 Frost Street, Cambridge, MA 02140
|
| 45 |
+
*/
|
| 46 |
+
#pragma once
|
| 47 |
+
|
| 48 |
+
#include "../config.h"
|
| 49 |
+
#include "../error.h"
|
| 50 |
+
#include "chbevl.h"
|
| 51 |
+
#include "const.h"
|
| 52 |
+
#include "gamma.h"
|
| 53 |
+
#include "trig.h"
|
| 54 |
+
|
| 55 |
+
namespace xsf {
|
| 56 |
+
namespace cephes {
|
| 57 |
+
|
| 58 |
+
namespace detail {
|
| 59 |
+
|
| 60 |
+
/* Chebyshev coefficients for reciprocal Gamma function
|
| 61 |
+
* in interval 0 to 1. Function is 1/(x Gamma(x)) - 1
|
| 62 |
+
*/
|
| 63 |
+
|
| 64 |
+
constexpr double rgamma_R[] = {
|
| 65 |
+
3.13173458231230000000E-17, -6.70718606477908000000E-16, 2.20039078172259550000E-15,
|
| 66 |
+
2.47691630348254132600E-13, -6.60074100411295197440E-12, 5.13850186324226978840E-11,
|
| 67 |
+
1.08965386454418662084E-9, -3.33964630686836942556E-8, 2.68975996440595483619E-7,
|
| 68 |
+
2.96001177518801696639E-6, -8.04814124978471142852E-5, 4.16609138709688864714E-4,
|
| 69 |
+
5.06579864028608725080E-3, -6.41925436109158228810E-2, -4.98558728684003594785E-3,
|
| 70 |
+
1.27546015610523951063E-1};
|
| 71 |
+
|
| 72 |
+
} // namespace detail
|
| 73 |
+
|
| 74 |
+
XSF_HOST_DEVICE double rgamma(double x) {
|
| 75 |
+
double w, y, z;
|
| 76 |
+
|
| 77 |
+
if (x == 0) {
|
| 78 |
+
// This case is separate from below to get correct sign for zero.
|
| 79 |
+
return x;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
if (x < 0 && x == std::floor(x)) {
|
| 83 |
+
// Gamma poles.
|
| 84 |
+
return 0.0;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
if (std::abs(x) > 4.0) {
|
| 88 |
+
return 1.0 / Gamma(x);
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
z = 1.0;
|
| 92 |
+
w = x;
|
| 93 |
+
|
| 94 |
+
while (w > 1.0) { /* Downward recurrence */
|
| 95 |
+
w -= 1.0;
|
| 96 |
+
z *= w;
|
| 97 |
+
}
|
| 98 |
+
while (w < 0.0) { /* Upward recurrence */
|
| 99 |
+
z /= w;
|
| 100 |
+
w += 1.0;
|
| 101 |
+
}
|
| 102 |
+
if (w == 0.0) /* Nonpositive integer */
|
| 103 |
+
return (0.0);
|
| 104 |
+
if (w == 1.0) /* Other integer */
|
| 105 |
+
return (1.0 / z);
|
| 106 |
+
|
| 107 |
+
y = w * (1.0 + chbevl(4.0 * w - 2.0, detail::rgamma_R, 16)) / z;
|
| 108 |
+
return (y);
|
| 109 |
+
}
|
| 110 |
+
} // namespace cephes
|
| 111 |
+
} // namespace xsf
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/scipy_iv.h
ADDED
|
@@ -0,0 +1,811 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Translated into C++ by SciPy developers in 2024.
|
| 2 |
+
* Original header with Copyright information appears below.
|
| 3 |
+
*/
|
| 4 |
+
|
| 5 |
+
/* iv.c
|
| 6 |
+
*
|
| 7 |
+
* Modified Bessel function of noninteger order
|
| 8 |
+
*
|
| 9 |
+
*
|
| 10 |
+
*
|
| 11 |
+
* SYNOPSIS:
|
| 12 |
+
*
|
| 13 |
+
* double v, x, y, iv();
|
| 14 |
+
*
|
| 15 |
+
* y = iv( v, x );
|
| 16 |
+
*
|
| 17 |
+
*
|
| 18 |
+
*
|
| 19 |
+
* DESCRIPTION:
|
| 20 |
+
*
|
| 21 |
+
* Returns modified Bessel function of order v of the
|
| 22 |
+
* argument. If x is negative, v must be integer valued.
|
| 23 |
+
*
|
| 24 |
+
*/
|
| 25 |
+
/* iv.c */
|
| 26 |
+
/* Modified Bessel function of noninteger order */
|
| 27 |
+
/* If x < 0, then v must be an integer. */
|
| 28 |
+
|
| 29 |
+
/*
|
| 30 |
+
* Parts of the code are copyright:
|
| 31 |
+
*
|
| 32 |
+
* Cephes Math Library Release 2.8: June, 2000
|
| 33 |
+
* Copyright 1984, 1987, 1988, 2000 by Stephen L. Moshier
|
| 34 |
+
*
|
| 35 |
+
* And other parts:
|
| 36 |
+
*
|
| 37 |
+
* Copyright (c) 2006 Xiaogang Zhang
|
| 38 |
+
* Use, modification and distribution are subject to the
|
| 39 |
+
* Boost Software License, Version 1.0.
|
| 40 |
+
*
|
| 41 |
+
* Boost Software License - Version 1.0 - August 17th, 2003
|
| 42 |
+
*
|
| 43 |
+
* Permission is hereby granted, free of charge, to any person or
|
| 44 |
+
* organization obtaining a copy of the software and accompanying
|
| 45 |
+
* documentation covered by this license (the "Software") to use, reproduce,
|
| 46 |
+
* display, distribute, execute, and transmit the Software, and to prepare
|
| 47 |
+
* derivative works of the Software, and to permit third-parties to whom the
|
| 48 |
+
* Software is furnished to do so, all subject to the following:
|
| 49 |
+
*
|
| 50 |
+
* The copyright notices in the Software and this entire statement,
|
| 51 |
+
* including the above license grant, this restriction and the following
|
| 52 |
+
* disclaimer, must be included in all copies of the Software, in whole or
|
| 53 |
+
* in part, and all derivative works of the Software, unless such copies or
|
| 54 |
+
* derivative works are solely in the form of machine-executable object code
|
| 55 |
+
* generated by a source language processor.
|
| 56 |
+
*
|
| 57 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
| 58 |
+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
| 59 |
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
|
| 60 |
+
* NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE
|
| 61 |
+
* DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY,
|
| 62 |
+
* WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
| 63 |
+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 64 |
+
* SOFTWARE.
|
| 65 |
+
*
|
| 66 |
+
* And the rest are:
|
| 67 |
+
*
|
| 68 |
+
* Copyright (C) 2009 Pauli Virtanen
|
| 69 |
+
* Distributed under the same license as Scipy.
|
| 70 |
+
*
|
| 71 |
+
*/
|
| 72 |
+
#pragma once
|
| 73 |
+
|
| 74 |
+
#include "../config.h"
|
| 75 |
+
#include "../error.h"
|
| 76 |
+
|
| 77 |
+
#include "const.h"
|
| 78 |
+
#include "gamma.h"
|
| 79 |
+
#include "trig.h"
|
| 80 |
+
|
| 81 |
+
namespace xsf {
|
| 82 |
+
namespace cephes {
|
| 83 |
+
|
| 84 |
+
namespace detail {
|
| 85 |
+
|
| 86 |
+
/*
|
| 87 |
+
* Compute Iv from (AMS5 9.7.1), asymptotic expansion for large |z|
|
| 88 |
+
* Iv ~ exp(x)/sqrt(2 pi x) ( 1 + (4*v*v-1)/8x + (4*v*v-1)(4*v*v-9)/8x/2! + ...)
|
| 89 |
+
*/
|
| 90 |
+
XSF_HOST_DEVICE inline double iv_asymptotic(double v, double x) {
|
| 91 |
+
double mu;
|
| 92 |
+
double sum, term, prefactor, factor;
|
| 93 |
+
int k;
|
| 94 |
+
|
| 95 |
+
prefactor = std::exp(x) / std::sqrt(2 * M_PI * x);
|
| 96 |
+
|
| 97 |
+
if (prefactor == std::numeric_limits<double>::infinity()) {
|
| 98 |
+
return prefactor;
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
mu = 4 * v * v;
|
| 102 |
+
sum = 1.0;
|
| 103 |
+
term = 1.0;
|
| 104 |
+
k = 1;
|
| 105 |
+
|
| 106 |
+
do {
|
| 107 |
+
factor = (mu - (2 * k - 1) * (2 * k - 1)) / (8 * x) / k;
|
| 108 |
+
if (k > 100) {
|
| 109 |
+
/* didn't converge */
|
| 110 |
+
set_error("iv(iv_asymptotic)", SF_ERROR_NO_RESULT, NULL);
|
| 111 |
+
break;
|
| 112 |
+
}
|
| 113 |
+
term *= -factor;
|
| 114 |
+
sum += term;
|
| 115 |
+
++k;
|
| 116 |
+
} while (std::abs(term) > MACHEP * std::abs(sum));
|
| 117 |
+
return sum * prefactor;
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
/*
|
| 121 |
+
* Uniform asymptotic expansion factors, (AMS5 9.3.9; AMS5 9.3.10)
|
| 122 |
+
*
|
| 123 |
+
* Computed with:
|
| 124 |
+
* --------------------
|
| 125 |
+
import numpy as np
|
| 126 |
+
t = np.poly1d([1,0])
|
| 127 |
+
def up1(p):
|
| 128 |
+
return .5*t*t*(1-t*t)*p.deriv() + 1/8. * ((1-5*t*t)*p).integ()
|
| 129 |
+
us = [np.poly1d([1])]
|
| 130 |
+
for k in range(10):
|
| 131 |
+
us.append(up1(us[-1]))
|
| 132 |
+
n = us[-1].order
|
| 133 |
+
for p in us:
|
| 134 |
+
print "{" + ", ".join(["0"]*(n-p.order) + map(repr, p)) + "},"
|
| 135 |
+
print "N_UFACTORS", len(us)
|
| 136 |
+
print "N_UFACTOR_TERMS", us[-1].order + 1
|
| 137 |
+
* --------------------
|
| 138 |
+
*/
|
| 139 |
+
constexpr int iv_N_UFACTORS = 11;
|
| 140 |
+
constexpr int iv_N_UFACTOR_TERMS = 31;
|
| 141 |
+
|
| 142 |
+
constexpr double iv_asymptotic_ufactors[iv_N_UFACTORS][iv_N_UFACTOR_TERMS] = {
|
| 143 |
+
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
|
| 144 |
+
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
| 145 |
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -0.20833333333333334,
|
| 146 |
+
0.0, 0.125, 0.0},
|
| 147 |
+
{0,
|
| 148 |
+
0,
|
| 149 |
+
0,
|
| 150 |
+
0,
|
| 151 |
+
0,
|
| 152 |
+
0,
|
| 153 |
+
0,
|
| 154 |
+
0,
|
| 155 |
+
0,
|
| 156 |
+
0,
|
| 157 |
+
0,
|
| 158 |
+
0,
|
| 159 |
+
0,
|
| 160 |
+
0,
|
| 161 |
+
0,
|
| 162 |
+
0,
|
| 163 |
+
0,
|
| 164 |
+
0,
|
| 165 |
+
0,
|
| 166 |
+
0,
|
| 167 |
+
0,
|
| 168 |
+
0,
|
| 169 |
+
0,
|
| 170 |
+
0,
|
| 171 |
+
0.3342013888888889,
|
| 172 |
+
0.0,
|
| 173 |
+
-0.40104166666666669,
|
| 174 |
+
0.0,
|
| 175 |
+
0.0703125,
|
| 176 |
+
0.0,
|
| 177 |
+
0.0},
|
| 178 |
+
{0, 0,
|
| 179 |
+
0, 0,
|
| 180 |
+
0, 0,
|
| 181 |
+
0, 0,
|
| 182 |
+
0, 0,
|
| 183 |
+
0, 0,
|
| 184 |
+
0, 0,
|
| 185 |
+
0, 0,
|
| 186 |
+
0, 0,
|
| 187 |
+
0, 0,
|
| 188 |
+
0, -1.0258125964506173,
|
| 189 |
+
0.0, 1.8464626736111112,
|
| 190 |
+
0.0, -0.89121093750000002,
|
| 191 |
+
0.0, 0.0732421875,
|
| 192 |
+
0.0, 0.0,
|
| 193 |
+
0.0},
|
| 194 |
+
{0,
|
| 195 |
+
0,
|
| 196 |
+
0,
|
| 197 |
+
0,
|
| 198 |
+
0,
|
| 199 |
+
0,
|
| 200 |
+
0,
|
| 201 |
+
0,
|
| 202 |
+
0,
|
| 203 |
+
0,
|
| 204 |
+
0,
|
| 205 |
+
0,
|
| 206 |
+
0,
|
| 207 |
+
0,
|
| 208 |
+
0,
|
| 209 |
+
0,
|
| 210 |
+
0,
|
| 211 |
+
0,
|
| 212 |
+
4.6695844234262474,
|
| 213 |
+
0.0,
|
| 214 |
+
-11.207002616222995,
|
| 215 |
+
0.0,
|
| 216 |
+
8.78912353515625,
|
| 217 |
+
0.0,
|
| 218 |
+
-2.3640869140624998,
|
| 219 |
+
0.0,
|
| 220 |
+
0.112152099609375,
|
| 221 |
+
0.0,
|
| 222 |
+
0.0,
|
| 223 |
+
0.0,
|
| 224 |
+
0.0},
|
| 225 |
+
{0, 0,
|
| 226 |
+
0, 0,
|
| 227 |
+
0, 0,
|
| 228 |
+
0, 0,
|
| 229 |
+
0, 0,
|
| 230 |
+
0, 0,
|
| 231 |
+
0, 0,
|
| 232 |
+
0, -28.212072558200244,
|
| 233 |
+
0.0, 84.636217674600744,
|
| 234 |
+
0.0, -91.818241543240035,
|
| 235 |
+
0.0, 42.534998745388457,
|
| 236 |
+
0.0, -7.3687943594796312,
|
| 237 |
+
0.0, 0.22710800170898438,
|
| 238 |
+
0.0, 0.0,
|
| 239 |
+
0.0, 0.0,
|
| 240 |
+
0.0},
|
| 241 |
+
{0,
|
| 242 |
+
0,
|
| 243 |
+
0,
|
| 244 |
+
0,
|
| 245 |
+
0,
|
| 246 |
+
0,
|
| 247 |
+
0,
|
| 248 |
+
0,
|
| 249 |
+
0,
|
| 250 |
+
0,
|
| 251 |
+
0,
|
| 252 |
+
0,
|
| 253 |
+
212.5701300392171,
|
| 254 |
+
0.0,
|
| 255 |
+
-765.25246814118157,
|
| 256 |
+
0.0,
|
| 257 |
+
1059.9904525279999,
|
| 258 |
+
0.0,
|
| 259 |
+
-699.57962737613275,
|
| 260 |
+
0.0,
|
| 261 |
+
218.19051174421159,
|
| 262 |
+
0.0,
|
| 263 |
+
-26.491430486951554,
|
| 264 |
+
0.0,
|
| 265 |
+
0.57250142097473145,
|
| 266 |
+
0.0,
|
| 267 |
+
0.0,
|
| 268 |
+
0.0,
|
| 269 |
+
0.0,
|
| 270 |
+
0.0,
|
| 271 |
+
0.0},
|
| 272 |
+
{0, 0,
|
| 273 |
+
0, 0,
|
| 274 |
+
0, 0,
|
| 275 |
+
0, 0,
|
| 276 |
+
0, -1919.4576623184068,
|
| 277 |
+
0.0, 8061.7221817373083,
|
| 278 |
+
0.0, -13586.550006434136,
|
| 279 |
+
0.0, 11655.393336864536,
|
| 280 |
+
0.0, -5305.6469786134048,
|
| 281 |
+
0.0, 1200.9029132163525,
|
| 282 |
+
0.0, -108.09091978839464,
|
| 283 |
+
0.0, 1.7277275025844574,
|
| 284 |
+
0.0, 0.0,
|
| 285 |
+
0.0, 0.0,
|
| 286 |
+
0.0, 0.0,
|
| 287 |
+
0.0},
|
| 288 |
+
{0,
|
| 289 |
+
0,
|
| 290 |
+
0,
|
| 291 |
+
0,
|
| 292 |
+
0,
|
| 293 |
+
0,
|
| 294 |
+
20204.291330966149,
|
| 295 |
+
0.0,
|
| 296 |
+
-96980.598388637503,
|
| 297 |
+
0.0,
|
| 298 |
+
192547.0012325315,
|
| 299 |
+
0.0,
|
| 300 |
+
-203400.17728041555,
|
| 301 |
+
0.0,
|
| 302 |
+
122200.46498301747,
|
| 303 |
+
0.0,
|
| 304 |
+
-41192.654968897557,
|
| 305 |
+
0.0,
|
| 306 |
+
7109.5143024893641,
|
| 307 |
+
0.0,
|
| 308 |
+
-493.915304773088,
|
| 309 |
+
0.0,
|
| 310 |
+
6.074042001273483,
|
| 311 |
+
0.0,
|
| 312 |
+
0.0,
|
| 313 |
+
0.0,
|
| 314 |
+
0.0,
|
| 315 |
+
0.0,
|
| 316 |
+
0.0,
|
| 317 |
+
0.0,
|
| 318 |
+
0.0},
|
| 319 |
+
{0, 0,
|
| 320 |
+
0, -242919.18790055133,
|
| 321 |
+
0.0, 1311763.6146629769,
|
| 322 |
+
0.0, -2998015.9185381061,
|
| 323 |
+
0.0, 3763271.2976564039,
|
| 324 |
+
0.0, -2813563.2265865342,
|
| 325 |
+
0.0, 1268365.2733216248,
|
| 326 |
+
0.0, -331645.17248456361,
|
| 327 |
+
0.0, 45218.768981362737,
|
| 328 |
+
0.0, -2499.8304818112092,
|
| 329 |
+
0.0, 24.380529699556064,
|
| 330 |
+
0.0, 0.0,
|
| 331 |
+
0.0, 0.0,
|
| 332 |
+
0.0, 0.0,
|
| 333 |
+
0.0, 0.0,
|
| 334 |
+
0.0},
|
| 335 |
+
{3284469.8530720375,
|
| 336 |
+
0.0,
|
| 337 |
+
-19706819.11843222,
|
| 338 |
+
0.0,
|
| 339 |
+
50952602.492664628,
|
| 340 |
+
0.0,
|
| 341 |
+
-74105148.211532637,
|
| 342 |
+
0.0,
|
| 343 |
+
66344512.274729028,
|
| 344 |
+
0.0,
|
| 345 |
+
-37567176.660763353,
|
| 346 |
+
0.0,
|
| 347 |
+
13288767.166421819,
|
| 348 |
+
0.0,
|
| 349 |
+
-2785618.1280864552,
|
| 350 |
+
0.0,
|
| 351 |
+
308186.40461266245,
|
| 352 |
+
0.0,
|
| 353 |
+
-13886.089753717039,
|
| 354 |
+
0.0,
|
| 355 |
+
110.01714026924674,
|
| 356 |
+
0.0,
|
| 357 |
+
0.0,
|
| 358 |
+
0.0,
|
| 359 |
+
0.0,
|
| 360 |
+
0.0,
|
| 361 |
+
0.0,
|
| 362 |
+
0.0,
|
| 363 |
+
0.0,
|
| 364 |
+
0.0,
|
| 365 |
+
0.0}};
|
| 366 |
+
|
| 367 |
+
/*
|
| 368 |
+
* Compute Iv, Kv from (AMS5 9.7.7 + 9.7.8), asymptotic expansion for large v
|
| 369 |
+
*/
|
| 370 |
+
XSF_HOST_DEVICE inline void ikv_asymptotic_uniform(double v, double x, double *i_value, double *k_value) {
|
| 371 |
+
double i_prefactor, k_prefactor;
|
| 372 |
+
double t, t2, eta, z;
|
| 373 |
+
double i_sum, k_sum, term, divisor;
|
| 374 |
+
int k, n;
|
| 375 |
+
int sign = 1;
|
| 376 |
+
|
| 377 |
+
if (v < 0) {
|
| 378 |
+
/* Negative v; compute I_{-v} and K_{-v} and use (AMS 9.6.2) */
|
| 379 |
+
sign = -1;
|
| 380 |
+
v = -v;
|
| 381 |
+
}
|
| 382 |
+
|
| 383 |
+
z = x / v;
|
| 384 |
+
t = 1 / std::sqrt(1 + z * z);
|
| 385 |
+
t2 = t * t;
|
| 386 |
+
eta = std::sqrt(1 + z * z) + std::log(z / (1 + 1 / t));
|
| 387 |
+
|
| 388 |
+
i_prefactor = std::sqrt(t / (2 * M_PI * v)) * std::exp(v * eta);
|
| 389 |
+
i_sum = 1.0;
|
| 390 |
+
|
| 391 |
+
k_prefactor = std::sqrt(M_PI * t / (2 * v)) * std::exp(-v * eta);
|
| 392 |
+
k_sum = 1.0;
|
| 393 |
+
|
| 394 |
+
divisor = v;
|
| 395 |
+
for (n = 1; n < iv_N_UFACTORS; ++n) {
|
| 396 |
+
/*
|
| 397 |
+
* Evaluate u_k(t) with Horner's scheme;
|
| 398 |
+
* (using the knowledge about which coefficients are zero)
|
| 399 |
+
*/
|
| 400 |
+
term = 0;
|
| 401 |
+
for (k = iv_N_UFACTOR_TERMS - 1 - 3 * n; k < iv_N_UFACTOR_TERMS - n; k += 2) {
|
| 402 |
+
term *= t2;
|
| 403 |
+
term += iv_asymptotic_ufactors[n][k];
|
| 404 |
+
}
|
| 405 |
+
for (k = 1; k < n; k += 2) {
|
| 406 |
+
term *= t2;
|
| 407 |
+
}
|
| 408 |
+
if (n % 2 == 1) {
|
| 409 |
+
term *= t;
|
| 410 |
+
}
|
| 411 |
+
|
| 412 |
+
/* Sum terms */
|
| 413 |
+
term /= divisor;
|
| 414 |
+
i_sum += term;
|
| 415 |
+
k_sum += (n % 2 == 0) ? term : -term;
|
| 416 |
+
|
| 417 |
+
/* Check convergence */
|
| 418 |
+
if (std::abs(term) < MACHEP) {
|
| 419 |
+
break;
|
| 420 |
+
}
|
| 421 |
+
|
| 422 |
+
divisor *= v;
|
| 423 |
+
}
|
| 424 |
+
|
| 425 |
+
if (std::abs(term) > 1e-3 * std::abs(i_sum)) {
|
| 426 |
+
/* Didn't converge */
|
| 427 |
+
set_error("ikv_asymptotic_uniform", SF_ERROR_NO_RESULT, NULL);
|
| 428 |
+
}
|
| 429 |
+
if (std::abs(term) > MACHEP * std::abs(i_sum)) {
|
| 430 |
+
/* Some precision lost */
|
| 431 |
+
set_error("ikv_asymptotic_uniform", SF_ERROR_LOSS, NULL);
|
| 432 |
+
}
|
| 433 |
+
|
| 434 |
+
if (k_value != NULL) {
|
| 435 |
+
/* symmetric in v */
|
| 436 |
+
*k_value = k_prefactor * k_sum;
|
| 437 |
+
}
|
| 438 |
+
|
| 439 |
+
if (i_value != NULL) {
|
| 440 |
+
if (sign == 1) {
|
| 441 |
+
*i_value = i_prefactor * i_sum;
|
| 442 |
+
} else {
|
| 443 |
+
/* (AMS 9.6.2) */
|
| 444 |
+
*i_value = (i_prefactor * i_sum + (2 / M_PI) * xsf::cephes::sinpi(v) * k_prefactor * k_sum);
|
| 445 |
+
}
|
| 446 |
+
}
|
| 447 |
+
}
|
| 448 |
+
|
| 449 |
+
/*
|
| 450 |
+
* The following code originates from the Boost C++ library,
|
| 451 |
+
* from file `boost/math/special_functions/detail/bessel_ik.hpp`,
|
| 452 |
+
* converted from C++ to C.
|
| 453 |
+
*/
|
| 454 |
+
|
| 455 |
+
/*
|
| 456 |
+
* Modified Bessel functions of the first and second kind of fractional order
|
| 457 |
+
*
|
| 458 |
+
* Calculate K(v, x) and K(v+1, x) by method analogous to
|
| 459 |
+
* Temme, Journal of Computational Physics, vol 21, 343 (1976)
|
| 460 |
+
*/
|
| 461 |
+
XSF_HOST_DEVICE inline int temme_ik_series(double v, double x, double *K, double *K1) {
|
| 462 |
+
double f, h, p, q, coef, sum, sum1, tolerance;
|
| 463 |
+
double a, b, c, d, sigma, gamma1, gamma2;
|
| 464 |
+
std::uint64_t k;
|
| 465 |
+
double gp;
|
| 466 |
+
double gm;
|
| 467 |
+
|
| 468 |
+
/*
|
| 469 |
+
* |x| <= 2, Temme series converge rapidly
|
| 470 |
+
* |x| > 2, the larger the |x|, the slower the convergence
|
| 471 |
+
*/
|
| 472 |
+
XSF_ASSERT(std::abs(x) <= 2);
|
| 473 |
+
XSF_ASSERT(std::abs(v) <= 0.5f);
|
| 474 |
+
|
| 475 |
+
gp = xsf::cephes::Gamma(v + 1) - 1;
|
| 476 |
+
gm = xsf::cephes::Gamma(-v + 1) - 1;
|
| 477 |
+
|
| 478 |
+
a = std::log(x / 2);
|
| 479 |
+
b = std::exp(v * a);
|
| 480 |
+
sigma = -a * v;
|
| 481 |
+
c = std::abs(v) < MACHEP ? 1 : xsf::cephes::sinpi(v) / (v * M_PI);
|
| 482 |
+
d = std::abs(sigma) < MACHEP ? 1 : std::sinh(sigma) / sigma;
|
| 483 |
+
gamma1 = std::abs(v) < MACHEP ? -SCIPY_EULER : (0.5 / v) * (gp - gm) * c;
|
| 484 |
+
gamma2 = (2 + gp + gm) * c / 2;
|
| 485 |
+
|
| 486 |
+
/* initial values */
|
| 487 |
+
p = (gp + 1) / (2 * b);
|
| 488 |
+
q = (1 + gm) * b / 2;
|
| 489 |
+
f = (std::cosh(sigma) * gamma1 + d * (-a) * gamma2) / c;
|
| 490 |
+
h = p;
|
| 491 |
+
coef = 1;
|
| 492 |
+
sum = coef * f;
|
| 493 |
+
sum1 = coef * h;
|
| 494 |
+
|
| 495 |
+
/* series summation */
|
| 496 |
+
tolerance = MACHEP;
|
| 497 |
+
for (k = 1; k < MAXITER; k++) {
|
| 498 |
+
f = (k * f + p + q) / (k * k - v * v);
|
| 499 |
+
p /= k - v;
|
| 500 |
+
q /= k + v;
|
| 501 |
+
h = p - k * f;
|
| 502 |
+
coef *= x * x / (4 * k);
|
| 503 |
+
sum += coef * f;
|
| 504 |
+
sum1 += coef * h;
|
| 505 |
+
if (std::abs(coef * f) < std::abs(sum) * tolerance) {
|
| 506 |
+
break;
|
| 507 |
+
}
|
| 508 |
+
}
|
| 509 |
+
if (k == MAXITER) {
|
| 510 |
+
set_error("ikv_temme(temme_ik_series)", SF_ERROR_NO_RESULT, NULL);
|
| 511 |
+
}
|
| 512 |
+
|
| 513 |
+
*K = sum;
|
| 514 |
+
*K1 = 2 * sum1 / x;
|
| 515 |
+
|
| 516 |
+
return 0;
|
| 517 |
+
}
|
| 518 |
+
|
| 519 |
+
/* Evaluate continued fraction fv = I_(v+1) / I_v, derived from
|
| 520 |
+
* Abramowitz and Stegun, Handbook of Mathematical Functions, 1972, 9.1.73 */
|
| 521 |
+
XSF_HOST_DEVICE inline int CF1_ik(double v, double x, double *fv) {
|
| 522 |
+
double C, D, f, a, b, delta, tiny, tolerance;
|
| 523 |
+
std::uint64_t k;
|
| 524 |
+
|
| 525 |
+
/*
|
| 526 |
+
* |x| <= |v|, CF1_ik converges rapidly
|
| 527 |
+
* |x| > |v|, CF1_ik needs O(|x|) iterations to converge
|
| 528 |
+
*/
|
| 529 |
+
|
| 530 |
+
/*
|
| 531 |
+
* modified Lentz's method, see
|
| 532 |
+
* Lentz, Applied Optics, vol 15, 668 (1976)
|
| 533 |
+
*/
|
| 534 |
+
tolerance = 2 * MACHEP;
|
| 535 |
+
tiny = 1 / std::sqrt(std::numeric_limits<double>::max());
|
| 536 |
+
C = f = tiny; /* b0 = 0, replace with tiny */
|
| 537 |
+
D = 0;
|
| 538 |
+
for (k = 1; k < MAXITER; k++) {
|
| 539 |
+
a = 1;
|
| 540 |
+
b = 2 * (v + k) / x;
|
| 541 |
+
C = b + a / C;
|
| 542 |
+
D = b + a * D;
|
| 543 |
+
if (C == 0) {
|
| 544 |
+
C = tiny;
|
| 545 |
+
}
|
| 546 |
+
if (D == 0) {
|
| 547 |
+
D = tiny;
|
| 548 |
+
}
|
| 549 |
+
D = 1 / D;
|
| 550 |
+
delta = C * D;
|
| 551 |
+
f *= delta;
|
| 552 |
+
if (std::abs(delta - 1) <= tolerance) {
|
| 553 |
+
break;
|
| 554 |
+
}
|
| 555 |
+
}
|
| 556 |
+
if (k == MAXITER) {
|
| 557 |
+
set_error("ikv_temme(CF1_ik)", SF_ERROR_NO_RESULT, NULL);
|
| 558 |
+
}
|
| 559 |
+
|
| 560 |
+
*fv = f;
|
| 561 |
+
|
| 562 |
+
return 0;
|
| 563 |
+
}
|
| 564 |
+
|
| 565 |
+
/*
|
| 566 |
+
* Calculate K(v, x) and K(v+1, x) by evaluating continued fraction
|
| 567 |
+
* z1 / z0 = U(v+1.5, 2v+1, 2x) / U(v+0.5, 2v+1, 2x), see
|
| 568 |
+
* Thompson and Barnett, Computer Physics Communications, vol 47, 245 (1987)
|
| 569 |
+
*/
|
| 570 |
+
XSF_HOST_DEVICE inline int CF2_ik(double v, double x, double *Kv, double *Kv1) {
|
| 571 |
+
|
| 572 |
+
double S, C, Q, D, f, a, b, q, delta, tolerance, current, prev;
|
| 573 |
+
std::uint64_t k;
|
| 574 |
+
|
| 575 |
+
/*
|
| 576 |
+
* |x| >= |v|, CF2_ik converges rapidly
|
| 577 |
+
* |x| -> 0, CF2_ik fails to converge
|
| 578 |
+
*/
|
| 579 |
+
|
| 580 |
+
XSF_ASSERT(std::abs(x) > 1);
|
| 581 |
+
|
| 582 |
+
/*
|
| 583 |
+
* Steed's algorithm, see Thompson and Barnett,
|
| 584 |
+
* Journal of Computational Physics, vol 64, 490 (1986)
|
| 585 |
+
*/
|
| 586 |
+
tolerance = MACHEP;
|
| 587 |
+
a = v * v - 0.25;
|
| 588 |
+
b = 2 * (x + 1); /* b1 */
|
| 589 |
+
D = 1 / b; /* D1 = 1 / b1 */
|
| 590 |
+
f = delta = D; /* f1 = delta1 = D1, coincidence */
|
| 591 |
+
prev = 0; /* q0 */
|
| 592 |
+
current = 1; /* q1 */
|
| 593 |
+
Q = C = -a; /* Q1 = C1 because q1 = 1 */
|
| 594 |
+
S = 1 + Q * delta; /* S1 */
|
| 595 |
+
for (k = 2; k < MAXITER; k++) { /* starting from 2 */
|
| 596 |
+
/* continued fraction f = z1 / z0 */
|
| 597 |
+
a -= 2 * (k - 1);
|
| 598 |
+
b += 2;
|
| 599 |
+
D = 1 / (b + a * D);
|
| 600 |
+
delta *= b * D - 1;
|
| 601 |
+
f += delta;
|
| 602 |
+
|
| 603 |
+
/* series summation S = 1 + \sum_{n=1}^{\infty} C_n * z_n / z_0 */
|
| 604 |
+
q = (prev - (b - 2) * current) / a;
|
| 605 |
+
prev = current;
|
| 606 |
+
current = q; /* forward recurrence for q */
|
| 607 |
+
C *= -a / k;
|
| 608 |
+
Q += C * q;
|
| 609 |
+
S += Q * delta;
|
| 610 |
+
|
| 611 |
+
/* S converges slower than f */
|
| 612 |
+
if (std::abs(Q * delta) < std::abs(S) * tolerance) {
|
| 613 |
+
break;
|
| 614 |
+
}
|
| 615 |
+
}
|
| 616 |
+
if (k == MAXITER) {
|
| 617 |
+
set_error("ikv_temme(CF2_ik)", SF_ERROR_NO_RESULT, NULL);
|
| 618 |
+
}
|
| 619 |
+
|
| 620 |
+
*Kv = std::sqrt(M_PI / (2 * x)) * std::exp(-x) / S;
|
| 621 |
+
*Kv1 = *Kv * (0.5 + v + x + (v * v - 0.25) * f) / x;
|
| 622 |
+
|
| 623 |
+
return 0;
|
| 624 |
+
}
|
| 625 |
+
|
| 626 |
+
/* Flags for what to compute */
|
| 627 |
+
enum { ikv_temme_need_i = 0x1, ikv_temme_need_k = 0x2 };
|
| 628 |
+
|
| 629 |
+
/*
|
| 630 |
+
* Compute I(v, x) and K(v, x) simultaneously by Temme's method, see
|
| 631 |
+
* Temme, Journal of Computational Physics, vol 19, 324 (1975)
|
| 632 |
+
*/
|
| 633 |
+
XSF_HOST_DEVICE inline void ikv_temme(double v, double x, double *Iv_p, double *Kv_p) {
|
| 634 |
+
/* Kv1 = K_(v+1), fv = I_(v+1) / I_v */
|
| 635 |
+
/* Ku1 = K_(u+1), fu = I_(u+1) / I_u */
|
| 636 |
+
double u, Iv, Kv, Kv1, Ku, Ku1, fv;
|
| 637 |
+
double W, current, prev, next;
|
| 638 |
+
int reflect = 0;
|
| 639 |
+
unsigned n, k;
|
| 640 |
+
int kind;
|
| 641 |
+
|
| 642 |
+
kind = 0;
|
| 643 |
+
if (Iv_p != NULL) {
|
| 644 |
+
kind |= ikv_temme_need_i;
|
| 645 |
+
}
|
| 646 |
+
if (Kv_p != NULL) {
|
| 647 |
+
kind |= ikv_temme_need_k;
|
| 648 |
+
}
|
| 649 |
+
|
| 650 |
+
if (v < 0) {
|
| 651 |
+
reflect = 1;
|
| 652 |
+
v = -v; /* v is non-negative from here */
|
| 653 |
+
kind |= ikv_temme_need_k;
|
| 654 |
+
}
|
| 655 |
+
n = std::round(v);
|
| 656 |
+
u = v - n; /* -1/2 <= u < 1/2 */
|
| 657 |
+
|
| 658 |
+
if (x < 0) {
|
| 659 |
+
if (Iv_p != NULL)
|
| 660 |
+
*Iv_p = std::numeric_limits<double>::quiet_NaN();
|
| 661 |
+
if (Kv_p != NULL)
|
| 662 |
+
*Kv_p = std::numeric_limits<double>::quiet_NaN();
|
| 663 |
+
set_error("ikv_temme", SF_ERROR_DOMAIN, NULL);
|
| 664 |
+
return;
|
| 665 |
+
}
|
| 666 |
+
if (x == 0) {
|
| 667 |
+
Iv = (v == 0) ? 1 : 0;
|
| 668 |
+
if (kind & ikv_temme_need_k) {
|
| 669 |
+
set_error("ikv_temme", SF_ERROR_OVERFLOW, NULL);
|
| 670 |
+
Kv = std::numeric_limits<double>::infinity();
|
| 671 |
+
} else {
|
| 672 |
+
Kv = std::numeric_limits<double>::quiet_NaN(); /* any value will do */
|
| 673 |
+
}
|
| 674 |
+
|
| 675 |
+
if (reflect && (kind & ikv_temme_need_i)) {
|
| 676 |
+
double z = (u + n % 2);
|
| 677 |
+
|
| 678 |
+
Iv = xsf::cephes::sinpi(z) == 0 ? Iv : std::numeric_limits<double>::infinity();
|
| 679 |
+
if (std::isinf(Iv)) {
|
| 680 |
+
set_error("ikv_temme", SF_ERROR_OVERFLOW, NULL);
|
| 681 |
+
}
|
| 682 |
+
}
|
| 683 |
+
|
| 684 |
+
if (Iv_p != NULL) {
|
| 685 |
+
*Iv_p = Iv;
|
| 686 |
+
}
|
| 687 |
+
if (Kv_p != NULL) {
|
| 688 |
+
*Kv_p = Kv;
|
| 689 |
+
}
|
| 690 |
+
return;
|
| 691 |
+
}
|
| 692 |
+
/* x is positive until reflection */
|
| 693 |
+
W = 1 / x; /* Wronskian */
|
| 694 |
+
if (x <= 2) { /* x in (0, 2] */
|
| 695 |
+
temme_ik_series(u, x, &Ku, &Ku1); /* Temme series */
|
| 696 |
+
} else { /* x in (2, \infty) */
|
| 697 |
+
CF2_ik(u, x, &Ku, &Ku1); /* continued fraction CF2_ik */
|
| 698 |
+
}
|
| 699 |
+
prev = Ku;
|
| 700 |
+
current = Ku1;
|
| 701 |
+
for (k = 1; k <= n; k++) { /* forward recurrence for K */
|
| 702 |
+
next = 2 * (u + k) * current / x + prev;
|
| 703 |
+
prev = current;
|
| 704 |
+
current = next;
|
| 705 |
+
}
|
| 706 |
+
Kv = prev;
|
| 707 |
+
Kv1 = current;
|
| 708 |
+
if (kind & ikv_temme_need_i) {
|
| 709 |
+
double lim = (4 * v * v + 10) / (8 * x);
|
| 710 |
+
|
| 711 |
+
lim *= lim;
|
| 712 |
+
lim *= lim;
|
| 713 |
+
lim /= 24;
|
| 714 |
+
if ((lim < MACHEP * 10) && (x > 100)) {
|
| 715 |
+
/*
|
| 716 |
+
* x is huge compared to v, CF1 may be very slow
|
| 717 |
+
* to converge so use asymptotic expansion for large
|
| 718 |
+
* x case instead. Note that the asymptotic expansion
|
| 719 |
+
* isn't very accurate - so it's deliberately very hard
|
| 720 |
+
* to get here - probably we're going to overflow:
|
| 721 |
+
*/
|
| 722 |
+
Iv = iv_asymptotic(v, x);
|
| 723 |
+
} else {
|
| 724 |
+
CF1_ik(v, x, &fv); /* continued fraction CF1_ik */
|
| 725 |
+
Iv = W / (Kv * fv + Kv1); /* Wronskian relation */
|
| 726 |
+
}
|
| 727 |
+
} else {
|
| 728 |
+
Iv = std::numeric_limits<double>::quiet_NaN(); /* any value will do */
|
| 729 |
+
}
|
| 730 |
+
|
| 731 |
+
if (reflect) {
|
| 732 |
+
double z = (u + n % 2);
|
| 733 |
+
|
| 734 |
+
if (Iv_p != NULL) {
|
| 735 |
+
*Iv_p = Iv + (2 / M_PI) * xsf::cephes::sinpi(z) * Kv; /* reflection formula */
|
| 736 |
+
}
|
| 737 |
+
if (Kv_p != NULL) {
|
| 738 |
+
*Kv_p = Kv;
|
| 739 |
+
}
|
| 740 |
+
} else {
|
| 741 |
+
if (Iv_p != NULL) {
|
| 742 |
+
*Iv_p = Iv;
|
| 743 |
+
}
|
| 744 |
+
if (Kv_p != NULL) {
|
| 745 |
+
*Kv_p = Kv;
|
| 746 |
+
}
|
| 747 |
+
}
|
| 748 |
+
return;
|
| 749 |
+
}
|
| 750 |
+
|
| 751 |
+
} // namespace detail
|
| 752 |
+
|
| 753 |
+
XSF_HOST_DEVICE inline double iv(double v, double x) {
|
| 754 |
+
int sign;
|
| 755 |
+
double t, ax, res;
|
| 756 |
+
|
| 757 |
+
if (std::isnan(v) || std::isnan(x)) {
|
| 758 |
+
return std::numeric_limits<double>::quiet_NaN();
|
| 759 |
+
}
|
| 760 |
+
|
| 761 |
+
/* If v is a negative integer, invoke symmetry */
|
| 762 |
+
t = std::floor(v);
|
| 763 |
+
if (v < 0.0) {
|
| 764 |
+
if (t == v) {
|
| 765 |
+
v = -v; /* symmetry */
|
| 766 |
+
t = -t;
|
| 767 |
+
}
|
| 768 |
+
}
|
| 769 |
+
/* If x is negative, require v to be an integer */
|
| 770 |
+
sign = 1;
|
| 771 |
+
if (x < 0.0) {
|
| 772 |
+
if (t != v) {
|
| 773 |
+
set_error("iv", SF_ERROR_DOMAIN, NULL);
|
| 774 |
+
return (std::numeric_limits<double>::quiet_NaN());
|
| 775 |
+
}
|
| 776 |
+
if (v != 2.0 * std::floor(v / 2.0)) {
|
| 777 |
+
sign = -1;
|
| 778 |
+
}
|
| 779 |
+
}
|
| 780 |
+
|
| 781 |
+
/* Avoid logarithm singularity */
|
| 782 |
+
if (x == 0.0) {
|
| 783 |
+
if (v == 0.0) {
|
| 784 |
+
return 1.0;
|
| 785 |
+
}
|
| 786 |
+
if (v < 0.0) {
|
| 787 |
+
set_error("iv", SF_ERROR_OVERFLOW, NULL);
|
| 788 |
+
return std::numeric_limits<double>::infinity();
|
| 789 |
+
} else
|
| 790 |
+
return 0.0;
|
| 791 |
+
}
|
| 792 |
+
|
| 793 |
+
ax = std::abs(x);
|
| 794 |
+
if (std::abs(v) > 50) {
|
| 795 |
+
/*
|
| 796 |
+
* Uniform asymptotic expansion for large orders.
|
| 797 |
+
*
|
| 798 |
+
* This appears to overflow slightly later than the Boost
|
| 799 |
+
* implementation of Temme's method.
|
| 800 |
+
*/
|
| 801 |
+
detail::ikv_asymptotic_uniform(v, ax, &res, NULL);
|
| 802 |
+
} else {
|
| 803 |
+
/* Otherwise: Temme's method */
|
| 804 |
+
detail::ikv_temme(v, ax, &res, NULL);
|
| 805 |
+
}
|
| 806 |
+
res *= sign;
|
| 807 |
+
return res;
|
| 808 |
+
}
|
| 809 |
+
|
| 810 |
+
} // namespace cephes
|
| 811 |
+
} // namespace xsf
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/shichi.h
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Translated into C++ by SciPy developers in 2024.
|
| 2 |
+
* Original header with Copyright information appears below.
|
| 3 |
+
*/
|
| 4 |
+
|
| 5 |
+
/* shichi.c
|
| 6 |
+
*
|
| 7 |
+
* Hyperbolic sine and cosine integrals
|
| 8 |
+
*
|
| 9 |
+
*
|
| 10 |
+
*
|
| 11 |
+
* SYNOPSIS:
|
| 12 |
+
*
|
| 13 |
+
* double x, Chi, Shi, shichi();
|
| 14 |
+
*
|
| 15 |
+
* shichi( x, &Chi, &Shi );
|
| 16 |
+
*
|
| 17 |
+
*
|
| 18 |
+
* DESCRIPTION:
|
| 19 |
+
*
|
| 20 |
+
* Approximates the integrals
|
| 21 |
+
*
|
| 22 |
+
* x
|
| 23 |
+
* -
|
| 24 |
+
* | | cosh t - 1
|
| 25 |
+
* Chi(x) = eul + ln x + | ----------- dt,
|
| 26 |
+
* | | t
|
| 27 |
+
* -
|
| 28 |
+
* 0
|
| 29 |
+
*
|
| 30 |
+
* x
|
| 31 |
+
* -
|
| 32 |
+
* | | sinh t
|
| 33 |
+
* Shi(x) = | ------ dt
|
| 34 |
+
* | | t
|
| 35 |
+
* -
|
| 36 |
+
* 0
|
| 37 |
+
*
|
| 38 |
+
* where eul = 0.57721566490153286061 is Euler's constant.
|
| 39 |
+
* The integrals are evaluated by power series for x < 8
|
| 40 |
+
* and by Chebyshev expansions for x between 8 and 88.
|
| 41 |
+
* For large x, both functions approach exp(x)/2x.
|
| 42 |
+
* Arguments greater than 88 in magnitude return INFINITY.
|
| 43 |
+
*
|
| 44 |
+
*
|
| 45 |
+
* ACCURACY:
|
| 46 |
+
*
|
| 47 |
+
* Test interval 0 to 88.
|
| 48 |
+
* Relative error:
|
| 49 |
+
* arithmetic function # trials peak rms
|
| 50 |
+
* IEEE Shi 30000 6.9e-16 1.6e-16
|
| 51 |
+
* Absolute error, except relative when |Chi| > 1:
|
| 52 |
+
* IEEE Chi 30000 8.4e-16 1.4e-16
|
| 53 |
+
*/
|
| 54 |
+
|
| 55 |
+
/*
|
| 56 |
+
* Cephes Math Library Release 2.0: April, 1987
|
| 57 |
+
* Copyright 1984, 1987 by Stephen L. Moshier
|
| 58 |
+
* Direct inquiries to 30 Frost Street, Cambridge, MA 02140
|
| 59 |
+
*/
|
| 60 |
+
#pragma once
|
| 61 |
+
|
| 62 |
+
#include "../config.h"
|
| 63 |
+
|
| 64 |
+
#include "chbevl.h"
|
| 65 |
+
#include "const.h"
|
| 66 |
+
|
| 67 |
+
namespace xsf {
|
| 68 |
+
namespace cephes {
|
| 69 |
+
|
| 70 |
+
namespace detail {
|
| 71 |
+
|
| 72 |
+
/* x exp(-x) shi(x), inverted interval 8 to 18 */
|
| 73 |
+
constexpr double shichi_S1[] = {
|
| 74 |
+
1.83889230173399459482E-17, -9.55485532279655569575E-17, 2.04326105980879882648E-16,
|
| 75 |
+
1.09896949074905343022E-15, -1.31313534344092599234E-14, 5.93976226264314278932E-14,
|
| 76 |
+
-3.47197010497749154755E-14, -1.40059764613117131000E-12, 9.49044626224223543299E-12,
|
| 77 |
+
-1.61596181145435454033E-11, -1.77899784436430310321E-10, 1.35455469767246947469E-9,
|
| 78 |
+
-1.03257121792819495123E-9, -3.56699611114982536845E-8, 1.44818877384267342057E-7,
|
| 79 |
+
7.82018215184051295296E-7, -5.39919118403805073710E-6, -3.12458202168959833422E-5,
|
| 80 |
+
8.90136741950727517826E-5, 2.02558474743846862168E-3, 2.96064440855633256972E-2,
|
| 81 |
+
1.11847751047257036625E0};
|
| 82 |
+
|
| 83 |
+
/* x exp(-x) shi(x), inverted interval 18 to 88 */
|
| 84 |
+
constexpr double shichi_S2[] = {
|
| 85 |
+
-1.05311574154850938805E-17, 2.62446095596355225821E-17, 8.82090135625368160657E-17,
|
| 86 |
+
-3.38459811878103047136E-16, -8.30608026366935789136E-16, 3.93397875437050071776E-15,
|
| 87 |
+
1.01765565969729044505E-14, -4.21128170307640802703E-14, -1.60818204519802480035E-13,
|
| 88 |
+
3.34714954175994481761E-13, 2.72600352129153073807E-12, 1.66894954752839083608E-12,
|
| 89 |
+
-3.49278141024730899554E-11, -1.58580661666482709598E-10, -1.79289437183355633342E-10,
|
| 90 |
+
1.76281629144264523277E-9, 1.69050228879421288846E-8, 1.25391771228487041649E-7,
|
| 91 |
+
1.16229947068677338732E-6, 1.61038260117376323993E-5, 3.49810375601053973070E-4,
|
| 92 |
+
1.28478065259647610779E-2, 1.03665722588798326712E0};
|
| 93 |
+
|
| 94 |
+
/* x exp(-x) chin(x), inverted interval 8 to 18 */
|
| 95 |
+
constexpr double shichi_C1[] = {
|
| 96 |
+
-8.12435385225864036372E-18, 2.17586413290339214377E-17, 5.22624394924072204667E-17,
|
| 97 |
+
-9.48812110591690559363E-16, 5.35546311647465209166E-15, -1.21009970113732918701E-14,
|
| 98 |
+
-6.00865178553447437951E-14, 7.16339649156028587775E-13, -2.93496072607599856104E-12,
|
| 99 |
+
-1.40359438136491256904E-12, 8.76302288609054966081E-11, -4.40092476213282340617E-10,
|
| 100 |
+
-1.87992075640569295479E-10, 1.31458150989474594064E-8, -4.75513930924765465590E-8,
|
| 101 |
+
-2.21775018801848880741E-7, 1.94635531373272490962E-6, 4.33505889257316408893E-6,
|
| 102 |
+
-6.13387001076494349496E-5, -3.13085477492997465138E-4, 4.97164789823116062801E-4,
|
| 103 |
+
2.64347496031374526641E-2, 1.11446150876699213025E0};
|
| 104 |
+
|
| 105 |
+
/* x exp(-x) chin(x), inverted interval 18 to 88 */
|
| 106 |
+
constexpr double shichi_C2[] = {
|
| 107 |
+
8.06913408255155572081E-18, -2.08074168180148170312E-17, -5.98111329658272336816E-17,
|
| 108 |
+
2.68533951085945765591E-16, 4.52313941698904694774E-16, -3.10734917335299464535E-15,
|
| 109 |
+
-4.42823207332531972288E-15, 3.49639695410806959872E-14, 6.63406731718911586609E-14,
|
| 110 |
+
-3.71902448093119218395E-13, -1.27135418132338309016E-12, 2.74851141935315395333E-12,
|
| 111 |
+
2.33781843985453438400E-11, 2.71436006377612442764E-11, -2.56600180000355990529E-10,
|
| 112 |
+
-1.61021375163803438552E-9, -4.72543064876271773512E-9, -3.00095178028681682282E-9,
|
| 113 |
+
7.79387474390914922337E-8, 1.06942765566401507066E-6, 1.59503164802313196374E-5,
|
| 114 |
+
3.49592575153777996871E-4, 1.28475387530065247392E-2, 1.03665693917934275131E0};
|
| 115 |
+
|
| 116 |
+
/*
|
| 117 |
+
* Evaluate 3F0(a1, a2, a3; z)
|
| 118 |
+
*
|
| 119 |
+
* The series is only asymptotic, so this requires z large enough.
|
| 120 |
+
*/
|
| 121 |
+
XSF_HOST_DEVICE inline double hyp3f0(double a1, double a2, double a3, double z) {
|
| 122 |
+
int n, maxiter;
|
| 123 |
+
double err, sum, term, m;
|
| 124 |
+
|
| 125 |
+
m = std::pow(z, -1.0 / 3);
|
| 126 |
+
if (m < 50) {
|
| 127 |
+
maxiter = m;
|
| 128 |
+
} else {
|
| 129 |
+
maxiter = 50;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
term = 1.0;
|
| 133 |
+
sum = term;
|
| 134 |
+
for (n = 0; n < maxiter; ++n) {
|
| 135 |
+
term *= (a1 + n) * (a2 + n) * (a3 + n) * z / (n + 1);
|
| 136 |
+
sum += term;
|
| 137 |
+
if (std::abs(term) < 1e-13 * std::abs(sum) || term == 0) {
|
| 138 |
+
break;
|
| 139 |
+
}
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
err = std::abs(term);
|
| 143 |
+
|
| 144 |
+
if (err > 1e-13 * std::abs(sum)) {
|
| 145 |
+
return std::numeric_limits<double>::quiet_NaN();
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
return sum;
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
} // namespace detail
|
| 152 |
+
|
| 153 |
+
/* Sine and cosine integrals */
|
| 154 |
+
XSF_HOST_DEVICE inline int shichi(double x, double *si, double *ci) {
|
| 155 |
+
double k, z, c, s, a, b;
|
| 156 |
+
short sign;
|
| 157 |
+
|
| 158 |
+
if (x < 0.0) {
|
| 159 |
+
sign = -1;
|
| 160 |
+
x = -x;
|
| 161 |
+
} else {
|
| 162 |
+
sign = 0;
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
if (x == 0.0) {
|
| 166 |
+
*si = 0.0;
|
| 167 |
+
*ci = -std::numeric_limits<double>::infinity();
|
| 168 |
+
return (0);
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
if (x >= 8.0) {
|
| 172 |
+
goto chb;
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
if (x >= 88.0) {
|
| 176 |
+
goto asymp;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
z = x * x;
|
| 180 |
+
|
| 181 |
+
/* Direct power series expansion */
|
| 182 |
+
a = 1.0;
|
| 183 |
+
s = 1.0;
|
| 184 |
+
c = 0.0;
|
| 185 |
+
k = 2.0;
|
| 186 |
+
|
| 187 |
+
do {
|
| 188 |
+
a *= z / k;
|
| 189 |
+
c += a / k;
|
| 190 |
+
k += 1.0;
|
| 191 |
+
a /= k;
|
| 192 |
+
s += a / k;
|
| 193 |
+
k += 1.0;
|
| 194 |
+
} while (std::abs(a / s) > detail::MACHEP);
|
| 195 |
+
|
| 196 |
+
s *= x;
|
| 197 |
+
goto done;
|
| 198 |
+
|
| 199 |
+
chb:
|
| 200 |
+
/* Chebyshev series expansions */
|
| 201 |
+
if (x < 18.0) {
|
| 202 |
+
a = (576.0 / x - 52.0) / 10.0;
|
| 203 |
+
k = std::exp(x) / x;
|
| 204 |
+
s = k * chbevl(a, detail::shichi_S1, 22);
|
| 205 |
+
c = k * chbevl(a, detail::shichi_C1, 23);
|
| 206 |
+
goto done;
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
if (x <= 88.0) {
|
| 210 |
+
a = (6336.0 / x - 212.0) / 70.0;
|
| 211 |
+
k = std::exp(x) / x;
|
| 212 |
+
s = k * chbevl(a, detail::shichi_S2, 23);
|
| 213 |
+
c = k * chbevl(a, detail::shichi_C2, 24);
|
| 214 |
+
goto done;
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
asymp:
|
| 218 |
+
if (x > 1000) {
|
| 219 |
+
*si = std::numeric_limits<double>::infinity();
|
| 220 |
+
*ci = std::numeric_limits<double>::infinity();
|
| 221 |
+
} else {
|
| 222 |
+
/* Asymptotic expansions
|
| 223 |
+
* http://functions.wolfram.com/GammaBetaErf/CoshIntegral/06/02/
|
| 224 |
+
* http://functions.wolfram.com/GammaBetaErf/SinhIntegral/06/02/0001/
|
| 225 |
+
*/
|
| 226 |
+
a = detail::hyp3f0(0.5, 1, 1, 4.0 / (x * x));
|
| 227 |
+
b = detail::hyp3f0(1, 1, 1.5, 4.0 / (x * x));
|
| 228 |
+
*si = std::cosh(x) / x * a + std::sinh(x) / (x * x) * b;
|
| 229 |
+
*ci = std::sinh(x) / x * a + std::cosh(x) / (x * x) * b;
|
| 230 |
+
}
|
| 231 |
+
if (sign) {
|
| 232 |
+
*si = -*si;
|
| 233 |
+
}
|
| 234 |
+
return 0;
|
| 235 |
+
|
| 236 |
+
done:
|
| 237 |
+
if (sign) {
|
| 238 |
+
s = -s;
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
*si = s;
|
| 242 |
+
|
| 243 |
+
*ci = detail::SCIPY_EULER + std::log(x) + c;
|
| 244 |
+
return (0);
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
} // namespace cephes
|
| 248 |
+
} // namespace xsf
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/sici.h
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Translated into C++ by SciPy developers in 2024.
|
| 2 |
+
* Original header with Copyright information appears below.
|
| 3 |
+
*/
|
| 4 |
+
|
| 5 |
+
/* sici.c
|
| 6 |
+
*
|
| 7 |
+
* Sine and cosine integrals
|
| 8 |
+
*
|
| 9 |
+
*
|
| 10 |
+
*
|
| 11 |
+
* SYNOPSIS:
|
| 12 |
+
*
|
| 13 |
+
* double x, Ci, Si, sici();
|
| 14 |
+
*
|
| 15 |
+
* sici( x, &Si, &Ci );
|
| 16 |
+
*
|
| 17 |
+
*
|
| 18 |
+
* DESCRIPTION:
|
| 19 |
+
*
|
| 20 |
+
* Evaluates the integrals
|
| 21 |
+
*
|
| 22 |
+
* x
|
| 23 |
+
* -
|
| 24 |
+
* | cos t - 1
|
| 25 |
+
* Ci(x) = eul + ln x + | --------- dt,
|
| 26 |
+
* | t
|
| 27 |
+
* -
|
| 28 |
+
* 0
|
| 29 |
+
* x
|
| 30 |
+
* -
|
| 31 |
+
* | sin t
|
| 32 |
+
* Si(x) = | ----- dt
|
| 33 |
+
* | t
|
| 34 |
+
* -
|
| 35 |
+
* 0
|
| 36 |
+
*
|
| 37 |
+
* where eul = 0.57721566490153286061 is Euler's constant.
|
| 38 |
+
* The integrals are approximated by rational functions.
|
| 39 |
+
* For x > 8 auxiliary functions f(x) and g(x) are employed
|
| 40 |
+
* such that
|
| 41 |
+
*
|
| 42 |
+
* Ci(x) = f(x) sin(x) - g(x) cos(x)
|
| 43 |
+
* Si(x) = pi/2 - f(x) cos(x) - g(x) sin(x)
|
| 44 |
+
*
|
| 45 |
+
*
|
| 46 |
+
* ACCURACY:
|
| 47 |
+
* Test interval = [0,50].
|
| 48 |
+
* Absolute error, except relative when > 1:
|
| 49 |
+
* arithmetic function # trials peak rms
|
| 50 |
+
* IEEE Si 30000 4.4e-16 7.3e-17
|
| 51 |
+
* IEEE Ci 30000 6.9e-16 5.1e-17
|
| 52 |
+
*/
|
| 53 |
+
|
| 54 |
+
/*
|
| 55 |
+
* Cephes Math Library Release 2.1: January, 1989
|
| 56 |
+
* Copyright 1984, 1987, 1989 by Stephen L. Moshier
|
| 57 |
+
* Direct inquiries to 30 Frost Street, Cambridge, MA 02140
|
| 58 |
+
*/
|
| 59 |
+
#pragma once
|
| 60 |
+
|
| 61 |
+
#include "../config.h"
|
| 62 |
+
|
| 63 |
+
#include "const.h"
|
| 64 |
+
#include "polevl.h"
|
| 65 |
+
|
| 66 |
+
namespace xsf {
|
| 67 |
+
namespace cephes {
|
| 68 |
+
|
| 69 |
+
namespace detail {
|
| 70 |
+
|
| 71 |
+
constexpr double sici_SN[] = {
|
| 72 |
+
-8.39167827910303881427E-11, 4.62591714427012837309E-8, -9.75759303843632795789E-6,
|
| 73 |
+
9.76945438170435310816E-4, -4.13470316229406538752E-2, 1.00000000000000000302E0,
|
| 74 |
+
};
|
| 75 |
+
|
| 76 |
+
constexpr double sici_SD[] = {
|
| 77 |
+
2.03269266195951942049E-12, 1.27997891179943299903E-9, 4.41827842801218905784E-7,
|
| 78 |
+
9.96412122043875552487E-5, 1.42085239326149893930E-2, 9.99999999999999996984E-1,
|
| 79 |
+
};
|
| 80 |
+
|
| 81 |
+
constexpr double sici_CN[] = {
|
| 82 |
+
2.02524002389102268789E-11, -1.35249504915790756375E-8, 3.59325051419993077021E-6,
|
| 83 |
+
-4.74007206873407909465E-4, 2.89159652607555242092E-2, -1.00000000000000000080E0,
|
| 84 |
+
};
|
| 85 |
+
|
| 86 |
+
constexpr double sici_CD[] = {
|
| 87 |
+
4.07746040061880559506E-12, 3.06780997581887812692E-9, 1.23210355685883423679E-6,
|
| 88 |
+
3.17442024775032769882E-4, 5.10028056236446052392E-2, 4.00000000000000000080E0,
|
| 89 |
+
};
|
| 90 |
+
|
| 91 |
+
constexpr double sici_FN4[] = {
|
| 92 |
+
4.23612862892216586994E0, 5.45937717161812843388E0, 1.62083287701538329132E0, 1.67006611831323023771E-1,
|
| 93 |
+
6.81020132472518137426E-3, 1.08936580650328664411E-4, 5.48900223421373614008E-7,
|
| 94 |
+
};
|
| 95 |
+
|
| 96 |
+
constexpr double sici_FD4[] = {
|
| 97 |
+
/* 1.00000000000000000000E0, */
|
| 98 |
+
8.16496634205391016773E0, 7.30828822505564552187E0, 1.86792257950184183883E0, 1.78792052963149907262E-1,
|
| 99 |
+
7.01710668322789753610E-3, 1.10034357153915731354E-4, 5.48900252756255700982E-7,
|
| 100 |
+
};
|
| 101 |
+
|
| 102 |
+
constexpr double sici_FN8[] = {
|
| 103 |
+
4.55880873470465315206E-1, 7.13715274100146711374E-1, 1.60300158222319456320E-1,
|
| 104 |
+
1.16064229408124407915E-2, 3.49556442447859055605E-4, 4.86215430826454749482E-6,
|
| 105 |
+
3.20092790091004902806E-8, 9.41779576128512936592E-11, 9.70507110881952024631E-14,
|
| 106 |
+
};
|
| 107 |
+
|
| 108 |
+
constexpr double sici_FD8[] = {
|
| 109 |
+
/* 1.00000000000000000000E0, */
|
| 110 |
+
9.17463611873684053703E-1, 1.78685545332074536321E-1, 1.22253594771971293032E-2,
|
| 111 |
+
3.58696481881851580297E-4, 4.92435064317881464393E-6, 3.21956939101046018377E-8,
|
| 112 |
+
9.43720590350276732376E-11, 9.70507110881952025725E-14,
|
| 113 |
+
};
|
| 114 |
+
|
| 115 |
+
constexpr double sici_GN4[] = {
|
| 116 |
+
8.71001698973114191777E-2, 6.11379109952219284151E-1, 3.97180296392337498885E-1, 7.48527737628469092119E-2,
|
| 117 |
+
5.38868681462177273157E-3, 1.61999794598934024525E-4, 1.97963874140963632189E-6, 7.82579040744090311069E-9,
|
| 118 |
+
};
|
| 119 |
+
|
| 120 |
+
constexpr double sici_GD4[] = {
|
| 121 |
+
/* 1.00000000000000000000E0, */
|
| 122 |
+
1.64402202413355338886E0, 6.66296701268987968381E-1, 9.88771761277688796203E-2, 6.22396345441768420760E-3,
|
| 123 |
+
1.73221081474177119497E-4, 2.02659182086343991969E-6, 7.82579218933534490868E-9,
|
| 124 |
+
};
|
| 125 |
+
|
| 126 |
+
constexpr double sici_GN8[] = {
|
| 127 |
+
6.97359953443276214934E-1, 3.30410979305632063225E-1, 3.84878767649974295920E-2,
|
| 128 |
+
1.71718239052347903558E-3, 3.48941165502279436777E-5, 3.47131167084116673800E-7,
|
| 129 |
+
1.70404452782044526189E-9, 3.85945925430276600453E-12, 3.14040098946363334640E-15,
|
| 130 |
+
};
|
| 131 |
+
|
| 132 |
+
constexpr double sici_GD8[] = {
|
| 133 |
+
/* 1.00000000000000000000E0, */
|
| 134 |
+
1.68548898811011640017E0, 4.87852258695304967486E-1, 4.67913194259625806320E-2,
|
| 135 |
+
1.90284426674399523638E-3, 3.68475504442561108162E-5, 3.57043223443740838771E-7,
|
| 136 |
+
1.72693748966316146736E-9, 3.87830166023954706752E-12, 3.14040098946363335242E-15,
|
| 137 |
+
};
|
| 138 |
+
|
| 139 |
+
} // namespace detail
|
| 140 |
+
|
| 141 |
+
XSF_HOST_DEVICE inline int sici(double x, double *si, double *ci) {
|
| 142 |
+
double z, c, s, f, g;
|
| 143 |
+
short sign;
|
| 144 |
+
|
| 145 |
+
if (x < 0.0) {
|
| 146 |
+
sign = -1;
|
| 147 |
+
x = -x;
|
| 148 |
+
} else {
|
| 149 |
+
sign = 0;
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
if (x == 0.0) {
|
| 153 |
+
*si = 0.0;
|
| 154 |
+
*ci = -std::numeric_limits<double>::infinity();
|
| 155 |
+
return (0);
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
if (x > 1.0e9) {
|
| 159 |
+
if (std::isinf(x)) {
|
| 160 |
+
if (sign == -1) {
|
| 161 |
+
*si = -M_PI_2;
|
| 162 |
+
*ci = std::numeric_limits<double>::quiet_NaN();
|
| 163 |
+
} else {
|
| 164 |
+
*si = M_PI_2;
|
| 165 |
+
*ci = 0;
|
| 166 |
+
}
|
| 167 |
+
return 0;
|
| 168 |
+
}
|
| 169 |
+
*si = M_PI_2 - std::cos(x) / x;
|
| 170 |
+
*ci = std::sin(x) / x;
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
if (x > 4.0) {
|
| 174 |
+
goto asympt;
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
z = x * x;
|
| 178 |
+
s = x * polevl(z, detail::sici_SN, 5) / polevl(z, detail::sici_SD, 5);
|
| 179 |
+
c = z * polevl(z, detail::sici_CN, 5) / polevl(z, detail::sici_CD, 5);
|
| 180 |
+
|
| 181 |
+
if (sign) {
|
| 182 |
+
s = -s;
|
| 183 |
+
}
|
| 184 |
+
*si = s;
|
| 185 |
+
*ci = detail::SCIPY_EULER + std::log(x) + c; /* real part if x < 0 */
|
| 186 |
+
return (0);
|
| 187 |
+
|
| 188 |
+
/* The auxiliary functions are:
|
| 189 |
+
*
|
| 190 |
+
*
|
| 191 |
+
* *si = *si - M_PI_2;
|
| 192 |
+
* c = cos(x);
|
| 193 |
+
* s = sin(x);
|
| 194 |
+
*
|
| 195 |
+
* t = *ci * s - *si * c;
|
| 196 |
+
* a = *ci * c + *si * s;
|
| 197 |
+
*
|
| 198 |
+
* *si = t;
|
| 199 |
+
* *ci = -a;
|
| 200 |
+
*/
|
| 201 |
+
|
| 202 |
+
asympt:
|
| 203 |
+
|
| 204 |
+
s = std::sin(x);
|
| 205 |
+
c = std::cos(x);
|
| 206 |
+
z = 1.0 / (x * x);
|
| 207 |
+
if (x < 8.0) {
|
| 208 |
+
f = polevl(z, detail::sici_FN4, 6) / (x * p1evl(z, detail::sici_FD4, 7));
|
| 209 |
+
g = z * polevl(z, detail::sici_GN4, 7) / p1evl(z, detail::sici_GD4, 7);
|
| 210 |
+
} else {
|
| 211 |
+
f = polevl(z, detail::sici_FN8, 8) / (x * p1evl(z, detail::sici_FD8, 8));
|
| 212 |
+
g = z * polevl(z, detail::sici_GN8, 8) / p1evl(z, detail::sici_GD8, 9);
|
| 213 |
+
}
|
| 214 |
+
*si = M_PI_2 - f * c - g * s;
|
| 215 |
+
if (sign) {
|
| 216 |
+
*si = -(*si);
|
| 217 |
+
}
|
| 218 |
+
*ci = f * s - g * c;
|
| 219 |
+
|
| 220 |
+
return (0);
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
} // namespace cephes
|
| 224 |
+
} // namespace xsf
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/sindg.h
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Translated into C++ by SciPy developers in 2024.
|
| 2 |
+
* Original header with Copyright information appears below.
|
| 3 |
+
*/
|
| 4 |
+
|
| 5 |
+
/* sindg.c
|
| 6 |
+
*
|
| 7 |
+
* Circular sine of angle in degrees
|
| 8 |
+
*
|
| 9 |
+
*
|
| 10 |
+
*
|
| 11 |
+
* SYNOPSIS:
|
| 12 |
+
*
|
| 13 |
+
* double x, y, sindg();
|
| 14 |
+
*
|
| 15 |
+
* y = sindg( x );
|
| 16 |
+
*
|
| 17 |
+
*
|
| 18 |
+
*
|
| 19 |
+
* DESCRIPTION:
|
| 20 |
+
*
|
| 21 |
+
* Range reduction is into intervals of 45 degrees.
|
| 22 |
+
*
|
| 23 |
+
* Two polynomial approximating functions are employed.
|
| 24 |
+
* Between 0 and pi/4 the sine is approximated by
|
| 25 |
+
* x + x**3 P(x**2).
|
| 26 |
+
* Between pi/4 and pi/2 the cosine is represented as
|
| 27 |
+
* 1 - x**2 P(x**2).
|
| 28 |
+
*
|
| 29 |
+
*
|
| 30 |
+
*
|
| 31 |
+
* ACCURACY:
|
| 32 |
+
*
|
| 33 |
+
* Relative error:
|
| 34 |
+
* arithmetic domain # trials peak rms
|
| 35 |
+
* IEEE +-1000 30000 2.3e-16 5.6e-17
|
| 36 |
+
*
|
| 37 |
+
* ERROR MESSAGES:
|
| 38 |
+
*
|
| 39 |
+
* message condition value returned
|
| 40 |
+
* sindg total loss x > 1.0e14 (IEEE) 0.0
|
| 41 |
+
*
|
| 42 |
+
*/
|
| 43 |
+
/* cosdg.c
|
| 44 |
+
*
|
| 45 |
+
* Circular cosine of angle in degrees
|
| 46 |
+
*
|
| 47 |
+
*
|
| 48 |
+
*
|
| 49 |
+
* SYNOPSIS:
|
| 50 |
+
*
|
| 51 |
+
* double x, y, cosdg();
|
| 52 |
+
*
|
| 53 |
+
* y = cosdg( x );
|
| 54 |
+
*
|
| 55 |
+
*
|
| 56 |
+
*
|
| 57 |
+
* DESCRIPTION:
|
| 58 |
+
*
|
| 59 |
+
* Range reduction is into intervals of 45 degrees.
|
| 60 |
+
*
|
| 61 |
+
* Two polynomial approximating functions are employed.
|
| 62 |
+
* Between 0 and pi/4 the cosine is approximated by
|
| 63 |
+
* 1 - x**2 P(x**2).
|
| 64 |
+
* Between pi/4 and pi/2 the sine is represented as
|
| 65 |
+
* x + x**3 P(x**2).
|
| 66 |
+
*
|
| 67 |
+
*
|
| 68 |
+
* ACCURACY:
|
| 69 |
+
*
|
| 70 |
+
* Relative error:
|
| 71 |
+
* arithmetic domain # trials peak rms
|
| 72 |
+
* IEEE +-1000 30000 2.1e-16 5.7e-17
|
| 73 |
+
* See also sin().
|
| 74 |
+
*
|
| 75 |
+
*/
|
| 76 |
+
|
| 77 |
+
/* Cephes Math Library Release 2.0: April, 1987
|
| 78 |
+
* Copyright 1985, 1987 by Stephen L. Moshier
|
| 79 |
+
* Direct inquiries to 30 Frost Street, Cambridge, MA 02140 */
|
| 80 |
+
#pragma once
|
| 81 |
+
|
| 82 |
+
#include "../config.h"
|
| 83 |
+
#include "../error.h"
|
| 84 |
+
|
| 85 |
+
#include "const.h"
|
| 86 |
+
#include "polevl.h"
|
| 87 |
+
|
| 88 |
+
namespace xsf {
|
| 89 |
+
namespace cephes {
|
| 90 |
+
|
| 91 |
+
namespace detail {
|
| 92 |
+
|
| 93 |
+
constexpr double sincof[] = {1.58962301572218447952E-10, -2.50507477628503540135E-8,
|
| 94 |
+
2.75573136213856773549E-6, -1.98412698295895384658E-4,
|
| 95 |
+
8.33333333332211858862E-3, -1.66666666666666307295E-1};
|
| 96 |
+
|
| 97 |
+
constexpr double coscof[] = {1.13678171382044553091E-11, -2.08758833757683644217E-9, 2.75573155429816611547E-7,
|
| 98 |
+
-2.48015872936186303776E-5, 1.38888888888806666760E-3, -4.16666666666666348141E-2,
|
| 99 |
+
4.99999999999999999798E-1};
|
| 100 |
+
|
| 101 |
+
constexpr double sindg_lossth = 1.0e14;
|
| 102 |
+
|
| 103 |
+
} // namespace detail
|
| 104 |
+
|
| 105 |
+
XSF_HOST_DEVICE inline double sindg(double x) {
|
| 106 |
+
double y, z, zz;
|
| 107 |
+
int j, sign;
|
| 108 |
+
|
| 109 |
+
/* make argument positive but save the sign */
|
| 110 |
+
sign = 1;
|
| 111 |
+
if (x < 0) {
|
| 112 |
+
x = -x;
|
| 113 |
+
sign = -1;
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
if (x > detail::sindg_lossth) {
|
| 117 |
+
set_error("sindg", SF_ERROR_NO_RESULT, NULL);
|
| 118 |
+
return (0.0);
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
y = std::floor(x / 45.0); /* integer part of x/M_PI_4 */
|
| 122 |
+
|
| 123 |
+
/* strip high bits of integer part to prevent integer overflow */
|
| 124 |
+
z = std::ldexp(y, -4);
|
| 125 |
+
z = std::floor(z); /* integer part of y/8 */
|
| 126 |
+
z = y - std::ldexp(z, 4); /* y - 16 * (y/16) */
|
| 127 |
+
|
| 128 |
+
j = z; /* convert to integer for tests on the phase angle */
|
| 129 |
+
/* map zeros to origin */
|
| 130 |
+
if (j & 1) {
|
| 131 |
+
j += 1;
|
| 132 |
+
y += 1.0;
|
| 133 |
+
}
|
| 134 |
+
j = j & 07; /* octant modulo 360 degrees */
|
| 135 |
+
/* reflect in x axis */
|
| 136 |
+
if (j > 3) {
|
| 137 |
+
sign = -sign;
|
| 138 |
+
j -= 4;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
z = x - y * 45.0; /* x mod 45 degrees */
|
| 142 |
+
z *= detail::PI180; /* multiply by pi/180 to convert to radians */
|
| 143 |
+
zz = z * z;
|
| 144 |
+
|
| 145 |
+
if ((j == 1) || (j == 2)) {
|
| 146 |
+
y = 1.0 - zz * polevl(zz, detail::coscof, 6);
|
| 147 |
+
} else {
|
| 148 |
+
y = z + z * (zz * polevl(zz, detail::sincof, 5));
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
if (sign < 0)
|
| 152 |
+
y = -y;
|
| 153 |
+
|
| 154 |
+
return (y);
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
XSF_HOST_DEVICE inline double cosdg(double x) {
|
| 158 |
+
double y, z, zz;
|
| 159 |
+
int j, sign;
|
| 160 |
+
|
| 161 |
+
/* make argument positive */
|
| 162 |
+
sign = 1;
|
| 163 |
+
if (x < 0)
|
| 164 |
+
x = -x;
|
| 165 |
+
|
| 166 |
+
if (x > detail::sindg_lossth) {
|
| 167 |
+
set_error("cosdg", SF_ERROR_NO_RESULT, NULL);
|
| 168 |
+
return (0.0);
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
y = std::floor(x / 45.0);
|
| 172 |
+
z = std::ldexp(y, -4);
|
| 173 |
+
z = std::floor(z); /* integer part of y/8 */
|
| 174 |
+
z = y - std::ldexp(z, 4); /* y - 16 * (y/16) */
|
| 175 |
+
|
| 176 |
+
/* integer and fractional part modulo one octant */
|
| 177 |
+
j = z;
|
| 178 |
+
if (j & 1) { /* map zeros to origin */
|
| 179 |
+
j += 1;
|
| 180 |
+
y += 1.0;
|
| 181 |
+
}
|
| 182 |
+
j = j & 07;
|
| 183 |
+
if (j > 3) {
|
| 184 |
+
j -= 4;
|
| 185 |
+
sign = -sign;
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
if (j > 1)
|
| 189 |
+
sign = -sign;
|
| 190 |
+
|
| 191 |
+
z = x - y * 45.0; /* x mod 45 degrees */
|
| 192 |
+
z *= detail::PI180; /* multiply by pi/180 to convert to radians */
|
| 193 |
+
|
| 194 |
+
zz = z * z;
|
| 195 |
+
|
| 196 |
+
if ((j == 1) || (j == 2)) {
|
| 197 |
+
y = z + z * (zz * polevl(zz, detail::sincof, 5));
|
| 198 |
+
} else {
|
| 199 |
+
y = 1.0 - zz * polevl(zz, detail::coscof, 6);
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
if (sign < 0)
|
| 203 |
+
y = -y;
|
| 204 |
+
|
| 205 |
+
return (y);
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
/* Degrees, minutes, seconds to radians: */
|
| 209 |
+
|
| 210 |
+
/* 1 arc second, in radians = 4.848136811095359935899141023579479759563533023727e-6 */
|
| 211 |
+
|
| 212 |
+
namespace detail {
|
| 213 |
+
constexpr double sindg_P64800 = 4.848136811095359935899141023579479759563533023727e-6;
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
XSF_HOST_DEVICE inline double radian(double d, double m, double s) {
|
| 217 |
+
return (((d * 60.0 + m) * 60.0 + s) * detail::sindg_P64800);
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
} // namespace cephes
|
| 221 |
+
} // namespace xsf
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/tandg.h
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Translated into C++ by SciPy developers in 2024.
|
| 2 |
+
* Original header with Copyright information appears below.
|
| 3 |
+
*/
|
| 4 |
+
|
| 5 |
+
/* tandg.c
|
| 6 |
+
*
|
| 7 |
+
* Circular tangent of argument in degrees
|
| 8 |
+
*
|
| 9 |
+
*
|
| 10 |
+
*
|
| 11 |
+
* SYNOPSIS:
|
| 12 |
+
*
|
| 13 |
+
* double x, y, tandg();
|
| 14 |
+
*
|
| 15 |
+
* y = tandg( x );
|
| 16 |
+
*
|
| 17 |
+
*
|
| 18 |
+
*
|
| 19 |
+
* DESCRIPTION:
|
| 20 |
+
*
|
| 21 |
+
* Returns the circular tangent of the argument x in degrees.
|
| 22 |
+
*
|
| 23 |
+
* Range reduction is modulo pi/4. A rational function
|
| 24 |
+
* x + x**3 P(x**2)/Q(x**2)
|
| 25 |
+
* is employed in the basic interval [0, pi/4].
|
| 26 |
+
*
|
| 27 |
+
*
|
| 28 |
+
*
|
| 29 |
+
* ACCURACY:
|
| 30 |
+
*
|
| 31 |
+
* Relative error:
|
| 32 |
+
* arithmetic domain # trials peak rms
|
| 33 |
+
* IEEE 0,10 30000 3.2e-16 8.4e-17
|
| 34 |
+
*
|
| 35 |
+
* ERROR MESSAGES:
|
| 36 |
+
*
|
| 37 |
+
* message condition value returned
|
| 38 |
+
* tandg total loss x > 1.0e14 (IEEE) 0.0
|
| 39 |
+
* tandg singularity x = 180 k + 90 INFINITY
|
| 40 |
+
*/
|
| 41 |
+
/* cotdg.c
|
| 42 |
+
*
|
| 43 |
+
* Circular cotangent of argument in degrees
|
| 44 |
+
*
|
| 45 |
+
*
|
| 46 |
+
*
|
| 47 |
+
* SYNOPSIS:
|
| 48 |
+
*
|
| 49 |
+
* double x, y, cotdg();
|
| 50 |
+
*
|
| 51 |
+
* y = cotdg( x );
|
| 52 |
+
*
|
| 53 |
+
*
|
| 54 |
+
*
|
| 55 |
+
* DESCRIPTION:
|
| 56 |
+
*
|
| 57 |
+
* Returns the circular cotangent of the argument x in degrees.
|
| 58 |
+
*
|
| 59 |
+
* Range reduction is modulo pi/4. A rational function
|
| 60 |
+
* x + x**3 P(x**2)/Q(x**2)
|
| 61 |
+
* is employed in the basic interval [0, pi/4].
|
| 62 |
+
*
|
| 63 |
+
*
|
| 64 |
+
* ERROR MESSAGES:
|
| 65 |
+
*
|
| 66 |
+
* message condition value returned
|
| 67 |
+
* cotdg total loss x > 1.0e14 (IEEE) 0.0
|
| 68 |
+
* cotdg singularity x = 180 k INFINITY
|
| 69 |
+
*/
|
| 70 |
+
|
| 71 |
+
/*
|
| 72 |
+
* Cephes Math Library Release 2.0: April, 1987
|
| 73 |
+
* Copyright 1984, 1987 by Stephen L. Moshier
|
| 74 |
+
* Direct inquiries to 30 Frost Street, Cambridge, MA 02140
|
| 75 |
+
*/
|
| 76 |
+
#pragma once
|
| 77 |
+
|
| 78 |
+
#include "../config.h"
|
| 79 |
+
#include "../error.h"
|
| 80 |
+
|
| 81 |
+
namespace xsf {
|
| 82 |
+
namespace cephes {
|
| 83 |
+
|
| 84 |
+
namespace detail {
|
| 85 |
+
constexpr double tandg_lossth = 1.0e14;
|
| 86 |
+
|
| 87 |
+
XSF_HOST_DEVICE inline double tancot(double xx, int cotflg) {
|
| 88 |
+
double x;
|
| 89 |
+
int sign;
|
| 90 |
+
|
| 91 |
+
/* make argument positive but save the sign */
|
| 92 |
+
if (xx < 0) {
|
| 93 |
+
x = -xx;
|
| 94 |
+
sign = -1;
|
| 95 |
+
} else {
|
| 96 |
+
x = xx;
|
| 97 |
+
sign = 1;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
if (x > detail::tandg_lossth) {
|
| 101 |
+
set_error("tandg", SF_ERROR_NO_RESULT, NULL);
|
| 102 |
+
return 0.0;
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
/* modulo 180 */
|
| 106 |
+
x = x - 180.0 * std::floor(x / 180.0);
|
| 107 |
+
if (cotflg) {
|
| 108 |
+
if (x <= 90.0) {
|
| 109 |
+
x = 90.0 - x;
|
| 110 |
+
} else {
|
| 111 |
+
x = x - 90.0;
|
| 112 |
+
sign *= -1;
|
| 113 |
+
}
|
| 114 |
+
} else {
|
| 115 |
+
if (x > 90.0) {
|
| 116 |
+
x = 180.0 - x;
|
| 117 |
+
sign *= -1;
|
| 118 |
+
}
|
| 119 |
+
}
|
| 120 |
+
if (x == 0.0) {
|
| 121 |
+
return 0.0;
|
| 122 |
+
} else if (x == 45.0) {
|
| 123 |
+
return sign * 1.0;
|
| 124 |
+
} else if (x == 90.0) {
|
| 125 |
+
set_error((cotflg ? "cotdg" : "tandg"), SF_ERROR_SINGULAR, NULL);
|
| 126 |
+
return std::numeric_limits<double>::infinity();
|
| 127 |
+
}
|
| 128 |
+
/* x is now transformed into [0, 90) */
|
| 129 |
+
return sign * std::tan(x * detail::PI180);
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
} // namespace detail
|
| 133 |
+
|
| 134 |
+
XSF_HOST_DEVICE inline double tandg(double x) { return (detail::tancot(x, 0)); }
|
| 135 |
+
|
| 136 |
+
XSF_HOST_DEVICE inline double cotdg(double x) { return (detail::tancot(x, 1)); }
|
| 137 |
+
|
| 138 |
+
} // namespace cephes
|
| 139 |
+
} // namespace xsf
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/special/xsf/cephes/trig.h
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Translated into C++ by SciPy developers in 2024.
|
| 2 |
+
*
|
| 3 |
+
* Original author: Josh Wilson, 2020.
|
| 4 |
+
*/
|
| 5 |
+
|
| 6 |
+
/*
|
| 7 |
+
* Implement sin(pi * x) and cos(pi * x) for real x. Since the periods
|
| 8 |
+
* of these functions are integral (and thus representable in double
|
| 9 |
+
* precision), it's possible to compute them with greater accuracy
|
| 10 |
+
* than sin(x) and cos(x).
|
| 11 |
+
*/
|
| 12 |
+
#pragma once
|
| 13 |
+
|
| 14 |
+
#include "../config.h"
|
| 15 |
+
|
| 16 |
+
namespace xsf {
|
| 17 |
+
namespace cephes {
|
| 18 |
+
|
| 19 |
+
/* Compute sin(pi * x). */
|
| 20 |
+
template <typename T>
|
| 21 |
+
XSF_HOST_DEVICE T sinpi(T x) {
|
| 22 |
+
T s = 1.0;
|
| 23 |
+
|
| 24 |
+
if (x < 0.0) {
|
| 25 |
+
x = -x;
|
| 26 |
+
s = -1.0;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
T r = std::fmod(x, 2.0);
|
| 30 |
+
if (r < 0.5) {
|
| 31 |
+
return s * std::sin(M_PI * r);
|
| 32 |
+
} else if (r > 1.5) {
|
| 33 |
+
return s * std::sin(M_PI * (r - 2.0));
|
| 34 |
+
} else {
|
| 35 |
+
return -s * std::sin(M_PI * (r - 1.0));
|
| 36 |
+
}
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
/* Compute cos(pi * x) */
|
| 40 |
+
template <typename T>
|
| 41 |
+
XSF_HOST_DEVICE T cospi(T x) {
|
| 42 |
+
if (x < 0.0) {
|
| 43 |
+
x = -x;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
T r = std::fmod(x, 2.0);
|
| 47 |
+
if (r == 0.5) {
|
| 48 |
+
// We don't want to return -0.0
|
| 49 |
+
return 0.0;
|
| 50 |
+
}
|
| 51 |
+
if (r < 1.0) {
|
| 52 |
+
return -std::sin(M_PI * (r - 0.5));
|
| 53 |
+
} else {
|
| 54 |
+
return std::sin(M_PI * (r - 1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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Translated into C++ by SciPy developers in 2024. */
|
| 2 |
+
|
| 3 |
+
/* unity.c
|
| 4 |
+
*
|
| 5 |
+
* Relative error approximations for function arguments near
|
| 6 |
+
* unity.
|
| 7 |
+
*
|
| 8 |
+
* log1p(x) = log(1+x)
|
| 9 |
+
* expm1(x) = exp(x) - 1
|
| 10 |
+
* cosm1(x) = cos(x) - 1
|
| 11 |
+
* lgam1p(x) = lgam(1+x)
|
| 12 |
+
*
|
| 13 |
+
*/
|
| 14 |
+
|
| 15 |
+
/* Scipy changes:
|
| 16 |
+
* - 06-10-2016: added lgam1p
|
| 17 |
+
*/
|
| 18 |
+
#pragma once
|
| 19 |
+
|
| 20 |
+
#include "../config.h"
|
| 21 |
+
|
| 22 |
+
#include "const.h"
|
| 23 |
+
#include "gamma.h"
|
| 24 |
+
#include "polevl.h"
|
| 25 |
+
#include "zeta.h"
|
| 26 |
+
|
| 27 |
+
namespace xsf {
|
| 28 |
+
namespace cephes {
|
| 29 |
+
|
| 30 |
+
namespace detail {
|
| 31 |
+
|
| 32 |
+
/* log1p(x) = log(1 + x) */
|
| 33 |
+
|
| 34 |
+
/* Coefficients for log(1+x) = x - x**2/2 + x**3 P(x)/Q(x)
|
| 35 |
+
* 1/sqrt(2) <= x < sqrt(2)
|
| 36 |
+
* Theoretical peak relative error = 2.32e-20
|
| 37 |
+
*/
|
| 38 |
+
|
| 39 |
+
constexpr double unity_LP[] = {
|
| 40 |
+
4.5270000862445199635215E-5, 4.9854102823193375972212E-1, 6.5787325942061044846969E0,
|
| 41 |
+
2.9911919328553073277375E1, 6.0949667980987787057556E1, 5.7112963590585538103336E1,
|
| 42 |
+
2.0039553499201281259648E1,
|
| 43 |
+
};
|
| 44 |
+
|
| 45 |
+
constexpr double unity_LQ[] = {
|
| 46 |
+
/* 1.0000000000000000000000E0, */
|
| 47 |
+
1.5062909083469192043167E1, 8.3047565967967209469434E1, 2.2176239823732856465394E2,
|
| 48 |
+
3.0909872225312059774938E2, 2.1642788614495947685003E2, 6.0118660497603843919306E1,
|
| 49 |
+
};
|
| 50 |
+
|
| 51 |
+
} // namespace detail
|
| 52 |
+
|
| 53 |
+
XSF_HOST_DEVICE inline double log1p(double x) {
|
| 54 |
+
double z;
|
| 55 |
+
|
| 56 |
+
z = 1.0 + x;
|
| 57 |
+
if ((z < M_SQRT1_2) || (z > M_SQRT2))
|
| 58 |
+
return (std::log(z));
|
| 59 |
+
z = x * x;
|
| 60 |
+
z = -0.5 * z + x * (z * polevl(x, detail::unity_LP, 6) / p1evl(x, detail::unity_LQ, 6));
|
| 61 |
+
return (x + z);
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
/* log(1 + x) - x */
|
| 65 |
+
XSF_HOST_DEVICE inline double log1pmx(double x) {
|
| 66 |
+
if (std::abs(x) < 0.5) {
|
| 67 |
+
uint64_t n;
|
| 68 |
+
double xfac = x;
|
| 69 |
+
double term;
|
| 70 |
+
double res = 0;
|
| 71 |
+
|
| 72 |
+
for (n = 2; n < detail::MAXITER; n++) {
|
| 73 |
+
xfac *= -x;
|
| 74 |
+
term = xfac / n;
|
| 75 |
+
res += term;
|
| 76 |
+
if (std::abs(term) < detail::MACHEP * std::abs(res)) {
|
| 77 |
+
break;
|
| 78 |
+
}
|
| 79 |
+
}
|
| 80 |
+
return res;
|
| 81 |
+
} else {
|
| 82 |
+
return log1p(x) - x;
|
| 83 |
+
}
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
/* expm1(x) = exp(x) - 1 */
|
| 87 |
+
|
| 88 |
+
/* e^x = 1 + 2x P(x^2)/( Q(x^2) - P(x^2) )
|
| 89 |
+
* -0.5 <= x <= 0.5
|
| 90 |
+
*/
|
| 91 |
+
|
| 92 |
+
namespace detail {
|
| 93 |
+
|
| 94 |
+
constexpr double unity_EP[3] = {
|
| 95 |
+
1.2617719307481059087798E-4,
|
| 96 |
+
3.0299440770744196129956E-2,
|
| 97 |
+
9.9999999999999999991025E-1,
|
| 98 |
+
};
|
| 99 |
+
|
| 100 |
+
constexpr double unity_EQ[4] = {
|
| 101 |
+
3.0019850513866445504159E-6,
|
| 102 |
+
2.5244834034968410419224E-3,
|
| 103 |
+
2.2726554820815502876593E-1,
|
| 104 |
+
2.0000000000000000000897E0,
|
| 105 |
+
};
|
| 106 |
+
|
| 107 |
+
} // namespace detail
|
| 108 |
+
|
| 109 |
+
XSF_HOST_DEVICE inline double expm1(double x) {
|
| 110 |
+
double r, xx;
|
| 111 |
+
|
| 112 |
+
if (!std::isfinite(x)) {
|
| 113 |
+
if (std::isnan(x)) {
|
| 114 |
+
return x;
|
| 115 |
+
} else if (x > 0) {
|
| 116 |
+
return x;
|
| 117 |
+
} else {
|
| 118 |
+
return -1.0;
|
| 119 |
+
}
|
| 120 |
+
}
|
| 121 |
+
if ((x < -0.5) || (x > 0.5))
|
| 122 |
+
return (std::exp(x) - 1.0);
|
| 123 |
+
xx = x * x;
|
| 124 |
+
r = x * polevl(xx, detail::unity_EP, 2);
|
| 125 |
+
r = r / (polevl(xx, detail::unity_EQ, 3) - r);
|
| 126 |
+
return (r + r);
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
/* cosm1(x) = cos(x) - 1 */
|
| 130 |
+
|
| 131 |
+
namespace detail {
|
| 132 |
+
constexpr double unity_coscof[7] = {
|
| 133 |
+
4.7377507964246204691685E-14, -1.1470284843425359765671E-11, 2.0876754287081521758361E-9,
|
| 134 |
+
-2.7557319214999787979814E-7, 2.4801587301570552304991E-5, -1.3888888888888872993737E-3,
|
| 135 |
+
4.1666666666666666609054E-2,
|
| 136 |
+
};
|
| 137 |
+
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
XSF_HOST_DEVICE inline double cosm1(double x) {
|
| 141 |
+
double xx;
|
| 142 |
+
|
| 143 |
+
if ((x < -M_PI_4) || (x > M_PI_4))
|
| 144 |
+
return (std::cos(x) - 1.0);
|
| 145 |
+
xx = x * x;
|
| 146 |
+
xx = -0.5 * xx + xx * xx * polevl(xx, detail::unity_coscof, 6);
|
| 147 |
+
return xx;
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
namespace detail {
|
| 151 |
+
/* Compute lgam(x + 1) around x = 0 using its Taylor series. */
|
| 152 |
+
XSF_HOST_DEVICE inline double lgam1p_taylor(double x) {
|
| 153 |
+
int n;
|
| 154 |
+
double xfac, coeff, res;
|
| 155 |
+
|
| 156 |
+
if (x == 0) {
|
| 157 |
+
return 0;
|
| 158 |
+
}
|
| 159 |
+
res = -SCIPY_EULER * x;
|
| 160 |
+
xfac = -x;
|
| 161 |
+
for (n = 2; n < 42; n++) {
|
| 162 |
+
xfac *= -x;
|
| 163 |
+
coeff = xsf::cephes::zeta(n, 1) * xfac / n;
|
| 164 |
+
res += coeff;
|
| 165 |
+
if (std::abs(coeff) < detail::MACHEP * std::abs(res)) {
|
| 166 |
+
break;
|
| 167 |
+
}
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
return res;
|
| 171 |
+
}
|
| 172 |
+
} // namespace detail
|
| 173 |
+
|
| 174 |
+
/* Compute lgam(x + 1). */
|
| 175 |
+
XSF_HOST_DEVICE inline double lgam1p(double x) {
|
| 176 |
+
if (std::abs(x) <= 0.5) {
|
| 177 |
+
return detail::lgam1p_taylor(x);
|
| 178 |
+
} else if (std::abs(x - 1) < 0.5) {
|
| 179 |
+
return std::log(x) + detail::lgam1p_taylor(x - 1);
|
| 180 |
+
} else {
|
| 181 |
+
return lgam(x + 1);
|
| 182 |
+
}
|
| 183 |
+
}
|
| 184 |
+
|
| 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Translated into C++ by SciPy developers in 2024.
|
| 2 |
+
* Original header with Copyright information appears below.
|
| 3 |
+
*/
|
| 4 |
+
|
| 5 |
+
/* zeta.c
|
| 6 |
+
*
|
| 7 |
+
* Riemann zeta function of two arguments
|
| 8 |
+
*
|
| 9 |
+
*
|
| 10 |
+
*
|
| 11 |
+
* SYNOPSIS:
|
| 12 |
+
*
|
| 13 |
+
* double x, q, y, zeta();
|
| 14 |
+
*
|
| 15 |
+
* y = zeta( x, q );
|
| 16 |
+
*
|
| 17 |
+
*
|
| 18 |
+
*
|
| 19 |
+
* DESCRIPTION:
|
| 20 |
+
*
|
| 21 |
+
*
|
| 22 |
+
*
|
| 23 |
+
* inf.
|
| 24 |
+
* - -x
|
| 25 |
+
* zeta(x,q) = > (k+q)
|
| 26 |
+
* -
|
| 27 |
+
* k=0
|
| 28 |
+
*
|
| 29 |
+
* where x > 1 and q is not a negative integer or zero.
|
| 30 |
+
* The Euler-Maclaurin summation formula is used to obtain
|
| 31 |
+
* the expansion
|
| 32 |
+
*
|
| 33 |
+
* n
|
| 34 |
+
* - -x
|
| 35 |
+
* zeta(x,q) = > (k+q)
|
| 36 |
+
* -
|
| 37 |
+
* k=1
|
| 38 |
+
*
|
| 39 |
+
* 1-x inf. B x(x+1)...(x+2j)
|
| 40 |
+
* (n+q) 1 - 2j
|
| 41 |
+
* + --------- - ------- + > --------------------
|
| 42 |
+
* x-1 x - x+2j+1
|
| 43 |
+
* 2(n+q) j=1 (2j)! (n+q)
|
| 44 |
+
*
|
| 45 |
+
* where the B2j are Bernoulli numbers. Note that (see zetac.c)
|
| 46 |
+
* zeta(x,1) = zetac(x) + 1.
|
| 47 |
+
*
|
| 48 |
+
*
|
| 49 |
+
*
|
| 50 |
+
* ACCURACY:
|
| 51 |
+
*
|
| 52 |
+
*
|
| 53 |
+
*
|
| 54 |
+
* REFERENCE:
|
| 55 |
+
*
|
| 56 |
+
* Gradshteyn, I. S., and I. M. Ryzhik, Tables of Integrals,
|
| 57 |
+
* Series, and Products, p. 1073; Academic Press, 1980.
|
| 58 |
+
*
|
| 59 |
+
*/
|
| 60 |
+
|
| 61 |
+
/*
|
| 62 |
+
* Cephes Math Library Release 2.0: April, 1987
|
| 63 |
+
* Copyright 1984, 1987 by Stephen L. Moshier
|
| 64 |
+
* Direct inquiries to 30 Frost Street, Cambridge, MA 02140
|
| 65 |
+
*/
|
| 66 |
+
#pragma once
|
| 67 |
+
|
| 68 |
+
#include "../config.h"
|
| 69 |
+
#include "../error.h"
|
| 70 |
+
#include "const.h"
|
| 71 |
+
|
| 72 |
+
namespace xsf {
|
| 73 |
+
namespace cephes {
|
| 74 |
+
|
| 75 |
+
namespace detail {
|
| 76 |
+
/* Expansion coefficients
|
| 77 |
+
* for Euler-Maclaurin summation formula
|
| 78 |
+
* (2k)! / B2k
|
| 79 |
+
* where B2k are Bernoulli numbers
|
| 80 |
+
*/
|
| 81 |
+
constexpr double zeta_A[] = {
|
| 82 |
+
12.0,
|
| 83 |
+
-720.0,
|
| 84 |
+
30240.0,
|
| 85 |
+
-1209600.0,
|
| 86 |
+
47900160.0,
|
| 87 |
+
-1.8924375803183791606e9, /*1.307674368e12/691 */
|
| 88 |
+
7.47242496e10,
|
| 89 |
+
-2.950130727918164224e12, /*1.067062284288e16/3617 */
|
| 90 |
+
1.1646782814350067249e14, /*5.109094217170944e18/43867 */
|
| 91 |
+
-4.5979787224074726105e15, /*8.028576626982912e20/174611 */
|
| 92 |
+
1.8152105401943546773e17, /*1.5511210043330985984e23/854513 */
|
| 93 |
+
-7.1661652561756670113e18 /*1.6938241367317436694528e27/236364091 */
|
| 94 |
+
};
|
| 95 |
+
|
| 96 |
+
/* 30 Nov 86 -- error in third coefficient fixed */
|
| 97 |
+
} // namespace detail
|
| 98 |
+
|
| 99 |
+
XSF_HOST_DEVICE double inline zeta(double x, double q) {
|
| 100 |
+
int i;
|
| 101 |
+
double a, b, k, s, t, w;
|
| 102 |
+
|
| 103 |
+
if (x == 1.0)
|
| 104 |
+
goto retinf;
|
| 105 |
+
|
| 106 |
+
if (x < 1.0) {
|
| 107 |
+
domerr:
|
| 108 |
+
set_error("zeta", SF_ERROR_DOMAIN, NULL);
|
| 109 |
+
return (std::numeric_limits<double>::quiet_NaN());
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
if (q <= 0.0) {
|
| 113 |
+
if (q == floor(q)) {
|
| 114 |
+
set_error("zeta", SF_ERROR_SINGULAR, NULL);
|
| 115 |
+
retinf:
|
| 116 |
+
return (std::numeric_limits<double>::infinity());
|
| 117 |
+
}
|
| 118 |
+
if (x != std::floor(x))
|
| 119 |
+
goto domerr; /* because q^-x not defined */
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
/* Asymptotic expansion
|
| 123 |
+
* https://dlmf.nist.gov/25.11#E43
|
| 124 |
+
*/
|
| 125 |
+
if (q > 1e8) {
|
| 126 |
+
return (1 / (x - 1) + 1 / (2 * q)) * std::pow(q, 1 - x);
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
/* Euler-Maclaurin summation formula */
|
| 130 |
+
|
| 131 |
+
/* Permit negative q but continue sum until n+q > +9 .
|
| 132 |
+
* This case should be handled by a reflection formula.
|
| 133 |
+
* If q<0 and x is an integer, there is a relation to
|
| 134 |
+
* the polyGamma function.
|
| 135 |
+
*/
|
| 136 |
+
s = std::pow(q, -x);
|
| 137 |
+
a = q;
|
| 138 |
+
i = 0;
|
| 139 |
+
b = 0.0;
|
| 140 |
+
while ((i < 9) || (a <= 9.0)) {
|
| 141 |
+
i += 1;
|
| 142 |
+
a += 1.0;
|
| 143 |
+
b = std::pow(a, -x);
|
| 144 |
+
s += b;
|
| 145 |
+
if (std::abs(b / s) < detail::MACHEP)
|
| 146 |
+
goto done;
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
w = a;
|
| 150 |
+
s += b * w / (x - 1.0);
|
| 151 |
+
s -= 0.5 * b;
|
| 152 |
+
a = 1.0;
|
| 153 |
+
k = 0.0;
|
| 154 |
+
for (i = 0; i < 12; i++) {
|
| 155 |
+
a *= x + k;
|
| 156 |
+
b /= w;
|
| 157 |
+
t = a * b / detail::zeta_A[i];
|
| 158 |
+
s = s + t;
|
| 159 |
+
t = std::abs(t / s);
|
| 160 |
+
if (t < detail::MACHEP)
|
| 161 |
+
goto done;
|
| 162 |
+
k += 1.0;
|
| 163 |
+
a *= x + k;
|
| 164 |
+
b /= w;
|
| 165 |
+
k += 1.0;
|
| 166 |
+
}
|
| 167 |
+
done:
|
| 168 |
+
return (s);
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
} // namespace cephes
|
| 172 |
+
} // namespace xsf
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/stats/__init__.py
ADDED
|
@@ -0,0 +1,667 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
.. _statsrefmanual:
|
| 3 |
+
|
| 4 |
+
==========================================
|
| 5 |
+
Statistical functions (:mod:`scipy.stats`)
|
| 6 |
+
==========================================
|
| 7 |
+
|
| 8 |
+
.. currentmodule:: scipy.stats
|
| 9 |
+
|
| 10 |
+
This module contains a large number of probability distributions,
|
| 11 |
+
summary and frequency statistics, correlation functions and statistical
|
| 12 |
+
tests, masked statistics, kernel density estimation, quasi-Monte Carlo
|
| 13 |
+
functionality, and more.
|
| 14 |
+
|
| 15 |
+
Statistics is a very large area, and there are topics that are out of scope
|
| 16 |
+
for SciPy and are covered by other packages. Some of the most important ones
|
| 17 |
+
are:
|
| 18 |
+
|
| 19 |
+
- `statsmodels <https://www.statsmodels.org/stable/index.html>`__:
|
| 20 |
+
regression, linear models, time series analysis, extensions to topics
|
| 21 |
+
also covered by ``scipy.stats``.
|
| 22 |
+
- `Pandas <https://pandas.pydata.org/>`__: tabular data, time series
|
| 23 |
+
functionality, interfaces to other statistical languages.
|
| 24 |
+
- `PyMC <https://docs.pymc.io/>`__: Bayesian statistical
|
| 25 |
+
modeling, probabilistic machine learning.
|
| 26 |
+
- `scikit-learn <https://scikit-learn.org/>`__: classification, regression,
|
| 27 |
+
model selection.
|
| 28 |
+
- `Seaborn <https://seaborn.pydata.org/>`__: statistical data visualization.
|
| 29 |
+
- `rpy2 <https://rpy2.github.io/>`__: Python to R bridge.
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
Probability distributions
|
| 33 |
+
=========================
|
| 34 |
+
|
| 35 |
+
Each univariate distribution is an instance of a subclass of `rv_continuous`
|
| 36 |
+
(`rv_discrete` for discrete distributions):
|
| 37 |
+
|
| 38 |
+
.. autosummary::
|
| 39 |
+
:toctree: generated/
|
| 40 |
+
|
| 41 |
+
rv_continuous
|
| 42 |
+
rv_discrete
|
| 43 |
+
rv_histogram
|
| 44 |
+
|
| 45 |
+
Continuous distributions
|
| 46 |
+
------------------------
|
| 47 |
+
|
| 48 |
+
.. autosummary::
|
| 49 |
+
:toctree: generated/
|
| 50 |
+
|
| 51 |
+
alpha -- Alpha
|
| 52 |
+
anglit -- Anglit
|
| 53 |
+
arcsine -- Arcsine
|
| 54 |
+
argus -- Argus
|
| 55 |
+
beta -- Beta
|
| 56 |
+
betaprime -- Beta Prime
|
| 57 |
+
bradford -- Bradford
|
| 58 |
+
burr -- Burr (Type III)
|
| 59 |
+
burr12 -- Burr (Type XII)
|
| 60 |
+
cauchy -- Cauchy
|
| 61 |
+
chi -- Chi
|
| 62 |
+
chi2 -- Chi-squared
|
| 63 |
+
cosine -- Cosine
|
| 64 |
+
crystalball -- Crystalball
|
| 65 |
+
dgamma -- Double Gamma
|
| 66 |
+
dpareto_lognorm -- Double Pareto Lognormal
|
| 67 |
+
dweibull -- Double Weibull
|
| 68 |
+
erlang -- Erlang
|
| 69 |
+
expon -- Exponential
|
| 70 |
+
exponnorm -- Exponentially Modified Normal
|
| 71 |
+
exponweib -- Exponentiated Weibull
|
| 72 |
+
exponpow -- Exponential Power
|
| 73 |
+
f -- F (Snecdor F)
|
| 74 |
+
fatiguelife -- Fatigue Life (Birnbaum-Saunders)
|
| 75 |
+
fisk -- Fisk
|
| 76 |
+
foldcauchy -- Folded Cauchy
|
| 77 |
+
foldnorm -- Folded Normal
|
| 78 |
+
genlogistic -- Generalized Logistic
|
| 79 |
+
gennorm -- Generalized normal
|
| 80 |
+
genpareto -- Generalized Pareto
|
| 81 |
+
genexpon -- Generalized Exponential
|
| 82 |
+
genextreme -- Generalized Extreme Value
|
| 83 |
+
gausshyper -- Gauss Hypergeometric
|
| 84 |
+
gamma -- Gamma
|
| 85 |
+
gengamma -- Generalized gamma
|
| 86 |
+
genhalflogistic -- Generalized Half Logistic
|
| 87 |
+
genhyperbolic -- Generalized Hyperbolic
|
| 88 |
+
geninvgauss -- Generalized Inverse Gaussian
|
| 89 |
+
gibrat -- Gibrat
|
| 90 |
+
gompertz -- Gompertz (Truncated Gumbel)
|
| 91 |
+
gumbel_r -- Right Sided Gumbel, Log-Weibull, Fisher-Tippett, Extreme Value Type I
|
| 92 |
+
gumbel_l -- Left Sided Gumbel, etc.
|
| 93 |
+
halfcauchy -- Half Cauchy
|
| 94 |
+
halflogistic -- Half Logistic
|
| 95 |
+
halfnorm -- Half Normal
|
| 96 |
+
halfgennorm -- Generalized Half Normal
|
| 97 |
+
hypsecant -- Hyperbolic Secant
|
| 98 |
+
invgamma -- Inverse Gamma
|
| 99 |
+
invgauss -- Inverse Gaussian
|
| 100 |
+
invweibull -- Inverse Weibull
|
| 101 |
+
irwinhall -- Irwin-Hall
|
| 102 |
+
jf_skew_t -- Jones and Faddy Skew-T
|
| 103 |
+
johnsonsb -- Johnson SB
|
| 104 |
+
johnsonsu -- Johnson SU
|
| 105 |
+
kappa4 -- Kappa 4 parameter
|
| 106 |
+
kappa3 -- Kappa 3 parameter
|
| 107 |
+
ksone -- Distribution of Kolmogorov-Smirnov one-sided test statistic
|
| 108 |
+
kstwo -- Distribution of Kolmogorov-Smirnov two-sided test statistic
|
| 109 |
+
kstwobign -- Limiting Distribution of scaled Kolmogorov-Smirnov two-sided test statistic.
|
| 110 |
+
landau -- Landau
|
| 111 |
+
laplace -- Laplace
|
| 112 |
+
laplace_asymmetric -- Asymmetric Laplace
|
| 113 |
+
levy -- Levy
|
| 114 |
+
levy_l
|
| 115 |
+
levy_stable
|
| 116 |
+
logistic -- Logistic
|
| 117 |
+
loggamma -- Log-Gamma
|
| 118 |
+
loglaplace -- Log-Laplace (Log Double Exponential)
|
| 119 |
+
lognorm -- Log-Normal
|
| 120 |
+
loguniform -- Log-Uniform
|
| 121 |
+
lomax -- Lomax (Pareto of the second kind)
|
| 122 |
+
maxwell -- Maxwell
|
| 123 |
+
mielke -- Mielke's Beta-Kappa
|
| 124 |
+
moyal -- Moyal
|
| 125 |
+
nakagami -- Nakagami
|
| 126 |
+
ncx2 -- Non-central chi-squared
|
| 127 |
+
ncf -- Non-central F
|
| 128 |
+
nct -- Non-central Student's T
|
| 129 |
+
norm -- Normal (Gaussian)
|
| 130 |
+
norminvgauss -- Normal Inverse Gaussian
|
| 131 |
+
pareto -- Pareto
|
| 132 |
+
pearson3 -- Pearson type III
|
| 133 |
+
powerlaw -- Power-function
|
| 134 |
+
powerlognorm -- Power log normal
|
| 135 |
+
powernorm -- Power normal
|
| 136 |
+
rdist -- R-distribution
|
| 137 |
+
rayleigh -- Rayleigh
|
| 138 |
+
rel_breitwigner -- Relativistic Breit-Wigner
|
| 139 |
+
rice -- Rice
|
| 140 |
+
recipinvgauss -- Reciprocal Inverse Gaussian
|
| 141 |
+
semicircular -- Semicircular
|
| 142 |
+
skewcauchy -- Skew Cauchy
|
| 143 |
+
skewnorm -- Skew normal
|
| 144 |
+
studentized_range -- Studentized Range
|
| 145 |
+
t -- Student's T
|
| 146 |
+
trapezoid -- Trapezoidal
|
| 147 |
+
triang -- Triangular
|
| 148 |
+
truncexpon -- Truncated Exponential
|
| 149 |
+
truncnorm -- Truncated Normal
|
| 150 |
+
truncpareto -- Truncated Pareto
|
| 151 |
+
truncweibull_min -- Truncated minimum Weibull distribution
|
| 152 |
+
tukeylambda -- Tukey-Lambda
|
| 153 |
+
uniform -- Uniform
|
| 154 |
+
vonmises -- Von-Mises (Circular)
|
| 155 |
+
vonmises_line -- Von-Mises (Line)
|
| 156 |
+
wald -- Wald
|
| 157 |
+
weibull_min -- Minimum Weibull (see Frechet)
|
| 158 |
+
weibull_max -- Maximum Weibull (see Frechet)
|
| 159 |
+
wrapcauchy -- Wrapped Cauchy
|
| 160 |
+
|
| 161 |
+
The ``fit`` method of the univariate continuous distributions uses
|
| 162 |
+
maximum likelihood estimation to fit the distribution to a data set.
|
| 163 |
+
The ``fit`` method can accept regular data or *censored data*.
|
| 164 |
+
Censored data is represented with instances of the `CensoredData`
|
| 165 |
+
class.
|
| 166 |
+
|
| 167 |
+
.. autosummary::
|
| 168 |
+
:toctree: generated/
|
| 169 |
+
|
| 170 |
+
CensoredData
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
Multivariate distributions
|
| 174 |
+
--------------------------
|
| 175 |
+
|
| 176 |
+
.. autosummary::
|
| 177 |
+
:toctree: generated/
|
| 178 |
+
|
| 179 |
+
multivariate_normal -- Multivariate normal distribution
|
| 180 |
+
matrix_normal -- Matrix normal distribution
|
| 181 |
+
dirichlet -- Dirichlet
|
| 182 |
+
dirichlet_multinomial -- Dirichlet multinomial distribution
|
| 183 |
+
wishart -- Wishart
|
| 184 |
+
invwishart -- Inverse Wishart
|
| 185 |
+
multinomial -- Multinomial distribution
|
| 186 |
+
special_ortho_group -- SO(N) group
|
| 187 |
+
ortho_group -- O(N) group
|
| 188 |
+
unitary_group -- U(N) group
|
| 189 |
+
random_correlation -- random correlation matrices
|
| 190 |
+
multivariate_t -- Multivariate t-distribution
|
| 191 |
+
multivariate_hypergeom -- Multivariate hypergeometric distribution
|
| 192 |
+
normal_inverse_gamma -- Normal-inverse-gamma distribution
|
| 193 |
+
random_table -- Distribution of random tables with given marginals
|
| 194 |
+
uniform_direction -- Uniform distribution on S(N-1)
|
| 195 |
+
vonmises_fisher -- Von Mises-Fisher distribution
|
| 196 |
+
|
| 197 |
+
`scipy.stats.multivariate_normal` methods accept instances
|
| 198 |
+
of the following class to represent the covariance.
|
| 199 |
+
|
| 200 |
+
.. autosummary::
|
| 201 |
+
:toctree: generated/
|
| 202 |
+
|
| 203 |
+
Covariance -- Representation of a covariance matrix
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
Discrete distributions
|
| 207 |
+
----------------------
|
| 208 |
+
|
| 209 |
+
.. autosummary::
|
| 210 |
+
:toctree: generated/
|
| 211 |
+
|
| 212 |
+
bernoulli -- Bernoulli
|
| 213 |
+
betabinom -- Beta-Binomial
|
| 214 |
+
betanbinom -- Beta-Negative Binomial
|
| 215 |
+
binom -- Binomial
|
| 216 |
+
boltzmann -- Boltzmann (Truncated Discrete Exponential)
|
| 217 |
+
dlaplace -- Discrete Laplacian
|
| 218 |
+
geom -- Geometric
|
| 219 |
+
hypergeom -- Hypergeometric
|
| 220 |
+
logser -- Logarithmic (Log-Series, Series)
|
| 221 |
+
nbinom -- Negative Binomial
|
| 222 |
+
nchypergeom_fisher -- Fisher's Noncentral Hypergeometric
|
| 223 |
+
nchypergeom_wallenius -- Wallenius's Noncentral Hypergeometric
|
| 224 |
+
nhypergeom -- Negative Hypergeometric
|
| 225 |
+
planck -- Planck (Discrete Exponential)
|
| 226 |
+
poisson -- Poisson
|
| 227 |
+
poisson_binom -- Poisson Binomial
|
| 228 |
+
randint -- Discrete Uniform
|
| 229 |
+
skellam -- Skellam
|
| 230 |
+
yulesimon -- Yule-Simon
|
| 231 |
+
zipf -- Zipf (Zeta)
|
| 232 |
+
zipfian -- Zipfian
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
An overview of statistical functions is given below. Many of these functions
|
| 236 |
+
have a similar version in `scipy.stats.mstats` which work for masked arrays.
|
| 237 |
+
|
| 238 |
+
Summary statistics
|
| 239 |
+
==================
|
| 240 |
+
|
| 241 |
+
.. autosummary::
|
| 242 |
+
:toctree: generated/
|
| 243 |
+
|
| 244 |
+
describe -- Descriptive statistics
|
| 245 |
+
gmean -- Geometric mean
|
| 246 |
+
hmean -- Harmonic mean
|
| 247 |
+
pmean -- Power mean
|
| 248 |
+
kurtosis -- Fisher or Pearson kurtosis
|
| 249 |
+
mode -- Modal value
|
| 250 |
+
moment -- Central moment
|
| 251 |
+
lmoment
|
| 252 |
+
expectile -- Expectile
|
| 253 |
+
skew -- Skewness
|
| 254 |
+
kstat --
|
| 255 |
+
kstatvar --
|
| 256 |
+
tmean -- Truncated arithmetic mean
|
| 257 |
+
tvar -- Truncated variance
|
| 258 |
+
tmin --
|
| 259 |
+
tmax --
|
| 260 |
+
tstd --
|
| 261 |
+
tsem --
|
| 262 |
+
variation -- Coefficient of variation
|
| 263 |
+
find_repeats
|
| 264 |
+
rankdata
|
| 265 |
+
tiecorrect
|
| 266 |
+
trim_mean
|
| 267 |
+
gstd -- Geometric Standard Deviation
|
| 268 |
+
iqr
|
| 269 |
+
sem
|
| 270 |
+
bayes_mvs
|
| 271 |
+
mvsdist
|
| 272 |
+
entropy
|
| 273 |
+
differential_entropy
|
| 274 |
+
median_abs_deviation
|
| 275 |
+
|
| 276 |
+
Frequency statistics
|
| 277 |
+
====================
|
| 278 |
+
|
| 279 |
+
.. autosummary::
|
| 280 |
+
:toctree: generated/
|
| 281 |
+
|
| 282 |
+
cumfreq
|
| 283 |
+
percentileofscore
|
| 284 |
+
scoreatpercentile
|
| 285 |
+
relfreq
|
| 286 |
+
|
| 287 |
+
.. autosummary::
|
| 288 |
+
:toctree: generated/
|
| 289 |
+
|
| 290 |
+
binned_statistic -- Compute a binned statistic for a set of data.
|
| 291 |
+
binned_statistic_2d -- Compute a 2-D binned statistic for a set of data.
|
| 292 |
+
binned_statistic_dd -- Compute a d-D binned statistic for a set of data.
|
| 293 |
+
|
| 294 |
+
.. _hypotests:
|
| 295 |
+
|
| 296 |
+
Hypothesis Tests and related functions
|
| 297 |
+
======================================
|
| 298 |
+
SciPy has many functions for performing hypothesis tests that return a
|
| 299 |
+
test statistic and a p-value, and several of them return confidence intervals
|
| 300 |
+
and/or other related information.
|
| 301 |
+
|
| 302 |
+
The headings below are based on common uses of the functions within, but due to
|
| 303 |
+
the wide variety of statistical procedures, any attempt at coarse-grained
|
| 304 |
+
categorization will be imperfect. Also, note that tests within the same heading
|
| 305 |
+
are not interchangeable in general (e.g. many have different distributional
|
| 306 |
+
assumptions).
|
| 307 |
+
|
| 308 |
+
One Sample Tests / Paired Sample Tests
|
| 309 |
+
--------------------------------------
|
| 310 |
+
One sample tests are typically used to assess whether a single sample was
|
| 311 |
+
drawn from a specified distribution or a distribution with specified properties
|
| 312 |
+
(e.g. zero mean).
|
| 313 |
+
|
| 314 |
+
.. autosummary::
|
| 315 |
+
:toctree: generated/
|
| 316 |
+
|
| 317 |
+
ttest_1samp
|
| 318 |
+
binomtest
|
| 319 |
+
quantile_test
|
| 320 |
+
skewtest
|
| 321 |
+
kurtosistest
|
| 322 |
+
normaltest
|
| 323 |
+
jarque_bera
|
| 324 |
+
shapiro
|
| 325 |
+
anderson
|
| 326 |
+
cramervonmises
|
| 327 |
+
ks_1samp
|
| 328 |
+
goodness_of_fit
|
| 329 |
+
chisquare
|
| 330 |
+
power_divergence
|
| 331 |
+
|
| 332 |
+
Paired sample tests are often used to assess whether two samples were drawn
|
| 333 |
+
from the same distribution; they differ from the independent sample tests below
|
| 334 |
+
in that each observation in one sample is treated as paired with a
|
| 335 |
+
closely-related observation in the other sample (e.g. when environmental
|
| 336 |
+
factors are controlled between observations within a pair but not among pairs).
|
| 337 |
+
They can also be interpreted or used as one-sample tests (e.g. tests on the
|
| 338 |
+
mean or median of *differences* between paired observations).
|
| 339 |
+
|
| 340 |
+
.. autosummary::
|
| 341 |
+
:toctree: generated/
|
| 342 |
+
|
| 343 |
+
ttest_rel
|
| 344 |
+
wilcoxon
|
| 345 |
+
|
| 346 |
+
Association/Correlation Tests
|
| 347 |
+
-----------------------------
|
| 348 |
+
|
| 349 |
+
These tests are often used to assess whether there is a relationship (e.g.
|
| 350 |
+
linear) between paired observations in multiple samples or among the
|
| 351 |
+
coordinates of multivariate observations.
|
| 352 |
+
|
| 353 |
+
.. autosummary::
|
| 354 |
+
:toctree: generated/
|
| 355 |
+
|
| 356 |
+
linregress
|
| 357 |
+
pearsonr
|
| 358 |
+
spearmanr
|
| 359 |
+
pointbiserialr
|
| 360 |
+
kendalltau
|
| 361 |
+
chatterjeexi
|
| 362 |
+
weightedtau
|
| 363 |
+
somersd
|
| 364 |
+
siegelslopes
|
| 365 |
+
theilslopes
|
| 366 |
+
page_trend_test
|
| 367 |
+
multiscale_graphcorr
|
| 368 |
+
|
| 369 |
+
These association tests and are to work with samples in the form of contingency
|
| 370 |
+
tables. Supporting functions are available in `scipy.stats.contingency`.
|
| 371 |
+
|
| 372 |
+
.. autosummary::
|
| 373 |
+
:toctree: generated/
|
| 374 |
+
|
| 375 |
+
chi2_contingency
|
| 376 |
+
fisher_exact
|
| 377 |
+
barnard_exact
|
| 378 |
+
boschloo_exact
|
| 379 |
+
|
| 380 |
+
Independent Sample Tests
|
| 381 |
+
------------------------
|
| 382 |
+
Independent sample tests are typically used to assess whether multiple samples
|
| 383 |
+
were independently drawn from the same distribution or different distributions
|
| 384 |
+
with a shared property (e.g. equal means).
|
| 385 |
+
|
| 386 |
+
Some tests are specifically for comparing two samples.
|
| 387 |
+
|
| 388 |
+
.. autosummary::
|
| 389 |
+
:toctree: generated/
|
| 390 |
+
|
| 391 |
+
ttest_ind_from_stats
|
| 392 |
+
poisson_means_test
|
| 393 |
+
ttest_ind
|
| 394 |
+
mannwhitneyu
|
| 395 |
+
bws_test
|
| 396 |
+
ranksums
|
| 397 |
+
brunnermunzel
|
| 398 |
+
mood
|
| 399 |
+
ansari
|
| 400 |
+
cramervonmises_2samp
|
| 401 |
+
epps_singleton_2samp
|
| 402 |
+
ks_2samp
|
| 403 |
+
kstest
|
| 404 |
+
|
| 405 |
+
Others are generalized to multiple samples.
|
| 406 |
+
|
| 407 |
+
.. autosummary::
|
| 408 |
+
:toctree: generated/
|
| 409 |
+
|
| 410 |
+
f_oneway
|
| 411 |
+
tukey_hsd
|
| 412 |
+
dunnett
|
| 413 |
+
kruskal
|
| 414 |
+
alexandergovern
|
| 415 |
+
fligner
|
| 416 |
+
levene
|
| 417 |
+
bartlett
|
| 418 |
+
median_test
|
| 419 |
+
friedmanchisquare
|
| 420 |
+
anderson_ksamp
|
| 421 |
+
|
| 422 |
+
Resampling and Monte Carlo Methods
|
| 423 |
+
----------------------------------
|
| 424 |
+
The following functions can reproduce the p-value and confidence interval
|
| 425 |
+
results of most of the functions above, and often produce accurate results in a
|
| 426 |
+
wider variety of conditions. They can also be used to perform hypothesis tests
|
| 427 |
+
and generate confidence intervals for custom statistics. This flexibility comes
|
| 428 |
+
at the cost of greater computational requirements and stochastic results.
|
| 429 |
+
|
| 430 |
+
.. autosummary::
|
| 431 |
+
:toctree: generated/
|
| 432 |
+
|
| 433 |
+
monte_carlo_test
|
| 434 |
+
permutation_test
|
| 435 |
+
bootstrap
|
| 436 |
+
power
|
| 437 |
+
|
| 438 |
+
Instances of the following object can be passed into some hypothesis test
|
| 439 |
+
functions to perform a resampling or Monte Carlo version of the hypothesis
|
| 440 |
+
test.
|
| 441 |
+
|
| 442 |
+
.. autosummary::
|
| 443 |
+
:toctree: generated/
|
| 444 |
+
|
| 445 |
+
MonteCarloMethod
|
| 446 |
+
PermutationMethod
|
| 447 |
+
BootstrapMethod
|
| 448 |
+
|
| 449 |
+
Multiple Hypothesis Testing and Meta-Analysis
|
| 450 |
+
---------------------------------------------
|
| 451 |
+
These functions are for assessing the results of individual tests as a whole.
|
| 452 |
+
Functions for performing specific multiple hypothesis tests (e.g. post hoc
|
| 453 |
+
tests) are listed above.
|
| 454 |
+
|
| 455 |
+
.. autosummary::
|
| 456 |
+
:toctree: generated/
|
| 457 |
+
|
| 458 |
+
combine_pvalues
|
| 459 |
+
false_discovery_control
|
| 460 |
+
|
| 461 |
+
|
| 462 |
+
The following functions are related to the tests above but do not belong in the
|
| 463 |
+
above categories.
|
| 464 |
+
|
| 465 |
+
Random Variables
|
| 466 |
+
================
|
| 467 |
+
|
| 468 |
+
.. autosummary::
|
| 469 |
+
:toctree: generated/
|
| 470 |
+
|
| 471 |
+
make_distribution
|
| 472 |
+
Normal
|
| 473 |
+
Uniform
|
| 474 |
+
Mixture
|
| 475 |
+
order_statistic
|
| 476 |
+
truncate
|
| 477 |
+
abs
|
| 478 |
+
exp
|
| 479 |
+
log
|
| 480 |
+
|
| 481 |
+
Quasi-Monte Carlo
|
| 482 |
+
=================
|
| 483 |
+
|
| 484 |
+
.. toctree::
|
| 485 |
+
:maxdepth: 4
|
| 486 |
+
|
| 487 |
+
stats.qmc
|
| 488 |
+
|
| 489 |
+
Contingency Tables
|
| 490 |
+
==================
|
| 491 |
+
|
| 492 |
+
.. toctree::
|
| 493 |
+
:maxdepth: 4
|
| 494 |
+
|
| 495 |
+
stats.contingency
|
| 496 |
+
|
| 497 |
+
Masked statistics functions
|
| 498 |
+
===========================
|
| 499 |
+
|
| 500 |
+
.. toctree::
|
| 501 |
+
|
| 502 |
+
stats.mstats
|
| 503 |
+
|
| 504 |
+
|
| 505 |
+
Other statistical functionality
|
| 506 |
+
===============================
|
| 507 |
+
|
| 508 |
+
Transformations
|
| 509 |
+
---------------
|
| 510 |
+
|
| 511 |
+
.. autosummary::
|
| 512 |
+
:toctree: generated/
|
| 513 |
+
|
| 514 |
+
boxcox
|
| 515 |
+
boxcox_normmax
|
| 516 |
+
boxcox_llf
|
| 517 |
+
yeojohnson
|
| 518 |
+
yeojohnson_normmax
|
| 519 |
+
yeojohnson_llf
|
| 520 |
+
obrientransform
|
| 521 |
+
sigmaclip
|
| 522 |
+
trimboth
|
| 523 |
+
trim1
|
| 524 |
+
zmap
|
| 525 |
+
zscore
|
| 526 |
+
gzscore
|
| 527 |
+
|
| 528 |
+
Statistical distances
|
| 529 |
+
---------------------
|
| 530 |
+
|
| 531 |
+
.. autosummary::
|
| 532 |
+
:toctree: generated/
|
| 533 |
+
|
| 534 |
+
wasserstein_distance
|
| 535 |
+
wasserstein_distance_nd
|
| 536 |
+
energy_distance
|
| 537 |
+
|
| 538 |
+
Sampling
|
| 539 |
+
--------
|
| 540 |
+
|
| 541 |
+
.. toctree::
|
| 542 |
+
:maxdepth: 4
|
| 543 |
+
|
| 544 |
+
stats.sampling
|
| 545 |
+
|
| 546 |
+
Fitting / Survival Analysis
|
| 547 |
+
---------------------------
|
| 548 |
+
|
| 549 |
+
.. autosummary::
|
| 550 |
+
:toctree: generated/
|
| 551 |
+
|
| 552 |
+
fit
|
| 553 |
+
ecdf
|
| 554 |
+
logrank
|
| 555 |
+
|
| 556 |
+
Directional statistical functions
|
| 557 |
+
---------------------------------
|
| 558 |
+
|
| 559 |
+
.. autosummary::
|
| 560 |
+
:toctree: generated/
|
| 561 |
+
|
| 562 |
+
directional_stats
|
| 563 |
+
circmean
|
| 564 |
+
circvar
|
| 565 |
+
circstd
|
| 566 |
+
|
| 567 |
+
Sensitivity Analysis
|
| 568 |
+
--------------------
|
| 569 |
+
|
| 570 |
+
.. autosummary::
|
| 571 |
+
:toctree: generated/
|
| 572 |
+
|
| 573 |
+
sobol_indices
|
| 574 |
+
|
| 575 |
+
Plot-tests
|
| 576 |
+
----------
|
| 577 |
+
|
| 578 |
+
.. autosummary::
|
| 579 |
+
:toctree: generated/
|
| 580 |
+
|
| 581 |
+
ppcc_max
|
| 582 |
+
ppcc_plot
|
| 583 |
+
probplot
|
| 584 |
+
boxcox_normplot
|
| 585 |
+
yeojohnson_normplot
|
| 586 |
+
|
| 587 |
+
Univariate and multivariate kernel density estimation
|
| 588 |
+
-----------------------------------------------------
|
| 589 |
+
|
| 590 |
+
.. autosummary::
|
| 591 |
+
:toctree: generated/
|
| 592 |
+
|
| 593 |
+
gaussian_kde
|
| 594 |
+
|
| 595 |
+
Warnings / Errors used in :mod:`scipy.stats`
|
| 596 |
+
--------------------------------------------
|
| 597 |
+
|
| 598 |
+
.. autosummary::
|
| 599 |
+
:toctree: generated/
|
| 600 |
+
|
| 601 |
+
DegenerateDataWarning
|
| 602 |
+
ConstantInputWarning
|
| 603 |
+
NearConstantInputWarning
|
| 604 |
+
FitError
|
| 605 |
+
|
| 606 |
+
Result classes used in :mod:`scipy.stats`
|
| 607 |
+
-----------------------------------------
|
| 608 |
+
|
| 609 |
+
.. warning::
|
| 610 |
+
|
| 611 |
+
These classes are private, but they are included here because instances
|
| 612 |
+
of them are returned by other statistical functions. User import and
|
| 613 |
+
instantiation is not supported.
|
| 614 |
+
|
| 615 |
+
.. toctree::
|
| 616 |
+
:maxdepth: 2
|
| 617 |
+
|
| 618 |
+
stats._result_classes
|
| 619 |
+
|
| 620 |
+
""" # noqa: E501
|
| 621 |
+
|
| 622 |
+
from ._warnings_errors import (ConstantInputWarning, NearConstantInputWarning,
|
| 623 |
+
DegenerateDataWarning, FitError)
|
| 624 |
+
from ._stats_py import *
|
| 625 |
+
from ._variation import variation
|
| 626 |
+
from .distributions import *
|
| 627 |
+
from ._morestats import *
|
| 628 |
+
from ._multicomp import *
|
| 629 |
+
from ._binomtest import binomtest
|
| 630 |
+
from ._binned_statistic import *
|
| 631 |
+
from ._kde import gaussian_kde
|
| 632 |
+
from . import mstats
|
| 633 |
+
from . import qmc
|
| 634 |
+
from ._multivariate import *
|
| 635 |
+
from . import contingency
|
| 636 |
+
from .contingency import chi2_contingency
|
| 637 |
+
from ._censored_data import CensoredData
|
| 638 |
+
from ._resampling import (bootstrap, monte_carlo_test, permutation_test, power,
|
| 639 |
+
MonteCarloMethod, PermutationMethod, BootstrapMethod)
|
| 640 |
+
from ._entropy import *
|
| 641 |
+
from ._hypotests import *
|
| 642 |
+
from ._page_trend_test import page_trend_test
|
| 643 |
+
from ._mannwhitneyu import mannwhitneyu
|
| 644 |
+
from ._bws_test import bws_test
|
| 645 |
+
from ._fit import fit, goodness_of_fit
|
| 646 |
+
from ._covariance import Covariance
|
| 647 |
+
from ._sensitivity_analysis import *
|
| 648 |
+
from ._survival import *
|
| 649 |
+
from ._distribution_infrastructure import (
|
| 650 |
+
make_distribution, Mixture, order_statistic, truncate, exp, log, abs
|
| 651 |
+
)
|
| 652 |
+
from ._new_distributions import Normal, Uniform
|
| 653 |
+
from ._mgc import multiscale_graphcorr
|
| 654 |
+
from ._correlation import chatterjeexi
|
| 655 |
+
|
| 656 |
+
|
| 657 |
+
# Deprecated namespaces, to be removed in v2.0.0
|
| 658 |
+
from . import (
|
| 659 |
+
biasedurn, kde, morestats, mstats_basic, mstats_extras, mvn, stats
|
| 660 |
+
)
|
| 661 |
+
|
| 662 |
+
|
| 663 |
+
__all__ = [s for s in dir() if not s.startswith("_")] # Remove dunders.
|
| 664 |
+
|
| 665 |
+
from scipy._lib._testutils import PytestTester
|
| 666 |
+
test = PytestTester(__name__)
|
| 667 |
+
del PytestTester
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/stats/_axis_nan_policy.py
ADDED
|
@@ -0,0 +1,699 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Many scipy.stats functions support `axis` and `nan_policy` parameters.
|
| 2 |
+
# When the two are combined, it can be tricky to get all the behavior just
|
| 3 |
+
# right. This file contains utility functions useful for scipy.stats functions
|
| 4 |
+
# that support `axis` and `nan_policy`, including a decorator that
|
| 5 |
+
# automatically adds `axis` and `nan_policy` arguments to a function.
|
| 6 |
+
|
| 7 |
+
import warnings
|
| 8 |
+
import numpy as np
|
| 9 |
+
from functools import wraps
|
| 10 |
+
from scipy._lib._docscrape import FunctionDoc, Parameter
|
| 11 |
+
from scipy._lib._util import _contains_nan, AxisError, _get_nan
|
| 12 |
+
from scipy._lib._array_api import array_namespace, is_numpy
|
| 13 |
+
|
| 14 |
+
import inspect
|
| 15 |
+
|
| 16 |
+
too_small_1d_not_omit = (
|
| 17 |
+
"One or more sample arguments is too small; all "
|
| 18 |
+
"returned values will be NaN. "
|
| 19 |
+
"See documentation for sample size requirements.")
|
| 20 |
+
|
| 21 |
+
too_small_1d_omit = (
|
| 22 |
+
"After omitting NaNs, one or more sample arguments "
|
| 23 |
+
"is too small; all returned values will be NaN. "
|
| 24 |
+
"See documentation for sample size requirements.")
|
| 25 |
+
|
| 26 |
+
too_small_nd_not_omit = (
|
| 27 |
+
"All axis-slices of one or more sample arguments are "
|
| 28 |
+
"too small; all elements of returned arrays will be NaN. "
|
| 29 |
+
"See documentation for sample size requirements.")
|
| 30 |
+
|
| 31 |
+
too_small_nd_omit = (
|
| 32 |
+
"After omitting NaNs, one or more axis-slices of one "
|
| 33 |
+
"or more sample arguments is too small; corresponding "
|
| 34 |
+
"elements of returned arrays will be NaN. "
|
| 35 |
+
"See documentation for sample size requirements.")
|
| 36 |
+
|
| 37 |
+
class SmallSampleWarning(RuntimeWarning):
|
| 38 |
+
pass
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def _broadcast_arrays(arrays, axis=None, xp=None):
|
| 42 |
+
"""
|
| 43 |
+
Broadcast shapes of arrays, ignoring incompatibility of specified axes
|
| 44 |
+
"""
|
| 45 |
+
if not arrays:
|
| 46 |
+
return arrays
|
| 47 |
+
xp = array_namespace(*arrays) if xp is None else xp
|
| 48 |
+
arrays = [xp.asarray(arr) for arr in arrays]
|
| 49 |
+
shapes = [arr.shape for arr in arrays]
|
| 50 |
+
new_shapes = _broadcast_shapes(shapes, axis)
|
| 51 |
+
if axis is None:
|
| 52 |
+
new_shapes = [new_shapes]*len(arrays)
|
| 53 |
+
return [xp.broadcast_to(array, new_shape)
|
| 54 |
+
for array, new_shape in zip(arrays, new_shapes)]
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def _broadcast_shapes(shapes, axis=None):
|
| 58 |
+
"""
|
| 59 |
+
Broadcast shapes, ignoring incompatibility of specified axes
|
| 60 |
+
"""
|
| 61 |
+
if not shapes:
|
| 62 |
+
return shapes
|
| 63 |
+
|
| 64 |
+
# input validation
|
| 65 |
+
if axis is not None:
|
| 66 |
+
axis = np.atleast_1d(axis)
|
| 67 |
+
message = '`axis` must be an integer, a tuple of integers, or `None`.'
|
| 68 |
+
try:
|
| 69 |
+
with np.errstate(invalid='ignore'):
|
| 70 |
+
axis_int = axis.astype(int)
|
| 71 |
+
except ValueError as e:
|
| 72 |
+
raise AxisError(message) from e
|
| 73 |
+
if not np.array_equal(axis_int, axis):
|
| 74 |
+
raise AxisError(message)
|
| 75 |
+
axis = axis_int
|
| 76 |
+
|
| 77 |
+
# First, ensure all shapes have same number of dimensions by prepending 1s.
|
| 78 |
+
n_dims = max([len(shape) for shape in shapes])
|
| 79 |
+
new_shapes = np.ones((len(shapes), n_dims), dtype=int)
|
| 80 |
+
for row, shape in zip(new_shapes, shapes):
|
| 81 |
+
row[len(row)-len(shape):] = shape # can't use negative indices (-0:)
|
| 82 |
+
|
| 83 |
+
# Remove the shape elements of the axes to be ignored, but remember them.
|
| 84 |
+
if axis is not None:
|
| 85 |
+
axis[axis < 0] = n_dims + axis[axis < 0]
|
| 86 |
+
axis = np.sort(axis)
|
| 87 |
+
if axis[-1] >= n_dims or axis[0] < 0:
|
| 88 |
+
message = (f"`axis` is out of bounds "
|
| 89 |
+
f"for array of dimension {n_dims}")
|
| 90 |
+
raise AxisError(message)
|
| 91 |
+
|
| 92 |
+
if len(np.unique(axis)) != len(axis):
|
| 93 |
+
raise AxisError("`axis` must contain only distinct elements")
|
| 94 |
+
|
| 95 |
+
removed_shapes = new_shapes[:, axis]
|
| 96 |
+
new_shapes = np.delete(new_shapes, axis, axis=1)
|
| 97 |
+
|
| 98 |
+
# If arrays are broadcastable, shape elements that are 1 may be replaced
|
| 99 |
+
# with a corresponding non-1 shape element. Assuming arrays are
|
| 100 |
+
# broadcastable, that final shape element can be found with:
|
| 101 |
+
new_shape = np.max(new_shapes, axis=0)
|
| 102 |
+
# except in case of an empty array:
|
| 103 |
+
new_shape *= new_shapes.all(axis=0)
|
| 104 |
+
|
| 105 |
+
# Among all arrays, there can only be one unique non-1 shape element.
|
| 106 |
+
# Therefore, if any non-1 shape element does not match what we found
|
| 107 |
+
# above, the arrays must not be broadcastable after all.
|
| 108 |
+
if np.any(~((new_shapes == 1) | (new_shapes == new_shape))):
|
| 109 |
+
raise ValueError("Array shapes are incompatible for broadcasting.")
|
| 110 |
+
|
| 111 |
+
if axis is not None:
|
| 112 |
+
# Add back the shape elements that were ignored
|
| 113 |
+
new_axis = axis - np.arange(len(axis))
|
| 114 |
+
new_shapes = [tuple(np.insert(new_shape, new_axis, removed_shape))
|
| 115 |
+
for removed_shape in removed_shapes]
|
| 116 |
+
return new_shapes
|
| 117 |
+
else:
|
| 118 |
+
return tuple(new_shape)
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
def _broadcast_array_shapes_remove_axis(arrays, axis=None):
|
| 122 |
+
"""
|
| 123 |
+
Broadcast shapes of arrays, dropping specified axes
|
| 124 |
+
|
| 125 |
+
Given a sequence of arrays `arrays` and an integer or tuple `axis`, find
|
| 126 |
+
the shape of the broadcast result after consuming/dropping `axis`.
|
| 127 |
+
In other words, return output shape of a typical hypothesis test on
|
| 128 |
+
`arrays` vectorized along `axis`.
|
| 129 |
+
|
| 130 |
+
Examples
|
| 131 |
+
--------
|
| 132 |
+
>>> import numpy as np
|
| 133 |
+
>>> from scipy.stats._axis_nan_policy import _broadcast_array_shapes_remove_axis
|
| 134 |
+
>>> a = np.zeros((5, 2, 1))
|
| 135 |
+
>>> b = np.zeros((9, 3))
|
| 136 |
+
>>> _broadcast_array_shapes_remove_axis((a, b), 1)
|
| 137 |
+
(5, 3)
|
| 138 |
+
"""
|
| 139 |
+
# Note that here, `axis=None` means do not consume/drop any axes - _not_
|
| 140 |
+
# ravel arrays before broadcasting.
|
| 141 |
+
shapes = [arr.shape for arr in arrays]
|
| 142 |
+
return _broadcast_shapes_remove_axis(shapes, axis)
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
def _broadcast_shapes_remove_axis(shapes, axis=None):
|
| 146 |
+
"""
|
| 147 |
+
Broadcast shapes, dropping specified axes
|
| 148 |
+
|
| 149 |
+
Same as _broadcast_array_shapes_remove_axis, but given a sequence
|
| 150 |
+
of array shapes `shapes` instead of the arrays themselves.
|
| 151 |
+
"""
|
| 152 |
+
shapes = _broadcast_shapes(shapes, axis)
|
| 153 |
+
shape = shapes[0]
|
| 154 |
+
if axis is not None:
|
| 155 |
+
shape = np.delete(shape, axis)
|
| 156 |
+
return tuple(shape)
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
def _broadcast_concatenate(arrays, axis, paired=False):
|
| 160 |
+
"""Concatenate arrays along an axis with broadcasting."""
|
| 161 |
+
arrays = _broadcast_arrays(arrays, axis if not paired else None)
|
| 162 |
+
res = np.concatenate(arrays, axis=axis)
|
| 163 |
+
return res
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
# TODO: add support for `axis` tuples
|
| 167 |
+
def _remove_nans(samples, paired):
|
| 168 |
+
"Remove nans from paired or unpaired 1D samples"
|
| 169 |
+
# potential optimization: don't copy arrays that don't contain nans
|
| 170 |
+
if not paired:
|
| 171 |
+
return [sample[~np.isnan(sample)] for sample in samples]
|
| 172 |
+
|
| 173 |
+
# for paired samples, we need to remove the whole pair when any part
|
| 174 |
+
# has a nan
|
| 175 |
+
nans = np.isnan(samples[0])
|
| 176 |
+
for sample in samples[1:]:
|
| 177 |
+
nans = nans | np.isnan(sample)
|
| 178 |
+
not_nans = ~nans
|
| 179 |
+
return [sample[not_nans] for sample in samples]
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
def _remove_sentinel(samples, paired, sentinel):
|
| 183 |
+
"Remove sentinel values from paired or unpaired 1D samples"
|
| 184 |
+
# could consolidate with `_remove_nans`, but it's not quite as simple as
|
| 185 |
+
# passing `sentinel=np.nan` because `(np.nan == np.nan) is False`
|
| 186 |
+
|
| 187 |
+
# potential optimization: don't copy arrays that don't contain sentinel
|
| 188 |
+
if not paired:
|
| 189 |
+
return [sample[sample != sentinel] for sample in samples]
|
| 190 |
+
|
| 191 |
+
# for paired samples, we need to remove the whole pair when any part
|
| 192 |
+
# has a nan
|
| 193 |
+
sentinels = (samples[0] == sentinel)
|
| 194 |
+
for sample in samples[1:]:
|
| 195 |
+
sentinels = sentinels | (sample == sentinel)
|
| 196 |
+
not_sentinels = ~sentinels
|
| 197 |
+
return [sample[not_sentinels] for sample in samples]
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
def _masked_arrays_2_sentinel_arrays(samples):
|
| 201 |
+
# masked arrays in `samples` are converted to regular arrays, and values
|
| 202 |
+
# corresponding with masked elements are replaced with a sentinel value
|
| 203 |
+
|
| 204 |
+
# return without modifying arrays if none have a mask
|
| 205 |
+
has_mask = False
|
| 206 |
+
for sample in samples:
|
| 207 |
+
mask = getattr(sample, 'mask', False)
|
| 208 |
+
has_mask = has_mask or np.any(mask)
|
| 209 |
+
if not has_mask:
|
| 210 |
+
return samples, None # None means there is no sentinel value
|
| 211 |
+
|
| 212 |
+
# Choose a sentinel value. We can't use `np.nan`, because sentinel (masked)
|
| 213 |
+
# values are always omitted, but there are different nan policies.
|
| 214 |
+
dtype = np.result_type(*samples)
|
| 215 |
+
dtype = dtype if np.issubdtype(dtype, np.number) else np.float64
|
| 216 |
+
for i in range(len(samples)):
|
| 217 |
+
# Things get more complicated if the arrays are of different types.
|
| 218 |
+
# We could have different sentinel values for each array, but
|
| 219 |
+
# the purpose of this code is convenience, not efficiency.
|
| 220 |
+
samples[i] = samples[i].astype(dtype, copy=False)
|
| 221 |
+
|
| 222 |
+
inexact = np.issubdtype(dtype, np.inexact)
|
| 223 |
+
info = np.finfo if inexact else np.iinfo
|
| 224 |
+
max_possible, min_possible = info(dtype).max, info(dtype).min
|
| 225 |
+
nextafter = np.nextafter if inexact else (lambda x, _: x - 1)
|
| 226 |
+
|
| 227 |
+
sentinel = max_possible
|
| 228 |
+
# For simplicity, min_possible/np.infs are not candidate sentinel values
|
| 229 |
+
while sentinel > min_possible:
|
| 230 |
+
for sample in samples:
|
| 231 |
+
if np.any(sample == sentinel): # choose a new sentinel value
|
| 232 |
+
sentinel = nextafter(sentinel, -np.inf)
|
| 233 |
+
break
|
| 234 |
+
else: # when sentinel value is OK, break the while loop
|
| 235 |
+
break
|
| 236 |
+
else:
|
| 237 |
+
message = ("This function replaces masked elements with sentinel "
|
| 238 |
+
"values, but the data contains all distinct values of this "
|
| 239 |
+
"data type. Consider promoting the dtype to `np.float64`.")
|
| 240 |
+
raise ValueError(message)
|
| 241 |
+
|
| 242 |
+
# replace masked elements with sentinel value
|
| 243 |
+
out_samples = []
|
| 244 |
+
for sample in samples:
|
| 245 |
+
mask = getattr(sample, 'mask', None)
|
| 246 |
+
if mask is not None: # turn all masked arrays into sentinel arrays
|
| 247 |
+
mask = np.broadcast_to(mask, sample.shape)
|
| 248 |
+
sample = sample.data.copy() if np.any(mask) else sample.data
|
| 249 |
+
sample = np.asarray(sample) # `sample.data` could be a memoryview?
|
| 250 |
+
sample[mask] = sentinel
|
| 251 |
+
out_samples.append(sample)
|
| 252 |
+
|
| 253 |
+
return out_samples, sentinel
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
def _check_empty_inputs(samples, axis):
|
| 257 |
+
"""
|
| 258 |
+
Check for empty sample; return appropriate output for a vectorized hypotest
|
| 259 |
+
"""
|
| 260 |
+
# if none of the samples are empty, we need to perform the test
|
| 261 |
+
if not any(sample.size == 0 for sample in samples):
|
| 262 |
+
return None
|
| 263 |
+
# otherwise, the statistic and p-value will be either empty arrays or
|
| 264 |
+
# arrays with NaNs. Produce the appropriate array and return it.
|
| 265 |
+
output_shape = _broadcast_array_shapes_remove_axis(samples, axis)
|
| 266 |
+
output = np.ones(output_shape) * _get_nan(*samples)
|
| 267 |
+
return output
|
| 268 |
+
|
| 269 |
+
|
| 270 |
+
def _add_reduced_axes(res, reduced_axes, keepdims):
|
| 271 |
+
"""
|
| 272 |
+
Add reduced axes back to all the arrays in the result object
|
| 273 |
+
if keepdims = True.
|
| 274 |
+
"""
|
| 275 |
+
return ([np.expand_dims(output, reduced_axes)
|
| 276 |
+
if not isinstance(output, int) else output for output in res]
|
| 277 |
+
if keepdims else res)
|
| 278 |
+
|
| 279 |
+
|
| 280 |
+
# Standard docstring / signature entries for `axis`, `nan_policy`, `keepdims`
|
| 281 |
+
_name = 'axis'
|
| 282 |
+
_desc = (
|
| 283 |
+
"""If an int, the axis of the input along which to compute the statistic.
|
| 284 |
+
The statistic of each axis-slice (e.g. row) of the input will appear in a
|
| 285 |
+
corresponding element of the output.
|
| 286 |
+
If ``None``, the input will be raveled before computing the statistic."""
|
| 287 |
+
.split('\n'))
|
| 288 |
+
|
| 289 |
+
|
| 290 |
+
def _get_axis_params(default_axis=0, _name=_name, _desc=_desc): # bind NOW
|
| 291 |
+
_type = f"int or None, default: {default_axis}"
|
| 292 |
+
_axis_parameter_doc = Parameter(_name, _type, _desc)
|
| 293 |
+
_axis_parameter = inspect.Parameter(_name,
|
| 294 |
+
inspect.Parameter.KEYWORD_ONLY,
|
| 295 |
+
default=default_axis)
|
| 296 |
+
return _axis_parameter_doc, _axis_parameter
|
| 297 |
+
|
| 298 |
+
|
| 299 |
+
_name = 'nan_policy'
|
| 300 |
+
_type = "{'propagate', 'omit', 'raise'}"
|
| 301 |
+
_desc = (
|
| 302 |
+
"""Defines how to handle input NaNs.
|
| 303 |
+
|
| 304 |
+
- ``propagate``: if a NaN is present in the axis slice (e.g. row) along
|
| 305 |
+
which the statistic is computed, the corresponding entry of the output
|
| 306 |
+
will be NaN.
|
| 307 |
+
- ``omit``: NaNs will be omitted when performing the calculation.
|
| 308 |
+
If insufficient data remains in the axis slice along which the
|
| 309 |
+
statistic is computed, the corresponding entry of the output will be
|
| 310 |
+
NaN.
|
| 311 |
+
- ``raise``: if a NaN is present, a ``ValueError`` will be raised."""
|
| 312 |
+
.split('\n'))
|
| 313 |
+
_nan_policy_parameter_doc = Parameter(_name, _type, _desc)
|
| 314 |
+
_nan_policy_parameter = inspect.Parameter(_name,
|
| 315 |
+
inspect.Parameter.KEYWORD_ONLY,
|
| 316 |
+
default='propagate')
|
| 317 |
+
|
| 318 |
+
_name = 'keepdims'
|
| 319 |
+
_type = "bool, default: False"
|
| 320 |
+
_desc = (
|
| 321 |
+
"""If this is set to True, the axes which are reduced are left
|
| 322 |
+
in the result as dimensions with size one. With this option,
|
| 323 |
+
the result will broadcast correctly against the input array."""
|
| 324 |
+
.split('\n'))
|
| 325 |
+
_keepdims_parameter_doc = Parameter(_name, _type, _desc)
|
| 326 |
+
_keepdims_parameter = inspect.Parameter(_name,
|
| 327 |
+
inspect.Parameter.KEYWORD_ONLY,
|
| 328 |
+
default=False)
|
| 329 |
+
|
| 330 |
+
_standard_note_addition = (
|
| 331 |
+
"""\nBeginning in SciPy 1.9, ``np.matrix`` inputs (not recommended for new
|
| 332 |
+
code) are converted to ``np.ndarray`` before the calculation is performed. In
|
| 333 |
+
this case, the output will be a scalar or ``np.ndarray`` of appropriate shape
|
| 334 |
+
rather than a 2D ``np.matrix``. Similarly, while masked elements of masked
|
| 335 |
+
arrays are ignored, the output will be a scalar or ``np.ndarray`` rather than a
|
| 336 |
+
masked array with ``mask=False``.""").split('\n')
|
| 337 |
+
|
| 338 |
+
|
| 339 |
+
def _axis_nan_policy_factory(tuple_to_result, default_axis=0,
|
| 340 |
+
n_samples=1, paired=False,
|
| 341 |
+
result_to_tuple=None, too_small=0,
|
| 342 |
+
n_outputs=2, kwd_samples=(), override=None):
|
| 343 |
+
"""Factory for a wrapper that adds axis/nan_policy params to a function.
|
| 344 |
+
|
| 345 |
+
Parameters
|
| 346 |
+
----------
|
| 347 |
+
tuple_to_result : callable
|
| 348 |
+
Callable that returns an object of the type returned by the function
|
| 349 |
+
being wrapped (e.g. the namedtuple or dataclass returned by a
|
| 350 |
+
statistical test) provided the separate components (e.g. statistic,
|
| 351 |
+
pvalue).
|
| 352 |
+
default_axis : int, default: 0
|
| 353 |
+
The default value of the axis argument. Standard is 0 except when
|
| 354 |
+
backwards compatibility demands otherwise (e.g. `None`).
|
| 355 |
+
n_samples : int or callable, default: 1
|
| 356 |
+
The number of data samples accepted by the function
|
| 357 |
+
(e.g. `mannwhitneyu`), a callable that accepts a dictionary of
|
| 358 |
+
parameters passed into the function and returns the number of data
|
| 359 |
+
samples (e.g. `wilcoxon`), or `None` to indicate an arbitrary number
|
| 360 |
+
of samples (e.g. `kruskal`).
|
| 361 |
+
paired : {False, True}
|
| 362 |
+
Whether the function being wrapped treats the samples as paired (i.e.
|
| 363 |
+
corresponding elements of each sample should be considered as different
|
| 364 |
+
components of the same sample.)
|
| 365 |
+
result_to_tuple : callable, optional
|
| 366 |
+
Function that unpacks the results of the function being wrapped into
|
| 367 |
+
a tuple. This is essentially the inverse of `tuple_to_result`. Default
|
| 368 |
+
is `None`, which is appropriate for statistical tests that return a
|
| 369 |
+
statistic, pvalue tuple (rather than, e.g., a non-iterable datalass).
|
| 370 |
+
too_small : int or callable, default: 0
|
| 371 |
+
The largest unnacceptably small sample for the function being wrapped.
|
| 372 |
+
For example, some functions require samples of size two or more or they
|
| 373 |
+
raise an error. This argument prevents the error from being raised when
|
| 374 |
+
input is not 1D and instead places a NaN in the corresponding element
|
| 375 |
+
of the result. If callable, it must accept a list of samples, axis,
|
| 376 |
+
and a dictionary of keyword arguments passed to the wrapper function as
|
| 377 |
+
arguments and return a bool indicating weather the samples passed are
|
| 378 |
+
too small.
|
| 379 |
+
n_outputs : int or callable, default: 2
|
| 380 |
+
The number of outputs produced by the function given 1d sample(s). For
|
| 381 |
+
example, hypothesis tests that return a namedtuple or result object
|
| 382 |
+
with attributes ``statistic`` and ``pvalue`` use the default
|
| 383 |
+
``n_outputs=2``; summary statistics with scalar output use
|
| 384 |
+
``n_outputs=1``. Alternatively, may be a callable that accepts a
|
| 385 |
+
dictionary of arguments passed into the wrapped function and returns
|
| 386 |
+
the number of outputs corresponding with those arguments.
|
| 387 |
+
kwd_samples : sequence, default: ()
|
| 388 |
+
The names of keyword parameters that should be treated as samples. For
|
| 389 |
+
example, `gmean` accepts as its first argument a sample `a` but
|
| 390 |
+
also `weights` as a fourth, optional keyword argument. In this case, we
|
| 391 |
+
use `n_samples=1` and kwd_samples=['weights'].
|
| 392 |
+
override : dict, default: {'vectorization': False, 'nan_propagation': True}
|
| 393 |
+
Pass a dictionary with ``'vectorization': True`` to ensure that the
|
| 394 |
+
decorator overrides the function's behavior for multimensional input.
|
| 395 |
+
Use ``'nan_propagation': False`` to ensure that the decorator does not
|
| 396 |
+
override the function's behavior for ``nan_policy='propagate'``.
|
| 397 |
+
"""
|
| 398 |
+
# Specify which existing behaviors the decorator must override
|
| 399 |
+
temp = override or {}
|
| 400 |
+
override = {'vectorization': False,
|
| 401 |
+
'nan_propagation': True}
|
| 402 |
+
override.update(temp)
|
| 403 |
+
|
| 404 |
+
if result_to_tuple is None:
|
| 405 |
+
def result_to_tuple(res):
|
| 406 |
+
return res
|
| 407 |
+
|
| 408 |
+
# The only `result_to_tuple` that needs the second argument (number of
|
| 409 |
+
# outputs) is the one for `moment`, and this was realized very late.
|
| 410 |
+
# Rather than changing all `result_to_tuple` definitions, we wrap them
|
| 411 |
+
# here to accept a second argument if they don't already.
|
| 412 |
+
if len(inspect.signature(result_to_tuple).parameters) == 1:
|
| 413 |
+
def result_to_tuple(res, _, f=result_to_tuple):
|
| 414 |
+
return f(res)
|
| 415 |
+
|
| 416 |
+
if not callable(too_small):
|
| 417 |
+
def is_too_small(samples, *ts_args, axis=-1, **ts_kwargs):
|
| 418 |
+
for sample in samples:
|
| 419 |
+
if sample.shape[axis] <= too_small:
|
| 420 |
+
return True
|
| 421 |
+
return False
|
| 422 |
+
else:
|
| 423 |
+
is_too_small = too_small
|
| 424 |
+
|
| 425 |
+
def axis_nan_policy_decorator(hypotest_fun_in):
|
| 426 |
+
@wraps(hypotest_fun_in)
|
| 427 |
+
def axis_nan_policy_wrapper(*args, _no_deco=False, **kwds):
|
| 428 |
+
|
| 429 |
+
if _no_deco: # for testing, decorator does nothing
|
| 430 |
+
return hypotest_fun_in(*args, **kwds)
|
| 431 |
+
|
| 432 |
+
# For now, skip the decorator entirely if using array API. In the future,
|
| 433 |
+
# we'll probably want to use it for `keepdims`, `axis` tuples, etc.
|
| 434 |
+
if len(args) == 0: # extract sample from `kwds` if there are no `args`
|
| 435 |
+
used_kwd_samples = list(set(kwds).intersection(set(kwd_samples)))
|
| 436 |
+
temp = used_kwd_samples[:1]
|
| 437 |
+
else:
|
| 438 |
+
temp = args[0]
|
| 439 |
+
|
| 440 |
+
if not is_numpy(array_namespace(temp)):
|
| 441 |
+
msg = ("Use of `nan_policy` and `keepdims` "
|
| 442 |
+
"is incompatible with non-NumPy arrays.")
|
| 443 |
+
if 'nan_policy' in kwds or 'keepdims' in kwds:
|
| 444 |
+
raise NotImplementedError(msg)
|
| 445 |
+
return hypotest_fun_in(*args, **kwds)
|
| 446 |
+
|
| 447 |
+
# We need to be flexible about whether position or keyword
|
| 448 |
+
# arguments are used, but we need to make sure users don't pass
|
| 449 |
+
# both for the same parameter. To complicate matters, some
|
| 450 |
+
# functions accept samples with *args, and some functions already
|
| 451 |
+
# accept `axis` and `nan_policy` as positional arguments.
|
| 452 |
+
# The strategy is to make sure that there is no duplication
|
| 453 |
+
# between `args` and `kwds`, combine the two into `kwds`, then
|
| 454 |
+
# the samples, `nan_policy`, and `axis` from `kwds`, as they are
|
| 455 |
+
# dealt with separately.
|
| 456 |
+
|
| 457 |
+
# Check for intersection between positional and keyword args
|
| 458 |
+
params = list(inspect.signature(hypotest_fun_in).parameters)
|
| 459 |
+
if n_samples is None:
|
| 460 |
+
# Give unique names to each positional sample argument
|
| 461 |
+
# Note that *args can't be provided as a keyword argument
|
| 462 |
+
params = [f"arg{i}" for i in range(len(args))] + params[1:]
|
| 463 |
+
|
| 464 |
+
# raise if there are too many positional args
|
| 465 |
+
maxarg = (np.inf if inspect.getfullargspec(hypotest_fun_in).varargs
|
| 466 |
+
else len(inspect.getfullargspec(hypotest_fun_in).args))
|
| 467 |
+
if len(args) > maxarg: # let the function raise the right error
|
| 468 |
+
hypotest_fun_in(*args, **kwds)
|
| 469 |
+
|
| 470 |
+
# raise if multiple values passed for same parameter
|
| 471 |
+
d_args = dict(zip(params, args))
|
| 472 |
+
intersection = set(d_args) & set(kwds)
|
| 473 |
+
if intersection: # let the function raise the right error
|
| 474 |
+
hypotest_fun_in(*args, **kwds)
|
| 475 |
+
|
| 476 |
+
# Consolidate other positional and keyword args into `kwds`
|
| 477 |
+
kwds.update(d_args)
|
| 478 |
+
|
| 479 |
+
# rename avoids UnboundLocalError
|
| 480 |
+
if callable(n_samples):
|
| 481 |
+
# Future refactoring idea: no need for callable n_samples.
|
| 482 |
+
# Just replace `n_samples` and `kwd_samples` with a single
|
| 483 |
+
# list of the names of all samples, and treat all of them
|
| 484 |
+
# as `kwd_samples` are treated below.
|
| 485 |
+
n_samp = n_samples(kwds)
|
| 486 |
+
else:
|
| 487 |
+
n_samp = n_samples or len(args)
|
| 488 |
+
|
| 489 |
+
# get the number of outputs
|
| 490 |
+
n_out = n_outputs # rename to avoid UnboundLocalError
|
| 491 |
+
if callable(n_out):
|
| 492 |
+
n_out = n_out(kwds)
|
| 493 |
+
|
| 494 |
+
# If necessary, rearrange function signature: accept other samples
|
| 495 |
+
# as positional args right after the first n_samp args
|
| 496 |
+
kwd_samp = [name for name in kwd_samples
|
| 497 |
+
if kwds.get(name, None) is not None]
|
| 498 |
+
n_kwd_samp = len(kwd_samp)
|
| 499 |
+
if not kwd_samp:
|
| 500 |
+
hypotest_fun_out = hypotest_fun_in
|
| 501 |
+
else:
|
| 502 |
+
def hypotest_fun_out(*samples, **kwds):
|
| 503 |
+
new_kwds = dict(zip(kwd_samp, samples[n_samp:]))
|
| 504 |
+
kwds.update(new_kwds)
|
| 505 |
+
return hypotest_fun_in(*samples[:n_samp], **kwds)
|
| 506 |
+
|
| 507 |
+
# Extract the things we need here
|
| 508 |
+
try: # if something is missing
|
| 509 |
+
samples = [np.atleast_1d(kwds.pop(param))
|
| 510 |
+
for param in (params[:n_samp] + kwd_samp)]
|
| 511 |
+
except KeyError: # let the function raise the right error
|
| 512 |
+
# might need to revisit this if required arg is not a "sample"
|
| 513 |
+
hypotest_fun_in(*args, **kwds)
|
| 514 |
+
vectorized = True if 'axis' in params else False
|
| 515 |
+
vectorized = vectorized and not override['vectorization']
|
| 516 |
+
axis = kwds.pop('axis', default_axis)
|
| 517 |
+
nan_policy = kwds.pop('nan_policy', 'propagate')
|
| 518 |
+
keepdims = kwds.pop("keepdims", False)
|
| 519 |
+
del args # avoid the possibility of passing both `args` and `kwds`
|
| 520 |
+
|
| 521 |
+
# convert masked arrays to regular arrays with sentinel values
|
| 522 |
+
samples, sentinel = _masked_arrays_2_sentinel_arrays(samples)
|
| 523 |
+
|
| 524 |
+
# standardize to always work along last axis
|
| 525 |
+
reduced_axes = axis
|
| 526 |
+
if axis is None:
|
| 527 |
+
if samples:
|
| 528 |
+
# when axis=None, take the maximum of all dimensions since
|
| 529 |
+
# all the dimensions are reduced.
|
| 530 |
+
n_dims = np.max([sample.ndim for sample in samples])
|
| 531 |
+
reduced_axes = tuple(range(n_dims))
|
| 532 |
+
samples = [np.asarray(sample.ravel()) for sample in samples]
|
| 533 |
+
else:
|
| 534 |
+
# don't ignore any axes when broadcasting if paired
|
| 535 |
+
samples = _broadcast_arrays(samples, axis=axis if not paired else None)
|
| 536 |
+
axis = np.atleast_1d(axis)
|
| 537 |
+
n_axes = len(axis)
|
| 538 |
+
# move all axes in `axis` to the end to be raveled
|
| 539 |
+
samples = [np.moveaxis(sample, axis, range(-len(axis), 0))
|
| 540 |
+
for sample in samples]
|
| 541 |
+
shapes = [sample.shape for sample in samples]
|
| 542 |
+
# New shape is unchanged for all axes _not_ in `axis`
|
| 543 |
+
# At the end, we append the product of the shapes of the axes
|
| 544 |
+
# in `axis`. Appending -1 doesn't work for zero-size arrays!
|
| 545 |
+
new_shapes = [shape[:-n_axes] + (np.prod(shape[-n_axes:]),)
|
| 546 |
+
for shape in shapes]
|
| 547 |
+
samples = [sample.reshape(new_shape)
|
| 548 |
+
for sample, new_shape in zip(samples, new_shapes)]
|
| 549 |
+
axis = -1 # work over the last axis
|
| 550 |
+
NaN = _get_nan(*samples) if samples else np.nan
|
| 551 |
+
|
| 552 |
+
# if axis is not needed, just handle nan_policy and return
|
| 553 |
+
ndims = np.array([sample.ndim for sample in samples])
|
| 554 |
+
if np.all(ndims <= 1):
|
| 555 |
+
# Addresses nan_policy == "raise"
|
| 556 |
+
if nan_policy != 'propagate' or override['nan_propagation']:
|
| 557 |
+
contains_nan = [_contains_nan(sample, nan_policy)[0]
|
| 558 |
+
for sample in samples]
|
| 559 |
+
else:
|
| 560 |
+
# Behave as though there are no NaNs (even if there are)
|
| 561 |
+
contains_nan = [False]*len(samples)
|
| 562 |
+
|
| 563 |
+
# Addresses nan_policy == "propagate"
|
| 564 |
+
if any(contains_nan) and (nan_policy == 'propagate'
|
| 565 |
+
and override['nan_propagation']):
|
| 566 |
+
res = np.full(n_out, NaN)
|
| 567 |
+
res = _add_reduced_axes(res, reduced_axes, keepdims)
|
| 568 |
+
return tuple_to_result(*res)
|
| 569 |
+
|
| 570 |
+
# Addresses nan_policy == "omit"
|
| 571 |
+
too_small_msg = too_small_1d_not_omit
|
| 572 |
+
if any(contains_nan) and nan_policy == 'omit':
|
| 573 |
+
# consider passing in contains_nan
|
| 574 |
+
samples = _remove_nans(samples, paired)
|
| 575 |
+
too_small_msg = too_small_1d_omit
|
| 576 |
+
|
| 577 |
+
if sentinel:
|
| 578 |
+
samples = _remove_sentinel(samples, paired, sentinel)
|
| 579 |
+
|
| 580 |
+
if is_too_small(samples, kwds):
|
| 581 |
+
warnings.warn(too_small_msg, SmallSampleWarning, stacklevel=2)
|
| 582 |
+
res = np.full(n_out, NaN)
|
| 583 |
+
res = _add_reduced_axes(res, reduced_axes, keepdims)
|
| 584 |
+
return tuple_to_result(*res)
|
| 585 |
+
|
| 586 |
+
res = hypotest_fun_out(*samples, **kwds)
|
| 587 |
+
res = result_to_tuple(res, n_out)
|
| 588 |
+
res = _add_reduced_axes(res, reduced_axes, keepdims)
|
| 589 |
+
return tuple_to_result(*res)
|
| 590 |
+
|
| 591 |
+
# check for empty input
|
| 592 |
+
empty_output = _check_empty_inputs(samples, axis)
|
| 593 |
+
# only return empty output if zero sized input is too small.
|
| 594 |
+
if (
|
| 595 |
+
empty_output is not None
|
| 596 |
+
and (is_too_small(samples, kwds) or empty_output.size == 0)
|
| 597 |
+
):
|
| 598 |
+
if is_too_small(samples, kwds) and empty_output.size != 0:
|
| 599 |
+
warnings.warn(too_small_nd_not_omit, SmallSampleWarning,
|
| 600 |
+
stacklevel=2)
|
| 601 |
+
res = [empty_output.copy() for i in range(n_out)]
|
| 602 |
+
res = _add_reduced_axes(res, reduced_axes, keepdims)
|
| 603 |
+
return tuple_to_result(*res)
|
| 604 |
+
|
| 605 |
+
# otherwise, concatenate all samples along axis, remembering where
|
| 606 |
+
# each separate sample begins
|
| 607 |
+
lengths = np.array([sample.shape[axis] for sample in samples])
|
| 608 |
+
split_indices = np.cumsum(lengths)
|
| 609 |
+
x = _broadcast_concatenate(samples, axis, paired=paired)
|
| 610 |
+
|
| 611 |
+
# Addresses nan_policy == "raise"
|
| 612 |
+
if nan_policy != 'propagate' or override['nan_propagation']:
|
| 613 |
+
contains_nan, _ = _contains_nan(x, nan_policy)
|
| 614 |
+
else:
|
| 615 |
+
contains_nan = False # behave like there are no NaNs
|
| 616 |
+
|
| 617 |
+
if vectorized and not contains_nan and not sentinel:
|
| 618 |
+
res = hypotest_fun_out(*samples, axis=axis, **kwds)
|
| 619 |
+
res = result_to_tuple(res, n_out)
|
| 620 |
+
res = _add_reduced_axes(res, reduced_axes, keepdims)
|
| 621 |
+
return tuple_to_result(*res)
|
| 622 |
+
|
| 623 |
+
# Addresses nan_policy == "omit"
|
| 624 |
+
if contains_nan and nan_policy == 'omit':
|
| 625 |
+
def hypotest_fun(x):
|
| 626 |
+
samples = np.split(x, split_indices)[:n_samp+n_kwd_samp]
|
| 627 |
+
samples = _remove_nans(samples, paired)
|
| 628 |
+
if sentinel:
|
| 629 |
+
samples = _remove_sentinel(samples, paired, sentinel)
|
| 630 |
+
if is_too_small(samples, kwds):
|
| 631 |
+
warnings.warn(too_small_nd_omit, SmallSampleWarning,
|
| 632 |
+
stacklevel=4)
|
| 633 |
+
return np.full(n_out, NaN)
|
| 634 |
+
return result_to_tuple(hypotest_fun_out(*samples, **kwds), n_out)
|
| 635 |
+
|
| 636 |
+
# Addresses nan_policy == "propagate"
|
| 637 |
+
elif (contains_nan and nan_policy == 'propagate'
|
| 638 |
+
and override['nan_propagation']):
|
| 639 |
+
def hypotest_fun(x):
|
| 640 |
+
if np.isnan(x).any():
|
| 641 |
+
return np.full(n_out, NaN)
|
| 642 |
+
|
| 643 |
+
samples = np.split(x, split_indices)[:n_samp+n_kwd_samp]
|
| 644 |
+
if sentinel:
|
| 645 |
+
samples = _remove_sentinel(samples, paired, sentinel)
|
| 646 |
+
if is_too_small(samples, kwds):
|
| 647 |
+
return np.full(n_out, NaN)
|
| 648 |
+
return result_to_tuple(hypotest_fun_out(*samples, **kwds), n_out)
|
| 649 |
+
|
| 650 |
+
else:
|
| 651 |
+
def hypotest_fun(x):
|
| 652 |
+
samples = np.split(x, split_indices)[:n_samp+n_kwd_samp]
|
| 653 |
+
if sentinel:
|
| 654 |
+
samples = _remove_sentinel(samples, paired, sentinel)
|
| 655 |
+
if is_too_small(samples, kwds):
|
| 656 |
+
return np.full(n_out, NaN)
|
| 657 |
+
return result_to_tuple(hypotest_fun_out(*samples, **kwds), n_out)
|
| 658 |
+
|
| 659 |
+
x = np.moveaxis(x, axis, 0)
|
| 660 |
+
res = np.apply_along_axis(hypotest_fun, axis=0, arr=x)
|
| 661 |
+
res = _add_reduced_axes(res, reduced_axes, keepdims)
|
| 662 |
+
return tuple_to_result(*res)
|
| 663 |
+
|
| 664 |
+
_axis_parameter_doc, _axis_parameter = _get_axis_params(default_axis)
|
| 665 |
+
doc = FunctionDoc(axis_nan_policy_wrapper)
|
| 666 |
+
parameter_names = [param.name for param in doc['Parameters']]
|
| 667 |
+
if 'axis' in parameter_names:
|
| 668 |
+
doc['Parameters'][parameter_names.index('axis')] = (
|
| 669 |
+
_axis_parameter_doc)
|
| 670 |
+
else:
|
| 671 |
+
doc['Parameters'].append(_axis_parameter_doc)
|
| 672 |
+
if 'nan_policy' in parameter_names:
|
| 673 |
+
doc['Parameters'][parameter_names.index('nan_policy')] = (
|
| 674 |
+
_nan_policy_parameter_doc)
|
| 675 |
+
else:
|
| 676 |
+
doc['Parameters'].append(_nan_policy_parameter_doc)
|
| 677 |
+
if 'keepdims' in parameter_names:
|
| 678 |
+
doc['Parameters'][parameter_names.index('keepdims')] = (
|
| 679 |
+
_keepdims_parameter_doc)
|
| 680 |
+
else:
|
| 681 |
+
doc['Parameters'].append(_keepdims_parameter_doc)
|
| 682 |
+
doc['Notes'] += _standard_note_addition
|
| 683 |
+
doc = str(doc).split("\n", 1)[1] # remove signature
|
| 684 |
+
axis_nan_policy_wrapper.__doc__ = str(doc)
|
| 685 |
+
|
| 686 |
+
sig = inspect.signature(axis_nan_policy_wrapper)
|
| 687 |
+
parameters = sig.parameters
|
| 688 |
+
parameter_list = list(parameters.values())
|
| 689 |
+
if 'axis' not in parameters:
|
| 690 |
+
parameter_list.append(_axis_parameter)
|
| 691 |
+
if 'nan_policy' not in parameters:
|
| 692 |
+
parameter_list.append(_nan_policy_parameter)
|
| 693 |
+
if 'keepdims' not in parameters:
|
| 694 |
+
parameter_list.append(_keepdims_parameter)
|
| 695 |
+
sig = sig.replace(parameters=parameter_list)
|
| 696 |
+
axis_nan_policy_wrapper.__signature__ = sig
|
| 697 |
+
|
| 698 |
+
return axis_nan_policy_wrapper
|
| 699 |
+
return axis_nan_policy_decorator
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/stats/_biasedurn.pxd
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Declare the class with cdef
|
| 2 |
+
cdef extern from "biasedurn/stocc.h" nogil:
|
| 3 |
+
cdef cppclass CFishersNCHypergeometric:
|
| 4 |
+
CFishersNCHypergeometric(int, int, int, double, double) except +
|
| 5 |
+
int mode()
|
| 6 |
+
double mean()
|
| 7 |
+
double variance()
|
| 8 |
+
double probability(int x)
|
| 9 |
+
double moments(double * mean, double * var)
|
| 10 |
+
|
| 11 |
+
cdef cppclass CWalleniusNCHypergeometric:
|
| 12 |
+
CWalleniusNCHypergeometric() except +
|
| 13 |
+
CWalleniusNCHypergeometric(int, int, int, double, double) except +
|
| 14 |
+
int mode()
|
| 15 |
+
double mean()
|
| 16 |
+
double variance()
|
| 17 |
+
double probability(int x)
|
| 18 |
+
double moments(double * mean, double * var)
|
| 19 |
+
|
| 20 |
+
cdef cppclass StochasticLib3:
|
| 21 |
+
StochasticLib3(int seed) except +
|
| 22 |
+
double Random() except +
|
| 23 |
+
void SetAccuracy(double accur)
|
| 24 |
+
int FishersNCHyp (int n, int m, int N, double odds) except +
|
| 25 |
+
int WalleniusNCHyp (int n, int m, int N, double odds) except +
|
| 26 |
+
double(*next_double)()
|
| 27 |
+
double(*next_normal)(const double m, const double s)
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/stats/_binned_statistic.py
ADDED
|
@@ -0,0 +1,795 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import builtins
|
| 2 |
+
from warnings import catch_warnings, simplefilter
|
| 3 |
+
import numpy as np
|
| 4 |
+
from operator import index
|
| 5 |
+
from collections import namedtuple
|
| 6 |
+
|
| 7 |
+
__all__ = ['binned_statistic',
|
| 8 |
+
'binned_statistic_2d',
|
| 9 |
+
'binned_statistic_dd']
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
BinnedStatisticResult = namedtuple('BinnedStatisticResult',
|
| 13 |
+
('statistic', 'bin_edges', 'binnumber'))
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def binned_statistic(x, values, statistic='mean',
|
| 17 |
+
bins=10, range=None):
|
| 18 |
+
"""
|
| 19 |
+
Compute a binned statistic for one or more sets of data.
|
| 20 |
+
|
| 21 |
+
This is a generalization of a histogram function. A histogram divides
|
| 22 |
+
the space into bins, and returns the count of the number of points in
|
| 23 |
+
each bin. This function allows the computation of the sum, mean, median,
|
| 24 |
+
or other statistic of the values (or set of values) within each bin.
|
| 25 |
+
|
| 26 |
+
Parameters
|
| 27 |
+
----------
|
| 28 |
+
x : (N,) array_like
|
| 29 |
+
A sequence of values to be binned.
|
| 30 |
+
values : (N,) array_like or list of (N,) array_like
|
| 31 |
+
The data on which the statistic will be computed. This must be
|
| 32 |
+
the same shape as `x`, or a set of sequences - each the same shape as
|
| 33 |
+
`x`. If `values` is a set of sequences, the statistic will be computed
|
| 34 |
+
on each independently.
|
| 35 |
+
statistic : string or callable, optional
|
| 36 |
+
The statistic to compute (default is 'mean').
|
| 37 |
+
The following statistics are available:
|
| 38 |
+
|
| 39 |
+
* 'mean' : compute the mean of values for points within each bin.
|
| 40 |
+
Empty bins will be represented by NaN.
|
| 41 |
+
* 'std' : compute the standard deviation within each bin. This
|
| 42 |
+
is implicitly calculated with ddof=0.
|
| 43 |
+
* 'median' : compute the median of values for points within each
|
| 44 |
+
bin. Empty bins will be represented by NaN.
|
| 45 |
+
* 'count' : compute the count of points within each bin. This is
|
| 46 |
+
identical to an unweighted histogram. `values` array is not
|
| 47 |
+
referenced.
|
| 48 |
+
* 'sum' : compute the sum of values for points within each bin.
|
| 49 |
+
This is identical to a weighted histogram.
|
| 50 |
+
* 'min' : compute the minimum of values for points within each bin.
|
| 51 |
+
Empty bins will be represented by NaN.
|
| 52 |
+
* 'max' : compute the maximum of values for point within each bin.
|
| 53 |
+
Empty bins will be represented by NaN.
|
| 54 |
+
* function : a user-defined function which takes a 1D array of
|
| 55 |
+
values, and outputs a single numerical statistic. This function
|
| 56 |
+
will be called on the values in each bin. Empty bins will be
|
| 57 |
+
represented by function([]), or NaN if this returns an error.
|
| 58 |
+
|
| 59 |
+
bins : int or sequence of scalars, optional
|
| 60 |
+
If `bins` is an int, it defines the number of equal-width bins in the
|
| 61 |
+
given range (10 by default). If `bins` is a sequence, it defines the
|
| 62 |
+
bin edges, including the rightmost edge, allowing for non-uniform bin
|
| 63 |
+
widths. Values in `x` that are smaller than lowest bin edge are
|
| 64 |
+
assigned to bin number 0, values beyond the highest bin are assigned to
|
| 65 |
+
``bins[-1]``. If the bin edges are specified, the number of bins will
|
| 66 |
+
be, (nx = len(bins)-1).
|
| 67 |
+
range : (float, float) or [(float, float)], optional
|
| 68 |
+
The lower and upper range of the bins. If not provided, range
|
| 69 |
+
is simply ``(x.min(), x.max())``. Values outside the range are
|
| 70 |
+
ignored.
|
| 71 |
+
|
| 72 |
+
Returns
|
| 73 |
+
-------
|
| 74 |
+
statistic : array
|
| 75 |
+
The values of the selected statistic in each bin.
|
| 76 |
+
bin_edges : array of dtype float
|
| 77 |
+
Return the bin edges ``(length(statistic)+1)``.
|
| 78 |
+
binnumber: 1-D ndarray of ints
|
| 79 |
+
Indices of the bins (corresponding to `bin_edges`) in which each value
|
| 80 |
+
of `x` belongs. Same length as `values`. A binnumber of `i` means the
|
| 81 |
+
corresponding value is between (bin_edges[i-1], bin_edges[i]).
|
| 82 |
+
|
| 83 |
+
See Also
|
| 84 |
+
--------
|
| 85 |
+
numpy.digitize, numpy.histogram, binned_statistic_2d, binned_statistic_dd
|
| 86 |
+
|
| 87 |
+
Notes
|
| 88 |
+
-----
|
| 89 |
+
All but the last (righthand-most) bin is half-open. In other words, if
|
| 90 |
+
`bins` is ``[1, 2, 3, 4]``, then the first bin is ``[1, 2)`` (including 1,
|
| 91 |
+
but excluding 2) and the second ``[2, 3)``. The last bin, however, is
|
| 92 |
+
``[3, 4]``, which *includes* 4.
|
| 93 |
+
|
| 94 |
+
.. versionadded:: 0.11.0
|
| 95 |
+
|
| 96 |
+
Examples
|
| 97 |
+
--------
|
| 98 |
+
>>> import numpy as np
|
| 99 |
+
>>> from scipy import stats
|
| 100 |
+
>>> import matplotlib.pyplot as plt
|
| 101 |
+
|
| 102 |
+
First some basic examples:
|
| 103 |
+
|
| 104 |
+
Create two evenly spaced bins in the range of the given sample, and sum the
|
| 105 |
+
corresponding values in each of those bins:
|
| 106 |
+
|
| 107 |
+
>>> values = [1.0, 1.0, 2.0, 1.5, 3.0]
|
| 108 |
+
>>> stats.binned_statistic([1, 1, 2, 5, 7], values, 'sum', bins=2)
|
| 109 |
+
BinnedStatisticResult(statistic=array([4. , 4.5]),
|
| 110 |
+
bin_edges=array([1., 4., 7.]), binnumber=array([1, 1, 1, 2, 2]))
|
| 111 |
+
|
| 112 |
+
Multiple arrays of values can also be passed. The statistic is calculated
|
| 113 |
+
on each set independently:
|
| 114 |
+
|
| 115 |
+
>>> values = [[1.0, 1.0, 2.0, 1.5, 3.0], [2.0, 2.0, 4.0, 3.0, 6.0]]
|
| 116 |
+
>>> stats.binned_statistic([1, 1, 2, 5, 7], values, 'sum', bins=2)
|
| 117 |
+
BinnedStatisticResult(statistic=array([[4. , 4.5],
|
| 118 |
+
[8. , 9. ]]), bin_edges=array([1., 4., 7.]),
|
| 119 |
+
binnumber=array([1, 1, 1, 2, 2]))
|
| 120 |
+
|
| 121 |
+
>>> stats.binned_statistic([1, 2, 1, 2, 4], np.arange(5), statistic='mean',
|
| 122 |
+
... bins=3)
|
| 123 |
+
BinnedStatisticResult(statistic=array([1., 2., 4.]),
|
| 124 |
+
bin_edges=array([1., 2., 3., 4.]),
|
| 125 |
+
binnumber=array([1, 2, 1, 2, 3]))
|
| 126 |
+
|
| 127 |
+
As a second example, we now generate some random data of sailing boat speed
|
| 128 |
+
as a function of wind speed, and then determine how fast our boat is for
|
| 129 |
+
certain wind speeds:
|
| 130 |
+
|
| 131 |
+
>>> rng = np.random.default_rng()
|
| 132 |
+
>>> windspeed = 8 * rng.random(500)
|
| 133 |
+
>>> boatspeed = .3 * windspeed**.5 + .2 * rng.random(500)
|
| 134 |
+
>>> bin_means, bin_edges, binnumber = stats.binned_statistic(windspeed,
|
| 135 |
+
... boatspeed, statistic='median', bins=[1,2,3,4,5,6,7])
|
| 136 |
+
>>> plt.figure()
|
| 137 |
+
>>> plt.plot(windspeed, boatspeed, 'b.', label='raw data')
|
| 138 |
+
>>> plt.hlines(bin_means, bin_edges[:-1], bin_edges[1:], colors='g', lw=5,
|
| 139 |
+
... label='binned statistic of data')
|
| 140 |
+
>>> plt.legend()
|
| 141 |
+
|
| 142 |
+
Now we can use ``binnumber`` to select all datapoints with a windspeed
|
| 143 |
+
below 1:
|
| 144 |
+
|
| 145 |
+
>>> low_boatspeed = boatspeed[binnumber == 0]
|
| 146 |
+
|
| 147 |
+
As a final example, we will use ``bin_edges`` and ``binnumber`` to make a
|
| 148 |
+
plot of a distribution that shows the mean and distribution around that
|
| 149 |
+
mean per bin, on top of a regular histogram and the probability
|
| 150 |
+
distribution function:
|
| 151 |
+
|
| 152 |
+
>>> x = np.linspace(0, 5, num=500)
|
| 153 |
+
>>> x_pdf = stats.maxwell.pdf(x)
|
| 154 |
+
>>> samples = stats.maxwell.rvs(size=10000)
|
| 155 |
+
|
| 156 |
+
>>> bin_means, bin_edges, binnumber = stats.binned_statistic(x, x_pdf,
|
| 157 |
+
... statistic='mean', bins=25)
|
| 158 |
+
>>> bin_width = (bin_edges[1] - bin_edges[0])
|
| 159 |
+
>>> bin_centers = bin_edges[1:] - bin_width/2
|
| 160 |
+
|
| 161 |
+
>>> plt.figure()
|
| 162 |
+
>>> plt.hist(samples, bins=50, density=True, histtype='stepfilled',
|
| 163 |
+
... alpha=0.2, label='histogram of data')
|
| 164 |
+
>>> plt.plot(x, x_pdf, 'r-', label='analytical pdf')
|
| 165 |
+
>>> plt.hlines(bin_means, bin_edges[:-1], bin_edges[1:], colors='g', lw=2,
|
| 166 |
+
... label='binned statistic of data')
|
| 167 |
+
>>> plt.plot((binnumber - 0.5) * bin_width, x_pdf, 'g.', alpha=0.5)
|
| 168 |
+
>>> plt.legend(fontsize=10)
|
| 169 |
+
>>> plt.show()
|
| 170 |
+
|
| 171 |
+
"""
|
| 172 |
+
try:
|
| 173 |
+
N = len(bins)
|
| 174 |
+
except TypeError:
|
| 175 |
+
N = 1
|
| 176 |
+
|
| 177 |
+
if N != 1:
|
| 178 |
+
bins = [np.asarray(bins, float)]
|
| 179 |
+
|
| 180 |
+
if range is not None:
|
| 181 |
+
if len(range) == 2:
|
| 182 |
+
range = [range]
|
| 183 |
+
|
| 184 |
+
medians, edges, binnumbers = binned_statistic_dd(
|
| 185 |
+
[x], values, statistic, bins, range)
|
| 186 |
+
|
| 187 |
+
return BinnedStatisticResult(medians, edges[0], binnumbers)
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
BinnedStatistic2dResult = namedtuple('BinnedStatistic2dResult',
|
| 191 |
+
('statistic', 'x_edge', 'y_edge',
|
| 192 |
+
'binnumber'))
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
def binned_statistic_2d(x, y, values, statistic='mean',
|
| 196 |
+
bins=10, range=None, expand_binnumbers=False):
|
| 197 |
+
"""
|
| 198 |
+
Compute a bidimensional binned statistic for one or more sets of data.
|
| 199 |
+
|
| 200 |
+
This is a generalization of a histogram2d function. A histogram divides
|
| 201 |
+
the space into bins, and returns the count of the number of points in
|
| 202 |
+
each bin. This function allows the computation of the sum, mean, median,
|
| 203 |
+
or other statistic of the values (or set of values) within each bin.
|
| 204 |
+
|
| 205 |
+
Parameters
|
| 206 |
+
----------
|
| 207 |
+
x : (N,) array_like
|
| 208 |
+
A sequence of values to be binned along the first dimension.
|
| 209 |
+
y : (N,) array_like
|
| 210 |
+
A sequence of values to be binned along the second dimension.
|
| 211 |
+
values : (N,) array_like or list of (N,) array_like
|
| 212 |
+
The data on which the statistic will be computed. This must be
|
| 213 |
+
the same shape as `x`, or a list of sequences - each with the same
|
| 214 |
+
shape as `x`. If `values` is such a list, the statistic will be
|
| 215 |
+
computed on each independently.
|
| 216 |
+
statistic : string or callable, optional
|
| 217 |
+
The statistic to compute (default is 'mean').
|
| 218 |
+
The following statistics are available:
|
| 219 |
+
|
| 220 |
+
* 'mean' : compute the mean of values for points within each bin.
|
| 221 |
+
Empty bins will be represented by NaN.
|
| 222 |
+
* 'std' : compute the standard deviation within each bin. This
|
| 223 |
+
is implicitly calculated with ddof=0.
|
| 224 |
+
* 'median' : compute the median of values for points within each
|
| 225 |
+
bin. Empty bins will be represented by NaN.
|
| 226 |
+
* 'count' : compute the count of points within each bin. This is
|
| 227 |
+
identical to an unweighted histogram. `values` array is not
|
| 228 |
+
referenced.
|
| 229 |
+
* 'sum' : compute the sum of values for points within each bin.
|
| 230 |
+
This is identical to a weighted histogram.
|
| 231 |
+
* 'min' : compute the minimum of values for points within each bin.
|
| 232 |
+
Empty bins will be represented by NaN.
|
| 233 |
+
* 'max' : compute the maximum of values for point within each bin.
|
| 234 |
+
Empty bins will be represented by NaN.
|
| 235 |
+
* function : a user-defined function which takes a 1D array of
|
| 236 |
+
values, and outputs a single numerical statistic. This function
|
| 237 |
+
will be called on the values in each bin. Empty bins will be
|
| 238 |
+
represented by function([]), or NaN if this returns an error.
|
| 239 |
+
|
| 240 |
+
bins : int or [int, int] or array_like or [array, array], optional
|
| 241 |
+
The bin specification:
|
| 242 |
+
|
| 243 |
+
* the number of bins for the two dimensions (nx = ny = bins),
|
| 244 |
+
* the number of bins in each dimension (nx, ny = bins),
|
| 245 |
+
* the bin edges for the two dimensions (x_edge = y_edge = bins),
|
| 246 |
+
* the bin edges in each dimension (x_edge, y_edge = bins).
|
| 247 |
+
|
| 248 |
+
If the bin edges are specified, the number of bins will be,
|
| 249 |
+
(nx = len(x_edge)-1, ny = len(y_edge)-1).
|
| 250 |
+
|
| 251 |
+
range : (2,2) array_like, optional
|
| 252 |
+
The leftmost and rightmost edges of the bins along each dimension
|
| 253 |
+
(if not specified explicitly in the `bins` parameters):
|
| 254 |
+
[[xmin, xmax], [ymin, ymax]]. All values outside of this range will be
|
| 255 |
+
considered outliers and not tallied in the histogram.
|
| 256 |
+
expand_binnumbers : bool, optional
|
| 257 |
+
'False' (default): the returned `binnumber` is a shape (N,) array of
|
| 258 |
+
linearized bin indices.
|
| 259 |
+
'True': the returned `binnumber` is 'unraveled' into a shape (2,N)
|
| 260 |
+
ndarray, where each row gives the bin numbers in the corresponding
|
| 261 |
+
dimension.
|
| 262 |
+
See the `binnumber` returned value, and the `Examples` section.
|
| 263 |
+
|
| 264 |
+
.. versionadded:: 0.17.0
|
| 265 |
+
|
| 266 |
+
Returns
|
| 267 |
+
-------
|
| 268 |
+
statistic : (nx, ny) ndarray
|
| 269 |
+
The values of the selected statistic in each two-dimensional bin.
|
| 270 |
+
x_edge : (nx + 1) ndarray
|
| 271 |
+
The bin edges along the first dimension.
|
| 272 |
+
y_edge : (ny + 1) ndarray
|
| 273 |
+
The bin edges along the second dimension.
|
| 274 |
+
binnumber : (N,) array of ints or (2,N) ndarray of ints
|
| 275 |
+
This assigns to each element of `sample` an integer that represents the
|
| 276 |
+
bin in which this observation falls. The representation depends on the
|
| 277 |
+
`expand_binnumbers` argument. See `Notes` for details.
|
| 278 |
+
|
| 279 |
+
|
| 280 |
+
See Also
|
| 281 |
+
--------
|
| 282 |
+
numpy.digitize, numpy.histogram2d, binned_statistic, binned_statistic_dd
|
| 283 |
+
|
| 284 |
+
Notes
|
| 285 |
+
-----
|
| 286 |
+
Binedges:
|
| 287 |
+
All but the last (righthand-most) bin is half-open. In other words, if
|
| 288 |
+
`bins` is ``[1, 2, 3, 4]``, then the first bin is ``[1, 2)`` (including 1,
|
| 289 |
+
but excluding 2) and the second ``[2, 3)``. The last bin, however, is
|
| 290 |
+
``[3, 4]``, which *includes* 4.
|
| 291 |
+
|
| 292 |
+
`binnumber`:
|
| 293 |
+
This returned argument assigns to each element of `sample` an integer that
|
| 294 |
+
represents the bin in which it belongs. The representation depends on the
|
| 295 |
+
`expand_binnumbers` argument. If 'False' (default): The returned
|
| 296 |
+
`binnumber` is a shape (N,) array of linearized indices mapping each
|
| 297 |
+
element of `sample` to its corresponding bin (using row-major ordering).
|
| 298 |
+
Note that the returned linearized bin indices are used for an array with
|
| 299 |
+
extra bins on the outer binedges to capture values outside of the defined
|
| 300 |
+
bin bounds.
|
| 301 |
+
If 'True': The returned `binnumber` is a shape (2,N) ndarray where
|
| 302 |
+
each row indicates bin placements for each dimension respectively. In each
|
| 303 |
+
dimension, a binnumber of `i` means the corresponding value is between
|
| 304 |
+
(D_edge[i-1], D_edge[i]), where 'D' is either 'x' or 'y'.
|
| 305 |
+
|
| 306 |
+
.. versionadded:: 0.11.0
|
| 307 |
+
|
| 308 |
+
Examples
|
| 309 |
+
--------
|
| 310 |
+
>>> from scipy import stats
|
| 311 |
+
|
| 312 |
+
Calculate the counts with explicit bin-edges:
|
| 313 |
+
|
| 314 |
+
>>> x = [0.1, 0.1, 0.1, 0.6]
|
| 315 |
+
>>> y = [2.1, 2.6, 2.1, 2.1]
|
| 316 |
+
>>> binx = [0.0, 0.5, 1.0]
|
| 317 |
+
>>> biny = [2.0, 2.5, 3.0]
|
| 318 |
+
>>> ret = stats.binned_statistic_2d(x, y, None, 'count', bins=[binx, biny])
|
| 319 |
+
>>> ret.statistic
|
| 320 |
+
array([[2., 1.],
|
| 321 |
+
[1., 0.]])
|
| 322 |
+
|
| 323 |
+
The bin in which each sample is placed is given by the `binnumber`
|
| 324 |
+
returned parameter. By default, these are the linearized bin indices:
|
| 325 |
+
|
| 326 |
+
>>> ret.binnumber
|
| 327 |
+
array([5, 6, 5, 9])
|
| 328 |
+
|
| 329 |
+
The bin indices can also be expanded into separate entries for each
|
| 330 |
+
dimension using the `expand_binnumbers` parameter:
|
| 331 |
+
|
| 332 |
+
>>> ret = stats.binned_statistic_2d(x, y, None, 'count', bins=[binx, biny],
|
| 333 |
+
... expand_binnumbers=True)
|
| 334 |
+
>>> ret.binnumber
|
| 335 |
+
array([[1, 1, 1, 2],
|
| 336 |
+
[1, 2, 1, 1]])
|
| 337 |
+
|
| 338 |
+
Which shows that the first three elements belong in the xbin 1, and the
|
| 339 |
+
fourth into xbin 2; and so on for y.
|
| 340 |
+
|
| 341 |
+
"""
|
| 342 |
+
|
| 343 |
+
# This code is based on np.histogram2d
|
| 344 |
+
try:
|
| 345 |
+
N = len(bins)
|
| 346 |
+
except TypeError:
|
| 347 |
+
N = 1
|
| 348 |
+
|
| 349 |
+
if N != 1 and N != 2:
|
| 350 |
+
xedges = yedges = np.asarray(bins, float)
|
| 351 |
+
bins = [xedges, yedges]
|
| 352 |
+
|
| 353 |
+
medians, edges, binnumbers = binned_statistic_dd(
|
| 354 |
+
[x, y], values, statistic, bins, range,
|
| 355 |
+
expand_binnumbers=expand_binnumbers)
|
| 356 |
+
|
| 357 |
+
return BinnedStatistic2dResult(medians, edges[0], edges[1], binnumbers)
|
| 358 |
+
|
| 359 |
+
|
| 360 |
+
BinnedStatisticddResult = namedtuple('BinnedStatisticddResult',
|
| 361 |
+
('statistic', 'bin_edges',
|
| 362 |
+
'binnumber'))
|
| 363 |
+
|
| 364 |
+
|
| 365 |
+
def _bincount(x, weights):
|
| 366 |
+
if np.iscomplexobj(weights):
|
| 367 |
+
a = np.bincount(x, np.real(weights))
|
| 368 |
+
b = np.bincount(x, np.imag(weights))
|
| 369 |
+
z = a + b*1j
|
| 370 |
+
|
| 371 |
+
else:
|
| 372 |
+
z = np.bincount(x, weights)
|
| 373 |
+
return z
|
| 374 |
+
|
| 375 |
+
|
| 376 |
+
def binned_statistic_dd(sample, values, statistic='mean',
|
| 377 |
+
bins=10, range=None, expand_binnumbers=False,
|
| 378 |
+
binned_statistic_result=None):
|
| 379 |
+
"""
|
| 380 |
+
Compute a multidimensional binned statistic for a set of data.
|
| 381 |
+
|
| 382 |
+
This is a generalization of a histogramdd function. A histogram divides
|
| 383 |
+
the space into bins, and returns the count of the number of points in
|
| 384 |
+
each bin. This function allows the computation of the sum, mean, median,
|
| 385 |
+
or other statistic of the values within each bin.
|
| 386 |
+
|
| 387 |
+
Parameters
|
| 388 |
+
----------
|
| 389 |
+
sample : array_like
|
| 390 |
+
Data to histogram passed as a sequence of N arrays of length D, or
|
| 391 |
+
as an (N,D) array.
|
| 392 |
+
values : (N,) array_like or list of (N,) array_like
|
| 393 |
+
The data on which the statistic will be computed. This must be
|
| 394 |
+
the same shape as `sample`, or a list of sequences - each with the
|
| 395 |
+
same shape as `sample`. If `values` is such a list, the statistic
|
| 396 |
+
will be computed on each independently.
|
| 397 |
+
statistic : string or callable, optional
|
| 398 |
+
The statistic to compute (default is 'mean').
|
| 399 |
+
The following statistics are available:
|
| 400 |
+
|
| 401 |
+
* 'mean' : compute the mean of values for points within each bin.
|
| 402 |
+
Empty bins will be represented by NaN.
|
| 403 |
+
* 'median' : compute the median of values for points within each
|
| 404 |
+
bin. Empty bins will be represented by NaN.
|
| 405 |
+
* 'count' : compute the count of points within each bin. This is
|
| 406 |
+
identical to an unweighted histogram. `values` array is not
|
| 407 |
+
referenced.
|
| 408 |
+
* 'sum' : compute the sum of values for points within each bin.
|
| 409 |
+
This is identical to a weighted histogram.
|
| 410 |
+
* 'std' : compute the standard deviation within each bin. This
|
| 411 |
+
is implicitly calculated with ddof=0. If the number of values
|
| 412 |
+
within a given bin is 0 or 1, the computed standard deviation value
|
| 413 |
+
will be 0 for the bin.
|
| 414 |
+
* 'min' : compute the minimum of values for points within each bin.
|
| 415 |
+
Empty bins will be represented by NaN.
|
| 416 |
+
* 'max' : compute the maximum of values for point within each bin.
|
| 417 |
+
Empty bins will be represented by NaN.
|
| 418 |
+
* function : a user-defined function which takes a 1D array of
|
| 419 |
+
values, and outputs a single numerical statistic. This function
|
| 420 |
+
will be called on the values in each bin. Empty bins will be
|
| 421 |
+
represented by function([]), or NaN if this returns an error.
|
| 422 |
+
|
| 423 |
+
bins : sequence or positive int, optional
|
| 424 |
+
The bin specification must be in one of the following forms:
|
| 425 |
+
|
| 426 |
+
* A sequence of arrays describing the bin edges along each dimension.
|
| 427 |
+
* The number of bins for each dimension (nx, ny, ... = bins).
|
| 428 |
+
* The number of bins for all dimensions (nx = ny = ... = bins).
|
| 429 |
+
range : sequence, optional
|
| 430 |
+
A sequence of lower and upper bin edges to be used if the edges are
|
| 431 |
+
not given explicitly in `bins`. Defaults to the minimum and maximum
|
| 432 |
+
values along each dimension.
|
| 433 |
+
expand_binnumbers : bool, optional
|
| 434 |
+
'False' (default): the returned `binnumber` is a shape (N,) array of
|
| 435 |
+
linearized bin indices.
|
| 436 |
+
'True': the returned `binnumber` is 'unraveled' into a shape (D,N)
|
| 437 |
+
ndarray, where each row gives the bin numbers in the corresponding
|
| 438 |
+
dimension.
|
| 439 |
+
See the `binnumber` returned value, and the `Examples` section of
|
| 440 |
+
`binned_statistic_2d`.
|
| 441 |
+
binned_statistic_result : binnedStatisticddResult
|
| 442 |
+
Result of a previous call to the function in order to reuse bin edges
|
| 443 |
+
and bin numbers with new values and/or a different statistic.
|
| 444 |
+
To reuse bin numbers, `expand_binnumbers` must have been set to False
|
| 445 |
+
(the default)
|
| 446 |
+
|
| 447 |
+
.. versionadded:: 0.17.0
|
| 448 |
+
|
| 449 |
+
Returns
|
| 450 |
+
-------
|
| 451 |
+
statistic : ndarray, shape(nx1, nx2, nx3,...)
|
| 452 |
+
The values of the selected statistic in each two-dimensional bin.
|
| 453 |
+
bin_edges : list of ndarrays
|
| 454 |
+
A list of D arrays describing the (nxi + 1) bin edges for each
|
| 455 |
+
dimension.
|
| 456 |
+
binnumber : (N,) array of ints or (D,N) ndarray of ints
|
| 457 |
+
This assigns to each element of `sample` an integer that represents the
|
| 458 |
+
bin in which this observation falls. The representation depends on the
|
| 459 |
+
`expand_binnumbers` argument. See `Notes` for details.
|
| 460 |
+
|
| 461 |
+
|
| 462 |
+
See Also
|
| 463 |
+
--------
|
| 464 |
+
numpy.digitize, numpy.histogramdd, binned_statistic, binned_statistic_2d
|
| 465 |
+
|
| 466 |
+
Notes
|
| 467 |
+
-----
|
| 468 |
+
Binedges:
|
| 469 |
+
All but the last (righthand-most) bin is half-open in each dimension. In
|
| 470 |
+
other words, if `bins` is ``[1, 2, 3, 4]``, then the first bin is
|
| 471 |
+
``[1, 2)`` (including 1, but excluding 2) and the second ``[2, 3)``. The
|
| 472 |
+
last bin, however, is ``[3, 4]``, which *includes* 4.
|
| 473 |
+
|
| 474 |
+
`binnumber`:
|
| 475 |
+
This returned argument assigns to each element of `sample` an integer that
|
| 476 |
+
represents the bin in which it belongs. The representation depends on the
|
| 477 |
+
`expand_binnumbers` argument. If 'False' (default): The returned
|
| 478 |
+
`binnumber` is a shape (N,) array of linearized indices mapping each
|
| 479 |
+
element of `sample` to its corresponding bin (using row-major ordering).
|
| 480 |
+
If 'True': The returned `binnumber` is a shape (D,N) ndarray where
|
| 481 |
+
each row indicates bin placements for each dimension respectively. In each
|
| 482 |
+
dimension, a binnumber of `i` means the corresponding value is between
|
| 483 |
+
(bin_edges[D][i-1], bin_edges[D][i]), for each dimension 'D'.
|
| 484 |
+
|
| 485 |
+
.. versionadded:: 0.11.0
|
| 486 |
+
|
| 487 |
+
Examples
|
| 488 |
+
--------
|
| 489 |
+
>>> import numpy as np
|
| 490 |
+
>>> from scipy import stats
|
| 491 |
+
>>> import matplotlib.pyplot as plt
|
| 492 |
+
>>> from mpl_toolkits.mplot3d import Axes3D
|
| 493 |
+
|
| 494 |
+
Take an array of 600 (x, y) coordinates as an example.
|
| 495 |
+
`binned_statistic_dd` can handle arrays of higher dimension `D`. But a plot
|
| 496 |
+
of dimension `D+1` is required.
|
| 497 |
+
|
| 498 |
+
>>> mu = np.array([0., 1.])
|
| 499 |
+
>>> sigma = np.array([[1., -0.5],[-0.5, 1.5]])
|
| 500 |
+
>>> multinormal = stats.multivariate_normal(mu, sigma)
|
| 501 |
+
>>> data = multinormal.rvs(size=600, random_state=235412)
|
| 502 |
+
>>> data.shape
|
| 503 |
+
(600, 2)
|
| 504 |
+
|
| 505 |
+
Create bins and count how many arrays fall in each bin:
|
| 506 |
+
|
| 507 |
+
>>> N = 60
|
| 508 |
+
>>> x = np.linspace(-3, 3, N)
|
| 509 |
+
>>> y = np.linspace(-3, 4, N)
|
| 510 |
+
>>> ret = stats.binned_statistic_dd(data, np.arange(600), bins=[x, y],
|
| 511 |
+
... statistic='count')
|
| 512 |
+
>>> bincounts = ret.statistic
|
| 513 |
+
|
| 514 |
+
Set the volume and the location of bars:
|
| 515 |
+
|
| 516 |
+
>>> dx = x[1] - x[0]
|
| 517 |
+
>>> dy = y[1] - y[0]
|
| 518 |
+
>>> x, y = np.meshgrid(x[:-1]+dx/2, y[:-1]+dy/2)
|
| 519 |
+
>>> z = 0
|
| 520 |
+
|
| 521 |
+
>>> bincounts = bincounts.ravel()
|
| 522 |
+
>>> x = x.ravel()
|
| 523 |
+
>>> y = y.ravel()
|
| 524 |
+
|
| 525 |
+
>>> fig = plt.figure()
|
| 526 |
+
>>> ax = fig.add_subplot(111, projection='3d')
|
| 527 |
+
>>> with np.errstate(divide='ignore'): # silence random axes3d warning
|
| 528 |
+
... ax.bar3d(x, y, z, dx, dy, bincounts)
|
| 529 |
+
|
| 530 |
+
Reuse bin numbers and bin edges with new values:
|
| 531 |
+
|
| 532 |
+
>>> ret2 = stats.binned_statistic_dd(data, -np.arange(600),
|
| 533 |
+
... binned_statistic_result=ret,
|
| 534 |
+
... statistic='mean')
|
| 535 |
+
"""
|
| 536 |
+
known_stats = ['mean', 'median', 'count', 'sum', 'std', 'min', 'max']
|
| 537 |
+
if not callable(statistic) and statistic not in known_stats:
|
| 538 |
+
raise ValueError(f'invalid statistic {statistic!r}')
|
| 539 |
+
|
| 540 |
+
try:
|
| 541 |
+
bins = index(bins)
|
| 542 |
+
except TypeError:
|
| 543 |
+
# bins is not an integer
|
| 544 |
+
pass
|
| 545 |
+
# If bins was an integer-like object, now it is an actual Python int.
|
| 546 |
+
|
| 547 |
+
# NOTE: for _bin_edges(), see e.g. gh-11365
|
| 548 |
+
if isinstance(bins, int) and not np.isfinite(sample).all():
|
| 549 |
+
raise ValueError(f'{sample!r} contains non-finite values.')
|
| 550 |
+
|
| 551 |
+
# `Ndim` is the number of dimensions (e.g. `2` for `binned_statistic_2d`)
|
| 552 |
+
# `Dlen` is the length of elements along each dimension.
|
| 553 |
+
# This code is based on np.histogramdd
|
| 554 |
+
try:
|
| 555 |
+
# `sample` is an ND-array.
|
| 556 |
+
Dlen, Ndim = sample.shape
|
| 557 |
+
except (AttributeError, ValueError):
|
| 558 |
+
# `sample` is a sequence of 1D arrays.
|
| 559 |
+
sample = np.atleast_2d(sample).T
|
| 560 |
+
Dlen, Ndim = sample.shape
|
| 561 |
+
|
| 562 |
+
# Store initial shape of `values` to preserve it in the output
|
| 563 |
+
values = np.asarray(values)
|
| 564 |
+
input_shape = list(values.shape)
|
| 565 |
+
# Make sure that `values` is 2D to iterate over rows
|
| 566 |
+
values = np.atleast_2d(values)
|
| 567 |
+
Vdim, Vlen = values.shape
|
| 568 |
+
|
| 569 |
+
# Make sure `values` match `sample`
|
| 570 |
+
if statistic != 'count' and Vlen != Dlen:
|
| 571 |
+
raise AttributeError('The number of `values` elements must match the '
|
| 572 |
+
'length of each `sample` dimension.')
|
| 573 |
+
|
| 574 |
+
try:
|
| 575 |
+
M = len(bins)
|
| 576 |
+
if M != Ndim:
|
| 577 |
+
raise AttributeError('The dimension of bins must be equal '
|
| 578 |
+
'to the dimension of the sample x.')
|
| 579 |
+
except TypeError:
|
| 580 |
+
bins = Ndim * [bins]
|
| 581 |
+
|
| 582 |
+
if binned_statistic_result is None:
|
| 583 |
+
nbin, edges, dedges = _bin_edges(sample, bins, range)
|
| 584 |
+
binnumbers = _bin_numbers(sample, nbin, edges, dedges)
|
| 585 |
+
else:
|
| 586 |
+
edges = binned_statistic_result.bin_edges
|
| 587 |
+
nbin = np.array([len(edges[i]) + 1 for i in builtins.range(Ndim)])
|
| 588 |
+
# +1 for outlier bins
|
| 589 |
+
dedges = [np.diff(edges[i]) for i in builtins.range(Ndim)]
|
| 590 |
+
binnumbers = binned_statistic_result.binnumber
|
| 591 |
+
|
| 592 |
+
# Avoid overflow with double precision. Complex `values` -> `complex128`.
|
| 593 |
+
result_type = np.result_type(values, np.float64)
|
| 594 |
+
result = np.empty([Vdim, nbin.prod()], dtype=result_type)
|
| 595 |
+
|
| 596 |
+
if statistic in {'mean', np.mean}:
|
| 597 |
+
result.fill(np.nan)
|
| 598 |
+
flatcount = _bincount(binnumbers, None)
|
| 599 |
+
a = flatcount.nonzero()
|
| 600 |
+
for vv in builtins.range(Vdim):
|
| 601 |
+
flatsum = _bincount(binnumbers, values[vv])
|
| 602 |
+
result[vv, a] = flatsum[a] / flatcount[a]
|
| 603 |
+
elif statistic in {'std', np.std}:
|
| 604 |
+
result.fill(np.nan)
|
| 605 |
+
flatcount = _bincount(binnumbers, None)
|
| 606 |
+
a = flatcount.nonzero()
|
| 607 |
+
for vv in builtins.range(Vdim):
|
| 608 |
+
flatsum = _bincount(binnumbers, values[vv])
|
| 609 |
+
delta = values[vv] - flatsum[binnumbers] / flatcount[binnumbers]
|
| 610 |
+
std = np.sqrt(
|
| 611 |
+
_bincount(binnumbers, delta*np.conj(delta))[a] / flatcount[a]
|
| 612 |
+
)
|
| 613 |
+
result[vv, a] = std
|
| 614 |
+
result = np.real(result)
|
| 615 |
+
elif statistic == 'count':
|
| 616 |
+
result = np.empty([Vdim, nbin.prod()], dtype=np.float64)
|
| 617 |
+
result.fill(0)
|
| 618 |
+
flatcount = _bincount(binnumbers, None)
|
| 619 |
+
a = np.arange(len(flatcount))
|
| 620 |
+
result[:, a] = flatcount[np.newaxis, :]
|
| 621 |
+
elif statistic in {'sum', np.sum}:
|
| 622 |
+
result.fill(0)
|
| 623 |
+
for vv in builtins.range(Vdim):
|
| 624 |
+
flatsum = _bincount(binnumbers, values[vv])
|
| 625 |
+
a = np.arange(len(flatsum))
|
| 626 |
+
result[vv, a] = flatsum
|
| 627 |
+
elif statistic in {'median', np.median}:
|
| 628 |
+
result.fill(np.nan)
|
| 629 |
+
for vv in builtins.range(Vdim):
|
| 630 |
+
i = np.lexsort((values[vv], binnumbers))
|
| 631 |
+
_, j, counts = np.unique(binnumbers[i],
|
| 632 |
+
return_index=True, return_counts=True)
|
| 633 |
+
mid = j + (counts - 1) / 2
|
| 634 |
+
mid_a = values[vv, i][np.floor(mid).astype(int)]
|
| 635 |
+
mid_b = values[vv, i][np.ceil(mid).astype(int)]
|
| 636 |
+
medians = (mid_a + mid_b) / 2
|
| 637 |
+
result[vv, binnumbers[i][j]] = medians
|
| 638 |
+
elif statistic in {'min', np.min}:
|
| 639 |
+
result.fill(np.nan)
|
| 640 |
+
for vv in builtins.range(Vdim):
|
| 641 |
+
i = np.argsort(values[vv])[::-1] # Reversed so the min is last
|
| 642 |
+
result[vv, binnumbers[i]] = values[vv, i]
|
| 643 |
+
elif statistic in {'max', np.max}:
|
| 644 |
+
result.fill(np.nan)
|
| 645 |
+
for vv in builtins.range(Vdim):
|
| 646 |
+
i = np.argsort(values[vv])
|
| 647 |
+
result[vv, binnumbers[i]] = values[vv, i]
|
| 648 |
+
elif callable(statistic):
|
| 649 |
+
with np.errstate(invalid='ignore'), catch_warnings():
|
| 650 |
+
simplefilter("ignore", RuntimeWarning)
|
| 651 |
+
try:
|
| 652 |
+
null = statistic([])
|
| 653 |
+
except Exception:
|
| 654 |
+
null = np.nan
|
| 655 |
+
if np.iscomplexobj(null):
|
| 656 |
+
result = result.astype(np.complex128)
|
| 657 |
+
result.fill(null)
|
| 658 |
+
try:
|
| 659 |
+
_calc_binned_statistic(
|
| 660 |
+
Vdim, binnumbers, result, values, statistic
|
| 661 |
+
)
|
| 662 |
+
except ValueError:
|
| 663 |
+
result = result.astype(np.complex128)
|
| 664 |
+
_calc_binned_statistic(
|
| 665 |
+
Vdim, binnumbers, result, values, statistic
|
| 666 |
+
)
|
| 667 |
+
|
| 668 |
+
# Shape into a proper matrix
|
| 669 |
+
result = result.reshape(np.append(Vdim, nbin))
|
| 670 |
+
|
| 671 |
+
# Remove outliers (indices 0 and -1 for each bin-dimension).
|
| 672 |
+
core = tuple([slice(None)] + Ndim * [slice(1, -1)])
|
| 673 |
+
result = result[core]
|
| 674 |
+
|
| 675 |
+
# Unravel binnumbers into an ndarray, each row the bins for each dimension
|
| 676 |
+
if expand_binnumbers and Ndim > 1:
|
| 677 |
+
binnumbers = np.asarray(np.unravel_index(binnumbers, nbin))
|
| 678 |
+
|
| 679 |
+
if np.any(result.shape[1:] != nbin - 2):
|
| 680 |
+
raise RuntimeError('Internal Shape Error')
|
| 681 |
+
|
| 682 |
+
# Reshape to have output (`result`) match input (`values`) shape
|
| 683 |
+
result = result.reshape(input_shape[:-1] + list(nbin-2))
|
| 684 |
+
|
| 685 |
+
return BinnedStatisticddResult(result, edges, binnumbers)
|
| 686 |
+
|
| 687 |
+
|
| 688 |
+
def _calc_binned_statistic(Vdim, bin_numbers, result, values, stat_func):
|
| 689 |
+
unique_bin_numbers = np.unique(bin_numbers)
|
| 690 |
+
for vv in builtins.range(Vdim):
|
| 691 |
+
bin_map = _create_binned_data(bin_numbers, unique_bin_numbers,
|
| 692 |
+
values, vv)
|
| 693 |
+
for i in unique_bin_numbers:
|
| 694 |
+
stat = stat_func(np.array(bin_map[i]))
|
| 695 |
+
if np.iscomplexobj(stat) and not np.iscomplexobj(result):
|
| 696 |
+
raise ValueError("The statistic function returns complex ")
|
| 697 |
+
result[vv, i] = stat
|
| 698 |
+
|
| 699 |
+
|
| 700 |
+
def _create_binned_data(bin_numbers, unique_bin_numbers, values, vv):
|
| 701 |
+
""" Create hashmap of bin ids to values in bins
|
| 702 |
+
key: bin number
|
| 703 |
+
value: list of binned data
|
| 704 |
+
"""
|
| 705 |
+
bin_map = dict()
|
| 706 |
+
for i in unique_bin_numbers:
|
| 707 |
+
bin_map[i] = []
|
| 708 |
+
for i in builtins.range(len(bin_numbers)):
|
| 709 |
+
bin_map[bin_numbers[i]].append(values[vv, i])
|
| 710 |
+
return bin_map
|
| 711 |
+
|
| 712 |
+
|
| 713 |
+
def _bin_edges(sample, bins=None, range=None):
|
| 714 |
+
""" Create edge arrays
|
| 715 |
+
"""
|
| 716 |
+
Dlen, Ndim = sample.shape
|
| 717 |
+
|
| 718 |
+
nbin = np.empty(Ndim, int) # Number of bins in each dimension
|
| 719 |
+
edges = Ndim * [None] # Bin edges for each dim (will be 2D array)
|
| 720 |
+
dedges = Ndim * [None] # Spacing between edges (will be 2D array)
|
| 721 |
+
|
| 722 |
+
# Select range for each dimension
|
| 723 |
+
# Used only if number of bins is given.
|
| 724 |
+
if range is None:
|
| 725 |
+
smin = np.atleast_1d(np.array(sample.min(axis=0), float))
|
| 726 |
+
smax = np.atleast_1d(np.array(sample.max(axis=0), float))
|
| 727 |
+
else:
|
| 728 |
+
if len(range) != Ndim:
|
| 729 |
+
raise ValueError(
|
| 730 |
+
f"range given for {len(range)} dimensions; {Ndim} required")
|
| 731 |
+
smin = np.empty(Ndim)
|
| 732 |
+
smax = np.empty(Ndim)
|
| 733 |
+
for i in builtins.range(Ndim):
|
| 734 |
+
if range[i][1] < range[i][0]:
|
| 735 |
+
raise ValueError(
|
| 736 |
+
f"In {f'dimension {i + 1} of ' if Ndim > 1 else ''}range,"
|
| 737 |
+
" start must be <= stop")
|
| 738 |
+
smin[i], smax[i] = range[i]
|
| 739 |
+
|
| 740 |
+
# Make sure the bins have a finite width.
|
| 741 |
+
for i in builtins.range(len(smin)):
|
| 742 |
+
if smin[i] == smax[i]:
|
| 743 |
+
smin[i] = smin[i] - .5
|
| 744 |
+
smax[i] = smax[i] + .5
|
| 745 |
+
|
| 746 |
+
# Preserve sample floating point precision in bin edges
|
| 747 |
+
edges_dtype = (sample.dtype if np.issubdtype(sample.dtype, np.floating)
|
| 748 |
+
else float)
|
| 749 |
+
|
| 750 |
+
# Create edge arrays
|
| 751 |
+
for i in builtins.range(Ndim):
|
| 752 |
+
if np.isscalar(bins[i]):
|
| 753 |
+
nbin[i] = bins[i] + 2 # +2 for outlier bins
|
| 754 |
+
edges[i] = np.linspace(smin[i], smax[i], nbin[i] - 1,
|
| 755 |
+
dtype=edges_dtype)
|
| 756 |
+
else:
|
| 757 |
+
edges[i] = np.asarray(bins[i], edges_dtype)
|
| 758 |
+
nbin[i] = len(edges[i]) + 1 # +1 for outlier bins
|
| 759 |
+
dedges[i] = np.diff(edges[i])
|
| 760 |
+
|
| 761 |
+
nbin = np.asarray(nbin)
|
| 762 |
+
|
| 763 |
+
return nbin, edges, dedges
|
| 764 |
+
|
| 765 |
+
|
| 766 |
+
def _bin_numbers(sample, nbin, edges, dedges):
|
| 767 |
+
"""Compute the bin number each sample falls into, in each dimension
|
| 768 |
+
"""
|
| 769 |
+
Dlen, Ndim = sample.shape
|
| 770 |
+
|
| 771 |
+
sampBin = [
|
| 772 |
+
np.digitize(sample[:, i], edges[i])
|
| 773 |
+
for i in range(Ndim)
|
| 774 |
+
]
|
| 775 |
+
|
| 776 |
+
# Using `digitize`, values that fall on an edge are put in the right bin.
|
| 777 |
+
# For the rightmost bin, we want values equal to the right
|
| 778 |
+
# edge to be counted in the last bin, and not as an outlier.
|
| 779 |
+
for i in range(Ndim):
|
| 780 |
+
# Find the rounding precision
|
| 781 |
+
dedges_min = dedges[i].min()
|
| 782 |
+
if dedges_min == 0:
|
| 783 |
+
raise ValueError('The smallest edge difference is numerically 0.')
|
| 784 |
+
decimal = int(-np.log10(dedges_min)) + 6
|
| 785 |
+
# Find which points are on the rightmost edge.
|
| 786 |
+
on_edge = np.where((sample[:, i] >= edges[i][-1]) &
|
| 787 |
+
(np.around(sample[:, i], decimal) ==
|
| 788 |
+
np.around(edges[i][-1], decimal)))[0]
|
| 789 |
+
# Shift these points one bin to the left.
|
| 790 |
+
sampBin[i][on_edge] -= 1
|
| 791 |
+
|
| 792 |
+
# Compute the sample indices in the flattened statistic matrix.
|
| 793 |
+
binnumbers = np.ravel_multi_index(sampBin, nbin)
|
| 794 |
+
|
| 795 |
+
return binnumbers
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/stats/_binomtest.py
ADDED
|
@@ -0,0 +1,375 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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3 |
+
from scipy._lib._util import _validate_int
|
| 4 |
+
from scipy.optimize import brentq
|
| 5 |
+
from scipy.special import ndtri
|
| 6 |
+
from ._discrete_distns import binom
|
| 7 |
+
from ._common import ConfidenceInterval
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class BinomTestResult:
|
| 11 |
+
"""
|
| 12 |
+
Result of `scipy.stats.binomtest`.
|
| 13 |
+
|
| 14 |
+
Attributes
|
| 15 |
+
----------
|
| 16 |
+
k : int
|
| 17 |
+
The number of successes (copied from `binomtest` input).
|
| 18 |
+
n : int
|
| 19 |
+
The number of trials (copied from `binomtest` input).
|
| 20 |
+
alternative : str
|
| 21 |
+
Indicates the alternative hypothesis specified in the input
|
| 22 |
+
to `binomtest`. It will be one of ``'two-sided'``, ``'greater'``,
|
| 23 |
+
or ``'less'``.
|
| 24 |
+
statistic: float
|
| 25 |
+
The estimate of the proportion of successes.
|
| 26 |
+
pvalue : float
|
| 27 |
+
The p-value of the hypothesis test.
|
| 28 |
+
|
| 29 |
+
"""
|
| 30 |
+
def __init__(self, k, n, alternative, statistic, pvalue):
|
| 31 |
+
self.k = k
|
| 32 |
+
self.n = n
|
| 33 |
+
self.alternative = alternative
|
| 34 |
+
self.statistic = statistic
|
| 35 |
+
self.pvalue = pvalue
|
| 36 |
+
|
| 37 |
+
# add alias for backward compatibility
|
| 38 |
+
self.proportion_estimate = statistic
|
| 39 |
+
|
| 40 |
+
def __repr__(self):
|
| 41 |
+
s = ("BinomTestResult("
|
| 42 |
+
f"k={self.k}, "
|
| 43 |
+
f"n={self.n}, "
|
| 44 |
+
f"alternative={self.alternative!r}, "
|
| 45 |
+
f"statistic={self.statistic}, "
|
| 46 |
+
f"pvalue={self.pvalue})")
|
| 47 |
+
return s
|
| 48 |
+
|
| 49 |
+
def proportion_ci(self, confidence_level=0.95, method='exact'):
|
| 50 |
+
"""
|
| 51 |
+
Compute the confidence interval for ``statistic``.
|
| 52 |
+
|
| 53 |
+
Parameters
|
| 54 |
+
----------
|
| 55 |
+
confidence_level : float, optional
|
| 56 |
+
Confidence level for the computed confidence interval
|
| 57 |
+
of the estimated proportion. Default is 0.95.
|
| 58 |
+
method : {'exact', 'wilson', 'wilsoncc'}, optional
|
| 59 |
+
Selects the method used to compute the confidence interval
|
| 60 |
+
for the estimate of the proportion:
|
| 61 |
+
|
| 62 |
+
'exact' :
|
| 63 |
+
Use the Clopper-Pearson exact method [1]_.
|
| 64 |
+
'wilson' :
|
| 65 |
+
Wilson's method, without continuity correction ([2]_, [3]_).
|
| 66 |
+
'wilsoncc' :
|
| 67 |
+
Wilson's method, with continuity correction ([2]_, [3]_).
|
| 68 |
+
|
| 69 |
+
Default is ``'exact'``.
|
| 70 |
+
|
| 71 |
+
Returns
|
| 72 |
+
-------
|
| 73 |
+
ci : ``ConfidenceInterval`` object
|
| 74 |
+
The object has attributes ``low`` and ``high`` that hold the
|
| 75 |
+
lower and upper bounds of the confidence interval.
|
| 76 |
+
|
| 77 |
+
References
|
| 78 |
+
----------
|
| 79 |
+
.. [1] C. J. Clopper and E. S. Pearson, The use of confidence or
|
| 80 |
+
fiducial limits illustrated in the case of the binomial,
|
| 81 |
+
Biometrika, Vol. 26, No. 4, pp 404-413 (Dec. 1934).
|
| 82 |
+
.. [2] E. B. Wilson, Probable inference, the law of succession, and
|
| 83 |
+
statistical inference, J. Amer. Stat. Assoc., 22, pp 209-212
|
| 84 |
+
(1927).
|
| 85 |
+
.. [3] Robert G. Newcombe, Two-sided confidence intervals for the
|
| 86 |
+
single proportion: comparison of seven methods, Statistics
|
| 87 |
+
in Medicine, 17, pp 857-872 (1998).
|
| 88 |
+
|
| 89 |
+
Examples
|
| 90 |
+
--------
|
| 91 |
+
>>> from scipy.stats import binomtest
|
| 92 |
+
>>> result = binomtest(k=7, n=50, p=0.1)
|
| 93 |
+
>>> result.statistic
|
| 94 |
+
0.14
|
| 95 |
+
>>> result.proportion_ci()
|
| 96 |
+
ConfidenceInterval(low=0.05819170033997342, high=0.26739600249700846)
|
| 97 |
+
"""
|
| 98 |
+
if method not in ('exact', 'wilson', 'wilsoncc'):
|
| 99 |
+
raise ValueError(f"method ('{method}') must be one of 'exact', "
|
| 100 |
+
"'wilson' or 'wilsoncc'.")
|
| 101 |
+
if not (0 <= confidence_level <= 1):
|
| 102 |
+
raise ValueError(f'confidence_level ({confidence_level}) must be in '
|
| 103 |
+
'the interval [0, 1].')
|
| 104 |
+
if method == 'exact':
|
| 105 |
+
low, high = _binom_exact_conf_int(self.k, self.n,
|
| 106 |
+
confidence_level,
|
| 107 |
+
self.alternative)
|
| 108 |
+
else:
|
| 109 |
+
# method is 'wilson' or 'wilsoncc'
|
| 110 |
+
low, high = _binom_wilson_conf_int(self.k, self.n,
|
| 111 |
+
confidence_level,
|
| 112 |
+
self.alternative,
|
| 113 |
+
correction=method == 'wilsoncc')
|
| 114 |
+
return ConfidenceInterval(low=low, high=high)
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
def _findp(func):
|
| 118 |
+
try:
|
| 119 |
+
p = brentq(func, 0, 1)
|
| 120 |
+
except RuntimeError:
|
| 121 |
+
raise RuntimeError('numerical solver failed to converge when '
|
| 122 |
+
'computing the confidence limits') from None
|
| 123 |
+
except ValueError as exc:
|
| 124 |
+
raise ValueError('brentq raised a ValueError; report this to the '
|
| 125 |
+
'SciPy developers') from exc
|
| 126 |
+
return p
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
def _binom_exact_conf_int(k, n, confidence_level, alternative):
|
| 130 |
+
"""
|
| 131 |
+
Compute the estimate and confidence interval for the binomial test.
|
| 132 |
+
|
| 133 |
+
Returns proportion, prop_low, prop_high
|
| 134 |
+
"""
|
| 135 |
+
if alternative == 'two-sided':
|
| 136 |
+
alpha = (1 - confidence_level) / 2
|
| 137 |
+
if k == 0:
|
| 138 |
+
plow = 0.0
|
| 139 |
+
else:
|
| 140 |
+
plow = _findp(lambda p: binom.sf(k-1, n, p) - alpha)
|
| 141 |
+
if k == n:
|
| 142 |
+
phigh = 1.0
|
| 143 |
+
else:
|
| 144 |
+
phigh = _findp(lambda p: binom.cdf(k, n, p) - alpha)
|
| 145 |
+
elif alternative == 'less':
|
| 146 |
+
alpha = 1 - confidence_level
|
| 147 |
+
plow = 0.0
|
| 148 |
+
if k == n:
|
| 149 |
+
phigh = 1.0
|
| 150 |
+
else:
|
| 151 |
+
phigh = _findp(lambda p: binom.cdf(k, n, p) - alpha)
|
| 152 |
+
elif alternative == 'greater':
|
| 153 |
+
alpha = 1 - confidence_level
|
| 154 |
+
if k == 0:
|
| 155 |
+
plow = 0.0
|
| 156 |
+
else:
|
| 157 |
+
plow = _findp(lambda p: binom.sf(k-1, n, p) - alpha)
|
| 158 |
+
phigh = 1.0
|
| 159 |
+
return plow, phigh
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
def _binom_wilson_conf_int(k, n, confidence_level, alternative, correction):
|
| 163 |
+
# This function assumes that the arguments have already been validated.
|
| 164 |
+
# In particular, `alternative` must be one of 'two-sided', 'less' or
|
| 165 |
+
# 'greater'.
|
| 166 |
+
p = k / n
|
| 167 |
+
if alternative == 'two-sided':
|
| 168 |
+
z = ndtri(0.5 + 0.5*confidence_level)
|
| 169 |
+
else:
|
| 170 |
+
z = ndtri(confidence_level)
|
| 171 |
+
|
| 172 |
+
# For reference, the formulas implemented here are from
|
| 173 |
+
# Newcombe (1998) (ref. [3] in the proportion_ci docstring).
|
| 174 |
+
denom = 2*(n + z**2)
|
| 175 |
+
center = (2*n*p + z**2)/denom
|
| 176 |
+
q = 1 - p
|
| 177 |
+
if correction:
|
| 178 |
+
if alternative == 'less' or k == 0:
|
| 179 |
+
lo = 0.0
|
| 180 |
+
else:
|
| 181 |
+
dlo = (1 + z*sqrt(z**2 - 2 - 1/n + 4*p*(n*q + 1))) / denom
|
| 182 |
+
lo = center - dlo
|
| 183 |
+
if alternative == 'greater' or k == n:
|
| 184 |
+
hi = 1.0
|
| 185 |
+
else:
|
| 186 |
+
dhi = (1 + z*sqrt(z**2 + 2 - 1/n + 4*p*(n*q - 1))) / denom
|
| 187 |
+
hi = center + dhi
|
| 188 |
+
else:
|
| 189 |
+
delta = z/denom * sqrt(4*n*p*q + z**2)
|
| 190 |
+
if alternative == 'less' or k == 0:
|
| 191 |
+
lo = 0.0
|
| 192 |
+
else:
|
| 193 |
+
lo = center - delta
|
| 194 |
+
if alternative == 'greater' or k == n:
|
| 195 |
+
hi = 1.0
|
| 196 |
+
else:
|
| 197 |
+
hi = center + delta
|
| 198 |
+
|
| 199 |
+
return lo, hi
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
def binomtest(k, n, p=0.5, alternative='two-sided'):
|
| 203 |
+
"""
|
| 204 |
+
Perform a test that the probability of success is p.
|
| 205 |
+
|
| 206 |
+
The binomial test [1]_ is a test of the null hypothesis that the
|
| 207 |
+
probability of success in a Bernoulli experiment is `p`.
|
| 208 |
+
|
| 209 |
+
Details of the test can be found in many texts on statistics, such
|
| 210 |
+
as section 24.5 of [2]_.
|
| 211 |
+
|
| 212 |
+
Parameters
|
| 213 |
+
----------
|
| 214 |
+
k : int
|
| 215 |
+
The number of successes.
|
| 216 |
+
n : int
|
| 217 |
+
The number of trials.
|
| 218 |
+
p : float, optional
|
| 219 |
+
The hypothesized probability of success, i.e. the expected
|
| 220 |
+
proportion of successes. The value must be in the interval
|
| 221 |
+
``0 <= p <= 1``. The default value is ``p = 0.5``.
|
| 222 |
+
alternative : {'two-sided', 'greater', 'less'}, optional
|
| 223 |
+
Indicates the alternative hypothesis. The default value is
|
| 224 |
+
'two-sided'.
|
| 225 |
+
|
| 226 |
+
Returns
|
| 227 |
+
-------
|
| 228 |
+
result : `~scipy.stats._result_classes.BinomTestResult` instance
|
| 229 |
+
The return value is an object with the following attributes:
|
| 230 |
+
|
| 231 |
+
k : int
|
| 232 |
+
The number of successes (copied from `binomtest` input).
|
| 233 |
+
n : int
|
| 234 |
+
The number of trials (copied from `binomtest` input).
|
| 235 |
+
alternative : str
|
| 236 |
+
Indicates the alternative hypothesis specified in the input
|
| 237 |
+
to `binomtest`. It will be one of ``'two-sided'``, ``'greater'``,
|
| 238 |
+
or ``'less'``.
|
| 239 |
+
statistic : float
|
| 240 |
+
The estimate of the proportion of successes.
|
| 241 |
+
pvalue : float
|
| 242 |
+
The p-value of the hypothesis test.
|
| 243 |
+
|
| 244 |
+
The object has the following methods:
|
| 245 |
+
|
| 246 |
+
proportion_ci(confidence_level=0.95, method='exact') :
|
| 247 |
+
Compute the confidence interval for ``statistic``.
|
| 248 |
+
|
| 249 |
+
Notes
|
| 250 |
+
-----
|
| 251 |
+
.. versionadded:: 1.7.0
|
| 252 |
+
|
| 253 |
+
References
|
| 254 |
+
----------
|
| 255 |
+
.. [1] Binomial test, https://en.wikipedia.org/wiki/Binomial_test
|
| 256 |
+
.. [2] Jerrold H. Zar, Biostatistical Analysis (fifth edition),
|
| 257 |
+
Prentice Hall, Upper Saddle River, New Jersey USA (2010)
|
| 258 |
+
|
| 259 |
+
Examples
|
| 260 |
+
--------
|
| 261 |
+
>>> from scipy.stats import binomtest
|
| 262 |
+
|
| 263 |
+
A car manufacturer claims that no more than 10% of their cars are unsafe.
|
| 264 |
+
15 cars are inspected for safety, 3 were found to be unsafe. Test the
|
| 265 |
+
manufacturer's claim:
|
| 266 |
+
|
| 267 |
+
>>> result = binomtest(3, n=15, p=0.1, alternative='greater')
|
| 268 |
+
>>> result.pvalue
|
| 269 |
+
0.18406106910639114
|
| 270 |
+
|
| 271 |
+
The null hypothesis cannot be rejected at the 5% level of significance
|
| 272 |
+
because the returned p-value is greater than the critical value of 5%.
|
| 273 |
+
|
| 274 |
+
The test statistic is equal to the estimated proportion, which is simply
|
| 275 |
+
``3/15``:
|
| 276 |
+
|
| 277 |
+
>>> result.statistic
|
| 278 |
+
0.2
|
| 279 |
+
|
| 280 |
+
We can use the `proportion_ci()` method of the result to compute the
|
| 281 |
+
confidence interval of the estimate:
|
| 282 |
+
|
| 283 |
+
>>> result.proportion_ci(confidence_level=0.95)
|
| 284 |
+
ConfidenceInterval(low=0.05684686759024681, high=1.0)
|
| 285 |
+
|
| 286 |
+
"""
|
| 287 |
+
k = _validate_int(k, 'k', minimum=0)
|
| 288 |
+
n = _validate_int(n, 'n', minimum=1)
|
| 289 |
+
if k > n:
|
| 290 |
+
raise ValueError(f'k ({k}) must not be greater than n ({n}).')
|
| 291 |
+
|
| 292 |
+
if not (0 <= p <= 1):
|
| 293 |
+
raise ValueError(f"p ({p}) must be in range [0,1]")
|
| 294 |
+
|
| 295 |
+
if alternative not in ('two-sided', 'less', 'greater'):
|
| 296 |
+
raise ValueError(f"alternative ('{alternative}') not recognized; \n"
|
| 297 |
+
"must be 'two-sided', 'less' or 'greater'")
|
| 298 |
+
if alternative == 'less':
|
| 299 |
+
pval = binom.cdf(k, n, p)
|
| 300 |
+
elif alternative == 'greater':
|
| 301 |
+
pval = binom.sf(k-1, n, p)
|
| 302 |
+
else:
|
| 303 |
+
# alternative is 'two-sided'
|
| 304 |
+
d = binom.pmf(k, n, p)
|
| 305 |
+
rerr = 1 + 1e-7
|
| 306 |
+
if k == p * n:
|
| 307 |
+
# special case as shortcut, would also be handled by `else` below
|
| 308 |
+
pval = 1.
|
| 309 |
+
elif k < p * n:
|
| 310 |
+
ix = _binary_search_for_binom_tst(lambda x1: -binom.pmf(x1, n, p),
|
| 311 |
+
-d*rerr, np.ceil(p * n), n)
|
| 312 |
+
# y is the number of terms between mode and n that are <= d*rerr.
|
| 313 |
+
# ix gave us the first term where a(ix) <= d*rerr < a(ix-1)
|
| 314 |
+
# if the first equality doesn't hold, y=n-ix. Otherwise, we
|
| 315 |
+
# need to include ix as well as the equality holds. Note that
|
| 316 |
+
# the equality will hold in very very rare situations due to rerr.
|
| 317 |
+
y = n - ix + int(d*rerr == binom.pmf(ix, n, p))
|
| 318 |
+
pval = binom.cdf(k, n, p) + binom.sf(n - y, n, p)
|
| 319 |
+
else:
|
| 320 |
+
ix = _binary_search_for_binom_tst(lambda x1: binom.pmf(x1, n, p),
|
| 321 |
+
d*rerr, 0, np.floor(p * n))
|
| 322 |
+
# y is the number of terms between 0 and mode that are <= d*rerr.
|
| 323 |
+
# we need to add a 1 to account for the 0 index.
|
| 324 |
+
# For comparing this with old behavior, see
|
| 325 |
+
# tst_binary_srch_for_binom_tst method in test_morestats.
|
| 326 |
+
y = ix + 1
|
| 327 |
+
pval = binom.cdf(y-1, n, p) + binom.sf(k-1, n, p)
|
| 328 |
+
|
| 329 |
+
pval = min(1.0, pval)
|
| 330 |
+
|
| 331 |
+
result = BinomTestResult(k=k, n=n, alternative=alternative,
|
| 332 |
+
statistic=k/n, pvalue=pval)
|
| 333 |
+
return result
|
| 334 |
+
|
| 335 |
+
|
| 336 |
+
def _binary_search_for_binom_tst(a, d, lo, hi):
|
| 337 |
+
"""
|
| 338 |
+
Conducts an implicit binary search on a function specified by `a`.
|
| 339 |
+
|
| 340 |
+
Meant to be used on the binomial PMF for the case of two-sided tests
|
| 341 |
+
to obtain the value on the other side of the mode where the tail
|
| 342 |
+
probability should be computed. The values on either side of
|
| 343 |
+
the mode are always in order, meaning binary search is applicable.
|
| 344 |
+
|
| 345 |
+
Parameters
|
| 346 |
+
----------
|
| 347 |
+
a : callable
|
| 348 |
+
The function over which to perform binary search. Its values
|
| 349 |
+
for inputs lo and hi should be in ascending order.
|
| 350 |
+
d : float
|
| 351 |
+
The value to search.
|
| 352 |
+
lo : int
|
| 353 |
+
The lower end of range to search.
|
| 354 |
+
hi : int
|
| 355 |
+
The higher end of the range to search.
|
| 356 |
+
|
| 357 |
+
Returns
|
| 358 |
+
-------
|
| 359 |
+
int
|
| 360 |
+
The index, i between lo and hi
|
| 361 |
+
such that a(i)<=d<a(i+1)
|
| 362 |
+
"""
|
| 363 |
+
while lo < hi:
|
| 364 |
+
mid = lo + (hi-lo)//2
|
| 365 |
+
midval = a(mid)
|
| 366 |
+
if midval < d:
|
| 367 |
+
lo = mid+1
|
| 368 |
+
elif midval > d:
|
| 369 |
+
hi = mid-1
|
| 370 |
+
else:
|
| 371 |
+
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
from functools import partial
|
| 3 |
+
from scipy import stats
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def _bws_input_validation(x, y, alternative, method):
|
| 7 |
+
''' Input validation and standardization for bws test'''
|
| 8 |
+
x, y = np.atleast_1d(x, y)
|
| 9 |
+
if x.ndim > 1 or y.ndim > 1:
|
| 10 |
+
raise ValueError('`x` and `y` must be exactly one-dimensional.')
|
| 11 |
+
if np.isnan(x).any() or np.isnan(y).any():
|
| 12 |
+
raise ValueError('`x` and `y` must not contain NaNs.')
|
| 13 |
+
if np.size(x) == 0 or np.size(y) == 0:
|
| 14 |
+
raise ValueError('`x` and `y` must be of nonzero size.')
|
| 15 |
+
|
| 16 |
+
z = stats.rankdata(np.concatenate((x, y)))
|
| 17 |
+
x, y = z[:len(x)], z[len(x):]
|
| 18 |
+
|
| 19 |
+
alternatives = {'two-sided', 'less', 'greater'}
|
| 20 |
+
alternative = alternative.lower()
|
| 21 |
+
if alternative not in alternatives:
|
| 22 |
+
raise ValueError(f'`alternative` must be one of {alternatives}.')
|
| 23 |
+
|
| 24 |
+
method = stats.PermutationMethod() if method is None else method
|
| 25 |
+
if not isinstance(method, stats.PermutationMethod):
|
| 26 |
+
raise ValueError('`method` must be an instance of '
|
| 27 |
+
'`scipy.stats.PermutationMethod`')
|
| 28 |
+
|
| 29 |
+
return x, y, alternative, method
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def _bws_statistic(x, y, alternative, axis):
|
| 33 |
+
'''Compute the BWS test statistic for two independent samples'''
|
| 34 |
+
# Public function currently does not accept `axis`, but `permutation_test`
|
| 35 |
+
# uses `axis` to make vectorized call.
|
| 36 |
+
|
| 37 |
+
Ri, Hj = np.sort(x, axis=axis), np.sort(y, axis=axis)
|
| 38 |
+
n, m = Ri.shape[axis], Hj.shape[axis]
|
| 39 |
+
i, j = np.arange(1, n+1), np.arange(1, m+1)
|
| 40 |
+
|
| 41 |
+
Bx_num = Ri - (m + n)/n * i
|
| 42 |
+
By_num = Hj - (m + n)/m * j
|
| 43 |
+
|
| 44 |
+
if alternative == 'two-sided':
|
| 45 |
+
Bx_num *= Bx_num
|
| 46 |
+
By_num *= By_num
|
| 47 |
+
else:
|
| 48 |
+
Bx_num *= np.abs(Bx_num)
|
| 49 |
+
By_num *= np.abs(By_num)
|
| 50 |
+
|
| 51 |
+
Bx_den = i/(n+1) * (1 - i/(n+1)) * m*(m+n)/n
|
| 52 |
+
By_den = j/(m+1) * (1 - j/(m+1)) * n*(m+n)/m
|
| 53 |
+
|
| 54 |
+
Bx = 1/n * np.sum(Bx_num/Bx_den, axis=axis)
|
| 55 |
+
By = 1/m * np.sum(By_num/By_den, axis=axis)
|
| 56 |
+
|
| 57 |
+
B = (Bx + By) / 2 if alternative == 'two-sided' else (Bx - By) / 2
|
| 58 |
+
|
| 59 |
+
return B
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def bws_test(x, y, *, alternative="two-sided", method=None):
|
| 63 |
+
r'''Perform the Baumgartner-Weiss-Schindler test on two independent samples.
|
| 64 |
+
|
| 65 |
+
The Baumgartner-Weiss-Schindler (BWS) test is a nonparametric test of
|
| 66 |
+
the null hypothesis that the distribution underlying sample `x`
|
| 67 |
+
is the same as the distribution underlying sample `y`. Unlike
|
| 68 |
+
the Kolmogorov-Smirnov, Wilcoxon, and Cramer-Von Mises tests,
|
| 69 |
+
the BWS test weights the integral by the variance of the difference
|
| 70 |
+
in cumulative distribution functions (CDFs), emphasizing the tails of the
|
| 71 |
+
distributions, which increases the power of the test in many applications.
|
| 72 |
+
|
| 73 |
+
Parameters
|
| 74 |
+
----------
|
| 75 |
+
x, y : array-like
|
| 76 |
+
1-d arrays of samples.
|
| 77 |
+
alternative : {'two-sided', 'less', 'greater'}, optional
|
| 78 |
+
Defines the alternative hypothesis. Default is 'two-sided'.
|
| 79 |
+
Let *F(u)* and *G(u)* be the cumulative distribution functions of the
|
| 80 |
+
distributions underlying `x` and `y`, respectively. Then the following
|
| 81 |
+
alternative hypotheses are available:
|
| 82 |
+
|
| 83 |
+
* 'two-sided': the distributions are not equal, i.e. *F(u) ≠ G(u)* for
|
| 84 |
+
at least one *u*.
|
| 85 |
+
* 'less': the distribution underlying `x` is stochastically less than
|
| 86 |
+
the distribution underlying `y`, i.e. *F(u) >= G(u)* for all *u*.
|
| 87 |
+
* 'greater': the distribution underlying `x` is stochastically greater
|
| 88 |
+
than the distribution underlying `y`, i.e. *F(u) <= G(u)* for all
|
| 89 |
+
*u*.
|
| 90 |
+
|
| 91 |
+
Under a more restrictive set of assumptions, the alternative hypotheses
|
| 92 |
+
can be expressed in terms of the locations of the distributions;
|
| 93 |
+
see [2] section 5.1.
|
| 94 |
+
method : PermutationMethod, optional
|
| 95 |
+
Configures the method used to compute the p-value. The default is
|
| 96 |
+
the default `PermutationMethod` object.
|
| 97 |
+
|
| 98 |
+
Returns
|
| 99 |
+
-------
|
| 100 |
+
res : PermutationTestResult
|
| 101 |
+
An object with attributes:
|
| 102 |
+
|
| 103 |
+
statistic : float
|
| 104 |
+
The observed test statistic of the data.
|
| 105 |
+
pvalue : float
|
| 106 |
+
The p-value for the given alternative.
|
| 107 |
+
null_distribution : ndarray
|
| 108 |
+
The values of the test statistic generated under the null hypothesis.
|
| 109 |
+
|
| 110 |
+
See also
|
| 111 |
+
--------
|
| 112 |
+
scipy.stats.wilcoxon, scipy.stats.mannwhitneyu, scipy.stats.ttest_ind
|
| 113 |
+
|
| 114 |
+
Notes
|
| 115 |
+
-----
|
| 116 |
+
When ``alternative=='two-sided'``, the statistic is defined by the
|
| 117 |
+
equations given in [1]_ Section 2. This statistic is not appropriate for
|
| 118 |
+
one-sided alternatives; in that case, the statistic is the *negative* of
|
| 119 |
+
that given by the equations in [1]_ Section 2. Consequently, when the
|
| 120 |
+
distribution of the first sample is stochastically greater than that of the
|
| 121 |
+
second sample, the statistic will tend to be positive.
|
| 122 |
+
|
| 123 |
+
References
|
| 124 |
+
----------
|
| 125 |
+
.. [1] Neuhäuser, M. (2005). Exact Tests Based on the
|
| 126 |
+
Baumgartner-Weiss-Schindler Statistic: A Survey. Statistical Papers,
|
| 127 |
+
46(1), 1-29.
|
| 128 |
+
.. [2] Fay, M. P., & Proschan, M. A. (2010). Wilcoxon-Mann-Whitney or t-test?
|
| 129 |
+
On assumptions for hypothesis tests and multiple interpretations of
|
| 130 |
+
decision rules. Statistics surveys, 4, 1.
|
| 131 |
+
|
| 132 |
+
Examples
|
| 133 |
+
--------
|
| 134 |
+
We follow the example of table 3 in [1]_: Fourteen children were divided
|
| 135 |
+
randomly into two groups. Their ranks at performing a specific tests are
|
| 136 |
+
as follows.
|
| 137 |
+
|
| 138 |
+
>>> import numpy as np
|
| 139 |
+
>>> x = [1, 2, 3, 4, 6, 7, 8]
|
| 140 |
+
>>> y = [5, 9, 10, 11, 12, 13, 14]
|
| 141 |
+
|
| 142 |
+
We use the BWS test to assess whether there is a statistically significant
|
| 143 |
+
difference between the two groups.
|
| 144 |
+
The null hypothesis is that there is no difference in the distributions of
|
| 145 |
+
performance between the two groups. We decide that a significance level of
|
| 146 |
+
1% is required to reject the null hypothesis in favor of the alternative
|
| 147 |
+
that the distributions are different.
|
| 148 |
+
Since the number of samples is very small, we can compare the observed test
|
| 149 |
+
statistic against the *exact* distribution of the test statistic under the
|
| 150 |
+
null hypothesis.
|
| 151 |
+
|
| 152 |
+
>>> from scipy.stats import bws_test
|
| 153 |
+
>>> res = bws_test(x, y)
|
| 154 |
+
>>> print(res.statistic)
|
| 155 |
+
5.132167152575315
|
| 156 |
+
|
| 157 |
+
This agrees with :math:`B = 5.132` reported in [1]_. The *p*-value produced
|
| 158 |
+
by `bws_test` also agrees with :math:`p = 0.0029` reported in [1]_.
|
| 159 |
+
|
| 160 |
+
>>> print(res.pvalue)
|
| 161 |
+
0.002913752913752914
|
| 162 |
+
|
| 163 |
+
Because the p-value is below our threshold of 1%, we take this as evidence
|
| 164 |
+
against the null hypothesis in favor of the alternative that there is a
|
| 165 |
+
difference in performance between the two groups.
|
| 166 |
+
'''
|
| 167 |
+
|
| 168 |
+
x, y, alternative, method = _bws_input_validation(x, y, alternative,
|
| 169 |
+
method)
|
| 170 |
+
bws_statistic = partial(_bws_statistic, alternative=alternative)
|
| 171 |
+
|
| 172 |
+
permutation_alternative = 'less' if alternative == 'less' else 'greater'
|
| 173 |
+
res = stats.permutation_test((x, y), bws_statistic,
|
| 174 |
+
alternative=permutation_alternative,
|
| 175 |
+
**method._asdict())
|
| 176 |
+
|
| 177 |
+
return res
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/stats/_censored_data.py
ADDED
|
@@ -0,0 +1,459 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def _validate_1d(a, name, allow_inf=False):
|
| 5 |
+
if np.ndim(a) != 1:
|
| 6 |
+
raise ValueError(f'`{name}` must be a one-dimensional sequence.')
|
| 7 |
+
if np.isnan(a).any():
|
| 8 |
+
raise ValueError(f'`{name}` must not contain nan.')
|
| 9 |
+
if not allow_inf and np.isinf(a).any():
|
| 10 |
+
raise ValueError(f'`{name}` must contain only finite values.')
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def _validate_interval(interval):
|
| 14 |
+
interval = np.asarray(interval)
|
| 15 |
+
if interval.shape == (0,):
|
| 16 |
+
# The input was a sequence with length 0.
|
| 17 |
+
interval = interval.reshape((0, 2))
|
| 18 |
+
if interval.ndim != 2 or interval.shape[-1] != 2:
|
| 19 |
+
raise ValueError('`interval` must be a two-dimensional array with '
|
| 20 |
+
'shape (m, 2), where m is the number of '
|
| 21 |
+
'interval-censored values, but got shape '
|
| 22 |
+
f'{interval.shape}')
|
| 23 |
+
|
| 24 |
+
if np.isnan(interval).any():
|
| 25 |
+
raise ValueError('`interval` must not contain nan.')
|
| 26 |
+
if np.isinf(interval).all(axis=1).any():
|
| 27 |
+
raise ValueError('In each row in `interval`, both values must not'
|
| 28 |
+
' be infinite.')
|
| 29 |
+
if (interval[:, 0] > interval[:, 1]).any():
|
| 30 |
+
raise ValueError('In each row of `interval`, the left value must not'
|
| 31 |
+
' exceed the right value.')
|
| 32 |
+
|
| 33 |
+
uncensored_mask = interval[:, 0] == interval[:, 1]
|
| 34 |
+
left_mask = np.isinf(interval[:, 0])
|
| 35 |
+
right_mask = np.isinf(interval[:, 1])
|
| 36 |
+
interval_mask = np.isfinite(interval).all(axis=1) & ~uncensored_mask
|
| 37 |
+
|
| 38 |
+
uncensored2 = interval[uncensored_mask, 0]
|
| 39 |
+
left2 = interval[left_mask, 1]
|
| 40 |
+
right2 = interval[right_mask, 0]
|
| 41 |
+
interval2 = interval[interval_mask]
|
| 42 |
+
|
| 43 |
+
return uncensored2, left2, right2, interval2
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def _validate_x_censored(x, censored):
|
| 47 |
+
x = np.asarray(x)
|
| 48 |
+
if x.ndim != 1:
|
| 49 |
+
raise ValueError('`x` must be one-dimensional.')
|
| 50 |
+
censored = np.asarray(censored)
|
| 51 |
+
if censored.ndim != 1:
|
| 52 |
+
raise ValueError('`censored` must be one-dimensional.')
|
| 53 |
+
if (~np.isfinite(x)).any():
|
| 54 |
+
raise ValueError('`x` must not contain nan or inf.')
|
| 55 |
+
if censored.size != x.size:
|
| 56 |
+
raise ValueError('`x` and `censored` must have the same length.')
|
| 57 |
+
return x, censored.astype(bool)
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
class CensoredData:
|
| 61 |
+
"""
|
| 62 |
+
Instances of this class represent censored data.
|
| 63 |
+
|
| 64 |
+
Instances may be passed to the ``fit`` method of continuous
|
| 65 |
+
univariate SciPy distributions for maximum likelihood estimation.
|
| 66 |
+
The *only* method of the univariate continuous distributions that
|
| 67 |
+
understands `CensoredData` is the ``fit`` method. An instance of
|
| 68 |
+
`CensoredData` can not be passed to methods such as ``pdf`` and
|
| 69 |
+
``cdf``.
|
| 70 |
+
|
| 71 |
+
An observation is said to be *censored* when the precise value is unknown,
|
| 72 |
+
but it has a known upper and/or lower bound. The conventional terminology
|
| 73 |
+
is:
|
| 74 |
+
|
| 75 |
+
* left-censored: an observation is below a certain value but it is
|
| 76 |
+
unknown by how much.
|
| 77 |
+
* right-censored: an observation is above a certain value but it is
|
| 78 |
+
unknown by how much.
|
| 79 |
+
* interval-censored: an observation lies somewhere on an interval between
|
| 80 |
+
two values.
|
| 81 |
+
|
| 82 |
+
Left-, right-, and interval-censored data can be represented by
|
| 83 |
+
`CensoredData`.
|
| 84 |
+
|
| 85 |
+
For convenience, the class methods ``left_censored`` and
|
| 86 |
+
``right_censored`` are provided to create a `CensoredData`
|
| 87 |
+
instance from a single one-dimensional array of measurements
|
| 88 |
+
and a corresponding boolean array to indicate which measurements
|
| 89 |
+
are censored. The class method ``interval_censored`` accepts two
|
| 90 |
+
one-dimensional arrays that hold the lower and upper bounds of the
|
| 91 |
+
intervals.
|
| 92 |
+
|
| 93 |
+
Parameters
|
| 94 |
+
----------
|
| 95 |
+
uncensored : array_like, 1D
|
| 96 |
+
Uncensored observations.
|
| 97 |
+
left : array_like, 1D
|
| 98 |
+
Left-censored observations.
|
| 99 |
+
right : array_like, 1D
|
| 100 |
+
Right-censored observations.
|
| 101 |
+
interval : array_like, 2D, with shape (m, 2)
|
| 102 |
+
Interval-censored observations. Each row ``interval[k, :]``
|
| 103 |
+
represents the interval for the kth interval-censored observation.
|
| 104 |
+
|
| 105 |
+
Notes
|
| 106 |
+
-----
|
| 107 |
+
In the input array `interval`, the lower bound of the interval may
|
| 108 |
+
be ``-inf``, and the upper bound may be ``inf``, but at least one must be
|
| 109 |
+
finite. When the lower bound is ``-inf``, the row represents a left-
|
| 110 |
+
censored observation, and when the upper bound is ``inf``, the row
|
| 111 |
+
represents a right-censored observation. If the length of an interval
|
| 112 |
+
is 0 (i.e. ``interval[k, 0] == interval[k, 1]``, the observation is
|
| 113 |
+
treated as uncensored. So one can represent all the types of censored
|
| 114 |
+
and uncensored data in ``interval``, but it is generally more convenient
|
| 115 |
+
to use `uncensored`, `left` and `right` for uncensored, left-censored and
|
| 116 |
+
right-censored observations, respectively.
|
| 117 |
+
|
| 118 |
+
Examples
|
| 119 |
+
--------
|
| 120 |
+
In the most general case, a censored data set may contain values that
|
| 121 |
+
are left-censored, right-censored, interval-censored, and uncensored.
|
| 122 |
+
For example, here we create a data set with five observations. Two
|
| 123 |
+
are uncensored (values 1 and 1.5), one is a left-censored observation
|
| 124 |
+
of 0, one is a right-censored observation of 10 and one is
|
| 125 |
+
interval-censored in the interval [2, 3].
|
| 126 |
+
|
| 127 |
+
>>> import numpy as np
|
| 128 |
+
>>> from scipy.stats import CensoredData
|
| 129 |
+
>>> data = CensoredData(uncensored=[1, 1.5], left=[0], right=[10],
|
| 130 |
+
... interval=[[2, 3]])
|
| 131 |
+
>>> print(data)
|
| 132 |
+
CensoredData(5 values: 2 not censored, 1 left-censored,
|
| 133 |
+
1 right-censored, 1 interval-censored)
|
| 134 |
+
|
| 135 |
+
Equivalently,
|
| 136 |
+
|
| 137 |
+
>>> data = CensoredData(interval=[[1, 1],
|
| 138 |
+
... [1.5, 1.5],
|
| 139 |
+
... [-np.inf, 0],
|
| 140 |
+
... [10, np.inf],
|
| 141 |
+
... [2, 3]])
|
| 142 |
+
>>> print(data)
|
| 143 |
+
CensoredData(5 values: 2 not censored, 1 left-censored,
|
| 144 |
+
1 right-censored, 1 interval-censored)
|
| 145 |
+
|
| 146 |
+
A common case is to have a mix of uncensored observations and censored
|
| 147 |
+
observations that are all right-censored (or all left-censored). For
|
| 148 |
+
example, consider an experiment in which six devices are started at
|
| 149 |
+
various times and left running until they fail. Assume that time is
|
| 150 |
+
measured in hours, and the experiment is stopped after 30 hours, even
|
| 151 |
+
if all the devices have not failed by that time. We might end up with
|
| 152 |
+
data such as this::
|
| 153 |
+
|
| 154 |
+
Device Start-time Fail-time Time-to-failure
|
| 155 |
+
1 0 13 13
|
| 156 |
+
2 2 24 22
|
| 157 |
+
3 5 22 17
|
| 158 |
+
4 8 23 15
|
| 159 |
+
5 10 *** >20
|
| 160 |
+
6 12 *** >18
|
| 161 |
+
|
| 162 |
+
Two of the devices had not failed when the experiment was stopped;
|
| 163 |
+
the observations of the time-to-failure for these two devices are
|
| 164 |
+
right-censored. We can represent this data with
|
| 165 |
+
|
| 166 |
+
>>> data = CensoredData(uncensored=[13, 22, 17, 15], right=[20, 18])
|
| 167 |
+
>>> print(data)
|
| 168 |
+
CensoredData(6 values: 4 not censored, 2 right-censored)
|
| 169 |
+
|
| 170 |
+
Alternatively, we can use the method `CensoredData.right_censored` to
|
| 171 |
+
create a representation of this data. The time-to-failure observations
|
| 172 |
+
are put the list ``ttf``. The ``censored`` list indicates which values
|
| 173 |
+
in ``ttf`` are censored.
|
| 174 |
+
|
| 175 |
+
>>> ttf = [13, 22, 17, 15, 20, 18]
|
| 176 |
+
>>> censored = [False, False, False, False, True, True]
|
| 177 |
+
|
| 178 |
+
Pass these lists to `CensoredData.right_censored` to create an
|
| 179 |
+
instance of `CensoredData`.
|
| 180 |
+
|
| 181 |
+
>>> data = CensoredData.right_censored(ttf, censored)
|
| 182 |
+
>>> print(data)
|
| 183 |
+
CensoredData(6 values: 4 not censored, 2 right-censored)
|
| 184 |
+
|
| 185 |
+
If the input data is interval censored and already stored in two
|
| 186 |
+
arrays, one holding the low end of the intervals and another
|
| 187 |
+
holding the high ends, the class method ``interval_censored`` can
|
| 188 |
+
be used to create the `CensoredData` instance.
|
| 189 |
+
|
| 190 |
+
This example creates an instance with four interval-censored values.
|
| 191 |
+
The intervals are [10, 11], [0.5, 1], [2, 3], and [12.5, 13.5].
|
| 192 |
+
|
| 193 |
+
>>> a = [10, 0.5, 2, 12.5] # Low ends of the intervals
|
| 194 |
+
>>> b = [11, 1.0, 3, 13.5] # High ends of the intervals
|
| 195 |
+
>>> data = CensoredData.interval_censored(low=a, high=b)
|
| 196 |
+
>>> print(data)
|
| 197 |
+
CensoredData(4 values: 0 not censored, 4 interval-censored)
|
| 198 |
+
|
| 199 |
+
Finally, we create and censor some data from the `weibull_min`
|
| 200 |
+
distribution, and then fit `weibull_min` to that data. We'll assume
|
| 201 |
+
that the location parameter is known to be 0.
|
| 202 |
+
|
| 203 |
+
>>> from scipy.stats import weibull_min
|
| 204 |
+
>>> rng = np.random.default_rng()
|
| 205 |
+
|
| 206 |
+
Create the random data set.
|
| 207 |
+
|
| 208 |
+
>>> x = weibull_min.rvs(2.5, loc=0, scale=30, size=250, random_state=rng)
|
| 209 |
+
>>> x[x > 40] = 40 # Right-censor values greater or equal to 40.
|
| 210 |
+
|
| 211 |
+
Create the `CensoredData` instance with the `right_censored` method.
|
| 212 |
+
The censored values are those where the value is 40.
|
| 213 |
+
|
| 214 |
+
>>> data = CensoredData.right_censored(x, x == 40)
|
| 215 |
+
>>> print(data)
|
| 216 |
+
CensoredData(250 values: 215 not censored, 35 right-censored)
|
| 217 |
+
|
| 218 |
+
35 values have been right-censored.
|
| 219 |
+
|
| 220 |
+
Fit `weibull_min` to the censored data. We expect to shape and scale
|
| 221 |
+
to be approximately 2.5 and 30, respectively.
|
| 222 |
+
|
| 223 |
+
>>> weibull_min.fit(data, floc=0)
|
| 224 |
+
(2.3575922823897315, 0, 30.40650074451254)
|
| 225 |
+
|
| 226 |
+
"""
|
| 227 |
+
|
| 228 |
+
def __init__(self, uncensored=None, *, left=None, right=None,
|
| 229 |
+
interval=None):
|
| 230 |
+
if uncensored is None:
|
| 231 |
+
uncensored = []
|
| 232 |
+
if left is None:
|
| 233 |
+
left = []
|
| 234 |
+
if right is None:
|
| 235 |
+
right = []
|
| 236 |
+
if interval is None:
|
| 237 |
+
interval = np.empty((0, 2))
|
| 238 |
+
|
| 239 |
+
_validate_1d(uncensored, 'uncensored')
|
| 240 |
+
_validate_1d(left, 'left')
|
| 241 |
+
_validate_1d(right, 'right')
|
| 242 |
+
uncensored2, left2, right2, interval2 = _validate_interval(interval)
|
| 243 |
+
|
| 244 |
+
self._uncensored = np.concatenate((uncensored, uncensored2))
|
| 245 |
+
self._left = np.concatenate((left, left2))
|
| 246 |
+
self._right = np.concatenate((right, right2))
|
| 247 |
+
# Note that by construction, the private attribute _interval
|
| 248 |
+
# will be a 2D array that contains only finite values representing
|
| 249 |
+
# intervals with nonzero but finite length.
|
| 250 |
+
self._interval = interval2
|
| 251 |
+
|
| 252 |
+
def __repr__(self):
|
| 253 |
+
uncensored_str = " ".join(np.array_repr(self._uncensored).split())
|
| 254 |
+
left_str = " ".join(np.array_repr(self._left).split())
|
| 255 |
+
right_str = " ".join(np.array_repr(self._right).split())
|
| 256 |
+
interval_str = " ".join(np.array_repr(self._interval).split())
|
| 257 |
+
return (f"CensoredData(uncensored={uncensored_str}, left={left_str}, "
|
| 258 |
+
f"right={right_str}, interval={interval_str})")
|
| 259 |
+
|
| 260 |
+
def __str__(self):
|
| 261 |
+
num_nc = len(self._uncensored)
|
| 262 |
+
num_lc = len(self._left)
|
| 263 |
+
num_rc = len(self._right)
|
| 264 |
+
num_ic = len(self._interval)
|
| 265 |
+
n = num_nc + num_lc + num_rc + num_ic
|
| 266 |
+
parts = [f'{num_nc} not censored']
|
| 267 |
+
if num_lc > 0:
|
| 268 |
+
parts.append(f'{num_lc} left-censored')
|
| 269 |
+
if num_rc > 0:
|
| 270 |
+
parts.append(f'{num_rc} right-censored')
|
| 271 |
+
if num_ic > 0:
|
| 272 |
+
parts.append(f'{num_ic} interval-censored')
|
| 273 |
+
return f'CensoredData({n} values: ' + ', '.join(parts) + ')'
|
| 274 |
+
|
| 275 |
+
# This is not a complete implementation of the arithmetic operators.
|
| 276 |
+
# All we need is subtracting a scalar and dividing by a scalar.
|
| 277 |
+
|
| 278 |
+
def __sub__(self, other):
|
| 279 |
+
return CensoredData(uncensored=self._uncensored - other,
|
| 280 |
+
left=self._left - other,
|
| 281 |
+
right=self._right - other,
|
| 282 |
+
interval=self._interval - other)
|
| 283 |
+
|
| 284 |
+
def __truediv__(self, other):
|
| 285 |
+
return CensoredData(uncensored=self._uncensored / other,
|
| 286 |
+
left=self._left / other,
|
| 287 |
+
right=self._right / other,
|
| 288 |
+
interval=self._interval / other)
|
| 289 |
+
|
| 290 |
+
def __len__(self):
|
| 291 |
+
"""
|
| 292 |
+
The number of values (censored and not censored).
|
| 293 |
+
"""
|
| 294 |
+
return (len(self._uncensored) + len(self._left) + len(self._right)
|
| 295 |
+
+ len(self._interval))
|
| 296 |
+
|
| 297 |
+
def num_censored(self):
|
| 298 |
+
"""
|
| 299 |
+
Number of censored values.
|
| 300 |
+
"""
|
| 301 |
+
return len(self._left) + len(self._right) + len(self._interval)
|
| 302 |
+
|
| 303 |
+
@classmethod
|
| 304 |
+
def right_censored(cls, x, censored):
|
| 305 |
+
"""
|
| 306 |
+
Create a `CensoredData` instance of right-censored data.
|
| 307 |
+
|
| 308 |
+
Parameters
|
| 309 |
+
----------
|
| 310 |
+
x : array_like
|
| 311 |
+
`x` is the array of observed data or measurements.
|
| 312 |
+
`x` must be a one-dimensional sequence of finite numbers.
|
| 313 |
+
censored : array_like of bool
|
| 314 |
+
`censored` must be a one-dimensional sequence of boolean
|
| 315 |
+
values. If ``censored[k]`` is True, the corresponding value
|
| 316 |
+
in `x` is right-censored. That is, the value ``x[k]``
|
| 317 |
+
is the lower bound of the true (but unknown) value.
|
| 318 |
+
|
| 319 |
+
Returns
|
| 320 |
+
-------
|
| 321 |
+
data : `CensoredData`
|
| 322 |
+
An instance of `CensoredData` that represents the
|
| 323 |
+
collection of uncensored and right-censored values.
|
| 324 |
+
|
| 325 |
+
Examples
|
| 326 |
+
--------
|
| 327 |
+
>>> from scipy.stats import CensoredData
|
| 328 |
+
|
| 329 |
+
Two uncensored values (4 and 10) and two right-censored values
|
| 330 |
+
(24 and 25).
|
| 331 |
+
|
| 332 |
+
>>> data = CensoredData.right_censored([4, 10, 24, 25],
|
| 333 |
+
... [False, False, True, True])
|
| 334 |
+
>>> data
|
| 335 |
+
CensoredData(uncensored=array([ 4., 10.]),
|
| 336 |
+
left=array([], dtype=float64), right=array([24., 25.]),
|
| 337 |
+
interval=array([], shape=(0, 2), dtype=float64))
|
| 338 |
+
>>> print(data)
|
| 339 |
+
CensoredData(4 values: 2 not censored, 2 right-censored)
|
| 340 |
+
"""
|
| 341 |
+
x, censored = _validate_x_censored(x, censored)
|
| 342 |
+
return cls(uncensored=x[~censored], right=x[censored])
|
| 343 |
+
|
| 344 |
+
@classmethod
|
| 345 |
+
def left_censored(cls, x, censored):
|
| 346 |
+
"""
|
| 347 |
+
Create a `CensoredData` instance of left-censored data.
|
| 348 |
+
|
| 349 |
+
Parameters
|
| 350 |
+
----------
|
| 351 |
+
x : array_like
|
| 352 |
+
`x` is the array of observed data or measurements.
|
| 353 |
+
`x` must be a one-dimensional sequence of finite numbers.
|
| 354 |
+
censored : array_like of bool
|
| 355 |
+
`censored` must be a one-dimensional sequence of boolean
|
| 356 |
+
values. If ``censored[k]`` is True, the corresponding value
|
| 357 |
+
in `x` is left-censored. That is, the value ``x[k]``
|
| 358 |
+
is the upper bound of the true (but unknown) value.
|
| 359 |
+
|
| 360 |
+
Returns
|
| 361 |
+
-------
|
| 362 |
+
data : `CensoredData`
|
| 363 |
+
An instance of `CensoredData` that represents the
|
| 364 |
+
collection of uncensored and left-censored values.
|
| 365 |
+
|
| 366 |
+
Examples
|
| 367 |
+
--------
|
| 368 |
+
>>> from scipy.stats import CensoredData
|
| 369 |
+
|
| 370 |
+
Two uncensored values (0.12 and 0.033) and two left-censored values
|
| 371 |
+
(both 1e-3).
|
| 372 |
+
|
| 373 |
+
>>> data = CensoredData.left_censored([0.12, 0.033, 1e-3, 1e-3],
|
| 374 |
+
... [False, False, True, True])
|
| 375 |
+
>>> data
|
| 376 |
+
CensoredData(uncensored=array([0.12 , 0.033]),
|
| 377 |
+
left=array([0.001, 0.001]), right=array([], dtype=float64),
|
| 378 |
+
interval=array([], shape=(0, 2), dtype=float64))
|
| 379 |
+
>>> print(data)
|
| 380 |
+
CensoredData(4 values: 2 not censored, 2 left-censored)
|
| 381 |
+
"""
|
| 382 |
+
x, censored = _validate_x_censored(x, censored)
|
| 383 |
+
return cls(uncensored=x[~censored], left=x[censored])
|
| 384 |
+
|
| 385 |
+
@classmethod
|
| 386 |
+
def interval_censored(cls, low, high):
|
| 387 |
+
"""
|
| 388 |
+
Create a `CensoredData` instance of interval-censored data.
|
| 389 |
+
|
| 390 |
+
This method is useful when all the data is interval-censored, and
|
| 391 |
+
the low and high ends of the intervals are already stored in
|
| 392 |
+
separate one-dimensional arrays.
|
| 393 |
+
|
| 394 |
+
Parameters
|
| 395 |
+
----------
|
| 396 |
+
low : array_like
|
| 397 |
+
The one-dimensional array containing the low ends of the
|
| 398 |
+
intervals.
|
| 399 |
+
high : array_like
|
| 400 |
+
The one-dimensional array containing the high ends of the
|
| 401 |
+
intervals.
|
| 402 |
+
|
| 403 |
+
Returns
|
| 404 |
+
-------
|
| 405 |
+
data : `CensoredData`
|
| 406 |
+
An instance of `CensoredData` that represents the
|
| 407 |
+
collection of censored values.
|
| 408 |
+
|
| 409 |
+
Examples
|
| 410 |
+
--------
|
| 411 |
+
>>> import numpy as np
|
| 412 |
+
>>> from scipy.stats import CensoredData
|
| 413 |
+
|
| 414 |
+
``a`` and ``b`` are the low and high ends of a collection of
|
| 415 |
+
interval-censored values.
|
| 416 |
+
|
| 417 |
+
>>> a = [0.5, 2.0, 3.0, 5.5]
|
| 418 |
+
>>> b = [1.0, 2.5, 3.5, 7.0]
|
| 419 |
+
>>> data = CensoredData.interval_censored(low=a, high=b)
|
| 420 |
+
>>> print(data)
|
| 421 |
+
CensoredData(4 values: 0 not censored, 4 interval-censored)
|
| 422 |
+
"""
|
| 423 |
+
_validate_1d(low, 'low', allow_inf=True)
|
| 424 |
+
_validate_1d(high, 'high', allow_inf=True)
|
| 425 |
+
if len(low) != len(high):
|
| 426 |
+
raise ValueError('`low` and `high` must have the same length.')
|
| 427 |
+
interval = np.column_stack((low, high))
|
| 428 |
+
uncensored, left, right, interval = _validate_interval(interval)
|
| 429 |
+
return cls(uncensored=uncensored, left=left, right=right,
|
| 430 |
+
interval=interval)
|
| 431 |
+
|
| 432 |
+
def _uncensor(self):
|
| 433 |
+
"""
|
| 434 |
+
This function is used when a non-censored version of the data
|
| 435 |
+
is needed to create a rough estimate of the parameters of a
|
| 436 |
+
distribution via the method of moments or some similar method.
|
| 437 |
+
The data is "uncensored" by taking the given endpoints as the
|
| 438 |
+
data for the left- or right-censored data, and the mean for the
|
| 439 |
+
interval-censored data.
|
| 440 |
+
"""
|
| 441 |
+
data = np.concatenate((self._uncensored, self._left, self._right,
|
| 442 |
+
self._interval.mean(axis=1)))
|
| 443 |
+
return data
|
| 444 |
+
|
| 445 |
+
def _supported(self, a, b):
|
| 446 |
+
"""
|
| 447 |
+
Return a subset of self containing the values that are in
|
| 448 |
+
(or overlap with) the interval (a, b).
|
| 449 |
+
"""
|
| 450 |
+
uncensored = self._uncensored
|
| 451 |
+
uncensored = uncensored[(a < uncensored) & (uncensored < b)]
|
| 452 |
+
left = self._left
|
| 453 |
+
left = left[a < left]
|
| 454 |
+
right = self._right
|
| 455 |
+
right = right[right < b]
|
| 456 |
+
interval = self._interval
|
| 457 |
+
interval = interval[(a < interval[:, 1]) & (interval[:, 0] < b)]
|
| 458 |
+
return CensoredData(uncensored, left=left, right=right,
|
| 459 |
+
interval=interval)
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/stats/_common.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from collections import namedtuple
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
ConfidenceInterval = namedtuple("ConfidenceInterval", ["low", "high"])
|
| 5 |
+
ConfidenceInterval. __doc__ = "Class for confidence intervals."
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/stats/_constants.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Statistics-related constants.
|
| 3 |
+
|
| 4 |
+
"""
|
| 5 |
+
import numpy as np
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
# The smallest representable positive number such that 1.0 + _EPS != 1.0.
|
| 9 |
+
_EPS = np.finfo(float).eps
|
| 10 |
+
|
| 11 |
+
# The largest [in magnitude] usable floating value.
|
| 12 |
+
_XMAX = np.finfo(float).max
|
| 13 |
+
|
| 14 |
+
# The log of the largest usable floating value; useful for knowing
|
| 15 |
+
# when exp(something) will overflow
|
| 16 |
+
_LOGXMAX = np.log(_XMAX)
|
| 17 |
+
|
| 18 |
+
# The smallest [in magnitude] usable (i.e. not subnormal) double precision
|
| 19 |
+
# floating value.
|
| 20 |
+
_XMIN = np.finfo(float).tiny
|
| 21 |
+
|
| 22 |
+
# The log of the smallest [in magnitude] usable (i.e not subnormal)
|
| 23 |
+
# double precision floating value.
|
| 24 |
+
_LOGXMIN = np.log(_XMIN)
|
| 25 |
+
|
| 26 |
+
# -special.psi(1)
|
| 27 |
+
_EULER = 0.577215664901532860606512090082402431042
|
| 28 |
+
|
| 29 |
+
# special.zeta(3, 1) Apery's constant
|
| 30 |
+
_ZETA3 = 1.202056903159594285399738161511449990765
|
| 31 |
+
|
| 32 |
+
# sqrt(pi)
|
| 33 |
+
_SQRT_PI = 1.772453850905516027298167483341145182798
|
| 34 |
+
|
| 35 |
+
# sqrt(2/pi)
|
| 36 |
+
_SQRT_2_OVER_PI = 0.7978845608028654
|
| 37 |
+
|
| 38 |
+
# log(pi)
|
| 39 |
+
_LOG_PI = 1.1447298858494002
|
| 40 |
+
|
| 41 |
+
# log(sqrt(2/pi))
|
| 42 |
+
_LOG_SQRT_2_OVER_PI = -0.22579135264472744
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/stats/_continuous_distns.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
miniconda3/envs/active_proaction/lib/python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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
from scipy import stats
|
| 3 |
+
from scipy.stats._stats_py import _SimpleNormal, SignificanceResult, _get_pvalue
|
| 4 |
+
from scipy.stats._axis_nan_policy import _axis_nan_policy_factory
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
__all__ = ['chatterjeexi']
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
# TODO:
|
| 11 |
+
# - Adjust to respect dtype
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def _xi_statistic(x, y, y_continuous):
|
| 15 |
+
# Compute xi correlation statistic
|
| 16 |
+
|
| 17 |
+
# `axis=-1` is guaranteed by _axis_nan_policy decorator
|
| 18 |
+
n = x.shape[-1]
|
| 19 |
+
|
| 20 |
+
# "Rearrange the data as (X(1), Y(1)), . . . ,(X(n), Y(n))
|
| 21 |
+
# such that X(1) ≤ ··· ≤ X(n)"
|
| 22 |
+
j = np.argsort(x, axis=-1)
|
| 23 |
+
j, y = np.broadcast_arrays(j, y)
|
| 24 |
+
y = np.take_along_axis(y, j, axis=-1)
|
| 25 |
+
|
| 26 |
+
# "Let ri be the rank of Y(i), that is, the number of j such that Y(j) ≤ Y(i)"
|
| 27 |
+
r = stats.rankdata(y, method='max', axis=-1)
|
| 28 |
+
# " additionally define li to be the number of j such that Y(j) ≥ Y(i)"
|
| 29 |
+
# Could probably compute this from r, but that can be an enhancement
|
| 30 |
+
l = stats.rankdata(-y, method='max', axis=-1)
|
| 31 |
+
|
| 32 |
+
num = np.sum(np.abs(np.diff(r, axis=-1)), axis=-1)
|
| 33 |
+
if y_continuous: # [1] Eq. 1.1
|
| 34 |
+
statistic = 1 - 3 * num / (n ** 2 - 1)
|
| 35 |
+
else: # [1] Eq. 1.2
|
| 36 |
+
den = 2 * np.sum((n - l) * l, axis=-1)
|
| 37 |
+
statistic = 1 - n * num / den
|
| 38 |
+
|
| 39 |
+
return statistic, r, l
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def _xi_std(r, l, y_continuous):
|
| 43 |
+
# Compute asymptotic standard deviation of xi under null hypothesis of independence
|
| 44 |
+
|
| 45 |
+
# `axis=-1` is guaranteed by _axis_nan_policy decorator
|
| 46 |
+
n = np.float64(r.shape[-1])
|
| 47 |
+
|
| 48 |
+
# "Suppose that X and Y are independent and Y is continuous. Then
|
| 49 |
+
# √n·ξn(X, Y) → N(0, 2/5) in distribution as n → ∞"
|
| 50 |
+
if y_continuous: # [1] Theorem 2.1
|
| 51 |
+
return np.sqrt(2 / 5) / np.sqrt(n)
|
| 52 |
+
|
| 53 |
+
# "Suppose that X and Y are independent. Then √n·ξn(X, Y)
|
| 54 |
+
# converges to N(0, τ²) in distribution as n → ∞
|
| 55 |
+
# [1] Eq. 2.2 and surrounding math
|
| 56 |
+
i = np.arange(1, n + 1)
|
| 57 |
+
u = np.sort(r, axis=-1)
|
| 58 |
+
v = np.cumsum(u, axis=-1)
|
| 59 |
+
an = 1 / n**4 * np.sum((2*n - 2*i + 1) * u**2, axis=-1)
|
| 60 |
+
bn = 1 / n**5 * np.sum((v + (n - i)*u)**2, axis=-1)
|
| 61 |
+
cn = 1 / n**3 * np.sum((2*n - 2*i + 1) * u, axis=-1)
|
| 62 |
+
dn = 1 / n**3 * np.sum((l * (n - l)), axis=-1)
|
| 63 |
+
tau2 = (an - 2*bn + cn**2) / dn**2
|
| 64 |
+
|
| 65 |
+
return np.sqrt(tau2) / np.sqrt(n)
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def _chatterjeexi_iv(y_continuous, method):
|
| 69 |
+
# Input validation for `chatterjeexi`
|
| 70 |
+
# x, y, `axis` input validation taken care of by decorator
|
| 71 |
+
|
| 72 |
+
if y_continuous not in {True, False}:
|
| 73 |
+
raise ValueError('`y_continuous` must be boolean.')
|
| 74 |
+
|
| 75 |
+
if not isinstance(method, stats.PermutationMethod):
|
| 76 |
+
method = method.lower()
|
| 77 |
+
message = "`method` must be 'asymptotic' or a `PermutationMethod` instance."
|
| 78 |
+
if method != 'asymptotic':
|
| 79 |
+
raise ValueError(message)
|
| 80 |
+
|
| 81 |
+
return y_continuous, method
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def _unpack(res):
|
| 85 |
+
return res.statistic, res.pvalue
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
@_axis_nan_policy_factory(SignificanceResult, paired=True, n_samples=2,
|
| 89 |
+
result_to_tuple=_unpack, n_outputs=2, too_small=1)
|
| 90 |
+
def chatterjeexi(x, y, *, axis=0, y_continuous=False, method='asymptotic'):
|
| 91 |
+
r"""Compute the xi correlation and perform a test of independence
|
| 92 |
+
|
| 93 |
+
The xi correlation coefficient is a measure of association between two
|
| 94 |
+
variables; the value tends to be close to zero when the variables are
|
| 95 |
+
independent and close to 1 when there is a strong association. Unlike
|
| 96 |
+
other correlation coefficients, the xi correlation is effective even
|
| 97 |
+
when the association is not monotonic.
|
| 98 |
+
|
| 99 |
+
Parameters
|
| 100 |
+
----------
|
| 101 |
+
x, y : array-like
|
| 102 |
+
The samples: corresponding observations of the independent and
|
| 103 |
+
dependent variable. The (N-d) arrays must be broadcastable.
|
| 104 |
+
axis : int, default: 0
|
| 105 |
+
Axis along which to perform the test.
|
| 106 |
+
method : 'asymptotic' or `PermutationMethod` instance, optional
|
| 107 |
+
Selects the method used to calculate the *p*-value.
|
| 108 |
+
Default is 'asymptotic'. The following options are available.
|
| 109 |
+
|
| 110 |
+
* ``'asymptotic'``: compares the standardized test statistic
|
| 111 |
+
against the normal distribution.
|
| 112 |
+
* `PermutationMethod` instance. In this case, the p-value
|
| 113 |
+
is computed using `permutation_test` with the provided
|
| 114 |
+
configuration options and other appropriate settings.
|
| 115 |
+
|
| 116 |
+
y_continuous : bool, default: False
|
| 117 |
+
Whether `y` is assumed to be drawn from a continuous distribution.
|
| 118 |
+
If `y` is drawn from a continuous distribution, results are valid
|
| 119 |
+
whether this is assumed or not, but enabling this assumption will
|
| 120 |
+
result in faster computation and typically produce similar results.
|
| 121 |
+
|
| 122 |
+
Returns
|
| 123 |
+
-------
|
| 124 |
+
res : SignificanceResult
|
| 125 |
+
An object containing attributes:
|
| 126 |
+
|
| 127 |
+
statistic : float
|
| 128 |
+
The xi correlation statistic.
|
| 129 |
+
pvalue : float
|
| 130 |
+
The associated *p*-value: the probability of a statistic at least as
|
| 131 |
+
high as the observed value under the null hypothesis of independence.
|
| 132 |
+
|
| 133 |
+
See Also
|
| 134 |
+
--------
|
| 135 |
+
scipy.stats.pearsonr, scipy.stats.spearmanr, scipy.stats.kendalltau
|
| 136 |
+
|
| 137 |
+
Notes
|
| 138 |
+
-----
|
| 139 |
+
There is currently no special handling of ties in `x`; they are broken arbitrarily
|
| 140 |
+
by the implementation.
|
| 141 |
+
|
| 142 |
+
[1]_ notes that the statistic is not symmetric in `x` and `y` *by design*:
|
| 143 |
+
"...we may want to understand if :math:`Y` is a function :math:`X`, and not just
|
| 144 |
+
if one of the variables is a function of the other." See [1]_ Remark 1.
|
| 145 |
+
|
| 146 |
+
References
|
| 147 |
+
----------
|
| 148 |
+
.. [1] Chatterjee, Sourav. "A new coefficient of correlation." Journal of
|
| 149 |
+
the American Statistical Association 116.536 (2021): 2009-2022.
|
| 150 |
+
:doi:`10.1080/01621459.2020.1758115`.
|
| 151 |
+
|
| 152 |
+
Examples
|
| 153 |
+
--------
|
| 154 |
+
Generate perfectly correlated data, and observe that the xi correlation is
|
| 155 |
+
nearly 1.0.
|
| 156 |
+
|
| 157 |
+
>>> import numpy as np
|
| 158 |
+
>>> from scipy import stats
|
| 159 |
+
>>> rng = np.random.default_rng(348932549825235)
|
| 160 |
+
>>> x = rng.uniform(0, 10, size=100)
|
| 161 |
+
>>> y = np.sin(x)
|
| 162 |
+
>>> res = stats.chatterjeexi(x, y)
|
| 163 |
+
>>> res.statistic
|
| 164 |
+
np.float64(0.9012901290129013)
|
| 165 |
+
|
| 166 |
+
The probability of observing such a high value of the statistic under the
|
| 167 |
+
null hypothesis of independence is very low.
|
| 168 |
+
|
| 169 |
+
>>> res.pvalue
|
| 170 |
+
np.float64(2.2206974648177804e-46)
|
| 171 |
+
|
| 172 |
+
As noise is introduced, the correlation coefficient decreases.
|
| 173 |
+
|
| 174 |
+
>>> noise = rng.normal(scale=[[0.1], [0.5], [1]], size=(3, 100))
|
| 175 |
+
>>> res = stats.chatterjeexi(x, y + noise, axis=-1)
|
| 176 |
+
>>> res.statistic
|
| 177 |
+
array([0.79507951, 0.41824182, 0.16651665])
|
| 178 |
+
|
| 179 |
+
Because the distribution of `y` is continuous, it is valid to pass
|
| 180 |
+
``y_continuous=True``. The statistic is identical, and the p-value
|
| 181 |
+
(not shown) is only slightly different.
|
| 182 |
+
|
| 183 |
+
>>> stats.chatterjeexi(x, y + noise, y_continuous=True, axis=-1).statistic
|
| 184 |
+
array([0.79507951, 0.41824182, 0.16651665])
|
| 185 |
+
|
| 186 |
+
"""
|
| 187 |
+
# x, y, `axis` input validation taken care of by decorator
|
| 188 |
+
# In fact, `axis` is guaranteed to be -1
|
| 189 |
+
y_continuous, method = _chatterjeexi_iv(y_continuous, method)
|
| 190 |
+
|
| 191 |
+
# A highly negative statistic is possible, e.g.
|
| 192 |
+
# x = np.arange(100.), y = (x % 2 == 0)
|
| 193 |
+
# Unclear whether we should expose `alternative`, though.
|
| 194 |
+
alternative = 'greater'
|
| 195 |
+
|
| 196 |
+
if method == 'asymptotic':
|
| 197 |
+
xi, r, l = _xi_statistic(x, y, y_continuous)
|
| 198 |
+
std = _xi_std(r, l, y_continuous)
|
| 199 |
+
norm = _SimpleNormal()
|
| 200 |
+
pvalue = _get_pvalue(xi / std, norm, alternative=alternative)
|
| 201 |
+
elif isinstance(method, stats.PermutationMethod):
|
| 202 |
+
res = stats.permutation_test(
|
| 203 |
+
# Could be faster if we just permuted the ranks; for now, keep it simple.
|
| 204 |
+
data=(y,), statistic=lambda y, axis: _xi_statistic(x, y, y_continuous)[0],
|
| 205 |
+
alternative=alternative, permutation_type='pairings', **method._asdict(),
|
| 206 |
+
axis=-1) # `axis=-1` is guaranteed by _axis_nan_policy decorator
|
| 207 |
+
|
| 208 |
+
xi, pvalue = res.statistic, res.pvalue
|
| 209 |
+
|
| 210 |
+
return SignificanceResult(xi, pvalue)
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/stats/_covariance.py
ADDED
|
@@ -0,0 +1,633 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from functools import cached_property
|
| 2 |
+
|
| 3 |
+
import numpy as np
|
| 4 |
+
from scipy import linalg
|
| 5 |
+
from scipy.stats import _multivariate
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
__all__ = ["Covariance"]
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class Covariance:
|
| 12 |
+
"""
|
| 13 |
+
Representation of a covariance matrix
|
| 14 |
+
|
| 15 |
+
Calculations involving covariance matrices (e.g. data whitening,
|
| 16 |
+
multivariate normal function evaluation) are often performed more
|
| 17 |
+
efficiently using a decomposition of the covariance matrix instead of the
|
| 18 |
+
covariance matrix itself. This class allows the user to construct an
|
| 19 |
+
object representing a covariance matrix using any of several
|
| 20 |
+
decompositions and perform calculations using a common interface.
|
| 21 |
+
|
| 22 |
+
.. note::
|
| 23 |
+
|
| 24 |
+
The `Covariance` class cannot be instantiated directly. Instead, use
|
| 25 |
+
one of the factory methods (e.g. `Covariance.from_diagonal`).
|
| 26 |
+
|
| 27 |
+
Examples
|
| 28 |
+
--------
|
| 29 |
+
The `Covariance` class is used by calling one of its
|
| 30 |
+
factory methods to create a `Covariance` object, then pass that
|
| 31 |
+
representation of the `Covariance` matrix as a shape parameter of a
|
| 32 |
+
multivariate distribution.
|
| 33 |
+
|
| 34 |
+
For instance, the multivariate normal distribution can accept an array
|
| 35 |
+
representing a covariance matrix:
|
| 36 |
+
|
| 37 |
+
>>> from scipy import stats
|
| 38 |
+
>>> import numpy as np
|
| 39 |
+
>>> d = [1, 2, 3]
|
| 40 |
+
>>> A = np.diag(d) # a diagonal covariance matrix
|
| 41 |
+
>>> x = [4, -2, 5] # a point of interest
|
| 42 |
+
>>> dist = stats.multivariate_normal(mean=[0, 0, 0], cov=A)
|
| 43 |
+
>>> dist.pdf(x)
|
| 44 |
+
4.9595685102808205e-08
|
| 45 |
+
|
| 46 |
+
but the calculations are performed in a very generic way that does not
|
| 47 |
+
take advantage of any special properties of the covariance matrix. Because
|
| 48 |
+
our covariance matrix is diagonal, we can use ``Covariance.from_diagonal``
|
| 49 |
+
to create an object representing the covariance matrix, and
|
| 50 |
+
`multivariate_normal` can use this to compute the probability density
|
| 51 |
+
function more efficiently.
|
| 52 |
+
|
| 53 |
+
>>> cov = stats.Covariance.from_diagonal(d)
|
| 54 |
+
>>> dist = stats.multivariate_normal(mean=[0, 0, 0], cov=cov)
|
| 55 |
+
>>> dist.pdf(x)
|
| 56 |
+
4.9595685102808205e-08
|
| 57 |
+
|
| 58 |
+
"""
|
| 59 |
+
def __init__(self):
|
| 60 |
+
message = ("The `Covariance` class cannot be instantiated directly. "
|
| 61 |
+
"Please use one of the factory methods "
|
| 62 |
+
"(e.g. `Covariance.from_diagonal`).")
|
| 63 |
+
raise NotImplementedError(message)
|
| 64 |
+
|
| 65 |
+
@staticmethod
|
| 66 |
+
def from_diagonal(diagonal):
|
| 67 |
+
r"""
|
| 68 |
+
Return a representation of a covariance matrix from its diagonal.
|
| 69 |
+
|
| 70 |
+
Parameters
|
| 71 |
+
----------
|
| 72 |
+
diagonal : array_like
|
| 73 |
+
The diagonal elements of a diagonal matrix.
|
| 74 |
+
|
| 75 |
+
Notes
|
| 76 |
+
-----
|
| 77 |
+
Let the diagonal elements of a diagonal covariance matrix :math:`D` be
|
| 78 |
+
stored in the vector :math:`d`.
|
| 79 |
+
|
| 80 |
+
When all elements of :math:`d` are strictly positive, whitening of a
|
| 81 |
+
data point :math:`x` is performed by computing
|
| 82 |
+
:math:`x \cdot d^{-1/2}`, where the inverse square root can be taken
|
| 83 |
+
element-wise.
|
| 84 |
+
:math:`\log\det{D}` is calculated as :math:`-2 \sum(\log{d})`,
|
| 85 |
+
where the :math:`\log` operation is performed element-wise.
|
| 86 |
+
|
| 87 |
+
This `Covariance` class supports singular covariance matrices. When
|
| 88 |
+
computing ``_log_pdet``, non-positive elements of :math:`d` are
|
| 89 |
+
ignored. Whitening is not well defined when the point to be whitened
|
| 90 |
+
does not lie in the span of the columns of the covariance matrix. The
|
| 91 |
+
convention taken here is to treat the inverse square root of
|
| 92 |
+
non-positive elements of :math:`d` as zeros.
|
| 93 |
+
|
| 94 |
+
Examples
|
| 95 |
+
--------
|
| 96 |
+
Prepare a symmetric positive definite covariance matrix ``A`` and a
|
| 97 |
+
data point ``x``.
|
| 98 |
+
|
| 99 |
+
>>> import numpy as np
|
| 100 |
+
>>> from scipy import stats
|
| 101 |
+
>>> rng = np.random.default_rng()
|
| 102 |
+
>>> n = 5
|
| 103 |
+
>>> A = np.diag(rng.random(n))
|
| 104 |
+
>>> x = rng.random(size=n)
|
| 105 |
+
|
| 106 |
+
Extract the diagonal from ``A`` and create the `Covariance` object.
|
| 107 |
+
|
| 108 |
+
>>> d = np.diag(A)
|
| 109 |
+
>>> cov = stats.Covariance.from_diagonal(d)
|
| 110 |
+
|
| 111 |
+
Compare the functionality of the `Covariance` object against a
|
| 112 |
+
reference implementations.
|
| 113 |
+
|
| 114 |
+
>>> res = cov.whiten(x)
|
| 115 |
+
>>> ref = np.diag(d**-0.5) @ x
|
| 116 |
+
>>> np.allclose(res, ref)
|
| 117 |
+
True
|
| 118 |
+
>>> res = cov.log_pdet
|
| 119 |
+
>>> ref = np.linalg.slogdet(A)[-1]
|
| 120 |
+
>>> np.allclose(res, ref)
|
| 121 |
+
True
|
| 122 |
+
|
| 123 |
+
"""
|
| 124 |
+
return CovViaDiagonal(diagonal)
|
| 125 |
+
|
| 126 |
+
@staticmethod
|
| 127 |
+
def from_precision(precision, covariance=None):
|
| 128 |
+
r"""
|
| 129 |
+
Return a representation of a covariance from its precision matrix.
|
| 130 |
+
|
| 131 |
+
Parameters
|
| 132 |
+
----------
|
| 133 |
+
precision : array_like
|
| 134 |
+
The precision matrix; that is, the inverse of a square, symmetric,
|
| 135 |
+
positive definite covariance matrix.
|
| 136 |
+
covariance : array_like, optional
|
| 137 |
+
The square, symmetric, positive definite covariance matrix. If not
|
| 138 |
+
provided, this may need to be calculated (e.g. to evaluate the
|
| 139 |
+
cumulative distribution function of
|
| 140 |
+
`scipy.stats.multivariate_normal`) by inverting `precision`.
|
| 141 |
+
|
| 142 |
+
Notes
|
| 143 |
+
-----
|
| 144 |
+
Let the covariance matrix be :math:`A`, its precision matrix be
|
| 145 |
+
:math:`P = A^{-1}`, and :math:`L` be the lower Cholesky factor such
|
| 146 |
+
that :math:`L L^T = P`.
|
| 147 |
+
Whitening of a data point :math:`x` is performed by computing
|
| 148 |
+
:math:`x^T L`. :math:`\log\det{A}` is calculated as
|
| 149 |
+
:math:`-2tr(\log{L})`, where the :math:`\log` operation is performed
|
| 150 |
+
element-wise.
|
| 151 |
+
|
| 152 |
+
This `Covariance` class does not support singular covariance matrices
|
| 153 |
+
because the precision matrix does not exist for a singular covariance
|
| 154 |
+
matrix.
|
| 155 |
+
|
| 156 |
+
Examples
|
| 157 |
+
--------
|
| 158 |
+
Prepare a symmetric positive definite precision matrix ``P`` and a
|
| 159 |
+
data point ``x``. (If the precision matrix is not already available,
|
| 160 |
+
consider the other factory methods of the `Covariance` class.)
|
| 161 |
+
|
| 162 |
+
>>> import numpy as np
|
| 163 |
+
>>> from scipy import stats
|
| 164 |
+
>>> rng = np.random.default_rng()
|
| 165 |
+
>>> n = 5
|
| 166 |
+
>>> P = rng.random(size=(n, n))
|
| 167 |
+
>>> P = P @ P.T # a precision matrix must be positive definite
|
| 168 |
+
>>> x = rng.random(size=n)
|
| 169 |
+
|
| 170 |
+
Create the `Covariance` object.
|
| 171 |
+
|
| 172 |
+
>>> cov = stats.Covariance.from_precision(P)
|
| 173 |
+
|
| 174 |
+
Compare the functionality of the `Covariance` object against
|
| 175 |
+
reference implementations.
|
| 176 |
+
|
| 177 |
+
>>> res = cov.whiten(x)
|
| 178 |
+
>>> ref = x @ np.linalg.cholesky(P)
|
| 179 |
+
>>> np.allclose(res, ref)
|
| 180 |
+
True
|
| 181 |
+
>>> res = cov.log_pdet
|
| 182 |
+
>>> ref = -np.linalg.slogdet(P)[-1]
|
| 183 |
+
>>> np.allclose(res, ref)
|
| 184 |
+
True
|
| 185 |
+
|
| 186 |
+
"""
|
| 187 |
+
return CovViaPrecision(precision, covariance)
|
| 188 |
+
|
| 189 |
+
@staticmethod
|
| 190 |
+
def from_cholesky(cholesky):
|
| 191 |
+
r"""
|
| 192 |
+
Representation of a covariance provided via the (lower) Cholesky factor
|
| 193 |
+
|
| 194 |
+
Parameters
|
| 195 |
+
----------
|
| 196 |
+
cholesky : array_like
|
| 197 |
+
The lower triangular Cholesky factor of the covariance matrix.
|
| 198 |
+
|
| 199 |
+
Notes
|
| 200 |
+
-----
|
| 201 |
+
Let the covariance matrix be :math:`A` and :math:`L` be the lower
|
| 202 |
+
Cholesky factor such that :math:`L L^T = A`.
|
| 203 |
+
Whitening of a data point :math:`x` is performed by computing
|
| 204 |
+
:math:`L^{-1} x`. :math:`\log\det{A}` is calculated as
|
| 205 |
+
:math:`2tr(\log{L})`, where the :math:`\log` operation is performed
|
| 206 |
+
element-wise.
|
| 207 |
+
|
| 208 |
+
This `Covariance` class does not support singular covariance matrices
|
| 209 |
+
because the Cholesky decomposition does not exist for a singular
|
| 210 |
+
covariance matrix.
|
| 211 |
+
|
| 212 |
+
Examples
|
| 213 |
+
--------
|
| 214 |
+
Prepare a symmetric positive definite covariance matrix ``A`` and a
|
| 215 |
+
data point ``x``.
|
| 216 |
+
|
| 217 |
+
>>> import numpy as np
|
| 218 |
+
>>> from scipy import stats
|
| 219 |
+
>>> rng = np.random.default_rng()
|
| 220 |
+
>>> n = 5
|
| 221 |
+
>>> A = rng.random(size=(n, n))
|
| 222 |
+
>>> A = A @ A.T # make the covariance symmetric positive definite
|
| 223 |
+
>>> x = rng.random(size=n)
|
| 224 |
+
|
| 225 |
+
Perform the Cholesky decomposition of ``A`` and create the
|
| 226 |
+
`Covariance` object.
|
| 227 |
+
|
| 228 |
+
>>> L = np.linalg.cholesky(A)
|
| 229 |
+
>>> cov = stats.Covariance.from_cholesky(L)
|
| 230 |
+
|
| 231 |
+
Compare the functionality of the `Covariance` object against
|
| 232 |
+
reference implementation.
|
| 233 |
+
|
| 234 |
+
>>> from scipy.linalg import solve_triangular
|
| 235 |
+
>>> res = cov.whiten(x)
|
| 236 |
+
>>> ref = solve_triangular(L, x, lower=True)
|
| 237 |
+
>>> np.allclose(res, ref)
|
| 238 |
+
True
|
| 239 |
+
>>> res = cov.log_pdet
|
| 240 |
+
>>> ref = np.linalg.slogdet(A)[-1]
|
| 241 |
+
>>> np.allclose(res, ref)
|
| 242 |
+
True
|
| 243 |
+
|
| 244 |
+
"""
|
| 245 |
+
return CovViaCholesky(cholesky)
|
| 246 |
+
|
| 247 |
+
@staticmethod
|
| 248 |
+
def from_eigendecomposition(eigendecomposition):
|
| 249 |
+
r"""
|
| 250 |
+
Representation of a covariance provided via eigendecomposition
|
| 251 |
+
|
| 252 |
+
Parameters
|
| 253 |
+
----------
|
| 254 |
+
eigendecomposition : sequence
|
| 255 |
+
A sequence (nominally a tuple) containing the eigenvalue and
|
| 256 |
+
eigenvector arrays as computed by `scipy.linalg.eigh` or
|
| 257 |
+
`numpy.linalg.eigh`.
|
| 258 |
+
|
| 259 |
+
Notes
|
| 260 |
+
-----
|
| 261 |
+
Let the covariance matrix be :math:`A`, let :math:`V` be matrix of
|
| 262 |
+
eigenvectors, and let :math:`W` be the diagonal matrix of eigenvalues
|
| 263 |
+
such that `V W V^T = A`.
|
| 264 |
+
|
| 265 |
+
When all of the eigenvalues are strictly positive, whitening of a
|
| 266 |
+
data point :math:`x` is performed by computing
|
| 267 |
+
:math:`x^T (V W^{-1/2})`, where the inverse square root can be taken
|
| 268 |
+
element-wise.
|
| 269 |
+
:math:`\log\det{A}` is calculated as :math:`tr(\log{W})`,
|
| 270 |
+
where the :math:`\log` operation is performed element-wise.
|
| 271 |
+
|
| 272 |
+
This `Covariance` class supports singular covariance matrices. When
|
| 273 |
+
computing ``_log_pdet``, non-positive eigenvalues are ignored.
|
| 274 |
+
Whitening is not well defined when the point to be whitened
|
| 275 |
+
does not lie in the span of the columns of the covariance matrix. The
|
| 276 |
+
convention taken here is to treat the inverse square root of
|
| 277 |
+
non-positive eigenvalues as zeros.
|
| 278 |
+
|
| 279 |
+
Examples
|
| 280 |
+
--------
|
| 281 |
+
Prepare a symmetric positive definite covariance matrix ``A`` and a
|
| 282 |
+
data point ``x``.
|
| 283 |
+
|
| 284 |
+
>>> import numpy as np
|
| 285 |
+
>>> from scipy import stats
|
| 286 |
+
>>> rng = np.random.default_rng()
|
| 287 |
+
>>> n = 5
|
| 288 |
+
>>> A = rng.random(size=(n, n))
|
| 289 |
+
>>> A = A @ A.T # make the covariance symmetric positive definite
|
| 290 |
+
>>> x = rng.random(size=n)
|
| 291 |
+
|
| 292 |
+
Perform the eigendecomposition of ``A`` and create the `Covariance`
|
| 293 |
+
object.
|
| 294 |
+
|
| 295 |
+
>>> w, v = np.linalg.eigh(A)
|
| 296 |
+
>>> cov = stats.Covariance.from_eigendecomposition((w, v))
|
| 297 |
+
|
| 298 |
+
Compare the functionality of the `Covariance` object against
|
| 299 |
+
reference implementations.
|
| 300 |
+
|
| 301 |
+
>>> res = cov.whiten(x)
|
| 302 |
+
>>> ref = x @ (v @ np.diag(w**-0.5))
|
| 303 |
+
>>> np.allclose(res, ref)
|
| 304 |
+
True
|
| 305 |
+
>>> res = cov.log_pdet
|
| 306 |
+
>>> ref = np.linalg.slogdet(A)[-1]
|
| 307 |
+
>>> np.allclose(res, ref)
|
| 308 |
+
True
|
| 309 |
+
|
| 310 |
+
"""
|
| 311 |
+
return CovViaEigendecomposition(eigendecomposition)
|
| 312 |
+
|
| 313 |
+
def whiten(self, x):
|
| 314 |
+
"""
|
| 315 |
+
Perform a whitening transformation on data.
|
| 316 |
+
|
| 317 |
+
"Whitening" ("white" as in "white noise", in which each frequency has
|
| 318 |
+
equal magnitude) transforms a set of random variables into a new set of
|
| 319 |
+
random variables with unit-diagonal covariance. When a whitening
|
| 320 |
+
transform is applied to a sample of points distributed according to
|
| 321 |
+
a multivariate normal distribution with zero mean, the covariance of
|
| 322 |
+
the transformed sample is approximately the identity matrix.
|
| 323 |
+
|
| 324 |
+
Parameters
|
| 325 |
+
----------
|
| 326 |
+
x : array_like
|
| 327 |
+
An array of points. The last dimension must correspond with the
|
| 328 |
+
dimensionality of the space, i.e., the number of columns in the
|
| 329 |
+
covariance matrix.
|
| 330 |
+
|
| 331 |
+
Returns
|
| 332 |
+
-------
|
| 333 |
+
x_ : array_like
|
| 334 |
+
The transformed array of points.
|
| 335 |
+
|
| 336 |
+
References
|
| 337 |
+
----------
|
| 338 |
+
.. [1] "Whitening Transformation". Wikipedia.
|
| 339 |
+
https://en.wikipedia.org/wiki/Whitening_transformation
|
| 340 |
+
.. [2] Novak, Lukas, and Miroslav Vorechovsky. "Generalization of
|
| 341 |
+
coloring linear transformation". Transactions of VSB 18.2
|
| 342 |
+
(2018): 31-35. :doi:`10.31490/tces-2018-0013`
|
| 343 |
+
|
| 344 |
+
Examples
|
| 345 |
+
--------
|
| 346 |
+
>>> import numpy as np
|
| 347 |
+
>>> from scipy import stats
|
| 348 |
+
>>> rng = np.random.default_rng()
|
| 349 |
+
>>> n = 3
|
| 350 |
+
>>> A = rng.random(size=(n, n))
|
| 351 |
+
>>> cov_array = A @ A.T # make matrix symmetric positive definite
|
| 352 |
+
>>> precision = np.linalg.inv(cov_array)
|
| 353 |
+
>>> cov_object = stats.Covariance.from_precision(precision)
|
| 354 |
+
>>> x = rng.multivariate_normal(np.zeros(n), cov_array, size=(10000))
|
| 355 |
+
>>> x_ = cov_object.whiten(x)
|
| 356 |
+
>>> np.cov(x_, rowvar=False) # near-identity covariance
|
| 357 |
+
array([[0.97862122, 0.00893147, 0.02430451],
|
| 358 |
+
[0.00893147, 0.96719062, 0.02201312],
|
| 359 |
+
[0.02430451, 0.02201312, 0.99206881]])
|
| 360 |
+
|
| 361 |
+
"""
|
| 362 |
+
return self._whiten(np.asarray(x))
|
| 363 |
+
|
| 364 |
+
def colorize(self, x):
|
| 365 |
+
"""
|
| 366 |
+
Perform a colorizing transformation on data.
|
| 367 |
+
|
| 368 |
+
"Colorizing" ("color" as in "colored noise", in which different
|
| 369 |
+
frequencies may have different magnitudes) transforms a set of
|
| 370 |
+
uncorrelated random variables into a new set of random variables with
|
| 371 |
+
the desired covariance. When a coloring transform is applied to a
|
| 372 |
+
sample of points distributed according to a multivariate normal
|
| 373 |
+
distribution with identity covariance and zero mean, the covariance of
|
| 374 |
+
the transformed sample is approximately the covariance matrix used
|
| 375 |
+
in the coloring transform.
|
| 376 |
+
|
| 377 |
+
Parameters
|
| 378 |
+
----------
|
| 379 |
+
x : array_like
|
| 380 |
+
An array of points. The last dimension must correspond with the
|
| 381 |
+
dimensionality of the space, i.e., the number of columns in the
|
| 382 |
+
covariance matrix.
|
| 383 |
+
|
| 384 |
+
Returns
|
| 385 |
+
-------
|
| 386 |
+
x_ : array_like
|
| 387 |
+
The transformed array of points.
|
| 388 |
+
|
| 389 |
+
References
|
| 390 |
+
----------
|
| 391 |
+
.. [1] "Whitening Transformation". Wikipedia.
|
| 392 |
+
https://en.wikipedia.org/wiki/Whitening_transformation
|
| 393 |
+
.. [2] Novak, Lukas, and Miroslav Vorechovsky. "Generalization of
|
| 394 |
+
coloring linear transformation". Transactions of VSB 18.2
|
| 395 |
+
(2018): 31-35. :doi:`10.31490/tces-2018-0013`
|
| 396 |
+
|
| 397 |
+
Examples
|
| 398 |
+
--------
|
| 399 |
+
>>> import numpy as np
|
| 400 |
+
>>> from scipy import stats
|
| 401 |
+
>>> rng = np.random.default_rng(1638083107694713882823079058616272161)
|
| 402 |
+
>>> n = 3
|
| 403 |
+
>>> A = rng.random(size=(n, n))
|
| 404 |
+
>>> cov_array = A @ A.T # make matrix symmetric positive definite
|
| 405 |
+
>>> cholesky = np.linalg.cholesky(cov_array)
|
| 406 |
+
>>> cov_object = stats.Covariance.from_cholesky(cholesky)
|
| 407 |
+
>>> x = rng.multivariate_normal(np.zeros(n), np.eye(n), size=(10000))
|
| 408 |
+
>>> x_ = cov_object.colorize(x)
|
| 409 |
+
>>> cov_data = np.cov(x_, rowvar=False)
|
| 410 |
+
>>> np.allclose(cov_data, cov_array, rtol=3e-2)
|
| 411 |
+
True
|
| 412 |
+
"""
|
| 413 |
+
return self._colorize(np.asarray(x))
|
| 414 |
+
|
| 415 |
+
@property
|
| 416 |
+
def log_pdet(self):
|
| 417 |
+
"""
|
| 418 |
+
Log of the pseudo-determinant of the covariance matrix
|
| 419 |
+
"""
|
| 420 |
+
return np.array(self._log_pdet, dtype=float)[()]
|
| 421 |
+
|
| 422 |
+
@property
|
| 423 |
+
def rank(self):
|
| 424 |
+
"""
|
| 425 |
+
Rank of the covariance matrix
|
| 426 |
+
"""
|
| 427 |
+
return np.array(self._rank, dtype=int)[()]
|
| 428 |
+
|
| 429 |
+
@property
|
| 430 |
+
def covariance(self):
|
| 431 |
+
"""
|
| 432 |
+
Explicit representation of the covariance matrix
|
| 433 |
+
"""
|
| 434 |
+
return self._covariance
|
| 435 |
+
|
| 436 |
+
@property
|
| 437 |
+
def shape(self):
|
| 438 |
+
"""
|
| 439 |
+
Shape of the covariance array
|
| 440 |
+
"""
|
| 441 |
+
return self._shape
|
| 442 |
+
|
| 443 |
+
def _validate_matrix(self, A, name):
|
| 444 |
+
A = np.atleast_2d(A)
|
| 445 |
+
m, n = A.shape[-2:]
|
| 446 |
+
if m != n or A.ndim != 2 or not (np.issubdtype(A.dtype, np.integer) or
|
| 447 |
+
np.issubdtype(A.dtype, np.floating)):
|
| 448 |
+
message = (f"The input `{name}` must be a square, "
|
| 449 |
+
"two-dimensional array of real numbers.")
|
| 450 |
+
raise ValueError(message)
|
| 451 |
+
return A
|
| 452 |
+
|
| 453 |
+
def _validate_vector(self, A, name):
|
| 454 |
+
A = np.atleast_1d(A)
|
| 455 |
+
if A.ndim != 1 or not (np.issubdtype(A.dtype, np.integer) or
|
| 456 |
+
np.issubdtype(A.dtype, np.floating)):
|
| 457 |
+
message = (f"The input `{name}` must be a one-dimensional array "
|
| 458 |
+
"of real numbers.")
|
| 459 |
+
raise ValueError(message)
|
| 460 |
+
return A
|
| 461 |
+
|
| 462 |
+
|
| 463 |
+
class CovViaPrecision(Covariance):
|
| 464 |
+
|
| 465 |
+
def __init__(self, precision, covariance=None):
|
| 466 |
+
precision = self._validate_matrix(precision, 'precision')
|
| 467 |
+
if covariance is not None:
|
| 468 |
+
covariance = self._validate_matrix(covariance, 'covariance')
|
| 469 |
+
message = "`precision.shape` must equal `covariance.shape`."
|
| 470 |
+
if precision.shape != covariance.shape:
|
| 471 |
+
raise ValueError(message)
|
| 472 |
+
|
| 473 |
+
self._chol_P = np.linalg.cholesky(precision)
|
| 474 |
+
self._log_pdet = -2*np.log(np.diag(self._chol_P)).sum(axis=-1)
|
| 475 |
+
self._rank = precision.shape[-1] # must be full rank if invertible
|
| 476 |
+
self._precision = precision
|
| 477 |
+
self._cov_matrix = covariance
|
| 478 |
+
self._shape = precision.shape
|
| 479 |
+
self._allow_singular = False
|
| 480 |
+
|
| 481 |
+
def _whiten(self, x):
|
| 482 |
+
return x @ self._chol_P
|
| 483 |
+
|
| 484 |
+
@cached_property
|
| 485 |
+
def _covariance(self):
|
| 486 |
+
n = self._shape[-1]
|
| 487 |
+
return (linalg.cho_solve((self._chol_P, True), np.eye(n))
|
| 488 |
+
if self._cov_matrix is None else self._cov_matrix)
|
| 489 |
+
|
| 490 |
+
def _colorize(self, x):
|
| 491 |
+
return linalg.solve_triangular(self._chol_P.T, x.T, lower=False).T
|
| 492 |
+
|
| 493 |
+
|
| 494 |
+
def _dot_diag(x, d):
|
| 495 |
+
# If d were a full diagonal matrix, x @ d would always do what we want.
|
| 496 |
+
# Special treatment is needed for n-dimensional `d` in which each row
|
| 497 |
+
# includes only the diagonal elements of a covariance matrix.
|
| 498 |
+
return x * d if x.ndim < 2 else x * np.expand_dims(d, -2)
|
| 499 |
+
|
| 500 |
+
|
| 501 |
+
class CovViaDiagonal(Covariance):
|
| 502 |
+
|
| 503 |
+
def __init__(self, diagonal):
|
| 504 |
+
diagonal = self._validate_vector(diagonal, 'diagonal')
|
| 505 |
+
|
| 506 |
+
i_zero = diagonal <= 0
|
| 507 |
+
positive_diagonal = np.array(diagonal, dtype=np.float64)
|
| 508 |
+
|
| 509 |
+
positive_diagonal[i_zero] = 1 # ones don't affect determinant
|
| 510 |
+
self._log_pdet = np.sum(np.log(positive_diagonal), axis=-1)
|
| 511 |
+
|
| 512 |
+
psuedo_reciprocals = 1 / np.sqrt(positive_diagonal)
|
| 513 |
+
psuedo_reciprocals[i_zero] = 0
|
| 514 |
+
|
| 515 |
+
self._sqrt_diagonal = np.sqrt(diagonal)
|
| 516 |
+
self._LP = psuedo_reciprocals
|
| 517 |
+
self._rank = positive_diagonal.shape[-1] - i_zero.sum(axis=-1)
|
| 518 |
+
self._covariance = np.apply_along_axis(np.diag, -1, diagonal)
|
| 519 |
+
self._i_zero = i_zero
|
| 520 |
+
self._shape = self._covariance.shape
|
| 521 |
+
self._allow_singular = True
|
| 522 |
+
|
| 523 |
+
def _whiten(self, x):
|
| 524 |
+
return _dot_diag(x, self._LP)
|
| 525 |
+
|
| 526 |
+
def _colorize(self, x):
|
| 527 |
+
return _dot_diag(x, self._sqrt_diagonal)
|
| 528 |
+
|
| 529 |
+
def _support_mask(self, x):
|
| 530 |
+
"""
|
| 531 |
+
Check whether x lies in the support of the distribution.
|
| 532 |
+
"""
|
| 533 |
+
return ~np.any(_dot_diag(x, self._i_zero), axis=-1)
|
| 534 |
+
|
| 535 |
+
|
| 536 |
+
class CovViaCholesky(Covariance):
|
| 537 |
+
|
| 538 |
+
def __init__(self, cholesky):
|
| 539 |
+
L = self._validate_matrix(cholesky, 'cholesky')
|
| 540 |
+
|
| 541 |
+
self._factor = L
|
| 542 |
+
self._log_pdet = 2*np.log(np.diag(self._factor)).sum(axis=-1)
|
| 543 |
+
self._rank = L.shape[-1] # must be full rank for cholesky
|
| 544 |
+
self._shape = L.shape
|
| 545 |
+
self._allow_singular = False
|
| 546 |
+
|
| 547 |
+
@cached_property
|
| 548 |
+
def _covariance(self):
|
| 549 |
+
return self._factor @ self._factor.T
|
| 550 |
+
|
| 551 |
+
def _whiten(self, x):
|
| 552 |
+
res = linalg.solve_triangular(self._factor, x.T, lower=True).T
|
| 553 |
+
return res
|
| 554 |
+
|
| 555 |
+
def _colorize(self, x):
|
| 556 |
+
return x @ self._factor.T
|
| 557 |
+
|
| 558 |
+
|
| 559 |
+
class CovViaEigendecomposition(Covariance):
|
| 560 |
+
|
| 561 |
+
def __init__(self, eigendecomposition):
|
| 562 |
+
eigenvalues, eigenvectors = eigendecomposition
|
| 563 |
+
eigenvalues = self._validate_vector(eigenvalues, 'eigenvalues')
|
| 564 |
+
eigenvectors = self._validate_matrix(eigenvectors, 'eigenvectors')
|
| 565 |
+
message = ("The shapes of `eigenvalues` and `eigenvectors` "
|
| 566 |
+
"must be compatible.")
|
| 567 |
+
try:
|
| 568 |
+
eigenvalues = np.expand_dims(eigenvalues, -2)
|
| 569 |
+
eigenvectors, eigenvalues = np.broadcast_arrays(eigenvectors,
|
| 570 |
+
eigenvalues)
|
| 571 |
+
eigenvalues = eigenvalues[..., 0, :]
|
| 572 |
+
except ValueError:
|
| 573 |
+
raise ValueError(message)
|
| 574 |
+
|
| 575 |
+
i_zero = eigenvalues <= 0
|
| 576 |
+
positive_eigenvalues = np.array(eigenvalues, dtype=np.float64)
|
| 577 |
+
|
| 578 |
+
positive_eigenvalues[i_zero] = 1 # ones don't affect determinant
|
| 579 |
+
self._log_pdet = np.sum(np.log(positive_eigenvalues), axis=-1)
|
| 580 |
+
|
| 581 |
+
psuedo_reciprocals = 1 / np.sqrt(positive_eigenvalues)
|
| 582 |
+
psuedo_reciprocals[i_zero] = 0
|
| 583 |
+
|
| 584 |
+
self._LP = eigenvectors * psuedo_reciprocals
|
| 585 |
+
self._LA = eigenvectors * np.sqrt(eigenvalues)
|
| 586 |
+
self._rank = positive_eigenvalues.shape[-1] - i_zero.sum(axis=-1)
|
| 587 |
+
self._w = eigenvalues
|
| 588 |
+
self._v = eigenvectors
|
| 589 |
+
self._shape = eigenvectors.shape
|
| 590 |
+
self._null_basis = eigenvectors * i_zero
|
| 591 |
+
# This is only used for `_support_mask`, not to decide whether
|
| 592 |
+
# the covariance is singular or not.
|
| 593 |
+
self._eps = _multivariate._eigvalsh_to_eps(eigenvalues) * 10**3
|
| 594 |
+
self._allow_singular = True
|
| 595 |
+
|
| 596 |
+
def _whiten(self, x):
|
| 597 |
+
return x @ self._LP
|
| 598 |
+
|
| 599 |
+
def _colorize(self, x):
|
| 600 |
+
return x @ self._LA.T
|
| 601 |
+
|
| 602 |
+
@cached_property
|
| 603 |
+
def _covariance(self):
|
| 604 |
+
return (self._v * self._w) @ self._v.T
|
| 605 |
+
|
| 606 |
+
def _support_mask(self, x):
|
| 607 |
+
"""
|
| 608 |
+
Check whether x lies in the support of the distribution.
|
| 609 |
+
"""
|
| 610 |
+
residual = np.linalg.norm(x @ self._null_basis, axis=-1)
|
| 611 |
+
in_support = residual < self._eps
|
| 612 |
+
return in_support
|
| 613 |
+
|
| 614 |
+
|
| 615 |
+
class CovViaPSD(Covariance):
|
| 616 |
+
"""
|
| 617 |
+
Representation of a covariance provided via an instance of _PSD
|
| 618 |
+
"""
|
| 619 |
+
|
| 620 |
+
def __init__(self, psd):
|
| 621 |
+
self._LP = psd.U
|
| 622 |
+
self._log_pdet = psd.log_pdet
|
| 623 |
+
self._rank = psd.rank
|
| 624 |
+
self._covariance = psd._M
|
| 625 |
+
self._shape = psd._M.shape
|
| 626 |
+
self._psd = psd
|
| 627 |
+
self._allow_singular = False # by default
|
| 628 |
+
|
| 629 |
+
def _whiten(self, x):
|
| 630 |
+
return x @ self._LP
|
| 631 |
+
|
| 632 |
+
def _support_mask(self, x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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
from scipy.sparse import coo_matrix
|
| 3 |
+
from scipy._lib._bunch import _make_tuple_bunch
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
CrosstabResult = _make_tuple_bunch(
|
| 7 |
+
"CrosstabResult", ["elements", "count"]
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def crosstab(*args, levels=None, sparse=False):
|
| 12 |
+
"""
|
| 13 |
+
Return table of counts for each possible unique combination in ``*args``.
|
| 14 |
+
|
| 15 |
+
When ``len(args) > 1``, the array computed by this function is
|
| 16 |
+
often referred to as a *contingency table* [1]_.
|
| 17 |
+
|
| 18 |
+
The arguments must be sequences with the same length. The second return
|
| 19 |
+
value, `count`, is an integer array with ``len(args)`` dimensions. If
|
| 20 |
+
`levels` is None, the shape of `count` is ``(n0, n1, ...)``, where ``nk``
|
| 21 |
+
is the number of unique elements in ``args[k]``.
|
| 22 |
+
|
| 23 |
+
Parameters
|
| 24 |
+
----------
|
| 25 |
+
*args : sequences
|
| 26 |
+
A sequence of sequences whose unique aligned elements are to be
|
| 27 |
+
counted. The sequences in args must all be the same length.
|
| 28 |
+
levels : sequence, optional
|
| 29 |
+
If `levels` is given, it must be a sequence that is the same length as
|
| 30 |
+
`args`. Each element in `levels` is either a sequence or None. If it
|
| 31 |
+
is a sequence, it gives the values in the corresponding sequence in
|
| 32 |
+
`args` that are to be counted. If any value in the sequences in `args`
|
| 33 |
+
does not occur in the corresponding sequence in `levels`, that value
|
| 34 |
+
is ignored and not counted in the returned array `count`. The default
|
| 35 |
+
value of `levels` for ``args[i]`` is ``np.unique(args[i])``
|
| 36 |
+
sparse : bool, optional
|
| 37 |
+
If True, return a sparse matrix. The matrix will be an instance of
|
| 38 |
+
the `scipy.sparse.coo_matrix` class. Because SciPy's sparse matrices
|
| 39 |
+
must be 2-d, only two input sequences are allowed when `sparse` is
|
| 40 |
+
True. Default is False.
|
| 41 |
+
|
| 42 |
+
Returns
|
| 43 |
+
-------
|
| 44 |
+
res : CrosstabResult
|
| 45 |
+
An object containing the following attributes:
|
| 46 |
+
|
| 47 |
+
elements : tuple of numpy.ndarrays.
|
| 48 |
+
Tuple of length ``len(args)`` containing the arrays of elements
|
| 49 |
+
that are counted in `count`. These can be interpreted as the
|
| 50 |
+
labels of the corresponding dimensions of `count`. If `levels` was
|
| 51 |
+
given, then if ``levels[i]`` is not None, ``elements[i]`` will
|
| 52 |
+
hold the values given in ``levels[i]``.
|
| 53 |
+
count : numpy.ndarray or scipy.sparse.coo_matrix
|
| 54 |
+
Counts of the unique elements in ``zip(*args)``, stored in an
|
| 55 |
+
array. Also known as a *contingency table* when ``len(args) > 1``.
|
| 56 |
+
|
| 57 |
+
See Also
|
| 58 |
+
--------
|
| 59 |
+
numpy.unique
|
| 60 |
+
|
| 61 |
+
Notes
|
| 62 |
+
-----
|
| 63 |
+
.. versionadded:: 1.7.0
|
| 64 |
+
|
| 65 |
+
References
|
| 66 |
+
----------
|
| 67 |
+
.. [1] "Contingency table", http://en.wikipedia.org/wiki/Contingency_table
|
| 68 |
+
|
| 69 |
+
Examples
|
| 70 |
+
--------
|
| 71 |
+
>>> from scipy.stats.contingency import crosstab
|
| 72 |
+
|
| 73 |
+
Given the lists `a` and `x`, create a contingency table that counts the
|
| 74 |
+
frequencies of the corresponding pairs.
|
| 75 |
+
|
| 76 |
+
>>> a = ['A', 'B', 'A', 'A', 'B', 'B', 'A', 'A', 'B', 'B']
|
| 77 |
+
>>> x = ['X', 'X', 'X', 'Y', 'Z', 'Z', 'Y', 'Y', 'Z', 'Z']
|
| 78 |
+
>>> res = crosstab(a, x)
|
| 79 |
+
>>> avals, xvals = res.elements
|
| 80 |
+
>>> avals
|
| 81 |
+
array(['A', 'B'], dtype='<U1')
|
| 82 |
+
>>> xvals
|
| 83 |
+
array(['X', 'Y', 'Z'], dtype='<U1')
|
| 84 |
+
>>> res.count
|
| 85 |
+
array([[2, 3, 0],
|
| 86 |
+
[1, 0, 4]])
|
| 87 |
+
|
| 88 |
+
So ``('A', 'X')`` occurs twice, ``('A', 'Y')`` occurs three times, etc.
|
| 89 |
+
|
| 90 |
+
Higher dimensional contingency tables can be created.
|
| 91 |
+
|
| 92 |
+
>>> p = [0, 0, 0, 0, 1, 1, 1, 0, 0, 1]
|
| 93 |
+
>>> res = crosstab(a, x, p)
|
| 94 |
+
>>> res.count
|
| 95 |
+
array([[[2, 0],
|
| 96 |
+
[2, 1],
|
| 97 |
+
[0, 0]],
|
| 98 |
+
[[1, 0],
|
| 99 |
+
[0, 0],
|
| 100 |
+
[1, 3]]])
|
| 101 |
+
>>> res.count.shape
|
| 102 |
+
(2, 3, 2)
|
| 103 |
+
|
| 104 |
+
The values to be counted can be set by using the `levels` argument.
|
| 105 |
+
It allows the elements of interest in each input sequence to be
|
| 106 |
+
given explicitly instead finding the unique elements of the sequence.
|
| 107 |
+
|
| 108 |
+
For example, suppose one of the arguments is an array containing the
|
| 109 |
+
answers to a survey question, with integer values 1 to 4. Even if the
|
| 110 |
+
value 1 does not occur in the data, we want an entry for it in the table.
|
| 111 |
+
|
| 112 |
+
>>> q1 = [2, 3, 3, 2, 4, 4, 2, 3, 4, 4, 4, 3, 3, 3, 4] # 1 does not occur.
|
| 113 |
+
>>> q2 = [4, 4, 2, 2, 2, 4, 1, 1, 2, 2, 4, 2, 2, 2, 4] # 3 does not occur.
|
| 114 |
+
>>> options = [1, 2, 3, 4]
|
| 115 |
+
>>> res = crosstab(q1, q2, levels=(options, options))
|
| 116 |
+
>>> res.count
|
| 117 |
+
array([[0, 0, 0, 0],
|
| 118 |
+
[1, 1, 0, 1],
|
| 119 |
+
[1, 4, 0, 1],
|
| 120 |
+
[0, 3, 0, 3]])
|
| 121 |
+
|
| 122 |
+
If `levels` is given, but an element of `levels` is None, the unique values
|
| 123 |
+
of the corresponding argument are used. For example,
|
| 124 |
+
|
| 125 |
+
>>> res = crosstab(q1, q2, levels=(None, options))
|
| 126 |
+
>>> res.elements
|
| 127 |
+
[array([2, 3, 4]), [1, 2, 3, 4]]
|
| 128 |
+
>>> res.count
|
| 129 |
+
array([[1, 1, 0, 1],
|
| 130 |
+
[1, 4, 0, 1],
|
| 131 |
+
[0, 3, 0, 3]])
|
| 132 |
+
|
| 133 |
+
If we want to ignore the pairs where 4 occurs in ``q2``, we can
|
| 134 |
+
give just the values [1, 2] to `levels`, and the 4 will be ignored:
|
| 135 |
+
|
| 136 |
+
>>> res = crosstab(q1, q2, levels=(None, [1, 2]))
|
| 137 |
+
>>> res.elements
|
| 138 |
+
[array([2, 3, 4]), [1, 2]]
|
| 139 |
+
>>> res.count
|
| 140 |
+
array([[1, 1],
|
| 141 |
+
[1, 4],
|
| 142 |
+
[0, 3]])
|
| 143 |
+
|
| 144 |
+
Finally, let's repeat the first example, but return a sparse matrix:
|
| 145 |
+
|
| 146 |
+
>>> res = crosstab(a, x, sparse=True)
|
| 147 |
+
>>> res.count
|
| 148 |
+
<COOrdinate sparse matrix of dtype 'int64'
|
| 149 |
+
with 4 stored elements and shape (2, 3)>
|
| 150 |
+
>>> res.count.toarray()
|
| 151 |
+
array([[2, 3, 0],
|
| 152 |
+
[1, 0, 4]])
|
| 153 |
+
|
| 154 |
+
"""
|
| 155 |
+
nargs = len(args)
|
| 156 |
+
if nargs == 0:
|
| 157 |
+
raise TypeError("At least one input sequence is required.")
|
| 158 |
+
|
| 159 |
+
len0 = len(args[0])
|
| 160 |
+
if not all(len(a) == len0 for a in args[1:]):
|
| 161 |
+
raise ValueError("All input sequences must have the same length.")
|
| 162 |
+
|
| 163 |
+
if sparse and nargs != 2:
|
| 164 |
+
raise ValueError("When `sparse` is True, only two input sequences "
|
| 165 |
+
"are allowed.")
|
| 166 |
+
|
| 167 |
+
if levels is None:
|
| 168 |
+
# Call np.unique with return_inverse=True on each argument.
|
| 169 |
+
actual_levels, indices = zip(*[np.unique(a, return_inverse=True)
|
| 170 |
+
for a in args])
|
| 171 |
+
else:
|
| 172 |
+
# `levels` is not None...
|
| 173 |
+
if len(levels) != nargs:
|
| 174 |
+
raise ValueError('len(levels) must equal the number of input '
|
| 175 |
+
'sequences')
|
| 176 |
+
|
| 177 |
+
args = [np.asarray(arg) for arg in args]
|
| 178 |
+
mask = np.zeros((nargs, len0), dtype=np.bool_)
|
| 179 |
+
inv = np.zeros((nargs, len0), dtype=np.intp)
|
| 180 |
+
actual_levels = []
|
| 181 |
+
for k, (levels_list, arg) in enumerate(zip(levels, args)):
|
| 182 |
+
if levels_list is None:
|
| 183 |
+
levels_list, inv[k, :] = np.unique(arg, return_inverse=True)
|
| 184 |
+
mask[k, :] = True
|
| 185 |
+
else:
|
| 186 |
+
q = arg == np.asarray(levels_list).reshape(-1, 1)
|
| 187 |
+
mask[k, :] = np.any(q, axis=0)
|
| 188 |
+
qnz = q.T.nonzero()
|
| 189 |
+
inv[k, qnz[0]] = qnz[1]
|
| 190 |
+
actual_levels.append(levels_list)
|
| 191 |
+
|
| 192 |
+
mask_all = mask.all(axis=0)
|
| 193 |
+
indices = tuple(inv[:, mask_all])
|
| 194 |
+
|
| 195 |
+
if sparse:
|
| 196 |
+
count = coo_matrix((np.ones(len(indices[0]), dtype=int),
|
| 197 |
+
(indices[0], indices[1])))
|
| 198 |
+
count.sum_duplicates()
|
| 199 |
+
else:
|
| 200 |
+
shape = [len(u) for u in actual_levels]
|
| 201 |
+
count = np.zeros(shape, dtype=int)
|
| 202 |
+
np.add.at(count, indices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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# Author: Travis Oliphant 2002-2011 with contributions from
|
| 3 |
+
# SciPy Developers 2004-2011
|
| 4 |
+
#
|
| 5 |
+
from functools import partial
|
| 6 |
+
|
| 7 |
+
from scipy import special
|
| 8 |
+
from scipy.special import entr, logsumexp, betaln, gammaln as gamln, zeta
|
| 9 |
+
from scipy._lib._util import _lazywhere, rng_integers
|
| 10 |
+
from scipy.interpolate import interp1d
|
| 11 |
+
|
| 12 |
+
from numpy import floor, ceil, log, exp, sqrt, log1p, expm1, tanh, cosh, sinh
|
| 13 |
+
|
| 14 |
+
import numpy as np
|
| 15 |
+
|
| 16 |
+
from ._distn_infrastructure import (rv_discrete, get_distribution_names,
|
| 17 |
+
_vectorize_rvs_over_shapes,
|
| 18 |
+
_ShapeInfo, _isintegral,
|
| 19 |
+
rv_discrete_frozen)
|
| 20 |
+
from ._biasedurn import (_PyFishersNCHypergeometric,
|
| 21 |
+
_PyWalleniusNCHypergeometric,
|
| 22 |
+
_PyStochasticLib3)
|
| 23 |
+
from ._stats_pythran import _poisson_binom
|
| 24 |
+
|
| 25 |
+
import scipy.special._ufuncs as scu
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
class binom_gen(rv_discrete):
|
| 30 |
+
r"""A binomial discrete random variable.
|
| 31 |
+
|
| 32 |
+
%(before_notes)s
|
| 33 |
+
|
| 34 |
+
Notes
|
| 35 |
+
-----
|
| 36 |
+
The probability mass function for `binom` is:
|
| 37 |
+
|
| 38 |
+
.. math::
|
| 39 |
+
|
| 40 |
+
f(k) = \binom{n}{k} p^k (1-p)^{n-k}
|
| 41 |
+
|
| 42 |
+
for :math:`k \in \{0, 1, \dots, n\}`, :math:`0 \leq p \leq 1`
|
| 43 |
+
|
| 44 |
+
`binom` takes :math:`n` and :math:`p` as shape parameters,
|
| 45 |
+
where :math:`p` is the probability of a single success
|
| 46 |
+
and :math:`1-p` is the probability of a single failure.
|
| 47 |
+
|
| 48 |
+
This distribution uses routines from the Boost Math C++ library for
|
| 49 |
+
the computation of the ``pmf``, ``cdf``, ``sf``, ``ppf`` and ``isf``
|
| 50 |
+
methods. [1]_
|
| 51 |
+
|
| 52 |
+
%(after_notes)s
|
| 53 |
+
|
| 54 |
+
References
|
| 55 |
+
----------
|
| 56 |
+
.. [1] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
|
| 57 |
+
|
| 58 |
+
%(example)s
|
| 59 |
+
|
| 60 |
+
See Also
|
| 61 |
+
--------
|
| 62 |
+
hypergeom, nbinom, nhypergeom
|
| 63 |
+
|
| 64 |
+
"""
|
| 65 |
+
def _shape_info(self):
|
| 66 |
+
return [_ShapeInfo("n", True, (0, np.inf), (True, False)),
|
| 67 |
+
_ShapeInfo("p", False, (0, 1), (True, True))]
|
| 68 |
+
|
| 69 |
+
def _rvs(self, n, p, size=None, random_state=None):
|
| 70 |
+
return random_state.binomial(n, p, size)
|
| 71 |
+
|
| 72 |
+
def _argcheck(self, n, p):
|
| 73 |
+
return (n >= 0) & _isintegral(n) & (p >= 0) & (p <= 1)
|
| 74 |
+
|
| 75 |
+
def _get_support(self, n, p):
|
| 76 |
+
return self.a, n
|
| 77 |
+
|
| 78 |
+
def _logpmf(self, x, n, p):
|
| 79 |
+
k = floor(x)
|
| 80 |
+
combiln = (gamln(n+1) - (gamln(k+1) + gamln(n-k+1)))
|
| 81 |
+
return combiln + special.xlogy(k, p) + special.xlog1py(n-k, -p)
|
| 82 |
+
|
| 83 |
+
def _pmf(self, x, n, p):
|
| 84 |
+
# binom.pmf(k) = choose(n, k) * p**k * (1-p)**(n-k)
|
| 85 |
+
return scu._binom_pmf(x, n, p)
|
| 86 |
+
|
| 87 |
+
def _cdf(self, x, n, p):
|
| 88 |
+
k = floor(x)
|
| 89 |
+
return scu._binom_cdf(k, n, p)
|
| 90 |
+
|
| 91 |
+
def _sf(self, x, n, p):
|
| 92 |
+
k = floor(x)
|
| 93 |
+
return scu._binom_sf(k, n, p)
|
| 94 |
+
|
| 95 |
+
def _isf(self, x, n, p):
|
| 96 |
+
return scu._binom_isf(x, n, p)
|
| 97 |
+
|
| 98 |
+
def _ppf(self, q, n, p):
|
| 99 |
+
return scu._binom_ppf(q, n, p)
|
| 100 |
+
|
| 101 |
+
def _stats(self, n, p, moments='mv'):
|
| 102 |
+
mu = n * p
|
| 103 |
+
var = mu - n * np.square(p)
|
| 104 |
+
g1, g2 = None, None
|
| 105 |
+
if 's' in moments:
|
| 106 |
+
pq = p - np.square(p)
|
| 107 |
+
npq_sqrt = np.sqrt(n * pq)
|
| 108 |
+
t1 = np.reciprocal(npq_sqrt)
|
| 109 |
+
t2 = (2.0 * p) / npq_sqrt
|
| 110 |
+
g1 = t1 - t2
|
| 111 |
+
if 'k' in moments:
|
| 112 |
+
pq = p - np.square(p)
|
| 113 |
+
npq = n * pq
|
| 114 |
+
t1 = np.reciprocal(npq)
|
| 115 |
+
t2 = 6.0/n
|
| 116 |
+
g2 = t1 - t2
|
| 117 |
+
return mu, var, g1, g2
|
| 118 |
+
|
| 119 |
+
def _entropy(self, n, p):
|
| 120 |
+
k = np.r_[0:n + 1]
|
| 121 |
+
vals = self._pmf(k, n, p)
|
| 122 |
+
return np.sum(entr(vals), axis=0)
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
binom = binom_gen(name='binom')
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
class bernoulli_gen(binom_gen):
|
| 129 |
+
r"""A Bernoulli discrete random variable.
|
| 130 |
+
|
| 131 |
+
%(before_notes)s
|
| 132 |
+
|
| 133 |
+
Notes
|
| 134 |
+
-----
|
| 135 |
+
The probability mass function for `bernoulli` is:
|
| 136 |
+
|
| 137 |
+
.. math::
|
| 138 |
+
|
| 139 |
+
f(k) = \begin{cases}1-p &\text{if } k = 0\\
|
| 140 |
+
p &\text{if } k = 1\end{cases}
|
| 141 |
+
|
| 142 |
+
for :math:`k` in :math:`\{0, 1\}`, :math:`0 \leq p \leq 1`
|
| 143 |
+
|
| 144 |
+
`bernoulli` takes :math:`p` as shape parameter,
|
| 145 |
+
where :math:`p` is the probability of a single success
|
| 146 |
+
and :math:`1-p` is the probability of a single failure.
|
| 147 |
+
|
| 148 |
+
%(after_notes)s
|
| 149 |
+
|
| 150 |
+
%(example)s
|
| 151 |
+
|
| 152 |
+
"""
|
| 153 |
+
def _shape_info(self):
|
| 154 |
+
return [_ShapeInfo("p", False, (0, 1), (True, True))]
|
| 155 |
+
|
| 156 |
+
def _rvs(self, p, size=None, random_state=None):
|
| 157 |
+
return binom_gen._rvs(self, 1, p, size=size, random_state=random_state)
|
| 158 |
+
|
| 159 |
+
def _argcheck(self, p):
|
| 160 |
+
return (p >= 0) & (p <= 1)
|
| 161 |
+
|
| 162 |
+
def _get_support(self, p):
|
| 163 |
+
# Overrides binom_gen._get_support!x
|
| 164 |
+
return self.a, self.b
|
| 165 |
+
|
| 166 |
+
def _logpmf(self, x, p):
|
| 167 |
+
return binom._logpmf(x, 1, p)
|
| 168 |
+
|
| 169 |
+
def _pmf(self, x, p):
|
| 170 |
+
# bernoulli.pmf(k) = 1-p if k = 0
|
| 171 |
+
# = p if k = 1
|
| 172 |
+
return binom._pmf(x, 1, p)
|
| 173 |
+
|
| 174 |
+
def _cdf(self, x, p):
|
| 175 |
+
return binom._cdf(x, 1, p)
|
| 176 |
+
|
| 177 |
+
def _sf(self, x, p):
|
| 178 |
+
return binom._sf(x, 1, p)
|
| 179 |
+
|
| 180 |
+
def _isf(self, x, p):
|
| 181 |
+
return binom._isf(x, 1, p)
|
| 182 |
+
|
| 183 |
+
def _ppf(self, q, p):
|
| 184 |
+
return binom._ppf(q, 1, p)
|
| 185 |
+
|
| 186 |
+
def _stats(self, p):
|
| 187 |
+
return binom._stats(1, p)
|
| 188 |
+
|
| 189 |
+
def _entropy(self, p):
|
| 190 |
+
return entr(p) + entr(1-p)
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
bernoulli = bernoulli_gen(b=1, name='bernoulli')
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
class betabinom_gen(rv_discrete):
|
| 197 |
+
r"""A beta-binomial discrete random variable.
|
| 198 |
+
|
| 199 |
+
%(before_notes)s
|
| 200 |
+
|
| 201 |
+
Notes
|
| 202 |
+
-----
|
| 203 |
+
The beta-binomial distribution is a binomial distribution with a
|
| 204 |
+
probability of success `p` that follows a beta distribution.
|
| 205 |
+
|
| 206 |
+
The probability mass function for `betabinom` is:
|
| 207 |
+
|
| 208 |
+
.. math::
|
| 209 |
+
|
| 210 |
+
f(k) = \binom{n}{k} \frac{B(k + a, n - k + b)}{B(a, b)}
|
| 211 |
+
|
| 212 |
+
for :math:`k \in \{0, 1, \dots, n\}`, :math:`n \geq 0`, :math:`a > 0`,
|
| 213 |
+
:math:`b > 0`, where :math:`B(a, b)` is the beta function.
|
| 214 |
+
|
| 215 |
+
`betabinom` takes :math:`n`, :math:`a`, and :math:`b` as shape parameters.
|
| 216 |
+
|
| 217 |
+
References
|
| 218 |
+
----------
|
| 219 |
+
.. [1] https://en.wikipedia.org/wiki/Beta-binomial_distribution
|
| 220 |
+
|
| 221 |
+
%(after_notes)s
|
| 222 |
+
|
| 223 |
+
.. versionadded:: 1.4.0
|
| 224 |
+
|
| 225 |
+
See Also
|
| 226 |
+
--------
|
| 227 |
+
beta, binom
|
| 228 |
+
|
| 229 |
+
%(example)s
|
| 230 |
+
|
| 231 |
+
"""
|
| 232 |
+
def _shape_info(self):
|
| 233 |
+
return [_ShapeInfo("n", True, (0, np.inf), (True, False)),
|
| 234 |
+
_ShapeInfo("a", False, (0, np.inf), (False, False)),
|
| 235 |
+
_ShapeInfo("b", False, (0, np.inf), (False, False))]
|
| 236 |
+
|
| 237 |
+
def _rvs(self, n, a, b, size=None, random_state=None):
|
| 238 |
+
p = random_state.beta(a, b, size)
|
| 239 |
+
return random_state.binomial(n, p, size)
|
| 240 |
+
|
| 241 |
+
def _get_support(self, n, a, b):
|
| 242 |
+
return 0, n
|
| 243 |
+
|
| 244 |
+
def _argcheck(self, n, a, b):
|
| 245 |
+
return (n >= 0) & _isintegral(n) & (a > 0) & (b > 0)
|
| 246 |
+
|
| 247 |
+
def _logpmf(self, x, n, a, b):
|
| 248 |
+
k = floor(x)
|
| 249 |
+
combiln = -log(n + 1) - betaln(n - k + 1, k + 1)
|
| 250 |
+
return combiln + betaln(k + a, n - k + b) - betaln(a, b)
|
| 251 |
+
|
| 252 |
+
def _pmf(self, x, n, a, b):
|
| 253 |
+
return exp(self._logpmf(x, n, a, b))
|
| 254 |
+
|
| 255 |
+
def _stats(self, n, a, b, moments='mv'):
|
| 256 |
+
e_p = a / (a + b)
|
| 257 |
+
e_q = 1 - e_p
|
| 258 |
+
mu = n * e_p
|
| 259 |
+
var = n * (a + b + n) * e_p * e_q / (a + b + 1)
|
| 260 |
+
g1, g2 = None, None
|
| 261 |
+
if 's' in moments:
|
| 262 |
+
g1 = 1.0 / sqrt(var)
|
| 263 |
+
g1 *= (a + b + 2 * n) * (b - a)
|
| 264 |
+
g1 /= (a + b + 2) * (a + b)
|
| 265 |
+
if 'k' in moments:
|
| 266 |
+
g2 = (a + b).astype(e_p.dtype)
|
| 267 |
+
g2 *= (a + b - 1 + 6 * n)
|
| 268 |
+
g2 += 3 * a * b * (n - 2)
|
| 269 |
+
g2 += 6 * n ** 2
|
| 270 |
+
g2 -= 3 * e_p * b * n * (6 - n)
|
| 271 |
+
g2 -= 18 * e_p * e_q * n ** 2
|
| 272 |
+
g2 *= (a + b) ** 2 * (1 + a + b)
|
| 273 |
+
g2 /= (n * a * b * (a + b + 2) * (a + b + 3) * (a + b + n))
|
| 274 |
+
g2 -= 3
|
| 275 |
+
return mu, var, g1, g2
|
| 276 |
+
|
| 277 |
+
|
| 278 |
+
betabinom = betabinom_gen(name='betabinom')
|
| 279 |
+
|
| 280 |
+
|
| 281 |
+
class nbinom_gen(rv_discrete):
|
| 282 |
+
r"""A negative binomial discrete random variable.
|
| 283 |
+
|
| 284 |
+
%(before_notes)s
|
| 285 |
+
|
| 286 |
+
Notes
|
| 287 |
+
-----
|
| 288 |
+
Negative binomial distribution describes a sequence of i.i.d. Bernoulli
|
| 289 |
+
trials, repeated until a predefined, non-random number of successes occurs.
|
| 290 |
+
|
| 291 |
+
The probability mass function of the number of failures for `nbinom` is:
|
| 292 |
+
|
| 293 |
+
.. math::
|
| 294 |
+
|
| 295 |
+
f(k) = \binom{k+n-1}{n-1} p^n (1-p)^k
|
| 296 |
+
|
| 297 |
+
for :math:`k \ge 0`, :math:`0 < p \leq 1`
|
| 298 |
+
|
| 299 |
+
`nbinom` takes :math:`n` and :math:`p` as shape parameters where :math:`n`
|
| 300 |
+
is the number of successes, :math:`p` is the probability of a single
|
| 301 |
+
success, and :math:`1-p` is the probability of a single failure.
|
| 302 |
+
|
| 303 |
+
Another common parameterization of the negative binomial distribution is
|
| 304 |
+
in terms of the mean number of failures :math:`\mu` to achieve :math:`n`
|
| 305 |
+
successes. The mean :math:`\mu` is related to the probability of success
|
| 306 |
+
as
|
| 307 |
+
|
| 308 |
+
.. math::
|
| 309 |
+
|
| 310 |
+
p = \frac{n}{n + \mu}
|
| 311 |
+
|
| 312 |
+
The number of successes :math:`n` may also be specified in terms of a
|
| 313 |
+
"dispersion", "heterogeneity", or "aggregation" parameter :math:`\alpha`,
|
| 314 |
+
which relates the mean :math:`\mu` to the variance :math:`\sigma^2`,
|
| 315 |
+
e.g. :math:`\sigma^2 = \mu + \alpha \mu^2`. Regardless of the convention
|
| 316 |
+
used for :math:`\alpha`,
|
| 317 |
+
|
| 318 |
+
.. math::
|
| 319 |
+
|
| 320 |
+
p &= \frac{\mu}{\sigma^2} \\
|
| 321 |
+
n &= \frac{\mu^2}{\sigma^2 - \mu}
|
| 322 |
+
|
| 323 |
+
This distribution uses routines from the Boost Math C++ library for
|
| 324 |
+
the computation of the ``pmf``, ``cdf``, ``sf``, ``ppf``, ``isf``
|
| 325 |
+
and ``stats`` methods. [1]_
|
| 326 |
+
|
| 327 |
+
%(after_notes)s
|
| 328 |
+
|
| 329 |
+
References
|
| 330 |
+
----------
|
| 331 |
+
.. [1] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
|
| 332 |
+
|
| 333 |
+
%(example)s
|
| 334 |
+
|
| 335 |
+
See Also
|
| 336 |
+
--------
|
| 337 |
+
hypergeom, binom, nhypergeom
|
| 338 |
+
|
| 339 |
+
"""
|
| 340 |
+
def _shape_info(self):
|
| 341 |
+
return [_ShapeInfo("n", True, (0, np.inf), (True, False)),
|
| 342 |
+
_ShapeInfo("p", False, (0, 1), (True, True))]
|
| 343 |
+
|
| 344 |
+
def _rvs(self, n, p, size=None, random_state=None):
|
| 345 |
+
return random_state.negative_binomial(n, p, size)
|
| 346 |
+
|
| 347 |
+
def _argcheck(self, n, p):
|
| 348 |
+
return (n > 0) & (p > 0) & (p <= 1)
|
| 349 |
+
|
| 350 |
+
def _pmf(self, x, n, p):
|
| 351 |
+
# nbinom.pmf(k) = choose(k+n-1, n-1) * p**n * (1-p)**k
|
| 352 |
+
return scu._nbinom_pmf(x, n, p)
|
| 353 |
+
|
| 354 |
+
def _logpmf(self, x, n, p):
|
| 355 |
+
coeff = gamln(n+x) - gamln(x+1) - gamln(n)
|
| 356 |
+
return coeff + n*log(p) + special.xlog1py(x, -p)
|
| 357 |
+
|
| 358 |
+
def _cdf(self, x, n, p):
|
| 359 |
+
k = floor(x)
|
| 360 |
+
return scu._nbinom_cdf(k, n, p)
|
| 361 |
+
|
| 362 |
+
def _logcdf(self, x, n, p):
|
| 363 |
+
k = floor(x)
|
| 364 |
+
k, n, p = np.broadcast_arrays(k, n, p)
|
| 365 |
+
cdf = self._cdf(k, n, p)
|
| 366 |
+
cond = cdf > 0.5
|
| 367 |
+
def f1(k, n, p):
|
| 368 |
+
return np.log1p(-special.betainc(k + 1, n, 1 - p))
|
| 369 |
+
|
| 370 |
+
# do calc in place
|
| 371 |
+
logcdf = cdf
|
| 372 |
+
with np.errstate(divide='ignore'):
|
| 373 |
+
logcdf[cond] = f1(k[cond], n[cond], p[cond])
|
| 374 |
+
logcdf[~cond] = np.log(cdf[~cond])
|
| 375 |
+
return logcdf
|
| 376 |
+
|
| 377 |
+
def _sf(self, x, n, p):
|
| 378 |
+
k = floor(x)
|
| 379 |
+
return scu._nbinom_sf(k, n, p)
|
| 380 |
+
|
| 381 |
+
def _isf(self, x, n, p):
|
| 382 |
+
with np.errstate(over='ignore'): # see gh-17432
|
| 383 |
+
return scu._nbinom_isf(x, n, p)
|
| 384 |
+
|
| 385 |
+
def _ppf(self, q, n, p):
|
| 386 |
+
with np.errstate(over='ignore'): # see gh-17432
|
| 387 |
+
return scu._nbinom_ppf(q, n, p)
|
| 388 |
+
|
| 389 |
+
def _stats(self, n, p):
|
| 390 |
+
return (
|
| 391 |
+
scu._nbinom_mean(n, p),
|
| 392 |
+
scu._nbinom_variance(n, p),
|
| 393 |
+
scu._nbinom_skewness(n, p),
|
| 394 |
+
scu._nbinom_kurtosis_excess(n, p),
|
| 395 |
+
)
|
| 396 |
+
|
| 397 |
+
|
| 398 |
+
nbinom = nbinom_gen(name='nbinom')
|
| 399 |
+
|
| 400 |
+
|
| 401 |
+
class betanbinom_gen(rv_discrete):
|
| 402 |
+
r"""A beta-negative-binomial discrete random variable.
|
| 403 |
+
|
| 404 |
+
%(before_notes)s
|
| 405 |
+
|
| 406 |
+
Notes
|
| 407 |
+
-----
|
| 408 |
+
The beta-negative-binomial distribution is a negative binomial
|
| 409 |
+
distribution with a probability of success `p` that follows a
|
| 410 |
+
beta distribution.
|
| 411 |
+
|
| 412 |
+
The probability mass function for `betanbinom` is:
|
| 413 |
+
|
| 414 |
+
.. math::
|
| 415 |
+
|
| 416 |
+
f(k) = \binom{n + k - 1}{k} \frac{B(a + n, b + k)}{B(a, b)}
|
| 417 |
+
|
| 418 |
+
for :math:`k \ge 0`, :math:`n \geq 0`, :math:`a > 0`,
|
| 419 |
+
:math:`b > 0`, where :math:`B(a, b)` is the beta function.
|
| 420 |
+
|
| 421 |
+
`betanbinom` takes :math:`n`, :math:`a`, and :math:`b` as shape parameters.
|
| 422 |
+
|
| 423 |
+
References
|
| 424 |
+
----------
|
| 425 |
+
.. [1] https://en.wikipedia.org/wiki/Beta_negative_binomial_distribution
|
| 426 |
+
|
| 427 |
+
%(after_notes)s
|
| 428 |
+
|
| 429 |
+
.. versionadded:: 1.12.0
|
| 430 |
+
|
| 431 |
+
See Also
|
| 432 |
+
--------
|
| 433 |
+
betabinom : Beta binomial distribution
|
| 434 |
+
|
| 435 |
+
%(example)s
|
| 436 |
+
|
| 437 |
+
"""
|
| 438 |
+
def _shape_info(self):
|
| 439 |
+
return [_ShapeInfo("n", True, (0, np.inf), (True, False)),
|
| 440 |
+
_ShapeInfo("a", False, (0, np.inf), (False, False)),
|
| 441 |
+
_ShapeInfo("b", False, (0, np.inf), (False, False))]
|
| 442 |
+
|
| 443 |
+
def _rvs(self, n, a, b, size=None, random_state=None):
|
| 444 |
+
p = random_state.beta(a, b, size)
|
| 445 |
+
return random_state.negative_binomial(n, p, size)
|
| 446 |
+
|
| 447 |
+
def _argcheck(self, n, a, b):
|
| 448 |
+
return (n >= 0) & _isintegral(n) & (a > 0) & (b > 0)
|
| 449 |
+
|
| 450 |
+
def _logpmf(self, x, n, a, b):
|
| 451 |
+
k = floor(x)
|
| 452 |
+
combiln = -np.log(n + k) - betaln(n, k + 1)
|
| 453 |
+
return combiln + betaln(a + n, b + k) - betaln(a, b)
|
| 454 |
+
|
| 455 |
+
def _pmf(self, x, n, a, b):
|
| 456 |
+
return exp(self._logpmf(x, n, a, b))
|
| 457 |
+
|
| 458 |
+
def _stats(self, n, a, b, moments='mv'):
|
| 459 |
+
# reference: Wolfram Alpha input
|
| 460 |
+
# BetaNegativeBinomialDistribution[a, b, n]
|
| 461 |
+
def mean(n, a, b):
|
| 462 |
+
return n * b / (a - 1.)
|
| 463 |
+
mu = _lazywhere(a > 1, (n, a, b), f=mean, fillvalue=np.inf)
|
| 464 |
+
def var(n, a, b):
|
| 465 |
+
return (n * b * (n + a - 1.) * (a + b - 1.)
|
| 466 |
+
/ ((a - 2.) * (a - 1.)**2.))
|
| 467 |
+
var = _lazywhere(a > 2, (n, a, b), f=var, fillvalue=np.inf)
|
| 468 |
+
g1, g2 = None, None
|
| 469 |
+
def skew(n, a, b):
|
| 470 |
+
return ((2 * n + a - 1.) * (2 * b + a - 1.)
|
| 471 |
+
/ (a - 3.) / sqrt(n * b * (n + a - 1.) * (b + a - 1.)
|
| 472 |
+
/ (a - 2.)))
|
| 473 |
+
if 's' in moments:
|
| 474 |
+
g1 = _lazywhere(a > 3, (n, a, b), f=skew, fillvalue=np.inf)
|
| 475 |
+
def kurtosis(n, a, b):
|
| 476 |
+
term = (a - 2.)
|
| 477 |
+
term_2 = ((a - 1.)**2. * (a**2. + a * (6 * b - 1.)
|
| 478 |
+
+ 6. * (b - 1.) * b)
|
| 479 |
+
+ 3. * n**2. * ((a + 5.) * b**2. + (a + 5.)
|
| 480 |
+
* (a - 1.) * b + 2. * (a - 1.)**2)
|
| 481 |
+
+ 3 * (a - 1.) * n
|
| 482 |
+
* ((a + 5.) * b**2. + (a + 5.) * (a - 1.) * b
|
| 483 |
+
+ 2. * (a - 1.)**2.))
|
| 484 |
+
denominator = ((a - 4.) * (a - 3.) * b * n
|
| 485 |
+
* (a + b - 1.) * (a + n - 1.))
|
| 486 |
+
# Wolfram Alpha uses Pearson kurtosis, so we subtract 3 to get
|
| 487 |
+
# scipy's Fisher kurtosis
|
| 488 |
+
return term * term_2 / denominator - 3.
|
| 489 |
+
if 'k' in moments:
|
| 490 |
+
g2 = _lazywhere(a > 4, (n, a, b), f=kurtosis, fillvalue=np.inf)
|
| 491 |
+
return mu, var, g1, g2
|
| 492 |
+
|
| 493 |
+
|
| 494 |
+
betanbinom = betanbinom_gen(name='betanbinom')
|
| 495 |
+
|
| 496 |
+
|
| 497 |
+
class geom_gen(rv_discrete):
|
| 498 |
+
r"""A geometric discrete random variable.
|
| 499 |
+
|
| 500 |
+
%(before_notes)s
|
| 501 |
+
|
| 502 |
+
Notes
|
| 503 |
+
-----
|
| 504 |
+
The probability mass function for `geom` is:
|
| 505 |
+
|
| 506 |
+
.. math::
|
| 507 |
+
|
| 508 |
+
f(k) = (1-p)^{k-1} p
|
| 509 |
+
|
| 510 |
+
for :math:`k \ge 1`, :math:`0 < p \leq 1`
|
| 511 |
+
|
| 512 |
+
`geom` takes :math:`p` as shape parameter,
|
| 513 |
+
where :math:`p` is the probability of a single success
|
| 514 |
+
and :math:`1-p` is the probability of a single failure.
|
| 515 |
+
|
| 516 |
+
Note that when drawing random samples, the probability of observations that exceed
|
| 517 |
+
``np.iinfo(np.int64).max`` increases rapidly as $p$ decreases below $10^{-17}$. For
|
| 518 |
+
$p < 10^{-20}$, almost all observations would exceed the maximum ``int64``; however,
|
| 519 |
+
the output dtype is always ``int64``, so these values are clipped to the maximum.
|
| 520 |
+
|
| 521 |
+
%(after_notes)s
|
| 522 |
+
|
| 523 |
+
See Also
|
| 524 |
+
--------
|
| 525 |
+
planck
|
| 526 |
+
|
| 527 |
+
%(example)s
|
| 528 |
+
|
| 529 |
+
"""
|
| 530 |
+
|
| 531 |
+
def _shape_info(self):
|
| 532 |
+
return [_ShapeInfo("p", False, (0, 1), (True, True))]
|
| 533 |
+
|
| 534 |
+
def _rvs(self, p, size=None, random_state=None):
|
| 535 |
+
res = random_state.geometric(p, size=size)
|
| 536 |
+
# RandomState.geometric can wrap around to negative values; make behavior
|
| 537 |
+
# consistent with Generator.geometric by replacing with maximum integer.
|
| 538 |
+
max_int = np.iinfo(res.dtype).max
|
| 539 |
+
return np.where(res < 0, max_int, res)
|
| 540 |
+
|
| 541 |
+
def _argcheck(self, p):
|
| 542 |
+
return (p <= 1) & (p > 0)
|
| 543 |
+
|
| 544 |
+
def _pmf(self, k, p):
|
| 545 |
+
return np.power(1-p, k-1) * p
|
| 546 |
+
|
| 547 |
+
def _logpmf(self, k, p):
|
| 548 |
+
return special.xlog1py(k - 1, -p) + log(p)
|
| 549 |
+
|
| 550 |
+
def _cdf(self, x, p):
|
| 551 |
+
k = floor(x)
|
| 552 |
+
return -expm1(log1p(-p)*k)
|
| 553 |
+
|
| 554 |
+
def _sf(self, x, p):
|
| 555 |
+
return np.exp(self._logsf(x, p))
|
| 556 |
+
|
| 557 |
+
def _logsf(self, x, p):
|
| 558 |
+
k = floor(x)
|
| 559 |
+
return k*log1p(-p)
|
| 560 |
+
|
| 561 |
+
def _ppf(self, q, p):
|
| 562 |
+
vals = ceil(log1p(-q) / log1p(-p))
|
| 563 |
+
temp = self._cdf(vals-1, p)
|
| 564 |
+
return np.where((temp >= q) & (vals > 0), vals-1, vals)
|
| 565 |
+
|
| 566 |
+
def _stats(self, p):
|
| 567 |
+
mu = 1.0/p
|
| 568 |
+
qr = 1.0-p
|
| 569 |
+
var = qr / p / p
|
| 570 |
+
g1 = (2.0-p) / sqrt(qr)
|
| 571 |
+
g2 = np.polyval([1, -6, 6], p)/(1.0-p)
|
| 572 |
+
return mu, var, g1, g2
|
| 573 |
+
|
| 574 |
+
def _entropy(self, p):
|
| 575 |
+
return -np.log(p) - np.log1p(-p) * (1.0-p) / p
|
| 576 |
+
|
| 577 |
+
|
| 578 |
+
geom = geom_gen(a=1, name='geom', longname="A geometric")
|
| 579 |
+
|
| 580 |
+
|
| 581 |
+
class hypergeom_gen(rv_discrete):
|
| 582 |
+
r"""A hypergeometric discrete random variable.
|
| 583 |
+
|
| 584 |
+
The hypergeometric distribution models drawing objects from a bin.
|
| 585 |
+
`M` is the total number of objects, `n` is total number of Type I objects.
|
| 586 |
+
The random variate represents the number of Type I objects in `N` drawn
|
| 587 |
+
without replacement from the total population.
|
| 588 |
+
|
| 589 |
+
%(before_notes)s
|
| 590 |
+
|
| 591 |
+
Notes
|
| 592 |
+
-----
|
| 593 |
+
The symbols used to denote the shape parameters (`M`, `n`, and `N`) are not
|
| 594 |
+
universally accepted. See the Examples for a clarification of the
|
| 595 |
+
definitions used here.
|
| 596 |
+
|
| 597 |
+
The probability mass function is defined as,
|
| 598 |
+
|
| 599 |
+
.. math:: p(k, M, n, N) = \frac{\binom{n}{k} \binom{M - n}{N - k}}
|
| 600 |
+
{\binom{M}{N}}
|
| 601 |
+
|
| 602 |
+
for :math:`k \in [\max(0, N - M + n), \min(n, N)]`, where the binomial
|
| 603 |
+
coefficients are defined as,
|
| 604 |
+
|
| 605 |
+
.. math:: \binom{n}{k} \equiv \frac{n!}{k! (n - k)!}.
|
| 606 |
+
|
| 607 |
+
This distribution uses routines from the Boost Math C++ library for
|
| 608 |
+
the computation of the ``pmf``, ``cdf``, ``sf`` and ``stats`` methods. [1]_
|
| 609 |
+
|
| 610 |
+
%(after_notes)s
|
| 611 |
+
|
| 612 |
+
References
|
| 613 |
+
----------
|
| 614 |
+
.. [1] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
|
| 615 |
+
|
| 616 |
+
Examples
|
| 617 |
+
--------
|
| 618 |
+
>>> import numpy as np
|
| 619 |
+
>>> from scipy.stats import hypergeom
|
| 620 |
+
>>> import matplotlib.pyplot as plt
|
| 621 |
+
|
| 622 |
+
Suppose we have a collection of 20 animals, of which 7 are dogs. Then if
|
| 623 |
+
we want to know the probability of finding a given number of dogs if we
|
| 624 |
+
choose at random 12 of the 20 animals, we can initialize a frozen
|
| 625 |
+
distribution and plot the probability mass function:
|
| 626 |
+
|
| 627 |
+
>>> [M, n, N] = [20, 7, 12]
|
| 628 |
+
>>> rv = hypergeom(M, n, N)
|
| 629 |
+
>>> x = np.arange(0, n+1)
|
| 630 |
+
>>> pmf_dogs = rv.pmf(x)
|
| 631 |
+
|
| 632 |
+
>>> fig = plt.figure()
|
| 633 |
+
>>> ax = fig.add_subplot(111)
|
| 634 |
+
>>> ax.plot(x, pmf_dogs, 'bo')
|
| 635 |
+
>>> ax.vlines(x, 0, pmf_dogs, lw=2)
|
| 636 |
+
>>> ax.set_xlabel('# of dogs in our group of chosen animals')
|
| 637 |
+
>>> ax.set_ylabel('hypergeom PMF')
|
| 638 |
+
>>> plt.show()
|
| 639 |
+
|
| 640 |
+
Instead of using a frozen distribution we can also use `hypergeom`
|
| 641 |
+
methods directly. To for example obtain the cumulative distribution
|
| 642 |
+
function, use:
|
| 643 |
+
|
| 644 |
+
>>> prb = hypergeom.cdf(x, M, n, N)
|
| 645 |
+
|
| 646 |
+
And to generate random numbers:
|
| 647 |
+
|
| 648 |
+
>>> R = hypergeom.rvs(M, n, N, size=10)
|
| 649 |
+
|
| 650 |
+
See Also
|
| 651 |
+
--------
|
| 652 |
+
nhypergeom, binom, nbinom
|
| 653 |
+
|
| 654 |
+
"""
|
| 655 |
+
def _shape_info(self):
|
| 656 |
+
return [_ShapeInfo("M", True, (0, np.inf), (True, False)),
|
| 657 |
+
_ShapeInfo("n", True, (0, np.inf), (True, False)),
|
| 658 |
+
_ShapeInfo("N", True, (0, np.inf), (True, False))]
|
| 659 |
+
|
| 660 |
+
def _rvs(self, M, n, N, size=None, random_state=None):
|
| 661 |
+
return random_state.hypergeometric(n, M-n, N, size=size)
|
| 662 |
+
|
| 663 |
+
def _get_support(self, M, n, N):
|
| 664 |
+
return np.maximum(N-(M-n), 0), np.minimum(n, N)
|
| 665 |
+
|
| 666 |
+
def _argcheck(self, M, n, N):
|
| 667 |
+
cond = (M > 0) & (n >= 0) & (N >= 0)
|
| 668 |
+
cond &= (n <= M) & (N <= M)
|
| 669 |
+
cond &= _isintegral(M) & _isintegral(n) & _isintegral(N)
|
| 670 |
+
return cond
|
| 671 |
+
|
| 672 |
+
def _logpmf(self, k, M, n, N):
|
| 673 |
+
tot, good = M, n
|
| 674 |
+
bad = tot - good
|
| 675 |
+
result = (betaln(good+1, 1) + betaln(bad+1, 1) + betaln(tot-N+1, N+1) -
|
| 676 |
+
betaln(k+1, good-k+1) - betaln(N-k+1, bad-N+k+1) -
|
| 677 |
+
betaln(tot+1, 1))
|
| 678 |
+
return result
|
| 679 |
+
|
| 680 |
+
def _pmf(self, k, M, n, N):
|
| 681 |
+
return scu._hypergeom_pmf(k, n, N, M)
|
| 682 |
+
|
| 683 |
+
def _cdf(self, k, M, n, N):
|
| 684 |
+
return scu._hypergeom_cdf(k, n, N, M)
|
| 685 |
+
|
| 686 |
+
def _stats(self, M, n, N):
|
| 687 |
+
M, n, N = 1. * M, 1. * n, 1. * N
|
| 688 |
+
m = M - n
|
| 689 |
+
|
| 690 |
+
# Boost kurtosis_excess doesn't return the same as the value
|
| 691 |
+
# computed here.
|
| 692 |
+
g2 = M * (M + 1) - 6. * N * (M - N) - 6. * n * m
|
| 693 |
+
g2 *= (M - 1) * M * M
|
| 694 |
+
g2 += 6. * n * N * (M - N) * m * (5. * M - 6)
|
| 695 |
+
g2 /= n * N * (M - N) * m * (M - 2.) * (M - 3.)
|
| 696 |
+
return (
|
| 697 |
+
scu._hypergeom_mean(n, N, M),
|
| 698 |
+
scu._hypergeom_variance(n, N, M),
|
| 699 |
+
scu._hypergeom_skewness(n, N, M),
|
| 700 |
+
g2,
|
| 701 |
+
)
|
| 702 |
+
|
| 703 |
+
def _entropy(self, M, n, N):
|
| 704 |
+
k = np.r_[N - (M - n):min(n, N) + 1]
|
| 705 |
+
vals = self.pmf(k, M, n, N)
|
| 706 |
+
return np.sum(entr(vals), axis=0)
|
| 707 |
+
|
| 708 |
+
def _sf(self, k, M, n, N):
|
| 709 |
+
return scu._hypergeom_sf(k, n, N, M)
|
| 710 |
+
|
| 711 |
+
def _logsf(self, k, M, n, N):
|
| 712 |
+
res = []
|
| 713 |
+
for quant, tot, good, draw in zip(*np.broadcast_arrays(k, M, n, N)):
|
| 714 |
+
if (quant + 0.5) * (tot + 0.5) < (good - 0.5) * (draw - 0.5):
|
| 715 |
+
# Less terms to sum if we calculate log(1-cdf)
|
| 716 |
+
res.append(log1p(-exp(self.logcdf(quant, tot, good, draw))))
|
| 717 |
+
else:
|
| 718 |
+
# Integration over probability mass function using logsumexp
|
| 719 |
+
k2 = np.arange(quant + 1, draw + 1)
|
| 720 |
+
res.append(logsumexp(self._logpmf(k2, tot, good, draw)))
|
| 721 |
+
return np.asarray(res)
|
| 722 |
+
|
| 723 |
+
def _logcdf(self, k, M, n, N):
|
| 724 |
+
res = []
|
| 725 |
+
for quant, tot, good, draw in zip(*np.broadcast_arrays(k, M, n, N)):
|
| 726 |
+
if (quant + 0.5) * (tot + 0.5) > (good - 0.5) * (draw - 0.5):
|
| 727 |
+
# Less terms to sum if we calculate log(1-sf)
|
| 728 |
+
res.append(log1p(-exp(self.logsf(quant, tot, good, draw))))
|
| 729 |
+
else:
|
| 730 |
+
# Integration over probability mass function using logsumexp
|
| 731 |
+
k2 = np.arange(0, quant + 1)
|
| 732 |
+
res.append(logsumexp(self._logpmf(k2, tot, good, draw)))
|
| 733 |
+
return np.asarray(res)
|
| 734 |
+
|
| 735 |
+
|
| 736 |
+
hypergeom = hypergeom_gen(name='hypergeom')
|
| 737 |
+
|
| 738 |
+
|
| 739 |
+
class nhypergeom_gen(rv_discrete):
|
| 740 |
+
r"""A negative hypergeometric discrete random variable.
|
| 741 |
+
|
| 742 |
+
Consider a box containing :math:`M` balls:, :math:`n` red and
|
| 743 |
+
:math:`M-n` blue. We randomly sample balls from the box, one
|
| 744 |
+
at a time and *without* replacement, until we have picked :math:`r`
|
| 745 |
+
blue balls. `nhypergeom` is the distribution of the number of
|
| 746 |
+
red balls :math:`k` we have picked.
|
| 747 |
+
|
| 748 |
+
%(before_notes)s
|
| 749 |
+
|
| 750 |
+
Notes
|
| 751 |
+
-----
|
| 752 |
+
The symbols used to denote the shape parameters (`M`, `n`, and `r`) are not
|
| 753 |
+
universally accepted. See the Examples for a clarification of the
|
| 754 |
+
definitions used here.
|
| 755 |
+
|
| 756 |
+
The probability mass function is defined as,
|
| 757 |
+
|
| 758 |
+
.. math:: f(k; M, n, r) = \frac{{{k+r-1}\choose{k}}{{M-r-k}\choose{n-k}}}
|
| 759 |
+
{{M \choose n}}
|
| 760 |
+
|
| 761 |
+
for :math:`k \in [0, n]`, :math:`n \in [0, M]`, :math:`r \in [0, M-n]`,
|
| 762 |
+
and the binomial coefficient is:
|
| 763 |
+
|
| 764 |
+
.. math:: \binom{n}{k} \equiv \frac{n!}{k! (n - k)!}.
|
| 765 |
+
|
| 766 |
+
It is equivalent to observing :math:`k` successes in :math:`k+r-1`
|
| 767 |
+
samples with :math:`k+r`'th sample being a failure. The former
|
| 768 |
+
can be modelled as a hypergeometric distribution. The probability
|
| 769 |
+
of the latter is simply the number of failures remaining
|
| 770 |
+
:math:`M-n-(r-1)` divided by the size of the remaining population
|
| 771 |
+
:math:`M-(k+r-1)`. This relationship can be shown as:
|
| 772 |
+
|
| 773 |
+
.. math:: NHG(k;M,n,r) = HG(k;M,n,k+r-1)\frac{(M-n-(r-1))}{(M-(k+r-1))}
|
| 774 |
+
|
| 775 |
+
where :math:`NHG` is probability mass function (PMF) of the
|
| 776 |
+
negative hypergeometric distribution and :math:`HG` is the
|
| 777 |
+
PMF of the hypergeometric distribution.
|
| 778 |
+
|
| 779 |
+
%(after_notes)s
|
| 780 |
+
|
| 781 |
+
Examples
|
| 782 |
+
--------
|
| 783 |
+
>>> import numpy as np
|
| 784 |
+
>>> from scipy.stats import nhypergeom
|
| 785 |
+
>>> import matplotlib.pyplot as plt
|
| 786 |
+
|
| 787 |
+
Suppose we have a collection of 20 animals, of which 7 are dogs.
|
| 788 |
+
Then if we want to know the probability of finding a given number
|
| 789 |
+
of dogs (successes) in a sample with exactly 12 animals that
|
| 790 |
+
aren't dogs (failures), we can initialize a frozen distribution
|
| 791 |
+
and plot the probability mass function:
|
| 792 |
+
|
| 793 |
+
>>> M, n, r = [20, 7, 12]
|
| 794 |
+
>>> rv = nhypergeom(M, n, r)
|
| 795 |
+
>>> x = np.arange(0, n+2)
|
| 796 |
+
>>> pmf_dogs = rv.pmf(x)
|
| 797 |
+
|
| 798 |
+
>>> fig = plt.figure()
|
| 799 |
+
>>> ax = fig.add_subplot(111)
|
| 800 |
+
>>> ax.plot(x, pmf_dogs, 'bo')
|
| 801 |
+
>>> ax.vlines(x, 0, pmf_dogs, lw=2)
|
| 802 |
+
>>> ax.set_xlabel('# of dogs in our group with given 12 failures')
|
| 803 |
+
>>> ax.set_ylabel('nhypergeom PMF')
|
| 804 |
+
>>> plt.show()
|
| 805 |
+
|
| 806 |
+
Instead of using a frozen distribution we can also use `nhypergeom`
|
| 807 |
+
methods directly. To for example obtain the probability mass
|
| 808 |
+
function, use:
|
| 809 |
+
|
| 810 |
+
>>> prb = nhypergeom.pmf(x, M, n, r)
|
| 811 |
+
|
| 812 |
+
And to generate random numbers:
|
| 813 |
+
|
| 814 |
+
>>> R = nhypergeom.rvs(M, n, r, size=10)
|
| 815 |
+
|
| 816 |
+
To verify the relationship between `hypergeom` and `nhypergeom`, use:
|
| 817 |
+
|
| 818 |
+
>>> from scipy.stats import hypergeom, nhypergeom
|
| 819 |
+
>>> M, n, r = 45, 13, 8
|
| 820 |
+
>>> k = 6
|
| 821 |
+
>>> nhypergeom.pmf(k, M, n, r)
|
| 822 |
+
0.06180776620271643
|
| 823 |
+
>>> hypergeom.pmf(k, M, n, k+r-1) * (M - n - (r-1)) / (M - (k+r-1))
|
| 824 |
+
0.06180776620271644
|
| 825 |
+
|
| 826 |
+
See Also
|
| 827 |
+
--------
|
| 828 |
+
hypergeom, binom, nbinom
|
| 829 |
+
|
| 830 |
+
References
|
| 831 |
+
----------
|
| 832 |
+
.. [1] Negative Hypergeometric Distribution on Wikipedia
|
| 833 |
+
https://en.wikipedia.org/wiki/Negative_hypergeometric_distribution
|
| 834 |
+
|
| 835 |
+
.. [2] Negative Hypergeometric Distribution from
|
| 836 |
+
http://www.math.wm.edu/~leemis/chart/UDR/PDFs/Negativehypergeometric.pdf
|
| 837 |
+
|
| 838 |
+
"""
|
| 839 |
+
|
| 840 |
+
def _shape_info(self):
|
| 841 |
+
return [_ShapeInfo("M", True, (0, np.inf), (True, False)),
|
| 842 |
+
_ShapeInfo("n", True, (0, np.inf), (True, False)),
|
| 843 |
+
_ShapeInfo("r", True, (0, np.inf), (True, False))]
|
| 844 |
+
|
| 845 |
+
def _get_support(self, M, n, r):
|
| 846 |
+
return 0, n
|
| 847 |
+
|
| 848 |
+
def _argcheck(self, M, n, r):
|
| 849 |
+
cond = (n >= 0) & (n <= M) & (r >= 0) & (r <= M-n)
|
| 850 |
+
cond &= _isintegral(M) & _isintegral(n) & _isintegral(r)
|
| 851 |
+
return cond
|
| 852 |
+
|
| 853 |
+
def _rvs(self, M, n, r, size=None, random_state=None):
|
| 854 |
+
|
| 855 |
+
@_vectorize_rvs_over_shapes
|
| 856 |
+
def _rvs1(M, n, r, size, random_state):
|
| 857 |
+
# invert cdf by calculating all values in support, scalar M, n, r
|
| 858 |
+
a, b = self.support(M, n, r)
|
| 859 |
+
ks = np.arange(a, b+1)
|
| 860 |
+
cdf = self.cdf(ks, M, n, r)
|
| 861 |
+
ppf = interp1d(cdf, ks, kind='next', fill_value='extrapolate')
|
| 862 |
+
rvs = ppf(random_state.uniform(size=size)).astype(int)
|
| 863 |
+
if size is None:
|
| 864 |
+
return rvs.item()
|
| 865 |
+
return rvs
|
| 866 |
+
|
| 867 |
+
return _rvs1(M, n, r, size=size, random_state=random_state)
|
| 868 |
+
|
| 869 |
+
def _logpmf(self, k, M, n, r):
|
| 870 |
+
cond = ((r == 0) & (k == 0))
|
| 871 |
+
result = _lazywhere(~cond, (k, M, n, r),
|
| 872 |
+
lambda k, M, n, r:
|
| 873 |
+
(-betaln(k+1, r) + betaln(k+r, 1) -
|
| 874 |
+
betaln(n-k+1, M-r-n+1) + betaln(M-r-k+1, 1) +
|
| 875 |
+
betaln(n+1, M-n+1) - betaln(M+1, 1)),
|
| 876 |
+
fillvalue=0.0)
|
| 877 |
+
return result
|
| 878 |
+
|
| 879 |
+
def _pmf(self, k, M, n, r):
|
| 880 |
+
# same as the following but numerically more precise
|
| 881 |
+
# return comb(k+r-1, k) * comb(M-r-k, n-k) / comb(M, n)
|
| 882 |
+
return exp(self._logpmf(k, M, n, r))
|
| 883 |
+
|
| 884 |
+
def _stats(self, M, n, r):
|
| 885 |
+
# Promote the datatype to at least float
|
| 886 |
+
# mu = rn / (M-n+1)
|
| 887 |
+
M, n, r = 1.*M, 1.*n, 1.*r
|
| 888 |
+
mu = r*n / (M-n+1)
|
| 889 |
+
|
| 890 |
+
var = r*(M+1)*n / ((M-n+1)*(M-n+2)) * (1 - r / (M-n+1))
|
| 891 |
+
|
| 892 |
+
# The skew and kurtosis are mathematically
|
| 893 |
+
# intractable so return `None`. See [2]_.
|
| 894 |
+
g1, g2 = None, None
|
| 895 |
+
return mu, var, g1, g2
|
| 896 |
+
|
| 897 |
+
|
| 898 |
+
nhypergeom = nhypergeom_gen(name='nhypergeom')
|
| 899 |
+
|
| 900 |
+
|
| 901 |
+
# FIXME: Fails _cdfvec
|
| 902 |
+
class logser_gen(rv_discrete):
|
| 903 |
+
r"""A Logarithmic (Log-Series, Series) discrete random variable.
|
| 904 |
+
|
| 905 |
+
%(before_notes)s
|
| 906 |
+
|
| 907 |
+
Notes
|
| 908 |
+
-----
|
| 909 |
+
The probability mass function for `logser` is:
|
| 910 |
+
|
| 911 |
+
.. math::
|
| 912 |
+
|
| 913 |
+
f(k) = - \frac{p^k}{k \log(1-p)}
|
| 914 |
+
|
| 915 |
+
for :math:`k \ge 1`, :math:`0 < p < 1`
|
| 916 |
+
|
| 917 |
+
`logser` takes :math:`p` as shape parameter,
|
| 918 |
+
where :math:`p` is the probability of a single success
|
| 919 |
+
and :math:`1-p` is the probability of a single failure.
|
| 920 |
+
|
| 921 |
+
%(after_notes)s
|
| 922 |
+
|
| 923 |
+
%(example)s
|
| 924 |
+
|
| 925 |
+
"""
|
| 926 |
+
|
| 927 |
+
def _shape_info(self):
|
| 928 |
+
return [_ShapeInfo("p", False, (0, 1), (True, True))]
|
| 929 |
+
|
| 930 |
+
def _rvs(self, p, size=None, random_state=None):
|
| 931 |
+
# looks wrong for p>0.5, too few k=1
|
| 932 |
+
# trying to use generic is worse, no k=1 at all
|
| 933 |
+
return random_state.logseries(p, size=size)
|
| 934 |
+
|
| 935 |
+
def _argcheck(self, p):
|
| 936 |
+
return (p > 0) & (p < 1)
|
| 937 |
+
|
| 938 |
+
def _pmf(self, k, p):
|
| 939 |
+
# logser.pmf(k) = - p**k / (k*log(1-p))
|
| 940 |
+
return -np.power(p, k) * 1.0 / k / special.log1p(-p)
|
| 941 |
+
|
| 942 |
+
def _stats(self, p):
|
| 943 |
+
r = special.log1p(-p)
|
| 944 |
+
mu = p / (p - 1.0) / r
|
| 945 |
+
mu2p = -p / r / (p - 1.0)**2
|
| 946 |
+
var = mu2p - mu*mu
|
| 947 |
+
mu3p = -p / r * (1.0+p) / (1.0 - p)**3
|
| 948 |
+
mu3 = mu3p - 3*mu*mu2p + 2*mu**3
|
| 949 |
+
g1 = mu3 / np.power(var, 1.5)
|
| 950 |
+
|
| 951 |
+
mu4p = -p / r * (
|
| 952 |
+
1.0 / (p-1)**2 - 6*p / (p - 1)**3 + 6*p*p / (p-1)**4)
|
| 953 |
+
mu4 = mu4p - 4*mu3p*mu + 6*mu2p*mu*mu - 3*mu**4
|
| 954 |
+
g2 = mu4 / var**2 - 3.0
|
| 955 |
+
return mu, var, g1, g2
|
| 956 |
+
|
| 957 |
+
|
| 958 |
+
logser = logser_gen(a=1, name='logser', longname='A logarithmic')
|
| 959 |
+
|
| 960 |
+
|
| 961 |
+
class poisson_gen(rv_discrete):
|
| 962 |
+
r"""A Poisson discrete random variable.
|
| 963 |
+
|
| 964 |
+
%(before_notes)s
|
| 965 |
+
|
| 966 |
+
Notes
|
| 967 |
+
-----
|
| 968 |
+
The probability mass function for `poisson` is:
|
| 969 |
+
|
| 970 |
+
.. math::
|
| 971 |
+
|
| 972 |
+
f(k) = \exp(-\mu) \frac{\mu^k}{k!}
|
| 973 |
+
|
| 974 |
+
for :math:`k \ge 0`.
|
| 975 |
+
|
| 976 |
+
`poisson` takes :math:`\mu \geq 0` as shape parameter.
|
| 977 |
+
When :math:`\mu = 0`, the ``pmf`` method
|
| 978 |
+
returns ``1.0`` at quantile :math:`k = 0`.
|
| 979 |
+
|
| 980 |
+
%(after_notes)s
|
| 981 |
+
|
| 982 |
+
%(example)s
|
| 983 |
+
|
| 984 |
+
"""
|
| 985 |
+
|
| 986 |
+
def _shape_info(self):
|
| 987 |
+
return [_ShapeInfo("mu", False, (0, np.inf), (True, False))]
|
| 988 |
+
|
| 989 |
+
# Override rv_discrete._argcheck to allow mu=0.
|
| 990 |
+
def _argcheck(self, mu):
|
| 991 |
+
return mu >= 0
|
| 992 |
+
|
| 993 |
+
def _rvs(self, mu, size=None, random_state=None):
|
| 994 |
+
return random_state.poisson(mu, size)
|
| 995 |
+
|
| 996 |
+
def _logpmf(self, k, mu):
|
| 997 |
+
Pk = special.xlogy(k, mu) - gamln(k + 1) - mu
|
| 998 |
+
return Pk
|
| 999 |
+
|
| 1000 |
+
def _pmf(self, k, mu):
|
| 1001 |
+
# poisson.pmf(k) = exp(-mu) * mu**k / k!
|
| 1002 |
+
return exp(self._logpmf(k, mu))
|
| 1003 |
+
|
| 1004 |
+
def _cdf(self, x, mu):
|
| 1005 |
+
k = floor(x)
|
| 1006 |
+
return special.pdtr(k, mu)
|
| 1007 |
+
|
| 1008 |
+
def _sf(self, x, mu):
|
| 1009 |
+
k = floor(x)
|
| 1010 |
+
return special.pdtrc(k, mu)
|
| 1011 |
+
|
| 1012 |
+
def _ppf(self, q, mu):
|
| 1013 |
+
vals = ceil(special.pdtrik(q, mu))
|
| 1014 |
+
vals1 = np.maximum(vals - 1, 0)
|
| 1015 |
+
temp = special.pdtr(vals1, mu)
|
| 1016 |
+
return np.where(temp >= q, vals1, vals)
|
| 1017 |
+
|
| 1018 |
+
def _stats(self, mu):
|
| 1019 |
+
var = mu
|
| 1020 |
+
tmp = np.asarray(mu)
|
| 1021 |
+
mu_nonzero = tmp > 0
|
| 1022 |
+
g1 = _lazywhere(mu_nonzero, (tmp,), lambda x: sqrt(1.0/x), np.inf)
|
| 1023 |
+
g2 = _lazywhere(mu_nonzero, (tmp,), lambda x: 1.0/x, np.inf)
|
| 1024 |
+
return mu, var, g1, g2
|
| 1025 |
+
|
| 1026 |
+
|
| 1027 |
+
poisson = poisson_gen(name="poisson", longname='A Poisson')
|
| 1028 |
+
|
| 1029 |
+
|
| 1030 |
+
class planck_gen(rv_discrete):
|
| 1031 |
+
r"""A Planck discrete exponential random variable.
|
| 1032 |
+
|
| 1033 |
+
%(before_notes)s
|
| 1034 |
+
|
| 1035 |
+
Notes
|
| 1036 |
+
-----
|
| 1037 |
+
The probability mass function for `planck` is:
|
| 1038 |
+
|
| 1039 |
+
.. math::
|
| 1040 |
+
|
| 1041 |
+
f(k) = (1-\exp(-\lambda)) \exp(-\lambda k)
|
| 1042 |
+
|
| 1043 |
+
for :math:`k \ge 0` and :math:`\lambda > 0`.
|
| 1044 |
+
|
| 1045 |
+
`planck` takes :math:`\lambda` as shape parameter. The Planck distribution
|
| 1046 |
+
can be written as a geometric distribution (`geom`) with
|
| 1047 |
+
:math:`p = 1 - \exp(-\lambda)` shifted by ``loc = -1``.
|
| 1048 |
+
|
| 1049 |
+
%(after_notes)s
|
| 1050 |
+
|
| 1051 |
+
See Also
|
| 1052 |
+
--------
|
| 1053 |
+
geom
|
| 1054 |
+
|
| 1055 |
+
%(example)s
|
| 1056 |
+
|
| 1057 |
+
"""
|
| 1058 |
+
def _shape_info(self):
|
| 1059 |
+
return [_ShapeInfo("lambda", False, (0, np.inf), (False, False))]
|
| 1060 |
+
|
| 1061 |
+
def _argcheck(self, lambda_):
|
| 1062 |
+
return lambda_ > 0
|
| 1063 |
+
|
| 1064 |
+
def _pmf(self, k, lambda_):
|
| 1065 |
+
return -expm1(-lambda_)*exp(-lambda_*k)
|
| 1066 |
+
|
| 1067 |
+
def _cdf(self, x, lambda_):
|
| 1068 |
+
k = floor(x)
|
| 1069 |
+
return -expm1(-lambda_*(k+1))
|
| 1070 |
+
|
| 1071 |
+
def _sf(self, x, lambda_):
|
| 1072 |
+
return exp(self._logsf(x, lambda_))
|
| 1073 |
+
|
| 1074 |
+
def _logsf(self, x, lambda_):
|
| 1075 |
+
k = floor(x)
|
| 1076 |
+
return -lambda_*(k+1)
|
| 1077 |
+
|
| 1078 |
+
def _ppf(self, q, lambda_):
|
| 1079 |
+
vals = ceil(-1.0/lambda_ * log1p(-q)-1)
|
| 1080 |
+
vals1 = (vals-1).clip(*(self._get_support(lambda_)))
|
| 1081 |
+
temp = self._cdf(vals1, lambda_)
|
| 1082 |
+
return np.where(temp >= q, vals1, vals)
|
| 1083 |
+
|
| 1084 |
+
def _rvs(self, lambda_, size=None, random_state=None):
|
| 1085 |
+
# use relation to geometric distribution for sampling
|
| 1086 |
+
p = -expm1(-lambda_)
|
| 1087 |
+
return random_state.geometric(p, size=size) - 1.0
|
| 1088 |
+
|
| 1089 |
+
def _stats(self, lambda_):
|
| 1090 |
+
mu = 1/expm1(lambda_)
|
| 1091 |
+
var = exp(-lambda_)/(expm1(-lambda_))**2
|
| 1092 |
+
g1 = 2*cosh(lambda_/2.0)
|
| 1093 |
+
g2 = 4+2*cosh(lambda_)
|
| 1094 |
+
return mu, var, g1, g2
|
| 1095 |
+
|
| 1096 |
+
def _entropy(self, lambda_):
|
| 1097 |
+
C = -expm1(-lambda_)
|
| 1098 |
+
return lambda_*exp(-lambda_)/C - log(C)
|
| 1099 |
+
|
| 1100 |
+
|
| 1101 |
+
planck = planck_gen(a=0, name='planck', longname='A discrete exponential ')
|
| 1102 |
+
|
| 1103 |
+
|
| 1104 |
+
class boltzmann_gen(rv_discrete):
|
| 1105 |
+
r"""A Boltzmann (Truncated Discrete Exponential) random variable.
|
| 1106 |
+
|
| 1107 |
+
%(before_notes)s
|
| 1108 |
+
|
| 1109 |
+
Notes
|
| 1110 |
+
-----
|
| 1111 |
+
The probability mass function for `boltzmann` is:
|
| 1112 |
+
|
| 1113 |
+
.. math::
|
| 1114 |
+
|
| 1115 |
+
f(k) = (1-\exp(-\lambda)) \exp(-\lambda k) / (1-\exp(-\lambda N))
|
| 1116 |
+
|
| 1117 |
+
for :math:`k = 0,..., N-1`.
|
| 1118 |
+
|
| 1119 |
+
`boltzmann` takes :math:`\lambda > 0` and :math:`N > 0` as shape parameters.
|
| 1120 |
+
|
| 1121 |
+
%(after_notes)s
|
| 1122 |
+
|
| 1123 |
+
%(example)s
|
| 1124 |
+
|
| 1125 |
+
"""
|
| 1126 |
+
def _shape_info(self):
|
| 1127 |
+
return [_ShapeInfo("lambda_", False, (0, np.inf), (False, False)),
|
| 1128 |
+
_ShapeInfo("N", True, (0, np.inf), (False, False))]
|
| 1129 |
+
|
| 1130 |
+
def _argcheck(self, lambda_, N):
|
| 1131 |
+
return (lambda_ > 0) & (N > 0) & _isintegral(N)
|
| 1132 |
+
|
| 1133 |
+
def _get_support(self, lambda_, N):
|
| 1134 |
+
return self.a, N - 1
|
| 1135 |
+
|
| 1136 |
+
def _pmf(self, k, lambda_, N):
|
| 1137 |
+
# boltzmann.pmf(k) =
|
| 1138 |
+
# (1-exp(-lambda_)*exp(-lambda_*k)/(1-exp(-lambda_*N))
|
| 1139 |
+
fact = (1-exp(-lambda_))/(1-exp(-lambda_*N))
|
| 1140 |
+
return fact*exp(-lambda_*k)
|
| 1141 |
+
|
| 1142 |
+
def _cdf(self, x, lambda_, N):
|
| 1143 |
+
k = floor(x)
|
| 1144 |
+
return (1-exp(-lambda_*(k+1)))/(1-exp(-lambda_*N))
|
| 1145 |
+
|
| 1146 |
+
def _ppf(self, q, lambda_, N):
|
| 1147 |
+
qnew = q*(1-exp(-lambda_*N))
|
| 1148 |
+
vals = ceil(-1.0/lambda_ * log(1-qnew)-1)
|
| 1149 |
+
vals1 = (vals-1).clip(0.0, np.inf)
|
| 1150 |
+
temp = self._cdf(vals1, lambda_, N)
|
| 1151 |
+
return np.where(temp >= q, vals1, vals)
|
| 1152 |
+
|
| 1153 |
+
def _stats(self, lambda_, N):
|
| 1154 |
+
z = exp(-lambda_)
|
| 1155 |
+
zN = exp(-lambda_*N)
|
| 1156 |
+
mu = z/(1.0-z)-N*zN/(1-zN)
|
| 1157 |
+
var = z/(1.0-z)**2 - N*N*zN/(1-zN)**2
|
| 1158 |
+
trm = (1-zN)/(1-z)
|
| 1159 |
+
trm2 = (z*trm**2 - N*N*zN)
|
| 1160 |
+
g1 = z*(1+z)*trm**3 - N**3*zN*(1+zN)
|
| 1161 |
+
g1 = g1 / trm2**(1.5)
|
| 1162 |
+
g2 = z*(1+4*z+z*z)*trm**4 - N**4 * zN*(1+4*zN+zN*zN)
|
| 1163 |
+
g2 = g2 / trm2 / trm2
|
| 1164 |
+
return mu, var, g1, g2
|
| 1165 |
+
|
| 1166 |
+
|
| 1167 |
+
boltzmann = boltzmann_gen(name='boltzmann', a=0,
|
| 1168 |
+
longname='A truncated discrete exponential ')
|
| 1169 |
+
|
| 1170 |
+
|
| 1171 |
+
class randint_gen(rv_discrete):
|
| 1172 |
+
r"""A uniform discrete random variable.
|
| 1173 |
+
|
| 1174 |
+
%(before_notes)s
|
| 1175 |
+
|
| 1176 |
+
Notes
|
| 1177 |
+
-----
|
| 1178 |
+
The probability mass function for `randint` is:
|
| 1179 |
+
|
| 1180 |
+
.. math::
|
| 1181 |
+
|
| 1182 |
+
f(k) = \frac{1}{\texttt{high} - \texttt{low}}
|
| 1183 |
+
|
| 1184 |
+
for :math:`k \in \{\texttt{low}, \dots, \texttt{high} - 1\}`.
|
| 1185 |
+
|
| 1186 |
+
`randint` takes :math:`\texttt{low}` and :math:`\texttt{high}` as shape
|
| 1187 |
+
parameters.
|
| 1188 |
+
|
| 1189 |
+
%(after_notes)s
|
| 1190 |
+
|
| 1191 |
+
Examples
|
| 1192 |
+
--------
|
| 1193 |
+
>>> import numpy as np
|
| 1194 |
+
>>> from scipy.stats import randint
|
| 1195 |
+
>>> import matplotlib.pyplot as plt
|
| 1196 |
+
>>> fig, ax = plt.subplots(1, 1)
|
| 1197 |
+
|
| 1198 |
+
Calculate the first four moments:
|
| 1199 |
+
|
| 1200 |
+
>>> low, high = 7, 31
|
| 1201 |
+
>>> mean, var, skew, kurt = randint.stats(low, high, moments='mvsk')
|
| 1202 |
+
|
| 1203 |
+
Display the probability mass function (``pmf``):
|
| 1204 |
+
|
| 1205 |
+
>>> x = np.arange(low - 5, high + 5)
|
| 1206 |
+
>>> ax.plot(x, randint.pmf(x, low, high), 'bo', ms=8, label='randint pmf')
|
| 1207 |
+
>>> ax.vlines(x, 0, randint.pmf(x, low, high), colors='b', lw=5, alpha=0.5)
|
| 1208 |
+
|
| 1209 |
+
Alternatively, the distribution object can be called (as a function) to
|
| 1210 |
+
fix the shape and location. This returns a "frozen" RV object holding the
|
| 1211 |
+
given parameters fixed.
|
| 1212 |
+
|
| 1213 |
+
Freeze the distribution and display the frozen ``pmf``:
|
| 1214 |
+
|
| 1215 |
+
>>> rv = randint(low, high)
|
| 1216 |
+
>>> ax.vlines(x, 0, rv.pmf(x), colors='k', linestyles='-',
|
| 1217 |
+
... lw=1, label='frozen pmf')
|
| 1218 |
+
>>> ax.legend(loc='lower center')
|
| 1219 |
+
>>> plt.show()
|
| 1220 |
+
|
| 1221 |
+
Check the relationship between the cumulative distribution function
|
| 1222 |
+
(``cdf``) and its inverse, the percent point function (``ppf``):
|
| 1223 |
+
|
| 1224 |
+
>>> q = np.arange(low, high)
|
| 1225 |
+
>>> p = randint.cdf(q, low, high)
|
| 1226 |
+
>>> np.allclose(q, randint.ppf(p, low, high))
|
| 1227 |
+
True
|
| 1228 |
+
|
| 1229 |
+
Generate random numbers:
|
| 1230 |
+
|
| 1231 |
+
>>> r = randint.rvs(low, high, size=1000)
|
| 1232 |
+
|
| 1233 |
+
"""
|
| 1234 |
+
|
| 1235 |
+
def _shape_info(self):
|
| 1236 |
+
return [_ShapeInfo("low", True, (-np.inf, np.inf), (False, False)),
|
| 1237 |
+
_ShapeInfo("high", True, (-np.inf, np.inf), (False, False))]
|
| 1238 |
+
|
| 1239 |
+
def _argcheck(self, low, high):
|
| 1240 |
+
return (high > low) & _isintegral(low) & _isintegral(high)
|
| 1241 |
+
|
| 1242 |
+
def _get_support(self, low, high):
|
| 1243 |
+
return low, high-1
|
| 1244 |
+
|
| 1245 |
+
def _pmf(self, k, low, high):
|
| 1246 |
+
# randint.pmf(k) = 1./(high - low)
|
| 1247 |
+
p = np.ones_like(k) / (np.asarray(high, dtype=np.int64) - low)
|
| 1248 |
+
return np.where((k >= low) & (k < high), p, 0.)
|
| 1249 |
+
|
| 1250 |
+
def _cdf(self, x, low, high):
|
| 1251 |
+
k = floor(x)
|
| 1252 |
+
return (k - low + 1.) / (high - low)
|
| 1253 |
+
|
| 1254 |
+
def _ppf(self, q, low, high):
|
| 1255 |
+
vals = ceil(q * (high - low) + low) - 1
|
| 1256 |
+
vals1 = (vals - 1).clip(low, high)
|
| 1257 |
+
temp = self._cdf(vals1, low, high)
|
| 1258 |
+
return np.where(temp >= q, vals1, vals)
|
| 1259 |
+
|
| 1260 |
+
def _stats(self, low, high):
|
| 1261 |
+
m2, m1 = np.asarray(high), np.asarray(low)
|
| 1262 |
+
mu = (m2 + m1 - 1.0) / 2
|
| 1263 |
+
d = m2 - m1
|
| 1264 |
+
var = (d*d - 1) / 12.0
|
| 1265 |
+
g1 = 0.0
|
| 1266 |
+
g2 = -6.0/5.0 * (d*d + 1.0) / (d*d - 1.0)
|
| 1267 |
+
return mu, var, g1, g2
|
| 1268 |
+
|
| 1269 |
+
def _rvs(self, low, high, size=None, random_state=None):
|
| 1270 |
+
"""An array of *size* random integers >= ``low`` and < ``high``."""
|
| 1271 |
+
if np.asarray(low).size == 1 and np.asarray(high).size == 1:
|
| 1272 |
+
# no need to vectorize in that case
|
| 1273 |
+
return rng_integers(random_state, low, high, size=size)
|
| 1274 |
+
|
| 1275 |
+
if size is not None:
|
| 1276 |
+
# NumPy's RandomState.randint() doesn't broadcast its arguments.
|
| 1277 |
+
# Use `broadcast_to()` to extend the shapes of low and high
|
| 1278 |
+
# up to size. Then we can use the numpy.vectorize'd
|
| 1279 |
+
# randint without needing to pass it a `size` argument.
|
| 1280 |
+
low = np.broadcast_to(low, size)
|
| 1281 |
+
high = np.broadcast_to(high, size)
|
| 1282 |
+
randint = np.vectorize(partial(rng_integers, random_state),
|
| 1283 |
+
otypes=[np.dtype(int)])
|
| 1284 |
+
return randint(low, high)
|
| 1285 |
+
|
| 1286 |
+
def _entropy(self, low, high):
|
| 1287 |
+
return log(high - low)
|
| 1288 |
+
|
| 1289 |
+
|
| 1290 |
+
randint = randint_gen(name='randint', longname='A discrete uniform '
|
| 1291 |
+
'(random integer)')
|
| 1292 |
+
|
| 1293 |
+
|
| 1294 |
+
# FIXME: problems sampling.
|
| 1295 |
+
class zipf_gen(rv_discrete):
|
| 1296 |
+
r"""A Zipf (Zeta) discrete random variable.
|
| 1297 |
+
|
| 1298 |
+
%(before_notes)s
|
| 1299 |
+
|
| 1300 |
+
See Also
|
| 1301 |
+
--------
|
| 1302 |
+
zipfian
|
| 1303 |
+
|
| 1304 |
+
Notes
|
| 1305 |
+
-----
|
| 1306 |
+
The probability mass function for `zipf` is:
|
| 1307 |
+
|
| 1308 |
+
.. math::
|
| 1309 |
+
|
| 1310 |
+
f(k, a) = \frac{1}{\zeta(a) k^a}
|
| 1311 |
+
|
| 1312 |
+
for :math:`k \ge 1`, :math:`a > 1`.
|
| 1313 |
+
|
| 1314 |
+
`zipf` takes :math:`a > 1` as shape parameter. :math:`\zeta` is the
|
| 1315 |
+
Riemann zeta function (`scipy.special.zeta`)
|
| 1316 |
+
|
| 1317 |
+
The Zipf distribution is also known as the zeta distribution, which is
|
| 1318 |
+
a special case of the Zipfian distribution (`zipfian`).
|
| 1319 |
+
|
| 1320 |
+
%(after_notes)s
|
| 1321 |
+
|
| 1322 |
+
References
|
| 1323 |
+
----------
|
| 1324 |
+
.. [1] "Zeta Distribution", Wikipedia,
|
| 1325 |
+
https://en.wikipedia.org/wiki/Zeta_distribution
|
| 1326 |
+
|
| 1327 |
+
%(example)s
|
| 1328 |
+
|
| 1329 |
+
Confirm that `zipf` is the large `n` limit of `zipfian`.
|
| 1330 |
+
|
| 1331 |
+
>>> import numpy as np
|
| 1332 |
+
>>> from scipy.stats import zipf, zipfian
|
| 1333 |
+
>>> k = np.arange(11)
|
| 1334 |
+
>>> np.allclose(zipf.pmf(k, a), zipfian.pmf(k, a, n=10000000))
|
| 1335 |
+
True
|
| 1336 |
+
|
| 1337 |
+
"""
|
| 1338 |
+
|
| 1339 |
+
def _shape_info(self):
|
| 1340 |
+
return [_ShapeInfo("a", False, (1, np.inf), (False, False))]
|
| 1341 |
+
|
| 1342 |
+
def _rvs(self, a, size=None, random_state=None):
|
| 1343 |
+
return random_state.zipf(a, size=size)
|
| 1344 |
+
|
| 1345 |
+
def _argcheck(self, a):
|
| 1346 |
+
return a > 1
|
| 1347 |
+
|
| 1348 |
+
def _pmf(self, k, a):
|
| 1349 |
+
k = k.astype(np.float64)
|
| 1350 |
+
# zipf.pmf(k, a) = 1/(zeta(a) * k**a)
|
| 1351 |
+
Pk = 1.0 / special.zeta(a, 1) * k**-a
|
| 1352 |
+
return Pk
|
| 1353 |
+
|
| 1354 |
+
def _munp(self, n, a):
|
| 1355 |
+
return _lazywhere(
|
| 1356 |
+
a > n + 1, (a, n),
|
| 1357 |
+
lambda a, n: special.zeta(a - n, 1) / special.zeta(a, 1),
|
| 1358 |
+
np.inf)
|
| 1359 |
+
|
| 1360 |
+
|
| 1361 |
+
zipf = zipf_gen(a=1, name='zipf', longname='A Zipf')
|
| 1362 |
+
|
| 1363 |
+
|
| 1364 |
+
def _gen_harmonic_gt1(n, a):
|
| 1365 |
+
"""Generalized harmonic number, a > 1"""
|
| 1366 |
+
# See https://en.wikipedia.org/wiki/Harmonic_number; search for "hurwitz"
|
| 1367 |
+
return zeta(a, 1) - zeta(a, n+1)
|
| 1368 |
+
|
| 1369 |
+
|
| 1370 |
+
def _gen_harmonic_leq1(n, a):
|
| 1371 |
+
"""Generalized harmonic number, a <= 1"""
|
| 1372 |
+
if not np.size(n):
|
| 1373 |
+
return n
|
| 1374 |
+
n_max = np.max(n) # loop starts at maximum of all n
|
| 1375 |
+
out = np.zeros_like(a, dtype=float)
|
| 1376 |
+
# add terms of harmonic series; starting from smallest to avoid roundoff
|
| 1377 |
+
for i in np.arange(n_max, 0, -1, dtype=float):
|
| 1378 |
+
mask = i <= n # don't add terms after nth
|
| 1379 |
+
out[mask] += 1/i**a[mask]
|
| 1380 |
+
return out
|
| 1381 |
+
|
| 1382 |
+
|
| 1383 |
+
def _gen_harmonic(n, a):
|
| 1384 |
+
"""Generalized harmonic number"""
|
| 1385 |
+
n, a = np.broadcast_arrays(n, a)
|
| 1386 |
+
return _lazywhere(a > 1, (n, a),
|
| 1387 |
+
f=_gen_harmonic_gt1, f2=_gen_harmonic_leq1)
|
| 1388 |
+
|
| 1389 |
+
|
| 1390 |
+
class zipfian_gen(rv_discrete):
|
| 1391 |
+
r"""A Zipfian discrete random variable.
|
| 1392 |
+
|
| 1393 |
+
%(before_notes)s
|
| 1394 |
+
|
| 1395 |
+
See Also
|
| 1396 |
+
--------
|
| 1397 |
+
zipf
|
| 1398 |
+
|
| 1399 |
+
Notes
|
| 1400 |
+
-----
|
| 1401 |
+
The probability mass function for `zipfian` is:
|
| 1402 |
+
|
| 1403 |
+
.. math::
|
| 1404 |
+
|
| 1405 |
+
f(k, a, n) = \frac{1}{H_{n,a} k^a}
|
| 1406 |
+
|
| 1407 |
+
for :math:`k \in \{1, 2, \dots, n-1, n\}`, :math:`a \ge 0`,
|
| 1408 |
+
:math:`n \in \{1, 2, 3, \dots\}`.
|
| 1409 |
+
|
| 1410 |
+
`zipfian` takes :math:`a` and :math:`n` as shape parameters.
|
| 1411 |
+
:math:`H_{n,a}` is the :math:`n`:sup:`th` generalized harmonic
|
| 1412 |
+
number of order :math:`a`.
|
| 1413 |
+
|
| 1414 |
+
The Zipfian distribution reduces to the Zipf (zeta) distribution as
|
| 1415 |
+
:math:`n \rightarrow \infty`.
|
| 1416 |
+
|
| 1417 |
+
%(after_notes)s
|
| 1418 |
+
|
| 1419 |
+
References
|
| 1420 |
+
----------
|
| 1421 |
+
.. [1] "Zipf's Law", Wikipedia, https://en.wikipedia.org/wiki/Zipf's_law
|
| 1422 |
+
.. [2] Larry Leemis, "Zipf Distribution", Univariate Distribution
|
| 1423 |
+
Relationships. http://www.math.wm.edu/~leemis/chart/UDR/PDFs/Zipf.pdf
|
| 1424 |
+
|
| 1425 |
+
%(example)s
|
| 1426 |
+
|
| 1427 |
+
Confirm that `zipfian` reduces to `zipf` for large `n`, ``a > 1``.
|
| 1428 |
+
|
| 1429 |
+
>>> import numpy as np
|
| 1430 |
+
>>> from scipy.stats import zipf, zipfian
|
| 1431 |
+
>>> k = np.arange(11)
|
| 1432 |
+
>>> np.allclose(zipfian.pmf(k, a=3.5, n=10000000), zipf.pmf(k, a=3.5))
|
| 1433 |
+
True
|
| 1434 |
+
|
| 1435 |
+
"""
|
| 1436 |
+
|
| 1437 |
+
def _shape_info(self):
|
| 1438 |
+
return [_ShapeInfo("a", False, (0, np.inf), (True, False)),
|
| 1439 |
+
_ShapeInfo("n", True, (0, np.inf), (False, False))]
|
| 1440 |
+
|
| 1441 |
+
def _argcheck(self, a, n):
|
| 1442 |
+
# we need np.asarray here because moment (maybe others) don't convert
|
| 1443 |
+
return (a >= 0) & (n > 0) & (n == np.asarray(n, dtype=int))
|
| 1444 |
+
|
| 1445 |
+
def _get_support(self, a, n):
|
| 1446 |
+
return 1, n
|
| 1447 |
+
|
| 1448 |
+
def _pmf(self, k, a, n):
|
| 1449 |
+
k = k.astype(np.float64)
|
| 1450 |
+
return 1.0 / _gen_harmonic(n, a) * k**-a
|
| 1451 |
+
|
| 1452 |
+
def _cdf(self, k, a, n):
|
| 1453 |
+
return _gen_harmonic(k, a) / _gen_harmonic(n, a)
|
| 1454 |
+
|
| 1455 |
+
def _sf(self, k, a, n):
|
| 1456 |
+
k = k + 1 # # to match SciPy convention
|
| 1457 |
+
# see http://www.math.wm.edu/~leemis/chart/UDR/PDFs/Zipf.pdf
|
| 1458 |
+
return ((k**a*(_gen_harmonic(n, a) - _gen_harmonic(k, a)) + 1)
|
| 1459 |
+
/ (k**a*_gen_harmonic(n, a)))
|
| 1460 |
+
|
| 1461 |
+
def _stats(self, a, n):
|
| 1462 |
+
# see # see http://www.math.wm.edu/~leemis/chart/UDR/PDFs/Zipf.pdf
|
| 1463 |
+
Hna = _gen_harmonic(n, a)
|
| 1464 |
+
Hna1 = _gen_harmonic(n, a-1)
|
| 1465 |
+
Hna2 = _gen_harmonic(n, a-2)
|
| 1466 |
+
Hna3 = _gen_harmonic(n, a-3)
|
| 1467 |
+
Hna4 = _gen_harmonic(n, a-4)
|
| 1468 |
+
mu1 = Hna1/Hna
|
| 1469 |
+
mu2n = (Hna2*Hna - Hna1**2)
|
| 1470 |
+
mu2d = Hna**2
|
| 1471 |
+
mu2 = mu2n / mu2d
|
| 1472 |
+
g1 = (Hna3/Hna - 3*Hna1*Hna2/Hna**2 + 2*Hna1**3/Hna**3)/mu2**(3/2)
|
| 1473 |
+
g2 = (Hna**3*Hna4 - 4*Hna**2*Hna1*Hna3 + 6*Hna*Hna1**2*Hna2
|
| 1474 |
+
- 3*Hna1**4) / mu2n**2
|
| 1475 |
+
g2 -= 3
|
| 1476 |
+
return mu1, mu2, g1, g2
|
| 1477 |
+
|
| 1478 |
+
|
| 1479 |
+
zipfian = zipfian_gen(a=1, name='zipfian', longname='A Zipfian')
|
| 1480 |
+
|
| 1481 |
+
|
| 1482 |
+
class dlaplace_gen(rv_discrete):
|
| 1483 |
+
r"""A Laplacian discrete random variable.
|
| 1484 |
+
|
| 1485 |
+
%(before_notes)s
|
| 1486 |
+
|
| 1487 |
+
Notes
|
| 1488 |
+
-----
|
| 1489 |
+
The probability mass function for `dlaplace` is:
|
| 1490 |
+
|
| 1491 |
+
.. math::
|
| 1492 |
+
|
| 1493 |
+
f(k) = \tanh(a/2) \exp(-a |k|)
|
| 1494 |
+
|
| 1495 |
+
for integers :math:`k` and :math:`a > 0`.
|
| 1496 |
+
|
| 1497 |
+
`dlaplace` takes :math:`a` as shape parameter.
|
| 1498 |
+
|
| 1499 |
+
%(after_notes)s
|
| 1500 |
+
|
| 1501 |
+
%(example)s
|
| 1502 |
+
|
| 1503 |
+
"""
|
| 1504 |
+
|
| 1505 |
+
def _shape_info(self):
|
| 1506 |
+
return [_ShapeInfo("a", False, (0, np.inf), (False, False))]
|
| 1507 |
+
|
| 1508 |
+
def _pmf(self, k, a):
|
| 1509 |
+
# dlaplace.pmf(k) = tanh(a/2) * exp(-a*abs(k))
|
| 1510 |
+
return tanh(a/2.0) * exp(-a * abs(k))
|
| 1511 |
+
|
| 1512 |
+
def _cdf(self, x, a):
|
| 1513 |
+
k = floor(x)
|
| 1514 |
+
|
| 1515 |
+
def f(k, a):
|
| 1516 |
+
return 1.0 - exp(-a * k) / (exp(a) + 1)
|
| 1517 |
+
|
| 1518 |
+
def f2(k, a):
|
| 1519 |
+
return exp(a * (k + 1)) / (exp(a) + 1)
|
| 1520 |
+
|
| 1521 |
+
return _lazywhere(k >= 0, (k, a), f=f, f2=f2)
|
| 1522 |
+
|
| 1523 |
+
def _ppf(self, q, a):
|
| 1524 |
+
const = 1 + exp(a)
|
| 1525 |
+
vals = ceil(np.where(q < 1.0 / (1 + exp(-a)),
|
| 1526 |
+
log(q*const) / a - 1,
|
| 1527 |
+
-log((1-q) * const) / a))
|
| 1528 |
+
vals1 = vals - 1
|
| 1529 |
+
return np.where(self._cdf(vals1, a) >= q, vals1, vals)
|
| 1530 |
+
|
| 1531 |
+
def _stats(self, a):
|
| 1532 |
+
ea = exp(a)
|
| 1533 |
+
mu2 = 2.*ea/(ea-1.)**2
|
| 1534 |
+
mu4 = 2.*ea*(ea**2+10.*ea+1.) / (ea-1.)**4
|
| 1535 |
+
return 0., mu2, 0., mu4/mu2**2 - 3.
|
| 1536 |
+
|
| 1537 |
+
def _entropy(self, a):
|
| 1538 |
+
return a / sinh(a) - log(tanh(a/2.0))
|
| 1539 |
+
|
| 1540 |
+
def _rvs(self, a, size=None, random_state=None):
|
| 1541 |
+
# The discrete Laplace is equivalent to the two-sided geometric
|
| 1542 |
+
# distribution with PMF:
|
| 1543 |
+
# f(k) = (1 - alpha)/(1 + alpha) * alpha^abs(k)
|
| 1544 |
+
# Reference:
|
| 1545 |
+
# https://www.sciencedirect.com/science/
|
| 1546 |
+
# article/abs/pii/S0378375804003519
|
| 1547 |
+
# Furthermore, the two-sided geometric distribution is
|
| 1548 |
+
# equivalent to the difference between two iid geometric
|
| 1549 |
+
# distributions.
|
| 1550 |
+
# Reference (page 179):
|
| 1551 |
+
# https://pdfs.semanticscholar.org/61b3/
|
| 1552 |
+
# b99f466815808fd0d03f5d2791eea8b541a1.pdf
|
| 1553 |
+
# Thus, we can leverage the following:
|
| 1554 |
+
# 1) alpha = e^-a
|
| 1555 |
+
# 2) probability_of_success = 1 - alpha (Bernoulli trial)
|
| 1556 |
+
probOfSuccess = -np.expm1(-np.asarray(a))
|
| 1557 |
+
x = random_state.geometric(probOfSuccess, size=size)
|
| 1558 |
+
y = random_state.geometric(probOfSuccess, size=size)
|
| 1559 |
+
return x - y
|
| 1560 |
+
|
| 1561 |
+
|
| 1562 |
+
dlaplace = dlaplace_gen(a=-np.inf,
|
| 1563 |
+
name='dlaplace', longname='A discrete Laplacian')
|
| 1564 |
+
|
| 1565 |
+
|
| 1566 |
+
class poisson_binom_gen(rv_discrete):
|
| 1567 |
+
r"""A Poisson Binomial discrete random variable.
|
| 1568 |
+
|
| 1569 |
+
%(before_notes)s
|
| 1570 |
+
|
| 1571 |
+
See Also
|
| 1572 |
+
--------
|
| 1573 |
+
binom
|
| 1574 |
+
|
| 1575 |
+
Notes
|
| 1576 |
+
-----
|
| 1577 |
+
The probability mass function for `poisson_binom` is:
|
| 1578 |
+
|
| 1579 |
+
.. math::
|
| 1580 |
+
|
| 1581 |
+
f(k; p_1, p_2, ..., p_n) = \sum_{A \in F_k} \prod_{i \in A} p_i \prod_{j \in A^C} 1 - p_j
|
| 1582 |
+
|
| 1583 |
+
where :math:`k \in \{0, 1, \dots, n-1, n\}`, :math:`F_k` is the set of all
|
| 1584 |
+
subsets of :math:`k` integers that can be selected :math:`\{0, 1, \dots, n-1, n\}`,
|
| 1585 |
+
and :math:`A^C` is the complement of a set :math:`A`.
|
| 1586 |
+
|
| 1587 |
+
`poisson_binom` accepts a single array argument ``p`` for shape parameters
|
| 1588 |
+
:math:`0 ≤ p_i ≤ 1`, where the last axis corresponds with the index :math:`i` and
|
| 1589 |
+
any others are for batch dimensions. Broadcasting behaves according to the usual
|
| 1590 |
+
rules except that the last axis of ``p`` is ignored. Instances of this class do
|
| 1591 |
+
not support serialization/unserialization.
|
| 1592 |
+
|
| 1593 |
+
%(after_notes)s
|
| 1594 |
+
|
| 1595 |
+
References
|
| 1596 |
+
----------
|
| 1597 |
+
.. [1] "Poisson binomial distribution", Wikipedia,
|
| 1598 |
+
https://en.wikipedia.org/wiki/Poisson_binomial_distribution
|
| 1599 |
+
.. [2] Biscarri, William, Sihai Dave Zhao, and Robert J. Brunner. "A simple and
|
| 1600 |
+
fast method for computing the Poisson binomial distribution function".
|
| 1601 |
+
Computational Statistics & Data Analysis 122 (2018) 92-100.
|
| 1602 |
+
:doi:`10.1016/j.csda.2018.01.007`
|
| 1603 |
+
|
| 1604 |
+
%(example)s
|
| 1605 |
+
|
| 1606 |
+
""" # noqa: E501
|
| 1607 |
+
def _shape_info(self):
|
| 1608 |
+
# message = 'Fitting is not implemented for this distribution."
|
| 1609 |
+
# raise NotImplementedError(message)
|
| 1610 |
+
return []
|
| 1611 |
+
|
| 1612 |
+
def _argcheck(self, *args):
|
| 1613 |
+
p = np.stack(args, axis=0)
|
| 1614 |
+
conds = (0 <= p) & (p <= 1)
|
| 1615 |
+
return np.all(conds, axis=0)
|
| 1616 |
+
|
| 1617 |
+
def _rvs(self, *args, size=None, random_state=None):
|
| 1618 |
+
# convenient to work along the last axis here to avoid interference with `size`
|
| 1619 |
+
p = np.stack(args, axis=-1)
|
| 1620 |
+
# Size passed by the user is the *shape of the returned array*, so it won't
|
| 1621 |
+
# contain the length of the last axis of p.
|
| 1622 |
+
size = (p.shape if size is None else
|
| 1623 |
+
(size, 1) if np.isscalar(size) else tuple(size) + (1,))
|
| 1624 |
+
size = np.broadcast_shapes(p.shape, size)
|
| 1625 |
+
return bernoulli._rvs(p, size=size, random_state=random_state).sum(axis=-1)
|
| 1626 |
+
|
| 1627 |
+
def _get_support(self, *args):
|
| 1628 |
+
return 0, len(args)
|
| 1629 |
+
|
| 1630 |
+
def _pmf(self, k, *args):
|
| 1631 |
+
k = np.atleast_1d(k).astype(np.int64)
|
| 1632 |
+
k, *args = np.broadcast_arrays(k, *args)
|
| 1633 |
+
args = np.asarray(args, dtype=np.float64)
|
| 1634 |
+
return _poisson_binom(k, args, 'pmf')
|
| 1635 |
+
|
| 1636 |
+
def _cdf(self, k, *args):
|
| 1637 |
+
k = np.atleast_1d(k).astype(np.int64)
|
| 1638 |
+
k, *args = np.broadcast_arrays(k, *args)
|
| 1639 |
+
args = np.asarray(args, dtype=np.float64)
|
| 1640 |
+
return _poisson_binom(k, args, 'cdf')
|
| 1641 |
+
|
| 1642 |
+
def _stats(self, *args, **kwds):
|
| 1643 |
+
p = np.stack(args, axis=0)
|
| 1644 |
+
mean = np.sum(p, axis=0)
|
| 1645 |
+
var = np.sum(p * (1-p), axis=0)
|
| 1646 |
+
return (mean, var, None, None)
|
| 1647 |
+
|
| 1648 |
+
def __call__(self, *args, **kwds):
|
| 1649 |
+
return poisson_binomial_frozen(self, *args, **kwds)
|
| 1650 |
+
|
| 1651 |
+
|
| 1652 |
+
poisson_binom = poisson_binom_gen(name='poisson_binom', longname='A Poisson binomial',
|
| 1653 |
+
shapes='p')
|
| 1654 |
+
|
| 1655 |
+
# The _parse_args methods don't work with vector-valued shape parameters, so we rewrite
|
| 1656 |
+
# them. Note that `p` is accepted as an array with the index `i` of `p_i` corresponding
|
| 1657 |
+
# with the last axis; we return it as a tuple (p_1, p_2, ..., p_n) so that it looks
|
| 1658 |
+
# like `n` scalar (or arrays of scalar-valued) shape parameters to the infrastructure.
|
| 1659 |
+
|
| 1660 |
+
def _parse_args_rvs(self, p, loc=0, size=None):
|
| 1661 |
+
return tuple(np.moveaxis(p, -1, 0)), loc, 1.0, size
|
| 1662 |
+
|
| 1663 |
+
def _parse_args_stats(self, p, loc=0, moments='mv'):
|
| 1664 |
+
return tuple(np.moveaxis(p, -1, 0)), loc, 1.0, moments
|
| 1665 |
+
|
| 1666 |
+
def _parse_args(self, p, loc=0):
|
| 1667 |
+
return tuple(np.moveaxis(p, -1, 0)), loc, 1.0
|
| 1668 |
+
|
| 1669 |
+
# The infrastructure manually binds these methods to the instance, so
|
| 1670 |
+
# we can only override them by manually binding them, too.
|
| 1671 |
+
_pb_obj, _pb_cls = poisson_binom, poisson_binom_gen # shorter names (for PEP8)
|
| 1672 |
+
poisson_binom._parse_args_rvs = _parse_args_rvs.__get__(_pb_obj, _pb_cls)
|
| 1673 |
+
poisson_binom._parse_args_stats = _parse_args_stats.__get__(_pb_obj, _pb_cls)
|
| 1674 |
+
poisson_binom._parse_args = _parse_args.__get__(_pb_obj, _pb_cls)
|
| 1675 |
+
|
| 1676 |
+
class poisson_binomial_frozen(rv_discrete_frozen):
|
| 1677 |
+
# copied from rv_frozen; we just need to bind the `_parse_args` methods
|
| 1678 |
+
def __init__(self, dist, *args, **kwds): # verbatim
|
| 1679 |
+
self.args = args # verbatim
|
| 1680 |
+
self.kwds = kwds # verbatim
|
| 1681 |
+
|
| 1682 |
+
# create a new instance # verbatim
|
| 1683 |
+
self.dist = dist.__class__(**dist._updated_ctor_param()) # verbatim
|
| 1684 |
+
|
| 1685 |
+
# Here is the only modification
|
| 1686 |
+
self.dist._parse_args_rvs = _parse_args_rvs.__get__(_pb_obj, _pb_cls)
|
| 1687 |
+
self.dist._parse_args_stats = _parse_args_stats.__get__(_pb_obj, _pb_cls)
|
| 1688 |
+
self.dist._parse_args = _parse_args.__get__(_pb_obj, _pb_cls)
|
| 1689 |
+
|
| 1690 |
+
shapes, _, _ = self.dist._parse_args(*args, **kwds) # verbatim
|
| 1691 |
+
self.a, self.b = self.dist._get_support(*shapes) # verbatim
|
| 1692 |
+
|
| 1693 |
+
def expect(self, func=None, lb=None, ub=None, conditional=False, **kwds):
|
| 1694 |
+
a, loc, scale = self.dist._parse_args(*self.args, **self.kwds)
|
| 1695 |
+
# Here's the modification: we pass all args (including `loc`) into the `args`
|
| 1696 |
+
# parameter of `expect` so the shape only goes through `_parse_args` once.
|
| 1697 |
+
return self.dist.expect(func, self.args, loc, lb, ub, conditional, **kwds)
|
| 1698 |
+
|
| 1699 |
+
|
| 1700 |
+
class skellam_gen(rv_discrete):
|
| 1701 |
+
r"""A Skellam discrete random variable.
|
| 1702 |
+
|
| 1703 |
+
%(before_notes)s
|
| 1704 |
+
|
| 1705 |
+
Notes
|
| 1706 |
+
-----
|
| 1707 |
+
Probability distribution of the difference of two correlated or
|
| 1708 |
+
uncorrelated Poisson random variables.
|
| 1709 |
+
|
| 1710 |
+
Let :math:`k_1` and :math:`k_2` be two Poisson-distributed r.v. with
|
| 1711 |
+
expected values :math:`\lambda_1` and :math:`\lambda_2`. Then,
|
| 1712 |
+
:math:`k_1 - k_2` follows a Skellam distribution with parameters
|
| 1713 |
+
:math:`\mu_1 = \lambda_1 - \rho \sqrt{\lambda_1 \lambda_2}` and
|
| 1714 |
+
:math:`\mu_2 = \lambda_2 - \rho \sqrt{\lambda_1 \lambda_2}`, where
|
| 1715 |
+
:math:`\rho` is the correlation coefficient between :math:`k_1` and
|
| 1716 |
+
:math:`k_2`. If the two Poisson-distributed r.v. are independent then
|
| 1717 |
+
:math:`\rho = 0`.
|
| 1718 |
+
|
| 1719 |
+
Parameters :math:`\mu_1` and :math:`\mu_2` must be strictly positive.
|
| 1720 |
+
|
| 1721 |
+
For details see: https://en.wikipedia.org/wiki/Skellam_distribution
|
| 1722 |
+
|
| 1723 |
+
`skellam` takes :math:`\mu_1` and :math:`\mu_2` as shape parameters.
|
| 1724 |
+
|
| 1725 |
+
%(after_notes)s
|
| 1726 |
+
|
| 1727 |
+
%(example)s
|
| 1728 |
+
|
| 1729 |
+
"""
|
| 1730 |
+
def _shape_info(self):
|
| 1731 |
+
return [_ShapeInfo("mu1", False, (0, np.inf), (False, False)),
|
| 1732 |
+
_ShapeInfo("mu2", False, (0, np.inf), (False, False))]
|
| 1733 |
+
|
| 1734 |
+
def _rvs(self, mu1, mu2, size=None, random_state=None):
|
| 1735 |
+
n = size
|
| 1736 |
+
return (random_state.poisson(mu1, n) -
|
| 1737 |
+
random_state.poisson(mu2, n))
|
| 1738 |
+
|
| 1739 |
+
def _pmf(self, x, mu1, mu2):
|
| 1740 |
+
with np.errstate(over='ignore'): # see gh-17432
|
| 1741 |
+
px = np.where(x < 0,
|
| 1742 |
+
scu._ncx2_pdf(2*mu2, 2*(1-x), 2*mu1)*2,
|
| 1743 |
+
scu._ncx2_pdf(2*mu1, 2*(1+x), 2*mu2)*2)
|
| 1744 |
+
# ncx2.pdf() returns nan's for extremely low probabilities
|
| 1745 |
+
return px
|
| 1746 |
+
|
| 1747 |
+
def _cdf(self, x, mu1, mu2):
|
| 1748 |
+
x = floor(x)
|
| 1749 |
+
with np.errstate(over='ignore'): # see gh-17432
|
| 1750 |
+
px = np.where(x < 0,
|
| 1751 |
+
scu._ncx2_cdf(2*mu2, -2*x, 2*mu1),
|
| 1752 |
+
1 - scu._ncx2_cdf(2*mu1, 2*(x+1), 2*mu2))
|
| 1753 |
+
return px
|
| 1754 |
+
|
| 1755 |
+
def _stats(self, mu1, mu2):
|
| 1756 |
+
mean = mu1 - mu2
|
| 1757 |
+
var = mu1 + mu2
|
| 1758 |
+
g1 = mean / sqrt((var)**3)
|
| 1759 |
+
g2 = 1 / var
|
| 1760 |
+
return mean, var, g1, g2
|
| 1761 |
+
|
| 1762 |
+
|
| 1763 |
+
skellam = skellam_gen(a=-np.inf, name="skellam", longname='A Skellam')
|
| 1764 |
+
|
| 1765 |
+
|
| 1766 |
+
class yulesimon_gen(rv_discrete):
|
| 1767 |
+
r"""A Yule-Simon discrete random variable.
|
| 1768 |
+
|
| 1769 |
+
%(before_notes)s
|
| 1770 |
+
|
| 1771 |
+
Notes
|
| 1772 |
+
-----
|
| 1773 |
+
|
| 1774 |
+
The probability mass function for the `yulesimon` is:
|
| 1775 |
+
|
| 1776 |
+
.. math::
|
| 1777 |
+
|
| 1778 |
+
f(k) = \alpha B(k, \alpha+1)
|
| 1779 |
+
|
| 1780 |
+
for :math:`k=1,2,3,...`, where :math:`\alpha>0`.
|
| 1781 |
+
Here :math:`B` refers to the `scipy.special.beta` function.
|
| 1782 |
+
|
| 1783 |
+
The sampling of random variates is based on pg 553, Section 6.3 of [1]_.
|
| 1784 |
+
Our notation maps to the referenced logic via :math:`\alpha=a-1`.
|
| 1785 |
+
|
| 1786 |
+
For details see the wikipedia entry [2]_.
|
| 1787 |
+
|
| 1788 |
+
References
|
| 1789 |
+
----------
|
| 1790 |
+
.. [1] Devroye, Luc. "Non-uniform Random Variate Generation",
|
| 1791 |
+
(1986) Springer, New York.
|
| 1792 |
+
|
| 1793 |
+
.. [2] https://en.wikipedia.org/wiki/Yule-Simon_distribution
|
| 1794 |
+
|
| 1795 |
+
%(after_notes)s
|
| 1796 |
+
|
| 1797 |
+
%(example)s
|
| 1798 |
+
|
| 1799 |
+
"""
|
| 1800 |
+
def _shape_info(self):
|
| 1801 |
+
return [_ShapeInfo("alpha", False, (0, np.inf), (False, False))]
|
| 1802 |
+
|
| 1803 |
+
def _rvs(self, alpha, size=None, random_state=None):
|
| 1804 |
+
E1 = random_state.standard_exponential(size)
|
| 1805 |
+
E2 = random_state.standard_exponential(size)
|
| 1806 |
+
ans = ceil(-E1 / log1p(-exp(-E2 / alpha)))
|
| 1807 |
+
return ans
|
| 1808 |
+
|
| 1809 |
+
def _pmf(self, x, alpha):
|
| 1810 |
+
return alpha * special.beta(x, alpha + 1)
|
| 1811 |
+
|
| 1812 |
+
def _argcheck(self, alpha):
|
| 1813 |
+
return (alpha > 0)
|
| 1814 |
+
|
| 1815 |
+
def _logpmf(self, x, alpha):
|
| 1816 |
+
return log(alpha) + special.betaln(x, alpha + 1)
|
| 1817 |
+
|
| 1818 |
+
def _cdf(self, x, alpha):
|
| 1819 |
+
return 1 - x * special.beta(x, alpha + 1)
|
| 1820 |
+
|
| 1821 |
+
def _sf(self, x, alpha):
|
| 1822 |
+
return x * special.beta(x, alpha + 1)
|
| 1823 |
+
|
| 1824 |
+
def _logsf(self, x, alpha):
|
| 1825 |
+
return log(x) + special.betaln(x, alpha + 1)
|
| 1826 |
+
|
| 1827 |
+
def _stats(self, alpha):
|
| 1828 |
+
mu = np.where(alpha <= 1, np.inf, alpha / (alpha - 1))
|
| 1829 |
+
mu2 = np.where(alpha > 2,
|
| 1830 |
+
alpha**2 / ((alpha - 2.0) * (alpha - 1)**2),
|
| 1831 |
+
np.inf)
|
| 1832 |
+
mu2 = np.where(alpha <= 1, np.nan, mu2)
|
| 1833 |
+
g1 = np.where(alpha > 3,
|
| 1834 |
+
sqrt(alpha - 2) * (alpha + 1)**2 / (alpha * (alpha - 3)),
|
| 1835 |
+
np.inf)
|
| 1836 |
+
g1 = np.where(alpha <= 2, np.nan, g1)
|
| 1837 |
+
g2 = np.where(alpha > 4,
|
| 1838 |
+
alpha + 3 + ((11 * alpha**3 - 49 * alpha - 22) /
|
| 1839 |
+
(alpha * (alpha - 4) * (alpha - 3))),
|
| 1840 |
+
np.inf)
|
| 1841 |
+
g2 = np.where(alpha <= 2, np.nan, g2)
|
| 1842 |
+
return mu, mu2, g1, g2
|
| 1843 |
+
|
| 1844 |
+
|
| 1845 |
+
yulesimon = yulesimon_gen(name='yulesimon', a=1)
|
| 1846 |
+
|
| 1847 |
+
|
| 1848 |
+
class _nchypergeom_gen(rv_discrete):
|
| 1849 |
+
r"""A noncentral hypergeometric discrete random variable.
|
| 1850 |
+
|
| 1851 |
+
For subclassing by nchypergeom_fisher_gen and nchypergeom_wallenius_gen.
|
| 1852 |
+
|
| 1853 |
+
"""
|
| 1854 |
+
|
| 1855 |
+
rvs_name = None
|
| 1856 |
+
dist = None
|
| 1857 |
+
|
| 1858 |
+
def _shape_info(self):
|
| 1859 |
+
return [_ShapeInfo("M", True, (0, np.inf), (True, False)),
|
| 1860 |
+
_ShapeInfo("n", True, (0, np.inf), (True, False)),
|
| 1861 |
+
_ShapeInfo("N", True, (0, np.inf), (True, False)),
|
| 1862 |
+
_ShapeInfo("odds", False, (0, np.inf), (False, False))]
|
| 1863 |
+
|
| 1864 |
+
def _get_support(self, M, n, N, odds):
|
| 1865 |
+
N, m1, n = M, n, N # follow Wikipedia notation
|
| 1866 |
+
m2 = N - m1
|
| 1867 |
+
x_min = np.maximum(0, n - m2)
|
| 1868 |
+
x_max = np.minimum(n, m1)
|
| 1869 |
+
return x_min, x_max
|
| 1870 |
+
|
| 1871 |
+
def _argcheck(self, M, n, N, odds):
|
| 1872 |
+
M, n = np.asarray(M), np.asarray(n),
|
| 1873 |
+
N, odds = np.asarray(N), np.asarray(odds)
|
| 1874 |
+
cond1 = (M.astype(int) == M) & (M >= 0)
|
| 1875 |
+
cond2 = (n.astype(int) == n) & (n >= 0)
|
| 1876 |
+
cond3 = (N.astype(int) == N) & (N >= 0)
|
| 1877 |
+
cond4 = odds > 0
|
| 1878 |
+
cond5 = N <= M
|
| 1879 |
+
cond6 = n <= M
|
| 1880 |
+
return cond1 & cond2 & cond3 & cond4 & cond5 & cond6
|
| 1881 |
+
|
| 1882 |
+
def _rvs(self, M, n, N, odds, size=None, random_state=None):
|
| 1883 |
+
|
| 1884 |
+
@_vectorize_rvs_over_shapes
|
| 1885 |
+
def _rvs1(M, n, N, odds, size, random_state):
|
| 1886 |
+
length = np.prod(size)
|
| 1887 |
+
urn = _PyStochasticLib3()
|
| 1888 |
+
rv_gen = getattr(urn, self.rvs_name)
|
| 1889 |
+
rvs = rv_gen(N, n, M, odds, length, random_state)
|
| 1890 |
+
rvs = rvs.reshape(size)
|
| 1891 |
+
return rvs
|
| 1892 |
+
|
| 1893 |
+
return _rvs1(M, n, N, odds, size=size, random_state=random_state)
|
| 1894 |
+
|
| 1895 |
+
def _pmf(self, x, M, n, N, odds):
|
| 1896 |
+
|
| 1897 |
+
x, M, n, N, odds = np.broadcast_arrays(x, M, n, N, odds)
|
| 1898 |
+
if x.size == 0: # np.vectorize doesn't work with zero size input
|
| 1899 |
+
return np.empty_like(x)
|
| 1900 |
+
|
| 1901 |
+
@np.vectorize
|
| 1902 |
+
def _pmf1(x, M, n, N, odds):
|
| 1903 |
+
urn = self.dist(N, n, M, odds, 1e-12)
|
| 1904 |
+
return urn.probability(x)
|
| 1905 |
+
|
| 1906 |
+
return _pmf1(x, M, n, N, odds)
|
| 1907 |
+
|
| 1908 |
+
def _stats(self, M, n, N, odds, moments):
|
| 1909 |
+
|
| 1910 |
+
@np.vectorize
|
| 1911 |
+
def _moments1(M, n, N, odds):
|
| 1912 |
+
urn = self.dist(N, n, M, odds, 1e-12)
|
| 1913 |
+
return urn.moments()
|
| 1914 |
+
|
| 1915 |
+
m, v = (_moments1(M, n, N, odds) if ("m" in moments or "v" in moments)
|
| 1916 |
+
else (None, None))
|
| 1917 |
+
s, k = None, None
|
| 1918 |
+
return m, v, s, k
|
| 1919 |
+
|
| 1920 |
+
|
| 1921 |
+
class nchypergeom_fisher_gen(_nchypergeom_gen):
|
| 1922 |
+
r"""A Fisher's noncentral hypergeometric discrete random variable.
|
| 1923 |
+
|
| 1924 |
+
Fisher's noncentral hypergeometric distribution models drawing objects of
|
| 1925 |
+
two types from a bin. `M` is the total number of objects, `n` is the
|
| 1926 |
+
number of Type I objects, and `odds` is the odds ratio: the odds of
|
| 1927 |
+
selecting a Type I object rather than a Type II object when there is only
|
| 1928 |
+
one object of each type.
|
| 1929 |
+
The random variate represents the number of Type I objects drawn if we
|
| 1930 |
+
take a handful of objects from the bin at once and find out afterwards
|
| 1931 |
+
that we took `N` objects.
|
| 1932 |
+
|
| 1933 |
+
%(before_notes)s
|
| 1934 |
+
|
| 1935 |
+
See Also
|
| 1936 |
+
--------
|
| 1937 |
+
nchypergeom_wallenius, hypergeom, nhypergeom
|
| 1938 |
+
|
| 1939 |
+
Notes
|
| 1940 |
+
-----
|
| 1941 |
+
Let mathematical symbols :math:`N`, :math:`n`, and :math:`M` correspond
|
| 1942 |
+
with parameters `N`, `n`, and `M` (respectively) as defined above.
|
| 1943 |
+
|
| 1944 |
+
The probability mass function is defined as
|
| 1945 |
+
|
| 1946 |
+
.. math::
|
| 1947 |
+
|
| 1948 |
+
p(x; M, n, N, \omega) =
|
| 1949 |
+
\frac{\binom{n}{x}\binom{M - n}{N-x}\omega^x}{P_0},
|
| 1950 |
+
|
| 1951 |
+
for
|
| 1952 |
+
:math:`x \in [x_l, x_u]`,
|
| 1953 |
+
:math:`M \in {\mathbb N}`,
|
| 1954 |
+
:math:`n \in [0, M]`,
|
| 1955 |
+
:math:`N \in [0, M]`,
|
| 1956 |
+
:math:`\omega > 0`,
|
| 1957 |
+
where
|
| 1958 |
+
:math:`x_l = \max(0, N - (M - n))`,
|
| 1959 |
+
:math:`x_u = \min(N, n)`,
|
| 1960 |
+
|
| 1961 |
+
.. math::
|
| 1962 |
+
|
| 1963 |
+
P_0 = \sum_{y=x_l}^{x_u} \binom{n}{y}\binom{M - n}{N-y}\omega^y,
|
| 1964 |
+
|
| 1965 |
+
and the binomial coefficients are defined as
|
| 1966 |
+
|
| 1967 |
+
.. math:: \binom{n}{k} \equiv \frac{n!}{k! (n - k)!}.
|
| 1968 |
+
|
| 1969 |
+
`nchypergeom_fisher` uses the BiasedUrn package by Agner Fog with
|
| 1970 |
+
permission for it to be distributed under SciPy's license.
|
| 1971 |
+
|
| 1972 |
+
The symbols used to denote the shape parameters (`N`, `n`, and `M`) are not
|
| 1973 |
+
universally accepted; they are chosen for consistency with `hypergeom`.
|
| 1974 |
+
|
| 1975 |
+
Note that Fisher's noncentral hypergeometric distribution is distinct
|
| 1976 |
+
from Wallenius' noncentral hypergeometric distribution, which models
|
| 1977 |
+
drawing a pre-determined `N` objects from a bin one by one.
|
| 1978 |
+
When the odds ratio is unity, however, both distributions reduce to the
|
| 1979 |
+
ordinary hypergeometric distribution.
|
| 1980 |
+
|
| 1981 |
+
%(after_notes)s
|
| 1982 |
+
|
| 1983 |
+
References
|
| 1984 |
+
----------
|
| 1985 |
+
.. [1] Agner Fog, "Biased Urn Theory".
|
| 1986 |
+
https://cran.r-project.org/web/packages/BiasedUrn/vignettes/UrnTheory.pdf
|
| 1987 |
+
|
| 1988 |
+
.. [2] "Fisher's noncentral hypergeometric distribution", Wikipedia,
|
| 1989 |
+
https://en.wikipedia.org/wiki/Fisher's_noncentral_hypergeometric_distribution
|
| 1990 |
+
|
| 1991 |
+
%(example)s
|
| 1992 |
+
|
| 1993 |
+
"""
|
| 1994 |
+
|
| 1995 |
+
rvs_name = "rvs_fisher"
|
| 1996 |
+
dist = _PyFishersNCHypergeometric
|
| 1997 |
+
|
| 1998 |
+
|
| 1999 |
+
nchypergeom_fisher = nchypergeom_fisher_gen(
|
| 2000 |
+
name='nchypergeom_fisher',
|
| 2001 |
+
longname="A Fisher's noncentral hypergeometric")
|
| 2002 |
+
|
| 2003 |
+
|
| 2004 |
+
class nchypergeom_wallenius_gen(_nchypergeom_gen):
|
| 2005 |
+
r"""A Wallenius' noncentral hypergeometric discrete random variable.
|
| 2006 |
+
|
| 2007 |
+
Wallenius' noncentral hypergeometric distribution models drawing objects of
|
| 2008 |
+
two types from a bin. `M` is the total number of objects, `n` is the
|
| 2009 |
+
number of Type I objects, and `odds` is the odds ratio: the odds of
|
| 2010 |
+
selecting a Type I object rather than a Type II object when there is only
|
| 2011 |
+
one object of each type.
|
| 2012 |
+
The random variate represents the number of Type I objects drawn if we
|
| 2013 |
+
draw a pre-determined `N` objects from a bin one by one.
|
| 2014 |
+
|
| 2015 |
+
%(before_notes)s
|
| 2016 |
+
|
| 2017 |
+
See Also
|
| 2018 |
+
--------
|
| 2019 |
+
nchypergeom_fisher, hypergeom, nhypergeom
|
| 2020 |
+
|
| 2021 |
+
Notes
|
| 2022 |
+
-----
|
| 2023 |
+
Let mathematical symbols :math:`N`, :math:`n`, and :math:`M` correspond
|
| 2024 |
+
with parameters `N`, `n`, and `M` (respectively) as defined above.
|
| 2025 |
+
|
| 2026 |
+
The probability mass function is defined as
|
| 2027 |
+
|
| 2028 |
+
.. math::
|
| 2029 |
+
|
| 2030 |
+
p(x; N, n, M) = \binom{n}{x} \binom{M - n}{N-x}
|
| 2031 |
+
\int_0^1 \left(1-t^{\omega/D}\right)^x\left(1-t^{1/D}\right)^{N-x} dt
|
| 2032 |
+
|
| 2033 |
+
for
|
| 2034 |
+
:math:`x \in [x_l, x_u]`,
|
| 2035 |
+
:math:`M \in {\mathbb N}`,
|
| 2036 |
+
:math:`n \in [0, M]`,
|
| 2037 |
+
:math:`N \in [0, M]`,
|
| 2038 |
+
:math:`\omega > 0`,
|
| 2039 |
+
where
|
| 2040 |
+
:math:`x_l = \max(0, N - (M - n))`,
|
| 2041 |
+
:math:`x_u = \min(N, n)`,
|
| 2042 |
+
|
| 2043 |
+
.. math::
|
| 2044 |
+
|
| 2045 |
+
D = \omega(n - x) + ((M - n)-(N-x)),
|
| 2046 |
+
|
| 2047 |
+
and the binomial coefficients are defined as
|
| 2048 |
+
|
| 2049 |
+
.. math:: \binom{n}{k} \equiv \frac{n!}{k! (n - k)!}.
|
| 2050 |
+
|
| 2051 |
+
`nchypergeom_wallenius` uses the BiasedUrn package by Agner Fog with
|
| 2052 |
+
permission for it to be distributed under SciPy's license.
|
| 2053 |
+
|
| 2054 |
+
The symbols used to denote the shape parameters (`N`, `n`, and `M`) are not
|
| 2055 |
+
universally accepted; they are chosen for consistency with `hypergeom`.
|
| 2056 |
+
|
| 2057 |
+
Note that Wallenius' noncentral hypergeometric distribution is distinct
|
| 2058 |
+
from Fisher's noncentral hypergeometric distribution, which models
|
| 2059 |
+
take a handful of objects from the bin at once, finding out afterwards
|
| 2060 |
+
that `N` objects were taken.
|
| 2061 |
+
When the odds ratio is unity, however, both distributions reduce to the
|
| 2062 |
+
ordinary hypergeometric distribution.
|
| 2063 |
+
|
| 2064 |
+
%(after_notes)s
|
| 2065 |
+
|
| 2066 |
+
References
|
| 2067 |
+
----------
|
| 2068 |
+
.. [1] Agner Fog, "Biased Urn Theory".
|
| 2069 |
+
https://cran.r-project.org/web/packages/BiasedUrn/vignettes/UrnTheory.pdf
|
| 2070 |
+
|
| 2071 |
+
.. [2] "Wallenius' noncentral hypergeometric distribution", Wikipedia,
|
| 2072 |
+
https://en.wikipedia.org/wiki/Wallenius'_noncentral_hypergeometric_distribution
|
| 2073 |
+
|
| 2074 |
+
%(example)s
|
| 2075 |
+
|
| 2076 |
+
"""
|
| 2077 |
+
|
| 2078 |
+
rvs_name = "rvs_wallenius"
|
| 2079 |
+
dist = _PyWalleniusNCHypergeometric
|
| 2080 |
+
|
| 2081 |
+
|
| 2082 |
+
nchypergeom_wallenius = nchypergeom_wallenius_gen(
|
| 2083 |
+
name='nchypergeom_wallenius',
|
| 2084 |
+
longname="A Wallenius' noncentral hypergeometric")
|
| 2085 |
+
|
| 2086 |
+
|
| 2087 |
+
# Collect names of classes and objects in this module.
|
| 2088 |
+
pairs = list(globals().copy().items())
|
| 2089 |
+
_distn_names, _distn_gen_names = get_distribution_names(pairs, rv_discrete)
|
| 2090 |
+
|
| 2091 |
+
__all__ = _distn_names + _distn_gen_names
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/stats/_distn_infrastructure.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/stats/_distr_params.py
ADDED
|
@@ -0,0 +1,299 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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py as np
|
| 5 |
+
|
| 6 |
+
distcont = [
|
| 7 |
+
['alpha', (3.5704770516650459,)],
|
| 8 |
+
['anglit', ()],
|
| 9 |
+
['arcsine', ()],
|
| 10 |
+
['argus', (1.0,)],
|
| 11 |
+
['beta', (2.3098496451481823, 0.62687954300963677)],
|
| 12 |
+
['betaprime', (5, 6)],
|
| 13 |
+
['bradford', (0.29891359763170633,)],
|
| 14 |
+
['burr', (10.5, 4.3)],
|
| 15 |
+
['burr12', (10, 4)],
|
| 16 |
+
['cauchy', ()],
|
| 17 |
+
['chi', (78,)],
|
| 18 |
+
['chi2', (55,)],
|
| 19 |
+
['cosine', ()],
|
| 20 |
+
['crystalball', (2.0, 3.0)],
|
| 21 |
+
['dgamma', (1.1023326088288166,)],
|
| 22 |
+
['dpareto_lognorm', (3, 1.2, 1.5, 2)],
|
| 23 |
+
['dweibull', (2.0685080649914673,)],
|
| 24 |
+
['erlang', (10,)],
|
| 25 |
+
['expon', ()],
|
| 26 |
+
['exponnorm', (1.5,)],
|
| 27 |
+
['exponpow', (2.697119160358469,)],
|
| 28 |
+
['exponweib', (2.8923945291034436, 1.9505288745913174)],
|
| 29 |
+
['f', (29, 18)],
|
| 30 |
+
['fatiguelife', (29,)], # correction numargs = 1
|
| 31 |
+
['fisk', (3.0857548622253179,)],
|
| 32 |
+
['foldcauchy', (4.7164673455831894,)],
|
| 33 |
+
['foldnorm', (1.9521253373555869,)],
|
| 34 |
+
['gamma', (1.9932305483800778,)],
|
| 35 |
+
['gausshyper', (13.763771604130699, 3.1189636648681431,
|
| 36 |
+
2.5145980350183019, 5.1811649903971615)], # veryslow
|
| 37 |
+
['genexpon', (9.1325976465418908, 16.231956600590632, 3.2819552690843983)],
|
| 38 |
+
['genextreme', (-0.1,)],
|
| 39 |
+
['gengamma', (4.4162385429431925, 3.1193091679242761)],
|
| 40 |
+
['gengamma', (4.4162385429431925, -3.1193091679242761)],
|
| 41 |
+
['genhalflogistic', (0.77274727809929322,)],
|
| 42 |
+
['genhyperbolic', (0.5, 1.5, -0.5,)],
|
| 43 |
+
['geninvgauss', (2.3, 1.5)],
|
| 44 |
+
['genlogistic', (0.41192440799679475,)],
|
| 45 |
+
['gennorm', (1.2988442399460265,)],
|
| 46 |
+
['halfgennorm', (0.6748054997000371,)],
|
| 47 |
+
['genpareto', (0.1,)], # use case with finite moments
|
| 48 |
+
['gibrat', ()],
|
| 49 |
+
['gompertz', (0.94743713075105251,)],
|
| 50 |
+
['gumbel_l', ()],
|
| 51 |
+
['gumbel_r', ()],
|
| 52 |
+
['halfcauchy', ()],
|
| 53 |
+
['halflogistic', ()],
|
| 54 |
+
['halfnorm', ()],
|
| 55 |
+
['hypsecant', ()],
|
| 56 |
+
['invgamma', (4.0668996136993067,)],
|
| 57 |
+
['invgauss', (0.14546264555347513,)],
|
| 58 |
+
['invweibull', (10.58,)],
|
| 59 |
+
['irwinhall', (10,)],
|
| 60 |
+
['jf_skew_t', (8, 4)],
|
| 61 |
+
['johnsonsb', (4.3172675099141058, 3.1837781130785063)],
|
| 62 |
+
['johnsonsu', (2.554395574161155, 2.2482281679651965)],
|
| 63 |
+
['kappa4', (0.0, 0.0)],
|
| 64 |
+
['kappa4', (-0.1, 0.1)],
|
| 65 |
+
['kappa4', (0.0, 0.1)],
|
| 66 |
+
['kappa4', (0.1, 0.0)],
|
| 67 |
+
['kappa3', (1.0,)],
|
| 68 |
+
['ksone', (1000,)], # replace 22 by 100 to avoid failing range, ticket 956
|
| 69 |
+
['kstwo', (10,)],
|
| 70 |
+
['kstwobign', ()],
|
| 71 |
+
['landau', ()],
|
| 72 |
+
['laplace', ()],
|
| 73 |
+
['laplace_asymmetric', (2,)],
|
| 74 |
+
['levy', ()],
|
| 75 |
+
['levy_l', ()],
|
| 76 |
+
['levy_stable', (1.8, -0.5)],
|
| 77 |
+
['loggamma', (0.41411931826052117,)],
|
| 78 |
+
['logistic', ()],
|
| 79 |
+
['loglaplace', (3.2505926592051435,)],
|
| 80 |
+
['lognorm', (0.95368226960575331,)],
|
| 81 |
+
['loguniform', (0.01, 1.25)],
|
| 82 |
+
['lomax', (1.8771398388773268,)],
|
| 83 |
+
['maxwell', ()],
|
| 84 |
+
['mielke', (10.4, 4.6)],
|
| 85 |
+
['moyal', ()],
|
| 86 |
+
['nakagami', (4.9673794866666237,)],
|
| 87 |
+
['ncf', (27, 27, 0.41578441799226107)],
|
| 88 |
+
['nct', (14, 0.24045031331198066)],
|
| 89 |
+
['ncx2', (21, 1.0560465975116415)],
|
| 90 |
+
['norm', ()],
|
| 91 |
+
['norminvgauss', (1.25, 0.5)],
|
| 92 |
+
['pareto', (2.621716532144454,)],
|
| 93 |
+
['pearson3', (0.1,)],
|
| 94 |
+
['pearson3', (-2,)],
|
| 95 |
+
['powerlaw', (1.6591133289905851,)],
|
| 96 |
+
['powerlaw', (0.6591133289905851,)],
|
| 97 |
+
['powerlognorm', (2.1413923530064087, 0.44639540782048337)],
|
| 98 |
+
['powernorm', (4.4453652254590779,)],
|
| 99 |
+
['rayleigh', ()],
|
| 100 |
+
['rdist', (1.6,)],
|
| 101 |
+
['recipinvgauss', (0.63004267809369119,)],
|
| 102 |
+
['reciprocal', (0.01, 1.25)],
|
| 103 |
+
['rel_breitwigner', (36.545206797050334, )],
|
| 104 |
+
['rice', (0.7749725210111873,)],
|
| 105 |
+
['semicircular', ()],
|
| 106 |
+
['skewcauchy', (0.5,)],
|
| 107 |
+
['skewnorm', (4.0,)],
|
| 108 |
+
['studentized_range', (3.0, 10.0)],
|
| 109 |
+
['t', (2.7433514990818093,)],
|
| 110 |
+
['trapezoid', (0.2, 0.8)],
|
| 111 |
+
['triang', (0.15785029824528218,)],
|
| 112 |
+
['truncexpon', (4.6907725456810478,)],
|
| 113 |
+
['truncnorm', (-1.0978730080013919, 2.7306754109031979)],
|
| 114 |
+
['truncnorm', (0.1, 2.)],
|
| 115 |
+
['truncpareto', (1.8, 5.3)],
|
| 116 |
+
['truncpareto', (2, 5)],
|
| 117 |
+
['truncweibull_min', (2.5, 0.25, 1.75)],
|
| 118 |
+
['tukeylambda', (3.1321477856738267,)],
|
| 119 |
+
['uniform', ()],
|
| 120 |
+
['vonmises', (3.9939042581071398,)],
|
| 121 |
+
['vonmises_line', (3.9939042581071398,)],
|
| 122 |
+
['wald', ()],
|
| 123 |
+
['weibull_max', (2.8687961709100187,)],
|
| 124 |
+
['weibull_min', (1.7866166930421596,)],
|
| 125 |
+
['wrapcauchy', (0.031071279018614728,)]
|
| 126 |
+
]
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
distdiscrete = [
|
| 130 |
+
['bernoulli',(0.3,)],
|
| 131 |
+
['betabinom', (5, 2.3, 0.63)],
|
| 132 |
+
['betanbinom', (5, 9.3, 1)],
|
| 133 |
+
['binom', (5, 0.4)],
|
| 134 |
+
['boltzmann',(1.4, 19)],
|
| 135 |
+
['dlaplace', (0.8,)], # 0.5
|
| 136 |
+
['geom', (0.5,)],
|
| 137 |
+
['hypergeom',(30, 12, 6)],
|
| 138 |
+
['hypergeom',(21,3,12)], # numpy.random (3,18,12) numpy ticket:921
|
| 139 |
+
['hypergeom',(21,18,11)], # numpy.random (18,3,11) numpy ticket:921
|
| 140 |
+
['nchypergeom_fisher', (140, 80, 60, 0.5)],
|
| 141 |
+
['nchypergeom_wallenius', (140, 80, 60, 0.5)],
|
| 142 |
+
['logser', (0.6,)], # re-enabled, numpy ticket:921
|
| 143 |
+
['nbinom', (0.4, 0.4)], # from tickets: 583
|
| 144 |
+
['nbinom', (5, 0.5)],
|
| 145 |
+
['planck', (0.51,)], # 4.1
|
| 146 |
+
['poisson', (0.6,)],
|
| 147 |
+
['poisson_binom', ([0.1, 0.6, 0.7, 0.8],)],
|
| 148 |
+
['randint', (7, 31)],
|
| 149 |
+
['skellam', (15, 8)],
|
| 150 |
+
['zipf', (6.6,)],
|
| 151 |
+
['zipfian', (0.75, 15)],
|
| 152 |
+
['zipfian', (1.25, 10)],
|
| 153 |
+
['yulesimon', (11.0,)],
|
| 154 |
+
['nhypergeom', (20, 7, 1)]
|
| 155 |
+
]
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
invdistdiscrete = [
|
| 159 |
+
# In each of the following, at least one shape parameter is invalid
|
| 160 |
+
['hypergeom', (3, 3, 4)],
|
| 161 |
+
['nhypergeom', (5, 2, 8)],
|
| 162 |
+
['nchypergeom_fisher', (3, 3, 4, 1)],
|
| 163 |
+
['nchypergeom_wallenius', (3, 3, 4, 1)],
|
| 164 |
+
['bernoulli', (1.5, )],
|
| 165 |
+
['binom', (10, 1.5)],
|
| 166 |
+
['betabinom', (10, -0.4, -0.5)],
|
| 167 |
+
['betanbinom', (10, -0.4, -0.5)],
|
| 168 |
+
['boltzmann', (-1, 4)],
|
| 169 |
+
['dlaplace', (-0.5, )],
|
| 170 |
+
['geom', (1.5, )],
|
| 171 |
+
['logser', (1.5, )],
|
| 172 |
+
['nbinom', (10, 1.5)],
|
| 173 |
+
['planck', (-0.5, )],
|
| 174 |
+
['poisson', (-0.5, )],
|
| 175 |
+
['poisson_binom', ([-1, 2, 0.5],)],
|
| 176 |
+
['randint', (5, 2)],
|
| 177 |
+
['skellam', (-5, -2)],
|
| 178 |
+
['zipf', (-2, )],
|
| 179 |
+
['yulesimon', (-2, )],
|
| 180 |
+
['zipfian', (-0.75, 15)]
|
| 181 |
+
]
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
invdistcont = [
|
| 185 |
+
# In each of the following, at least one shape parameter is invalid
|
| 186 |
+
['alpha', (-1, )],
|
| 187 |
+
['anglit', ()],
|
| 188 |
+
['arcsine', ()],
|
| 189 |
+
['argus', (-1, )],
|
| 190 |
+
['beta', (-2, 2)],
|
| 191 |
+
['betaprime', (-2, 2)],
|
| 192 |
+
['bradford', (-1, )],
|
| 193 |
+
['burr', (-1, 1)],
|
| 194 |
+
['burr12', (-1, 1)],
|
| 195 |
+
['cauchy', ()],
|
| 196 |
+
['chi', (-1, )],
|
| 197 |
+
['chi2', (-1, )],
|
| 198 |
+
['cosine', ()],
|
| 199 |
+
['crystalball', (-1, 2)],
|
| 200 |
+
['dgamma', (-1, )],
|
| 201 |
+
['dpareto_lognorm', (3, -1.2, 1.5, 2)],
|
| 202 |
+
['dweibull', (-1, )],
|
| 203 |
+
['erlang', (-1, )],
|
| 204 |
+
['expon', ()],
|
| 205 |
+
['exponnorm', (-1, )],
|
| 206 |
+
['exponweib', (1, -1)],
|
| 207 |
+
['exponpow', (-1, )],
|
| 208 |
+
['f', (10, -10)],
|
| 209 |
+
['fatiguelife', (-1, )],
|
| 210 |
+
['fisk', (-1, )],
|
| 211 |
+
['foldcauchy', (-1, )],
|
| 212 |
+
['foldnorm', (-1, )],
|
| 213 |
+
['genlogistic', (-1, )],
|
| 214 |
+
['gennorm', (-1, )],
|
| 215 |
+
['genpareto', (np.inf, )],
|
| 216 |
+
['genexpon', (1, 2, -3)],
|
| 217 |
+
['genextreme', (np.inf, )],
|
| 218 |
+
['genhyperbolic', (0.5, -0.5, -1.5,)],
|
| 219 |
+
['gausshyper', (1, 2, 3, -4)],
|
| 220 |
+
['gamma', (-1, )],
|
| 221 |
+
['gengamma', (-1, 0)],
|
| 222 |
+
['genhalflogistic', (-1, )],
|
| 223 |
+
['geninvgauss', (1, 0)],
|
| 224 |
+
['gibrat', ()],
|
| 225 |
+
['gompertz', (-1, )],
|
| 226 |
+
['gumbel_r', ()],
|
| 227 |
+
['gumbel_l', ()],
|
| 228 |
+
['halfcauchy', ()],
|
| 229 |
+
['halflogistic', ()],
|
| 230 |
+
['halfnorm', ()],
|
| 231 |
+
['halfgennorm', (-1, )],
|
| 232 |
+
['hypsecant', ()],
|
| 233 |
+
['invgamma', (-1, )],
|
| 234 |
+
['invgauss', (-1, )],
|
| 235 |
+
['invweibull', (-1, )],
|
| 236 |
+
['irwinhall', (-1,)],
|
| 237 |
+
['irwinhall', (0,)],
|
| 238 |
+
['irwinhall', (2.5,)],
|
| 239 |
+
['jf_skew_t', (-1, 0)],
|
| 240 |
+
['johnsonsb', (1, -2)],
|
| 241 |
+
['johnsonsu', (1, -2)],
|
| 242 |
+
['kappa4', (np.nan, 0)],
|
| 243 |
+
['kappa3', (-1, )],
|
| 244 |
+
['ksone', (-1, )],
|
| 245 |
+
['kstwo', (-1, )],
|
| 246 |
+
['kstwobign', ()],
|
| 247 |
+
['landau', ()],
|
| 248 |
+
['laplace', ()],
|
| 249 |
+
['laplace_asymmetric', (-1, )],
|
| 250 |
+
['levy', ()],
|
| 251 |
+
['levy_l', ()],
|
| 252 |
+
['levy_stable', (-1, 1)],
|
| 253 |
+
['logistic', ()],
|
| 254 |
+
['loggamma', (-1, )],
|
| 255 |
+
['loglaplace', (-1, )],
|
| 256 |
+
['lognorm', (-1, )],
|
| 257 |
+
['loguniform', (10, 5)],
|
| 258 |
+
['lomax', (-1, )],
|
| 259 |
+
['maxwell', ()],
|
| 260 |
+
['mielke', (1, -2)],
|
| 261 |
+
['moyal', ()],
|
| 262 |
+
['nakagami', (-1, )],
|
| 263 |
+
['ncx2', (-1, 2)],
|
| 264 |
+
['ncf', (10, 20, -1)],
|
| 265 |
+
['nct', (-1, 2)],
|
| 266 |
+
['norm', ()],
|
| 267 |
+
['norminvgauss', (5, -10)],
|
| 268 |
+
['pareto', (-1, )],
|
| 269 |
+
['pearson3', (np.nan, )],
|
| 270 |
+
['powerlaw', (-1, )],
|
| 271 |
+
['powerlognorm', (1, -2)],
|
| 272 |
+
['powernorm', (-1, )],
|
| 273 |
+
['rdist', (-1, )],
|
| 274 |
+
['rayleigh', ()],
|
| 275 |
+
['rice', (-1, )],
|
| 276 |
+
['recipinvgauss', (-1, )],
|
| 277 |
+
['semicircular', ()],
|
| 278 |
+
['skewnorm', (np.inf, )],
|
| 279 |
+
['studentized_range', (-1, 1)],
|
| 280 |
+
['rel_breitwigner', (-2, )],
|
| 281 |
+
['t', (-1, )],
|
| 282 |
+
['trapezoid', (0, 2)],
|
| 283 |
+
['triang', (2, )],
|
| 284 |
+
['truncexpon', (-1, )],
|
| 285 |
+
['truncnorm', (10, 5)],
|
| 286 |
+
['truncpareto', (-1, 5)],
|
| 287 |
+
['truncpareto', (1.8, .5)],
|
| 288 |
+
['truncweibull_min', (-2.5, 0.25, 1.75)],
|
| 289 |
+
['tukeylambda', (np.nan, )],
|
| 290 |
+
['uniform', ()],
|
| 291 |
+
['vonmises', (-1, )],
|
| 292 |
+
['vonmises_line', (-1, )],
|
| 293 |
+
['wald', ()],
|
| 294 |
+
['weibull_min', (-1, )],
|
| 295 |
+
['weibull_max', (-1, )],
|
| 296 |
+
['wrapcauchy', (2, )],
|
| 297 |
+
['reciprocal', (15, 10)],
|
| 298 |
+
['skewcauchy', (2, )]
|
| 299 |
+
]
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/stats/_distribution_infrastructure.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/stats/_entropy.py
ADDED
|
@@ -0,0 +1,429 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
+
"""
|
| 2 |
+
Created on Fri Apr 2 09:06:05 2021
|
| 3 |
+
|
| 4 |
+
@author: matth
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import math
|
| 8 |
+
import numpy as np
|
| 9 |
+
from scipy import special
|
| 10 |
+
from ._axis_nan_policy import _axis_nan_policy_factory, _broadcast_arrays
|
| 11 |
+
from scipy._lib._array_api import array_namespace, xp_moveaxis_to_end
|
| 12 |
+
|
| 13 |
+
__all__ = ['entropy', 'differential_entropy']
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
@_axis_nan_policy_factory(
|
| 17 |
+
lambda x: x,
|
| 18 |
+
n_samples=lambda kwgs: (
|
| 19 |
+
2 if ("qk" in kwgs and kwgs["qk"] is not None)
|
| 20 |
+
else 1
|
| 21 |
+
),
|
| 22 |
+
n_outputs=1, result_to_tuple=lambda x: (x,), paired=True,
|
| 23 |
+
too_small=-1 # entropy doesn't have too small inputs
|
| 24 |
+
)
|
| 25 |
+
def entropy(pk: np.typing.ArrayLike,
|
| 26 |
+
qk: np.typing.ArrayLike | None = None,
|
| 27 |
+
base: float | None = None,
|
| 28 |
+
axis: int = 0
|
| 29 |
+
) -> np.number | np.ndarray:
|
| 30 |
+
"""
|
| 31 |
+
Calculate the Shannon entropy/relative entropy of given distribution(s).
|
| 32 |
+
|
| 33 |
+
If only probabilities `pk` are given, the Shannon entropy is calculated as
|
| 34 |
+
``H = -sum(pk * log(pk))``.
|
| 35 |
+
|
| 36 |
+
If `qk` is not None, then compute the relative entropy
|
| 37 |
+
``D = sum(pk * log(pk / qk))``. This quantity is also known
|
| 38 |
+
as the Kullback-Leibler divergence.
|
| 39 |
+
|
| 40 |
+
This routine will normalize `pk` and `qk` if they don't sum to 1.
|
| 41 |
+
|
| 42 |
+
Parameters
|
| 43 |
+
----------
|
| 44 |
+
pk : array_like
|
| 45 |
+
Defines the (discrete) distribution. Along each axis-slice of ``pk``,
|
| 46 |
+
element ``i`` is the (possibly unnormalized) probability of event
|
| 47 |
+
``i``.
|
| 48 |
+
qk : array_like, optional
|
| 49 |
+
Sequence against which the relative entropy is computed. Should be in
|
| 50 |
+
the same format as `pk`.
|
| 51 |
+
base : float, optional
|
| 52 |
+
The logarithmic base to use, defaults to ``e`` (natural logarithm).
|
| 53 |
+
axis : int, optional
|
| 54 |
+
The axis along which the entropy is calculated. Default is 0.
|
| 55 |
+
|
| 56 |
+
Returns
|
| 57 |
+
-------
|
| 58 |
+
S : {float, array_like}
|
| 59 |
+
The calculated entropy.
|
| 60 |
+
|
| 61 |
+
Notes
|
| 62 |
+
-----
|
| 63 |
+
Informally, the Shannon entropy quantifies the expected uncertainty
|
| 64 |
+
inherent in the possible outcomes of a discrete random variable.
|
| 65 |
+
For example,
|
| 66 |
+
if messages consisting of sequences of symbols from a set are to be
|
| 67 |
+
encoded and transmitted over a noiseless channel, then the Shannon entropy
|
| 68 |
+
``H(pk)`` gives a tight lower bound for the average number of units of
|
| 69 |
+
information needed per symbol if the symbols occur with frequencies
|
| 70 |
+
governed by the discrete distribution `pk` [1]_. The choice of base
|
| 71 |
+
determines the choice of units; e.g., ``e`` for nats, ``2`` for bits, etc.
|
| 72 |
+
|
| 73 |
+
The relative entropy, ``D(pk|qk)``, quantifies the increase in the average
|
| 74 |
+
number of units of information needed per symbol if the encoding is
|
| 75 |
+
optimized for the probability distribution `qk` instead of the true
|
| 76 |
+
distribution `pk`. Informally, the relative entropy quantifies the expected
|
| 77 |
+
excess in surprise experienced if one believes the true distribution is
|
| 78 |
+
`qk` when it is actually `pk`.
|
| 79 |
+
|
| 80 |
+
A related quantity, the cross entropy ``CE(pk, qk)``, satisfies the
|
| 81 |
+
equation ``CE(pk, qk) = H(pk) + D(pk|qk)`` and can also be calculated with
|
| 82 |
+
the formula ``CE = -sum(pk * log(qk))``. It gives the average
|
| 83 |
+
number of units of information needed per symbol if an encoding is
|
| 84 |
+
optimized for the probability distribution `qk` when the true distribution
|
| 85 |
+
is `pk`. It is not computed directly by `entropy`, but it can be computed
|
| 86 |
+
using two calls to the function (see Examples).
|
| 87 |
+
|
| 88 |
+
See [2]_ for more information.
|
| 89 |
+
|
| 90 |
+
References
|
| 91 |
+
----------
|
| 92 |
+
.. [1] Shannon, C.E. (1948), A Mathematical Theory of Communication.
|
| 93 |
+
Bell System Technical Journal, 27: 379-423.
|
| 94 |
+
https://doi.org/10.1002/j.1538-7305.1948.tb01338.x
|
| 95 |
+
.. [2] Thomas M. Cover and Joy A. Thomas. 2006. Elements of Information
|
| 96 |
+
Theory (Wiley Series in Telecommunications and Signal Processing).
|
| 97 |
+
Wiley-Interscience, USA.
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
Examples
|
| 101 |
+
--------
|
| 102 |
+
The outcome of a fair coin is the most uncertain:
|
| 103 |
+
|
| 104 |
+
>>> import numpy as np
|
| 105 |
+
>>> from scipy.stats import entropy
|
| 106 |
+
>>> base = 2 # work in units of bits
|
| 107 |
+
>>> pk = np.array([1/2, 1/2]) # fair coin
|
| 108 |
+
>>> H = entropy(pk, base=base)
|
| 109 |
+
>>> H
|
| 110 |
+
1.0
|
| 111 |
+
>>> H == -np.sum(pk * np.log(pk)) / np.log(base)
|
| 112 |
+
True
|
| 113 |
+
|
| 114 |
+
The outcome of a biased coin is less uncertain:
|
| 115 |
+
|
| 116 |
+
>>> qk = np.array([9/10, 1/10]) # biased coin
|
| 117 |
+
>>> entropy(qk, base=base)
|
| 118 |
+
0.46899559358928117
|
| 119 |
+
|
| 120 |
+
The relative entropy between the fair coin and biased coin is calculated
|
| 121 |
+
as:
|
| 122 |
+
|
| 123 |
+
>>> D = entropy(pk, qk, base=base)
|
| 124 |
+
>>> D
|
| 125 |
+
0.7369655941662062
|
| 126 |
+
>>> np.isclose(D, np.sum(pk * np.log(pk/qk)) / np.log(base), rtol=4e-16, atol=0)
|
| 127 |
+
True
|
| 128 |
+
|
| 129 |
+
The cross entropy can be calculated as the sum of the entropy and
|
| 130 |
+
relative entropy`:
|
| 131 |
+
|
| 132 |
+
>>> CE = entropy(pk, base=base) + entropy(pk, qk, base=base)
|
| 133 |
+
>>> CE
|
| 134 |
+
1.736965594166206
|
| 135 |
+
>>> CE == -np.sum(pk * np.log(qk)) / np.log(base)
|
| 136 |
+
True
|
| 137 |
+
|
| 138 |
+
"""
|
| 139 |
+
if base is not None and base <= 0:
|
| 140 |
+
raise ValueError("`base` must be a positive number or `None`.")
|
| 141 |
+
|
| 142 |
+
xp = array_namespace(pk) if qk is None else array_namespace(pk, qk)
|
| 143 |
+
|
| 144 |
+
pk = xp.asarray(pk)
|
| 145 |
+
with np.errstate(invalid='ignore'):
|
| 146 |
+
pk = 1.0*pk / xp.sum(pk, axis=axis, keepdims=True) # type: ignore[operator]
|
| 147 |
+
if qk is None:
|
| 148 |
+
vec = special.entr(pk)
|
| 149 |
+
else:
|
| 150 |
+
qk = xp.asarray(qk)
|
| 151 |
+
pk, qk = _broadcast_arrays((pk, qk), axis=None, xp=xp) # don't ignore any axes
|
| 152 |
+
sum_kwargs = dict(axis=axis, keepdims=True)
|
| 153 |
+
qk = 1.0*qk / xp.sum(qk, **sum_kwargs) # type: ignore[operator, call-overload]
|
| 154 |
+
vec = special.rel_entr(pk, qk)
|
| 155 |
+
S = xp.sum(vec, axis=axis)
|
| 156 |
+
if base is not None:
|
| 157 |
+
S /= math.log(base)
|
| 158 |
+
return S
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
def _differential_entropy_is_too_small(samples, kwargs, axis=-1):
|
| 162 |
+
values = samples[0]
|
| 163 |
+
n = values.shape[axis]
|
| 164 |
+
window_length = kwargs.get("window_length",
|
| 165 |
+
math.floor(math.sqrt(n) + 0.5))
|
| 166 |
+
if not 2 <= 2 * window_length < n:
|
| 167 |
+
return True
|
| 168 |
+
return False
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
@_axis_nan_policy_factory(
|
| 172 |
+
lambda x: x, n_outputs=1, result_to_tuple=lambda x: (x,),
|
| 173 |
+
too_small=_differential_entropy_is_too_small
|
| 174 |
+
)
|
| 175 |
+
def differential_entropy(
|
| 176 |
+
values: np.typing.ArrayLike,
|
| 177 |
+
*,
|
| 178 |
+
window_length: int | None = None,
|
| 179 |
+
base: float | None = None,
|
| 180 |
+
axis: int = 0,
|
| 181 |
+
method: str = "auto",
|
| 182 |
+
) -> np.number | np.ndarray:
|
| 183 |
+
r"""Given a sample of a distribution, estimate the differential entropy.
|
| 184 |
+
|
| 185 |
+
Several estimation methods are available using the `method` parameter. By
|
| 186 |
+
default, a method is selected based the size of the sample.
|
| 187 |
+
|
| 188 |
+
Parameters
|
| 189 |
+
----------
|
| 190 |
+
values : sequence
|
| 191 |
+
Sample from a continuous distribution.
|
| 192 |
+
window_length : int, optional
|
| 193 |
+
Window length for computing Vasicek estimate. Must be an integer
|
| 194 |
+
between 1 and half of the sample size. If ``None`` (the default), it
|
| 195 |
+
uses the heuristic value
|
| 196 |
+
|
| 197 |
+
.. math::
|
| 198 |
+
\left \lfloor \sqrt{n} + 0.5 \right \rfloor
|
| 199 |
+
|
| 200 |
+
where :math:`n` is the sample size. This heuristic was originally
|
| 201 |
+
proposed in [2]_ and has become common in the literature.
|
| 202 |
+
base : float, optional
|
| 203 |
+
The logarithmic base to use, defaults to ``e`` (natural logarithm).
|
| 204 |
+
axis : int, optional
|
| 205 |
+
The axis along which the differential entropy is calculated.
|
| 206 |
+
Default is 0.
|
| 207 |
+
method : {'vasicek', 'van es', 'ebrahimi', 'correa', 'auto'}, optional
|
| 208 |
+
The method used to estimate the differential entropy from the sample.
|
| 209 |
+
Default is ``'auto'``. See Notes for more information.
|
| 210 |
+
|
| 211 |
+
Returns
|
| 212 |
+
-------
|
| 213 |
+
entropy : float
|
| 214 |
+
The calculated differential entropy.
|
| 215 |
+
|
| 216 |
+
Notes
|
| 217 |
+
-----
|
| 218 |
+
This function will converge to the true differential entropy in the limit
|
| 219 |
+
|
| 220 |
+
.. math::
|
| 221 |
+
n \to \infty, \quad m \to \infty, \quad \frac{m}{n} \to 0
|
| 222 |
+
|
| 223 |
+
The optimal choice of ``window_length`` for a given sample size depends on
|
| 224 |
+
the (unknown) distribution. Typically, the smoother the density of the
|
| 225 |
+
distribution, the larger the optimal value of ``window_length`` [1]_.
|
| 226 |
+
|
| 227 |
+
The following options are available for the `method` parameter.
|
| 228 |
+
|
| 229 |
+
* ``'vasicek'`` uses the estimator presented in [1]_. This is
|
| 230 |
+
one of the first and most influential estimators of differential entropy.
|
| 231 |
+
* ``'van es'`` uses the bias-corrected estimator presented in [3]_, which
|
| 232 |
+
is not only consistent but, under some conditions, asymptotically normal.
|
| 233 |
+
* ``'ebrahimi'`` uses an estimator presented in [4]_, which was shown
|
| 234 |
+
in simulation to have smaller bias and mean squared error than
|
| 235 |
+
the Vasicek estimator.
|
| 236 |
+
* ``'correa'`` uses the estimator presented in [5]_ based on local linear
|
| 237 |
+
regression. In a simulation study, it had consistently smaller mean
|
| 238 |
+
square error than the Vasiceck estimator, but it is more expensive to
|
| 239 |
+
compute.
|
| 240 |
+
* ``'auto'`` selects the method automatically (default). Currently,
|
| 241 |
+
this selects ``'van es'`` for very small samples (<10), ``'ebrahimi'``
|
| 242 |
+
for moderate sample sizes (11-1000), and ``'vasicek'`` for larger
|
| 243 |
+
samples, but this behavior is subject to change in future versions.
|
| 244 |
+
|
| 245 |
+
All estimators are implemented as described in [6]_.
|
| 246 |
+
|
| 247 |
+
References
|
| 248 |
+
----------
|
| 249 |
+
.. [1] Vasicek, O. (1976). A test for normality based on sample entropy.
|
| 250 |
+
Journal of the Royal Statistical Society:
|
| 251 |
+
Series B (Methodological), 38(1), 54-59.
|
| 252 |
+
.. [2] Crzcgorzewski, P., & Wirczorkowski, R. (1999). Entropy-based
|
| 253 |
+
goodness-of-fit test for exponentiality. Communications in
|
| 254 |
+
Statistics-Theory and Methods, 28(5), 1183-1202.
|
| 255 |
+
.. [3] Van Es, B. (1992). Estimating functionals related to a density by a
|
| 256 |
+
class of statistics based on spacings. Scandinavian Journal of
|
| 257 |
+
Statistics, 61-72.
|
| 258 |
+
.. [4] Ebrahimi, N., Pflughoeft, K., & Soofi, E. S. (1994). Two measures
|
| 259 |
+
of sample entropy. Statistics & Probability Letters, 20(3), 225-234.
|
| 260 |
+
.. [5] Correa, J. C. (1995). A new estimator of entropy. Communications
|
| 261 |
+
in Statistics-Theory and Methods, 24(10), 2439-2449.
|
| 262 |
+
.. [6] Noughabi, H. A. (2015). Entropy Estimation Using Numerical Methods.
|
| 263 |
+
Annals of Data Science, 2(2), 231-241.
|
| 264 |
+
https://link.springer.com/article/10.1007/s40745-015-0045-9
|
| 265 |
+
|
| 266 |
+
Examples
|
| 267 |
+
--------
|
| 268 |
+
>>> import numpy as np
|
| 269 |
+
>>> from scipy.stats import differential_entropy, norm
|
| 270 |
+
|
| 271 |
+
Entropy of a standard normal distribution:
|
| 272 |
+
|
| 273 |
+
>>> rng = np.random.default_rng()
|
| 274 |
+
>>> values = rng.standard_normal(100)
|
| 275 |
+
>>> differential_entropy(values)
|
| 276 |
+
1.3407817436640392
|
| 277 |
+
|
| 278 |
+
Compare with the true entropy:
|
| 279 |
+
|
| 280 |
+
>>> float(norm.entropy())
|
| 281 |
+
1.4189385332046727
|
| 282 |
+
|
| 283 |
+
For several sample sizes between 5 and 1000, compare the accuracy of
|
| 284 |
+
the ``'vasicek'``, ``'van es'``, and ``'ebrahimi'`` methods. Specifically,
|
| 285 |
+
compare the root mean squared error (over 1000 trials) between the estimate
|
| 286 |
+
and the true differential entropy of the distribution.
|
| 287 |
+
|
| 288 |
+
>>> from scipy import stats
|
| 289 |
+
>>> import matplotlib.pyplot as plt
|
| 290 |
+
>>>
|
| 291 |
+
>>>
|
| 292 |
+
>>> def rmse(res, expected):
|
| 293 |
+
... '''Root mean squared error'''
|
| 294 |
+
... return np.sqrt(np.mean((res - expected)**2))
|
| 295 |
+
>>>
|
| 296 |
+
>>>
|
| 297 |
+
>>> a, b = np.log10(5), np.log10(1000)
|
| 298 |
+
>>> ns = np.round(np.logspace(a, b, 10)).astype(int)
|
| 299 |
+
>>> reps = 1000 # number of repetitions for each sample size
|
| 300 |
+
>>> expected = stats.expon.entropy()
|
| 301 |
+
>>>
|
| 302 |
+
>>> method_errors = {'vasicek': [], 'van es': [], 'ebrahimi': []}
|
| 303 |
+
>>> for method in method_errors:
|
| 304 |
+
... for n in ns:
|
| 305 |
+
... rvs = stats.expon.rvs(size=(reps, n), random_state=rng)
|
| 306 |
+
... res = stats.differential_entropy(rvs, method=method, axis=-1)
|
| 307 |
+
... error = rmse(res, expected)
|
| 308 |
+
... method_errors[method].append(error)
|
| 309 |
+
>>>
|
| 310 |
+
>>> for method, errors in method_errors.items():
|
| 311 |
+
... plt.loglog(ns, errors, label=method)
|
| 312 |
+
>>>
|
| 313 |
+
>>> plt.legend()
|
| 314 |
+
>>> plt.xlabel('sample size')
|
| 315 |
+
>>> plt.ylabel('RMSE (1000 trials)')
|
| 316 |
+
>>> plt.title('Entropy Estimator Error (Exponential Distribution)')
|
| 317 |
+
|
| 318 |
+
"""
|
| 319 |
+
xp = array_namespace(values)
|
| 320 |
+
values = xp.asarray(values)
|
| 321 |
+
if xp.isdtype(values.dtype, "integral"): # type: ignore[union-attr]
|
| 322 |
+
values = xp.astype(values, xp.asarray(1.).dtype)
|
| 323 |
+
values = xp_moveaxis_to_end(values, axis, xp=xp)
|
| 324 |
+
n = values.shape[-1] # type: ignore[union-attr]
|
| 325 |
+
|
| 326 |
+
if window_length is None:
|
| 327 |
+
window_length = math.floor(math.sqrt(n) + 0.5)
|
| 328 |
+
|
| 329 |
+
if not 2 <= 2 * window_length < n:
|
| 330 |
+
raise ValueError(
|
| 331 |
+
f"Window length ({window_length}) must be positive and less "
|
| 332 |
+
f"than half the sample size ({n}).",
|
| 333 |
+
)
|
| 334 |
+
|
| 335 |
+
if base is not None and base <= 0:
|
| 336 |
+
raise ValueError("`base` must be a positive number or `None`.")
|
| 337 |
+
|
| 338 |
+
sorted_data = xp.sort(values, axis=-1)
|
| 339 |
+
|
| 340 |
+
methods = {"vasicek": _vasicek_entropy,
|
| 341 |
+
"van es": _van_es_entropy,
|
| 342 |
+
"correa": _correa_entropy,
|
| 343 |
+
"ebrahimi": _ebrahimi_entropy,
|
| 344 |
+
"auto": _vasicek_entropy}
|
| 345 |
+
method = method.lower()
|
| 346 |
+
if method not in methods:
|
| 347 |
+
message = f"`method` must be one of {set(methods)}"
|
| 348 |
+
raise ValueError(message)
|
| 349 |
+
|
| 350 |
+
if method == "auto":
|
| 351 |
+
if n <= 10:
|
| 352 |
+
method = 'van es'
|
| 353 |
+
elif n <= 1000:
|
| 354 |
+
method = 'ebrahimi'
|
| 355 |
+
else:
|
| 356 |
+
method = 'vasicek'
|
| 357 |
+
|
| 358 |
+
res = methods[method](sorted_data, window_length, xp=xp)
|
| 359 |
+
|
| 360 |
+
if base is not None:
|
| 361 |
+
res /= math.log(base)
|
| 362 |
+
|
| 363 |
+
# avoid dtype changes due to data-apis/array-api-compat#152
|
| 364 |
+
# can be removed when data-apis/array-api-compat#152 is resolved
|
| 365 |
+
return xp.astype(res, values.dtype) # type: ignore[union-attr]
|
| 366 |
+
|
| 367 |
+
|
| 368 |
+
def _pad_along_last_axis(X, m, *, xp):
|
| 369 |
+
"""Pad the data for computing the rolling window difference."""
|
| 370 |
+
# scales a bit better than method in _vasicek_like_entropy
|
| 371 |
+
shape = X.shape[:-1] + (m,)
|
| 372 |
+
Xl = xp.broadcast_to(X[..., :1], shape) # :1 vs 0 to maintain shape
|
| 373 |
+
Xr = xp.broadcast_to(X[..., -1:], shape)
|
| 374 |
+
return xp.concat((Xl, X, Xr), axis=-1)
|
| 375 |
+
|
| 376 |
+
|
| 377 |
+
def _vasicek_entropy(X, m, *, xp):
|
| 378 |
+
"""Compute the Vasicek estimator as described in [6] Eq. 1.3."""
|
| 379 |
+
n = X.shape[-1]
|
| 380 |
+
X = _pad_along_last_axis(X, m, xp=xp)
|
| 381 |
+
differences = X[..., 2 * m:] - X[..., : -2 * m:]
|
| 382 |
+
logs = xp.log(n/(2*m) * differences)
|
| 383 |
+
return xp.mean(logs, axis=-1)
|
| 384 |
+
|
| 385 |
+
|
| 386 |
+
def _van_es_entropy(X, m, *, xp):
|
| 387 |
+
"""Compute the van Es estimator as described in [6]."""
|
| 388 |
+
# No equation number, but referred to as HVE_mn.
|
| 389 |
+
# Typo: there should be a log within the summation.
|
| 390 |
+
n = X.shape[-1]
|
| 391 |
+
difference = X[..., m:] - X[..., :-m]
|
| 392 |
+
term1 = 1/(n-m) * xp.sum(xp.log((n+1)/m * difference), axis=-1)
|
| 393 |
+
k = xp.arange(m, n+1, dtype=term1.dtype)
|
| 394 |
+
return term1 + xp.sum(1/k) + math.log(m) - math.log(n+1)
|
| 395 |
+
|
| 396 |
+
|
| 397 |
+
def _ebrahimi_entropy(X, m, *, xp):
|
| 398 |
+
"""Compute the Ebrahimi estimator as described in [6]."""
|
| 399 |
+
# No equation number, but referred to as HE_mn
|
| 400 |
+
n = X.shape[-1]
|
| 401 |
+
X = _pad_along_last_axis(X, m, xp=xp)
|
| 402 |
+
|
| 403 |
+
differences = X[..., 2 * m:] - X[..., : -2 * m:]
|
| 404 |
+
|
| 405 |
+
i = xp.arange(1, n+1, dtype=X.dtype)
|
| 406 |
+
ci = xp.ones_like(i)*2
|
| 407 |
+
ci[i <= m] = 1 + (i[i <= m] - 1)/m
|
| 408 |
+
ci[i >= n - m + 1] = 1 + (n - i[i >= n-m+1])/m
|
| 409 |
+
|
| 410 |
+
logs = xp.log(n * differences / (ci * m))
|
| 411 |
+
return xp.mean(logs, axis=-1)
|
| 412 |
+
|
| 413 |
+
|
| 414 |
+
def _correa_entropy(X, m, *, xp):
|
| 415 |
+
"""Compute the Correa estimator as described in [6]."""
|
| 416 |
+
# No equation number, but referred to as HC_mn
|
| 417 |
+
n = X.shape[-1]
|
| 418 |
+
X = _pad_along_last_axis(X, m, xp=xp)
|
| 419 |
+
|
| 420 |
+
i = xp.arange(1, n+1)
|
| 421 |
+
dj = xp.arange(-m, m+1)[:, None]
|
| 422 |
+
j = i + dj
|
| 423 |
+
j0 = j + m - 1 # 0-indexed version of j
|
| 424 |
+
|
| 425 |
+
Xibar = xp.mean(X[..., j0], axis=-2, keepdims=True)
|
| 426 |
+
difference = X[..., j0] - Xibar
|
| 427 |
+
num = xp.sum(difference*dj, axis=-2) # dj is d-i
|
| 428 |
+
den = n*xp.sum(difference**2, axis=-2)
|
| 429 |
+
return -xp.mean(xp.log(num/den), axis=-1)
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/scipy/stats/_fit.py
ADDED
|
@@ -0,0 +1,1351 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import warnings
|
| 2 |
+
from collections import namedtuple
|
| 3 |
+
import numpy as np
|
| 4 |
+
from scipy import optimize, stats
|
| 5 |
+
from scipy._lib._util import check_random_state, _transition_to_rng
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def _combine_bounds(name, user_bounds, shape_domain, integral):
|
| 9 |
+
"""Intersection of user-defined bounds and distribution PDF/PMF domain"""
|
| 10 |
+
|
| 11 |
+
user_bounds = np.atleast_1d(user_bounds)
|
| 12 |
+
|
| 13 |
+
if user_bounds[0] > user_bounds[1]:
|
| 14 |
+
message = (f"There are no values for `{name}` on the interval "
|
| 15 |
+
f"{list(user_bounds)}.")
|
| 16 |
+
raise ValueError(message)
|
| 17 |
+
|
| 18 |
+
bounds = (max(user_bounds[0], shape_domain[0]),
|
| 19 |
+
min(user_bounds[1], shape_domain[1]))
|
| 20 |
+
|
| 21 |
+
if integral and (np.ceil(bounds[0]) > np.floor(bounds[1])):
|
| 22 |
+
message = (f"There are no integer values for `{name}` on the interval "
|
| 23 |
+
f"defined by the user-provided bounds and the domain "
|
| 24 |
+
"of the distribution.")
|
| 25 |
+
raise ValueError(message)
|
| 26 |
+
elif not integral and (bounds[0] > bounds[1]):
|
| 27 |
+
message = (f"There are no values for `{name}` on the interval "
|
| 28 |
+
f"defined by the user-provided bounds and the domain "
|
| 29 |
+
"of the distribution.")
|
| 30 |
+
raise ValueError(message)
|
| 31 |
+
|
| 32 |
+
if not np.all(np.isfinite(bounds)):
|
| 33 |
+
message = (f"The intersection of user-provided bounds for `{name}` "
|
| 34 |
+
f"and the domain of the distribution is not finite. Please "
|
| 35 |
+
f"provide finite bounds for shape `{name}` in `bounds`.")
|
| 36 |
+
raise ValueError(message)
|
| 37 |
+
|
| 38 |
+
return bounds
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
class FitResult:
|
| 42 |
+
r"""Result of fitting a discrete or continuous distribution to data
|
| 43 |
+
|
| 44 |
+
Attributes
|
| 45 |
+
----------
|
| 46 |
+
params : namedtuple
|
| 47 |
+
A namedtuple containing the maximum likelihood estimates of the
|
| 48 |
+
shape parameters, location, and (if applicable) scale of the
|
| 49 |
+
distribution.
|
| 50 |
+
success : bool or None
|
| 51 |
+
Whether the optimizer considered the optimization to terminate
|
| 52 |
+
successfully or not.
|
| 53 |
+
message : str or None
|
| 54 |
+
Any status message provided by the optimizer.
|
| 55 |
+
|
| 56 |
+
"""
|
| 57 |
+
|
| 58 |
+
def __init__(self, dist, data, discrete, res):
|
| 59 |
+
self._dist = dist
|
| 60 |
+
self._data = data
|
| 61 |
+
self.discrete = discrete
|
| 62 |
+
self.pxf = getattr(dist, "pmf", None) or getattr(dist, "pdf", None)
|
| 63 |
+
|
| 64 |
+
shape_names = [] if dist.shapes is None else dist.shapes.split(", ")
|
| 65 |
+
if not discrete:
|
| 66 |
+
FitParams = namedtuple('FitParams', shape_names + ['loc', 'scale'])
|
| 67 |
+
else:
|
| 68 |
+
FitParams = namedtuple('FitParams', shape_names + ['loc'])
|
| 69 |
+
|
| 70 |
+
self.params = FitParams(*res.x)
|
| 71 |
+
|
| 72 |
+
# Optimizer can report success even when nllf is infinite
|
| 73 |
+
if res.success and not np.isfinite(self.nllf()):
|
| 74 |
+
res.success = False
|
| 75 |
+
res.message = ("Optimization converged to parameter values that "
|
| 76 |
+
"are inconsistent with the data.")
|
| 77 |
+
self.success = getattr(res, "success", None)
|
| 78 |
+
self.message = getattr(res, "message", None)
|
| 79 |
+
|
| 80 |
+
def __repr__(self):
|
| 81 |
+
keys = ["params", "success", "message"]
|
| 82 |
+
m = max(map(len, keys)) + 1
|
| 83 |
+
return '\n'.join([key.rjust(m) + ': ' + repr(getattr(self, key))
|
| 84 |
+
for key in keys if getattr(self, key) is not None])
|
| 85 |
+
|
| 86 |
+
def nllf(self, params=None, data=None):
|
| 87 |
+
"""Negative log-likelihood function
|
| 88 |
+
|
| 89 |
+
Evaluates the negative of the log-likelihood function of the provided
|
| 90 |
+
data at the provided parameters.
|
| 91 |
+
|
| 92 |
+
Parameters
|
| 93 |
+
----------
|
| 94 |
+
params : tuple, optional
|
| 95 |
+
The shape parameters, location, and (if applicable) scale of the
|
| 96 |
+
distribution as a single tuple. Default is the maximum likelihood
|
| 97 |
+
estimates (``self.params``).
|
| 98 |
+
data : array_like, optional
|
| 99 |
+
The data for which the log-likelihood function is to be evaluated.
|
| 100 |
+
Default is the data to which the distribution was fit.
|
| 101 |
+
|
| 102 |
+
Returns
|
| 103 |
+
-------
|
| 104 |
+
nllf : float
|
| 105 |
+
The negative of the log-likelihood function.
|
| 106 |
+
|
| 107 |
+
"""
|
| 108 |
+
params = params if params is not None else self.params
|
| 109 |
+
data = data if data is not None else self._data
|
| 110 |
+
return self._dist.nnlf(theta=params, x=data)
|
| 111 |
+
|
| 112 |
+
def plot(self, ax=None, *, plot_type="hist"):
|
| 113 |
+
"""Visually compare the data against the fitted distribution.
|
| 114 |
+
|
| 115 |
+
Available only if `matplotlib` is installed.
|
| 116 |
+
|
| 117 |
+
Parameters
|
| 118 |
+
----------
|
| 119 |
+
ax : `matplotlib.axes.Axes`
|
| 120 |
+
Axes object to draw the plot onto, otherwise uses the current Axes.
|
| 121 |
+
plot_type : {"hist", "qq", "pp", "cdf"}
|
| 122 |
+
Type of plot to draw. Options include:
|
| 123 |
+
|
| 124 |
+
- "hist": Superposes the PDF/PMF of the fitted distribution
|
| 125 |
+
over a normalized histogram of the data.
|
| 126 |
+
- "qq": Scatter plot of theoretical quantiles against the
|
| 127 |
+
empirical quantiles. Specifically, the x-coordinates are the
|
| 128 |
+
values of the fitted distribution PPF evaluated at the
|
| 129 |
+
percentiles ``(np.arange(1, n) - 0.5)/n``, where ``n`` is the
|
| 130 |
+
number of data points, and the y-coordinates are the sorted
|
| 131 |
+
data points.
|
| 132 |
+
- "pp": Scatter plot of theoretical percentiles against the
|
| 133 |
+
observed percentiles. Specifically, the x-coordinates are the
|
| 134 |
+
percentiles ``(np.arange(1, n) - 0.5)/n``, where ``n`` is
|
| 135 |
+
the number of data points, and the y-coordinates are the values
|
| 136 |
+
of the fitted distribution CDF evaluated at the sorted
|
| 137 |
+
data points.
|
| 138 |
+
- "cdf": Superposes the CDF of the fitted distribution over the
|
| 139 |
+
empirical CDF. Specifically, the x-coordinates of the empirical
|
| 140 |
+
CDF are the sorted data points, and the y-coordinates are the
|
| 141 |
+
percentiles ``(np.arange(1, n) - 0.5)/n``, where ``n`` is
|
| 142 |
+
the number of data points.
|
| 143 |
+
|
| 144 |
+
Returns
|
| 145 |
+
-------
|
| 146 |
+
ax : `matplotlib.axes.Axes`
|
| 147 |
+
The matplotlib Axes object on which the plot was drawn.
|
| 148 |
+
|
| 149 |
+
Examples
|
| 150 |
+
--------
|
| 151 |
+
>>> import numpy as np
|
| 152 |
+
>>> from scipy import stats
|
| 153 |
+
>>> import matplotlib.pyplot as plt # matplotlib must be installed
|
| 154 |
+
>>> rng = np.random.default_rng()
|
| 155 |
+
>>> data = stats.nbinom(5, 0.5).rvs(size=1000, random_state=rng)
|
| 156 |
+
>>> bounds = [(0, 30), (0, 1)]
|
| 157 |
+
>>> res = stats.fit(stats.nbinom, data, bounds)
|
| 158 |
+
>>> ax = res.plot() # save matplotlib Axes object
|
| 159 |
+
|
| 160 |
+
The `matplotlib.axes.Axes` object can be used to customize the plot.
|
| 161 |
+
See `matplotlib.axes.Axes` documentation for details.
|
| 162 |
+
|
| 163 |
+
>>> ax.set_xlabel('number of trials') # customize axis label
|
| 164 |
+
>>> ax.get_children()[0].set_linewidth(5) # customize line widths
|
| 165 |
+
>>> ax.legend()
|
| 166 |
+
>>> plt.show()
|
| 167 |
+
"""
|
| 168 |
+
try:
|
| 169 |
+
import matplotlib # noqa: F401
|
| 170 |
+
except ModuleNotFoundError as exc:
|
| 171 |
+
message = "matplotlib must be installed to use method `plot`."
|
| 172 |
+
raise ModuleNotFoundError(message) from exc
|
| 173 |
+
|
| 174 |
+
plots = {'histogram': self._hist_plot, 'qq': self._qq_plot,
|
| 175 |
+
'pp': self._pp_plot, 'cdf': self._cdf_plot,
|
| 176 |
+
'hist': self._hist_plot}
|
| 177 |
+
if plot_type.lower() not in plots:
|
| 178 |
+
message = f"`plot_type` must be one of {set(plots.keys())}"
|
| 179 |
+
raise ValueError(message)
|
| 180 |
+
plot = plots[plot_type.lower()]
|
| 181 |
+
|
| 182 |
+
if ax is None:
|
| 183 |
+
import matplotlib.pyplot as plt
|
| 184 |
+
ax = plt.gca()
|
| 185 |
+
|
| 186 |
+
fit_params = np.atleast_1d(self.params)
|
| 187 |
+
|
| 188 |
+
return plot(ax=ax, fit_params=fit_params)
|
| 189 |
+
|
| 190 |
+
def _hist_plot(self, ax, fit_params):
|
| 191 |
+
from matplotlib.ticker import MaxNLocator
|
| 192 |
+
|
| 193 |
+
support = self._dist.support(*fit_params)
|
| 194 |
+
lb = support[0] if np.isfinite(support[0]) else min(self._data)
|
| 195 |
+
ub = support[1] if np.isfinite(support[1]) else max(self._data)
|
| 196 |
+
pxf = "PMF" if self.discrete else "PDF"
|
| 197 |
+
|
| 198 |
+
if self.discrete:
|
| 199 |
+
x = np.arange(lb, ub + 2)
|
| 200 |
+
y = self.pxf(x, *fit_params)
|
| 201 |
+
ax.vlines(x[:-1], 0, y[:-1], label='Fitted Distribution PMF',
|
| 202 |
+
color='C0')
|
| 203 |
+
options = dict(density=True, bins=x, align='left', color='C1')
|
| 204 |
+
ax.xaxis.set_major_locator(MaxNLocator(integer=True))
|
| 205 |
+
ax.set_xlabel('k')
|
| 206 |
+
ax.set_ylabel('PMF')
|
| 207 |
+
else:
|
| 208 |
+
x = np.linspace(lb, ub, 200)
|
| 209 |
+
y = self.pxf(x, *fit_params)
|
| 210 |
+
ax.plot(x, y, '--', label='Fitted Distribution PDF', color='C0')
|
| 211 |
+
options = dict(density=True, bins=50, align='mid', color='C1')
|
| 212 |
+
ax.set_xlabel('x')
|
| 213 |
+
ax.set_ylabel('PDF')
|
| 214 |
+
|
| 215 |
+
if len(self._data) > 50 or self.discrete:
|
| 216 |
+
ax.hist(self._data, label="Histogram of Data", **options)
|
| 217 |
+
else:
|
| 218 |
+
ax.plot(self._data, np.zeros_like(self._data), "*",
|
| 219 |
+
label='Data', color='C1')
|
| 220 |
+
|
| 221 |
+
ax.set_title(rf"Fitted $\tt {self._dist.name}$ {pxf} and Histogram")
|
| 222 |
+
ax.legend(*ax.get_legend_handles_labels())
|
| 223 |
+
return ax
|
| 224 |
+
|
| 225 |
+
def _qp_plot(self, ax, fit_params, qq):
|
| 226 |
+
data = np.sort(self._data)
|
| 227 |
+
ps = self._plotting_positions(len(self._data))
|
| 228 |
+
|
| 229 |
+
if qq:
|
| 230 |
+
qp = "Quantiles"
|
| 231 |
+
plot_type = 'Q-Q'
|
| 232 |
+
x = self._dist.ppf(ps, *fit_params)
|
| 233 |
+
y = data
|
| 234 |
+
else:
|
| 235 |
+
qp = "Percentiles"
|
| 236 |
+
plot_type = 'P-P'
|
| 237 |
+
x = ps
|
| 238 |
+
y = self._dist.cdf(data, *fit_params)
|
| 239 |
+
|
| 240 |
+
ax.plot(x, y, '.', label=f'Fitted Distribution {plot_type}',
|
| 241 |
+
color='C0', zorder=1)
|
| 242 |
+
xlim = ax.get_xlim()
|
| 243 |
+
ylim = ax.get_ylim()
|
| 244 |
+
lim = [min(xlim[0], ylim[0]), max(xlim[1], ylim[1])]
|
| 245 |
+
if not qq:
|
| 246 |
+
lim = max(lim[0], 0), min(lim[1], 1)
|
| 247 |
+
|
| 248 |
+
if self.discrete and qq:
|
| 249 |
+
q_min, q_max = int(lim[0]), int(lim[1]+1)
|
| 250 |
+
q_ideal = np.arange(q_min, q_max)
|
| 251 |
+
# q_ideal = np.unique(self._dist.ppf(ps, *fit_params))
|
| 252 |
+
ax.plot(q_ideal, q_ideal, 'o', label='Reference', color='k',
|
| 253 |
+
alpha=0.25, markerfacecolor='none', clip_on=True)
|
| 254 |
+
elif self.discrete and not qq:
|
| 255 |
+
# The intent of this is to match the plot that would be produced
|
| 256 |
+
# if x were continuous on [0, 1] and y were cdf(ppf(x)).
|
| 257 |
+
# It can be approximated by letting x = np.linspace(0, 1, 1000),
|
| 258 |
+
# but this might not look great when zooming in. The vertical
|
| 259 |
+
# portions are included to indicate where the transition occurs
|
| 260 |
+
# where the data completely obscures the horizontal portions.
|
| 261 |
+
p_min, p_max = lim
|
| 262 |
+
a, b = self._dist.support(*fit_params)
|
| 263 |
+
p_min = max(p_min, 0 if np.isfinite(a) else 1e-3)
|
| 264 |
+
p_max = min(p_max, 1 if np.isfinite(b) else 1-1e-3)
|
| 265 |
+
q_min, q_max = self._dist.ppf([p_min, p_max], *fit_params)
|
| 266 |
+
qs = np.arange(q_min-1, q_max+1)
|
| 267 |
+
ps = self._dist.cdf(qs, *fit_params)
|
| 268 |
+
ax.step(ps, ps, '-', label='Reference', color='k', alpha=0.25,
|
| 269 |
+
clip_on=True)
|
| 270 |
+
else:
|
| 271 |
+
ax.plot(lim, lim, '-', label='Reference', color='k', alpha=0.25,
|
| 272 |
+
clip_on=True)
|
| 273 |
+
|
| 274 |
+
ax.set_xlim(lim)
|
| 275 |
+
ax.set_ylim(lim)
|
| 276 |
+
ax.set_xlabel(rf"Fitted $\tt {self._dist.name}$ Theoretical {qp}")
|
| 277 |
+
ax.set_ylabel(f"Data {qp}")
|
| 278 |
+
ax.set_title(rf"Fitted $\tt {self._dist.name}$ {plot_type} Plot")
|
| 279 |
+
ax.legend(*ax.get_legend_handles_labels())
|
| 280 |
+
ax.set_aspect('equal')
|
| 281 |
+
return ax
|
| 282 |
+
|
| 283 |
+
def _qq_plot(self, **kwargs):
|
| 284 |
+
return self._qp_plot(qq=True, **kwargs)
|
| 285 |
+
|
| 286 |
+
def _pp_plot(self, **kwargs):
|
| 287 |
+
return self._qp_plot(qq=False, **kwargs)
|
| 288 |
+
|
| 289 |
+
def _plotting_positions(self, n, a=.5):
|
| 290 |
+
# See https://en.wikipedia.org/wiki/Q%E2%80%93Q_plot#Plotting_positions
|
| 291 |
+
k = np.arange(1, n+1)
|
| 292 |
+
return (k-a) / (n + 1 - 2*a)
|
| 293 |
+
|
| 294 |
+
def _cdf_plot(self, ax, fit_params):
|
| 295 |
+
data = np.sort(self._data)
|
| 296 |
+
ecdf = self._plotting_positions(len(self._data))
|
| 297 |
+
ls = '--' if len(np.unique(data)) < 30 else '.'
|
| 298 |
+
xlabel = 'k' if self.discrete else 'x'
|
| 299 |
+
ax.step(data, ecdf, ls, label='Empirical CDF', color='C1', zorder=0)
|
| 300 |
+
|
| 301 |
+
xlim = ax.get_xlim()
|
| 302 |
+
q = np.linspace(*xlim, 300)
|
| 303 |
+
tcdf = self._dist.cdf(q, *fit_params)
|
| 304 |
+
|
| 305 |
+
ax.plot(q, tcdf, label='Fitted Distribution CDF', color='C0', zorder=1)
|
| 306 |
+
ax.set_xlim(xlim)
|
| 307 |
+
ax.set_ylim(0, 1)
|
| 308 |
+
ax.set_xlabel(xlabel)
|
| 309 |
+
ax.set_ylabel("CDF")
|
| 310 |
+
ax.set_title(rf"Fitted $\tt {self._dist.name}$ and Empirical CDF")
|
| 311 |
+
handles, labels = ax.get_legend_handles_labels()
|
| 312 |
+
ax.legend(handles[::-1], labels[::-1])
|
| 313 |
+
return ax
|
| 314 |
+
|
| 315 |
+
|
| 316 |
+
def fit(dist, data, bounds=None, *, guess=None, method='mle',
|
| 317 |
+
optimizer=optimize.differential_evolution):
|
| 318 |
+
r"""Fit a discrete or continuous distribution to data
|
| 319 |
+
|
| 320 |
+
Given a distribution, data, and bounds on the parameters of the
|
| 321 |
+
distribution, return maximum likelihood estimates of the parameters.
|
| 322 |
+
|
| 323 |
+
Parameters
|
| 324 |
+
----------
|
| 325 |
+
dist : `scipy.stats.rv_continuous` or `scipy.stats.rv_discrete`
|
| 326 |
+
The object representing the distribution to be fit to the data.
|
| 327 |
+
data : 1D array_like
|
| 328 |
+
The data to which the distribution is to be fit. If the data contain
|
| 329 |
+
any of ``np.nan``, ``np.inf``, or -``np.inf``, the fit method will
|
| 330 |
+
raise a ``ValueError``.
|
| 331 |
+
bounds : dict or sequence of tuples, optional
|
| 332 |
+
If a dictionary, each key is the name of a parameter of the
|
| 333 |
+
distribution, and the corresponding value is a tuple containing the
|
| 334 |
+
lower and upper bound on that parameter. If the distribution is
|
| 335 |
+
defined only for a finite range of values of that parameter, no entry
|
| 336 |
+
for that parameter is required; e.g., some distributions have
|
| 337 |
+
parameters which must be on the interval [0, 1]. Bounds for parameters
|
| 338 |
+
location (``loc``) and scale (``scale``) are optional; by default,
|
| 339 |
+
they are fixed to 0 and 1, respectively.
|
| 340 |
+
|
| 341 |
+
If a sequence, element *i* is a tuple containing the lower and upper
|
| 342 |
+
bound on the *i*\ th parameter of the distribution. In this case,
|
| 343 |
+
bounds for *all* distribution shape parameters must be provided.
|
| 344 |
+
Optionally, bounds for location and scale may follow the
|
| 345 |
+
distribution shape parameters.
|
| 346 |
+
|
| 347 |
+
If a shape is to be held fixed (e.g. if it is known), the
|
| 348 |
+
lower and upper bounds may be equal. If a user-provided lower or upper
|
| 349 |
+
bound is beyond a bound of the domain for which the distribution is
|
| 350 |
+
defined, the bound of the distribution's domain will replace the
|
| 351 |
+
user-provided value. Similarly, parameters which must be integral
|
| 352 |
+
will be constrained to integral values within the user-provided bounds.
|
| 353 |
+
guess : dict or array_like, optional
|
| 354 |
+
If a dictionary, each key is the name of a parameter of the
|
| 355 |
+
distribution, and the corresponding value is a guess for the value
|
| 356 |
+
of the parameter.
|
| 357 |
+
|
| 358 |
+
If a sequence, element *i* is a guess for the *i*\ th parameter of the
|
| 359 |
+
distribution. In this case, guesses for *all* distribution shape
|
| 360 |
+
parameters must be provided.
|
| 361 |
+
|
| 362 |
+
If `guess` is not provided, guesses for the decision variables will
|
| 363 |
+
not be passed to the optimizer. If `guess` is provided, guesses for
|
| 364 |
+
any missing parameters will be set at the mean of the lower and
|
| 365 |
+
upper bounds. Guesses for parameters which must be integral will be
|
| 366 |
+
rounded to integral values, and guesses that lie outside the
|
| 367 |
+
intersection of the user-provided bounds and the domain of the
|
| 368 |
+
distribution will be clipped.
|
| 369 |
+
method : {'mle', 'mse'}
|
| 370 |
+
With ``method="mle"`` (default), the fit is computed by minimizing
|
| 371 |
+
the negative log-likelihood function. A large, finite penalty
|
| 372 |
+
(rather than infinite negative log-likelihood) is applied for
|
| 373 |
+
observations beyond the support of the distribution.
|
| 374 |
+
With ``method="mse"``, the fit is computed by minimizing
|
| 375 |
+
the negative log-product spacing function. The same penalty is applied
|
| 376 |
+
for observations beyond the support. We follow the approach of [1]_,
|
| 377 |
+
which is generalized for samples with repeated observations.
|
| 378 |
+
optimizer : callable, optional
|
| 379 |
+
`optimizer` is a callable that accepts the following positional
|
| 380 |
+
argument.
|
| 381 |
+
|
| 382 |
+
fun : callable
|
| 383 |
+
The objective function to be optimized. `fun` accepts one argument
|
| 384 |
+
``x``, candidate shape parameters of the distribution, and returns
|
| 385 |
+
the objective function value given ``x``, `dist`, and the provided
|
| 386 |
+
`data`.
|
| 387 |
+
The job of `optimizer` is to find values of the decision variables
|
| 388 |
+
that minimizes `fun`.
|
| 389 |
+
|
| 390 |
+
`optimizer` must also accept the following keyword argument.
|
| 391 |
+
|
| 392 |
+
bounds : sequence of tuples
|
| 393 |
+
The bounds on values of the decision variables; each element will
|
| 394 |
+
be a tuple containing the lower and upper bound on a decision
|
| 395 |
+
variable.
|
| 396 |
+
|
| 397 |
+
If `guess` is provided, `optimizer` must also accept the following
|
| 398 |
+
keyword argument.
|
| 399 |
+
|
| 400 |
+
x0 : array_like
|
| 401 |
+
The guesses for each decision variable.
|
| 402 |
+
|
| 403 |
+
If the distribution has any shape parameters that must be integral or
|
| 404 |
+
if the distribution is discrete and the location parameter is not
|
| 405 |
+
fixed, `optimizer` must also accept the following keyword argument.
|
| 406 |
+
|
| 407 |
+
integrality : array_like of bools
|
| 408 |
+
For each decision variable, True if the decision variable
|
| 409 |
+
must be constrained to integer values and False if the decision
|
| 410 |
+
variable is continuous.
|
| 411 |
+
|
| 412 |
+
`optimizer` must return an object, such as an instance of
|
| 413 |
+
`scipy.optimize.OptimizeResult`, which holds the optimal values of
|
| 414 |
+
the decision variables in an attribute ``x``. If attributes
|
| 415 |
+
``fun``, ``status``, or ``message`` are provided, they will be
|
| 416 |
+
included in the result object returned by `fit`.
|
| 417 |
+
|
| 418 |
+
Returns
|
| 419 |
+
-------
|
| 420 |
+
result : `~scipy.stats._result_classes.FitResult`
|
| 421 |
+
An object with the following fields.
|
| 422 |
+
|
| 423 |
+
params : namedtuple
|
| 424 |
+
A namedtuple containing the maximum likelihood estimates of the
|
| 425 |
+
shape parameters, location, and (if applicable) scale of the
|
| 426 |
+
distribution.
|
| 427 |
+
success : bool or None
|
| 428 |
+
Whether the optimizer considered the optimization to terminate
|
| 429 |
+
successfully or not.
|
| 430 |
+
message : str or None
|
| 431 |
+
Any status message provided by the optimizer.
|
| 432 |
+
|
| 433 |
+
The object has the following method:
|
| 434 |
+
|
| 435 |
+
nllf(params=None, data=None)
|
| 436 |
+
By default, the negative log-likelihood function at the fitted
|
| 437 |
+
`params` for the given `data`. Accepts a tuple containing
|
| 438 |
+
alternative shapes, location, and scale of the distribution and
|
| 439 |
+
an array of alternative data.
|
| 440 |
+
|
| 441 |
+
plot(ax=None)
|
| 442 |
+
Superposes the PDF/PMF of the fitted distribution over a normalized
|
| 443 |
+
histogram of the data.
|
| 444 |
+
|
| 445 |
+
See Also
|
| 446 |
+
--------
|
| 447 |
+
rv_continuous, rv_discrete
|
| 448 |
+
|
| 449 |
+
Notes
|
| 450 |
+
-----
|
| 451 |
+
Optimization is more likely to converge to the maximum likelihood estimate
|
| 452 |
+
when the user provides tight bounds containing the maximum likelihood
|
| 453 |
+
estimate. For example, when fitting a binomial distribution to data, the
|
| 454 |
+
number of experiments underlying each sample may be known, in which case
|
| 455 |
+
the corresponding shape parameter ``n`` can be fixed.
|
| 456 |
+
|
| 457 |
+
References
|
| 458 |
+
----------
|
| 459 |
+
.. [1] Shao, Yongzhao, and Marjorie G. Hahn. "Maximum product of spacings
|
| 460 |
+
method: a unified formulation with illustration of strong
|
| 461 |
+
consistency." Illinois Journal of Mathematics 43.3 (1999): 489-499.
|
| 462 |
+
|
| 463 |
+
Examples
|
| 464 |
+
--------
|
| 465 |
+
Suppose we wish to fit a distribution to the following data.
|
| 466 |
+
|
| 467 |
+
>>> import numpy as np
|
| 468 |
+
>>> from scipy import stats
|
| 469 |
+
>>> rng = np.random.default_rng()
|
| 470 |
+
>>> dist = stats.nbinom
|
| 471 |
+
>>> shapes = (5, 0.5)
|
| 472 |
+
>>> data = dist.rvs(*shapes, size=1000, random_state=rng)
|
| 473 |
+
|
| 474 |
+
Suppose we do not know how the data were generated, but we suspect that
|
| 475 |
+
it follows a negative binomial distribution with parameters *n* and *p*\.
|
| 476 |
+
(See `scipy.stats.nbinom`.) We believe that the parameter *n* was fewer
|
| 477 |
+
than 30, and we know that the parameter *p* must lie on the interval
|
| 478 |
+
[0, 1]. We record this information in a variable `bounds` and pass
|
| 479 |
+
this information to `fit`.
|
| 480 |
+
|
| 481 |
+
>>> bounds = [(0, 30), (0, 1)]
|
| 482 |
+
>>> res = stats.fit(dist, data, bounds)
|
| 483 |
+
|
| 484 |
+
`fit` searches within the user-specified `bounds` for the
|
| 485 |
+
values that best match the data (in the sense of maximum likelihood
|
| 486 |
+
estimation). In this case, it found shape values similar to those
|
| 487 |
+
from which the data were actually generated.
|
| 488 |
+
|
| 489 |
+
>>> res.params
|
| 490 |
+
FitParams(n=5.0, p=0.5028157644634368, loc=0.0) # may vary
|
| 491 |
+
|
| 492 |
+
We can visualize the results by superposing the probability mass function
|
| 493 |
+
of the distribution (with the shapes fit to the data) over a normalized
|
| 494 |
+
histogram of the data.
|
| 495 |
+
|
| 496 |
+
>>> import matplotlib.pyplot as plt # matplotlib must be installed to plot
|
| 497 |
+
>>> res.plot()
|
| 498 |
+
>>> plt.show()
|
| 499 |
+
|
| 500 |
+
Note that the estimate for *n* was exactly integral; this is because
|
| 501 |
+
the domain of the `nbinom` PMF includes only integral *n*, and the `nbinom`
|
| 502 |
+
object "knows" that. `nbinom` also knows that the shape *p* must be a
|
| 503 |
+
value between 0 and 1. In such a case - when the domain of the distribution
|
| 504 |
+
with respect to a parameter is finite - we are not required to specify
|
| 505 |
+
bounds for the parameter.
|
| 506 |
+
|
| 507 |
+
>>> bounds = {'n': (0, 30)} # omit parameter p using a `dict`
|
| 508 |
+
>>> res2 = stats.fit(dist, data, bounds)
|
| 509 |
+
>>> res2.params
|
| 510 |
+
FitParams(n=5.0, p=0.5016492009232932, loc=0.0) # may vary
|
| 511 |
+
|
| 512 |
+
If we wish to force the distribution to be fit with *n* fixed at 6, we can
|
| 513 |
+
set both the lower and upper bounds on *n* to 6. Note, however, that the
|
| 514 |
+
value of the objective function being optimized is typically worse (higher)
|
| 515 |
+
in this case.
|
| 516 |
+
|
| 517 |
+
>>> bounds = {'n': (6, 6)} # fix parameter `n`
|
| 518 |
+
>>> res3 = stats.fit(dist, data, bounds)
|
| 519 |
+
>>> res3.params
|
| 520 |
+
FitParams(n=6.0, p=0.5486556076755706, loc=0.0) # may vary
|
| 521 |
+
>>> res3.nllf() > res.nllf()
|
| 522 |
+
True # may vary
|
| 523 |
+
|
| 524 |
+
Note that the numerical results of the previous examples are typical, but
|
| 525 |
+
they may vary because the default optimizer used by `fit`,
|
| 526 |
+
`scipy.optimize.differential_evolution`, is stochastic. However, we can
|
| 527 |
+
customize the settings used by the optimizer to ensure reproducibility -
|
| 528 |
+
or even use a different optimizer entirely - using the `optimizer`
|
| 529 |
+
parameter.
|
| 530 |
+
|
| 531 |
+
>>> from scipy.optimize import differential_evolution
|
| 532 |
+
>>> rng = np.random.default_rng(767585560716548)
|
| 533 |
+
>>> def optimizer(fun, bounds, *, integrality):
|
| 534 |
+
... return differential_evolution(fun, bounds, strategy='best2bin',
|
| 535 |
+
... rng=rng, integrality=integrality)
|
| 536 |
+
>>> bounds = [(0, 30), (0, 1)]
|
| 537 |
+
>>> res4 = stats.fit(dist, data, bounds, optimizer=optimizer)
|
| 538 |
+
>>> res4.params
|
| 539 |
+
FitParams(n=5.0, p=0.5015183149259951, loc=0.0)
|
| 540 |
+
|
| 541 |
+
"""
|
| 542 |
+
# --- Input Validation / Standardization --- #
|
| 543 |
+
user_bounds = bounds
|
| 544 |
+
user_guess = guess
|
| 545 |
+
|
| 546 |
+
# distribution input validation and information collection
|
| 547 |
+
if hasattr(dist, "pdf"): # can't use isinstance for types
|
| 548 |
+
default_bounds = {'loc': (0, 0), 'scale': (1, 1)}
|
| 549 |
+
discrete = False
|
| 550 |
+
elif hasattr(dist, "pmf"):
|
| 551 |
+
default_bounds = {'loc': (0, 0)}
|
| 552 |
+
discrete = True
|
| 553 |
+
else:
|
| 554 |
+
message = ("`dist` must be an instance of `rv_continuous` "
|
| 555 |
+
"or `rv_discrete.`")
|
| 556 |
+
raise ValueError(message)
|
| 557 |
+
|
| 558 |
+
try:
|
| 559 |
+
param_info = dist._param_info()
|
| 560 |
+
except AttributeError as e:
|
| 561 |
+
message = (f"Distribution `{dist.name}` is not yet supported by "
|
| 562 |
+
"`scipy.stats.fit` because shape information has "
|
| 563 |
+
"not been defined.")
|
| 564 |
+
raise ValueError(message) from e
|
| 565 |
+
|
| 566 |
+
# data input validation
|
| 567 |
+
data = np.asarray(data)
|
| 568 |
+
if data.ndim != 1:
|
| 569 |
+
message = "`data` must be exactly one-dimensional."
|
| 570 |
+
raise ValueError(message)
|
| 571 |
+
if not (np.issubdtype(data.dtype, np.number)
|
| 572 |
+
and np.all(np.isfinite(data))):
|
| 573 |
+
message = "All elements of `data` must be finite numbers."
|
| 574 |
+
raise ValueError(message)
|
| 575 |
+
|
| 576 |
+
# bounds input validation and information collection
|
| 577 |
+
n_params = len(param_info)
|
| 578 |
+
n_shapes = n_params - (1 if discrete else 2)
|
| 579 |
+
param_list = [param.name for param in param_info]
|
| 580 |
+
param_names = ", ".join(param_list)
|
| 581 |
+
shape_names = ", ".join(param_list[:n_shapes])
|
| 582 |
+
|
| 583 |
+
if user_bounds is None:
|
| 584 |
+
user_bounds = {}
|
| 585 |
+
|
| 586 |
+
if isinstance(user_bounds, dict):
|
| 587 |
+
default_bounds.update(user_bounds)
|
| 588 |
+
user_bounds = default_bounds
|
| 589 |
+
user_bounds_array = np.empty((n_params, 2))
|
| 590 |
+
for i in range(n_params):
|
| 591 |
+
param_name = param_info[i].name
|
| 592 |
+
user_bound = user_bounds.pop(param_name, None)
|
| 593 |
+
if user_bound is None:
|
| 594 |
+
user_bound = param_info[i].domain
|
| 595 |
+
user_bounds_array[i] = user_bound
|
| 596 |
+
if user_bounds:
|
| 597 |
+
message = ("Bounds provided for the following unrecognized "
|
| 598 |
+
f"parameters will be ignored: {set(user_bounds)}")
|
| 599 |
+
warnings.warn(message, RuntimeWarning, stacklevel=2)
|
| 600 |
+
|
| 601 |
+
else:
|
| 602 |
+
try:
|
| 603 |
+
user_bounds = np.asarray(user_bounds, dtype=float)
|
| 604 |
+
if user_bounds.size == 0:
|
| 605 |
+
user_bounds = np.empty((0, 2))
|
| 606 |
+
except ValueError as e:
|
| 607 |
+
message = ("Each element of a `bounds` sequence must be a tuple "
|
| 608 |
+
"containing two elements: the lower and upper bound of "
|
| 609 |
+
"a distribution parameter.")
|
| 610 |
+
raise ValueError(message) from e
|
| 611 |
+
if (user_bounds.ndim != 2 or user_bounds.shape[1] != 2):
|
| 612 |
+
message = ("Each element of `bounds` must be a tuple specifying "
|
| 613 |
+
"the lower and upper bounds of a shape parameter")
|
| 614 |
+
raise ValueError(message)
|
| 615 |
+
if user_bounds.shape[0] < n_shapes:
|
| 616 |
+
message = (f"A `bounds` sequence must contain at least {n_shapes} "
|
| 617 |
+
"elements: tuples specifying the lower and upper "
|
| 618 |
+
f"bounds of all shape parameters {shape_names}.")
|
| 619 |
+
raise ValueError(message)
|
| 620 |
+
if user_bounds.shape[0] > n_params:
|
| 621 |
+
message = ("A `bounds` sequence may not contain more than "
|
| 622 |
+
f"{n_params} elements: tuples specifying the lower and "
|
| 623 |
+
"upper bounds of distribution parameters "
|
| 624 |
+
f"{param_names}.")
|
| 625 |
+
raise ValueError(message)
|
| 626 |
+
|
| 627 |
+
user_bounds_array = np.empty((n_params, 2))
|
| 628 |
+
user_bounds_array[n_shapes:] = list(default_bounds.values())
|
| 629 |
+
user_bounds_array[:len(user_bounds)] = user_bounds
|
| 630 |
+
|
| 631 |
+
user_bounds = user_bounds_array
|
| 632 |
+
validated_bounds = []
|
| 633 |
+
for i in range(n_params):
|
| 634 |
+
name = param_info[i].name
|
| 635 |
+
user_bound = user_bounds_array[i]
|
| 636 |
+
param_domain = param_info[i].domain
|
| 637 |
+
integral = param_info[i].integrality
|
| 638 |
+
combined = _combine_bounds(name, user_bound, param_domain, integral)
|
| 639 |
+
validated_bounds.append(combined)
|
| 640 |
+
|
| 641 |
+
bounds = np.asarray(validated_bounds)
|
| 642 |
+
integrality = [param.integrality for param in param_info]
|
| 643 |
+
|
| 644 |
+
# guess input validation
|
| 645 |
+
|
| 646 |
+
if user_guess is None:
|
| 647 |
+
guess_array = None
|
| 648 |
+
elif isinstance(user_guess, dict):
|
| 649 |
+
default_guess = {param.name: np.mean(bound)
|
| 650 |
+
for param, bound in zip(param_info, bounds)}
|
| 651 |
+
unrecognized = set(user_guess) - set(default_guess)
|
| 652 |
+
if unrecognized:
|
| 653 |
+
message = ("Guesses provided for the following unrecognized "
|
| 654 |
+
f"parameters will be ignored: {unrecognized}")
|
| 655 |
+
warnings.warn(message, RuntimeWarning, stacklevel=2)
|
| 656 |
+
default_guess.update(user_guess)
|
| 657 |
+
|
| 658 |
+
message = ("Each element of `guess` must be a scalar "
|
| 659 |
+
"guess for a distribution parameter.")
|
| 660 |
+
try:
|
| 661 |
+
guess_array = np.asarray([default_guess[param.name]
|
| 662 |
+
for param in param_info], dtype=float)
|
| 663 |
+
except ValueError as e:
|
| 664 |
+
raise ValueError(message) from e
|
| 665 |
+
|
| 666 |
+
else:
|
| 667 |
+
message = ("Each element of `guess` must be a scalar "
|
| 668 |
+
"guess for a distribution parameter.")
|
| 669 |
+
try:
|
| 670 |
+
user_guess = np.asarray(user_guess, dtype=float)
|
| 671 |
+
except ValueError as e:
|
| 672 |
+
raise ValueError(message) from e
|
| 673 |
+
if user_guess.ndim != 1:
|
| 674 |
+
raise ValueError(message)
|
| 675 |
+
if user_guess.shape[0] < n_shapes:
|
| 676 |
+
message = (f"A `guess` sequence must contain at least {n_shapes} "
|
| 677 |
+
"elements: scalar guesses for the distribution shape "
|
| 678 |
+
f"parameters {shape_names}.")
|
| 679 |
+
raise ValueError(message)
|
| 680 |
+
if user_guess.shape[0] > n_params:
|
| 681 |
+
message = ("A `guess` sequence may not contain more than "
|
| 682 |
+
f"{n_params} elements: scalar guesses for the "
|
| 683 |
+
f"distribution parameters {param_names}.")
|
| 684 |
+
raise ValueError(message)
|
| 685 |
+
|
| 686 |
+
guess_array = np.mean(bounds, axis=1)
|
| 687 |
+
guess_array[:len(user_guess)] = user_guess
|
| 688 |
+
|
| 689 |
+
if guess_array is not None:
|
| 690 |
+
guess_rounded = guess_array.copy()
|
| 691 |
+
|
| 692 |
+
guess_rounded[integrality] = np.round(guess_rounded[integrality])
|
| 693 |
+
rounded = np.where(guess_rounded != guess_array)[0]
|
| 694 |
+
for i in rounded:
|
| 695 |
+
message = (f"Guess for parameter `{param_info[i].name}` "
|
| 696 |
+
f"rounded from {guess_array[i]} to {guess_rounded[i]}.")
|
| 697 |
+
warnings.warn(message, RuntimeWarning, stacklevel=2)
|
| 698 |
+
|
| 699 |
+
guess_clipped = np.clip(guess_rounded, bounds[:, 0], bounds[:, 1])
|
| 700 |
+
clipped = np.where(guess_clipped != guess_rounded)[0]
|
| 701 |
+
for i in clipped:
|
| 702 |
+
message = (f"Guess for parameter `{param_info[i].name}` "
|
| 703 |
+
f"clipped from {guess_rounded[i]} to "
|
| 704 |
+
f"{guess_clipped[i]}.")
|
| 705 |
+
warnings.warn(message, RuntimeWarning, stacklevel=2)
|
| 706 |
+
|
| 707 |
+
guess = guess_clipped
|
| 708 |
+
else:
|
| 709 |
+
guess = None
|
| 710 |
+
|
| 711 |
+
# --- Fitting --- #
|
| 712 |
+
def nllf(free_params, data=data): # bind data NOW
|
| 713 |
+
with np.errstate(invalid='ignore', divide='ignore'):
|
| 714 |
+
return dist._penalized_nnlf(free_params, data)
|
| 715 |
+
|
| 716 |
+
def nlpsf(free_params, data=data): # bind data NOW
|
| 717 |
+
with np.errstate(invalid='ignore', divide='ignore'):
|
| 718 |
+
return dist._penalized_nlpsf(free_params, data)
|
| 719 |
+
|
| 720 |
+
methods = {'mle': nllf, 'mse': nlpsf}
|
| 721 |
+
objective = methods[method.lower()]
|
| 722 |
+
|
| 723 |
+
with np.errstate(invalid='ignore', divide='ignore'):
|
| 724 |
+
kwds = {}
|
| 725 |
+
if bounds is not None:
|
| 726 |
+
kwds['bounds'] = bounds
|
| 727 |
+
if np.any(integrality):
|
| 728 |
+
kwds['integrality'] = integrality
|
| 729 |
+
if guess is not None:
|
| 730 |
+
kwds['x0'] = guess
|
| 731 |
+
res = optimizer(objective, **kwds)
|
| 732 |
+
|
| 733 |
+
return FitResult(dist, data, discrete, res)
|
| 734 |
+
|
| 735 |
+
|
| 736 |
+
GoodnessOfFitResult = namedtuple('GoodnessOfFitResult',
|
| 737 |
+
('fit_result', 'statistic', 'pvalue',
|
| 738 |
+
'null_distribution'))
|
| 739 |
+
|
| 740 |
+
|
| 741 |
+
@_transition_to_rng('random_state')
|
| 742 |
+
def goodness_of_fit(dist, data, *, known_params=None, fit_params=None,
|
| 743 |
+
guessed_params=None, statistic='ad', n_mc_samples=9999,
|
| 744 |
+
rng=None):
|
| 745 |
+
r"""
|
| 746 |
+
Perform a goodness of fit test comparing data to a distribution family.
|
| 747 |
+
|
| 748 |
+
Given a distribution family and data, perform a test of the null hypothesis
|
| 749 |
+
that the data were drawn from a distribution in that family. Any known
|
| 750 |
+
parameters of the distribution may be specified. Remaining parameters of
|
| 751 |
+
the distribution will be fit to the data, and the p-value of the test
|
| 752 |
+
is computed accordingly. Several statistics for comparing the distribution
|
| 753 |
+
to data are available.
|
| 754 |
+
|
| 755 |
+
Parameters
|
| 756 |
+
----------
|
| 757 |
+
dist : `scipy.stats.rv_continuous`
|
| 758 |
+
The object representing the distribution family under the null
|
| 759 |
+
hypothesis.
|
| 760 |
+
data : 1D array_like
|
| 761 |
+
Finite, uncensored data to be tested.
|
| 762 |
+
known_params : dict, optional
|
| 763 |
+
A dictionary containing name-value pairs of known distribution
|
| 764 |
+
parameters. Monte Carlo samples are randomly drawn from the
|
| 765 |
+
null-hypothesized distribution with these values of the parameters.
|
| 766 |
+
Before the statistic is evaluated for the observed `data` and each
|
| 767 |
+
Monte Carlo sample, only remaining unknown parameters of the
|
| 768 |
+
null-hypothesized distribution family are fit to the samples; the
|
| 769 |
+
known parameters are held fixed. If all parameters of the distribution
|
| 770 |
+
family are known, then the step of fitting the distribution family to
|
| 771 |
+
each sample is omitted.
|
| 772 |
+
fit_params : dict, optional
|
| 773 |
+
A dictionary containing name-value pairs of distribution parameters
|
| 774 |
+
that have already been fit to the data, e.g. using `scipy.stats.fit`
|
| 775 |
+
or the ``fit`` method of `dist`. Monte Carlo samples are drawn from the
|
| 776 |
+
null-hypothesized distribution with these specified values of the
|
| 777 |
+
parameter. However, these and all other unknown parameters of the
|
| 778 |
+
null-hypothesized distribution family are always fit to the sample,
|
| 779 |
+
whether that is the observed `data` or a Monte Carlo sample, before
|
| 780 |
+
the statistic is evaluated.
|
| 781 |
+
guessed_params : dict, optional
|
| 782 |
+
A dictionary containing name-value pairs of distribution parameters
|
| 783 |
+
which have been guessed. These parameters are always considered as
|
| 784 |
+
free parameters and are fit both to the provided `data` as well as
|
| 785 |
+
to the Monte Carlo samples drawn from the null-hypothesized
|
| 786 |
+
distribution. The purpose of these `guessed_params` is to be used as
|
| 787 |
+
initial values for the numerical fitting procedure.
|
| 788 |
+
statistic : {"ad", "ks", "cvm", "filliben"} or callable, optional
|
| 789 |
+
The statistic used to compare data to a distribution after fitting
|
| 790 |
+
unknown parameters of the distribution family to the data. The
|
| 791 |
+
Anderson-Darling ("ad") [1]_, Kolmogorov-Smirnov ("ks") [1]_,
|
| 792 |
+
Cramer-von Mises ("cvm") [1]_, and Filliben ("filliben") [7]_
|
| 793 |
+
statistics are available. Alternatively, a callable with signature
|
| 794 |
+
``(dist, data, axis)`` may be supplied to compute the statistic. Here
|
| 795 |
+
``dist`` is a frozen distribution object (potentially with array
|
| 796 |
+
parameters), ``data`` is an array of Monte Carlo samples (of
|
| 797 |
+
compatible shape), and ``axis`` is the axis of ``data`` along which
|
| 798 |
+
the statistic must be computed.
|
| 799 |
+
n_mc_samples : int, default: 9999
|
| 800 |
+
The number of Monte Carlo samples drawn from the null hypothesized
|
| 801 |
+
distribution to form the null distribution of the statistic. The
|
| 802 |
+
sample size of each is the same as the given `data`.
|
| 803 |
+
rng : `numpy.random.Generator`, optional
|
| 804 |
+
Pseudorandom number generator state. When `rng` is None, a new
|
| 805 |
+
`numpy.random.Generator` is created using entropy from the
|
| 806 |
+
operating system. Types other than `numpy.random.Generator` are
|
| 807 |
+
passed to `numpy.random.default_rng` to instantiate a ``Generator``.
|
| 808 |
+
|
| 809 |
+
Returns
|
| 810 |
+
-------
|
| 811 |
+
res : GoodnessOfFitResult
|
| 812 |
+
An object with the following attributes.
|
| 813 |
+
|
| 814 |
+
fit_result : `~scipy.stats._result_classes.FitResult`
|
| 815 |
+
An object representing the fit of the provided `dist` to `data`.
|
| 816 |
+
This object includes the values of distribution family parameters
|
| 817 |
+
that fully define the null-hypothesized distribution, that is,
|
| 818 |
+
the distribution from which Monte Carlo samples are drawn.
|
| 819 |
+
statistic : float
|
| 820 |
+
The value of the statistic comparing provided `data` to the
|
| 821 |
+
null-hypothesized distribution.
|
| 822 |
+
pvalue : float
|
| 823 |
+
The proportion of elements in the null distribution with
|
| 824 |
+
statistic values at least as extreme as the statistic value of the
|
| 825 |
+
provided `data`.
|
| 826 |
+
null_distribution : ndarray
|
| 827 |
+
The value of the statistic for each Monte Carlo sample
|
| 828 |
+
drawn from the null-hypothesized distribution.
|
| 829 |
+
|
| 830 |
+
Notes
|
| 831 |
+
-----
|
| 832 |
+
This is a generalized Monte Carlo goodness-of-fit procedure, special cases
|
| 833 |
+
of which correspond with various Anderson-Darling tests, Lilliefors' test,
|
| 834 |
+
etc. The test is described in [2]_, [3]_, and [4]_ as a parametric
|
| 835 |
+
bootstrap test. This is a Monte Carlo test in which parameters that
|
| 836 |
+
specify the distribution from which samples are drawn have been estimated
|
| 837 |
+
from the data. We describe the test using "Monte Carlo" rather than
|
| 838 |
+
"parametric bootstrap" throughout to avoid confusion with the more familiar
|
| 839 |
+
nonparametric bootstrap, and describe how the test is performed below.
|
| 840 |
+
|
| 841 |
+
*Traditional goodness of fit tests*
|
| 842 |
+
|
| 843 |
+
Traditionally, critical values corresponding with a fixed set of
|
| 844 |
+
significance levels are pre-calculated using Monte Carlo methods. Users
|
| 845 |
+
perform the test by calculating the value of the test statistic only for
|
| 846 |
+
their observed `data` and comparing this value to tabulated critical
|
| 847 |
+
values. This practice is not very flexible, as tables are not available for
|
| 848 |
+
all distributions and combinations of known and unknown parameter values.
|
| 849 |
+
Also, results can be inaccurate when critical values are interpolated from
|
| 850 |
+
limited tabulated data to correspond with the user's sample size and
|
| 851 |
+
fitted parameter values. To overcome these shortcomings, this function
|
| 852 |
+
allows the user to perform the Monte Carlo trials adapted to their
|
| 853 |
+
particular data.
|
| 854 |
+
|
| 855 |
+
*Algorithmic overview*
|
| 856 |
+
|
| 857 |
+
In brief, this routine executes the following steps:
|
| 858 |
+
|
| 859 |
+
1. Fit unknown parameters to the given `data`, thereby forming the
|
| 860 |
+
"null-hypothesized" distribution, and compute the statistic of
|
| 861 |
+
this pair of data and distribution.
|
| 862 |
+
2. Draw random samples from this null-hypothesized distribution.
|
| 863 |
+
3. Fit the unknown parameters to each random sample.
|
| 864 |
+
4. Calculate the statistic between each sample and the distribution that
|
| 865 |
+
has been fit to the sample.
|
| 866 |
+
5. Compare the value of the statistic corresponding with `data` from (1)
|
| 867 |
+
against the values of the statistic corresponding with the random
|
| 868 |
+
samples from (4). The p-value is the proportion of samples with a
|
| 869 |
+
statistic value greater than or equal to the statistic of the observed
|
| 870 |
+
data.
|
| 871 |
+
|
| 872 |
+
In more detail, the steps are as follows.
|
| 873 |
+
|
| 874 |
+
First, any unknown parameters of the distribution family specified by
|
| 875 |
+
`dist` are fit to the provided `data` using maximum likelihood estimation.
|
| 876 |
+
(One exception is the normal distribution with unknown location and scale:
|
| 877 |
+
we use the bias-corrected standard deviation ``np.std(data, ddof=1)`` for
|
| 878 |
+
the scale as recommended in [1]_.)
|
| 879 |
+
These values of the parameters specify a particular member of the
|
| 880 |
+
distribution family referred to as the "null-hypothesized distribution",
|
| 881 |
+
that is, the distribution from which the data were sampled under the null
|
| 882 |
+
hypothesis. The `statistic`, which compares data to a distribution, is
|
| 883 |
+
computed between `data` and the null-hypothesized distribution.
|
| 884 |
+
|
| 885 |
+
Next, many (specifically `n_mc_samples`) new samples, each containing the
|
| 886 |
+
same number of observations as `data`, are drawn from the
|
| 887 |
+
null-hypothesized distribution. All unknown parameters of the distribution
|
| 888 |
+
family `dist` are fit to *each resample*, and the `statistic` is computed
|
| 889 |
+
between each sample and its corresponding fitted distribution. These
|
| 890 |
+
values of the statistic form the Monte Carlo null distribution (not to be
|
| 891 |
+
confused with the "null-hypothesized distribution" above).
|
| 892 |
+
|
| 893 |
+
The p-value of the test is the proportion of statistic values in the Monte
|
| 894 |
+
Carlo null distribution that are at least as extreme as the statistic value
|
| 895 |
+
of the provided `data`. More precisely, the p-value is given by
|
| 896 |
+
|
| 897 |
+
.. math::
|
| 898 |
+
|
| 899 |
+
p = \frac{b + 1}
|
| 900 |
+
{m + 1}
|
| 901 |
+
|
| 902 |
+
where :math:`b` is the number of statistic values in the Monte Carlo null
|
| 903 |
+
distribution that are greater than or equal to the statistic value
|
| 904 |
+
calculated for `data`, and :math:`m` is the number of elements in the
|
| 905 |
+
Monte Carlo null distribution (`n_mc_samples`). The addition of :math:`1`
|
| 906 |
+
to the numerator and denominator can be thought of as including the
|
| 907 |
+
value of the statistic corresponding with `data` in the null distribution,
|
| 908 |
+
but a more formal explanation is given in [5]_.
|
| 909 |
+
|
| 910 |
+
*Limitations*
|
| 911 |
+
|
| 912 |
+
The test can be very slow for some distribution families because unknown
|
| 913 |
+
parameters of the distribution family must be fit to each of the Monte
|
| 914 |
+
Carlo samples, and for most distributions in SciPy, distribution fitting
|
| 915 |
+
performed via numerical optimization.
|
| 916 |
+
|
| 917 |
+
*Anti-Pattern*
|
| 918 |
+
|
| 919 |
+
For this reason, it may be tempting
|
| 920 |
+
to treat parameters of the distribution pre-fit to `data` (by the user)
|
| 921 |
+
as though they were `known_params`, as specification of all parameters of
|
| 922 |
+
the distribution precludes the need to fit the distribution to each Monte
|
| 923 |
+
Carlo sample. (This is essentially how the original Kilmogorov-Smirnov
|
| 924 |
+
test is performed.) Although such a test can provide evidence against the
|
| 925 |
+
null hypothesis, the test is conservative in the sense that small p-values
|
| 926 |
+
will tend to (greatly) *overestimate* the probability of making a type I
|
| 927 |
+
error (that is, rejecting the null hypothesis although it is true), and the
|
| 928 |
+
power of the test is low (that is, it is less likely to reject the null
|
| 929 |
+
hypothesis even when the null hypothesis is false).
|
| 930 |
+
This is because the Monte Carlo samples are less likely to agree with the
|
| 931 |
+
null-hypothesized distribution as well as `data`. This tends to increase
|
| 932 |
+
the values of the statistic recorded in the null distribution, so that a
|
| 933 |
+
larger number of them exceed the value of statistic for `data`, thereby
|
| 934 |
+
inflating the p-value.
|
| 935 |
+
|
| 936 |
+
References
|
| 937 |
+
----------
|
| 938 |
+
.. [1] M. A. Stephens (1974). "EDF Statistics for Goodness of Fit and
|
| 939 |
+
Some Comparisons." Journal of the American Statistical Association,
|
| 940 |
+
Vol. 69, pp. 730-737.
|
| 941 |
+
.. [2] W. Stute, W. G. Manteiga, and M. P. Quindimil (1993).
|
| 942 |
+
"Bootstrap based goodness-of-fit-tests." Metrika 40.1: 243-256.
|
| 943 |
+
.. [3] C. Genest, & B Rémillard. (2008). "Validity of the parametric
|
| 944 |
+
bootstrap for goodness-of-fit testing in semiparametric models."
|
| 945 |
+
Annales de l'IHP Probabilités et statistiques. Vol. 44. No. 6.
|
| 946 |
+
.. [4] I. Kojadinovic and J. Yan (2012). "Goodness-of-fit testing based on
|
| 947 |
+
a weighted bootstrap: A fast large-sample alternative to the
|
| 948 |
+
parametric bootstrap." Canadian Journal of Statistics 40.3: 480-500.
|
| 949 |
+
.. [5] B. Phipson and G. K. Smyth (2010). "Permutation P-values Should
|
| 950 |
+
Never Be Zero: Calculating Exact P-values When Permutations Are
|
| 951 |
+
Randomly Drawn." Statistical Applications in Genetics and Molecular
|
| 952 |
+
Biology 9.1.
|
| 953 |
+
.. [6] H. W. Lilliefors (1967). "On the Kolmogorov-Smirnov test for
|
| 954 |
+
normality with mean and variance unknown." Journal of the American
|
| 955 |
+
statistical Association 62.318: 399-402.
|
| 956 |
+
.. [7] Filliben, James J. "The probability plot correlation coefficient
|
| 957 |
+
test for normality." Technometrics 17.1 (1975): 111-117.
|
| 958 |
+
|
| 959 |
+
Examples
|
| 960 |
+
--------
|
| 961 |
+
A well-known test of the null hypothesis that data were drawn from a
|
| 962 |
+
given distribution is the Kolmogorov-Smirnov (KS) test, available in SciPy
|
| 963 |
+
as `scipy.stats.ks_1samp`. Suppose we wish to test whether the following
|
| 964 |
+
data:
|
| 965 |
+
|
| 966 |
+
>>> import numpy as np
|
| 967 |
+
>>> from scipy import stats
|
| 968 |
+
>>> rng = np.random.default_rng()
|
| 969 |
+
>>> x = stats.uniform.rvs(size=75, random_state=rng)
|
| 970 |
+
|
| 971 |
+
were sampled from a normal distribution. To perform a KS test, the
|
| 972 |
+
empirical distribution function of the observed data will be compared
|
| 973 |
+
against the (theoretical) cumulative distribution function of a normal
|
| 974 |
+
distribution. Of course, to do this, the normal distribution under the null
|
| 975 |
+
hypothesis must be fully specified. This is commonly done by first fitting
|
| 976 |
+
the ``loc`` and ``scale`` parameters of the distribution to the observed
|
| 977 |
+
data, then performing the test.
|
| 978 |
+
|
| 979 |
+
>>> loc, scale = np.mean(x), np.std(x, ddof=1)
|
| 980 |
+
>>> cdf = stats.norm(loc, scale).cdf
|
| 981 |
+
>>> stats.ks_1samp(x, cdf)
|
| 982 |
+
KstestResult(statistic=0.1119257570456813,
|
| 983 |
+
pvalue=0.2827756409939257,
|
| 984 |
+
statistic_location=0.7751845155861765,
|
| 985 |
+
statistic_sign=-1)
|
| 986 |
+
|
| 987 |
+
An advantage of the KS-test is that the p-value - the probability of
|
| 988 |
+
obtaining a value of the test statistic under the null hypothesis as
|
| 989 |
+
extreme as the value obtained from the observed data - can be calculated
|
| 990 |
+
exactly and efficiently. `goodness_of_fit` can only approximate these
|
| 991 |
+
results.
|
| 992 |
+
|
| 993 |
+
>>> known_params = {'loc': loc, 'scale': scale}
|
| 994 |
+
>>> res = stats.goodness_of_fit(stats.norm, x, known_params=known_params,
|
| 995 |
+
... statistic='ks', rng=rng)
|
| 996 |
+
>>> res.statistic, res.pvalue
|
| 997 |
+
(0.1119257570456813, 0.2788)
|
| 998 |
+
|
| 999 |
+
The statistic matches exactly, but the p-value is estimated by forming
|
| 1000 |
+
a "Monte Carlo null distribution", that is, by explicitly drawing random
|
| 1001 |
+
samples from `scipy.stats.norm` with the provided parameters and
|
| 1002 |
+
calculating the stastic for each. The fraction of these statistic values
|
| 1003 |
+
at least as extreme as ``res.statistic`` approximates the exact p-value
|
| 1004 |
+
calculated by `scipy.stats.ks_1samp`.
|
| 1005 |
+
|
| 1006 |
+
However, in many cases, we would prefer to test only that the data were
|
| 1007 |
+
sampled from one of *any* member of the normal distribution family, not
|
| 1008 |
+
specifically from the normal distribution with the location and scale
|
| 1009 |
+
fitted to the observed sample. In this case, Lilliefors [6]_ argued that
|
| 1010 |
+
the KS test is far too conservative (that is, the p-value overstates
|
| 1011 |
+
the actual probability of rejecting a true null hypothesis) and thus lacks
|
| 1012 |
+
power - the ability to reject the null hypothesis when the null hypothesis
|
| 1013 |
+
is actually false.
|
| 1014 |
+
Indeed, our p-value above is approximately 0.28, which is far too large
|
| 1015 |
+
to reject the null hypothesis at any common significance level.
|
| 1016 |
+
|
| 1017 |
+
Consider why this might be. Note that in the KS test above, the statistic
|
| 1018 |
+
always compares data against the CDF of a normal distribution fitted to the
|
| 1019 |
+
*observed data*. This tends to reduce the value of the statistic for the
|
| 1020 |
+
observed data, but it is "unfair" when computing the statistic for other
|
| 1021 |
+
samples, such as those we randomly draw to form the Monte Carlo null
|
| 1022 |
+
distribution. It is easy to correct for this: whenever we compute the KS
|
| 1023 |
+
statistic of a sample, we use the CDF of a normal distribution fitted
|
| 1024 |
+
to *that sample*. The null distribution in this case has not been
|
| 1025 |
+
calculated exactly and is tyically approximated using Monte Carlo methods
|
| 1026 |
+
as described above. This is where `goodness_of_fit` excels.
|
| 1027 |
+
|
| 1028 |
+
>>> res = stats.goodness_of_fit(stats.norm, x, statistic='ks',
|
| 1029 |
+
... rng=rng)
|
| 1030 |
+
>>> res.statistic, res.pvalue
|
| 1031 |
+
(0.1119257570456813, 0.0196)
|
| 1032 |
+
|
| 1033 |
+
Indeed, this p-value is much smaller, and small enough to (correctly)
|
| 1034 |
+
reject the null hypothesis at common significance levels, including 5% and
|
| 1035 |
+
2.5%.
|
| 1036 |
+
|
| 1037 |
+
However, the KS statistic is not very sensitive to all deviations from
|
| 1038 |
+
normality. The original advantage of the KS statistic was the ability
|
| 1039 |
+
to compute the null distribution theoretically, but a more sensitive
|
| 1040 |
+
statistic - resulting in a higher test power - can be used now that we can
|
| 1041 |
+
approximate the null distribution
|
| 1042 |
+
computationally. The Anderson-Darling statistic [1]_ tends to be more
|
| 1043 |
+
sensitive, and critical values of the this statistic have been tabulated
|
| 1044 |
+
for various significance levels and sample sizes using Monte Carlo methods.
|
| 1045 |
+
|
| 1046 |
+
>>> res = stats.anderson(x, 'norm')
|
| 1047 |
+
>>> print(res.statistic)
|
| 1048 |
+
1.2139573337497467
|
| 1049 |
+
>>> print(res.critical_values)
|
| 1050 |
+
[0.549 0.625 0.75 0.875 1.041]
|
| 1051 |
+
>>> print(res.significance_level)
|
| 1052 |
+
[15. 10. 5. 2.5 1. ]
|
| 1053 |
+
|
| 1054 |
+
Here, the observed value of the statistic exceeds the critical value
|
| 1055 |
+
corresponding with a 1% significance level. This tells us that the p-value
|
| 1056 |
+
of the observed data is less than 1%, but what is it? We could interpolate
|
| 1057 |
+
from these (already-interpolated) values, but `goodness_of_fit` can
|
| 1058 |
+
estimate it directly.
|
| 1059 |
+
|
| 1060 |
+
>>> res = stats.goodness_of_fit(stats.norm, x, statistic='ad',
|
| 1061 |
+
... rng=rng)
|
| 1062 |
+
>>> res.statistic, res.pvalue
|
| 1063 |
+
(1.2139573337497467, 0.0034)
|
| 1064 |
+
|
| 1065 |
+
A further advantage is that use of `goodness_of_fit` is not limited to
|
| 1066 |
+
a particular set of distributions or conditions on which parameters
|
| 1067 |
+
are known versus which must be estimated from data. Instead,
|
| 1068 |
+
`goodness_of_fit` can estimate p-values relatively quickly for any
|
| 1069 |
+
distribution with a sufficiently fast and reliable ``fit`` method. For
|
| 1070 |
+
instance, here we perform a goodness of fit test using the Cramer-von Mises
|
| 1071 |
+
statistic against the Rayleigh distribution with known location and unknown
|
| 1072 |
+
scale.
|
| 1073 |
+
|
| 1074 |
+
>>> rng = np.random.default_rng()
|
| 1075 |
+
>>> x = stats.chi(df=2.2, loc=0, scale=2).rvs(size=1000, random_state=rng)
|
| 1076 |
+
>>> res = stats.goodness_of_fit(stats.rayleigh, x, statistic='cvm',
|
| 1077 |
+
... known_params={'loc': 0}, rng=rng)
|
| 1078 |
+
|
| 1079 |
+
This executes fairly quickly, but to check the reliability of the ``fit``
|
| 1080 |
+
method, we should inspect the fit result.
|
| 1081 |
+
|
| 1082 |
+
>>> res.fit_result # location is as specified, and scale is reasonable
|
| 1083 |
+
params: FitParams(loc=0.0, scale=2.1026719844231243)
|
| 1084 |
+
success: True
|
| 1085 |
+
message: 'The fit was performed successfully.'
|
| 1086 |
+
>>> import matplotlib.pyplot as plt # matplotlib must be installed to plot
|
| 1087 |
+
>>> res.fit_result.plot()
|
| 1088 |
+
>>> plt.show()
|
| 1089 |
+
|
| 1090 |
+
If the distribution is not fit to the observed data as well as possible,
|
| 1091 |
+
the test may not control the type I error rate, that is, the chance of
|
| 1092 |
+
rejecting the null hypothesis even when it is true.
|
| 1093 |
+
|
| 1094 |
+
We should also look for extreme outliers in the null distribution that
|
| 1095 |
+
may be caused by unreliable fitting. These do not necessarily invalidate
|
| 1096 |
+
the result, but they tend to reduce the test's power.
|
| 1097 |
+
|
| 1098 |
+
>>> _, ax = plt.subplots()
|
| 1099 |
+
>>> ax.hist(np.log10(res.null_distribution))
|
| 1100 |
+
>>> ax.set_xlabel("log10 of CVM statistic under the null hypothesis")
|
| 1101 |
+
>>> ax.set_ylabel("Frequency")
|
| 1102 |
+
>>> ax.set_title("Histogram of the Monte Carlo null distribution")
|
| 1103 |
+
>>> plt.show()
|
| 1104 |
+
|
| 1105 |
+
This plot seems reassuring.
|
| 1106 |
+
|
| 1107 |
+
If ``fit`` method is working reliably, and if the distribution of the test
|
| 1108 |
+
statistic is not particularly sensitive to the values of the fitted
|
| 1109 |
+
parameters, then the p-value provided by `goodness_of_fit` is expected to
|
| 1110 |
+
be a good approximation.
|
| 1111 |
+
|
| 1112 |
+
>>> res.statistic, res.pvalue
|
| 1113 |
+
(0.2231991510248692, 0.0525)
|
| 1114 |
+
|
| 1115 |
+
"""
|
| 1116 |
+
args = _gof_iv(dist, data, known_params, fit_params, guessed_params,
|
| 1117 |
+
statistic, n_mc_samples, rng)
|
| 1118 |
+
(dist, data, fixed_nhd_params, fixed_rfd_params, guessed_nhd_params,
|
| 1119 |
+
guessed_rfd_params, statistic, n_mc_samples_int, rng) = args
|
| 1120 |
+
|
| 1121 |
+
# Fit null hypothesis distribution to data
|
| 1122 |
+
nhd_fit_fun = _get_fit_fun(dist, data, guessed_nhd_params,
|
| 1123 |
+
fixed_nhd_params)
|
| 1124 |
+
nhd_vals = nhd_fit_fun(data)
|
| 1125 |
+
nhd_dist = dist(*nhd_vals)
|
| 1126 |
+
|
| 1127 |
+
def rvs(size):
|
| 1128 |
+
return nhd_dist.rvs(size=size, random_state=rng)
|
| 1129 |
+
|
| 1130 |
+
# Define statistic
|
| 1131 |
+
fit_fun = _get_fit_fun(dist, data, guessed_rfd_params, fixed_rfd_params)
|
| 1132 |
+
if callable(statistic):
|
| 1133 |
+
compare_fun = statistic
|
| 1134 |
+
else:
|
| 1135 |
+
compare_fun = _compare_dict[statistic]
|
| 1136 |
+
alternative = getattr(compare_fun, 'alternative', 'greater')
|
| 1137 |
+
|
| 1138 |
+
def statistic_fun(data, axis):
|
| 1139 |
+
# Make things simple by always working along the last axis.
|
| 1140 |
+
data = np.moveaxis(data, axis, -1)
|
| 1141 |
+
rfd_vals = fit_fun(data)
|
| 1142 |
+
rfd_dist = dist(*rfd_vals)
|
| 1143 |
+
return compare_fun(rfd_dist, data, axis=-1)
|
| 1144 |
+
|
| 1145 |
+
res = stats.monte_carlo_test(data, rvs, statistic_fun, vectorized=True,
|
| 1146 |
+
n_resamples=n_mc_samples, axis=-1,
|
| 1147 |
+
alternative=alternative)
|
| 1148 |
+
opt_res = optimize.OptimizeResult()
|
| 1149 |
+
opt_res.success = True
|
| 1150 |
+
opt_res.message = "The fit was performed successfully."
|
| 1151 |
+
opt_res.x = nhd_vals
|
| 1152 |
+
# Only continuous distributions for now, hence discrete=False
|
| 1153 |
+
# There's no fundamental limitation; it's just that we're not using
|
| 1154 |
+
# stats.fit, discrete distributions don't have `fit` method, and
|
| 1155 |
+
# we haven't written any vectorized fit functions for a discrete
|
| 1156 |
+
# distribution yet.
|
| 1157 |
+
return GoodnessOfFitResult(FitResult(dist, data, False, opt_res),
|
| 1158 |
+
res.statistic, res.pvalue,
|
| 1159 |
+
res.null_distribution)
|
| 1160 |
+
|
| 1161 |
+
|
| 1162 |
+
def _get_fit_fun(dist, data, guessed_params, fixed_params):
|
| 1163 |
+
|
| 1164 |
+
shape_names = [] if dist.shapes is None else dist.shapes.split(", ")
|
| 1165 |
+
param_names = shape_names + ['loc', 'scale']
|
| 1166 |
+
fparam_names = ['f'+name for name in param_names]
|
| 1167 |
+
all_fixed = not set(fparam_names).difference(fixed_params)
|
| 1168 |
+
guessed_shapes = [guessed_params.pop(x, None)
|
| 1169 |
+
for x in shape_names if x in guessed_params]
|
| 1170 |
+
|
| 1171 |
+
if all_fixed:
|
| 1172 |
+
def fit_fun(data):
|
| 1173 |
+
return [fixed_params[name] for name in fparam_names]
|
| 1174 |
+
# Define statistic, including fitting distribution to data
|
| 1175 |
+
elif dist in _fit_funs:
|
| 1176 |
+
def fit_fun(data):
|
| 1177 |
+
params = _fit_funs[dist](data, **fixed_params)
|
| 1178 |
+
params = np.asarray(np.broadcast_arrays(*params))
|
| 1179 |
+
if params.ndim > 1:
|
| 1180 |
+
params = params[..., np.newaxis]
|
| 1181 |
+
return params
|
| 1182 |
+
else:
|
| 1183 |
+
def fit_fun_1d(data):
|
| 1184 |
+
return dist.fit(data, *guessed_shapes, **guessed_params,
|
| 1185 |
+
**fixed_params)
|
| 1186 |
+
|
| 1187 |
+
def fit_fun(data):
|
| 1188 |
+
params = np.apply_along_axis(fit_fun_1d, axis=-1, arr=data)
|
| 1189 |
+
if params.ndim > 1:
|
| 1190 |
+
params = params.T[..., np.newaxis]
|
| 1191 |
+
return params
|
| 1192 |
+
|
| 1193 |
+
return fit_fun
|
| 1194 |
+
|
| 1195 |
+
|
| 1196 |
+
# Vectorized fitting functions. These are to accept ND `data` in which each
|
| 1197 |
+
# row (slice along last axis) is a sample to fit and scalar fixed parameters.
|
| 1198 |
+
# They return a tuple of shape parameter arrays, each of shape data.shape[:-1].
|
| 1199 |
+
def _fit_norm(data, floc=None, fscale=None):
|
| 1200 |
+
loc = floc
|
| 1201 |
+
scale = fscale
|
| 1202 |
+
if loc is None and scale is None:
|
| 1203 |
+
loc = np.mean(data, axis=-1)
|
| 1204 |
+
scale = np.std(data, ddof=1, axis=-1)
|
| 1205 |
+
elif loc is None:
|
| 1206 |
+
loc = np.mean(data, axis=-1)
|
| 1207 |
+
elif scale is None:
|
| 1208 |
+
scale = np.sqrt(((data - loc)**2).mean(axis=-1))
|
| 1209 |
+
return loc, scale
|
| 1210 |
+
|
| 1211 |
+
|
| 1212 |
+
_fit_funs = {stats.norm: _fit_norm} # type: ignore[attr-defined]
|
| 1213 |
+
|
| 1214 |
+
|
| 1215 |
+
# Vectorized goodness of fit statistic functions. These accept a frozen
|
| 1216 |
+
# distribution object and `data` in which each row (slice along last axis) is
|
| 1217 |
+
# a sample.
|
| 1218 |
+
|
| 1219 |
+
|
| 1220 |
+
def _anderson_darling(dist, data, axis):
|
| 1221 |
+
x = np.sort(data, axis=-1)
|
| 1222 |
+
n = data.shape[-1]
|
| 1223 |
+
i = np.arange(1, n+1)
|
| 1224 |
+
Si = (2*i - 1)/n * (dist.logcdf(x) + dist.logsf(x[..., ::-1]))
|
| 1225 |
+
S = np.sum(Si, axis=-1)
|
| 1226 |
+
return -n - S
|
| 1227 |
+
|
| 1228 |
+
|
| 1229 |
+
def _compute_dplus(cdfvals): # adapted from _stats_py before gh-17062
|
| 1230 |
+
n = cdfvals.shape[-1]
|
| 1231 |
+
return (np.arange(1.0, n + 1) / n - cdfvals).max(axis=-1)
|
| 1232 |
+
|
| 1233 |
+
|
| 1234 |
+
def _compute_dminus(cdfvals):
|
| 1235 |
+
n = cdfvals.shape[-1]
|
| 1236 |
+
return (cdfvals - np.arange(0.0, n)/n).max(axis=-1)
|
| 1237 |
+
|
| 1238 |
+
|
| 1239 |
+
def _kolmogorov_smirnov(dist, data, axis=-1):
|
| 1240 |
+
x = np.sort(data, axis=axis)
|
| 1241 |
+
cdfvals = dist.cdf(x)
|
| 1242 |
+
cdfvals = np.moveaxis(cdfvals, axis, -1)
|
| 1243 |
+
Dplus = _compute_dplus(cdfvals) # always works along last axis
|
| 1244 |
+
Dminus = _compute_dminus(cdfvals)
|
| 1245 |
+
return np.maximum(Dplus, Dminus)
|
| 1246 |
+
|
| 1247 |
+
|
| 1248 |
+
def _corr(X, M):
|
| 1249 |
+
# Correlation coefficient r, simplified and vectorized as we need it.
|
| 1250 |
+
# See [7] Equation (2). Lemma 1/2 are only for distributions symmetric
|
| 1251 |
+
# about 0.
|
| 1252 |
+
Xm = X.mean(axis=-1, keepdims=True)
|
| 1253 |
+
Mm = M.mean(axis=-1, keepdims=True)
|
| 1254 |
+
num = np.sum((X - Xm) * (M - Mm), axis=-1)
|
| 1255 |
+
den = np.sqrt(np.sum((X - Xm)**2, axis=-1) * np.sum((M - Mm)**2, axis=-1))
|
| 1256 |
+
return num/den
|
| 1257 |
+
|
| 1258 |
+
|
| 1259 |
+
def _filliben(dist, data, axis):
|
| 1260 |
+
# [7] Section 8 # 1
|
| 1261 |
+
X = np.sort(data, axis=-1)
|
| 1262 |
+
|
| 1263 |
+
# [7] Section 8 # 2
|
| 1264 |
+
n = data.shape[-1]
|
| 1265 |
+
k = np.arange(1, n+1)
|
| 1266 |
+
# Filliben used an approximation for the uniform distribution order
|
| 1267 |
+
# statistic medians.
|
| 1268 |
+
# m = (k - .3175)/(n + 0.365)
|
| 1269 |
+
# m[-1] = 0.5**(1/n)
|
| 1270 |
+
# m[0] = 1 - m[-1]
|
| 1271 |
+
# We can just as easily use the (theoretically) exact values. See e.g.
|
| 1272 |
+
# https://en.wikipedia.org/wiki/Order_statistic
|
| 1273 |
+
# "Order statistics sampled from a uniform distribution"
|
| 1274 |
+
m = stats.beta(k, n + 1 - k).median()
|
| 1275 |
+
|
| 1276 |
+
# [7] Section 8 # 3
|
| 1277 |
+
M = dist.ppf(m)
|
| 1278 |
+
|
| 1279 |
+
# [7] Section 8 # 4
|
| 1280 |
+
return _corr(X, M)
|
| 1281 |
+
_filliben.alternative = 'less' # type: ignore[attr-defined]
|
| 1282 |
+
|
| 1283 |
+
|
| 1284 |
+
def _cramer_von_mises(dist, data, axis):
|
| 1285 |
+
x = np.sort(data, axis=-1)
|
| 1286 |
+
n = data.shape[-1]
|
| 1287 |
+
cdfvals = dist.cdf(x)
|
| 1288 |
+
u = (2*np.arange(1, n+1) - 1)/(2*n)
|
| 1289 |
+
w = 1 / (12*n) + np.sum((u - cdfvals)**2, axis=-1)
|
| 1290 |
+
return w
|
| 1291 |
+
|
| 1292 |
+
|
| 1293 |
+
_compare_dict = {"ad": _anderson_darling, "ks": _kolmogorov_smirnov,
|
| 1294 |
+
"cvm": _cramer_von_mises, "filliben": _filliben}
|
| 1295 |
+
|
| 1296 |
+
|
| 1297 |
+
def _gof_iv(dist, data, known_params, fit_params, guessed_params, statistic,
|
| 1298 |
+
n_mc_samples, rng):
|
| 1299 |
+
|
| 1300 |
+
if not isinstance(dist, stats.rv_continuous):
|
| 1301 |
+
message = ("`dist` must be a (non-frozen) instance of "
|
| 1302 |
+
"`stats.rv_continuous`.")
|
| 1303 |
+
raise TypeError(message)
|
| 1304 |
+
|
| 1305 |
+
data = np.asarray(data, dtype=float)
|
| 1306 |
+
if not data.ndim == 1:
|
| 1307 |
+
message = "`data` must be a one-dimensional array of numbers."
|
| 1308 |
+
raise ValueError(message)
|
| 1309 |
+
|
| 1310 |
+
# Leave validation of these key/value pairs to the `fit` method,
|
| 1311 |
+
# but collect these into dictionaries that will be used
|
| 1312 |
+
known_params = known_params or dict()
|
| 1313 |
+
fit_params = fit_params or dict()
|
| 1314 |
+
guessed_params = guessed_params or dict()
|
| 1315 |
+
|
| 1316 |
+
known_params_f = {("f"+key): val for key, val in known_params.items()}
|
| 1317 |
+
fit_params_f = {("f"+key): val for key, val in fit_params.items()}
|
| 1318 |
+
|
| 1319 |
+
# These are the values of parameters of the null distribution family
|
| 1320 |
+
# with which resamples are drawn
|
| 1321 |
+
fixed_nhd_params = known_params_f.copy()
|
| 1322 |
+
fixed_nhd_params.update(fit_params_f)
|
| 1323 |
+
|
| 1324 |
+
# These are fixed when fitting the distribution family to resamples
|
| 1325 |
+
fixed_rfd_params = known_params_f.copy()
|
| 1326 |
+
|
| 1327 |
+
# These are used as guesses when fitting the distribution family to
|
| 1328 |
+
# the original data
|
| 1329 |
+
guessed_nhd_params = guessed_params.copy()
|
| 1330 |
+
|
| 1331 |
+
# These are used as guesses when fitting the distribution family to
|
| 1332 |
+
# resamples
|
| 1333 |
+
guessed_rfd_params = fit_params.copy()
|
| 1334 |
+
guessed_rfd_params.update(guessed_params)
|
| 1335 |
+
|
| 1336 |
+
if not callable(statistic):
|
| 1337 |
+
statistic = statistic.lower()
|
| 1338 |
+
statistics = {'ad', 'ks', 'cvm', 'filliben'}
|
| 1339 |
+
if statistic not in statistics:
|
| 1340 |
+
message = f"`statistic` must be one of {statistics}."
|
| 1341 |
+
raise ValueError(message)
|
| 1342 |
+
|
| 1343 |
+
n_mc_samples_int = int(n_mc_samples)
|
| 1344 |
+
if n_mc_samples_int != n_mc_samples:
|
| 1345 |
+
message = "`n_mc_samples` must be an integer."
|
| 1346 |
+
raise TypeError(message)
|
| 1347 |
+
|
| 1348 |
+
rng = check_random_state(rng)
|
| 1349 |
+
|
| 1350 |
+
return (dist, data, fixed_nhd_params, fixed_rfd_params, guessed_nhd_params,
|
| 1351 |
+
guessed_rfd_params, statistic, n_mc_samples_int, rng)
|