File indexing completed on 2025-01-30 09:45:16
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_MATH_DISTRIBUTION_CONCEPT_HPP
0012 #define BOOST_MATH_DISTRIBUTION_CONCEPT_HPP
0013
0014 #ifndef BOOST_MATH_STANDALONE
0015
0016 #include <boost/math/distributions/complement.hpp>
0017 #include <boost/math/distributions/fwd.hpp>
0018 #ifdef _MSC_VER
0019 #pragma warning(push)
0020 #pragma warning(disable: 4100)
0021 #pragma warning(disable: 4510)
0022 #pragma warning(disable: 4610)
0023 #pragma warning(disable: 4189)
0024 #endif
0025 #include <boost/concept_check.hpp>
0026 #ifdef _MSC_VER
0027 #pragma warning(pop)
0028 #endif
0029 #include <utility>
0030
0031 namespace boost{
0032 namespace math{
0033
0034 namespace concepts
0035 {
0036
0037
0038
0039 template <class RealType>
0040 class distribution_archetype
0041 {
0042 public:
0043 typedef RealType value_type;
0044
0045 distribution_archetype(const distribution_archetype&);
0046 distribution_archetype& operator=(const distribution_archetype&);
0047
0048
0049
0050 static distribution_archetype& get_object()
0051 {
0052
0053 return *reinterpret_cast<distribution_archetype*>(nullptr);
0054 }
0055 };
0056
0057
0058
0059
0060 template <class RealType>
0061 RealType pdf(const distribution_archetype<RealType>& dist, const RealType& x);
0062
0063 template <class RealType>
0064 RealType cdf(const distribution_archetype<RealType>& dist, const RealType& x);
0065
0066 template <class RealType>
0067 RealType quantile(const distribution_archetype<RealType>& dist, const RealType& p);
0068
0069 template <class RealType>
0070 RealType cdf(const complemented2_type<distribution_archetype<RealType>, RealType>& c);
0071
0072 template <class RealType>
0073 RealType quantile(const complemented2_type<distribution_archetype<RealType>, RealType>& c);
0074
0075 template <class RealType>
0076 RealType mean(const distribution_archetype<RealType>& dist);
0077
0078 template <class RealType>
0079 RealType standard_deviation(const distribution_archetype<RealType>& dist);
0080
0081 template <class RealType>
0082 RealType variance(const distribution_archetype<RealType>& dist);
0083
0084 template <class RealType>
0085 RealType hazard(const distribution_archetype<RealType>& dist);
0086
0087 template <class RealType>
0088 RealType chf(const distribution_archetype<RealType>& dist);
0089
0090
0091 template <class RealType>
0092 RealType coefficient_of_variation(const distribution_archetype<RealType>& dist);
0093
0094 template <class RealType>
0095 RealType mode(const distribution_archetype<RealType>& dist);
0096
0097 template <class RealType>
0098 RealType skewness(const distribution_archetype<RealType>& dist);
0099
0100 template <class RealType>
0101 RealType kurtosis_excess(const distribution_archetype<RealType>& dist);
0102
0103 template <class RealType>
0104 RealType kurtosis(const distribution_archetype<RealType>& dist);
0105
0106 template <class RealType>
0107 RealType median(const distribution_archetype<RealType>& dist);
0108
0109 template <class RealType>
0110 std::pair<RealType, RealType> range(const distribution_archetype<RealType>& dist);
0111
0112 template <class RealType>
0113 std::pair<RealType, RealType> support(const distribution_archetype<RealType>& dist);
0114
0115
0116
0117
0118
0119 template <class Distribution>
0120 struct DistributionConcept
0121 {
0122 typedef typename Distribution::value_type value_type;
0123
0124 void constraints()
0125 {
0126 function_requires<CopyConstructibleConcept<Distribution> >();
0127 function_requires<AssignableConcept<Distribution> >();
0128
0129 const Distribution& dist = DistributionConcept<Distribution>::get_object();
0130
0131 value_type x = 0;
0132
0133 value_type v = cdf(dist, x);
0134 v = cdf(complement(dist, x));
0135 suppress_unused_variable_warning(v);
0136 v = pdf(dist, x);
0137 suppress_unused_variable_warning(v);
0138 v = quantile(dist, x);
0139 suppress_unused_variable_warning(v);
0140 v = quantile(complement(dist, x));
0141 suppress_unused_variable_warning(v);
0142 v = mean(dist);
0143 suppress_unused_variable_warning(v);
0144 v = mode(dist);
0145 suppress_unused_variable_warning(v);
0146 v = standard_deviation(dist);
0147 suppress_unused_variable_warning(v);
0148 v = variance(dist);
0149 suppress_unused_variable_warning(v);
0150 v = hazard(dist, x);
0151 suppress_unused_variable_warning(v);
0152 v = chf(dist, x);
0153 suppress_unused_variable_warning(v);
0154 v = coefficient_of_variation(dist);
0155 suppress_unused_variable_warning(v);
0156 v = skewness(dist);
0157 suppress_unused_variable_warning(v);
0158 v = kurtosis(dist);
0159 suppress_unused_variable_warning(v);
0160 v = kurtosis_excess(dist);
0161 suppress_unused_variable_warning(v);
0162 v = median(dist);
0163 suppress_unused_variable_warning(v);
0164 std::pair<value_type, value_type> pv;
0165 pv = range(dist);
0166 suppress_unused_variable_warning(pv);
0167 pv = support(dist);
0168 suppress_unused_variable_warning(pv);
0169
0170 float f = 1;
0171 v = cdf(dist, f);
0172 suppress_unused_variable_warning(v);
0173 v = cdf(complement(dist, f));
0174 suppress_unused_variable_warning(v);
0175 v = pdf(dist, f);
0176 suppress_unused_variable_warning(v);
0177 v = quantile(dist, f);
0178 suppress_unused_variable_warning(v);
0179 v = quantile(complement(dist, f));
0180 suppress_unused_variable_warning(v);
0181 v = hazard(dist, f);
0182 suppress_unused_variable_warning(v);
0183 v = chf(dist, f);
0184 suppress_unused_variable_warning(v);
0185 double d = 1;
0186 v = cdf(dist, d);
0187 suppress_unused_variable_warning(v);
0188 v = cdf(complement(dist, d));
0189 suppress_unused_variable_warning(v);
0190 v = pdf(dist, d);
0191 suppress_unused_variable_warning(v);
0192 v = quantile(dist, d);
0193 suppress_unused_variable_warning(v);
0194 v = quantile(complement(dist, d));
0195 suppress_unused_variable_warning(v);
0196 v = hazard(dist, d);
0197 suppress_unused_variable_warning(v);
0198 v = chf(dist, d);
0199 suppress_unused_variable_warning(v);
0200 #ifndef TEST_MPFR
0201 long double ld = 1;
0202 v = cdf(dist, ld);
0203 suppress_unused_variable_warning(v);
0204 v = cdf(complement(dist, ld));
0205 suppress_unused_variable_warning(v);
0206 v = pdf(dist, ld);
0207 suppress_unused_variable_warning(v);
0208 v = quantile(dist, ld);
0209 suppress_unused_variable_warning(v);
0210 v = quantile(complement(dist, ld));
0211 suppress_unused_variable_warning(v);
0212 v = hazard(dist, ld);
0213 suppress_unused_variable_warning(v);
0214 v = chf(dist, ld);
0215 suppress_unused_variable_warning(v);
0216 #endif
0217 int i = 1;
0218 v = cdf(dist, i);
0219 suppress_unused_variable_warning(v);
0220 v = cdf(complement(dist, i));
0221 suppress_unused_variable_warning(v);
0222 v = pdf(dist, i);
0223 suppress_unused_variable_warning(v);
0224 v = quantile(dist, i);
0225 suppress_unused_variable_warning(v);
0226 v = quantile(complement(dist, i));
0227 suppress_unused_variable_warning(v);
0228 v = hazard(dist, i);
0229 suppress_unused_variable_warning(v);
0230 v = chf(dist, i);
0231 suppress_unused_variable_warning(v);
0232 unsigned long li = 1;
0233 v = cdf(dist, li);
0234 suppress_unused_variable_warning(v);
0235 v = cdf(complement(dist, li));
0236 suppress_unused_variable_warning(v);
0237 v = pdf(dist, li);
0238 suppress_unused_variable_warning(v);
0239 v = quantile(dist, li);
0240 suppress_unused_variable_warning(v);
0241 v = quantile(complement(dist, li));
0242 suppress_unused_variable_warning(v);
0243 v = hazard(dist, li);
0244 suppress_unused_variable_warning(v);
0245 v = chf(dist, li);
0246 suppress_unused_variable_warning(v);
0247 test_extra_members(dist);
0248 }
0249 template <class D>
0250 static void test_extra_members(const D&)
0251 {}
0252 template <class R, class P>
0253 static void test_extra_members(const boost::math::bernoulli_distribution<R, P>& d)
0254 {
0255 value_type r = d.success_fraction();
0256 (void)r;
0257 }
0258 template <class R, class P>
0259 static void test_extra_members(const boost::math::beta_distribution<R, P>& d)
0260 {
0261 value_type r1 = d.alpha();
0262 value_type r2 = d.beta();
0263 r1 = boost::math::beta_distribution<R, P>::find_alpha(r1, r2);
0264 suppress_unused_variable_warning(r1);
0265 r1 = boost::math::beta_distribution<R, P>::find_beta(r1, r2);
0266 suppress_unused_variable_warning(r1);
0267 r1 = boost::math::beta_distribution<R, P>::find_alpha(r1, r2, r1);
0268 suppress_unused_variable_warning(r1);
0269 r1 = boost::math::beta_distribution<R, P>::find_beta(r1, r2, r1);
0270 suppress_unused_variable_warning(r1);
0271 }
0272 template <class R, class P>
0273 static void test_extra_members(const boost::math::binomial_distribution<R, P>& d)
0274 {
0275 value_type r = d.success_fraction();
0276 r = d.trials();
0277 r = Distribution::find_lower_bound_on_p(r, r, r);
0278 r = Distribution::find_lower_bound_on_p(r, r, r, Distribution::clopper_pearson_exact_interval);
0279 r = Distribution::find_lower_bound_on_p(r, r, r, Distribution::jeffreys_prior_interval);
0280 r = Distribution::find_upper_bound_on_p(r, r, r);
0281 r = Distribution::find_upper_bound_on_p(r, r, r, Distribution::clopper_pearson_exact_interval);
0282 r = Distribution::find_upper_bound_on_p(r, r, r, Distribution::jeffreys_prior_interval);
0283 r = Distribution::find_minimum_number_of_trials(r, r, r);
0284 r = Distribution::find_maximum_number_of_trials(r, r, r);
0285 suppress_unused_variable_warning(r);
0286 }
0287 template <class R, class P>
0288 static void test_extra_members(const boost::math::cauchy_distribution<R, P>& d)
0289 {
0290 value_type r = d.location();
0291 r = d.scale();
0292 suppress_unused_variable_warning(r);
0293 }
0294 template <class R, class P>
0295 static void test_extra_members(const boost::math::chi_squared_distribution<R, P>& d)
0296 {
0297 value_type r = d.degrees_of_freedom();
0298 r = Distribution::find_degrees_of_freedom(r, r, r, r);
0299 r = Distribution::find_degrees_of_freedom(r, r, r, r, r);
0300 suppress_unused_variable_warning(r);
0301 }
0302 template <class R, class P>
0303 static void test_extra_members(const boost::math::exponential_distribution<R, P>& d)
0304 {
0305 value_type r = d.lambda();
0306 suppress_unused_variable_warning(r);
0307 }
0308 template <class R, class P>
0309 static void test_extra_members(const boost::math::extreme_value_distribution<R, P>& d)
0310 {
0311 value_type r = d.scale();
0312 r = d.location();
0313 suppress_unused_variable_warning(r);
0314 }
0315 template <class R, class P>
0316 static void test_extra_members(const boost::math::fisher_f_distribution<R, P>& d)
0317 {
0318 value_type r = d.degrees_of_freedom1();
0319 r = d.degrees_of_freedom2();
0320 suppress_unused_variable_warning(r);
0321 }
0322 template <class R, class P>
0323 static void test_extra_members(const boost::math::gamma_distribution<R, P>& d)
0324 {
0325 value_type r = d.scale();
0326 r = d.shape();
0327 suppress_unused_variable_warning(r);
0328 }
0329 template <class R, class P>
0330 static void test_extra_members(const boost::math::inverse_chi_squared_distribution<R, P>& d)
0331 {
0332 value_type r = d.scale();
0333 r = d.degrees_of_freedom();
0334 suppress_unused_variable_warning(r);
0335 }
0336 template <class R, class P>
0337 static void test_extra_members(const boost::math::inverse_gamma_distribution<R, P>& d)
0338 {
0339 value_type r = d.scale();
0340 r = d.shape();
0341 suppress_unused_variable_warning(r);
0342 }
0343 template <class R, class P>
0344 static void test_extra_members(const boost::math::hypergeometric_distribution<R, P>& d)
0345 {
0346 unsigned u = d.defective();
0347 u = d.sample_count();
0348 u = d.total();
0349 suppress_unused_variable_warning(u);
0350 }
0351 template <class R, class P>
0352 static void test_extra_members(const boost::math::laplace_distribution<R, P>& d)
0353 {
0354 value_type r = d.scale();
0355 r = d.location();
0356 suppress_unused_variable_warning(r);
0357 }
0358 template <class R, class P>
0359 static void test_extra_members(const boost::math::logistic_distribution<R, P>& d)
0360 {
0361 value_type r = d.scale();
0362 r = d.location();
0363 suppress_unused_variable_warning(r);
0364 }
0365 template <class R, class P>
0366 static void test_extra_members(const boost::math::lognormal_distribution<R, P>& d)
0367 {
0368 value_type r = d.scale();
0369 r = d.location();
0370 suppress_unused_variable_warning(r);
0371 }
0372 template <class R, class P>
0373 static void test_extra_members(const boost::math::negative_binomial_distribution<R, P>& d)
0374 {
0375 value_type r = d.success_fraction();
0376 r = d.successes();
0377 r = Distribution::find_lower_bound_on_p(r, r, r);
0378 r = Distribution::find_upper_bound_on_p(r, r, r);
0379 r = Distribution::find_minimum_number_of_trials(r, r, r);
0380 r = Distribution::find_maximum_number_of_trials(r, r, r);
0381 suppress_unused_variable_warning(r);
0382 }
0383 template <class R, class P>
0384 static void test_extra_members(const boost::math::non_central_beta_distribution<R, P>& d)
0385 {
0386 value_type r1 = d.alpha();
0387 value_type r2 = d.beta();
0388 r1 = d.non_centrality();
0389 (void)r1;
0390 (void)r2;
0391 }
0392 template <class R, class P>
0393 static void test_extra_members(const boost::math::non_central_chi_squared_distribution<R, P>& d)
0394 {
0395 value_type r = d.degrees_of_freedom();
0396 r = d.non_centrality();
0397 r = Distribution::find_degrees_of_freedom(r, r, r);
0398 r = Distribution::find_degrees_of_freedom(boost::math::complement(r, r, r));
0399 r = Distribution::find_non_centrality(r, r, r);
0400 r = Distribution::find_non_centrality(boost::math::complement(r, r, r));
0401 (void)r;
0402 }
0403 template <class R, class P>
0404 static void test_extra_members(const boost::math::non_central_f_distribution<R, P>& d)
0405 {
0406 value_type r = d.degrees_of_freedom1();
0407 r = d.degrees_of_freedom2();
0408 r = d.non_centrality();
0409 (void)r;
0410 }
0411 template <class R, class P>
0412 static void test_extra_members(const boost::math::non_central_t_distribution<R, P>& d)
0413 {
0414 value_type r = d.degrees_of_freedom();
0415 r = d.non_centrality();
0416 (void)r;
0417 }
0418 template <class R, class P>
0419 static void test_extra_members(const boost::math::normal_distribution<R, P>& d)
0420 {
0421 value_type r = d.scale();
0422 r = d.location();
0423 r = d.mean();
0424 r = d.standard_deviation();
0425 (void)r;
0426 }
0427 template <class R, class P>
0428 static void test_extra_members(const boost::math::pareto_distribution<R, P>& d)
0429 {
0430 value_type r = d.scale();
0431 r = d.shape();
0432 (void)r;
0433 }
0434 template <class R, class P>
0435 static void test_extra_members(const boost::math::poisson_distribution<R, P>& d)
0436 {
0437 value_type r = d.mean();
0438 (void)r;
0439 }
0440 template <class R, class P>
0441 static void test_extra_members(const boost::math::rayleigh_distribution<R, P>& d)
0442 {
0443 value_type r = d.sigma();
0444 (void)r;
0445 }
0446 template <class R, class P>
0447 static void test_extra_members(const boost::math::students_t_distribution<R, P>& d)
0448 {
0449 value_type r = d.degrees_of_freedom();
0450 r = d.find_degrees_of_freedom(r, r, r, r);
0451 r = d.find_degrees_of_freedom(r, r, r, r, r);
0452 (void)r;
0453 }
0454 template <class R, class P>
0455 static void test_extra_members(const boost::math::triangular_distribution<R, P>& d)
0456 {
0457 value_type r = d.lower();
0458 r = d.mode();
0459 r = d.upper();
0460 (void)r;
0461 }
0462 template <class R, class P>
0463 static void test_extra_members(const boost::math::weibull_distribution<R, P>& d)
0464 {
0465 value_type r = d.scale();
0466 r = d.shape();
0467 (void)r;
0468 }
0469 template <class R, class P>
0470 static void test_extra_members(const boost::math::uniform_distribution<R, P>& d)
0471 {
0472 value_type r = d.lower();
0473 r = d.upper();
0474 (void)r;
0475 }
0476 private:
0477 static Distribution* pd;
0478 static Distribution& get_object()
0479 {
0480
0481 return *pd;
0482 }
0483 };
0484
0485 template <class Distribution>
0486 Distribution* DistributionConcept<Distribution>::pd = 0;
0487
0488 }
0489 }
0490 }
0491
0492 #else
0493 #error This header can not be used in standalone mode.
0494 #endif
0495
0496 #endif
0497