| Server IP : 93.86.61.54 / Your IP : 216.73.216.156 Web Server : Apache/2.4.62 (Ubuntu) System : Linux rasin.ddns.net 6.8.0-124-generic #124~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 21:05:19 UTC x86_64 User : www-data ( 33) PHP Version : 8.4.22 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /usr/include/boost/math/distributions/ |
Upload File : |
// Copyright Nick Thompson 2019.
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_MATH_DISTRIBUTIONS_EMPIRICAL_CUMULATIVE_DISTRIBUTION_FUNCTION_HPP
#define BOOST_MATH_DISTRIBUTIONS_EMPIRICAL_CUMULATIVE_DISTRIBUTION_FUNCTION_HPP
#include <algorithm>
#include <iterator>
#include <stdexcept>
namespace boost { namespace math{
template<class RandomAccessContainer>
class empirical_cumulative_distribution_function {
using Real = typename RandomAccessContainer::value_type;
public:
empirical_cumulative_distribution_function(RandomAccessContainer && v, bool sorted = false)
{
if (v.size() == 0) {
throw std::domain_error("At least one sample is required to compute an empirical CDF.");
}
m_v = std::move(v);
if (!sorted) {
std::sort(m_v.begin(), m_v.end());
}
}
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);
}
if (x >= m_v[m_v.size()-1]) {
return Real(1);
}
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());
}
}
RandomAccessContainer&& return_data() {
return std::move(m_v);
}
private:
RandomAccessContainer m_v;
};
}}
#endif