Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r63330 - in trunk: boost/random libs/random/doc libs/random/test
From: steven_at_[hidden]
Date: 2010-06-25 19:53:36


Author: steven_watanabe
Date: 2010-06-25 19:53:34 EDT (Fri, 25 Jun 2010)
New Revision: 63330
URL: http://svn.boost.org/trac/boost/changeset/63330

Log:
Add extreme_value_distribution.
Added:
   trunk/boost/random/extreme_value_distribution.hpp
      - copied, changed from r63328, /trunk/boost/random/weibull_distribution.hpp
   trunk/libs/random/test/test_extreme_value.cpp
      - copied, changed from r63328, /trunk/libs/random/test/test_weibull.cpp
   trunk/libs/random/test/test_extreme_value_distribution.cpp
      - copied, changed from r63328, /trunk/libs/random/test/test_weibull_distribution.cpp
Text files modified:
   trunk/boost/random/extreme_value_distribution.hpp | 60 +++++++++++++++---------------
   trunk/libs/random/doc/Jamfile.v2 | 1
   trunk/libs/random/doc/distributions.qbk | 1
   trunk/libs/random/doc/random.qbk | 1
   trunk/libs/random/test/Jamfile.v2 | 2 +
   trunk/libs/random/test/test_extreme_value.cpp | 18 ++++----
   trunk/libs/random/test/test_extreme_value_distribution.cpp | 80 +++++++++++++++++++---------------------
   7 files changed, 82 insertions(+), 81 deletions(-)

Copied: trunk/boost/random/extreme_value_distribution.hpp (from r63328, /trunk/boost/random/weibull_distribution.hpp)
==============================================================================
--- /trunk/boost/random/weibull_distribution.hpp (original)
+++ trunk/boost/random/extreme_value_distribution.hpp 2010-06-25 19:53:34 EDT (Fri, 25 Jun 2010)
@@ -1,4 +1,4 @@
-/* boost random/weibull_distribution.hpp header file
+/* boost random/extreme_value_distribution.hpp header file
  *
  * Copyright Steven Watanabe 2010
  * Distributed under the Boost Software License, Version 1.0. (See
@@ -10,8 +10,8 @@
  * $Id$
  */
 
-#ifndef BOOST_RANDOM_WEIBULL_DISTRIBUTION_HPP
-#define BOOST_RANDOM_WEIBULL_DISTRIBUTION_HPP
+#ifndef BOOST_RANDOM_EXTREME_VALUE_DISTRIBUTION_HPP
+#define BOOST_RANDOM_EXTREME_VALUE_DISTRIBUTION_HPP
 
 #include <boost/config/no_tr1/cmath.hpp>
 #include <iosfwd>
