123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387 |
- #ifndef BOOST_MATH_DISTRIBUTIONS_FISHER_F_HPP
- #define BOOST_MATH_DISTRIBUTIONS_FISHER_F_HPP
- #include <boost/math/distributions/fwd.hpp>
- #include <boost/math/special_functions/beta.hpp>
- #include <boost/math/distributions/complement.hpp>
- #include <boost/math/distributions/detail/common_error_handling.hpp>
- #include <boost/math/special_functions/fpclassify.hpp>
- #include <utility>
- namespace boost{ namespace math{
- template <class RealType = double, class Policy = policies::policy<> >
- class fisher_f_distribution
- {
- public:
- typedef RealType value_type;
- typedef Policy policy_type;
- fisher_f_distribution(const RealType& i, const RealType& j) : m_df1(i), m_df2(j)
- {
- static const char* function = "fisher_f_distribution<%1%>::fisher_f_distribution";
- RealType result;
- detail::check_df(
- function, m_df1, &result, Policy());
- detail::check_df(
- function, m_df2, &result, Policy());
- }
- RealType degrees_of_freedom1()const
- {
- return m_df1;
- }
- RealType degrees_of_freedom2()const
- {
- return m_df2;
- }
- private:
-
-
-
- RealType m_df1;
- RealType m_df2;
- };
- typedef fisher_f_distribution<double> fisher_f;
- template <class RealType, class Policy>
- inline const std::pair<RealType, RealType> range(const fisher_f_distribution<RealType, Policy>& )
- {
- using boost::math::tools::max_value;
- return std::pair<RealType, RealType>(static_cast<RealType>(0), max_value<RealType>());
- }
- template <class RealType, class Policy>
- inline const std::pair<RealType, RealType> support(const fisher_f_distribution<RealType, Policy>& )
- {
-
- using boost::math::tools::max_value;
- return std::pair<RealType, RealType>(static_cast<RealType>(0), max_value<RealType>());
- }
- template <class RealType, class Policy>
- RealType pdf(const fisher_f_distribution<RealType, Policy>& dist, const RealType& x)
- {
- BOOST_MATH_STD_USING
- RealType df1 = dist.degrees_of_freedom1();
- RealType df2 = dist.degrees_of_freedom2();
-
- RealType error_result = 0;
- static const char* function = "boost::math::pdf(fisher_f_distribution<%1%> const&, %1%)";
- if(false == (detail::check_df(
- function, df1, &error_result, Policy())
- && detail::check_df(
- function, df2, &error_result, Policy())))
- return error_result;
- if((x < 0) || !(boost::math::isfinite)(x))
- {
- return policies::raise_domain_error<RealType>(
- function, "Random variable parameter was %1%, but must be > 0 !", x, Policy());
- }
- if(x == 0)
- {
-
- if(df1 < 2)
- return policies::raise_overflow_error<RealType>(
- function, 0, Policy());
- else if(df1 == 2)
- return 1;
- else
- return 0;
- }
-
-
-
-
-
-
-
-
- RealType v1x = df1 * x;
- RealType result;
- if(v1x > df2)
- {
- result = (df2 * df1) / ((df2 + v1x) * (df2 + v1x));
- result *= ibeta_derivative(df2 / 2, df1 / 2, df2 / (df2 + v1x), Policy());
- }
- else
- {
- result = df2 + df1 * x;
- result = (result * df1 - x * df1 * df1) / (result * result);
- result *= ibeta_derivative(df1 / 2, df2 / 2, v1x / (df2 + v1x), Policy());
- }
- return result;
- }
- template <class RealType, class Policy>
- inline RealType cdf(const fisher_f_distribution<RealType, Policy>& dist, const RealType& x)
- {
- static const char* function = "boost::math::cdf(fisher_f_distribution<%1%> const&, %1%)";
- RealType df1 = dist.degrees_of_freedom1();
- RealType df2 = dist.degrees_of_freedom2();
-
- RealType error_result = 0;
- if(false == detail::check_df(
- function, df1, &error_result, Policy())
- && detail::check_df(
- function, df2, &error_result, Policy()))
- return error_result;
- if((x < 0) || !(boost::math::isfinite)(x))
- {
- return policies::raise_domain_error<RealType>(
- function, "Random Variable parameter was %1%, but must be > 0 !", x, Policy());
- }
- RealType v1x = df1 * x;
-
-
-
-
-
-
-
-
-
- return v1x > df2
- ? boost::math::ibetac(df2 / 2, df1 / 2, df2 / (df2 + v1x), Policy())
- : boost::math::ibeta(df1 / 2, df2 / 2, v1x / (df2 + v1x), Policy());
- }
- template <class RealType, class Policy>
- inline RealType quantile(const fisher_f_distribution<RealType, Policy>& dist, const RealType& p)
- {
- static const char* function = "boost::math::quantile(fisher_f_distribution<%1%> const&, %1%)";
- RealType df1 = dist.degrees_of_freedom1();
- RealType df2 = dist.degrees_of_freedom2();
-
- RealType error_result = 0;
- if(false == (detail::check_df(
- function, df1, &error_result, Policy())
- && detail::check_df(
- function, df2, &error_result, Policy())
- && detail::check_probability(
- function, p, &error_result, Policy())))
- return error_result;
-
-
- RealType x, y(0);
- x = boost::math::ibeta_inv(df1 / 2, df2 / 2, p, &y, Policy());
- return df2 * x / (df1 * y);
- }
- template <class RealType, class Policy>
- inline RealType cdf(const complemented2_type<fisher_f_distribution<RealType, Policy>, RealType>& c)
- {
- static const char* function = "boost::math::cdf(fisher_f_distribution<%1%> const&, %1%)";
- RealType df1 = c.dist.degrees_of_freedom1();
- RealType df2 = c.dist.degrees_of_freedom2();
- RealType x = c.param;
-
- RealType error_result = 0;
- if(false == detail::check_df(
- function, df1, &error_result, Policy())
- && detail::check_df(
- function, df2, &error_result, Policy()))
- return error_result;
- if((x < 0) || !(boost::math::isfinite)(x))
- {
- return policies::raise_domain_error<RealType>(
- function, "Random Variable parameter was %1%, but must be > 0 !", x, Policy());
- }
- RealType v1x = df1 * x;
-
-
-
-
-
-
-
-
-
- return v1x > df2
- ? boost::math::ibeta(df2 / 2, df1 / 2, df2 / (df2 + v1x), Policy())
- : boost::math::ibetac(df1 / 2, df2 / 2, v1x / (df2 + v1x), Policy());
- }
- template <class RealType, class Policy>
- inline RealType quantile(const complemented2_type<fisher_f_distribution<RealType, Policy>, RealType>& c)
- {
- static const char* function = "boost::math::quantile(fisher_f_distribution<%1%> const&, %1%)";
- RealType df1 = c.dist.degrees_of_freedom1();
- RealType df2 = c.dist.degrees_of_freedom2();
- RealType p = c.param;
-
- RealType error_result = 0;
- if(false == (detail::check_df(
- function, df1, &error_result, Policy())
- && detail::check_df(
- function, df2, &error_result, Policy())
- && detail::check_probability(
- function, p, &error_result, Policy())))
- return error_result;
- RealType x, y;
- x = boost::math::ibetac_inv(df1 / 2, df2 / 2, p, &y, Policy());
- return df2 * x / (df1 * y);
- }
- template <class RealType, class Policy>
- inline RealType mean(const fisher_f_distribution<RealType, Policy>& dist)
- {
- static const char* function = "boost::math::mean(fisher_f_distribution<%1%> const&)";
- RealType df1 = dist.degrees_of_freedom1();
- RealType df2 = dist.degrees_of_freedom2();
-
- RealType error_result = 0;
- if(false == detail::check_df(
- function, df1, &error_result, Policy())
- && detail::check_df(
- function, df2, &error_result, Policy()))
- return error_result;
- if(df2 <= 2)
- {
- return policies::raise_domain_error<RealType>(
- function, "Second degree of freedom was %1% but must be > 2 in order for the distribution to have a mean.", df2, Policy());
- }
- return df2 / (df2 - 2);
- }
- template <class RealType, class Policy>
- inline RealType variance(const fisher_f_distribution<RealType, Policy>& dist)
- {
- static const char* function = "boost::math::variance(fisher_f_distribution<%1%> const&)";
- RealType df1 = dist.degrees_of_freedom1();
- RealType df2 = dist.degrees_of_freedom2();
-
- RealType error_result = 0;
- if(false == detail::check_df(
- function, df1, &error_result, Policy())
- && detail::check_df(
- function, df2, &error_result, Policy()))
- return error_result;
- if(df2 <= 4)
- {
- return policies::raise_domain_error<RealType>(
- function, "Second degree of freedom was %1% but must be > 4 in order for the distribution to have a valid variance.", df2, Policy());
- }
- return 2 * df2 * df2 * (df1 + df2 - 2) / (df1 * (df2 - 2) * (df2 - 2) * (df2 - 4));
- }
- template <class RealType, class Policy>
- inline RealType mode(const fisher_f_distribution<RealType, Policy>& dist)
- {
- static const char* function = "boost::math::mode(fisher_f_distribution<%1%> const&)";
- RealType df1 = dist.degrees_of_freedom1();
- RealType df2 = dist.degrees_of_freedom2();
-
- RealType error_result = 0;
- if(false == detail::check_df(
- function, df1, &error_result, Policy())
- && detail::check_df(
- function, df2, &error_result, Policy()))
- return error_result;
- if(df2 <= 2)
- {
- return policies::raise_domain_error<RealType>(
- function, "Second degree of freedom was %1% but must be > 2 in order for the distribution to have a mode.", df2, Policy());
- }
- return df2 * (df1 - 2) / (df1 * (df2 + 2));
- }
- template <class RealType, class Policy>
- inline RealType skewness(const fisher_f_distribution<RealType, Policy>& dist)
- {
- static const char* function = "boost::math::skewness(fisher_f_distribution<%1%> const&)";
- BOOST_MATH_STD_USING
-
- RealType df1 = dist.degrees_of_freedom1();
- RealType df2 = dist.degrees_of_freedom2();
-
- RealType error_result = 0;
- if(false == detail::check_df(
- function, df1, &error_result, Policy())
- && detail::check_df(
- function, df2, &error_result, Policy()))
- return error_result;
- if(df2 <= 6)
- {
- return policies::raise_domain_error<RealType>(
- function, "Second degree of freedom was %1% but must be > 6 in order for the distribution to have a skewness.", df2, Policy());
- }
- return 2 * (df2 + 2 * df1 - 2) * sqrt((2 * df2 - 8) / (df1 * (df2 + df1 - 2))) / (df2 - 6);
- }
- template <class RealType, class Policy>
- RealType kurtosis_excess(const fisher_f_distribution<RealType, Policy>& dist);
- template <class RealType, class Policy>
- inline RealType kurtosis(const fisher_f_distribution<RealType, Policy>& dist)
- {
- return 3 + kurtosis_excess(dist);
- }
- template <class RealType, class Policy>
- inline RealType kurtosis_excess(const fisher_f_distribution<RealType, Policy>& dist)
- {
- static const char* function = "boost::math::kurtosis_excess(fisher_f_distribution<%1%> const&)";
-
- RealType df1 = dist.degrees_of_freedom1();
- RealType df2 = dist.degrees_of_freedom2();
-
- RealType error_result = 0;
- if(false == detail::check_df(
- function, df1, &error_result, Policy())
- && detail::check_df(
- function, df2, &error_result, Policy()))
- return error_result;
- if(df2 <= 8)
- {
- return policies::raise_domain_error<RealType>(
- function, "Second degree of freedom was %1% but must be > 8 in order for the distribution to have a kurtosis.", df2, Policy());
- }
- RealType df2_2 = df2 * df2;
- RealType df1_2 = df1 * df1;
- RealType n = -16 + 20 * df2 - 8 * df2_2 + df2_2 * df2 + 44 * df1 - 32 * df2 * df1 + 5 * df2_2 * df1 - 22 * df1_2 + 5 * df2 * df1_2;
- n *= 12;
- RealType d = df1 * (df2 - 6) * (df2 - 8) * (df1 + df2 - 2);
- return n / d;
- }
- }
- }
- #include <boost/math/distributions/detail/derived_accessors.hpp>
- #endif
|