mirror of
https://github.com/boostorg/math.git
synced 2026-01-19 04:22:09 +00:00
Fix for issue #800
This commit is contained in:
@@ -578,11 +578,11 @@ namespace boost
|
|||||||
BOOST_MATH_STD_USING
|
BOOST_MATH_STD_USING
|
||||||
if ((boost::math::isinf)(v))
|
if ((boost::math::isinf)(v))
|
||||||
{
|
{
|
||||||
return 3;
|
return 1;
|
||||||
}
|
}
|
||||||
if (delta == 0)
|
if (delta == 0)
|
||||||
{ // == Student's t
|
{ // == Student's t
|
||||||
return 3;
|
return 1;
|
||||||
}
|
}
|
||||||
T mean = boost::math::detail::mean(v, delta, pol);
|
T mean = boost::math::detail::mean(v, delta, pol);
|
||||||
T l2 = delta * delta;
|
T l2 = delta * delta;
|
||||||
@@ -592,6 +592,7 @@ namespace boost
|
|||||||
result *= -mean * mean;
|
result *= -mean * mean;
|
||||||
result += v * v * (l2 * l2 + 6 * l2 + 3) / ((v - 4) * (v - 2));
|
result += v * v * (l2 * l2 + 6 * l2 + 3) / ((v - 4) * (v - 2));
|
||||||
result /= var * var;
|
result /= var * var;
|
||||||
|
result -= static_cast<T>(3);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -889,7 +889,7 @@ test-suite distribution_tests :
|
|||||||
[ run complex_test.cpp ../../test/build//boost_unit_test_framework ]
|
[ run complex_test.cpp ../../test/build//boost_unit_test_framework ]
|
||||||
|
|
||||||
[ compile test_dist_deduction_guides.cpp : [ requires cpp_deduction_guides cpp_variadic_templates ] ]
|
[ compile test_dist_deduction_guides.cpp : [ requires cpp_deduction_guides cpp_variadic_templates ] ]
|
||||||
|
[ run git_issue_800.cpp ../../test/build//boost_unit_test_framework ]
|
||||||
;
|
;
|
||||||
|
|
||||||
test-suite mp :
|
test-suite mp :
|
||||||
|
|||||||
33
test/git_issue_800.cpp
Normal file
33
test/git_issue_800.cpp
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
// Copyright Matt Borland, 2022
|
||||||
|
// Use, modification and distribution are subject to the
|
||||||
|
// Boost Software License, Version 1.0. (See accompanying file
|
||||||
|
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
|
#include "math_unit_test.hpp"
|
||||||
|
#include <boost/math/distributions/non_central_t.hpp>
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void test()
|
||||||
|
{
|
||||||
|
boost::math::non_central_t_distribution<T> nct(T(10), T(3));
|
||||||
|
|
||||||
|
// https://www.wolframalpha.com/input?i2d=true&i=N%5C%2891%29Kurtosis%5C%2891%29NoncentralStudentTDistribution%5C%2891%2910%5C%2844%29+3%5C%2893%29%5C%2893%29%5C%2844%2930%5C%2893%29
|
||||||
|
CHECK_MOLLIFIED_CLOSE(boost::math::kurtosis(nct), T(5.44234533171835241424739188827L), 1e-6);
|
||||||
|
|
||||||
|
boost::math::non_central_t_distribution<T> nct0(T(10), T(0));
|
||||||
|
|
||||||
|
// https://www.wolframalpha.com/input?i2d=true&i=Kurtosis%5C%2891%29NoncentralStudentTDistribution%5C%2891%2910%5C%2844%29+0%5C%2893%29%5C%2893%29
|
||||||
|
CHECK_ULP_CLOSE(boost::math::kurtosis(nct0), T(4), 1);
|
||||||
|
|
||||||
|
// https://www.wolframalpha.com/input?i2d=true&i=ExcessKurtosis%5C%2891%29NoncentralStudentTDistribution%5C%2891%2910%5C%2844%29+0%5C%2893%29%5C%2893%29
|
||||||
|
CHECK_ULP_CLOSE(boost::math::kurtosis_excess(nct0), T(1), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
test<float>();
|
||||||
|
test<double>();
|
||||||
|
test<long double>();
|
||||||
|
|
||||||
|
return boost::math::test::report_errors();
|
||||||
|
}
|
||||||
@@ -107,7 +107,7 @@ RealType naive_kurtosis_excess(RealType v, RealType delta)
|
|||||||
/ ((-4 + v) * (-2 + v));
|
/ ((-4 + v) * (-2 + v));
|
||||||
r /= (1 + delta*delta)*v / (-2 + v) - delta*delta*v *tgr*tgr / 2;
|
r /= (1 + delta*delta)*v / (-2 + v) - delta*delta*v *tgr*tgr / 2;
|
||||||
r /= (1 + delta*delta)*v / (-2 + v) - delta*delta*v *tgr*tgr / 2;
|
r /= (1 + delta*delta)*v / (-2 + v) - delta*delta*v *tgr*tgr / 2;
|
||||||
return r;
|
return r - static_cast<RealType>(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
float naive_kurtosis_excess(float v, float delta)
|
float naive_kurtosis_excess(float v, float delta)
|
||||||
@@ -139,7 +139,7 @@ void test_spot(
|
|||||||
BOOST_CHECK_CLOSE(
|
BOOST_CHECK_CLOSE(
|
||||||
skewness(dist), naive_skewness(df, ncp), tol * 10 * tolerance_tgamma_extra);
|
skewness(dist), naive_skewness(df, ncp), tol * 10 * tolerance_tgamma_extra);
|
||||||
BOOST_CHECK_CLOSE(
|
BOOST_CHECK_CLOSE(
|
||||||
kurtosis_excess(dist), naive_kurtosis_excess(df, ncp), tol * 50 * tolerance_tgamma_extra);
|
kurtosis_excess(dist), naive_kurtosis_excess(df, ncp), tol * 350 * tolerance_tgamma_extra);
|
||||||
BOOST_CHECK_CLOSE(
|
BOOST_CHECK_CLOSE(
|
||||||
kurtosis(dist), 3 + naive_kurtosis_excess(df, ncp), tol * 50 * tolerance_tgamma_extra);
|
kurtosis(dist), 3 + naive_kurtosis_excess(df, ncp), tol * 50 * tolerance_tgamma_extra);
|
||||||
}
|
}
|
||||||
@@ -517,8 +517,8 @@ void test_big_df(RealType)
|
|||||||
BOOST_CHECK_EQUAL(variance(maxdf), 1);
|
BOOST_CHECK_EQUAL(variance(maxdf), 1);
|
||||||
BOOST_CHECK_EQUAL(skewness(infdf), 0);
|
BOOST_CHECK_EQUAL(skewness(infdf), 0);
|
||||||
BOOST_CHECK_EQUAL(skewness(maxdf), 0);
|
BOOST_CHECK_EQUAL(skewness(maxdf), 0);
|
||||||
BOOST_CHECK_EQUAL(kurtosis_excess(infdf), 3);
|
BOOST_CHECK_EQUAL(kurtosis_excess(infdf), 1);
|
||||||
BOOST_CHECK_CLOSE_FRACTION(kurtosis_excess(maxdf), static_cast<RealType>(3), tolerance);
|
BOOST_CHECK_CLOSE_FRACTION(kurtosis_excess(maxdf), static_cast<RealType>(1), tolerance);
|
||||||
|
|
||||||
// Bad df examples.
|
// Bad df examples.
|
||||||
#ifndef BOOST_NO_EXCEPTIONS
|
#ifndef BOOST_NO_EXCEPTIONS
|
||||||
|
|||||||
Reference in New Issue
Block a user