@@ -25,26 +25,26 @@
 namespace random {
 
 /**
- * The Weibull distribution is a real valued distribution with two
- * parameters a and b, producing values >= 0.
+ * The extreme value distribution is a real valued distribution with two
+ * parameters a and b.
  *
- * It has \f$\displaystyle p(x) = \frac{a}{b}\left(\frac{x}{b}\right)^{a-1}e^{-\left(\frac{x}{b}\right)^a}\f$.
+ * It has \f$\displaystyle p(x) = \frac{1}{b}e^{\frac{a-x}{b} - e^\frac{a-x}{b}}\f$.
  */
 template<class RealType = double>
-class weibull_distribution {
+class extreme_value_distribution {
 public:
     typedef RealType result_type;
     typedef RealType input_type;
 
     class param_type {
     public:
- typedef weibull_distribution distribution_type;
+ typedef extreme_value_distribution distribution_type;
 
         /**
          * Constructs a @c param_type from the "a" and "b" parameters
          * of the distribution.
          *
- * Requires: a > 0 && b > 0
+ * Requires: b > 0
          */
         explicit param_type(RealType a_arg = 1.0, RealType b_arg = 1.0)
           : _a(a_arg), _b(b_arg)
@@ -76,38 +76,37 @@
     };
 
     /**
- * Constructs a @c weibull_distribution from its "a" and "b" parameters.
+ * Constructs an @c extreme_value_distribution from its "a" and "b" parameters.
      *
- * Requires: a > 0 && b > 0
+ * Requires: b > 0
      */
- explicit weibull_distribution(RealType a_arg = 1.0, RealType b_arg = 1.0)
+ explicit extreme_value_distribution(RealType a_arg = 1.0, RealType b_arg = 1.0)
       : _a(a_arg), _b(b_arg)
     {}
- /** Constructs a @c weilbull_distribution from its parameters. */
- explicit weibull_distribution(const param_type& parm)
+ /** Constructs an @c extreme_value_distribution from its parameters. */
+ explicit extreme_value_distribution(const param_type& parm)
       : _a(parm.a()), _b(parm.b())
     {}
 
     /**
      * Returns a random variate distributed according to the
- * @c weibull_distribution.
+ * @c extreme_value_distribution.
      */
     template<class URNG>
     RealType operator()(URNG& urng) const
     {
- using std::pow;
         using std::log;
- return _b*pow(-log(1 - uniform_01<RealType>()(urng)), 1/_a);
+ return _a - log(-log(uniform_01<RealType>()(urng))) * _b;
     }
 
     /**
- * Returns a random variate distributed accordint to the Weibull
- * distribution with parameters specified by @c parm.
+ * Returns a random variate distributed accordint to the extreme
+ * value distribution with parameters specified by @c parm.
      */
     template<class URNG>
     RealType operator()(URNG& urng, const param_type& parm) const
     {
- return weibull_distribution(parm)(urng);
+ return extreme_value_distribution(parm)(urng);
     }
 
     /** Returns the "a" parameter of the distribution. */
@@ -116,7 +115,8 @@
     RealType b() const { return _b; }
 
     /** Returns the smallest value that the distribution can produce. */
- RealType min BOOST_PREVENT_MACRO_SUBSTITUTION () { return 0; }
+ RealType min BOOST_PREVENT_MACRO_SUBSTITUTION ()
+ { return -std::numeric_limits<RealType>::infinity(); }
     /** Returns the largest value that the distribution can produce. */
     RealType max BOOST_PREVENT_MACRO_SUBSTITUTION ()
     { return std::numeric_limits<RealType>::infinity(); }
@@ -130,15 +130,15 @@
         _b = parm.b();
     }
 
- /** Writes a @c weibull_distribution to a @c std::ostream. */
- BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, weibull_distribution, wd)
+ /** Writes an @c extreme_value_distribution to a @c std::ostream. */
+ BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, extreme_value_distribution, wd)
     {
         os << wd.param();
         return os;
     }
 
- /** Reads a @c weibull_distribution from a @c std::istream. */
- BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, weibull_distribution, wd)
+ /** Reads an @c extreme_value_distribution from a @c std::istream. */
+ BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, extreme_value_distribution, wd)
     {
         param_type parm;
         if(is >> parm) {
@@ -148,17 +148,17 @@
     }
 
     /**
- * Returns true if the two instances of @c weibull_distribution will
+ * Returns true if the two instances of @c extreme_value_distribution will
      * return identical sequences of values given equal generators.
      */
- BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(weibull_distribution, lhs, rhs)
+ BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(extreme_value_distribution, lhs, rhs)
     { return lhs._a == rhs._a && lhs._b == rhs._b; }
     
     /**
- * Returns true if the two instances of @c weibull_distribution will
+ * Returns true if the two instances of @c extreme_value_distribution will
      * return different sequences of values given equal generators.
      */
- BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(weibull_distribution)
+ BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(extreme_value_distribution)
 
 private:
     RealType _a;
@@ -168,4 +168,4 @@
 } // namespace random
 } // namespace boost
 
-#endif // BOOST_RANDOM_WEIBULL_DISTRIBUTION_HPP
+#endif // BOOST_RANDOM_EXTREME_VALUE_DISTRIBUTION_HPP

Modified: trunk/libs/random/doc/Jamfile.v2
==============================================================================
--- trunk/libs/random/doc/Jamfile.v2 (original)
+++ trunk/libs/random/doc/Jamfile.v2 2010-06-25 19:53:34 EDT (Fri, 25 Jun 2010)
@@ -22,6 +22,7 @@
     discard_block
     discrete_distribution
     exponential_distribution
+ extreme_value_distribution
     gamma_distribution
     geometric_distribution
     inversive_congruential

Modified: trunk/libs/random/doc/distributions.qbk
==============================================================================
--- trunk/libs/random/doc/distributions.qbk (original)
+++ trunk/libs/random/doc/distributions.qbk 2010-06-25 19:53:34 EDT (Fri, 25 Jun 2010)
@@ -67,6 +67,7 @@
                               [measuring the job completion time of an assembly
                                line worker]]
   [[__weibull_distribution] [weibull distribution] [-]]
