File: boost_math.h

package info (click to toggle)
boost1.83 1.83.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 545,632 kB
  • sloc: cpp: 3,857,086; xml: 125,552; ansic: 34,414; python: 25,887; asm: 5,276; sh: 4,799; ada: 1,681; makefile: 1,629; perl: 1,212; pascal: 1,139; sql: 810; yacc: 478; ruby: 102; lisp: 24; csh: 6
file content (331 lines) | stat: -rw-r--r-- 9,290 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
// boost_math.h

// Copyright John Maddock 2007.
// Copyright Paul A. Bristow 2007.

// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)

//#define BOOST_MATH_OVERFLOW_ERROR_POLICY errno_on_error
//#define BOOST_MATH_ASSERT_UNDEFINED_POLICY false
// These are now defined in project properties
// "BOOST_MATH_ASSERT_UNDEFINED_POLICY=0"
// "BOOST_MATH_OVERFLOW_ERROR_POLICY=errno_on_error"
// to avoid complications with pre-compiled headers.

#ifdef _MSC_VER
#  pragma once
#  pragma warning (disable : 4127)
#endif

using namespace System;

#define TRANSLATE_EXCEPTIONS_BEGIN try{

#define TRANSLATE_EXCEPTIONS_END \
    }catch(const std::exception& e){  \
        System::String^ s = gcnew System::String(e.what());\
        InvalidOperationException^ se = gcnew InvalidOperationException(s);\
        throw se;  \
    }

namespace boost_math {

   class any_imp
   {
   public:
     // Distribution properties.
      virtual double mean()const = 0;
      virtual double mode()const = 0;
      virtual double median()const = 0;
      virtual double variance()const = 0;
      virtual double standard_deviation()const = 0;
      virtual double skewness()const = 0;
      virtual double kurtosis()const = 0;
      virtual double kurtosis_excess()const = 0;
      virtual double coefficient_of_variation()const = 0;
      // Values computed from random variate x.
      virtual double hazard(double x)const = 0;
      virtual double chf(double x)const = 0;
      virtual double cdf(double x)const = 0;
      virtual double ccdf(double x)const = 0;
      virtual double pdf(double x)const = 0;
      virtual double quantile(double x)const = 0;
      virtual double quantile_c(double x)const = 0;
      // Range & support of x
      virtual double lowest()const = 0;
      virtual double uppermost()const = 0;
      virtual double lower()const = 0;
      virtual double upper()const = 0;
   };

   template <class Distribution>
   class concrete_distribution : public any_imp
   {
   public:
      concrete_distribution(const Distribution& d) : m_dist(d) {}
      // Distribution properties.
      virtual double mean()const
      {
         return boost::math::mean(m_dist);
      }
      virtual double median()const
      {
         return boost::math::median(m_dist);
      }
      virtual double mode()const
      {
         return boost::math::mode(m_dist);
      }
      virtual double variance()const
      {
         return boost::math::variance(m_dist);
      }
      virtual double skewness()const
      {
         return boost::math::skewness(m_dist);
      }
      virtual double standard_deviation()const
      {
         return boost::math::standard_deviation(m_dist);
      }
      virtual double coefficient_of_variation()const
      {
         return boost::math::coefficient_of_variation(m_dist);
      }
      virtual double kurtosis()const
      {
         return boost::math::kurtosis(m_dist);
      }
      virtual double kurtosis_excess()const
      {
         return boost::math::kurtosis_excess(m_dist);
      }
      // Range of x for the distribution.
      virtual double lowest()const
      {
         return boost::math::range(m_dist).first;
      }
      virtual double uppermost()const
      {
         return boost::math::range(m_dist).second;
      }
      // Support of x for the distribution.
      virtual double lower()const
      {
         return boost::math::support(m_dist).first;
      }
      virtual double upper()const
      {
         return boost::math::support(m_dist).second;
      }

      // Values computed from random variate x.
      virtual double hazard(double x)const
      {
         return boost::math::hazard(m_dist, x);
      }
      virtual double chf(double x)const
      {
         return boost::math::chf(m_dist, x);
      }
      virtual double cdf(double x)const
      {
         return boost::math::cdf(m_dist, x);
      }
      virtual double ccdf(double x)const
      {
         return boost::math::cdf(complement(m_dist, x));
      }
      virtual double pdf(double x)const
      {
         return boost::math::pdf(m_dist, x);
      }
      virtual double quantile(double x)const
      {
         return boost::math::quantile(m_dist, x);
      }
      virtual double quantile_c(double x)const
      {
         return boost::math::quantile(complement(m_dist, x));
      }
   private:
      Distribution m_dist;
   };

