LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Toggle main menu visibility
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
27
#include "
line/api/trace/trace_types.h
"
28
#include "
line/num/number.h
"
29
#include "
line/util/error.h
"
30
31
namespace
line
{
32
namespace
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
*/
41
template
<
class
T>
42
std::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
line::InputError::InputError
InputError(const std::string &what)
Definition
error.h:39
error.h
The exception types the port throws.
line::trace
Definition
autocov.h:38
line::trace::mtrace_pc
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
line
Definition
aoi_dist2ph.h:52
number.h
Number-type abstraction for the templated API port.
line::num_traits
Definition
number.h:111
trace_types.h
Shared declarations for the empirical trace statistics domain.
include
line
api
trace
mtrace_pc.h
Generated by
1.18.0