5#ifndef LINE_API_MAM_MAP_MOMENT_H
6#define LINE_API_MAM_MAP_MOMENT_H
63 if (m.
D0.rows() != m.
D1.rows() || m.
D0.cols() != m.
D1.cols())
64 throw InputError(
"map_infgen: D0 and D1 have different shapes");
66 for (std::size_t i = 0; i < Q.
rows(); ++i)
67 for (std::size_t j = 0; j < Q.
cols(); ++j) Q(i, j) = m.
D0(i, j) + m.
D1(i, j);
80 const std::vector<T> p =
map_prob(m);
81 const std::vector<T> pD1 =
vecmul(p, m.
D1);
83 for (
const T& v : pD1) s += v;
90 const std::vector<T> p =
map_prob(m);
93 for (
const T& v : a) s += v;
95 for (T& v : a) v /= s;
111 for (std::size_t i = 0; i < negD0.
rows(); ++i)
112 for (std::size_t j = 0; j < negD0.
cols(); ++j) negD0(i, j) = -negD0(i, j);
121 for (std::size_t i = 0; i < negD0.
rows(); ++i)
122 for (std::size_t j = 0; j < negD0.
cols(); ++j) negD0(i, j) = -negD0(i, j);
124 const std::vector<T> x =
map_pie(m);
125 const std::vector<T> xA =
vecmul(x, A);
127 for (
const T& v : xA) s += v;
172 for (T& v : x) v *= lam;
174 for (std::size_t i = 0; i < negD0.
rows(); ++i)
175 for (std::size_t j = 0; j < negD0.
cols(); ++j) negD0(i, j) = -negD0(i, j);
180 throw NumericError(
"map_acf: the inter-arrival time is deterministic, the autocorrelation "
181 "coefficient is undefined (zero variance)");
184 out.reserve(lags.size());
185 for (
unsigned lag : lags) {
188 for (std::size_t i = 0; i < xP.size(); ++i) s += xP[i] * y[i];
197 const std::size_t n = m.
order();
199 const std::vector<T> p =
map_prob(m);
201 for (std::size_t i = 0; i < n; ++i)
202 for (std::size_t j = 0; j < n; ++j) A(i, j) = Q(i, j) + p[j];
203 const std::vector<T> pie =
map_pie(m);
205 const std::vector<T> t2 =
vecmul(t1, m.
D1);
207 for (
const T& v : t2) s += v;
217 m.
D0(0, 0) = -lambda;
NumericError(const std::string &what)
Steady-state distribution of a continuous-time Markov chain.
The exception types the port throws.
Dense linear algebra over the templated number type: products, identity, inverse, and powers.
Dense matrix and non-owning view.
std::vector< T > map_acf(const Map< T > &m, const std::vector< unsigned > &lags)
Autocorrelation coefficients of the inter-arrival times at the given lags,.
T map_idc(const Map< T > &m)
Index of dispersion for counts, I = 1 + 2(lambda - pie (Q + e pi)^-1 D1 e).
Matrix< T > map_infgen(const Map< T > &m)
Generator of the underlying phase process, D0 + D1.
T map_mean(const Map< T > &m)
Mean inter-arrival time, 1/lambda.
T map_var(const Map< T > &m)
Variance of the inter-arrival time.
int map_feastol()
Tolerance exponent shared by the KPC feasibility checks (map_feastol.m).
Map< T > map_exponential(const T &lambda)
Two-phase MAP constructor for a Poisson process of rate lambda.
std::vector< T > map_prob(const Map< T > &m)
Stationary distribution of the phase process, pi (D0 + D1) = 0.
std::vector< T > map_pie(const Map< T > &m)
Phase distribution seen by an arriving job, pie = pi D1 / (pi D1 e).
T map_scv(const Map< T > &m)
Squared coefficient of variation.
Matrix< T > map_embedded(const Map< T > &m)
Embedded DTMC at arrival epochs, P = (-D0)^-1 D1.
T map_moment(const Map< T > &m, unsigned k)
Raw moment of order k of the inter-arrival time: k!
T map_lambda(const Map< T > &m)
Stationary arrival rate, lambda = pi D1 e.
std::vector< T > ctmc_solve(const Matrix< T > &Qin)
Steady-state distribution of a continuous-time Markov chain.
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 > matmul(const Matrix< T > &A, const Matrix< T > &B)
Matrix product A B.
std::vector< T > mulvec(const Matrix< T > &A, const std::vector< T > &v)
Matrix times column vector, A v.
Matrix< T > matpow(const Matrix< T > &A, unsigned k)
Integer matrix power, by repeated squaring.
std::vector< T > ones(std::size_t n)
Column vector of ones, the ubiquitous e in MAP algebra.
Number-type abstraction for the templated API port.
A MAP as the pair of matrices (D0, D1).
std::size_t order() const