LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
trace_bicov.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_BICOV_H
6#define LINE_API_TRACE_TRACE_BICOV_H
7
8/**
9 * @file
10 * @ingroup api_trace
11 * Bicovariance of a trace on a lag grid.
12 *
13 * Templated port of matlab/lib/kpctoolbox/trace/trace_bicov.m, cross-checked
14 * against `jar/src/main/java/jline/api/trace/Trace_var.java#trace_bicov` (same
15 * grid construction; the JAR values differ because its trace_joint drops the
16 * cumulative sum, see trace_joint.h).
17 *
18 * For every ordered pair (i,j) drawn from the grid the third-order joint
19 * moment E[X_t X_{t+i} X_{t+i+j}] is evaluated. Note that both references
20 * return the raw joint moment, not a centred cumulant, despite the name.
21 *
22 * ARITHMETIC: a vector of joint moments, exact in Rational.
23 */
24
25#include <cstddef>
26#include <vector>
27
30#include "line/num/number.h"
31#include "line/util/error.h"
32
33namespace line {
34namespace trace {
35
36/** Return value of trace_bicov, mirroring [BiCov, BiCovLags]. */
37template <class T>
39 std::vector<T> bicov; ///< one moment per grid pair
40 std::vector<std::vector<int>> lags; ///< the [1,i,j] increment triples
41};
42
43/**
44 * @brief Bicovariance of a trace on a lag grid.
45 *
46 * @param S the trace
47 * @param grid the lag values swept in both positions
48 */
49template <class T>
50TraceBicovResult<T> trace_bicov(const std::vector<T>& S, const std::vector<int>& grid) {
51 detail::require_nonempty(S, "trace_bicov");
53 const std::vector<unsigned> order(3, 1u);
54 for (std::size_t a = 0; a < grid.size(); ++a) {
55 for (std::size_t b = 0; b < grid.size(); ++b) {
56 std::vector<int> lag(3);
57 lag[0] = 1;
58 lag[1] = grid[a];
59 lag[2] = grid[b];
60 out.lags.push_back(lag);
61 out.bicov.push_back(trace_joint(S, lag, order));
62 }
63 }
64 return out;
65}
66
67} // namespace trace
68} // namespace line
69
70#endif // LINE_API_TRACE_TRACE_BICOV_H
The exception types the port throws.
TraceBicovResult< T > trace_bicov(const std::vector< T > &S, const std::vector< int > &grid)
Bicovariance of a trace on a lag grid.
Definition trace_bicov.h:50
T trace_joint(const std::vector< T > &S, const std::vector< int > &lag, const std::vector< unsigned > &order)
Joint moments of a trace, E[X_i^{k_1} X_{i+l_2}^{k_2} ...].
Definition trace_joint.h:53
Number-type abstraction for the templated API port.
Return value of trace_bicov, mirroring [BiCov, BiCovLags].
Definition trace_bicov.h:38
std::vector< std::vector< int > > lags
the [1,i,j] increment triples
Definition trace_bicov.h:40
std::vector< T > bicov
one moment per grid pair
Definition trace_bicov.h:39
Joint moments of a trace, E[X_i^{k_1} X_{i+l_2}^{k_2} ...].
Shared declarations for the empirical trace statistics domain.