1 // Copyright John Maddock 2007.
2 // Copyright Paul A. Bristow 2007, 2009, 2012.
4 // Use, modification and distribution are subject to the
5 // Boost Software License, Version 1.0.
6 // (See accompanying file LICENSE_1_0.txt
7 // or copy at http://www.boost.org/LICENSE_1_0.txt)
9 // boost_math.cpp This is the main DLL file.
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 // to avoid complications with pre-compiled headers:
15 // "BOOST_MATH_ASSERT_UNDEFINED_POLICY=0"
16 // "BOOST_MATH_OVERFLOW_ERROR_POLICY="errno_on_error""
17 // so command line shows:
18 // /D "BOOST_MATH_ASSERT_UNDEFINED_POLICY=0"
19 // /D "BOOST_MATH_OVERFLOW_ERROR_POLICY="errno_on_error""
24 # pragma warning(disable: 4400) // 'const boost_math::any_distribution ^' : const/volatile qualifiers on this type are not supported
25 # pragma warning(disable: 4244) // 'argument' : conversion from 'double' to 'unsigned int', possible loss of data
26 # pragma warning(disable: 4512) // assignment operator could not be generated
27 // hypergeometric expects integer parameters.
28 # pragma warning(disable: 4127) // constant
31 #include "boost_math.h"
36 any_distribution::any_distribution(int t
, double arg1
, double arg2
, double arg3
)
38 TRANSLATE_EXCEPTIONS_BEGIN
39 // This is where all the work gets done:
40 switch(t
) // index of distribution to distribution_info distributions[]
41 { // New entries must match distribution names, parameter name(s) and defaults defined below.
43 this->reset(new concrete_distribution
<boost::math::bernoulli
>(boost::math::bernoulli(arg1
)));
46 this->reset(new concrete_distribution
<boost::math::beta_distribution
<> >(boost::math::beta_distribution
<>(arg1
, arg2
)));
47 break; // Note - no typedef, so need explicit type <> but rely on default = double.
49 this->reset(new concrete_distribution
<boost::math::binomial_distribution
<> >(boost::math::binomial_distribution
<>(arg1
, arg2
)));
50 break; // Note - no typedef, so need explicit type <> but rely on default = double.
52 this->reset(new concrete_distribution
<boost::math::cauchy
>(boost::math::cauchy(arg1
, arg2
)));
55 this->reset(new concrete_distribution
<boost::math::chi_squared
>(boost::math::chi_squared(arg1
)));
58 this->reset(new concrete_distribution
<boost::math::exponential
>(boost::math::exponential(arg1
)));
61 this->reset(new concrete_distribution
<boost::math::extreme_value
>(boost::math::extreme_value(arg1
)));
64 this->reset(new concrete_distribution
<boost::math::fisher_f
>(boost::math::fisher_f(arg1
, arg2
)));
67 this->reset(new concrete_distribution
<boost::math::gamma_distribution
<> >(boost::math::gamma_distribution
<>(arg1
, arg2
)));
70 this->reset(new concrete_distribution
<boost::math::geometric_distribution
<> >(boost::math::geometric_distribution
<>(arg1
)));
73 this->reset(new concrete_distribution
<boost::math::hypergeometric_distribution
<> >(boost::math::hypergeometric_distribution
<>(arg1
, arg2
, arg3
)));
76 this->reset(new concrete_distribution
<boost::math::inverse_chi_squared_distribution
<> >(boost::math::inverse_chi_squared_distribution
<>(arg1
, arg2
)));
79 this->reset(new concrete_distribution
<boost::math::inverse_gamma_distribution
<> >(boost::math::inverse_gamma_distribution
<>(arg1
, arg2
)));
82 this->reset(new concrete_distribution
<boost::math::inverse_gaussian_distribution
<> >(boost::math::inverse_gaussian_distribution
<>(arg1
, arg2
)));
85 this->reset(new concrete_distribution
<boost::math::laplace_distribution
<> >(boost::math::laplace_distribution
<>(arg1
, arg2
)));
88 this->reset(new concrete_distribution
<boost::math::logistic_distribution
<> >(boost::math::logistic_distribution
<>(arg1
, arg2
)));
91 this->reset(new concrete_distribution
<boost::math::lognormal_distribution
<> >(boost::math::lognormal_distribution
<>(arg1
, arg2
)));
94 this->reset(new concrete_distribution
<boost::math::negative_binomial_distribution
<> >(boost::math::negative_binomial_distribution
<>(arg1
, arg2
)));
97 this->reset(new concrete_distribution
<boost::math::non_central_beta_distribution
<> >(boost::math::non_central_beta_distribution
<>(arg1
, arg2
, arg3
)));
100 this->reset(new concrete_distribution
<boost::math::non_central_chi_squared_distribution
<> >(boost::math::non_central_chi_squared_distribution
<>(arg1
, arg2
)));
103 this->reset(new concrete_distribution
<boost::math::non_central_f_distribution
<> >(boost::math::non_central_f_distribution
<>(arg1
, arg2
, arg3
)));
106 this->reset(new concrete_distribution
<boost::math::non_central_t_distribution
<> >(boost::math::non_central_t_distribution
<>(arg1
, arg2
)));
109 this->reset(new concrete_distribution
<boost::math::normal_distribution
<> >(boost::math::normal_distribution
<>(arg1
, arg2
)));
112 this->reset(new concrete_distribution
<boost::math::pareto
>(boost::math::pareto(arg1
, arg2
)));
115 this->reset(new concrete_distribution
<boost::math::poisson
>(boost::math::poisson(arg1
)));
118 this->reset(new concrete_distribution
<boost::math::rayleigh
>(boost::math::rayleigh(arg1
)));
121 this->reset(new concrete_distribution
<boost::math::skew_normal
>(boost::math::skew_normal(arg1
, arg2
, arg3
)));
124 this->reset(new concrete_distribution
<boost::math::students_t
>(boost::math::students_t(arg1
)));
127 this->reset(new concrete_distribution
<boost::math::triangular
>(boost::math::triangular(arg1
, arg2
, arg3
)));
130 this->reset(new concrete_distribution
<boost::math::uniform
>(boost::math::uniform(arg1
, arg2
)));
133 this->reset(new concrete_distribution
<boost::math::weibull
>(boost::math::weibull(arg1
, arg2
)));
138 // TODO Need some proper error handling here?
141 TRANSLATE_EXCEPTIONS_END
142 } // any_distribution constructor.
144 struct distribution_info
146 const char* name
; // of distribution.
147 const char* first_param
; // Parameters' name like "degrees of freedom",
148 const char* second_param
; // if required, else "",
149 const char* third_param
; // if required, else "".
150 // triangular and non-centrals need 3 parameters.
151 // (Only the Bi-Weibull would need 5 parameters?)
152 double first_default
; // distribution parameter value, often 0, 0.5 or 1.
153 double second_default
; // 0 if there isn't a second argument.
154 // Note that defaults below follow default argument in constructors,
155 // if any, but need not be the same.
156 double third_default
; // 0 if there isn't a third argument.
159 distribution_info distributions
[] =
160 { // distribution name, parameter name(s) and default(s)
161 // Order must match any_distribution constructor above!
162 // Null string "" and zero default for un-used arguments.
163 { "Bernoulli", "Probability", "", "",0.5, 0, 0}, // case 0
164 { "Beta", "Alpha", "Beta", "", 1, 1, 0}, // case 1
165 { "Binomial", "Trials", "Probability of success", "", 1, 0.5, 0}, // case 2
166 { "Cauchy", "Location", "Scale", "", 0, 1, 0}, // case 3
167 { "Chi_squared", "Degrees of freedom", "", "", 1, 0, 0}, // case 4
168 { "Exponential", "lambda", "", "", 1, 0, 0}, // case 5
169 { "Extreme value", "Location", "Scale", "", 0, 1, 0}, // case 6
170 { "Fisher-F", "Degrees of freedom 1", "Degrees of freedom 2", "", 1, 1, 0}, // case 7
171 { "Gamma (Erlang)", "Shape", "Scale", "", 1, 1, 0}, // case 8
172 { "Geometric", "Probability", "", "", 1, 0, 0}, // case 9
173 { "HyperGeometric", "Defects", "Samples", "Objects", 1, 0, 1}, // case 10
174 { "InverseChiSq", "Degrees of Freedom", "Scale", "", 1, 1, 0}, // case 11
175 { "InverseGamma", "Shape", "Scale", "", 1, 1, 0}, // case 12
176 { "InverseGaussian", "Mean", "Scale", "", 1, 1, 0}, // case 13
177 { "Laplace", "Location", "Scale", "", 0, 1, 0}, // case 14
178 { "Logistic", "Location", "Scale", "", 0, 1, 0}, // case 15
179 { "LogNormal", "Location", "Scale", "", 0, 1, 0}, // case 16
180 { "Negative Binomial", "Successes", "Probability of success", "", 1, 0.5, 0}, // case 17
181 { "Noncentral Beta", "Shape alpha", "Shape beta", "Non-centrality", 1, 1, 0}, // case 18
182 { "Noncentral ChiSquare", "Degrees of Freedom", "Non-centrality", "", 1, 0, 0}, // case 19
183 { "Noncentral F", "Degrees of Freedom 1", "Degrees of Freedom 2", "Non-centrality", 1, 1, 0}, // case 20
184 { "Noncentral t", "Degrees of Freedom", "Non-centrality", "", 1, 0, 0}, // case 21
185 { "Normal (Gaussian)", "Mean", "Standard Deviation", "", 0, 1, 0}, // case 22
186 { "Pareto", "Location", "Shape","", 1, 1, 0}, // case 23
187 { "Poisson", "Mean", "", "", 1, 0, 0}, // case 24
188 { "Rayleigh", "Shape", "", "", 1, 0, 0}, // case 25
189 { "Skew Normal", "Location", "Shape", "Skew", 0, 1, 0}, // case 27 (defaults to Gaussian).
190 { "Student's t", "Degrees of Freedom", "", "", 1, 0, 0}, // case 28
191 { "Triangular", "Lower", "Mode", "Upper", -1, 0, +1 }, // case 29 3rd parameter!
192 // 0, 0.5, 1 also said to be 'standard' but this is most like an approximation to Gaussian distribution.
193 { "Uniform", "Lower", "Upper", "", 0, 1, 0}, // case 30
194 { "Weibull", "Shape", "Scale", "", 1, 1, 0}, // case 31
197 // How many distributions are supported:
198 int any_distribution::size()
200 return sizeof(distributions
) / sizeof(distributions
[0]);
203 // Display name of i'th distribution:
204 System::String
^ any_distribution::distribution_name(int i
)
208 return gcnew
System::String(distributions
[i
].name
);
210 // Name of first distribution parameter, or null if not supported:
211 System::String
^ any_distribution::first_param_name(int i
)
215 return gcnew
System::String(distributions
[i
].first_param
);
217 // Name of second distribution parameter, or null if not supported:
218 System::String
^ any_distribution::second_param_name(int i
)
222 return gcnew
System::String(distributions
[i
].second_param
);
224 // Name of third distribution parameter, or null if not supported:
225 System::String
^ any_distribution::third_param_name(int i
)
229 return gcnew
System::String(distributions
[i
].third_param
);
231 // default value for first parameter:
232 double any_distribution::first_param_default(int i
)
236 return distributions
[i
].first_default
;
238 // default value for second parameter:
239 double any_distribution::second_param_default(int i
)
243 return distributions
[i
].second_default
;
245 // default value for third parameter:
246 double any_distribution::third_param_default(int i
)
250 return distributions
[i
].third_default
;
253 } // namespace boost_math