5#ifndef LINE_API_MAM_MMAP_LAMBDA_H
6#define LINE_API_MAM_MMAP_LAMBDA_H
48 std::vector<Matrix<T>>
Dc;
59 for (std::size_t i = 0; i < A.
rows(); ++i)
60 for (std::size_t j = 0; j < A.
cols(); ++j) {
62 for (std::size_t k = 0; k < B.
rows(); ++k)
63 for (std::size_t l = 0; l < B.
cols(); ++l)
64 C(i * B.
rows() + k, j * B.
cols() + l) = A(i, j) * B(k, l);
73 throw InputError(
"krons: both operands must be square");
77 for (std::size_t i = 0; i < C.
rows(); ++i)
78 for (std::size_t j = 0; j < C.
cols(); ++j) C(i, j) = left(i, j) + right(i, j);
89 const std::size_t na = a.
order(), nb = b.
order();
94 const Matrix<T> zeroA(na, na, zero), zeroB(nb, nb, zero);
95 for (std::size_t c = 0; c < a.
classes(); ++c) s.
Dc.push_back(
krons(a.
Dc[c], zeroB));
96 for (std::size_t c = 0; c < b.
classes(); ++c) s.
Dc.push_back(
krons(zeroA, b.
Dc[c]));
105 for (std::size_t c = 0; c < m.
classes(); ++c) {
106 const std::vector<T> t =
vecmul(theta, m.
Dc[c]);
107 for (
const T& v : t) lk[c] += v;
122 for (std::size_t i = 0; i < negD0.
rows(); ++i)
123 for (std::size_t j = 0; j < negD0.
cols(); ++j) negD0(i, j) = -negD0(i, j);
127 for (std::size_t c = 0; c < m.
classes(); ++c) {
129 for (
const T& v : t) pc[c] += v;
138 for (std::size_t i = 0; i < m.
order(); ++i) {
139 for (std::size_t j = 0; j < m.
order(); ++j) {
141 for (std::size_t c = 0; c < m.
classes(); ++c) {
142 if (m.
Dc[c](i, j) < zero)
return false;
145 if (s != m.
D1(i, j))
return false;
146 if (i != j && m.
D0(i, j) < zero)
return false;
149 for (std::size_t j = 0; j < m.
order(); ++j) row += m.
D0(i, j) + m.
D1(i, j);
150 if (row != zero)
return false;
172 for (std::size_t c = 0; c < m.
classes(); ++c)
173 for (std::size_t i = 0; i < m.
order(); ++i)
174 for (std::size_t j = 0; j < m.
order(); ++j)
175 if (m.
Dc[c](i, j) < -tol)
return false;
176 for (std::size_t i = 0; i < m.
order(); ++i)
177 for (std::size_t j = 0; j < m.
order(); ++j) {
179 for (std::size_t c = 0; c < m.
classes(); ++c) s -= m.
Dc[c](i, j);
180 if (
num_abs(T(s)) > tol)
return false;
193 const std::size_t n = m.
order();
194 for (std::size_t i = 0; i < n; ++i)
195 for (std::size_t j = 0; j < n; ++j)
196 if (i != j && m.
D0(i, j) < zero) m.
D0(i, j) = zero;
197 for (std::size_t c = 0; c < m.
classes(); ++c)
198 for (std::size_t i = 0; i < n; ++i)
199 for (std::size_t j = 0; j < n; ++j)
200 if (m.
Dc[c](i, j) < zero) m.
Dc[c](i, j) = zero;
202 for (std::size_t c = 0; c < m.
classes(); ++c)
203 for (std::size_t i = 0; i < n; ++i)
204 for (std::size_t j = 0; j < n; ++j) m.
D1(i, j) += m.
Dc[c](i, j);
205 for (std::size_t i = 0; i < n; ++i) {
208 for (std::size_t j = 0; j < n; ++j) s += m.
D0(i, j) + m.
D1(i, j);
220 for (std::size_t i = 0; i < m.
order(); ++i)
221 for (std::size_t j = 0; j < m.
order(); ++j) {
225 for (std::size_t c = 0; c < m.
classes(); ++c)
226 for (std::size_t i = 0; i < m.
order(); ++i)
227 for (std::size_t j = 0; j < m.
order(); ++j) m.
Dc[c](i, j) *= ratio;
247 for (std::size_t k : hide) {
257 std::vector<std::size_t> hide;
258 for (std::size_t k = 0; k < in.
classes(); ++k)
259 if (k != keep) hide.push_back(k);
269 const std::size_t C = weights.
cols();
270 if (C == 0)
throw InputError(
"mmap_mark: no classes");
271 for (std::size_t c = 0; c < C; ++c) {
273 for (std::size_t i = 0; i < Dc.
rows(); ++i)
274 for (std::size_t j = 0; j < Dc.
cols(); ++j) Dc(i, j) = base.
D1(i, j) * weights(i, c);
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.
Mmap< T > mmap_normalize(const Mmap< T > &in)
Clamp negative off-diagonal and per-class entries to zero and rebuild D1 and the diagonal of D0 from ...
Mmap< T > mmap_scale(const Mmap< T > &in, const T &M)
Rescale time so that the mean inter-arrival time becomes M.
std::vector< T > mmap_lambda(const Mmap< T > &m)
Alias kept for parity with the MATLAB name.
bool mmap_isfeasible_tol(const Mmap< T > &m, const T &tol)
Feasibility of a marked MAP WITHIN A TOLERANCE, the semantics of matlab/lib/m3a/m3a/mmap/mmap_isfeasi...
Matrix< T > krons(const Matrix< T > &A, const Matrix< T > &B)
Kronecker sum, MATLAB's krons: kron(A, I_nb) + kron(I_na, B).
Mmap< T > mmap_hide_but(const Mmap< T > &in, std::size_t keep)
mmap_hide(m, setdiff(1:K, keep)): keep ONE mark, hide every other.
Mmap< T > mmap_hide(const Mmap< T > &in, const std::vector< std::size_t > &hide)
Hide a subset of the marks (mmap_hide.m).
T map_mean(const Map< T > &m)
Mean inter-arrival time, 1/lambda.
Matrix< T > kron(const Matrix< T > &A, const Matrix< T > &B)
Kronecker product.
std::vector< T > map_prob(const Map< T > &m)
Stationary distribution of the phase process, pi (D0 + D1) = 0.
bool map_isfeasible(const Map< T > &m, const T &tol)
Structural feasibility of a MAP within a tolerance (map_isfeasible.m): off-diagonal D0 and all of D1 ...
Mmap< T > mmap_mark(const Map< T > &base, const Matrix< T > &weights)
Turn a MAP into a single-class MMAP (mmap_mark with one class).
std::vector< T > map_pie(const Map< T > &m)
Phase distribution seen by an arriving job, pie = pi D1 / (pi D1 e).
Mmap< T > mmap_super(const Mmap< T > &a, const Mmap< T > &b)
Superposition of two MMAPs: the phase process is the product chain, and the class list of the result ...
bool mmap_isfeasible(const Mmap< T > &m)
True when the per-class matrices partition D1 exactly and D0 is a generator.
std::vector< T > mmap_pc(const Mmap< T > &m)
Class probabilities seen by an arriving job, pc = pie (-D0)^-1 D1^(c) e.
std::vector< T > mmap_count_lambda(const Mmap< T > &m)
Per-class arrival rates, lambda_c = theta D1^(c) e.
std::vector< T > vecmul(const std::vector< T > &v, const Matrix< T > &A)
Row vector times matrix, v A.
Matrix< T > inverse(const Matrix< T > &A)
Inverse by LU with one factorization and n back substitutions.
Matrix< T > eye(std::size_t n)
Identity of order n.
Number-type abstraction for the templated API port.
A MAP as the pair of matrices (D0, D1).
An MMAP: the underlying MAP plus the per-class arrival matrices.
std::size_t classes() const
std::vector< Matrix< T > > Dc
per-class matrices, sum_c Dc = D1
std::size_t order() const