]> AND Private Git Repository - canny.git/blob - stc/exp/ml_stc_linux_make_v1.0/include/boost/random/lognormal_distribution.hpp
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
72932cfcb5f0147726b61659d56f355191087d3c
[canny.git] / stc / exp / ml_stc_linux_make_v1.0 / include / boost / random / lognormal_distribution.hpp
1 /* boost random/lognormal_distribution.hpp header file\r
2  *\r
3  * Copyright Jens Maurer 2000-2001\r
4  * Distributed under the Boost Software License, Version 1.0. (See\r
5  * accompanying file LICENSE_1_0.txt or copy at\r
6  * http://www.boost.org/LICENSE_1_0.txt)\r
7  *\r
8  * See http://www.boost.org for most recent version including documentation.\r
9  *\r
10  * $Id: lognormal_distribution.hpp 52492 2009-04-19 14:55:57Z steven_watanabe $\r
11  *\r
12  * Revision history\r
13  *  2001-02-18  moved to individual header files\r
14  */\r
15 \r
16 #ifndef BOOST_RANDOM_LOGNORMAL_DISTRIBUTION_HPP\r
17 #define BOOST_RANDOM_LOGNORMAL_DISTRIBUTION_HPP\r
18 \r
19 #include <boost/config/no_tr1/cmath.hpp>      // std::exp, std::sqrt\r
20 #include <cassert>\r
21 #include <iostream>\r
22 #include <boost/limits.hpp>\r
23 #include <boost/static_assert.hpp>\r
24 #include <boost/random/detail/config.hpp>\r
25 #include <boost/random/normal_distribution.hpp>\r
26 \r
27 #ifdef BOOST_NO_STDC_NAMESPACE\r
28 namespace std {\r
29   using ::log;\r
30   using ::sqrt;\r
31 }\r
32 #endif\r
33 \r
34 namespace boost {\r
35 \r
36 #if defined(__GNUC__) && (__GNUC__ < 3)\r
37 // Special gcc workaround: gcc 2.95.x ignores using-declarations\r
38 // in template classes (confirmed by gcc author Martin v. Loewis)\r
39   using std::sqrt;\r
40   using std::exp;\r
41 #endif\r
42 \r
43 template<class RealType = double>\r
44 class lognormal_distribution\r
45 {\r
46 public:\r
47   typedef typename normal_distribution<RealType>::input_type input_type;\r
48   typedef RealType result_type;\r
49 \r
50 #ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS\r
51     BOOST_STATIC_ASSERT(!std::numeric_limits<RealType>::is_integer);\r
52 #endif\r
53 \r
54   explicit lognormal_distribution(result_type mean_arg = result_type(1),\r
55                                   result_type sigma_arg = result_type(1))\r
56     : _mean(mean_arg), _sigma(sigma_arg)\r
57   { \r
58     assert(_mean > result_type(0));\r
59     init();\r
60   }\r
61 \r
62   // compiler-generated copy ctor and assignment operator are fine\r
63 \r
64   RealType mean() const { return _mean; }\r
65   RealType sigma() const { return _sigma; }\r
66   void reset() { _normal.reset(); }\r
67 \r
68   template<class Engine>\r
69   result_type operator()(Engine& eng)\r
70   {\r
71 #ifndef BOOST_NO_STDC_NAMESPACE\r
72     // allow for Koenig lookup\r
73     using std::exp;\r
74 #endif\r
75     return exp(_normal(eng) * _nsigma + _nmean);\r
76   }\r
77 \r
78 #ifndef BOOST_RANDOM_NO_STREAM_OPERATORS\r
79   template<class CharT, class Traits>\r
80   friend std::basic_ostream<CharT,Traits>&\r
81   operator<<(std::basic_ostream<CharT,Traits>& os, const lognormal_distribution& ld)\r
82   {\r
83     os << ld._normal << " " << ld._mean << " " << ld._sigma;\r
84     return os;\r
85   }\r
86 \r
87   template<class CharT, class Traits>\r
88   friend std::basic_istream<CharT,Traits>&\r
89   operator>>(std::basic_istream<CharT,Traits>& is, lognormal_distribution& ld)\r
90   {\r
91     is >> std::ws >> ld._normal >> std::ws >> ld._mean >> std::ws >> ld._sigma;\r
92     ld.init();\r
93     return is;\r
94   }\r
95 #endif\r
96 \r
97 private:\r
98   void init()\r
99   {\r
100 #ifndef BOOST_NO_STDC_NAMESPACE\r
101     // allow for Koenig lookup\r
102     using std::exp; using std::log; using std::sqrt;\r
103 #endif\r
104     _nmean = log(_mean*_mean/sqrt(_sigma*_sigma + _mean*_mean));\r
105     _nsigma = sqrt(log(_sigma*_sigma/_mean/_mean+result_type(1)));\r
106   }\r
107 \r
108   RealType _mean, _sigma;\r
109   RealType _nmean, _nsigma;\r
110   normal_distribution<result_type> _normal;\r
111 };\r
112 \r
113 } // namespace boost\r
114 \r
115 #endif // BOOST_RANDOM_LOGNORMAL_DISTRIBUTION_HPP\r