3 // Copyright John Maddock 2007.
4 // Copyright Paul A. Bristow 2007.
6 // Use, modification and distribution are subject to the
7 // Boost Software License, Version 1.0.
8 // (See accompanying file LICENSE_1_0.txt
9 // or copy at http://www.boost.org/LICENSE_1_0.txt)
11 //#define BOOST_MATH_OVERFLOW_ERROR_POLICY errno_on_error
12 //#define BOOST_MATH_ASSERT_UNDEFINED_POLICY false
13 // These are now defined in project properties
14 // "BOOST_MATH_ASSERT_UNDEFINED_POLICY=0"
15 // "BOOST_MATH_OVERFLOW_ERROR_POLICY=errno_on_error"
16 // to avoid complications with pre-compiled headers.
20 # pragma warning (disable : 4127)
23 using namespace System
;
25 #define TRANSLATE_EXCEPTIONS_BEGIN try{
27 #define TRANSLATE_EXCEPTIONS_END \
28 }catch(const std::exception& e){ \
29 System::String^ s = gcnew System::String(e.what());\
30 InvalidOperationException^ se = gcnew InvalidOperationException(s);\
34 namespace boost_math
{
39 // Distribution properties.
40 virtual double mean()const = 0;
41 virtual double mode()const = 0;
42 virtual double median()const = 0;
43 virtual double variance()const = 0;
44 virtual double standard_deviation()const = 0;
45 virtual double skewness()const = 0;
46 virtual double kurtosis()const = 0;
47 virtual double kurtosis_excess()const = 0;
48 virtual double coefficient_of_variation()const = 0;
49 // Values computed from random variate x.
50 virtual double hazard(double x
)const = 0;
51 virtual double chf(double x
)const = 0;
52 virtual double cdf(double x
)const = 0;
53 virtual double ccdf(double x
)const = 0;
54 virtual double pdf(double x
)const = 0;
55 virtual double quantile(double x
)const = 0;
56 virtual double quantile_c(double x
)const = 0;
57 // Range & support of x
58 virtual double lowest()const = 0;
59 virtual double uppermost()const = 0;
60 virtual double lower()const = 0;
61 virtual double upper()const = 0;
64 template <class Distribution
>
65 class concrete_distribution
: public any_imp
68 concrete_distribution(const Distribution
& d
) : m_dist(d
) {}
69 // Distribution properties.
70 virtual double mean()const
72 return boost::math::mean(m_dist
);
74 virtual double median()const
76 return boost::math::median(m_dist
);
78 virtual double mode()const
80 return boost::math::mode(m_dist
);
82 virtual double variance()const
84 return boost::math::variance(m_dist
);
86 virtual double skewness()const
88 return boost::math::skewness(m_dist
);
90 virtual double standard_deviation()const
92 return boost::math::standard_deviation(m_dist
);
94 virtual double coefficient_of_variation()const
96 return boost::math::coefficient_of_variation(m_dist
);
98 virtual double kurtosis()const
100 return boost::math::kurtosis(m_dist
);
102 virtual double kurtosis_excess()const
104 return boost::math::kurtosis_excess(m_dist
);
106 // Range of x for the distribution.
107 virtual double lowest()const
109 return boost::math::range(m_dist
).first
;
111 virtual double uppermost()const
113 return boost::math::range(m_dist
).second
;
115 // Support of x for the distribution.
116 virtual double lower()const
118 return boost::math::support(m_dist
).first
;
120 virtual double upper()const
122 return boost::math::support(m_dist
).second
;
125 // Values computed from random variate x.
126 virtual double hazard(double x
)const
128 return boost::math::hazard(m_dist
, x
);
130 virtual double chf(double x
)const
132 return boost::math::chf(m_dist
, x
);
134 virtual double cdf(double x
)const
136 return boost::math::cdf(m_dist
, x
);
138 virtual double ccdf(double x
)const
140 return boost::math::cdf(complement(m_dist
, x
));
142 virtual double pdf(double x
)const
144 return boost::math::pdf(m_dist
, x
);
146 virtual double quantile(double x
)const
148 return boost::math::quantile(m_dist
, x
);
150 virtual double quantile_c(double x
)const
152 return boost::math::quantile(complement(m_dist
, x
));
158 public ref
class any_distribution
161 // Added methods for this class here.
162 any_distribution(int t
, double arg1
, double arg2
, double arg3
);
167 // Is it OK for these to be inline?
168 // Distribution properties as 'pointer-to-implementions'.
171 TRANSLATE_EXCEPTIONS_BEGIN
172 return pimpl
->mean();
173 TRANSLATE_EXCEPTIONS_END
177 TRANSLATE_EXCEPTIONS_BEGIN
178 return pimpl
->median();
179 TRANSLATE_EXCEPTIONS_END
183 TRANSLATE_EXCEPTIONS_BEGIN
184 return pimpl
->mode();
185 TRANSLATE_EXCEPTIONS_END
189 TRANSLATE_EXCEPTIONS_BEGIN
190 return pimpl
->variance();
191 TRANSLATE_EXCEPTIONS_END
193 double standard_deviation()
195 TRANSLATE_EXCEPTIONS_BEGIN
196 return pimpl
->standard_deviation();
197 TRANSLATE_EXCEPTIONS_END
199 double coefficient_of_variation()
200 { // aka Relative Standard deviation.
201 TRANSLATE_EXCEPTIONS_BEGIN
202 return pimpl
->coefficient_of_variation();
203 TRANSLATE_EXCEPTIONS_END
207 TRANSLATE_EXCEPTIONS_BEGIN
208 return pimpl
->skewness();
209 TRANSLATE_EXCEPTIONS_END
213 TRANSLATE_EXCEPTIONS_BEGIN
214 return pimpl
->kurtosis();
215 TRANSLATE_EXCEPTIONS_END
217 double kurtosis_excess()
219 TRANSLATE_EXCEPTIONS_BEGIN
220 return pimpl
->kurtosis_excess();
221 TRANSLATE_EXCEPTIONS_END
223 // Values computed from random variate x.
224 double hazard(double x
)
226 TRANSLATE_EXCEPTIONS_BEGIN
227 return pimpl
->hazard(x
);
228 TRANSLATE_EXCEPTIONS_END
232 TRANSLATE_EXCEPTIONS_BEGIN
233 return pimpl
->chf(x
);
234 TRANSLATE_EXCEPTIONS_END
238 TRANSLATE_EXCEPTIONS_BEGIN
239 return pimpl
->cdf(x
);
240 TRANSLATE_EXCEPTIONS_END
242 double ccdf(double x
)
244 TRANSLATE_EXCEPTIONS_BEGIN
245 return pimpl
->ccdf(x
);
246 TRANSLATE_EXCEPTIONS_END
250 TRANSLATE_EXCEPTIONS_BEGIN
251 return pimpl
->pdf(x
);
252 TRANSLATE_EXCEPTIONS_END
254 double quantile(double x
)
256 TRANSLATE_EXCEPTIONS_BEGIN
257 return pimpl
->quantile(x
);
258 TRANSLATE_EXCEPTIONS_END
260 double quantile_c(double x
)
262 TRANSLATE_EXCEPTIONS_BEGIN
263 return pimpl
->quantile_c(x
);
264 TRANSLATE_EXCEPTIONS_END
269 TRANSLATE_EXCEPTIONS_BEGIN
270 return pimpl
->lowest();
271 TRANSLATE_EXCEPTIONS_END
276 TRANSLATE_EXCEPTIONS_BEGIN
277 return pimpl
->uppermost();
278 TRANSLATE_EXCEPTIONS_END
283 TRANSLATE_EXCEPTIONS_BEGIN
284 return pimpl
->lower();
285 TRANSLATE_EXCEPTIONS_END
289 TRANSLATE_EXCEPTIONS_BEGIN
290 return pimpl
->upper();
291 TRANSLATE_EXCEPTIONS_END
294 // How many distributions are supported:
296 // Display name of i'th distribution:
297 static System::String
^ distribution_name(int i
);
298 // Name of first distribution parameter, or null if not supported:
299 static System::String
^ first_param_name(int i
);
300 // Name of second distribution parameter, or null if not supported:
301 static System::String
^ second_param_name(int i
);
302 // Name of third distribution parameter, or null if not supported:
303 static System::String
^ third_param_name(int i
);
304 // Default value for first parameter:
305 static double first_param_default(int i
);
306 // Default value for second parameter:
307 static double second_param_default(int i
);
308 // Default value for third parameter:
309 static double third_param_default(int i
);
312 any_distribution(const any_distribution
^)
313 { // Constructor is private.
315 const any_distribution
^ operator=(const any_distribution
^ d
)
316 { // Copy Constructor is private too.
319 // We really should use a shared_ptr here,
320 // but apparently it's not allowed in a managed class like this :-(
321 void reset(any_imp
* p
)
324 { // Exists already, so