|
Boost-Commit : |
From: pbristow_at_[hidden]
Date: 2007-08-28 11:34:59
Author: pbristow
Date: 2007-08-28 11:34:58 EDT (Tue, 28 Aug 2007)
New Revision: 39040
URL: http://svn.boost.org/trac/boost/changeset/39040
Log:
failed attempt to get link to work coinflip_eg_catch
Text files modified:
sandbox/math_toolkit/libs/math/example/binomial_coinflip_example.cpp | 36 ++++++++++++++++++------------------
1 files changed, 18 insertions(+), 18 deletions(-)
Modified: sandbox/math_toolkit/libs/math/example/binomial_coinflip_example.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/example/binomial_coinflip_example.cpp (original)
+++ sandbox/math_toolkit/libs/math/example/binomial_coinflip_example.cpp 2007-08-28 11:34:58 EDT (Tue, 28 Aug 2007)
@@ -6,13 +6,13 @@
// (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
-// Simple example of computing probabilities and quantiles for
+// Simple example of computing probabilities and quantiles for
// a Bernoulli random variable representing the flipping of a coin.
// http://mathworld.wolfram.com/CoinTossing.html
// http://en.wikipedia.org/wiki/Bernoulli_trial
// Weisstein, Eric W. "Dice." From MathWorld--A Wolfram Web Resource.
-// http://mathworld.wolfram.com/Dice.html
+// http://mathworld.wolfram.com/Dice.html
// http://en.wikipedia.org/wiki/Bernoulli_distribution
// http://mathworld.wolfram.com/BernoulliDistribution.html
//
@@ -29,7 +29,7 @@
A variable in such a sequence may be called a Bernoulli variable.
This example shows using the Binomial distribution to predict the probability
-of heads and tails when throwing a coin.
+of heads and tails when throwing a coin.
The number of correct answers (say heads),
X, is distributed as a binomial random variable
@@ -55,16 +55,16 @@
{
cout << "Using Binomial distribution to predict how many heads and tails." << endl;
try
- {
+ {
/*`
-See note [link binomial_coinflip_example_catch_block
-with the catch block] about why a try and catch block is always a good idea.
+See note [link coinflip_eg_catch with the catch block]
+about why a try and catch block is always a good idea.
-First, construct a binomial distribution with parameters success_fraction
+First, construct a binomial distribution with parameters success_fraction
1/2, and how many flips.
*/
const double success_fraction = 0.5; // = 50% = 1/2 for a 'fair' coin.
- int flips = 10;
+ int flips = 10;
binomial flip(flips, success_fraction);
cout.precision(4);
@@ -77,7 +77,7 @@
cout << "Standard deviation is " << standard_deviation(flip) << endl;
cout << "So about 2/3 will lie within 1 standard deviation and get between "
<< ceil(mean(flip) - standard_deviation(flip)) << " and "
- << floor(mean(flip) + standard_deviation(flip)) << " correct." << endl;
+ << floor(mean(flip) + standard_deviation(flip)) << " correct." << endl;
cout << "Skewness is " << skewness(flip) << endl;
// Skewness of binomial distributions is only zero (symmetrical)
// if success_fraction is exactly one half,
@@ -109,8 +109,8 @@
*/
cout << "Probability of getting 9 or 10 heads is " << cdf(complement(flip, 8)) << endl;
/*`
-Since the subtraction may involve
-[@http://docs.sun.com/source/806-3568/ncg_goldberg.html cancellation error],
+Since the subtraction may involve
+[@http://docs.sun.com/source/806-3568/ncg_goldberg.html cancellation error],
where as `cdf(complement(flip, 8))`
does not use such a subtraction internally, and so does not exhibit the problem.
@@ -138,10 +138,10 @@
*/
// Print a table of probability for the exactly a number of heads.
cout << "Probability of getting exactly (==) heads" << endl;
- for (int successes = 0; successes <= flips; successes++)
+ for (int successes = 0; successes <= flips; successes++)
{ // Say success means getting a head (or equally success means getting a tail).
double probability = pdf(flip, successes);
- cout << left << setw(2) << successes << " " << setw(10)
+ cout << left << setw(2) << successes << " " << setw(10)
<< probability << " or 1 in " << 1. / probability
<< ", or " << probability * 100. << "%" << endl;
} // for i
@@ -149,7 +149,7 @@
// Tabulate the probability of getting between zero heads and 0 upto 10 heads.
cout << "Probability of getting upto (<=) heads" << endl;
- for (int successes = 0; successes <= flips; successes++)
+ for (int successes = 0; successes <= flips; successes++)
{ // Say success means getting a head
// (equally success could mean getting a tail).
double probability = cdf(flip, successes); // P(X <= heads)
@@ -163,14 +163,14 @@
}
catch(const std::exception& e)
{
- /*`
- [#binomial_coinflip_example_catch_block]
+ //[#coinflip_eg_catch]
+ /*`
It is always essential to include try & catch blocks because
- default policies are to throw exceptions on arguments that
+ default policies are to throw exceptions on arguments that
are out of domain or cause errors like numeric-overflow.
Lacking try & catch blocks, the program will abort, whereas the
- message below from the thrown exception will give some helpful
+ message below from the thrown exception will give some helpful
clues as to the cause of the problem.
*/
std::cout <<
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk