LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
mmap_count_var.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_MAM_MMAP_COUNT_VAR_H
6#define LINE_API_MAM_MMAP_COUNT_VAR_H
7
8/**
9 * @file
10 * @ingroup api_mam
11 * Per-class variance of the counting process of a marked MAP.
12 *
13 * Templated port of matlab/lib/m3a/m3a/mmap/mmap_count_var.m. It is the He and
14 * Neuts variance of map_count_var applied class by class: for class k, with
15 * D = D0 + D1 the generator of the phase process (the AGGREGATE one, not the
16 * class-k one), theta its stationary vector and tmp = (e theta - D)^-1,
17 *
18 * Var[N_k(t)] = (lambda_k - 2 lambda_k^2 + 2 theta Dk tmp Dk e) t
19 * - 2 theta Dk tmp (I - exp(D t)) tmp Dk e,
20 *
21 * with lambda_k = theta Dk e. The phase process is shared across classes, so
22 * the exponential is computed once and reused for every class.
23 *
24 * ARITHMETIC: transcendental, as map_count_var. The rational MMAP counting
25 * descriptors (mmap_count_mean, mmap_count_lambda) are in mmap_lambda.h.
26 */
27
28#include <cstddef>
29#include <vector>
30
34#include "line/num/number.h"
35#include "line/util/error.h"
36#include "line/util/expm.h"
37#include "line/util/linalg.h"
38#include "line/util/matrix.h"
39
40namespace line {
41namespace mam {
42
43/**
44 * @brief Per-class variance of the counting process of a marked MAP.
45 *
46 * @param mm the marked MAP
47 * @param t window length
48 * @return Var[N_k(t)] for each class k
49 */
50template <class T>
51std::vector<T> mmap_count_var(const Mmap<T>& mm, const T& t) {
53 "mmap_count_var requires transcendental arithmetic");
54 if (t < num_traits<T>::from_int(0)) throw InputError("mmap_count_var: negative window length");
55 const std::size_t n = mm.order();
56 const std::size_t K = mm.classes();
57 if (K == 0) throw InputError("mmap_count_var: the MMAP has no classes");
58
59 const Map<T> base = mm.map();
60 const Matrix<T> D = map_infgen(base);
61 const std::vector<T> theta = map_prob(base);
62 const Matrix<T> tmp = detail::map_count_deviation(D, theta);
63 const std::vector<T> e = ones<T>(n);
64 const Matrix<T> E = expm(D, t);
65 const T two = num_traits<T>::from_int(2);
66
67 std::vector<T> out;
68 out.reserve(K);
69 for (std::size_t k = 0; k < K; ++k) {
70 const Matrix<T>& Dk = mm.Dc[k];
71 const std::vector<T> thetaDk = vecmul(theta, Dk);
72 T lam = num_traits<T>::from_int(0);
73 for (const T& v : thetaDk) lam += v;
74 const std::vector<T> c = vecmul(thetaDk, tmp); // theta Dk tmp
75 const std::vector<T> d = mulvec(tmp, mulvec(Dk, e)); // tmp Dk e
76 const std::vector<T> cDk = vecmul(c, Dk);
77 T cDke = num_traits<T>::from_int(0);
78 for (const T& v : cDk) cDke += v;
79
80 const std::vector<T> cE = vecmul(c, E);
81 T corr = num_traits<T>::from_int(0);
82 for (std::size_t i = 0; i < n; ++i) corr += (c[i] - cE[i]) * d[i];
83 out.push_back((lam - two * lam * lam + two * cDke) * t - two * corr);
84 }
85 return out;
86}
87
88} // namespace mam
89} // namespace line
90
91#endif // LINE_API_MAM_MMAP_COUNT_VAR_H
InputError(const std::string &what)
Definition error.h:105
The exception types the port throws.
Matrix exponential by scaling and squaring with a diagonal Pade approximant.
Dense linear algebra over the templated number type: products, identity, inverse, and powers.
Variance of the counting process of a MAP at resolution t.
Markovian arrival process descriptors: stationary vectors, rate, moments, autocorrelation and the ind...
Dense matrix and non-owning view.
Marked MAP (MMAP) algebra: per-class rates, class probabilities, superposition, normalization and sca...
Matrix< T > map_infgen(const Map< T > &m)
Generator of the underlying phase process, D0 + D1.
Definition map_moment.h:62
std::vector< T > map_prob(const Map< T > &m)
Stationary distribution of the phase process, pi (D0 + D1) = 0.
Definition map_moment.h:73
std::vector< T > mmap_count_var(const Mmap< T > &mm, const T &t)
Per-class variance of the counting process of a marked MAP.
Conservation laws of a layered queueing network, enumerated from its structure.
Definition aoi_dist2ph.h:52
std::vector< T > vecmul(const std::vector< T > &v, const Matrix< T > &A)
Row vector times matrix, v A.
Definition linalg.h:50
std::vector< T > mulvec(const Matrix< T > &A, const std::vector< T > &v)
Matrix times column vector, A v.
Definition linalg.h:62
std::vector< T > ones(std::size_t n)
Column vector of ones, the ubiquitous e in MAP algebra.
Definition linalg.h:104
Matrix< T > expm(const Matrix< T > &A)
Matrix exponential exp(A).
Definition expm.h:141
Number-type abstraction for the templated API port.
A MAP as the pair of matrices (D0, D1).
Definition map_moment.h:53
An MMAP: the underlying MAP plus the per-class arrival matrices.
Definition mmap_lambda.h:45
Map< T > map() const
Definition mmap_lambda.h:52
std::size_t classes() const
Definition mmap_lambda.h:51
std::vector< Matrix< T > > Dc
per-class matrices, sum_c Dc = D1
Definition mmap_lambda.h:48
std::size_t order() const
Definition mmap_lambda.h:50