LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
mtrace_pc.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_MTRACE_PC_H
6#define LINE_API_TRACE_MTRACE_PC_H
7
8/**
9 * @file
10 * @ingroup api_trace
11 * Class probabilities of a marked trace, p_c = count_c / N.
12 *
13 * Templated port of matlab/lib/m3a/m3a/mtrace/mtrace_pc.m, cross-checked
14 * against jar/src/main/java/jline/api/trace/Mtrace_pc.java (identical).
15 *
16 * The inter-arrival times are not used; both references take them only for
17 * signature orthogonality with the rest of the mtrace family, so they are not
18 * a parameter here.
19 *
20 * ARITHMETIC: counts over the sample size, exact in Rational. The entries sum
21 * to exactly 1 in the exact backends.
22 */
23
24#include <cstddef>
25#include <vector>
26
28#include "line/num/number.h"
29#include "line/util/error.h"
30
31namespace line {
32namespace trace {
33
34/**
35 * @brief Class probabilities of a marked trace, p_c = count_c / N. Templated
36 * port of matlab/lib/m3a/m3a/mtrace/mtrace_pc.m, cross-checked against
37 * jar/src/main/java/jline/api/trace/Mtrace_pc.java (identical).
38 *
39 * @param A class labels; @return one probability per label of unique(A).
40 */
41template <class T>
42std::vector<T> mtrace_pc(const std::vector<int>& A) {
43 if (A.empty()) throw InputError("mtrace_pc: the trace is empty");
44 const std::vector<int> labels = detail::unique_labels(A);
45 std::vector<T> pc;
46 pc.reserve(labels.size());
47 const T N = num_traits<T>::from_int(static_cast<long>(A.size()));
48 for (std::size_t i = 0; i < labels.size(); ++i) {
49 long count = 0;
50 for (std::size_t k = 0; k < A.size(); ++k)
51 if (A[k] == labels[i]) ++count;
52 pc.push_back(num_traits<T>::from_int(count) / N);
53 }
54 return pc;
55}
56
57} // namespace trace
58} // namespace line
59
60#endif // LINE_API_TRACE_MTRACE_PC_H
InputError(const std::string &what)
Definition error.h:39
The exception types the port throws.
std::vector< T > mtrace_pc(const std::vector< int > &A)
Class probabilities of a marked trace, p_c = count_c / N.
Definition mtrace_pc.h:42
Number-type abstraction for the templated API port.
Shared declarations for the empirical trace statistics domain.