Boost logo

Boost-Commit :

From: pbristow_at_[hidden]
Date: 2007-09-16 11:29:12


Author: pbristow
Date: 2007-09-16 11:29:11 EDT (Sun, 16 Sep 2007)
New Revision: 39326
URL: http://svn.boost.org/trac/boost/changeset/39326

Log:
deletion?
Removed:
   sandbox/math_toolkit/libs/math/example/negative_binomial_construction_examples.cpp
   sandbox/math_toolkit/libs/math/example/negative_binomial_example3.cpp
   sandbox/math_toolkit/libs/math/example/statistics_functions_example1.cpp

Deleted: sandbox/math_toolkit/libs/math/example/negative_binomial_construction_examples.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/example/negative_binomial_construction_examples.cpp 2007-09-16 11:29:11 EDT (Sun, 16 Sep 2007)
+++ (empty file)
@@ -1,98 +0,0 @@
-NOte now obselete - see deistribution_construction.cpp
-
-
-// negative_binomial_example2.cpp
-
-// Copyright Paul A. Bristow 2007.
-
-// 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)
-
-// Example 2 of using constructing distributions, shown here for negative_binomial.
-
-#include <boost/math/distributions/negative_binomial.hpp> // for negative_binomial_distribution
- using boost::math::negative_binomial_distribution; // default type is double.
- using boost::math::negative_binomial; // typedef provides default type is double.
-#include <boost/math/distributions/binomial.hpp> // for negative_binomial_distribution
-
-#include <iostream>
- using std::cout;
- using std::endl;
-
-int main()
-{
- // Several examples of constructing distributions, for example, negative binomial:
- // A negative binomial with 8 successes and a success fraction 0.25, 25% or 1 in 4 is constructed like this:
-
- boost::math::negative_binomial_distribution<double> mydist0(8., 0.25);
- // But this is inconveniently long.
-
- // The prefix boost::math:: can be avoided by
- using boost::math::negative_binomial_distribution;
- // Allows convenient reference to negative_binomial_distribution.
-
- negative_binomial_distribution<> mydist9(8., 0.25); // Uses default RealType = double.
- // But the name "negative_binomial_distribution" is still inconveniently long,
- // so for most distributions, a typedef is provided, for example:
-
- // typedef negative_binomial_distribution<double> negative_binomial; // Reserved name of type double.
-
- using boost::math::negative_binomial; // Allows convenient access to the name negative_binomial.
-
- // Some examples using the provided typedef:
- // Allows convenient reference to negative_binomial of default type double.
- negative_binomial mydist10(5., 0.4); // Both arguments double.
- // And automatic conversion takes place, so you can use integers and floats:
- negative_binomial mydist11(5, 0.4); // Using provided typedef double, int and double arguments.
- // This is probably the most common usage.
- negative_binomial mydist12(5., 0.4F); // Double and float arguments.
- negative_binomial mydist13(5, 1); // Both arguments integer.
-
- // But for cases when the typdef distribution name
- // would clash with a math special function
- // (for example binomial, beta and gamma)
- // the typedef is deliberately not provided, and
- // the longer version(s) must be used.
- // For example:
- using namespace boost::math;
- // NOT binomial myb010(1, 0.5); but
- binomial_distribution<> myb1(1, 0.5);
-
- // You can also provide the type RealType explicitly thus:
- negative_binomial_distribution<double> mydist1(8., 0.25); // Explicit double.
- negative_binomial_distribution<float> mydist2(8., 0.25); // Explicit float, double arguments -> float.
- negative_binomial_distribution<float> mydist3(8, 0.25); // Explicit float, integer & double arguments -> float.
- negative_binomial_distribution<float> mydist4(8.F, 0.25F); // Explicit float, float arguments, no conversion.
- negative_binomial_distribution<float> mydist5(8, 1); // Explicit integer, integer arguments -> float.
- negative_binomial_distribution<double> mydist6(8., 0.25); // Explicit double.
- negative_binomial_distribution<long double> mydist7(8., 0.25); // Explicit long double.
- // And if you have your own RealType called MyFPType,
- // for example NTL quad_float (128-bit floating-point), then:
- // negative_binomial_distribution<MyFPType> mydist6(8, 1); // Integer arguments -> MyFPType.
-
- // Note that default constructor arguments are only provided for some distributions.
- // negative_binomial_distribution<> mydist;
- // error C2512 no appropriate default constructor available.
- // Since there are no accessor functions, no default constructor are provided,
- // because it is difficult to chose any sensible default values for this distribution.
- // For other distribution, like the normal distribution,
- // it is obviously very useful to provide
- // defaults for the mean and standard deviation thus:
- // normal_distribution(RealType mean = 0, RealType sd = 1)
-
- return 0;
-} // int main()
-
-/*
-
-
-
-*/
-
-
-
-
-
-

