5#ifndef LINE_API_MAM_M3PP_SUPERPOS_FITC_H
6#define LINE_API_MAM_M3PP_SUPERPOS_FITC_H
64T m3_from_raw(
const T& m1,
const T& m2,
const T& m3) {
67 return m3 - three * m2 * m1 + two * m1 * m1 * m1;
72T col_mean(
const Matrix<long>& C, std::size_t col,
unsigned power) {
74 for (std::size_t i = 0; i < C.
rows(); ++i) {
77 for (
unsigned k = 0; k < power; ++k) p *= v;
80 return acc / num_traits<T>::from_int(
static_cast<long>(C.
rows()));
85T col_var(
const Matrix<long>& C, std::size_t col) {
86 const std::size_t n = C.rows();
87 if (n < 2)
throw InputError(
"m3pp_superpos_fitc: fewer than two counting windows");
88 const T mu = col_mean<T>(C, col, 1);
89 T acc = num_traits<T>::from_int(0);
90 for (std::size_t i = 0; i < n; ++i) {
91 const T d = num_traits<T>::from_int(
static_cast<long>(C(i, col))) - mu;
94 return acc / num_traits<T>::from_int(
static_cast<long>(n - 1));
112 const std::vector<T>& binfv,
const std::vector<T>& m3tv,
113 const T& t,
const T& tinf) {
115 "m3pp_superpos_fitc requires transcendental arithmetic");
116 const std::size_t m = av.size();
117 if (m == 0)
throw InputError(
"m3pp_superpos_fitc: no classes");
118 if (btv.size() != m || binfv.size() != m || m3tv.size() != m)
119 throw InputError(
"m3pp_superpos_fitc: av, btv, binfv and m3tv must have the same length");
122 for (std::size_t i = 0; i < m; ++i) {
127 comp.
Dc.push_back(f.
map.D1);
128 res.
parts.push_back(comp);
146 const std::size_t m = mm.
classes();
147 if (m == 0)
throw InputError(
"m3pp_superpos_fitc_theoretical: the MMAP has no classes");
153 std::vector<unsigned> orders;
160 for (std::size_t i = 0; i < m; ++i)
161 m3tv[i] = fitdetail::m3_from_raw(mtv(0, i), mtv(1, i), mtv(2, i));
176 const T& t,
const T& tinf) {
177 if (Tv.empty())
throw InputError(
"m3pp_superpos_fitc_trace: empty trace");
178 if (A.size() != Tv.size())
179 throw InputError(
"m3pp_superpos_fitc_trace: labels and inter-arrival times disagree");
182 for (std::size_t i = 0; i < Tv.size(); ++i) sumT += Tv[i];
187 const std::size_t m = Nt.
labels.size();
189 std::vector<T> av(m), btv(m), binfv(m), m3tv(m);
190 for (std::size_t i = 0; i < m; ++i) {
192 for (std::size_t k = 0; k < A.size(); ++k)
193 if (A[k] == Nt.
labels[i]) ++cnt;
196 btv[i] = fitdetail::col_var<T>(Nt.
counts, i) / (av[i] * t);
197 binfv[i] = fitdetail::col_var<T>(Ninf.
counts, i) / (av[i] * tinf);
198 m3tv[i] = fitdetail::m3_from_raw(fitdetail::col_mean<T>(Nt.
counts, i, 1),
199 fitdetail::col_mean<T>(Nt.
counts, i, 2),
200 fitdetail::col_mean<T>(Nt.
counts, i, 3));
208 const std::vector<int>& A) {
209 if (Tv.empty())
throw InputError(
"m3pp_superpos_fitc_trace: empty trace");
211 for (std::size_t i = 0; i < Tv.size(); ++i) sumT += Tv[i];
The exception types the port throws.
Power moments of the counts of a MAP in a window of length t.
Dense matrix and non-owning view.
Marked MAP (MMAP) algebra: per-class rates, class probabilities, superposition, normalization and sca...
Marked MAP statistics: embedded chains, class-transition probabilities, forward and cross moments,...
MMPP(2) matching counting-process characteristics (matlab/lib/kpctoolbox/mmpp/mmpp2_fitc....
Per-class counting processes of a marked trace: for each arrival, how many events of each class fall ...
Mmpp2FitcResult< T > mmpp2_fitc(const T &mu, const T &bt1, const T &bt2, const T &binf, const T &m3t2, const T &t1, const T &t2)
MMPP(2) from the arrival rate, the IDC at t1, t2 and infinity, and the third central moment of the co...
M3ppSuperposResult< T > m3pp_superpos_fitc_trace(const std::vector< T > &Tv, const std::vector< int > &A, const T &t, const T &tinf)
Superpose one M3PP per class to fit a multi-class trace.
M3ppSuperposResult< T > m3pp_superpos_fitc(const std::vector< T > &av, const std::vector< T > &btv, const std::vector< T > &binfv, const std::vector< T > &m3tv, const T &t, const T &tinf)
Fit one second-order M3PP per class from its counting characteristics and superpose them.
Matrix< T > mmap_count_moment(const Mmap< T > &m, const T &t, const std::vector< unsigned > &orders)
Per-class counting moments of a marked MAP, mmap_count_moment.
std::vector< T > mmap_count_idc(const Mmap< T > &mm, const T &t)
Per-class index of dispersion of counts over a window of length t.
M3ppSuperposResult< T > m3pp_superpos_fitc_theoretical(const Mmap< T > &mm, const T &t, const T &tinf)
Superpose one M3PP per class to fit the counting characteristics of a given MMAP.
std::vector< T > mmap_count_mean(const Mmap< T > &mm, const T &t)
Per-class mean of the counting process over a window of length t.
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 ...
MtraceCountsResult< T > mtrace_iat2counts(const std::vector< T > &Tv, const std::vector< int > &A, const T &scale)
Per-class counting processes of a marked trace: for each arrival, how many events of each class fall ...
Number-type abstraction for the templated API port.
Result of the superposition fits.
Mmap< T > mmap
the superposed process
std::vector< Mmap< T > > parts
the per-class components, before superposition
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
Return value of mtrace_iat2counts.
Matrix< long > counts
(rows x C), column c for labels[c]
std::vector< int > labels
the distinct labels, increasing