
On Tue, May 19, 2009 at 2:49 PM, Marco Guazzone <marco.guazzone@gmail.com> wrote:
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.
Just for completeness, the different helper functions would become: --- [code_snip] --- // Discrete Uniform Distribution template <typename InputType, typename ValueType, typename Policy> inline ValueType pdf(const discrete_uniform_distribution<InputType, ValueType, Policy>& dist, const InputType& x) { return ValueType(1.0)/(dist.upper()-dist.lower()+1); } template <typename InputType, typename ValueType, typename Policy> inline ValueType cdf(const discrete_uniform_distribution<InputType, ValueType, Policy>& dist, const InputType& q) { if (q <= dist.lower()) return 0; if (q >= dist.upper()) return 1; return (q-dist.lower()+1)/ValueType(dist.upper()-dist.lower()+1); } template <typename InputType, typename ValueType, typename Policy> inline InputType quantile(const discrete_uniform_distribution<InputType, ValueType, Policy>& dist, const ValueType& p) { return p*(dist.upper()-dist.lower()+1)+dist.lower()-1; } // Continuous Uniform Distribution template <typename InputType, typename ValueType, typename Policy> inline ValueType pdf(const continuous_uniform_distribution<InputType, ValueType, Policy>& dist, const InputType& x) { return ValueType(1.0)/(dist.upper()-dist.lower()); } template <typename InputType, typename ValueType, typename Policy> inline ValueType cdf(const continuous_uniform_distribution<InputType, ValueType, Policy>& dist, const InputType& q) { if (q <= dist.lower()) return 0; if (q >= dist.upper()) return 1; return (q-dist.lower())/ValueType(dist.upper()-dist.lower()); } template <typename InputType, typename ValueType, typename Policy> inline InputType quantile(const continuous_uniform_distribution<InputType, ValueType, Policy>& dist, const ValueType& p) { return p*(dist.upper()-dist.lower())+dist.lower(); } // and so on... --- [/code_snip] --- Cheers, -- Marco