LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Toggle main menu visibility
Loading...
Searching...
No Matches
ctmc_timereverse.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_MC_CTMC_TIMEREVERSE_H
6
#define LINE_API_MC_CTMC_TIMEREVERSE_H
7
8
/**
9
* @file
10
* @ingroup api_mc
11
* Time-reversed generator and transition matrix.
12
*
13
* Templated port of matlab/lib/kpctoolbox/mc/ctmc_timereverse.m and
14
* dtmc_timereverse.m. The reversed chain is Qrev = diag(pi)^-1 Q' diag(pi),
15
* written here as the transpose of the elementwise scaling Q(i,j) pi_i / pi_j,
16
* which is the same matrix and is how MATLAB assembles it.
17
*
18
* The construction needs the stationary law, so it is defined only for an
19
* irreducible chain: on a reducible one the stationary vector is not unique and
20
* the reversal is not either.
21
*/
22
23
#include <cstddef>
24
#include <vector>
25
26
#include "
line/api/mc/ctmc_solve.h
"
27
#include "
line/api/mc/dtmc_solve.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
mc
{
34
35
/** Generator of the time-reversed CTMC. */
36
template
<
class
T>
37
Matrix<T>
ctmc_timereverse
(
const
Matrix<T>
& Q) {
38
const
std::size_t n = Q.
rows
();
39
if
(Q.
cols
() != n)
throw
InputError
(
"ctmc_timereverse: Q is not square"
);
40
const
std::vector<T> pie =
ctmc_solve
(Q);
41
Matrix<T>
Qrev(n, n,
num_traits<T>::from_int
(0));
42
for
(std::size_t i = 0; i < n; ++i)
43
for
(std::size_t j = 0; j < n; ++j) Qrev(j, i) = Q(i, j) * pie[i] / pie[j];
44
return
Qrev;
45
}
46
47
/** Transition matrix of the time-reversed DTMC. */
48
template
<
class
T>
49
Matrix<T>
dtmc_timereverse
(
const
Matrix<T>
& P) {
50
const
std::size_t n = P.
rows
();
51
if
(P.
cols
() != n)
throw
InputError
(
"dtmc_timereverse: P is not square"
);
52
const
std::vector<T> pie =
dtmc_solve
(P);
53
Matrix<T>
Prev(n, n,
num_traits<T>::from_int
(0));
54
for
(std::size_t i = 0; i < n; ++i)
55
for
(std::size_t j = 0; j < n; ++j) Prev(j, i) = P(i, j) * pie[i] / pie[j];
56
return
Prev;
57
}
58
59
}
// namespace mc
60
}
// namespace line
61
62
#endif
line::InputError::InputError
InputError(const std::string &what)
Definition
error.h:39
line::Matrix
Definition
matrix.h:56
line::Matrix::cols
std::size_t cols() const
Definition
matrix.h:90
line::Matrix::rows
std::size_t rows() const
Definition
matrix.h:89
ctmc_solve.h
Steady-state distribution of a continuous-time Markov chain.
dtmc_solve.h
Equilibrium distribution of a discrete-time Markov chain, and stochastic complementation.
error.h
The exception types the port throws.
matrix.h
Dense matrix and non-owning view.
line::mc
Definition
ctmc_bicgstab.h:59
line::mc::ctmc_solve
std::vector< T > ctmc_solve(const Matrix< T > &Qin)
Steady-state distribution of a continuous-time Markov chain.
Definition
ctmc_solve.h:122
line::mc::dtmc_timereverse
Matrix< T > dtmc_timereverse(const Matrix< T > &P)
Transition matrix of the time-reversed DTMC.
Definition
ctmc_timereverse.h:49
line::mc::dtmc_solve
std::vector< T > dtmc_solve(const Matrix< T > &P)
Stationary distribution of a stochastic matrix P.
Definition
dtmc_solve.h:106
line::mc::ctmc_timereverse
Matrix< T > ctmc_timereverse(const Matrix< T > &Q)
Generator of the time-reversed CTMC.
Definition
ctmc_timereverse.h:37
line
Definition
aoi_dist2ph.h:52
number.h
Number-type abstraction for the templated API port.
line::num_traits
Definition
number.h:111
include
line
api
mc
ctmc_timereverse.h
Generated by
1.18.0