LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
map_cdf.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_MAP_CDF_H
6#define LINE_API_MAM_MAP_CDF_H
7
8/**
9 * @file
10 * @ingroup api_mam
11 * Cumulative distribution of the inter-arrival time of a MAP.
12 *
13 * Templated port of matlab/lib/kpctoolbox/map/map_cdf.m, cross-checked against
14 * jar/src/main/java/jline/api/mam/Map_cdf.java.
15 *
16 * Conditional on the phase pie seen by an arrival, the next inter-arrival time
17 * is phase-type with representation (pie, D0), so
18 *
19 * F(t) = 1 - pie exp(D0 t) e, f(t) = pie exp(D0 t) (-D0) e.
20 *
21 * ARITHMETIC: exp(D0 t) is a tolerance-controlled approximation, so both
22 * functions require transcendental arithmetic; pie itself is exact (a linear
23 * solve, see map_moment.h).
24 *
25 * DIVERGENCE, MATLAB vs JAR: MATLAB evaluates exp(D0 t) directly for every
26 * process. The JAR switches to Foxglynn uniformization when D0 has no negative
27 * off-diagonal entry and to a direct exponential otherwise, because
28 * uniformization is invalid for an ME/RAP representation whose D0 is not a
29 * sub-generator. This port follows MATLAB and always uses the exponential,
30 * which is correct for both cases. NOTE, MEASURED: the uniformization path is
31 * not merely faster, it is also the ACCURATE one at small t. F(t) = 1 - s here
32 * loses every significant digit once s is within a few ulp of one, so for a
33 * value far below the rounding of s this function returns round-off of either
34 * sign; uniformization with an explicit absorbing state sums only nonnegative
35 * terms and stays exact. pfqn_stdf therefore evaluates its level CDFs by that
36 * construction (detail::stdf_hypoexp_cdf) rather than through this function.
37 * Any caller of map_cdf that needs a small CDF accurately has the same problem
38 * and no fix. The JAR additionally clamps a NaN CDF value to the previous
39 * finite one, which is a workaround, not a definition, and is not reproduced.
40 */
41
42#include <cstddef>
43#include <vector>
44
46#include "line/num/number.h"
47#include "line/util/error.h"
48#include "line/util/expm.h"
49#include "line/util/linalg.h"
50#include "line/util/matrix.h"
51
52namespace line {
53namespace mam {
54
55/**
56 * Cumulative distribution of the inter-arrival time at the given points.
57 *
58 * @param m the MAP (D0, D1)
59 * @param points evaluation times, each >= 0
60 * @return F(t) = Pr[T <= t] in the order of points
61 */
62template <class T>
63std::vector<T> map_cdf(const Map<T>& m, const std::vector<T>& points) {
64 static_assert(num_traits<T>::has_transcendental, "map_cdf requires transcendental arithmetic");
65 const std::vector<T> pie = map_pie(m);
66 const T zero = num_traits<T>::from_int(0);
67 const T one = num_traits<T>::from_int(1);
68 std::vector<T> out;
69 out.reserve(points.size());
70 for (std::size_t k = 0; k < points.size(); ++k) {
71 if (points[k] < zero) throw InputError("map_cdf: negative evaluation point");
72 if (points[k] == zero) {
73 out.push_back(zero);
74 continue;
75 }
76 const std::vector<T> v = vecmul(pie, expm(m.D0, points[k]));
77 T s = zero;
78 for (const T& x : v) s += x;
79 out.push_back(one - s);
80 }
81 return out;
82}
83
84} // namespace mam
85} // namespace line
86
87#endif // LINE_API_MAM_MAP_CDF_H
InputError(const std::string &what)
Definition error.h:39
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.
Markovian arrival process descriptors: stationary vectors, rate, moments, autocorrelation and the ind...
Dense matrix and non-owning view.
std::vector< T > map_cdf(const Map< T > &m, const std::vector< T > &points)
Cumulative distribution of the inter-arrival time at the given points.
Definition map_cdf.h:63
std::vector< T > map_pie(const Map< T > &m)
Phase distribution seen by an arriving job, pie = pi D1 / (pi D1 e).
Definition map_moment.h:89
std::vector< T > vecmul(const std::vector< T > &v, const Matrix< T > &A)
Row vector times matrix, v A.
Definition linalg.h:50
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
Matrix< T > D0
Definition map_moment.h:54