LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Toggle main menu visibility
Loading...
Searching...
No Matches
mtrace_sigma.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_SIGMA_H
6
#define LINE_API_TRACE_MTRACE_SIGMA_H
7
8
/**
9
* @file
10
* @ingroup api_trace
11
* One-step class transition frequencies of a marked trace,
12
*
13
* sigma(i,j) = #{t : A_t = i, A_{t+1} = j} / (N-1).
14
*
15
* Templated port of matlab/lib/m3a/m3a/mtrace/mtrace_sigma.m, cross-checked
16
* against jar/src/main/java/jline/api/trace/Mtrace_sigma.java (identical).
17
*
18
* Note that this is the JOINT frequency of the pair, not the conditional
19
* transition probability: the whole matrix sums to 1, its rows do not.
20
*
21
* ARITHMETIC: counts over N-1, exact in Rational.
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
#include "
line/util/matrix.h
"
31
32
namespace
line
{
33
namespace
trace
{
34
35
/**
36
* @brief One-step class transition frequencies of a marked trace, sigma(i,j)
37
* = #{t : A_t = i, A_{t+1} = j} / (N-1).
38
*
39
* @param L class labels; @return (C x C) matrix over the labels of unique(L).
40
*/
41
template
<
class
T>
42
Matrix<T>
mtrace_sigma
(
const
std::vector<int>& L) {
43
if
(L.size() < 2)
throw
InputError
(
"mtrace_sigma: at least two events are required"
);
44
const
std::vector<int> marks = detail::unique_labels(L);
45
const
std::size_t C = marks.size();
46
Matrix<T>
sigma(C, C,
num_traits<T>::from_int
(0));
47
const
T den =
num_traits<T>::from_int
(
static_cast<
long
>
(L.size() - 1));
48
for
(std::size_t i = 0; i < C; ++i) {
49
for
(std::size_t j = 0; j < C; ++j) {
50
long
count = 0;
51
for
(std::size_t t = 0; t + 1 < L.size(); ++t)
52
if
(L[t] == marks[i] && L[t + 1] == marks[j]) ++count;
53
sigma(i, j) =
num_traits<T>::from_int
(count) / den;
54
}
55
}
56
return
sigma;
57
}
58
59
}
// namespace trace
60
}
// namespace line
61
62
#endif
// LINE_API_TRACE_MTRACE_SIGMA_H
line::InputError::InputError
InputError(const std::string &what)
Definition
error.h:39
line::Matrix
Definition
matrix.h:56
error.h
The exception types the port throws.
matrix.h
Dense matrix and non-owning view.
line::trace
Definition
autocov.h:38
line::trace::mtrace_sigma
Matrix< T > mtrace_sigma(const std::vector< int > &L)
One-step class transition frequencies of a marked trace, sigma(i,j) = #{t : A_t = i,...
Definition
mtrace_sigma.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_sigma.h
Generated by
1.18.0