+ [[__extreme_value_distribution] [extreme value distribution] [-]]
   [[__uniform_on_sphere] [uniform distribution on a unit sphere of arbitrary
                           dimension]
                          [choosing a random point on Earth (assumed to be a

Modified: trunk/libs/random/doc/random.qbk
==============================================================================
--- trunk/libs/random/doc/random.qbk (original)
+++ trunk/libs/random/doc/random.qbk 2010-06-25 19:53:34 EDT (Fri, 25 Jun 2010)
@@ -78,6 +78,7 @@
 [def __lognormal_distribution [classref boost::lognormal_distribution lognormal_distribution]]
 [def __uniform_on_sphere [classref boost::uniform_on_sphere uniform_on_sphere]]
 [def __weibull_distribution [classref boost::random::weibull_distribution weibull_distribution]]
+[def __extreme_value_distribution [classref boost::random::extreme_value_distribution extreme_value_distribution]]
 
 [include performance_data.qbk]
 

Modified: trunk/libs/random/test/Jamfile.v2
==============================================================================
--- trunk/libs/random/test/Jamfile.v2 (original)
+++ trunk/libs/random/test/Jamfile.v2 2010-06-25 19:53:34 EDT (Fri, 25 Jun 2010)
@@ -56,6 +56,8 @@
 run test_gamma_distribution.cpp /boost//unit_test_framework ;
 run test_weibull.cpp ;
 run test_weibull_distribution.cpp /boost//unit_test_framework ;
+run test_extreme_value.cpp ;
+run test_extreme_value_distribution.cpp /boost//unit_test_framework ;
 
 # run nondet_random_speed.cpp ;
 # run random_device.cpp ;

Copied: trunk/libs/random/test/test_extreme_value.cpp (from r63328, /trunk/libs/random/test/test_weibull.cpp)
==============================================================================
--- /trunk/libs/random/test/test_weibull.cpp (original)
+++ trunk/libs/random/test/test_extreme_value.cpp 2010-06-25 19:53:34 EDT (Fri, 25 Jun 2010)
@@ -1,4 +1,4 @@
-/* test_gamma.cpp
+/* test_extreme_value.cpp
  *
  * Copyright Steven Watanabe 2010
  * Distributed under the Boost Software License, Version 1.0. (See
@@ -9,11 +9,11 @@
  *
  */
 
-#include <boost/random/weibull_distribution.hpp>
+#include <boost/random/extreme_value_distribution.hpp>
 #include <boost/random/uniform_int.hpp>
 #include <boost/random/uniform_01.hpp>
 #include <boost/random/mersenne_twister.hpp>
-#include <boost/math/distributions/weibull.hpp>
+#include <boost/math/distributions/extreme_value.hpp>
 #include <boost/lexical_cast.hpp>
 #include <boost/exception/diagnostic_information.hpp>
 #include <vector>
@@ -22,15 +22,15 @@
 
 #include "statistic_tests.hpp"
 
-bool do_test(double alpha, double beta, int max) {
- std::cout << "running gamma(" << alpha << ", " << beta << ")" << " " << max << " times: " << std::flush;
+bool do_test(double a, double b, int max) {
+ std::cout << "running extreme_value(" << a << ", " << b << ")" << " " << max << " times: " << std::flush;
 
- boost::math::weibull_distribution<> expected(alpha, beta);
+ boost::math::extreme_value_distribution<> expected(a, b);
     
- boost::random::weibull_distribution<> dist(alpha, beta);
+ boost::random::extreme_value_distribution<> dist(a, b);
     boost::mt19937 gen;
     kolmogorov_experiment test(max);
- boost::variate_generator<boost::mt19937&, boost::random::weibull_distribution<> > vgen(gen, dist);
+ boost::variate_generator<boost::mt19937&, boost::random::extreme_value_distribution<> > vgen(gen, dist);
 
     double prob = test.probability(test.run(vgen, expected));
 
@@ -60,7 +60,7 @@
 }
 
 int usage() {
- std::cerr << "Usage: test_weibull -r <repeat> -a <max a> -b <max b> -t <trials>" << std::endl;
+ std::cerr << "Usage: test_extreme_value -r <repeat> -a <max a> -b <max b> -t <trials>" << std::endl;
     return 2;
 }
 

Copied: trunk/libs/random/test/test_extreme_value_distribution.cpp (from r63328, /trunk/libs/random/test/test_weibull_distribution.cpp)
==============================================================================
--- /trunk/libs/random/test/test_weibull_distribution.cpp (original)
+++ trunk/libs/random/test/test_extreme_value_distribution.cpp 2010-06-25 19:53:34 EDT (Fri, 25 Jun 2010)
@@ -1,4 +1,4 @@
-/* test_gamma_distribution.cpp
+/* test_extreme_value_distribution.cpp
  *
  * Copyright Steven Watanabe 2010
  * Distributed under the Boost Software License, Version 1.0. (See
@@ -9,7 +9,7 @@
  *
  */
 
-#include <boost/random/weibull_distribution.hpp>
+#include <boost/random/extreme_value_distribution.hpp>
 #include <boost/random/linear_congruential.hpp>
 #include <sstream>
 
@@ -17,74 +17,74 @@
 #include <boost/test/unit_test.hpp>
 
 BOOST_AUTO_TEST_CASE(test_constructors) {
- boost::random::weibull_distribution<> dist;
+ boost::random::extreme_value_distribution<> dist;
     BOOST_CHECK_EQUAL(dist.a(), 1.0);
     BOOST_CHECK_EQUAL(dist.b(), 1.0);
- boost::random::weibull_distribution<> dist_one(7.5);
+ boost::random::extreme_value_distribution<> dist_one(7.5);
     BOOST_CHECK_EQUAL(dist_one.a(), 7.5);
     BOOST_CHECK_EQUAL(dist_one.b(), 1.0);
- boost::random::weibull_distribution<> dist_two(7.5, 0.25);
+ boost::random::extreme_value_distribution<> dist_two(7.5, 0.25);
     BOOST_CHECK_EQUAL(dist_two.a(), 7.5);
     BOOST_CHECK_EQUAL(dist_two.b(), 0.25);
- boost::random::weibull_distribution<> copy(dist);
+ boost::random::extreme_value_distribution<> copy(dist);
     BOOST_CHECK_EQUAL(dist, copy);
- boost::random::weibull_distribution<> copy_one(dist_one);
+ boost::random::extreme_value_distribution<> copy_one(dist_one);
     BOOST_CHECK_EQUAL(dist_one, copy_one);
- boost::random::weibull_distribution<> copy_two(dist_two);
+ boost::random::extreme_value_distribution<> copy_two(dist_two);
     BOOST_CHECK_EQUAL(dist_two, copy_two);
 }
 
 BOOST_AUTO_TEST_CASE(test_param) {
- boost::random::weibull_distribution<> dist(7.5, 0.25);
- boost::random::weibull_distribution<>::param_type param = dist.param();
+ boost::random::extreme_value_distribution<> dist(7.5, 0.25);
+ boost::random::extreme_value_distribution<>::param_type param = dist.param();
     BOOST_CHECK_EQUAL(param.a(), 7.5);
     BOOST_CHECK_EQUAL(param.b(), 0.25);
- boost::random::weibull_distribution<> copy1(param);
+ boost::random::extreme_value_distribution<> copy1(param);
     BOOST_CHECK_EQUAL(dist, copy1);
- boost::random::weibull_distribution<> copy2;
+ boost::random::extreme_value_distribution<> copy2;
     copy2.param(param);
     BOOST_CHECK_EQUAL(dist, copy2);
 
- boost::random::weibull_distribution<>::param_type param_copy = param;
+ boost::random::extreme_value_distribution<>::param_type param_copy = param;
     BOOST_CHECK_EQUAL(param, param_copy);
     BOOST_CHECK(param == param_copy);
     BOOST_CHECK(!(param != param_copy));
- boost::random::weibull_distribution<>::param_type param_default;
+ boost::random::extreme_value_distribution<>::param_type param_default;
     BOOST_CHECK_EQUAL(param_default.a(), 1.0);
     BOOST_CHECK_EQUAL(param_default.b(), 1.0);
     BOOST_CHECK(param != param_default);
     BOOST_CHECK(!(param == param_default));
- boost::random::weibull_distribution<>::param_type param_one(7.5);
+ boost::random::extreme_value_distribution<>::param_type param_one(7.5);
     BOOST_CHECK_EQUAL(param_one.a(), 7.5);
     BOOST_CHECK_EQUAL(param_one.b(), 1.0);
     BOOST_CHECK(param != param_one);
     BOOST_CHECK(!(param == param_one));
     BOOST_CHECK(param_default != param_one);
     BOOST_CHECK(!(param_default == param_one));
- boost::random::weibull_distribution<>::param_type param_two(7.5, 0.25);
+ boost::random::extreme_value_distribution<>::param_type param_two(7.5, 0.25);
     BOOST_CHECK_EQUAL(param_two.a(), 7.5);
     BOOST_CHECK_EQUAL(param_two.b(), 0.25);
 }
 
 BOOST_AUTO_TEST_CASE(test_min_max) {
- boost::random::weibull_distribution<> dist;
- BOOST_CHECK_EQUAL((dist.min)(), 0);
+ boost::random::extreme_value_distribution<> dist;
+ BOOST_CHECK_EQUAL((dist.min)(), -(std::numeric_limits<double>::infinity)());
     BOOST_CHECK_EQUAL((dist.max)(), (std::numeric_limits<double>::infinity)());
- boost::random::weibull_distribution<> dist_one(7.5);
- BOOST_CHECK_EQUAL((dist_one.min)(), 0);
+ boost::random::extreme_value_distribution<> dist_one(7.5);
+ BOOST_CHECK_EQUAL((dist_one.min)(), -(std::numeric_limits<double>::infinity)());
     BOOST_CHECK_EQUAL((dist_one.max)(), (std::numeric_limits<double>::infinity)());
- boost::random::weibull_distribution<> dist_two(7.5, 0.25);
- BOOST_CHECK_EQUAL((dist_two.min)(), 0);
+ boost::random::extreme_value_distribution<> dist_two(7.5, 0.25);
+ BOOST_CHECK_EQUAL((dist_two.min)(), -(std::numeric_limits<double>::infinity)());
     BOOST_CHECK_EQUAL((dist_two.max)(), (std::numeric_limits<double>::infinity)());
 }
 
 BOOST_AUTO_TEST_CASE(test_comparison) {
- boost::random::weibull_distribution<> dist;
- boost::random::weibull_distribution<> dist_copy(dist);
- boost::random::weibull_distribution<> dist_one(7.5);
- boost::random::weibull_distribution<> dist_one_copy(dist_one);
- boost::random::weibull_distribution<> dist_two(7.5, 0.25);
- boost::random::weibull_distribution<> dist_two_copy(dist_two);
+ boost::random::extreme_value_distribution<> dist;
+ boost::random::extreme_value_distribution<> dist_copy(dist);
+ boost::random::extreme_value_distribution<> dist_one(7.5);
+ boost::random::extreme_value_distribution<> dist_one_copy(dist_one);
+ boost::random::extreme_value_distribution<> dist_two(7.5, 0.25);
+ boost::random::extreme_value_distribution<> dist_two_copy(dist_two);
     BOOST_CHECK(dist == dist_copy);
     BOOST_CHECK(!(dist != dist_copy));
     BOOST_CHECK(dist_one == dist_one_copy);
@@ -100,33 +100,29 @@
 }
 
 BOOST_AUTO_TEST_CASE(test_streaming) {
- boost::random::weibull_distribution<> dist(7.5, 0.25);
+ boost::random::extreme_value_distribution<> dist(7.5, 0.25);
     std::stringstream stream;
     stream << dist;
- boost::random::weibull_distribution<> restored_dist;
+ boost::random::extreme_value_distribution<> restored_dist;
     stream >> restored_dist;
     BOOST_CHECK_EQUAL(dist, restored_dist);
 }
 
 BOOST_AUTO_TEST_CASE(test_generation) {
     boost::minstd_rand0 gen;
- boost::random::weibull_distribution<> dist;
- boost::random::weibull_distribution<> dist_two(1.0, 1000000.0);
+ boost::random::extreme_value_distribution<> dist(-100.0);
+ boost::random::extreme_value_distribution<> dist_two(100.0);
     for(int i = 0; i < 10; ++i) {
         // This test is not guaranteed to work, since
- // a weibull distribution with a large scale parameter
- // can produce small values and a distribution with
- // a small scale can produce large values, but the
- // chances of failure are small.
+ // a extreme value distribution with a large location
+ // parameter can produce small values and vice versa
         double value = dist(gen);
- BOOST_CHECK_GE(value, 0.0);
- BOOST_CHECK_LE(value, 100.0);
+ BOOST_CHECK_LE(value, 0.0);
         double value_two = dist_two(gen);
- BOOST_CHECK_GE(value_two, 100.0);
+ BOOST_CHECK_GE(value_two, 0.0);
         double value_param = dist_two(gen, dist.param());
- BOOST_CHECK_GE(value_param, 0);
- BOOST_CHECK_LE(value_param, 100.0);
+ BOOST_CHECK_LE(value_param, 0.0);
         double value_two_param = dist(gen, dist_two.param());
- BOOST_CHECK_GE(value_two_param, 100.0);
+ BOOST_CHECK_GE(value_two_param, 0.0);
     }
 }


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