non_central_beta.hpp
来自「Boost provides free peer-reviewed portab」· HPP 代码 · 共 846 行 · 第 1/3 页
HPP
846 行
Policy, policies::promote_float<false>, policies::promote_double<false>, policies::discrete_quantile<>, policies::assert_undefined<> >::type forwarding_policy; value_type a = dist.alpha(); value_type b = dist.beta(); value_type l = dist.non_centrality(); value_type r; if(!beta_detail::check_alpha( function, a, &r, Policy()) || !beta_detail::check_beta( function, b, &r, Policy()) || !detail::check_non_centrality( function, l, &r, Policy()) || !beta_detail::check_x( function, static_cast<value_type>(x), &r, Policy())) return (RealType)r; BOOST_MATH_STD_USING if(l == 0) return pdf(boost::math::beta_distribution<RealType, Policy>(dist.alpha(), dist.beta()), x); return policies::checked_narrowing_cast<RealType, forwarding_policy>( non_central_beta_pdf(a, b, l, static_cast<value_type>(x), 1 - static_cast<value_type>(x), forwarding_policy()), "function"); } } // namespace detail template <class RealType = double, class Policy = policies::policy<> > class non_central_beta_distribution { public: typedef RealType value_type; typedef Policy policy_type; non_central_beta_distribution(RealType a_, RealType b_, RealType lambda) : a(a_), b(b_), ncp(lambda) { const char* function = "boost::math::non_central_beta_distribution<%1%>::non_central_beta_distribution(%1%,%1%)"; RealType r; beta_detail::check_alpha( function, a, &r, Policy()); beta_detail::check_beta( function, b, &r, Policy()); detail::check_non_centrality( function, lambda, &r, Policy()); } // non_central_beta_distribution constructor. RealType alpha() const { // Private data getter function. return a; } RealType beta() const { // Private data getter function. return b; } RealType non_centrality() const { // Private data getter function. return ncp; } private: // Data member, initialized by constructor. RealType a; // alpha. RealType b; // beta. RealType ncp; // non-centrality parameter }; // template <class RealType, class Policy> class non_central_beta_distribution typedef non_central_beta_distribution<double> non_central_beta; // 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_beta_distribution<RealType, Policy>& /* dist */) { // Range of permissible values for random variable k. using boost::math::tools::max_value; return std::pair<RealType, RealType>(0, 1); } template <class RealType, class Policy> inline const std::pair<RealType, RealType> support(const non_central_beta_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, 1); } template <class RealType, class Policy> inline RealType mode(const non_central_beta_distribution<RealType, Policy>& dist) { // mode. static const char* function = "mode(non_central_beta_distribution<%1%> const&)"; RealType a = dist.alpha(); RealType b = dist.beta(); RealType l = dist.non_centrality(); RealType r; if(!beta_detail::check_alpha( function, a, &r, Policy()) || !beta_detail::check_beta( function, b, &r, Policy()) || !detail::check_non_centrality( function, l, &r, Policy())) return (RealType)r; RealType c = a + b + l / 2; RealType mean = 1 - (b / c) * (1 + l / (2 * c * c)); return detail::generic_find_mode_01( dist, mean, function); }#if 0 // // We don't have the necessary information to implement // these at present. These are just disabled for now, // prototypes retained so we can fill in the blanks // later: // template <class RealType, class Policy> inline RealType mean(const non_central_beta_distribution<RealType, Policy>& dist) { // TODO return 0; } // mean template <class RealType, class Policy> inline RealType variance(const non_central_beta_distribution<RealType, Policy>& dist) { // variance. const char* function = "boost::math::non_central_beta_distribution<%1%>::variance()"; // TODO return 0; } // RealType standard_deviation(const non_central_beta_distribution<RealType, Policy>& dist) // standard_deviation provided by derived accessors. template <class RealType, class Policy> inline RealType skewness(const non_central_beta_distribution<RealType, Policy>& dist) { // skewness = sqrt(l). const char* function = "boost::math::non_central_beta_distribution<%1%>::skewness()"; // TODO return 0; } template <class RealType, class Policy> inline RealType kurtosis_excess(const non_central_beta_distribution<RealType, Policy>& dist) { const char* function = "boost::math::non_central_beta_distribution<%1%>::kurtosis_excess()"; // TODO return 0; } // kurtosis_excess template <class RealType, class Policy> inline RealType kurtosis(const non_central_beta_distribution<RealType, Policy>& dist) { return kurtosis_excess(dist) + 3; }#endif template <class RealType, class Policy> inline RealType pdf(const non_central_beta_distribution<RealType, Policy>& dist, const RealType& x) { // Probability Density/Mass Function. return detail::nc_beta_pdf(dist, x); } // pdf template <class RealType, class Policy> RealType cdf(const non_central_beta_distribution<RealType, Policy>& dist, const RealType& x) { const char* function = "boost::math::non_central_beta_distribution<%1%>::cdf(%1%)"; RealType a = dist.alpha(); RealType b = dist.beta(); RealType l = dist.non_centrality(); RealType r; if(!beta_detail::check_alpha( function, a, &r, Policy()) || !beta_detail::check_beta( function, b, &r, Policy()) || !detail::check_non_centrality( function, l, &r, Policy()) || !beta_detail::check_x( function, x, &r, Policy())) return (RealType)r; if(l == 0) return cdf(beta_distribution<RealType, Policy>(a, b), x); return detail::non_central_beta_cdf(x, 1 - x, a, b, l, false, Policy()); } // cdf template <class RealType, class Policy> RealType cdf(const complemented2_type<non_central_beta_distribution<RealType, Policy>, RealType>& c) { // Complemented Cumulative Distribution Function const char* function = "boost::math::non_central_beta_distribution<%1%>::cdf(%1%)"; non_central_beta_distribution<RealType, Policy> const& dist = c.dist; RealType a = dist.alpha(); RealType b = dist.beta(); RealType l = dist.non_centrality(); RealType x = c.param; RealType r; if(!beta_detail::check_alpha( function, a, &r, Policy()) || !beta_detail::check_beta( function, b, &r, Policy()) || !detail::check_non_centrality( function, l, &r, Policy()) || !beta_detail::check_x( function, x, &r, Policy())) return (RealType)r; if(l == 0) return cdf(complement(beta_distribution<RealType, Policy>(a, b), x)); return detail::non_central_beta_cdf(x, 1 - x, a, b, l, true, Policy()); } // ccdf template <class RealType, class Policy> inline RealType quantile(const non_central_beta_distribution<RealType, Policy>& dist, const RealType& p) { // Quantile (or Percent Point) function. return detail::nc_beta_quantile(dist, p, false); } // quantile template <class RealType, class Policy> inline RealType quantile(const complemented2_type<non_central_beta_distribution<RealType, Policy>, RealType>& c) { // Quantile (or Percent Point) function. return detail::nc_beta_quantile(c.dist, c.param, true); } // quantile complement. } // namespace math} // namespace boost// This include must be at the end, *after* the accessors// for this distribution have been defined, in order to// keep compilers that support two-phase lookup happy.#include <boost/math/distributions/detail/derived_accessors.hpp>#endif // BOOST_MATH_SPECIAL_NON_CENTRAL_BETA_HPP
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?