LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
trace_mean.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_MEAN_H
6#define LINE_API_TRACE_TRACE_MEAN_H
7
8/**
9 * @file
10 * @ingroup api_trace
11 * Sample mean of a trace.
12 *
13 * Templated port of matlab/lib/kpctoolbox/trace/trace_mean.m, cross-checked
14 * against jar/src/main/java/jline/api/trace/Trace_mean.java (identical: both
15 * are sum/n).
16 *
17 * ARITHMETIC: a sum and one division, exact in Rational.
18 */
19
20#include <vector>
21
23#include "line/num/number.h"
24#include "line/util/error.h"
25
26namespace line {
27namespace trace {
28
29/** (1/n) sum_i S(i). */
30template <class T>
31T trace_mean(const std::vector<T>& S) {
32 detail::require_nonempty(S, "trace_mean");
34 for (const T& v : S) s += v;
35 return s / num_traits<T>::from_int(static_cast<long>(S.size()));
36}
37
38} // namespace trace
39} // namespace line
40
41#endif // LINE_API_TRACE_TRACE_MEAN_H
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
Number-type abstraction for the templated API port.
Shared declarations for the empirical trace statistics domain.