source: trunk/yat/random/ContinuousDistribution.h @ 3900

Last change on this file since 3900 was 3900, checked in by Peter, 3 years ago

closes #944; add configure check whether class is availabale in boost and exclude typedef if not. Lift out test for that typedef to separate test so it can be skipped (without skipping all sister tests) when boost is old.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.6 KB
Line 
1#ifndef theplu_yat_random_continuous_distribution
2#define theplu_yat_random_continuous_distribution
3
4// $Id: ContinuousDistribution.h 3900 2020-05-03 08:29:25Z peter $
5
6/*
7  Copyright (C) 2020 Peter Johansson
8
9  This file is part of the yat library, http://dev.thep.lu.se/yat
10
11  The yat library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU General Public License as
13  published by the Free Software Foundation; either version 3 of the
14  License, or (at your option) any later version.
15
16  The yat library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20
21  You should have received a copy of the GNU General Public License
22  along with yat. If not, see <http://www.gnu.org/licenses/>.
23*/
24
25// to #define BOOST_ALLOW_DEPRECATED_HEADERS if needed
26#include <yat/utility/config_public.h>
27
28#include "Distribution.h"
29
30#include <boost/random/cauchy_distribution.hpp>
31#include <boost/random/chi_squared_distribution.hpp>
32#include <boost/random/extreme_value_distribution.hpp>
33#include <boost/random/fisher_f_distribution.hpp>
34#include <boost/random/gamma_distribution.hpp>
35#include <boost/random/lognormal_distribution.hpp>
36#ifdef YAT_HAVE_BOOST_RANDOM_NON_CENTRAL_CHI_SQUARED_DISTRIBUTION
37#include <boost/random/non_central_chi_squared_distribution.hpp>
38#endif
39#include <boost/random/student_t_distribution.hpp>
40
41namespace theplu {
42namespace yat {
43namespace random {
44
45  /**
46     Proxy class between RNG and <a href="https://www.boost.org/doc/libs/1_72_0/doc/html/boost_random/reference.html#boost_random.reference.distributions">Boost Distributions</a>
47
48     \since New in yat 0.18
49   */
50  template<class RND>
51  class ContinuousDistribution :
52    public Distribution<RND, double>, public Continuous
53  {
54  public:
55    /**
56       \return a random number from distribution with parameters \a p.
57     */
58    double operator()(const typename RND::param_type& p) const
59    {
60      return const_cast<RND&>(this->distribution_)(this->urng_, p);
61    }
62
63
64    /**
65       \return a random number from distribution with parameters as in
66       param().
67     */
68    double operator()(void) const
69    {
70      return const_cast<RND&>(this->distribution_)(this->urng_);
71    }
72  };
73
74
75  /**
76     \see
77     <a href="https://www.boost.org/doc/libs/1_72_0/doc/html/boost/random/cauchy_distribution.html">
78     Boost cauchy_distribution</a>
79
80     \since New in yat 0.18
81   */
82  typedef ContinuousDistribution<boost::random::cauchy_distribution<> > Cauchy;
83
84  /**
85     \see
86     <a href="https://www.boost.org/doc/libs/1_72_0/doc/html/boost/random/chi_squared_distribution.html">
87     Boost chi_squared_distribution</a>
88
89     \since New in yat 0.18
90   */
91  typedef ContinuousDistribution<boost::random::chi_squared_distribution<> >
92  ChiSquared;
93
94  /**
95     \see
96     <a href="https://www.boost.org/doc/libs/1_72_0/doc/html/boost/random/extreme_value_distribution.html">
97     Boost extreme_value_distribution</a>
98
99     \since New in yat 0.18
100   */
101  typedef ContinuousDistribution<boost::random::extreme_value_distribution<> >
102  ExtremeValue;
103
104  /**
105     \see
106     <a href="https://www.boost.org/doc/libs/1_72_0/doc/html/boost/random/fisher_f_distribution.html">
107     Boost fisher_f_distribution</a>
108
109     \since New in yat 0.18
110   */
111  typedef ContinuousDistribution<boost::random::fisher_f_distribution<> >
112  FisherF;
113
114  /**
115     \see
116     <a href="https://www.boost.org/doc/libs/1_72_0/doc/html/boost/random/gamma_distribution.html">
117     Boost gamma_distribution</a>
118
119     \since New in yat 0.18
120   */
121  typedef ContinuousDistribution<boost::random::gamma_distribution<> > Gamma;
122
123  /**
124     \see
125     <a href="https://www.boost.org/doc/libs/1_72_0/doc/html/boost/random/lognormal_distribution.html">
126     Boost lognormal_distribution</a>
127
128     \since New in yat 0.18
129   */
130  typedef ContinuousDistribution<boost::random::lognormal_distribution<> >
131  Lognormal;
132
133  /**
134     \see
135     <a href="https://www.boost.org/doc/libs/1_72_0/doc/html/boost/random/non_central_chi_squared_distribution.html">
136     Boost non_central_chi_squared_distribution</a>
137
138     \since New in yat 0.18
139
140     \note non_central_chi_squared_distribution is not available in
141     older boost (it does exist in boost 1.59)
142   */
143#ifdef YAT_HAVE_BOOST_RANDOM_NON_CENTRAL_CHI_SQUARED_DISTRIBUTION
144  typedef
145  ContinuousDistribution<boost::random::non_central_chi_squared_distribution<> >
146  NonCentralChiSquared;
147#endif
148
149  /**
150     \see
151     <a href="https://www.boost.org/doc/libs/1_72_0/doc/html/boost/random/student_t_distribution.html">
152     Boost student_t_distribution</a>
153
154     \since New in yat 0.18
155   */
156  typedef ContinuousDistribution<boost::random::student_t_distribution<> >
157  StudentT;
158
159}}} // of namespace random, yat, and theplu
160
161#endif
Note: See TracBrowser for help on using the repository browser.