Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r65129 - trunk/libs/math/example
From: pbristow_at_[hidden]
Date: 2010-08-30 05:34:38


Author: pbristow
Date: 2010-08-30 05:34:36 EDT (Mon, 30 Aug 2010)
New Revision: 65129
URL: http://svn.boost.org/trac/boost/changeset/65129

Log:
Avoid name ambiguity.
Text files modified:
   trunk/libs/math/example/students_t_single_sample.cpp | 355 +++++++++++++++++++--------------------
   1 files changed, 177 insertions(+), 178 deletions(-)

Modified: trunk/libs/math/example/students_t_single_sample.cpp
==============================================================================
--- trunk/libs/math/example/students_t_single_sample.cpp (original)
+++ trunk/libs/math/example/students_t_single_sample.cpp 2010-08-30 05:34:36 EDT (Mon, 30 Aug 2010)
@@ -1,5 +1,5 @@
 // Copyright John Maddock 2006
-// Copyright Paul A. Bristow 2007
+// Copyright Paul A. Bristow 2007, 2010
 
 // Use, modification and distribution are subject to the
 // Boost Software License, Version 1.0.
@@ -12,9 +12,16 @@
 # pragma warning(disable: 4610) // can never be instantiated - user defined constructor required.
 #endif
 
+#include <boost/math/distributions/students_t.hpp>
+
+// avoid "using namespace std;" and "using namespace boost::math;"
+// to avoid potential ambiguity with names in std random.
 #include <iostream>
+using std::cout; using std::endl;
+using std::left; using std::fixed; using std::right; using std::scientific;
 #include <iomanip>
-#include <boost/math/distributions/students_t.hpp>
+using std::setw;
+using std::setprecision;
 
 void confidence_limits_on_mean(double Sm, double Sd, unsigned Sn)
 {
@@ -35,8 +42,7 @@
    // contains the true mean or it does not.
    // See http://www.itl.nist.gov/div898/handbook/eda/section3/eda352.htm
 
- using namespace std;
- using namespace boost::math;
+ using boost::math::students_t;
 
    // Print out general info:
    cout <<
@@ -86,7 +92,7 @@
       cout << fixed << setprecision(5) << setw(15) << right << Sm + w << endl;
    }
    cout << endl;
-}
+} // void confidence_limits_on_mean
 
 void single_sample_t_test(double M, double Sm, double Sd, unsigned Sn, double alpha)
 {
@@ -103,9 +109,8 @@
    // to chance. We can also test the alternative hypothesis
    // that any difference is not down to chance.
    // See http://www.itl.nist.gov/div898/handbook/eda/section3/eda352.htm
- //
- using namespace std;
- using namespace boost::math;
+
+ using boost::math::students_t;
 
    // Print header:
    cout <<
@@ -159,7 +164,7 @@
    else
       cout << "REJECTED\n";
    cout << endl << endl;
-}
+} // void single_sample_t_test(
 
 void single_sample_find_df(double M, double Sm, double Sd)
 {
@@ -168,8 +173,8 @@
    // Sm = Sample Mean.
    // Sd = Sample Standard Deviation.
    //
- using namespace std;
- using namespace boost::math;
+
+ using boost::math::students_t;
 
    // Print out general info:
    cout <<
@@ -216,7 +221,7 @@
       cout << fixed << setprecision(0) << setw(16) << right << size << endl;
    }
    cout << endl;
