|
Boost : |
Subject: [boost] [Math/Statistical Distributions] Rethinking of distribution template parameters.
From: Marco Guazzone (marco.guazzone_at_[hidden])
Date: 2009-05-19 08:49:40
Dear Boost developers,
This is a feature request for the next version of Math/Statisical
Distributions lib.
Currently, due to lack of input type information, discrete
distributions can only be "emulated" by using the discrete_quantile
policy.
However, doing so the effective quantile type is still a real type.
In my opinion, this have at least two disadvantages:
1. Operations are slow since the underlying quantile type is still
real. Instead, operations on really integral types are generally
faster.
2. Quantile comparison might be inaccurate since we are comparing real types
So, for improving the support of discrete distributions, I think it
would be nice if the all probability distributions gain a third
template parameter, named, for instance, InputType.
This can be used as follows:
For discrete distributions, like the "discrete uniform distribution":
--- [discrete_snip] ---
template < typename InputType = int, typename ValueType = double,
typename Policy = policies::policy<> >
class discrete_uniform_distribution
{
public:
typedef InputType input_type;
typedef ValueType value_type;
typedef Policy policy_type;
discrete_uniform_distribution(input_type lower = 0, input_type upper = 9)
: lower_(lower), upper_(upper)
{
// Empty
}
inline input_type lower() const { return lower_; }
inline input_type upper() const { return upper_; }
private:
input_type lower_;
input_type upper_;
};
--- [/discrete_snip] ---
For continuos distributions, like the "continuous uniform distribution":
--- [continuous_snip] ---
template < typename InputType = double, typename ValueType =
InputType, typename Policy = policies::policy<> >
class continuous_uniform_distribution
{
public:
typedef InputType input_type;
typedef ValueType value_type;
typedef Policy policy_type;
continuous_uniform_distribution(input_type lower = 0, input_type upper = 9)
: lower_(lower), upper_(upper)
{
// Empty
}
inline input_type lower() const { return lower_; }
inline input_type upper() const { return upper_; }
private:
input_type lower_;
input_type upper_;
};
--- [/continuous_snip] ---
NOTE: as you know, discrete and uniform distributions behave
differently. So two different class (or two different instantiations
of the same templated class) must be provided.
What do you think?
Thank you for your attention!!
-- Marco
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk