5#ifndef LINE_API_TRACE_TRACE_SUMMARY_H
6#define LINE_API_TRACE_TRACE_SUMMARY_H
58inline T sorted_median(
const std::vector<T>& x) {
59 const std::size_t n = x.size();
60 if (n % 2 == 1)
return x[n / 2];
61 return (x[n / 2 - 1] + x[n / 2]) / num_traits<T>::from_int(2);
66inline T sorted_percentile(
const std::vector<T>& x,
long p_num,
long p_den) {
67 const long n =
static_cast<long>(x.size());
68 if (n == 1)
return x[0];
70 const long num = p_num * (n - 1);
71 const long lower = num / (p_den * 100);
72 const long rem = num - lower * p_den * 100;
73 if (rem == 0)
return x[
static_cast<std::size_t
>(lower)];
74 const T w = num_traits<T>::from_rational(rem, p_den * 100);
75 return x[
static_cast<std::size_t
>(lower)] * (num_traits<T>::from_int(1) - w) +
76 x[
static_cast<std::size_t
>(lower + 1)] * w;
105 "trace_summary requires transcendental arithmetic");
106 detail::require_nonempty(S,
"trace_summary");
107 if (S.size() < 6)
throw InputError(
"trace_summary: at least six samples are required");
113 std::vector<T> x = S;
114 std::sort(x.begin(), x.end());
117 out.
q25 = detail::sorted_percentile(x, 25, 1);
118 out.
q50 = detail::sorted_percentile(x, 50, 1);
119 out.
q75 = detail::sorted_percentile(x, 75, 1);
120 out.
p95 = detail::sorted_percentile(x, 95, 1);
123 std::vector<T> dev(S.size());
124 for (std::size_t i = 0; i < S.size(); ++i) dev[i] =
num_abs(T(S[i] - out.
q50));
125 std::sort(dev.begin(), dev.end());
126 out.
mad = detail::sorted_median(dev);
132 throw NumericError(
"trace_summary: the trace is constant");
134 for (std::size_t i = 0; i < S.size(); ++i) {
135 const T d = S[i] - out.
mean;
141 std::vector<int> lags;
142 for (
int l = 1; l <= 4; ++l) lags.push_back(l);
NumericError(const std::string &what)
The exception types the port throws.
T trace_skew(const std::vector< T > &S)
Bias-corrected sample skewness (MATLAB's skewness(S,0), equivalently the G1 estimator).
T trace_idc(const std::vector< T > &S)
Index of dispersion for counts, estimated by its asymptotic equality with the index of dispersion for...
T trace_mean(const std::vector< T > &S)
(1/n) sum_i S(i).
TraceSummary< T > trace_summary(const std::vector< T > &S)
Descriptive summary of a trace: moments, shape, order statistics, autocorrelation and burstiness.
T trace_var(const std::vector< T > &S, bool unbiased=true)
Sample variance of a trace.
T trace_scv(const std::vector< T > &S, bool unbiased=true)
Squared coefficient of variation of a trace, var/mean^2.
std::vector< T > trace_acf(const std::vector< T > &S, const std::vector< int > &lags)
Autocorrelation coefficients of a trace at the requested lags.
Number-type abstraction for the templated API port.
Return value of trace_summary.
T mad
median absolute deviation about the median
T kurt_excess
population kurtosis minus 3
std::vector< T > acf
lags 1..4
T skew
bias-corrected skewness, see trace_skew
Autocorrelation coefficients of a trace at the requested lags.
Index of dispersion for counts, estimated by its asymptotic equality with the index of dispersion for...
Squared coefficient of variation of a trace, var/mean^2.
Bias-corrected sample skewness (MATLAB's skewness(S,0), equivalently the G1 estimator).
Shared declarations for the empirical trace statistics domain.
Sample variance of a trace.