cpp-toolbox  0.0.1
A toolbox library for C++
Loading...
Searching...
No Matches
statistics.hpp File Reference
#include <algorithm>
#include <cmath>
#include <functional>
#include <iterator>
#include <map>
#include <numeric>
#include <stdexcept>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>
#include <cpp-toolbox/type_traits.hpp>
Include dependency graph for statistics.hpp:

Go to the source code of this file.

Namespaces

namespace  toolbox
 
namespace  toolbox::math
 

Functions

template<typename TContainer >
void toolbox::math::check_empty (const TContainer &data, const char *func_name)
 检查容器是否为空并抛出异常/Check if the container is empty and throw an exception
 
template<typename TContainer >
double toolbox::math::mean (const TContainer &data)
 计算容器中元素的平均值/Compute the mean (average) of elements in a container
 
template<typename TContainer >
double toolbox::math::median (const TContainer &data)
 计算容器中元素的中位数/Compute the median of elements in a container
 
template<typename TContainer >
std::vector< typename TContainer::value_type > toolbox::math::mode (const TContainer &data)
 计算容器中元素的众数(可能有多个)/Compute the mode(s) of elements in a container (may be multiple)
 
template<typename TContainer >
double toolbox::math::variance (const TContainer &data, bool sample_variance=true)
 计算方差(默认样本方差 N-1)/Compute the variance (default is sample variance N-1)
 
template<typename TContainer >
double toolbox::math::stdev (const TContainer &data, bool sample_stdev=true)
 计算标准差(默认样本标准差)/Compute the standard deviation (default is sample standard deviation)
 
template<typename TContainer >
TContainer::value_type toolbox::math::sum (const TContainer &data)
 计算容器中元素的总和(返回容器元素类型)/Compute the sum of elements in the container (returns container element type)
 
template<typename TContainer >
double toolbox::math::sum_d (const TContainer &data)
 计算容器中元素的总和(返回 double 类型以保证精度和范围)/Compute the sum of elements in the container (returns double for precision and range)
 
template<typename TContainer >
TContainer::value_type toolbox::math::min (const TContainer &data)
 查找容器中的最小值/Find the minimum value in the container
 
template<typename TContainer >
TContainer::value_type toolbox::math::max (const TContainer &data)
 查找容器中的最大值/Find the maximum value in the container
 
template<typename TContainer >
TContainer::value_type toolbox::math::range (const TContainer &data)
 计算容器中元素的全距(最大值-最小值)/Compute the range (max - min) of elements in the container
 
template<typename TContainer >
double toolbox::math::percentile (const TContainer &data, double p)
 计算百分位数(使用最近邻等级法和线性插值)/Compute the percentile (using nearest-rank and linear interpolation)
 
template<typename TContainer >
std::vector< typename TContainer::value_type > toolbox::math::min_k (const TContainer &data, size_t k)
 返回容器中k个最小的元素,升序排列/Return the k smallest elements in the container, sorted ascending
 
template<typename TContainer >
std::vector< typename TContainer::value_type > toolbox::math::max_k (const TContainer &data, size_t k)
 返回容器中k个最大的元素,降序排列/Return the k largest elements in the container, sorted descending