   public ref class any_distribution
   {
     public:
      // Added methods for this class here.
      any_distribution(int t, double arg1, double arg2, double arg3);
      ~any_distribution()
      {
         reset(0);
      }
      // Is it OK for these to be inline?
      // Distribution properties as 'pointer-to-implementations'.
      double mean()
      {
         TRANSLATE_EXCEPTIONS_BEGIN
         return pimpl->mean();
         TRANSLATE_EXCEPTIONS_END
      }
      double median()
      {
         TRANSLATE_EXCEPTIONS_BEGIN
         return pimpl->median();
         TRANSLATE_EXCEPTIONS_END
      }
      double mode()
      {
         TRANSLATE_EXCEPTIONS_BEGIN
         return pimpl->mode();
         TRANSLATE_EXCEPTIONS_END
      }
      double variance()
      {
         TRANSLATE_EXCEPTIONS_BEGIN
         return pimpl->variance();
         TRANSLATE_EXCEPTIONS_END
      }
      double standard_deviation()
      {
         TRANSLATE_EXCEPTIONS_BEGIN
         return pimpl->standard_deviation();
         TRANSLATE_EXCEPTIONS_END
      }
      double coefficient_of_variation()
      { // aka Relative Standard deviation.
         TRANSLATE_EXCEPTIONS_BEGIN
         return pimpl->coefficient_of_variation();
         TRANSLATE_EXCEPTIONS_END
      }
      double skewness()
      {
         TRANSLATE_EXCEPTIONS_BEGIN
         return pimpl->skewness();
         TRANSLATE_EXCEPTIONS_END
      }
      double kurtosis()
      {
         TRANSLATE_EXCEPTIONS_BEGIN
         return pimpl->kurtosis();
         TRANSLATE_EXCEPTIONS_END
      }
      double kurtosis_excess()
      {
         TRANSLATE_EXCEPTIONS_BEGIN
         return pimpl->kurtosis_excess();
         TRANSLATE_EXCEPTIONS_END
      }
      // Values computed from random variate x.
      double hazard(double x)
      {
         TRANSLATE_EXCEPTIONS_BEGIN
         return pimpl->hazard(x);
         TRANSLATE_EXCEPTIONS_END
      }
      double chf(double x)
      {
         TRANSLATE_EXCEPTIONS_BEGIN
         return pimpl->chf(x);
         TRANSLATE_EXCEPTIONS_END
      }
      double cdf(double x)
      {
         TRANSLATE_EXCEPTIONS_BEGIN
         return pimpl->cdf(x);
         TRANSLATE_EXCEPTIONS_END
      }
      double ccdf(double x)
      {
         TRANSLATE_EXCEPTIONS_BEGIN
         return pimpl->ccdf(x);
         TRANSLATE_EXCEPTIONS_END
     }
      double pdf(double x)
      {
         TRANSLATE_EXCEPTIONS_BEGIN
         return pimpl->pdf(x);
         TRANSLATE_EXCEPTIONS_END
      }
      double quantile(double x)
      {
         TRANSLATE_EXCEPTIONS_BEGIN
         return pimpl->quantile(x);
         TRANSLATE_EXCEPTIONS_END
      }
      double quantile_c(double x)
      {
         TRANSLATE_EXCEPTIONS_BEGIN
         return pimpl->quantile_c(x);
         TRANSLATE_EXCEPTIONS_END
      }

      double lowest()
      {
         TRANSLATE_EXCEPTIONS_BEGIN
         return pimpl->lowest();
         TRANSLATE_EXCEPTIONS_END
      }

      double uppermost()
      {
         TRANSLATE_EXCEPTIONS_BEGIN
         return pimpl->uppermost();
         TRANSLATE_EXCEPTIONS_END
      }

      double lower()
      {
         TRANSLATE_EXCEPTIONS_BEGIN
         return pimpl->lower();
         TRANSLATE_EXCEPTIONS_END
      }
      double upper()
      {
         TRANSLATE_EXCEPTIONS_BEGIN
         return pimpl->upper();
         TRANSLATE_EXCEPTIONS_END
      }

      // How many distributions are supported:
      static int size();
      // Display name of i'th distribution:
      static System::String^ distribution_name(int i);
      // Name of first distribution parameter, or null if not supported:
      static System::String^ first_param_name(int i);
      // Name of second distribution parameter, or null if not supported:
      static System::String^ second_param_name(int i);
      // Name of third distribution parameter, or null if not supported:
      static System::String^ third_param_name(int i);
      // Default value for first parameter:
      static double first_param_default(int i);
      // Default value for second parameter:
      static double second_param_default(int i);
      // Default value for third parameter:
      static double third_param_default(int i);

   private:
      any_distribution(const any_distribution^)
      { // Constructor is private.
      }
      const any_distribution^ operator=(const any_distribution^ d)
      { // Copy Constructor is private too.
         return d;
      }
      // We really should use a shared_ptr here, 
      // but apparently it's not allowed in a managed class like this :-(
      void reset(any_imp* p)
      {
         if(pimpl)
         { // Exists already, so
            delete pimpl;
         }
         pimpl = p;
      }
      any_imp* pimpl;
   };
}