LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
trace_idc.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_IDC_H
6#define LINE_API_TRACE_TRACE_IDC_H
7
8/**
9 * @file
10 * @ingroup api_trace
11 * Index of dispersion for counts, estimated by its asymptotic equality with
12 * the index of dispersion for intervals at a large aggregation level.
13 *
14 * Templated port of matlab/lib/kpctoolbox/trace/trace_idc.m, cross-checked
15 * against `jar/src/main/java/jline/api/trace/Trace_var.java#trace_idc`.
16 *
17 * DIVERGENCE, MATLAB vs JAR: the aggregation level is
18 * min(1000, ceil(n/30)) in MATLAB but min(1000, n/30) with integer division
19 * in the JAR. They differ on every trace whose length is not a multiple of
20 * 30, and for n < 30 the JAR asks for k = 0, which its trace_idi turns into a
21 * division by zero (NaN). MATLAB is the reference.
22 *
23 * ARITHMETIC: as trace_idi, exact in Rational.
24 */
25
26#include <vector>
27
30#include "line/num/number.h"
31#include "line/util/error.h"
32
33namespace line {
34namespace trace {
35
36/**
37 * @brief Index of dispersion for counts, estimated by its asymptotic equality
38 * with the index of dispersion for intervals at a large aggregation
39 * level.
40 *
41 * @param S the trace; the aggregation level is min(1000, ceil(n/30)).
42 */
43template <class T>
44T trace_idc(const std::vector<T>& S) {
45 detail::require_nonempty(S, "trace_idc");
46 const long n = static_cast<long>(S.size());
47 const long k = std::min<long>(1000, (n + 29) / 30);
48 const TraceIdiResult<T> r = trace_idi(S, std::vector<long>(1, k));
49 return r.idi[0];
50}
51
52} // namespace trace
53} // namespace line
54
55#endif // LINE_API_TRACE_TRACE_IDC_H
The exception types the port throws.
T trace_idc(const std::vector< T > &S)
Index of dispersion for counts, estimated by its asymptotic equality with the index of dispersion for...
Definition trace_idc.h:44
TraceIdiResult< T > trace_idi(const std::vector< T > &S, const std::vector< long > &k_set, long aggregate_n=0, bool drop_trailing_zero=false)
Index of dispersion for intervals, IDI(k) = k * var(S_t + ... + S_{t+k-1}) / mean(S_t + ....
Definition trace_idi.h:71
Number-type abstraction for the templated API port.
Return value of trace_idi, mirroring [IDIk, support].
Definition trace_idi.h:52
std::vector< T > idi
one value per requested k
Definition trace_idi.h:53
Index of dispersion for intervals,.
Shared declarations for the empirical trace statistics domain.