mirror of
https://github.com/boostorg/math.git
synced 2026-01-19 04:22:09 +00:00
Support integer distributions.
This commit is contained in:
48
doc/graphs/empiricial_cumulative_distribution_uniform.svg
Normal file
48
doc/graphs/empiricial_cumulative_distribution_uniform.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 29 KiB |
@@ -15,7 +15,6 @@ class empirical_cumulative_distribution_function {
|
||||
public:
|
||||
empirical_cumulative_distribution_function(RandomAccessContainer && v)
|
||||
{
|
||||
static_assert(!std::is_integral_v<Real>, "Integer data not implemented.");
|
||||
m_v = std::move(v);
|
||||
if (!std::is_sorted(m_v.begin(), m_v.end())) {
|
||||
std::sort(m_v.begin(), m_v.end());
|
||||
@@ -23,6 +22,17 @@ public:
|
||||
}
|
||||
|
||||
auto operator()(Real x) const {
|
||||
if constexpr (std::is_integral_v<Real>) {
|
||||
if (x < m_v[0]) {
|
||||
return double(0);
|
||||
}
|
||||
if (x >= m_v[m_v.size()-1]) {
|
||||
return double(1);
|
||||
}
|
||||
auto it = std::upper_bound(m_v.begin(), m_v.end(), x);
|
||||
return static_cast<double>(std::distance(m_v.begin(), it))/static_cast<double>(m_v.size());
|
||||
}
|
||||
else {
|
||||
if (x < m_v[0]) {
|
||||
return Real(0);
|
||||
}
|
||||
@@ -31,9 +41,11 @@ public:
|
||||
}
|
||||
auto it = std::upper_bound(m_v.begin(), m_v.end(), x);
|
||||
return static_cast<Real>(std::distance(m_v.begin(), it))/static_cast<Real>(m_v.size());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private:
|
||||
RandomAccessContainer m_v;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user