LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
trace_scv.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012-2026, QORE Lab, Imperial College London
3 * All rights reserved.
4 */
5#ifndef LINE_API_TRACE_TRACE_SCV_H
6#define LINE_API_TRACE_TRACE_SCV_H
7
8/**
9 * @file
10 * @ingroup api_trace
11 * Squared coefficient of variation of a trace, var/mean^2.
12 *
13 * Templated port of matlab/lib/kpctoolbox/trace/trace_scv.m, cross-checked
14 * against `jar/src/main/java/jline/api/trace/Trace_var.java#trace_scv`. The
15 * expression is the same; the two differ only through the variance
16 * denominator, see trace_var.h.
17 *
18 * ARITHMETIC: a ratio of sample moments, exact in Rational.
19 */
20
21#include <vector>
22
26#include "line/num/number.h"
27#include "line/util/error.h"
28
29namespace line {
30namespace trace {
31
32/**
33 * @brief Squared coefficient of variation of a trace, var/mean^2.
34 *
35 * @param S the trace
36 * @param unbiased variance denominator, see trace_var
37 */
38template <class T>
39T trace_scv(const std::vector<T>& S, bool unbiased = true) {
40 const T mu = trace_mean(S);
41 if (mu == num_traits<T>::from_int(0)) throw NumericError("trace_scv: the trace has zero mean");
42 return trace_var(S, unbiased) / (mu * mu);
43}
44
45} // namespace trace
46} // namespace line
47
48#endif // LINE_API_TRACE_TRACE_SCV_H
NumericError(const std::string &what)
Definition error.h:45
The exception types the port throws.
T trace_mean(const std::vector< T > &S)
(1/n) sum_i S(i).
Definition trace_mean.h:31
T trace_var(const std::vector< T > &S, bool unbiased=true)
Sample variance of a trace.
Definition trace_var.h:45
T trace_scv(const std::vector< T > &S, bool unbiased=true)
Squared coefficient of variation of a trace, var/mean^2.
Definition trace_scv.h:39
Number-type abstraction for the templated API port.
Sample mean of a trace.
Shared declarations for the empirical trace statistics domain.
Sample variance of a trace.