2
0
mirror of https://github.com/boostorg/math.git synced 2026-02-26 04:42:22 +00:00
Commit Graph

419 Commits

Author SHA1 Message Date
Evan Miller
18ed616376 Kolmogorov-Smirnov distribution (#422)
* Kolmogorov-Smirnov distribution #421

Add a new distribution, kolmogorov_smirnov_distribution, which takes a
parameter that represents the number of observations used in a
Kolmogorov-Smirnov test. (The K-S test is a popular test for comparing
two CDFs, but the test statistic is not implemented here.)

This implementation includes Kolmogorov's original 1st order Taylor
expansion. There is a literature on the distribution's other
mathematical properties (higher order terms and exact version); this
literature is summarized in the main header file for anyone who may
want to expand the implementation later.

The CDF is implemented using a Jacobi theta function, and the PDF is a
hand-rolled derivative of that function. Quantiles plug the CDF and PDF
into a Newton-Raphson iteration. The mean and variance have nice
closed-form expressions, and the mode uses a dumb run-time maximizer.

This commit includes graphs, a ULP plotter for the PDF, and the usual
compilation and numerical tests. The test file is on the small side, but
it integrates the distribution from zero to infinity, and covers the
quantiles pretty well. As of now the numerical tests only verify
self-consistency (e.g. distribution moments and CDF-quantile relations),
so there's room to add some external checks.

* Implement skewness for K-S distribution [CI SKIP]

The third moment integrates nicely with the help of Apery's constant
(zeta_three). Verify the result via quadrature.

* Implement kurtosis for the K-S distribution

Verify the result via quadrature.
2020-09-04 08:48:51 -04:00
jzmaddock
526fc6eef4 Update test_jacobi_theta compiler requirements in Jamfile.v2. 2020-08-27 18:36:18 +01:00
jzmaddock
b1c03c841a Jamfile.v2: Tidy up mpfr/gmp use so tests pass on mingw64 2020-08-18 11:19:48 +01:00
Evan Miller
d7141cd353 Jacobi Theta functions (#394)
* Jacobi Theta functions

Implementations, tests, and ULP plotting programs are provided for the
four Jacobi Theta functions per #373. Twenty-four public C++ functions
are provided in all, covering various precision-preserving scenarios.

Documentation for collaborators is provided in the code comments. Proper
documentation for end users will be provided when the implementation and
APIs are finalized.

Some tests are failing; this implementation is meant to start a
conversation. The core dilemma faced by the author was that large values
of |q| resulted in slow convergence, and sometimes wildly inaccurate
results. Following the implementation note in DLMF 20.14, I added code
to switch over to the imaginary versions of the theta functions when |q|
> 0.85.  This restored accuracy such that all of the identity tests
passed for a loose-enough epsilon, but then lost precision to the point
that the Wolfram Alpha spot checks failed. It is the author's hope that
someone with floating-point experience can tame the exponential dragons
and squeeze the ULPs back down to a reasonable range when |q| is large.

When #392 is merged I will add more thorough value tests, although I
fully expect them to fail until the underlying precision issues are
resolved.

As a final note, the precision issues do not affect the z=0 case - the
ULP plots indicate these return values within 2 ULP across all valid
|q|. So that's a start.

* [CI SKIP] Jacobi theta: Add special-value tests and more

* Add tests covering z=0 special values from MathWorld

* Add missing real_concept header

* Replace M_PI and friends with constants::pi etc

* Use BOOST_MATH_STD_USING in more places

* Jacobi theta: Test two more of Watson's identities [CI SKIP]

See https://mathworld.wolfram.com/JacobiThetaFunctions.html

(Equations 48 and 49)

* Improve precision of Jacobi theta functions [CI SKIP]

Rewrite the private imaginary versions to use double-sided summations
following DLMF 20.13.4 and 20.13.5. This cuts down the worst of the
precision issues by a factor of 10, and gets more of the tests to pass.

I am confident enough in the code path to eliminate the compile-time
__JACOBI_THETA_USE_IMAGINARY flag. In fact the imaginary-z code paths
are now enabled for all |q| > 0.04, i.e. most legal values of q.

More extensive tests will be needed to illuminate any remaining
precision issues.

* Jacobi theta: Make changes suggested in #394 [CI SKIP]

* Add LICENSE notice to main file

* Document convergence criteria

* Eliminate eps*eps = 0 logic. This causes some disagreement with the
zero returned by Wolfram Alpha for z=0, q > 0.99 in the fourth function.
Mathematically, the fourth function is never exactly zero, so I don't
trust Wolfram here.

* Per code-review comments, remove multiplications by floating-point 2.

* Tweak the plotting programs to display their titles, and to uniformly
use `float` as their CoarseType and `long double` as their
`PreciseType`.

* Add quadrature tests to Jacobi theta functions [CI SKIP]

The quadrature tests revealed a problem in the m1 functions: they too
should switch to the _IMAGINARY logic for q > exp(-pi), or will suffer
from slow convergence. Fix them.

Also tighten tolerances for many tests from sqrt(eps) to 100 * eps.

* Test Jacobi thetas against elliptic functions and elliptic integrals [CI SKIP]

See:

* https://dlmf.nist.gov/22.2
* https://dlmf.nist.gov/20.9#i

* Test Jacobi Thetas against their Laplace transforms [CI SKIP]

See:

* https://dlmf.nist.gov/20.10#ii

I did find some disagreement, and dropped the negative sign from the
theta1 equation. DLMF's theta2 and theta3 Laplace transform equations do
not agree at all with the computed values - will need to investigate.

In the meantime, the two implemented equations agree to 4 EPS so I am
keeping them.

* Add a note on using log1p with Jacobi theta functions [CI SKIP]

See discussion:

* https://github.com/boostorg/math/pull/394#issuecomment-655871762

* Add random data tests to Jacobi Theta functions [CI SKIP]

Add a test data generator program for the Jacobi theta functions.
This program will produce data for the tau parameterization, so that
precision isn't lost during the log-transformation. This distinguishes
it from the Wolfram Alpha data, which is parameterized by q.

A few of these new random-data tests are failing, but not by obscene
margins (< 100 EPS). These failures will be addressed when the test
tolerances are finalized.

* Add small-tau tests and simplify Jacobi Theta code [CI SKIP]

Add tests for small tau (i.e. large q). The tests are failing with mean
~ 200 EPS and max ~ 800 EPS. These look like worst-case input, and
should be the focus of future accuracy improvements.

This commit also simplifies the _IMAGINARY code by abstracting all of
the loops into a single svelte function.

* Add user documentation for Jacobi Theta functions [CI SKIP]

* Add function graphs to Jacobi Theta docs [CI SKIP]

* Define Jacobi Theta test tolerances [CI SKIP]

* Add implementation note on Jacobi theta functions [CI SKIP]

* Consolidate Jacobi Theta ULPs plotting programs [CI SKIP]

* Fix q domain checking of jacobi_theta4 [CI SKIP]

* Add ULPs plots to Jacobi Theta docs [CI SKIP]

Also add the built HTML files for easy evaluation. A full rebuild is
needed for the new docs to appear in the indexes.

* Add missing Jacobi Theta ULPs plots [CI SKIP]

* Add LaTeX source for Jacobi Theta equations [CI SKIP]

* Remove unused Jacobi Theta PNG equations [CI SKIP]

* Add Jacobi Theta performance script [CI SKIP]

Provided by @NAThompson.

* Remove vestigial eps*eps check from jacobi_theta3 [CI SKIP]

* Update Jacobi Theta docs per code review comments [CI SKIP]

* Enable arg promotion for Jacobi Theta functions [CI SKIP]

Add Jacobi theta functions to the instantiation tests and fix up
everything needed to make them pass. This changes the function
signatures to use promote_args.

* Fix Jacobi Theta plotting script [CI SKIP]

This script broke when the promote_args API was added.

* Change Jacobi Theta convergence criterion [CI SKIP]

Compare the non-oscillating part of the delta to the previous one.
This avoids some headaches comparing the delta to the partial sum,
because the partial sum can be a small number due to the oscillating
component alternating signs.

Because successive terms involve either q^n^2 or exp(-(pi*n)^2),
convergence should still happen pretty quickly. Graphs have been updated
and tests still passs with no noticeable difference.
2020-08-15 18:51:47 -04:00
Nick
cbd2af2890 Cohen acceleration (#415)
* Cohen acceleration

Accelerates convergence of an alternating series by a method designed by Cohen, Villegas, and Zagier.
2020-08-09 09:55:56 -04:00
John Maddock
01f495015c Merge branch 'no_long_double_fixes' into develop 2020-07-31 18:14:09 +01:00
Nick
8792935679 Engel expansions (#404) 2020-07-20 09:51:17 -04:00
jzmaddock
0aa86c3076 No Long double policies: add test case to Jamfile.v2. 2020-07-20 11:43:42 +01:00
Nick
ee2cd5d5e5 Luroth expansions (#401) 2020-07-18 09:28:39 -04:00
Nick
5a7e64a426 Tanh-sinh with MPFR test. (#389) 2020-07-04 13:09:20 -04:00
Nick
fbb62f01c5 Centered continued fractions (#379)
* Centered continued fraction [CI SKIP]

* Document centered cfrac. [CI SKIP]

* Unit tests for centered continued fraction [CI SKIP]

* Kick off build.

* Fix syntax error in docs [CI SKIP]

* Fix ADL.
2020-06-28 14:20:52 -04:00
Nick
1ac89b2b02 Simple continued fraction (#377)
* Simple continued fraction [CI SKIP]

* Comments on error analysis [CI SKIP]

* Simple continued fraction [CI SKIP]

* Clarify comment and kick off build.
2020-06-26 14:50:04 -04:00
Nick
4e0e8eb005 Add Feigenbaum constant. (#351)
* Add Feigenbaum constant.

* Add isnan to real_concept. Convert test_constants.cpp to math_unit_test.cpp.

* Reduce ULP tolerance to 2, which is the minimum that passes on my machine.

* Improvements to Feigenbaum.

* Ok this is pretty complicated . . . [CI SKIP]

* Take jzmaddock's suggestion to remove additions to real_concept.

* Remove test the demonstrates throw.

* Use BOOST_STATIC_ASSERT_MSG to retain C++03 compatibility.

* More precise conversion from binary to decimal.

* Plastic constant.

* Fix typos.

* New tests [CI SKIP]

* bugfix in test [CI SKIP]

* Update docs for new constants [CI SKIP]

* Fix outdated instructions [CI SKIP]

* Do C++11 check for new constants.

* Update constants.qbk [CI SKIP]

* Hopefully green up build

* Constants still *work* in C++03, but now they must be tested in C++11 mode.

* Remove boost::math::isnan.

* Test file requires C++17.
2020-06-04 21:57:38 -04:00
Nick
1186f1a7ff rsqrt (#361)
* rsqrt

* Link docs into math.qbk. [CI SKIP]

* Demo performance with a compiler that generates good instructions [CI SKIP]
2020-05-30 22:34:56 -04:00
Nick
9a45e6a358 AGM 2020-05-29 21:50:25 -04:00
Nick
c59659f4ed Reinch's modification to Clenshaw recurrence (#339)
* Reinch's modification to Clenshaw recurrence. [CI SKIP]

* Convert Chebyshev tests to math_unit_test.hpp

* Performance of translated Chebyshev Clenshaw recurrence. [CI SKIP]

* Prepare to use modified Clenshaw recurrence in Chebyshev transform.

* Remove unused headers from Chebyshev transform test [CI SKIP]

* Update Chebyshev transform tests to use math_unit_test.hpp
2020-04-25 09:01:05 -04:00
Nick
d71fba9875 Improvements for math_unit_test (#331)
* CHECK_LE for math_unit_test.hpp

* CHECK_CONDITIONED_ERROR

* Always accept 1ULP accurate evaluation

* Use new features of math_unit_test to test wavelet_transform.
2020-04-25 08:56:59 -04:00
Nick
735d582b36 Merge branch 'develop' into daubechies_attempt_2 2020-03-15 13:13:49 -04:00
Conor Jackson
bba5f4e259 Added exp integral tests for exp_sinh quadrature
Added tests of the complex eponential integral E1 for quadrature::exp_sinh. These tests involve the integral of a complex valued function over the (non-native) range (1,infinity). Currently these tests fail at compilation due to a bug in mapping the non-native range to the native one.
2020-03-10 18:22:58 +00:00
NAThompson
8c621d8be4 Sketch out Daubechies wavelet class [CI SKIP] 2020-03-10 07:15:52 -04:00
NAThompson
f38a3cc13f Remove some warning and try to fix msvc compile error by adding bigobj tag. 2020-03-10 05:57:38 -04:00
Nick Thompson
7db35cef21 Fix typo that breaks build. 2020-03-07 12:33:02 -05:00
NAThompson
17c9912aba Attempt to fix compilation error of Windows. Add compiler tests for Daubechies scaling. 2020-03-06 06:33:59 -05:00
NAThompson
e81a3c87ae Fix Jamfile syntax; kick off build. 2020-03-05 06:14:38 -05:00
jzmaddock
dc52a787c8 daubechies.hpp: simplify header and reduce dependencies. 2020-02-28 17:24:38 +00:00
NAThompson
6290803975 Finish up cubic Hermite interpolation. 2020-02-18 08:11:48 -05:00
NAThompson
6a3e69bca1 Merge branch 'develop' into daubechies_attempt_2 [CI SKIP] 2020-02-18 07:06:25 -05:00
NAThompson
b5188cfaba Continuous Daubechies wavelets: Fight bitrot. 2020-01-26 11:27:28 +08:00
jzmaddock
2d6cd609c9 Autodiff: minimise #includes and change type_traits usage to the std versions.
Update tests to match.
2020-01-25 18:41:40 +00:00
Nick
b1996cbe21 Merge branch 'develop' into quintic_hermite 2020-01-19 09:49:42 -05:00
NAThompson
0242d1ac6b Quintic Hermite: Fix #include, fix docs, add test to Jamfile. 2020-01-16 18:08:34 -05:00
NAThompson
d8c2219a23 Cubic Hermite spline interpolation. [CI SKIP] 2020-01-10 13:41:11 -05:00
NAThompson
6ce45899b6 PCHIP interpolation. 2020-01-09 14:17:08 -05:00
Nick Thompson
e4c4f6db94 Makima spline: First build. 2020-01-05 17:42:17 -05:00
NAThompson
c94557d1f5 Documentation and R^2. 2019-10-20 14:32:30 -04:00
Nick Thompson
293eab2b0c Linear regression [CI SKIP] 2019-10-20 10:01:26 -04:00
jzmaddock
b6895a63cb Merge pull request #256 from boostorg/extend_sterling
Apply Sterling's approximation to more gamma functions to improve mul…
2019-10-20 11:40:17 +01:00
jzmaddock
75f77481a0 Update Lanczos generator program.
Add lanczos approximations for multiprecision types up to 100 digit precision.
Add tests for new approximations.
2019-10-18 17:58:31 +01:00
Nick Thompson
b8044215e0 Merge branch 'develop' into runs_test [CI SKIP] 2019-10-13 21:19:57 -04:00
Nick
6018bf7e8d Runs test: Get p-value from distribution of statistic. [CI SKIP] 2019-10-13 13:17:17 -04:00
Nick Thompson
692e40ea7b Ljung-Box: Add test to Jamfile.v2 2019-10-11 21:42:17 -04:00
Nick
332b5b1679 One-sample t-test: Rearrangement of directory structure. 2019-10-06 14:59:28 -04:00
NAThompson
8b84a9806c Merge branch 'develop' into anderson_darling [CI SKIP] 2019-09-28 16:00:00 -04:00
NAThompson
9839e242ae Anderson-Darling: Add test to Jamfile. [CI SKIP] 2019-09-28 15:59:55 -04:00
Nick
ee555a0738 Empirical Cumulative Distribution function 2019-09-24 11:00:07 -04:00
jzmaddock
68ad518415 Rename test in Jamfile.
Fixes: https://github.com/boostorg/math/pull/250
2019-09-07 12:57:08 +01:00
Nick
2edf4a9790 Merge pull request #244 from boostorg/cardinal_quintic_b_spline_1
Cardinal quintic b spline 1
2019-08-29 09:02:43 -04:00
Nick
6cf90a9e93 Merge pull request #234 from boostorg/jacobi_1
Jacobi polynomials [CI SKIP]
2019-08-29 08:43:20 -04:00
pabristow
2b4a15a8a5 Merge branch 'develop' of https://github.com/boostorg/math into develop 2019-08-29 12:56:25 +01:00
pabristow
1219451047 [CI SKIP]increase tolerance from 3 to 5 eps for long double on test_recurrence.cpp to allow GCC-mingw to pass. 2019-08-29 12:55:54 +01:00