-}
+} // void single_sample_find_df
 
 int main()
 {
@@ -250,177 +255,171 @@
    single_sample_find_df(38.9, 37.8, 0.964365);
 
    return 0;
-}
+} // int main()
 
 /*
 
 Output:
 
------- Build started: Project: students_t_single_sample, Configuration: Debug Win32 ------
-Compiling...
-students_t_single_sample.cpp
-Linking...
-Autorun "i:\boost-06-05-03-1300\libs\math\test\Math_test\debug\students_t_single_sample.exe"
-__________________________________
-2-Sided Confidence Limits For Mean
-__________________________________
-
-Number of Observations = 195
-Mean = 9.26146
-Standard Deviation = 0.02278881
-
-
-_______________________________________________________________
-Confidence T Interval Lower Upper
- Value (%) Value Width Limit Limit
-_______________________________________________________________
- 50.000 0.676 1.103e-003 9.26036 9.26256
- 75.000 1.154 1.883e-003 9.25958 9.26334
- 90.000 1.653 2.697e-003 9.25876 9.26416
- 95.000 1.972 3.219e-003 9.25824 9.26468
- 99.000 2.601 4.245e-003 9.25721 9.26571
- 99.900 3.341 5.453e-003 9.25601 9.26691
- 99.990 3.973 6.484e-003 9.25498 9.26794
- 99.999 4.537 7.404e-003 9.25406 9.26886
-
-__________________________________
-Student t test for a single sample
-__________________________________
-
-Number of Observations = 195
-Sample Mean = 9.26146
-Sample Standard Deviation = 0.02279
-Expected True Mean = 5.00000
-
-Sample Mean - Expected Test Mean = 4.26146
-Degrees of Freedom = 194
-T Statistic = 2611.28380
-Probability that difference is due to chance = 0.000e+000
-
-Results for Alternative Hypothesis and alpha = 0.0500
-
-Alternative Hypothesis Conclusion
-Mean != 5.000 NOT REJECTED
-Mean < 5.000 REJECTED
-Mean > 5.000 NOT REJECTED
-
-
-_____________________________________________________________
-Estimated sample sizes required for various confidence levels
-_____________________________________________________________
-
-True Mean = 5.00000
-Sample Mean = 9.26146
-Sample Standard Deviation = 0.02279
-
-
-_______________________________________________________________
-Confidence Estimated Estimated
- Value (%) Sample Size Sample Size
- (one sided test) (two sided test)
-_______________________________________________________________
- 50.000 2 2
- 75.000 2 2
- 90.000 2 2
- 95.000 2 2
- 99.000 2 2
- 99.900 3 3
- 99.990 3 3
- 99.999 4 4
-
-__________________________________
-2-Sided Confidence Limits For Mean
-__________________________________
-
-Number of Observations = 3
-Mean = 37.8000000
-Standard Deviation = 0.9643650
-
-
-_______________________________________________________________
-Confidence T Interval Lower Upper
- Value (%) Value Width Limit Limit
-_______________________________________________________________
- 50.000 0.816 0.455 37.34539 38.25461
- 75.000 1.604 0.893 36.90717 38.69283
- 90.000 2.920 1.626 36.17422 39.42578
- 95.000 4.303 2.396 35.40438 40.19562
- 99.000 9.925 5.526 32.27408 43.32592
- 99.900 31.599 17.594 20.20639 55.39361
- 99.990 99.992 55.673 -17.87346 93.47346
- 99.999 316.225 176.067 -138.26683 213.86683
-
-__________________________________
-Student t test for a single sample
-__________________________________
-
-Number of Observations = 3
-Sample Mean = 37.80000
-Sample Standard Deviation = 0.96437
-Expected True Mean = 38.90000
-
-Sample Mean - Expected Test Mean = -1.10000
-Degrees of Freedom = 2
-T Statistic = -1.97566
-Probability that difference is due to chance = 1.869e-001
-
-Results for Alternative Hypothesis and alpha = 0.0500
-
-Alternative Hypothesis Conclusion
-Mean != 38.900 REJECTED
-Mean < 38.900 REJECTED
-Mean > 38.900 REJECTED
-
-
-__________________________________
-Student t test for a single sample
-__________________________________
-
-Number of Observations = 3
-Sample Mean = 37.80000
-Sample Standard Deviation = 0.96437
-Expected True Mean = 38.90000
-
-Sample Mean - Expected Test Mean = -1.10000
-Degrees of Freedom = 2
-T Statistic = -1.97566
-Probability that difference is due to chance = 1.869e-001
-
-Results for Alternative Hypothesis and alpha = 0.1000
-
-Alternative Hypothesis Conclusion
-Mean != 38.900 REJECTED
-Mean < 38.900 NOT REJECTED
-Mean > 38.900 REJECTED
-
-
-_____________________________________________________________
-Estimated sample sizes required for various confidence levels
-_____________________________________________________________
-
-True Mean = 38.90000
-Sample Mean = 37.80000
-Sample Standard Deviation = 0.96437
-
-
-_______________________________________________________________
-Confidence Estimated Estimated
- Value (%) Sample Size Sample Size
- (one sided test) (two sided test)
-_______________________________________________________________
- 75.000 3 4
- 90.000 7 9
- 95.000 11 13
- 99.000 20 22
- 99.900 35 37
- 99.990 50 53
- 99.999 66 68
-
-Build Time 0:03
-Build log was saved at "file://i:\boost-06-05-03-1300\libs\math\test\Math_test\students_t_single_sample\Debug\BuildLog.htm"
-students_t_single_sample - 0 error(s), 0 warning(s)
-========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
-
+------ Rebuild All started: Project: students_t_single_sample, Configuration: Release Win32 ------
+ students_t_single_sample.cpp
+ Generating code
+ Finished generating code
+ students_t_single_sample.vcxproj -> J:\Cpp\MathToolkit\test\Math_test\Release\students_t_single_sample.exe
+ __________________________________
+ 2-Sided Confidence Limits For Mean
+ __________________________________
+
+ Number of Observations = 195
+ Mean = 9.26146
+ Standard Deviation = 0.02278881
+
+
+ _______________________________________________________________
+ Confidence T Interval Lower Upper
+ Value (%) Value Width Limit Limit
+ _______________________________________________________________
+ 50.000 0.676 1.103e-003 9.26036 9.26256
+ 75.000 1.154 1.883e-003 9.25958 9.26334
+ 90.000 1.653 2.697e-003 9.25876 9.26416
+ 95.000 1.972 3.219e-003 9.25824 9.26468
+ 99.000 2.601 4.245e-003 9.25721 9.26571
+ 99.900 3.341 5.453e-003 9.25601 9.26691
+ 99.990 3.973 6.484e-003 9.25498 9.26794
+ 99.999 4.537 7.404e-003 9.25406 9.26886
+
+ __________________________________
+ Student t test for a single sample
+ __________________________________
+
+ Number of Observations = 195
+ Sample Mean = 9.26146
+ Sample Standard Deviation = 0.02279
+ Expected True Mean = 5.00000
+
+ Sample Mean - Expected Test Mean = 4.26146
+ Degrees of Freedom = 194
+ T Statistic = 2611.28380
+ Probability that difference is due to chance = 0.000e+000
+
+ Results for Alternative Hypothesis and alpha = 0.0500
+
+ Alternative Hypothesis Conclusion
+ Mean != 5.000 NOT REJECTED
+ Mean < 5.000 REJECTED
+ Mean > 5.000 NOT REJECTED
+
+
+ _____________________________________________________________
+ Estimated sample sizes required for various confidence levels
+ _____________________________________________________________
+
+ True Mean = 5.00000
+ Sample Mean = 9.26146
+ Sample Standard Deviation = 0.02279
+
+
+ _______________________________________________________________
+ Confidence Estimated Estimated
+ Value (%) Sample Size Sample Size
+ (one sided test) (two sided test)
+ _______________________________________________________________
+ 75.000 2 2
+ 90.000 2 2
+ 95.000 2 2
+ 99.000 2 2
+ 99.900 3 3
+ 99.990 3 3
+ 99.999 4 4
+
+ __________________________________
+ 2-Sided Confidence Limits For Mean
+ __________________________________
+
+ Number of Observations = 3
+ Mean = 37.8000000
+ Standard Deviation = 0.9643650
+
+
+ _______________________________________________________________
+ Confidence T Interval Lower Upper
+ Value (%) Value Width Limit Limit
+ _______________________________________________________________
+ 50.000 0.816 0.455 37.34539 38.25461
+ 75.000 1.604 0.893 36.90717 38.69283
+ 90.000 2.920 1.626 36.17422 39.42578
+ 95.000 4.303 2.396 35.40438 40.19562
+ 99.000 9.925 5.526 32.27408 43.32592
+ 99.900 31.599 17.594 20.20639 55.39361
+ 99.990 99.992 55.673 -17.87346 93.47346
+ 99.999 316.225 176.067 -138.26683 213.86683
+
+ __________________________________
+ Student t test for a single sample
+ __________________________________
+
+ Number of Observations = 3
+ Sample Mean = 37.80000
+ Sample Standard Deviation = 0.96437
+ Expected True Mean = 38.90000
+
+ Sample Mean - Expected Test Mean = -1.10000
+ Degrees of Freedom = 2
+ T Statistic = -1.97566
+ Probability that difference is due to chance = 1.869e-001
+
+ Results for Alternative Hypothesis and alpha = 0.0500
+
+ Alternative Hypothesis Conclusion
+ Mean != 38.900 REJECTED
+ Mean < 38.900 REJECTED
+ Mean > 38.900 REJECTED
+
+
+ __________________________________
+ Student t test for a single sample
+ __________________________________
+
+ Number of Observations = 3
+ Sample Mean = 37.80000
+ Sample Standard Deviation = 0.96437
+ Expected True Mean = 38.90000
+
+ Sample Mean - Expected Test Mean = -1.10000
+ Degrees of Freedom = 2
+ T Statistic = -1.97566
+ Probability that difference is due to chance = 1.869e-001
+
+ Results for Alternative Hypothesis and alpha = 0.1000
+
+ Alternative Hypothesis Conclusion
+ Mean != 38.900 REJECTED
+ Mean < 38.900 NOT REJECTED
+ Mean > 38.900 REJECTED
+
+
+ _____________________________________________________________
+ Estimated sample sizes required for various confidence levels
+ _____________________________________________________________
+
+ True Mean = 38.90000
+ Sample Mean = 37.80000
+ Sample Standard Deviation = 0.96437
+
+
+ _______________________________________________________________
+ Confidence Estimated Estimated
+ Value (%) Sample Size Sample Size
+ (one sided test) (two sided test)
+ _______________________________________________________________
+ 75.000 3 4
+ 90.000 7 9
+ 95.000 11 13
+ 99.000 20 22
+ 99.900 35 37
+ 99.990 50 53
+ 99.999 66 68
+
 
 */
 


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