⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dist_tutorial.qbk

📁 Boost provides free peer-reviewed portable C++ source libraries. We emphasize libraries that work
💻 QBK
📖 第 1 页 / 共 2 页
字号:
it is convenient to treat them as if they were continuous functions,and permit non-integral values of their parameters.Users wanting to enforce a strict mathematical model may use `floor` or `ceil` functions on the random variate prior to calling the distribution function.The quantile functions for these distributions are hard to specifyin a manner that will satisfy everyone all of the time.  The defaultbehaviour is to return an integer result, that has been rounded /outwards/: that is to say, lower quantiles - where the probablityis less than 0.5 are rounded down, while upper quantiles - wherethe probability is greater than 0.5 - are rounded up.  This behaviourensures that if an X% quantile is requested, then /at least/ the requestedcoverage will be present in the central region, and /no more than/the requested coverage will be present in the tails.This behaviour can be changed so that the quantile functions are roundeddifferently, or return a real-valued result using [link math_toolkit.policy.pol_overview Policies].  It is stronglyrecommended that you read the tutorial [link math_toolkit.policy.pol_tutorial.understand_dis_quantUnderstanding Quantiles of Discrete Distributions] beforeusing the quantile function on a discrete distribtion.  The[link math_toolkit.policy.pol_ref.discrete_quant_ref reference docs] describe how to change the rounding policyfor these distributions.For similar reasons continuous distributions with parameters like "degrees of freedom"that might appear to be integral, are treated as real values(and are promoted from integer to floating-point if necessary).In this case however, there are a small number of situations where non-integraldegrees of freedom do have a genuine meaning.][#complements][h4 Complements are supported too]Often you don't want the value of the CDF, but its complement, which isto say `1-p` rather than `p`.  You could calculate the CDF and subtractit from `1`, but if `p` is very close to `1` then cancellation errorwill cause you to lose significant digits.  In extreme cases, `p` mayactually be equal to `1`, even though the true value of the complement is non-zero.[link why_complements See also ['"Why complements?"]]In this library, whenever you want to receive a complement, just wrapall the function arguments in a call to `complement(...)`, for example:   students_t dist(5);   cout << "CDF at t = 1 is " << cdf(dist, 1.0) << endl;   cout << "Complement of CDF at t = 1 is " << cdf(complement(dist, 1.0)) << endl;But wait, now that we have a complement, we have to be able to use it as well.Any function that accepts a probability as an argument can also accept a complementby wrapping all of its arguments in a call to `complement(...)`, for example:   students_t dist(5);      for(double i = 10; i < 1e10; i *= 10)   {      // Calculate the quantile for a 1 in i chance:      double t = quantile(complement(dist, 1/i));      // Print it out:      cout << "Quantile of students-t with 5 degrees of freedom\n"              "for a 1 in " << i << " chance is " << t << endl;   } [tip[*Critical values are just quantiles]Some texts talk about quantiles, others about critical values, the basic rule is:['Lower critical values] are the same as the quantile.['Upper critical values] are the same as the quantile from the complementof the probability.For example, suppose we have a Bernoulli process, giving rise to a binomialdistribution with success ratio 0.1 and 100 trials in total.  The ['lower critical value] for a probability of 0.05 is given by:`quantile(binomial(100, 0.1), 0.05)`and the ['upper critical value] is given by:`quantile(complement(binomial(100, 0.1), 0.05))`which return 4.82 and 14.63 respectively.][#why_complements][tip[*Why bother with complements anyway?]It's very tempting to dispense with complements, and simply subtractthe probability from 1 when required.  However, consider what happens whenthe probability is very close to 1: let's say the probability expressed atfloat precision is `0.999999940f`, then `1 - 0.999999940f = 5.96046448e-008`,but the result is actually accurate to just ['one single bit]: the onlybit that didn't cancel out!Or to look at this another way: consider that we want the risk of falselyrejecting the null-hypothesis in the Student's t test to be 1 in 1 billion,for a sample size of 10,000.This gives a probability of 1 - 10[super -9], which is exactly 1 when calculated at float precision.  In this case calculating the quantile fromthe complement neatly solves the problem, so for example:`quantile(complement(students_t(10000), 1e-9))`returns the expected t-statistic `6.00336`, where as:`quantile(students_t(10000), 1-1e-9f)`raises an overflow error, since it is the same as:`quantile(students_t(10000), 1)`Which has no finite result.][h4 Parameters can be calculated]Sometimes it's the parameters that define the distribution that you need to find.  Suppose, for example, you have conducted a Students-t testfor equal means and the result is borderline.  Maybe your two samplesdiffer from each other, or maybe they don't; based on the resultof the test you can't be sure.  A legitimate question to ask then is"How many more measurements would I have to take before I would getan X% probability that the difference is real?"  Parameter finderscan answer questions like this, and are necessarily different foreach distribution.  They are implemented as static member functionsof the distributions, for example:   students_t::find_degrees_of_freedom(      1.3,        // difference from true mean to detect      0.05,       // maximum risk of falsely rejecting the null-hypothesis.      0.1,        // maximum risk of falsely failing to reject the null-hypothesis.      0.13);      // sample standard deviation      Returns the number of degrees of freedom required to obtain a 95%probability that the observed differences in means is not down tochance alone.  In the case that a borderline Students-t test resultwas previously obtained, this can be used to estimate how large the sample sizewould have to become before the observed difference was consideredsignificant.  It assumes, of course, that the sample mean and standarddeviation are invariant with sample size.   [h4 Summary]* Distributions are objects, which are constructed from whateverparameters the distribution may have.* Member functions allow you to retrieve the parameters of a distribution.* Generic non-member functions provide access to the properties thatare common to all the distributions (PDF, CDF, quantile etc).* Complements of probabilities are calculated by wrapping the function'sarguments in a call to `complement(...)`.* Functions that accept a probability can accept a complement of theprobability as well, by wrapping the function'sarguments in a call to `complement(...)`.* Static member functions allow the parameters of a distributionto be found from other information.Now that you have the basics, the next section looks at some worked examples.[endsect] [/section:overview Overview][section:weg Worked Examples][include distributions/distribution_construction.qbk][include distributions/students_t_examples.qbk][include distributions/chi_squared_examples.qbk][include distributions/f_dist_example.qbk][include distributions/binomial_example.qbk][include distributions/negative_binomial_example.qbk][include distributions/normal_example.qbk][include distributions/nc_chi_squared_example.qbk][include distributions/error_handling_example.qbk][include distributions/find_location_and_scale.qbk][include distributions/nag_library.qbk][endsect] [/section:weg Worked Examples][include background.qbk][endsect] [/ section:stat_tut Statistical Distributions Tutorial][/ dist_tutorial.qbk  Copyright 2006 John Maddock and Paul A. Bristow.  Distributed under 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).]

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -