Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r66765 - trunk/libs/math/example
From: pbristow_at_[hidden]
Date: 2010-11-26 05:23:24


Author: pbristow
Date: 2010-11-26 05:23:23 EST (Fri, 26 Nov 2010)
New Revision: 66765
URL: http://svn.boost.org/trac/boost/changeset/66765

Log:
Removed diagnostic output for gcc.
Text files modified:
   trunk/libs/math/example/inverse_chi_squared_example.cpp | 91 ++++++++-------------------------------
   1 files changed, 20 insertions(+), 71 deletions(-)

Modified: trunk/libs/math/example/inverse_chi_squared_example.cpp
==============================================================================
--- trunk/libs/math/example/inverse_chi_squared_example.cpp (original)
+++ trunk/libs/math/example/inverse_chi_squared_example.cpp 2010-11-26 05:23:23 EST (Fri, 26 Nov 2010)
@@ -63,13 +63,12 @@
 RealType naive_pdf4(RealType df, RealType scale, RealType x)
 { // Formula from http://mathworld.wolfram.com/InverseChi-SquaredDistribution.html
   // Weisstein, Eric W. "Inverse Chi-Squared Distribution." From MathWorld--A Wolfram Web Resource.
-
   // *Scaled* version, definition 3, df aka nu, scale aka sigma^2
   // using tgamma for simplicity as a check.
    using namespace std; // For ADL of std functions.
    using boost::math::tgamma;
- RealType nu = df; // Wolfram greek symbols.
- RealType xi = scale;
+ RealType nu = df; // Wolfram uses greek symbols nu,
+ RealType xi = scale; // and xi.
    RealType result =
      pow(2, -nu/2) * exp(- (nu * xi)/(2 * x)) * pow(x, -1-nu/2) * pow((nu * xi), nu/2)
      / tgamma(nu/2);
@@ -81,9 +80,11 @@
 
   cout << "Example (basic) using Inverse chi squared distribution. " << endl;
 
- cout.precision(std::numeric_limits<double>::max_digits10); //
+ // TODO find a more practial/useful example. Suggestions welcome?
+
   int i = std::numeric_limits<double>::max_digits10;
   cout << "Show all potentially significant decimal digits std::numeric_limits<double>::max_digits10 = " << i << endl;
+ cout.precision(std::numeric_limits<double>::max_digits10); //
 
   inverse_chi_squared ichsqdef; // All defaults - not very useful!
   cout << "default df = " << ichsqdef.degrees_of_freedom()
@@ -100,8 +101,8 @@
   {
     cout.precision(3);
     double nu = 5.;
- double scale1 = 1./ nu; // 1st definition sigma^2 = 1/df;
- double scale2 = 1.; // 2nd definition sigma^2 = 1
+ //double scale1 = 1./ nu; // 1st definition sigma^2 = 1/df;
+ //double scale2 = 1.; // 2nd definition sigma^2 = 1
     inverse_chi_squared ichsq(nu, 1/nu); // Not scaled
     inverse_chi_squared sichsq(nu, 1/nu); // scaled
 
@@ -109,18 +110,19 @@
 
     int width = 8;
 
- cout << " x pdf(inchsq) pdf1 pdf2 pdf(scaled) pdf pdf cdf" << endl;
+ cout << " x pdf pdf1 pdf2 pdf(scaled) pdf pdf cdf cdf" << endl;
     for (double x = 0.0; x < 1.; x += 0.1)
     {
       cout
- << setw(width) << x << ' ' << setw(width) << pdf(ichsq, x) // unscaled
- << ' ' << setw(width) << naive_pdf1(nu, 1/nu, x) // Wiki def 1 unscaled matches graph
- << ' ' << setw(width) << naive_pdf2(nu, scale2, x) // scale = 1 - 2nd definition.
+ << setw(width) << x
+ << ' ' << setw(width) << pdf(ichsq, x) // unscaled
+ << ' ' << setw(width) << naive_pdf1(nu, x) // Wiki def 1 unscaled matches graph
+ << ' ' << setw(width) << naive_pdf2(nu, x) // scale = 1 - 2nd definition.
         << ' ' << setw(width) << naive_pdf3(nu, 1/nu, x) // scaled
         << ' ' << setw(width) << naive_pdf4(nu, 1/nu, x) // scaled
         << ' ' << setw(width) << pdf(sichsq, x) // scaled
         << ' ' << setw(width) << cdf(sichsq, x) // scaled
- << ' ' << setw(width) << cdf(ichsq, x)
+ << ' ' << setw(width) << cdf(ichsq, x) // unscaled
        << endl;
     }
   }
@@ -128,8 +130,8 @@
   cout.precision(std::numeric_limits<double>::max_digits10);
 
   inverse_chi_squared ichisq(2., 0.5);
-
- cout << cdf(ichisq, 1.) << endl;
+ cout << "pdf(ichisq, 1.) = " << pdf(ichisq, 1.) << endl;
+ cout << "cdf(ichisq, 1.) = " << cdf(ichisq, 1.) << endl;
 
   return 0;
 } // int main()
@@ -137,13 +139,13 @@
 /*
 
 Output is:
- Example (basic) using Inverse chi squared distribution.
+ Example (basic) using Inverse chi squared distribution.
   Show all potentially significant decimal digits std::numeric_limits<double>::max_digits10 = 17
   default df = 1, default scale = 1
   default df = 4, default scale = 0.25
   default df = 3, default scale = 2
   nu = 5, scale = 0.2
- x pdf(inchsq) pdf1 pdf2 pdf(scaled) pdf pdf cdf
+ x pdf pdf1 pdf2 pdf(scaled) pdf pdf cdf cdf
          0 0 -1.#J -1.#J -1.#J -1.#J 0 0 0
        0.1 2.83 2.83 3.26e-007 2.83 2.83 2.83 0.0752 0.0752
        0.2 3.05 3.05 0.00774 3.05 3.05 3.05 0.416 0.416
@@ -155,61 +157,8 @@
        0.8 0.155 0.155 0.713 0.155 0.155 0.155 0.94 0.94
        0.9 0.11 0.11 0.668 0.11 0.11 0.11 0.953 0.953
          1 0.0807 0.0807 0.61 0.0807 0.0807 0.0807 0.963 0.963
+ pdf(ichisq, 1.) = 0.30326532985631671
+ cdf(ichisq, 1.) = 0.60653065971263365
 
-*/
-
-
-/* Parked temporary.
- double df = 5.;
- double x = 0.2;
- // Construction using default RealType double, and default shape and scale..
- inverse_chi_squared_distribution<> my_inverse_chi_squared(df); // (nu)
-
- cout << "my_inverse_chi_squared.degrees_of_freedom() = " << my_inverse_chi_squared.degrees_of_freedom() << endl;
- cout << "x = " << x << ", pdf = " << pdf(my_inverse_chi_squared, x)
- << ", cdf = " << cdf(my_inverse_chi_squared, x)
- << endl;
-
- // Construct using typedef and default shape and scale parameters.
-
- // Example of providing an 'out of domain' or 'bad' parameter,
- // here a degrees of freedom = 2, for which mean is not defined.
- // Try block is essential to catch the exception message.
- // (Uses the default policy which is to throw on all errors).
- try
- {
- inverse_chi_squared ic2(2);
- cout << "degrees of freedom(ic2) = " << ic2.degrees_of_freedom() << endl;
 
- cout << "mean(ic2) = " << mean(ic2) << endl;
- }
- catch(const std::exception& e)
- { // Always useful to include try & catch blocks because default policies
- // are to throw exceptions on arguments that cause errors like underflow, overflow.
- // Lacking try & catch blocks, the program will abort without a message below,
- // which may give some helpful clues as to the cause of the exception.
- std::cout <<
- "\n""Message from thrown exception was:\n " << e.what() << std::endl;
- }
-
- // Example of providing an 'out of domain' or 'bad' parameter,
- // here a degrees of freedom < 0, for which mean is not defined.
- // Try block is essential to catch the exception message.
- // (Uses the default policy which is to throw on all errors).
- try
- {
- inverse_chi_squared icm1(-1);
-
- }
- catch(const std::exception& e)
- { // Always useful to include try & catch blocks because default policies
- // are to throw exceptions on arguments that cause errors like underflow, overflow.
- // Lacking try & catch blocks, the program will abort without a message below,
- // which may give some helpful clues as to the cause of the exception.
- std::cout <<
- "\n""Message from thrown exception was:\n " << e.what() << std::endl;
- // Message from thrown exception was:
- // Error in function boost::math::variance(const inverse_gamma_distribution<double>&):
- // Shape parameter is 1.8999999999999999, but must be > 2!
- }
- */
\ No newline at end of file
+*/
\ No newline at end of file


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