5#ifndef LINE_API_MAM_MMAP_COMPRESS_H
6#define LINE_API_MAM_MMAP_COMPRESS_H
92 const std::vector<unsigned>& orders,
94 const std::size_t n = m.
order();
95 const std::size_t C = m.
classes();
99 for (std::size_t i = 0; i < n; ++i)
100 for (std::size_t j = 0; j < n; ++j) negD0(i, j) = -negD0(i, j);
103 std::vector<std::vector<T>> B(C, std::vector<T>(orders.size(), zero));
104 for (std::size_t c = 0; c < C; ++c) {
109 for (
const T& v : t) pa += v;
112 "mmap_backward_moment: class with zero arrival probability cannot be "
115 for (std::size_t h = 0; h < orders.size(); ++h) {
116 const unsigned k = orders[h];
119 for (
const T& v : t) s += v;
129 const std::vector<unsigned>& orders) {
150 const std::size_t I = maps.size();
151 if (I == 0)
throw InputError(
"mmap_mixture: no components");
152 if (alpha.size() != I)
throw InputError(
"mmap_mixture: one weight per component is required");
155 std::vector<std::size_t> sz(I), off(I);
156 std::size_t total = 0;
157 for (std::size_t i = 0; i < I; ++i) {
158 sz[i] = maps[i].order();
163 std::vector<std::vector<T>> pies(I);
164 for (std::size_t j = 0; j < I; ++j) pies[j] =
map_pie(maps[j]);
171 for (std::size_t i = 0; i < I; ++i) {
172 for (std::size_t a = 0; a < sz[i]; ++a)
173 for (std::size_t b = 0; b < sz[i]; ++b) out.
D0(off[i] + a, off[i] + b) = maps[i].D0(a, b);
175 std::vector<T> t(sz[i], zero);
176 for (std::size_t a = 0; a < sz[i]; ++a)
177 for (std::size_t b = 0; b < sz[i]; ++b) t[a] += maps[i].D1(a, b);
178 for (std::size_t j = 0; j < I; ++j)
179 for (std::size_t a = 0; a < sz[i]; ++a)
180 for (std::size_t b = 0; b < sz[j]; ++b) {
181 const T v = alpha[j] * t[a] * pies[j][b];
182 out.
D1(off[i] + a, off[j] + b) = v;
183 out.
Dc[i](off[i] + a, off[j] + b) = v;
213 "mmap_compress requires transcendental arithmetic");
216 "mmap_compress: only the order-1 mixture is ported; the 'mixture.order2', 'mamap2', "
217 "'mamap2.fb' and 'm3pp.*' methods dispatch to fitting families that are not part of "
218 "this port (mmap_mixture_fit_mmap, mamap2m_fit_mmap, mamap2m_fit_gamma_fb_mmap, "
219 "m3pp2m_fitc_theoretical)");
221 const std::size_t K = in.
classes();
222 if (K == 0)
throw InputError(
"mmap_compress: the MMAP has no classes");
223 const std::vector<T> p =
mmap_pc(in);
224 std::vector<unsigned> orders;
225 orders.push_back(1u);
226 orders.push_back(2u);
227 orders.push_back(3u);
231 std::vector<Map<T>> comps;
233 for (std::size_t k = 0; k < K; ++k) {
234 if (p[k] <= zeroTol) {
239 one.
Dc.assign(1, in.
Dc[k]);
241 comps.push_back(
aph2_fit(B[0][0], B[0][1], B[0][2]).aph);
APH(2) fit of three moments, with a fallback to adjusted moments (matlab/lib/m3a/m3a/aph2/aph2_fit....
NumericError(const std::string &what)
UnsupportedError(const std::string &what)
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...
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 ...
MmapCompressMethod
The compression methods of mmap_compress.m.
@ M3ppApproxDelta
'm3pp.approx_delta', not ported
@ M3ppApproxAg
'm3pp.approx_ag', not ported
@ Mamap2
'mamap2', not ported
@ Mamap2Fb
'mamap2.fb', not ported
@ MixtureOrder1
'default', 'mixture', 'mixture.order1'
@ MixtureOrder2
'mixture.order2', not ported
@ M3ppExactDelta
'm3pp.exact_delta', not ported
@ M3ppApproxCov
'm3pp.approx_cov', not ported
Aph2FitResult< T > aph2_fit(const T &M1, const T &M2, const T &M3)
Fit an APH(2) to (M1, M2, M3), relaxing the moments if necessary.
Mmap< T > mmap_mixture(const std::vector< T > &alpha, const std::vector< Map< T > > &maps)
Probabilistic mixture of MAPs (mmap_mixture.m).
Map< T > map_exponential(const T &lambda)
Two-phase MAP constructor for a Poisson process of rate lambda.
Mmap< T > mmap_compress(const Mmap< T > &in, MmapCompressMethod method)
Compress an MMAP (mmap_compress.m).
std::vector< std::vector< T > > mmap_backward_moment(const Mmap< T > &m, const std::vector< unsigned > &orders, bool normalized)
Class-conditional backward moments of an MMAP (mmap_backward_moment.m).
std::vector< T > map_pie(const Map< T > &m)
Phase distribution seen by an arriving job, pie = pi D1 / (pi D1 e).
std::vector< T > mmap_pc(const Mmap< T > &m)
Class probabilities seen by an arriving job, pc = pie (-D0)^-1 D1^(c) e.
T num_factorial(unsigned n)
Factorial as a value of T.
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 > matpow(const Matrix< T > &A, unsigned k)
Integer matrix power, by repeated squaring.
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