Deleted: sandbox/math_toolkit/libs/math/example/negative_binomial_example3.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/example/negative_binomial_example3.cpp 2007-09-16 11:29:11 EDT (Sun, 16 Sep 2007)
+++ (empty file)
@@ -1,198 +0,0 @@
-// negative_binomial_example3.cpp
-
-// Copyright Paul A. Bristow 2007.
-
-// 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)
-
-// Example 3 of using constructing distributions, mainly negative_binomial.
-
-//[neg_binomial_example3
-/*`
-First we need some includes to access the negative binomial distribution
-(and some basic std output of course).
-*/
-
-#include <boost/math/distributions/negative_binomial.hpp> // for negative_binomial_distribution
- using boost::math::negative_binomial; // typedef provides default type is double.
-
-#include <iostream>
- using std::cout;
- using std::endl;
- using std::setw;
-#include <limits>
- using std::numeric_limits;
-
-/*`
-A number of the application examples from K. Krishnamoorthy, Handbook of Statistical Distributions with Applications,
-ISBN 1 58488 635 8, page 100... are implemented using the Math Toolkit library.
-
-A sample example is shown here:
-*/
-
-//] [/ neg_binomial_example3]
-
-int main()
-{
- cout << "Example 3 Negative_binomial, Krishnamoorthy applications.";
-#if defined(__FILE__) && defined(__TIMESTAMP__)
- cout << " " << __FILE__ << ' ' << __TIMESTAMP__ << "\n";
-#endif
- cout << endl;
- {
-//[neg_binomial_example3_1
- // K. Krishnamoorthy, Handbook of Statistical Distributions with Applications,
- // ISBN 1 58488 635 8, page 100, example 7.3.1
- // r successes = 20, k failures = 18, and success probability (fraction) = 0.6
- negative_binomial nbk(20, 0.6); // successes, success_fraction.
- cout.precision(6); // default precision.
- cout << "Probability of <= 18, P(X <= 18) == cdf(18) = " << cdf(nbk, 18) << endl; // = 0.862419
- cout << "Probability of > 18, P(X < 18) == 1 - cdf(18) = " << 1 - cdf(nbk, 18) << endl; // = 0.137581
- // But this may suffer from inaccuracy, so much better to use the complement.
- cout << "Probability of > 18, P(X < 18) == 1 - cdf(18) = " << cdf(complement(nbk, 18)) << endl; // 0.137581
- // And, of course, the sum of probability of X <= 18 and X > 18 really should be unity!
- BOOST_ASSERT(cdf(nbk, 18) + cdf(complement(nbk, 18))); // = 0.862419 + 0.137581 == 1
- cout << "Probability of < 18 == <= 17 == cdf(17) = " << cdf(nbk, 17) << endl; //
- cout << "Probability of >= 18 == > 17 == 1 - cdf(17) = " << 1 - cdf(nbk, 17) << endl; // 0.181983
- // But this may suffer from inaccuracy, so much better to use the complement.
- cout << "Probability of >= 18 == > 17 == cdf(complement(nbk, 17)) = "
- << cdf(complement(nbk, 17)) << endl; // = 0.181983
- cout << "Probability of exactly == 18, P(X =18) = pdf(18) = " << pdf(nbk, 18) << endl; // 0.044402
- cout << endl;
-//] [/negative_binomial_example3_1 Quickbook end]
- }
- { // Example 7.3.2 to find the success probability when r = 4, k = 5, P(X <= k) = 0.56 and
- // calculates success probability = 0.417137.
- negative_binomial nb(4, 0.417137);
- cout << "P(X <= k) = " << cdf(nb, 5) << endl; // expect P(X <= k) = 0.56 got 0.560001
- // Now check the inverse by calculating the k failures.
- cout << " k = " << quantile(nb, 0.56) << endl; // expect to get k = 5. and got 5.000000
- // P(X <= k) = 0.56001
- // P(X >= k) = 0.55406
- // P(X == k) = 0.114061
- // Compute moments:
- // mean 5.58918, sd 3.66045, mode = 4, cv = 0.654918, skew 1.03665, Mean dev 2.86877, kurtosis 4.57463
- cout << "Mean = " << mean(nb) // 5.589176
- << ", sd = " << standard_deviation(nb)
- << ", Coefficient of variation (sd/mean) = " << standard_deviation(nb) / mean(nb)
- << ", mode = " << mode(nb) << ", skew " << skewness(nb)
- // << ", mean deviation = " << "??" // perhaps todo?
- << ", kurt = " << kurtosis(nb) << endl;
- }
- { // 7.3.3 Coin flipping. What are chances that 10th head will occur at the 12th flip.
- negative_binomial nb(10, 0.5);
-
- cout << "Probability that 10th head will occur at the 12th flip is " << pdf(nb, 12-10) << endl; // 0.013428
- cout << "P(X == k) " << pdf(nb, 12-10) << endl; // 0.013428
-
- cout << "Probability that 10th head will occur before the 12th flip is " << cdf(nb, 1) << endl; //
- cout << "P(X < k) is " << cdf(nb, 1) << endl; // 1 = 12 - 11, // 0.005859
-
- cout << "Probability that 10th head will occur on or before the 12th flip is " << cdf(nb, 2) << endl; //
- cout << "P(X <= k) is " << cdf(nb, 2) << endl; // P(X <= k) = 0.01928711
-
- cout << "Probability that 10th head will occur on or after the 12th flip is " << 1 - cdf(nb, 1) << endl; //
- cout << "P(X >= k) is " << cdf(complement(nb, 12-11)) << endl; // P(X >= k) = 0.994140625
-
- cout << "Probability that 10th head will occur after the 12th flip is " << 1 - cdf(nb, 2) << endl; //
- cout << "P(X > k) is " << cdf(complement(nb, 2)) << endl; // P(X > k) 0.980713
- /*
- Probability that 10th head will occur at the 12th flip is 0.013428
- P(X == k) 0.013428
- Probability that 10th head will occur before the 12th flip is 0.005859
- P(X < k) is 0.005859
- Probability that 10th head will occur on or before the 12th flip is 0.019287
- P(X <= k) is 0.019287
- Probability that 10th head will occur on or after the 12th flip is 0.994141
- P(X >= k) is 0.994141
- Probability that 10th head will occur after the 12th flip is 0.980713
- P(X > k) is 0.980713
- */
- }
- { // Example 7.3.4, Sample up to 30 items from each lot.
- // Chances of rejecting the lot if it indeed contains 15% defectives?
- // stop at the 3rd defective, or go on to sample all 30.
- negative_binomial nb(3, 0.15); // 3rd defective.
- // probability of observing 27 or less OK items to get the 3rd defective.
- // P(X <= k) = 0.8485994
- cout << "Chance of rejecting the lot is " << cdf(nb, 27) << " if the lot actually contains 15% defectives." << endl; // 0.848599
- }
- { // K. Krishnamoorthy, ISBN 1 58488 635 8, page 101, section 7.46 confidence Intervals for the Proportion
- // 7.6.1 Shipment inspected on-by-one randomly and found 6th defective at 30th inspection.
- // 2-sided 95% confidence 0.0771355 to 0.357748
- double alpha = 0.05; // Note divide by 2 if two-sided test.
- double successes = 6;
- double failures = 24;
- double trials = successes + failures;
- double l = negative_binomial::find_lower_bound_on_p(trials, successes, alpha/2); // 0.077136
- double u = negative_binomial::find_upper_bound_on_p(trials, successes, alpha/2); // 0.357748
- // These find_ use the Clopper-Pearson approach.
- cout << (1 - alpha) * 100 << "% confidence interval low " << l << ", up " << u << endl;
- cout << "So we conclude that the true percentage of defective items is between "
- << static_cast<int>(l * 100) << " and " << setw(2) << u * 100 << "%." << endl;
-
- cout << "The rounding style for a double type is: "
- << numeric_limits<double>::round_style << endl;
- }
- { // K. Krishnamoorthy, ISBN 1 58488 635 8, page 102, section 7.4 & 7.5
- // Suppose required k + r trials to get the rth success.
- double r = 5; double k = 25; // Example 7.5.1 values
- double rm1 = r -1; // r-1 is the penultimate success.
- double p = rm1/ (rm1 + k);
- // A point estimate phat of the actual proportion of defective items.
- // 0.137931
- // 'True' estimate, if this was all the items ever available, is successes/failures = r/k = 5/25 = 0.2
- // so the point estimate 'how we are doing from the info so far' is rather less at 0.138.
- cout << "Uniformly minimum variance unbiased estimator of success probability is " << p << endl;
- double v = 0.5 * p * p * (1 - p) * (k + k + 2 - p) / (k * (k - p + 2));
- cout << "Variance of estimator is " << v << endl; // 0.000633
- cout << "Standard deviation of estimator is " << sqrt(v) << endl; // 0.025 - seems smallish?
- // Would expect point estimate 0.14 + a couple of sd = 0.25 * 2 = 0.05 = 1.9 ~= 0.2?
- // So perhaps near enough?
- }
- return 0;
-} // int main()
-
-
-/*
-
-Output is:
-
-Example 3 Negative_binomial, Krishnamoorthy applications. ..\..\..\..\..\..\boost-sandbox\math_toolkit\libs\math\example\negative_binomial_example3.cpp Wed Aug 15 11:08:14 2007
-Probability of <= 18, P(X <= 18) == cdf(18) = 0.862419
-Probability of > 18, P(X < 18) == 1 - cdf(18) = 0.137581
-Probability of > 18, P(X < 18) == 1 - cdf(18) = 0.137581
-Probability of < 18 == <= 17 == cdf(17) = 0.818017
-Probability of >= 18 == > 17 == 1 - cdf(17) = 0.181983
-Probability of >= 18 == > 17 == cdf(complement(nbk, 17)) = 0.181983
-Probability of exactly == 18, P(X =18) = pdf(18) = 0.0444024
-P(X <= k) = 0.560001
- k = 5
-Mean = 5.58918, sd = 3.66045, Coefficient of variation (sd/mean) = 0.654918, mode = 4, skew 1.03665, kurt = 4.57463
-Probability that 10th head will occur at the 12th flip is 0.0134277
-P(X == k) 0.0134277
-Probability that 10th head will occur before the 12th flip is 0.00585938
-P(X < k) is 0.00585938
-Probability that 10th head will occur on or before the 12th flip is 0.0192871
-P(X <= k) is 0.0192871
-Probability that 10th head will occur on or after the 12th flip is 0.994141
-P(X >= k) is 0.994141
-Probability that 10th head will occur after the 12th flip is 0.980713
-P(X > k) is 0.980713
-Chance of rejecting the lot is 0.848599 if the lot actually contains 15% defectives.
-95% confidence interval low 0.0771355, up 0.357748
-So we conclude that the true percentage of defective items is between 7 and 35.7748%.
-The rounding style for a double type is: 1
-Uniformly minimum variance unbiased estimator of success probability is 0.137931
-Variance of estimator is 0.000633295
-Standard deviation of estimator is 0.0251654
-P(X <= 25) = 0.744767
-13
-
-
-*/
-
-
-

