5#ifndef LINE_API_MAM_MAP_RAND_H
6#define LINE_API_MAM_MAP_RAND_H
47template <
class T,
class Gen>
49 std::uniform_real_distribution<double> unif(0.0, 1.0);
51 for (std::size_t i = 0; i < K; ++i)
52 for (std::size_t j = 0; j < K; ++j) {
60template <
class T,
class Gen>
62 std::normal_distribution<double> nrm(mu, sigma);
64 for (std::size_t i = 0; i < K; ++i)
65 for (std::size_t j = 0; j < K; ++j) {
73template <
class T,
class Gen>
75 std::uniform_real_distribution<double> unif(0.0, 1.0);
77 for (std::size_t i = 0; i < K; ++i)
79 for (std::size_t i = 0; i < K; ++i) {
80 for (std::size_t j = 0; j < K; ++j) {
81 const double v = unif(gen);
97template <
class T,
class Gen>
99 if (classes == 0)
throw InputError(
"m3pp_rand: at least one class is required");
100 std::uniform_real_distribution<double> unif(0.0, 1.0);
102 std::vector<T> p(classes);
104 for (std::size_t c = 0; c < classes; ++c) {
111 for (std::size_t c = 0; c < classes; ++c) {
113 for (std::size_t i = 0; i < K; ++i)
114 for (std::size_t j = 0; j < K; ++j) Dc(i, j) = base.
D1(i, j) * p[c] / tot;
115 out.
Dc.push_back(Dc);
121template <
class T,
class Gen>
123 std::uniform_real_distribution<double> unif(0.0, 1.0);
125 for (std::size_t i = 0; i < K; ++i)
127 for (std::size_t i = 0; i < K; ++i)
128 for (std::size_t j = 0; j < K; ++j) {
129 const double v = unif(gen);
136template <
class T,
class Gen>
138 std::uniform_real_distribution<double> unif(0.0, 1.0);
139 std::vector<T> v(k), alpha(k);
141 for (std::size_t i = 0; i < k; ++i) {
146 for (std::size_t i = 0; i < k; ++i) alpha[i] = alpha[i] / s;
148 for (std::size_t i = 0; i < k; ++i) {
150 for (std::size_t j = 0; j < k; ++j) H1(i, j) = v[i] * alpha[j];
156template <
class T,
class Gen>
158 if (classes == 0)
throw InputError(
"mmap_rand: at least one class is required");
160 std::uniform_real_distribution<double> unif(0.0, 1.0);
161 std::vector<T> p(classes);
163 for (std::size_t c = 0; c < classes; ++c) {
170 for (std::size_t c = 0; c < classes; ++c) {
172 for (std::size_t i = 0; i < Dc.
rows(); ++i)
173 for (std::size_t j = 0; j < Dc.
cols(); ++j) Dc(i, j) = Dc(i, j) * p[c] / s;
174 out.
Dc.push_back(Dc);
189 const std::size_t n = ph.
D0.rows();
191 for (std::size_t i = 0; i < n; ++i)
192 for (std::size_t j = 0; j < n; ++j)
193 if (i != j &&
num_abs(ph.
D0(i, j)) > tol)
194 throw InputError(
"ph2hyper: the PH distribution is not hyperexponential");
198 for (std::size_t i = 0; i < n; ++i) {
200 negD0(i, i) = out.
lambda[i];
Equilibrium distribution of a discrete-time Markov chain, and stochastic complementation.
The exception types the port throws.
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.
Marked MAP (MMAP) algebra: per-class rates, class probabilities, superposition, normalization and sca...
Map< T > mmpp_rand(std::size_t K, Gen &gen)
Random MMPP of order K: the arrival matrix is diagonal, so arrivals do not switch phase.
Map< T > aph_rand(std::size_t K, Gen &gen)
Random acyclic PH renewal process of order K, upper triangular in D0.
Map< T > map_renewal(const Map< T > &in)
Renewal process with the same inter-arrival distribution: D1 is replaced by (D1 e) pie,...
Mmap< T > m3pp_rand(std::size_t K, std::size_t classes, Gen &gen)
Random M3PP of order K with classes marks (m3a/m3pp/m3pp_rand.m).
Map< T > map_randn(std::size_t K, double mu, double sigma, Gen &gen)
Random MAP of order K with folded normal entries, normalized.
Map< T > map_rand(std::size_t K, Gen &gen)
Random MAP of order K with uniform [0,1) entries, normalized.
Map< T > map_normalize(const Map< T > &in)
Clamp negative off-diagonal entries of D0 and negative entries of D1 to zero, then rebuild the diagon...
Map< T > hyper_rand(std::size_t k, Gen &gen)
Random hyperexponential of order k, given as a MAP.
Mmap< T > mmap_rand(std::size_t order, std::size_t classes, Gen &gen)
Random MMAP of the given order with a random split of D1 across the classes.
HyperParams< T > ph2hyper(const Map< T > &ph)
Reads a hyperexponential MAP back into rates and branch probabilities.
std::vector< T > dtmc_solve(const Matrix< T > &P)
Stationary distribution of a stochastic matrix P.
Matrix< T > inverse(const Matrix< T > &A)
Inverse by LU with one factorization and n back substitutions.
Matrix< T > matmul(const Matrix< T > &A, const Matrix< T > &B)
Matrix product A B.
Number-type abstraction for the templated API port.
Rates and branch probabilities of a hyperexponential given as a MAP.
A MAP as the pair of matrices (D0, D1).
An MMAP: the underlying MAP plus the per-class arrival matrices.
std::vector< Matrix< T > > Dc
per-class matrices, sum_c Dc = D1