non_central_f.hpp
来自「Boost provides free peer-reviewed portab」· HPP 代码 · 共 410 行 · 第 1/2 页
HPP
410 行
// boost\math\distributions\non_central_f.hpp// Copyright John Maddock 2008.// 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)#ifndef BOOST_MATH_SPECIAL_NON_CENTRAL_F_HPP#define BOOST_MATH_SPECIAL_NON_CENTRAL_F_HPP#include <boost/math/distributions/non_central_beta.hpp>#include <boost/math/distributions/detail/generic_mode.hpp>#include <boost/math/special_functions/pow.hpp>namespace boost{ namespace math { template <class RealType = double, class Policy = policies::policy<> > class non_central_f_distribution { public: typedef RealType value_type; typedef Policy policy_type; non_central_f_distribution(RealType v1_, RealType v2_, RealType lambda) : v1(v1_), v2(v2_), ncp(lambda) { const char* function = "boost::math::non_central_f_distribution<%1%>::non_central_f_distribution(%1%,%1%)"; RealType r; detail::check_df( function, v1, &r, Policy()); detail::check_df( function, v2, &r, Policy()); detail::check_non_centrality( function, lambda, &r, Policy()); } // non_central_f_distribution constructor. RealType degrees_of_freedom1()const { return v1; } RealType degrees_of_freedom2()const { return v2; } RealType non_centrality() const { // Private data getter function. return ncp; } private: // Data member, initialized by constructor. RealType v1; // alpha. RealType v2; // beta. RealType ncp; // non-centrality parameter }; // template <class RealType, class Policy> class non_central_f_distribution typedef non_central_f_distribution<double> non_central_f; // Reserved name of type double. // Non-member functions to give properties of the distribution. template <class RealType, class Policy> inline const std::pair<RealType, RealType> range(const non_central_f_distribution<RealType, Policy>& /* dist */) { // Range of permissible values for random variable k. using boost::math::tools::max_value; return std::pair<RealType, RealType>(0, max_value<RealType>()); } template <class RealType, class Policy> inline const std::pair<RealType, RealType> support(const non_central_f_distribution<RealType, Policy>& /* dist */) { // Range of supported values for random variable k. // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero. using boost::math::tools::max_value; return std::pair<RealType, RealType>(0, max_value<RealType>()); } template <class RealType, class Policy> inline RealType mean(const non_central_f_distribution<RealType, Policy>& dist) { const char* function = "mean(non_central_f_distribution<%1%> const&)"; RealType v1 = dist.degrees_of_freedom1(); RealType v2 = dist.degrees_of_freedom2(); RealType l = dist.non_centrality(); RealType r; if(!detail::check_df( function, v1, &r, Policy()) || !detail::check_df( function, v2, &r, Policy()) || !detail::check_non_centrality( function, l, &r, Policy())) return r; if(v2 <= 2) return policies::raise_domain_error( function, "Second degrees of freedom parameter was %1%, but must be > 2 !", v2, Policy()); return v2 * (v1 + l) / (v1 * (v2 - 2)); } // mean template <class RealType, class Policy> inline RealType mode(const non_central_f_distribution<RealType, Policy>& dist) { // mode. static const char* function = "mode(non_central_chi_squared_distribution<%1%> const&)"; RealType n = dist.degrees_of_freedom1(); RealType m = dist.degrees_of_freedom2(); RealType l = dist.non_centrality(); RealType r; if(!detail::check_df( function, n, &r, Policy()) || !detail::check_df( function, m, &r, Policy()) || !detail::check_non_centrality( function, l, &r, Policy())) return r; return detail::generic_find_mode( dist, m * (n + l) / (n * (m - 2)), function); } template <class RealType, class Policy> inline RealType variance(const non_central_f_distribution<RealType, Policy>& dist) { // variance. const char* function = "variance(non_central_f_distribution<%1%> const&)"; RealType n = dist.degrees_of_freedom1(); RealType m = dist.degrees_of_freedom2(); RealType l = dist.non_centrality(); RealType r; if(!detail::check_df( function, n, &r, Policy()) || !detail::check_df( function, m, &r, Policy()) || !detail::check_non_centrality( function, l, &r, Policy())) return r; if(m <= 4) return policies::raise_domain_error( function, "Second degrees of freedom parameter was %1%, but must be > 4 !", m, Policy()); RealType result = 2 * m * m * ((n + l) * (n + l) + (m - 2) * (n + 2 * l)); result /= (m - 4) * (m - 2) * (m - 2) * n * n; return result; } // RealType standard_deviation(const non_central_f_distribution<RealType, Policy>& dist) // standard_deviation provided by derived accessors. template <class RealType, class Policy> inline RealType skewness(const non_central_f_distribution<RealType, Policy>& dist) { // skewness = sqrt(l). const char* function = "skewness(non_central_f_distribution<%1%> const&)"; BOOST_MATH_STD_USING RealType n = dist.degrees_of_freedom1(); RealType m = dist.degrees_of_freedom2(); RealType l = dist.non_centrality(); RealType r; if(!detail::check_df( function, n, &r, Policy()) || !detail::check_df( function, m, &r, Policy()) || !detail::check_non_centrality( function, l, &r, Policy())) return r; if(m <= 6) return policies::raise_domain_error( function, "Second degrees of freedom parameter was %1%, but must be > 6 !", m, Policy());
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?