Deleted: sandbox/math_toolkit/libs/math/example/statistics_functions_example1.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/example/statistics_functions_example1.cpp 2007-09-16 11:29:11 EDT (Sun, 16 Sep 2007)
+++ (empty file)
@@ -1,137 +0,0 @@
-// statistics_functions_example1.cpp
-
-// Copyright Paul A. Bristow 2006.
-
-// 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)
-
-// Example 2 of using Thorsten Ottosen's statistics function.
-// Problems using list, so abandoned in favour of Eric Niebler's accumulator.
-
-
-//#include <boost/math/special_functions/students_t.hpp>
-// using boost::math::students_t; // Probability of students_t(df, t).
-
-//#define _SCL_SECURE_NO_DEPRECATE = 1 // avoid C4996 warning.
-//#define _SCL_SECURE_NO_DEPRECATE = 0 // get C4996 warning.
-#define _SCL_SECURE_NO_DEPRECATE = 1 // no C4996 warning.
-
-#ifdef _MSC_VER// needed for Boost.Array using const double
-# pragma warning(disable: 4510) // default constructor could not be generated.
-# pragma warning(disable: 4512) // assignment operator could not be generated.
-# pragma warning(disable: 4610) // can never be instantiated - user defined constructor required.
-#endif
-
-#include <boost/array.hpp>
- using boost::array;
-#include <boost/stat/univariate.hpp> // Various basic statistics functions.
- using boost::algorithm::mean;
-
-#include <boost/math/special_functions/students_t.hpp>
- using boost::math::students_t; // Probability of students_t(df, t).
-
-#include <iostream>
- using std::cout;
- using std::endl;
-#include <iterator>
- using std::ostream_iterator;
-#include <iomanip>
- using std::setprecision;
- using std::setw;
-#include <cmath>
- using std::sqrt;
-#include <vector>
- using std::vector;
-#include <algorithm>
- using std::copy;
-#include <list>
- using std::list;
-
-int main()
-{
- cout << "Example 1 of TO's statistics functions. ";
-#if defined(__FILE__) && defined(__TIMESTAMP__)
- cout << " " << __FILE__ << ' ' << __TIMESTAMP__ << ' '<< _MSC_FULL_VER;
-#endif
- cout << endl;
-
- const int n = 5;
- double data [n] = {10.08, 10.11, 10.09, 10.10, 10.12}; // C array.
- //const array <double, n> adata = {10.08, 10.11, 10.09, 10.10, 10.12}; // Boost array c3892 connot assign to variable that is const
- array <const double, n> cddata = {10.08, 10.11, 10.09, 10.10, 10.12}; // Boost array C4510 default constructor could not be generated with const double
- //const array <const double, n> adata = {10.08, 10.11, 10.09, 10.10, 10.12}; // Boost array c4510 & c4512 assignment operator could not be generated
- // warning C4610: class 'boost::array<T,N>' can never be instantiated - user defined constructor required.
- // const array <const double, n> adata = {10.08, 10.11, 10.09, 10.10, 10.12}; // Boost array
- //array <double, n> adata = {10.08, 10.11, 10.09, 10.10, 10.12}; // Boost array
- array <double, n> adata ; // Boost array
- copy (&data[0], &data[n], adata.begin()); // Note [n] (not [n-1]) because last is 1 beyond the end.
- // copy (&data[0], &data[n], adata.begin()); can't use this if double is const!
- // Error C3892: '_Dest' : you cannot assign to a variable that is const
- copy (cddata.begin(), cddata.end(), ostream_iterator<double>(cout, " ")); cout << endl;
- double cdm = mean<double>(cddata.begin(), cddata.end());
- BOOST_ASSERT(cddata.size() == n);
- cout <<"array size is " << cddata.size() << endl;
- cout << "array mean is " << cdm << endl;
-
- copy (adata.begin(), adata.end(), ostream_iterator<double>(cout, " ")); cout << endl;
- double am = mean<double>(adata.begin(), adata.end());
- BOOST_ASSERT(adata.size() == n);
- cout <<"array size is " << adata.size() << endl;
- cout << "array mean is " << am << endl;
-
- vector <double> vdata; // Std vector
- //vector <const double> vdata; // Std vector
- // vdata = {10.08, 10.11, 10.09, 10.10, 10.12}; is NOT allowed :-((
- vdata.reserve(5);
- vdata.assign(&data[0], &data[5]);
- cout << "vdata size = " << vdata.size() << endl;
- BOOST_ASSERT(vdata.size() == n);
- //copy (adata.begin(), adata.end(), vdata.begin()); // Asserts "vector iterator not dereferencable".
- copy (vdata.begin(), vdata.end(), ostream_iterator<double>(cout, " ")); cout << endl;
- double vm = mean<double>(vdata.begin(), vdata.end());
- cout << "vector mean is " << vm << endl;
-
- using boost::algorithm::variance;
- using boost::algorithm::std_deviation;
-
- double vv = variance<double>(vdata.begin(), vdata.end());
- cout << "vector variance is " << vv << endl;
-
- double vsd = std_deviation<double>(vdata.begin(), vdata.end());
- cout << "vector std_deviation is " << vsd << endl;
-
- using boost::algorithm::sorted_median;
- using boost::algorithm::unsorted_median;
-
- // double vsm = unsorted_median<double>(vdata.begin(), vdata.end());
- //cout << "vector sorted_median is " << vsm << endl;
-
-// Using contain list doesn't yet work for me - asked Thorsten Ottosen.
- list<double> ldata;
- ldata.assign(&data[0], &data[5]);
- BOOST_ASSERT(ldata.size() == n);
- copy (ldata.begin(), ldata.end(), ostream_iterator<double>(cout, " ")); cout << endl;
- double lm = mean<double>(ldata.begin(), ldata.end());
- cout << "list mean is " << lm << endl;
-
- //double standard = 10.11;
- //double t = (mean<double>(vdata.begin(), vdata.end()) - standard)
- //* std::sqrt(static_cast<double>(n))
- /// std_deviation<double>(vdata.begin(), vdata.end());
- //cout << "Student's t = " << t << endl; // Student's t = -1.41421
- //double degrees_of_freedom = n-1;
- //cout.precision(5); // Useful accuracy is only a few decimal digits, but seems to give at least 5.
- //cout << "Probability of Student's t is " << students_t(degrees_of_freedom, abs(t)) << endl; // is 0.8849 , is 1 tailed.
- //// So there is insufficient evidence of a difference to meet a 95% (1 in 20) criterion.
-
- return 0;
-} // int main()
-
-/*
-
-Output is:
-
-
-*/


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