87Json encode_longs(
const std::vector<long>& v) {
88 Json a = Json::array();
89 for (
long x : v) a.push_back(
static_cast<long long>(x));
93Json encode_long_matrix(
const Matrix<long>& m) {
94 Json a = Json::array();
95 for (std::size_t i = 0; i < m.rows(); ++i) {
96 Json row = Json::array();
97 for (std::size_t k = 0; k < m.cols(); ++k) row.push_back(
static_cast<long long>(m(i, k)));
103Json encode_sizes(
const std::vector<std::size_t>& v) {
104 Json a = Json::array();
111Json encode_defined(
const T& v,
long count) {
116Json encode_vector_defined(
const std::vector<T>& v,
const std::vector<long>& count) {
117 Json a = Json::array();
118 for (std::size_t k = 0; k < v.size(); ++k) a.push_back(encode_defined(v[k], count[k]));
123Json encode_matrix_defined(
const Matrix<T>& m,
const Matrix<long>& count) {
124 Json a = Json::array();
125 for (std::size_t i = 0; i < m.rows(); ++i) {
126 Json row = Json::array();
127 for (std::size_t k = 0; k < m.cols(); ++k) row.push_back(encode_defined(m(i, k), count(i, k)));
133std::string where_of(
const std::string& fn,
const char* key) {
return fn +
": " + key; }
135std::vector<long> to_longs(
const std::vector<int>& v) {
return std::vector<long>(v.begin(), v.end()); }
138std::vector<std::size_t> nonneg_sizes(
const std::vector<int>& v,
const std::string& where) {
139 std::vector<std::size_t> out;
140 out.reserve(v.size());
142 if (x < 0)
throw InputError(where +
": entries must be nonnegative, got " + std::to_string(x));
143 out.push_back(
static_cast<std::size_t
>(x));
148std::vector<unsigned> nonneg_unsigned(
const std::vector<int>& v,
const std::string& where) {
149 const std::vector<std::size_t> s = nonneg_sizes(v, where);
150 return std::vector<unsigned>(s.begin(), s.end());
154std::vector<std::size_t> one_based_to_zero(
const std::vector<int>& v,
const std::string& where) {
155 std::vector<std::size_t> out;
156 out.reserve(v.size());
158 if (x < 1)
throw InputError(where +
": class labels are 1-based, got " + std::to_string(x));
159 out.push_back(
static_cast<std::size_t
>(x - 1));
164std::vector<std::size_t> one_based_sizes(
const std::vector<int>& v,
const std::string& where) {
165 std::vector<std::size_t> out;
166 out.reserve(v.size());
168 if (x < 1)
throw InputError(where +
": class labels are 1-based, got " + std::to_string(x));
169 out.push_back(
static_cast<std::size_t
>(x));
176T number_or_fill(
const Json& j,
const std::string& where,
const T& fill) {
186Matrix<T> matrix_or_fill(
const Json& j,
const std::string& where,
const T& fill) {
189 m(0, 0) = number_or_fill<T>(j, where, fill);
193 if (j[0].is_array()) {
194 const std::size_t rows = j.size(), cols = j[0].size();
195 for (std::size_t i = 0; i < rows; ++i)
196 if (!j[i].is_array() || j[i].size() != cols)
197 throw InputError(where +
": row " + std::to_string(i) +
" is not an array of " +
198 std::to_string(cols) +
" entries");
200 Matrix<T> m(rows, cols);
201 for (std::size_t i = 0; i < rows; ++i)
202 for (std::size_t k = 0; k < cols; ++k) m(i, k) = number_or_fill<T>(j[i][k], where, fill);
205 Matrix<T> m(1, j.size());
206 for (std::size_t k = 0; k < j.size(); ++k) m(0, k) = number_or_fill<T>(j[k], where, fill);
212std::vector<T> column_major(
const Matrix<T>& m) {
214 v.reserve(m.rows() * m.cols());
215 for (std::size_t c = 0; c < m.cols(); ++c)
216 for (std::size_t r = 0; r < m.rows(); ++r) v.push_back(m(r, c));
220std::string lower(std::string s) {
221 for (
char& c : s) c =
static_cast<char>(std::tolower(
static_cast<unsigned char>(c)));
225std::string string_of(
const Json& j,
const std::string& where) {
227 throw InputError(where +
": expected a string, got " + std::string(j.type_name()));
228 return j.get<std::string>();
231std::vector<std::string> strings_of(
const Json& j,
const std::string& where) {
232 if (!j.is_array())
throw InputError(where +
": expected a list of strings");
233 std::vector<std::string> out;
234 for (
const Json& e : j) out.push_back(string_of(e, where));
239bool flag_of(
const Json& j,
const std::string& where) {
240 if (j.is_boolean())
return j.get<
bool>();
242 if (v.size() != 1 || (v[0] != 0 && v[0] != 1))
243 throw InputError(where +
": expected true, false, 0 or 1");
253void read_trace_cells(
const Json& data,
const std::string& where, std::vector<std::vector<T>>& at_ms,
254 std::vector<std::vector<T>>& rt) {
255 if (!data.is_array() || data.size() < 4)
256 throw InputError(where +
": expected the 6 x (K+1) cell array, as a list of rows; rows 3 "
257 "(arrival times, ms) and 4 (response times) are read");
258 const std::size_t cols = data[0].is_array() ? data[0].size() : 0;
259 for (std::size_t r = 0; r < data.size(); ++r)
260 if (!data[r].is_array() || data[r].size() != cols)
261 throw InputError(where +
": row " + std::to_string(r + 1) +
" must have " +
262 std::to_string(cols) +
" cells, like row 1");
263 if (cols < 2)
throw InputError(where +
": at least one class column plus the trailing column");
264 const std::size_t K = cols - 1;
265 at_ms.assign(K, std::vector<T>());
266 rt.assign(K, std::vector<T>());
267 for (std::size_t k = 0; k < K; ++k) {
277#define LINE_TRACE_SCALAR_OP(Name, fn, outkey) \
280 static Json run(Args& a) { \
281 const std::vector<T> S = a.vector<T>("S"); \
284 out[outkey] = encode_scalar(line::trace::fn<T>(S)); \
294#undef LINE_TRACE_SCALAR_OP
298 static Json run(Args& a) {
299 const std::vector<T> S = a.vector<T>(
"S");
300 const bool has_lags = a.has(
"lags");
301 const std::vector<int> lags = a.ints_or_empty(
"lags");
312 static Json run(Args& a) {
313 const std::vector<T> S = a.vector<T>(
"S");
314 const std::vector<int> grid = a.ints(
"GRID");
317 Json lags = Json::array();
318 for (
const std::vector<int>& l : r.
lags) lags.push_back(
encode_ints(l));
321 out[
"BiCovLags"] = lags;
328 static Json run(Args& a) {
329 const std::vector<T> S = a.vector<T>(
"T");
330 const bool has_limit = a.has(
"limit");
331 const int limit = has_limit ? a.required_integer(
"limit") : 0;
334 const line::trace::TraceGammaResult<T> r =
345struct OpTraceIat2bins {
347 static Json run(Args& a) {
348 const std::vector<T> S = a.vector<T>(
"S");
349 const T scale = a.number<T>(
"scale");
353 out[
"C"] = encode_longs(r.
counts);
359struct OpTraceIat2counts {
361 static Json run(Args& a) {
362 const std::vector<T> S = a.vector<T>(
"S");
363 const T scale = a.number<T>(
"scale");
379 static Json run(Args& a) {
380 const std::vector<T> S = a.vector<T>(
"S");
381 const std::vector<long> kset = to_longs(a.ints(
"kset"));
382 const bool has_option = a.has(
"OPTION");
383 const std::string option = lower(a.text(
"OPTION", std::string()));
384 const bool has_n = a.has(
"n");
386 line::trace::TraceIdiResult<T> r;
389 throw InputError(
"trace_idi: 'n' is the aggregation count of OPTION 'aggregate'; "
393 }
else if (option ==
"aggregate") {
394 if (!has_n)
throw InputError(
"trace_idi: OPTION 'aggregate' needs 'n'");
395 const int n = a.required_integer(
"n");
396 if (n < 1)
throw InputError(
"trace_idi: 'n' must be a positive integer");
399 }
else if (option ==
"aggregate-mix") {
401 "trace_idi: OPTION 'aggregate-mix' is not ported; the reference branch keeps "
402 "only the statistic of its last partition (see trace_idi.h)");
404 throw InputError(
"trace_idi: OPTION must be 'aggregate', got '" + option +
"'");
408 out[
"support"] = encode_longs(r.
support);
415 static Json run(Args& a) {
416 const std::vector<T> S = a.vector<T>(
"S");
417 const std::vector<int> lag = a.ints(
"lag");
418 const std::vector<unsigned> order = nonneg_unsigned(a.ints(
"order"),
"trace_joint: order");
428 static Json run(Args& a) {
429 const std::vector<int> X = a.ints(
"X");
445struct OpTraceSummary {
447 static Json run(Args& a) {
448 const std::vector<T> S = a.vector<T>(
"m");
449 a.unsupported(
"fid",
"it is a MATLAB file identifier for the printed report; the API "
450 "returns the values instead of printing them");
473struct OpMtraceMoment {
475 static Json run(Args& a) {
476 const std::vector<T> Tv = a.vector<T>(
"T");
477 const std::vector<int> A = a.ints(
"A");
478 const std::vector<unsigned> orders = nonneg_unsigned(a.ints(
"ORDERS"),
"mtrace_moment: ORDERS");
479 const bool has_after = a.has(
"AFTER"), has_norm = a.has(
"NORM");
480 if (has_norm && !has_after)
481 throw InputError(
"mtrace_moment: NORM follows AFTER positionally; give AFTER too");
482 const bool after = has_after ? a.boolean(
"AFTER",
false) :
false;
483 const bool norm = has_norm ? a.boolean(
"NORM",
false) :
false;
500#define LINE_MTRACE_DIRECTED_MOMENT_OP(Name, fn) \
503 static Json run(Args& a) { \
504 const std::vector<T> Tv = a.vector<T>("T"); \
505 const std::vector<int> A = a.ints("A"); \
506 const std::vector<unsigned> orders = \
507 nonneg_unsigned(a.ints("ORDERS"), #fn ": ORDERS"); \
508 const bool has_norm = a.has("NORM"); \
509 const bool norm = has_norm ? a.boolean("NORM", false) : false; \
513 out["M"] = encode_matrix(has_norm ? line::trace::fn<T>(Tv, A, orders, norm) \
514 : line::trace::fn<T>(Tv, A, orders)); \
521#undef LINE_MTRACE_DIRECTED_MOMENT_OP
523#define LINE_MTRACE_CROSS_MOMENT_OP(Name, fn) \
526 static Json run(Args& a) { \
527 const std::vector<T> Tv = a.vector<T>("T"); \
528 const std::vector<int> L = a.ints("L"); \
529 const unsigned k = a.uinteger("k"); \
531 const line::trace::MtraceCrossMomentResult<T> r = \
532 line::trace::fn<T>(Tv, L, k); \
534 out["MC"] = encode_matrix_defined(r.mc, r.count); \
541#undef LINE_MTRACE_CROSS_MOMENT_OP
543struct OpMtraceCount {
545 static Json run(Args& a) {
546 const std::vector<T> Tv = a.vector<T>(
"T");
547 const std::vector<int> A = a.ints(
"A");
548 const T t = a.number<T>(
"t");
558 static Json run(Args& a) {
559 const std::vector<T> Tv = a.vector<T>(
"T");
560 const std::vector<int> A = a.ints(
"A");
563 Json c = Json::array();
564 for (
const std::vector<Matrix<T>>& row : cov) c.push_back(
encode_matrices(row));
571struct OpMtraceIat2counts {
573 static Json run(Args& a) {
574 const std::vector<T> Tv = a.vector<T>(
"T");
575 const std::vector<int> A = a.ints(
"A");
576 const T scale = a.number<T>(
"scale");
577 a.unsupported(
"no_mex",
"it selects between MATLAB's MEX and script implementations of "
578 "the same counts; the port has one implementation");
586struct OpMtraceJoint {
588 static Json run(Args& a) {
589 const std::vector<T> Tv = a.vector<T>(
"T");
590 const std::vector<int> A = a.ints(
"A");
591 const std::vector<unsigned> i = nonneg_unsigned(a.ints(
"i"),
"mtrace_joint: i");
592 if (i.size() != 2)
throw InputError(
"mtrace_joint: 'i' must hold the two orders [i1, i2]");
596 out[
"JM"] = encode_vector_defined(r.
jm, r.
count);
603 static Json run(Args& a) {
604 const std::vector<T> Tv = a.vector<T>(
"trace");
605 const int ntypes = a.required_integer(
"ntypes");
606 const std::vector<int> type = a.ints(
"type");
608 const line::trace::MtraceMeanResult<T> r =
611 out[
"m"] = encode_vector_defined(r.
mean, r.
count);
616struct OpMtraceMerge {
618 static Json run(Args& a) {
619 const std::vector<T> t1 = a.vector<T>(
"t1");
620 const std::vector<T> t2 = a.vector<T>(
"t2");
631void refuse_unused_times(
Args& a,
const char* fn) {
633 throw InputError(std::string(fn) +
": 'T' is not read by the reference, whose result "
634 "depends on the labels L alone; omit it");
640 static Json run(Args& a) {
641 const std::vector<int> C = a.ints(
"C");
649struct OpMtraceSigma {
651 static Json run(Args& a) {
652 refuse_unused_times(a,
"mtrace_sigma");
653 const std::vector<int> L = a.ints(
"L");
662struct OpMtraceSigma2 {
664 static Json run(Args& a) {
665 refuse_unused_times(a,
"mtrace_sigma2");
666 const std::vector<int> L = a.ints(
"L");
669 const std::size_t C = s.rows();
670 Json cube = Json::array();
671 for (std::size_t i = 0; i < C; ++i) {
672 Json plane = Json::array();
673 for (std::size_t j = 0; j < C; ++j) {
674 Json row = Json::array();
675 for (std::size_t h = 0; h < C; ++h) row.push_back(
encode_scalar(s(i, j * C + h)));
676 plane.push_back(row);
678 cube.push_back(plane);
686struct OpMtraceSplit {
688 static Json run(Args& a) {
689 const std::vector<T> Tv = a.vector<T>(
"T");
690 const std::vector<int> L = a.ints(
"L");
698struct OpMtraceSummary {
700 static Json run(Args& a) {
701 const std::vector<T> Tv = a.vector<T>(
"T");
702 const std::vector<int> C = a.ints(
"C");
726struct OpInferComputeQlAtArrival {
728 static Json run(Args& a) {
729 const std::vector<T> at = a.vector<T>(
"at");
730 const std::vector<long> at_jobid = to_longs(a.ints(
"at_jobid"));
731 const std::vector<T> rt = a.vector<T>(
"rt");
732 const std::vector<long> rt_jobid = to_longs(a.ints(
"rt_jobid"));
733 const std::vector<std::size_t> cls =
734 one_based_to_zero(a.ints(
"class"),
"infer_compute_ql_at_arrival: class");
735 const std::size_t R = a.count(
"R");
744struct OpInferGetQlenArrival {
746 static Json run(Args& a) {
747 std::vector<std::vector<T>> at_ms, rt;
748 read_trace_cells<T>(a.get(
"data"),
"infer_get_qlen_arrival: data", at_ms, rt);
756struct OpInferLqnFindbyname {
758 static Json run(Args& a) {
759 const Json& container = a.get(
"container");
760 const std::string
name = string_of(a.get(
"name"),
"infer_lqn_findbyname: name");
762 if (!container.is_array())
763 throw InputError(
"infer_lqn_findbyname: 'container' must be a list of elements");
764 std::vector<std::string> names;
765 for (std::size_t k = 0; k < container.size(); ++k) {
766 const Json& e = container[k];
767 if (!e.is_object() || e.find(
"name") == e.end())
768 throw InputError(
"infer_lqn_findbyname: container entry " + std::to_string(k + 1) +
769 " has no 'name' field");
770 names.push_back(string_of(e[
"name"],
"infer_lqn_findbyname: container.name"));
779struct OpInferLqnGetobs {
781 static Json run(Args& a) {
782 const std::vector<std::string> names = strings_of(a.get(
"names"),
"infer_lqn_getobs: names");
783 const Json& mj = a.get(
"metrics");
784 const Json& sj = a.get(
"obsSpec");
786 line::infer::LqnMetrics<T> m;
788 Args ma(mj,
"infer_lqn_getobs: metrics");
789 m.
QLen = ma.vector_or_empty<T>(
"QLen");
790 m.
Util = ma.vector_or_empty<T>(
"Util");
791 m.
RespT = ma.vector_or_empty<T>(
"RespT");
792 m.
Tput = ma.vector_or_empty<T>(
"Tput");
795 if (!sj.is_array())
throw InputError(
"infer_lqn_getobs: 'obsSpec' must be a list of {metric, name}");
796 std::vector<line::infer::LqnObsSpec> spec;
797 for (
const Json& e : sj) {
798 Args ea(e,
"infer_lqn_getobs: obsSpec");
799 const std::string metric = lower(string_of(ea.get(
"metric"),
"infer_lqn_getobs: obsSpec.metric"));
800 line::infer::LqnObsSpec s;
801 s.
name = string_of(ea.get(
"name"),
"infer_lqn_getobs: obsSpec.name");
803 if (metric ==
"respt")
805 else if (metric ==
"util")
807 else if (metric ==
"tput")
809 else if (metric ==
"qlen")
812 throw InputError(
"infer_lqn_getobs: Unknown metric '" + metric +
"'.");
823 static Json run(Args& a) {
824 const Matrix<T> Q = a.matrix<T>(
"Q");
825 const std::vector<T> N = a.vector<T>(
"N");
826 const std::vector<T> Z = a.vector<T>(
"Z");
836 static Json run(Args& a) {
837 const std::vector<T> rt = a.vector<T>(
"rt");
838 const std::vector<std::size_t> cls = one_based_to_zero(a.ints(
"class"),
"infer_rps: class");
839 const Matrix<T> ql = a.matrix<T>(
"ql");
840 const int V = a.required_integer(
"V");
853struct OpInferQuickModel {
855 static Json run(Args& a) {
856 const bool is_open = flag_of(a.get(
"open"),
"infer_quick_model: open");
857 std::vector<lang::SchedStrategy> stations;
858 for (
const std::string& s : strings_of(a.get(
"stations"),
"infer_quick_model: stations"))
859 stations.push_back(io::detail::sched_from_json(s));
860 const Matrix<T> demands = a.matrix<T>(
"classes");
861 const bool has_servers = a.has(
"servers"), has_jobs = a.has(
"jobs"),
862 has_routing = a.has(
"routing");
863 if (has_jobs && !has_servers)
864 throw InputError(
"infer_quick_model: 'jobs' follows 'servers' positionally; give servers too");
865 if (has_routing && !(has_servers && has_jobs))
866 throw InputError(
"infer_quick_model: 'routing' follows 'servers' and 'jobs' "
867 "positionally; give both");
868 if (has_routing && is_open)
869 throw InputError(
"infer_quick_model: 'routing' applies to a closed model; an open "
870 "model is routed serially from the source to the sink");
871 const std::vector<double> servers = a.vector_or_empty<
double>(
"servers");
872 const std::vector<double> jobs = a.vector_or_empty<
double>(
"jobs");
873 std::vector<Matrix<T>> routing;
875 const Json& rj = a.get(
"routing");
876 const bool cell_form = rj.is_array() && !rj.empty() && rj[0].is_array() &&
877 !rj[0].empty() && rj[0][0].is_array();
879 routing = a.matrices<T>(
"routing");
881 const Matrix<T>
P = a.matrix<T>(
"routing");
882 routing.assign(demands.rows(), P);
886 qn::Network<T> model =
888 : has_jobs ? line::infer::
infer_quick_model<T>(is_open, stations, demands, servers, jobs)
889 : has_servers ? line::infer::
infer_quick_model<T>(is_open, stations, demands, servers)
902struct OpInferNhppKs {
904 static Json run(Args& a) {
905 const std::vector<T> times = a.vector<T>(
"times");
906 const T Tend = a.number<T>(
"T");
907 a.unsupported(
"cumRate",
"it is a function handle; without it the rate is taken "
908 "constant over the interval");
909 const bool has_method = a.has(
"method"), has_t0 = a.has(
"T0");
910 const std::string m = lower(a.text(
"method", std::string()));
911 if (has_t0 && !has_method)
912 throw InputError(
"infer_nhpp_ks: the port takes T0 after method; give 'method' too");
913 line::infer::NhppKsResult<T> r;
921 else if (m ==
"lewis")
924 throw InputError(
"infer_nhpp_ks: method must be 'cu' or 'lewis' ('tt' tests a "
925 "given cumRate, which is a function handle)");
926 const std::function<T(
const T&)> constant;
928 const T t0 = a.number<T>(
"T0");
951double nhpp_fit_alpha(
Args& a) {
952 return a.has(
"alpha") ? num_traits<T>::to_double(a.number<T>(
"alpha")) : 0.05;
956struct OpInferNhppLeemis {
958 static Json run(Args& a) {
959 const std::vector<T> times = a.vector<T>(
"times");
960 const T Tend = a.number<T>(
"T");
961 const std::vector<T> tq = a.vector_or_empty<T>(
"tq");
962 const double alpha = nhpp_fit_alpha<T>(a);
984struct OpInferNhppPowerlaw {
986 static Json run(Args& a) {
987 const std::vector<T> times = a.vector<T>(
"times");
988 const T Tend = a.number<T>(
"T");
989 const double alpha = nhpp_fit_alpha<T>(a);
993 Matrix<T> info(2, 2), cov(2, 2);
994 for (
int i = 0; i < 2; ++i)
995 for (
int j = 0; j < 2; ++j) {
996 info(i, j) = r.
info[i][j];
997 cov(i, j) = r.
cov[i][j];
1011 out[
"result"] = res;
1018Json encode_smp_fit(
const line::infer::SmpFit& f) {
1019 Json arcs = Json::array();
1020 for (
const line::infer::SmpArc& c : f.
arcs) {
1045std::vector<double> doubles_nan(
const Json& j,
const std::string& where) {
1046 const Matrix<double> m = matrix_or_fill<double>(j, where, std::numeric_limits<double>::quiet_NaN());
1047 return column_major(m);
1051line::infer::SmpFit read_smp_fit(
const Json& j) {
1052 const std::string w =
"infer_smp_hazard: fit";
1054 line::infer::SmpFit fit;
1055 fit.
approach = string_of(f.get(
"approach"), w +
".approach");
1056 fit.
nstates = f.count(
"nstates");
1057 fit.
ncov = f.count(
"ncov");
1058 fit.
loglik = number_or_fill<double>(f.get(
"loglik"), w +
".loglik",
1059 std::numeric_limits<double>::quiet_NaN());
1060 fit.
nparams = f.count(
"nparams");
1061 fit.
aic = number_or_fill<double>(f.get(
"aic"), w +
".aic", std::numeric_limits<double>::quiet_NaN());
1062 fit.
P = matrix_or_fill<double>(f.get(
"P"), w +
".P", std::numeric_limits<double>::quiet_NaN());
1063 const Json& arcs = f.get(
"arcs");
1065 if (!arcs.is_array())
throw InputError(w +
".arcs: expected a list of arcs");
1066 for (
const Json& e : arcs) {
1067 Args c(e, w +
".arcs");
1068 line::infer::SmpArc arc;
1069 arc.
from = c.count(
"from");
1070 arc.
to = c.count(
"to");
1071 arc.
family = string_of(c.get(
"family"), w +
".arcs.family");
1072 arc.
theta = doubles_nan(c.get(
"theta"), w +
".arcs.theta");
1073 arc.
params = doubles_nan(c.get(
"params"), w +
".arcs.params");
1074 arc.
beta = doubles_nan(c.get(
"beta"), w +
".arcs.beta");
1075 arc.
se = doubles_nan(c.get(
"se"), w +
".arcs.se");
1076 arc.
prob = number_or_fill<double>(c.get(
"prob"), w +
".arcs.prob",
1077 std::numeric_limits<double>::quiet_NaN());
1078 arc.
nevents = c.count(
"nevents");
1080 fit.
arcs.push_back(arc);
1086 static Json run(Args& a) {
1087 const std::string w =
"infer_smp";
1088 const std::vector<std::size_t> from = nonneg_sizes(a.ints(
"from"), w +
": from");
1089 const std::vector<std::size_t> to = nonneg_sizes(a.ints(
"to"), w +
": to");
1090 const std::vector<double> dur = a.vector<
double>(
"dur");
1091 line::infer::SmpOptions opt;
1092 if (a.has(
"approach")) opt.approach = lower(a.text(
"approach", std::string()));
1093 if (
const Json* d = a.opt(
"dist")) {
1094 if (d->is_string()) {
1095 opt.dist = lower(d->get<std::string>());
1097 if (!d->is_array())
throw InputError(w +
": 'dist' must be a family name or an E x E table of them");
1098 for (
const Json& row : *d) {
1099 if (!row.is_array())
throw InputError(w +
": 'dist' table rows must be lists");
1100 std::vector<std::string> r;
1101 for (
const Json& e : row) r.push_back(e.is_null() ? std::string() : lower(string_of(e, w +
": dist")));
1102 opt.dist_table.push_back(r);
1106 if (a.has(
"covariates")) opt.covariates = a.matrix<
double>(
"covariates");
1107 if (
const Json* cm = a.opt(
"covmask")) {
1108 if (!cm->is_array())
throw InputError(w +
": 'covmask' must be an E x E x p array");
1109 for (
const Json& plane : *cm) {
1110 if (!plane.is_array())
throw InputError(w +
": 'covmask' must be an E x E x p array");
1111 std::vector<std::vector<bool>> p;
1112 for (
const Json& row : plane) {
1113 if (!row.is_array())
throw InputError(w +
": 'covmask' must be an E x E x p array");
1114 std::vector<bool> r;
1115 for (
const Json& e : row) r.push_back(flag_of(e, w +
": covmask"));
1118 opt.covmask.push_back(p);
1121 if (a.has(
"nstates")) opt.nstates = a.count(
"nstates");
1122 if (a.has(
"tolx")) opt.tolx = a.number<
double>(
"tolx");
1123 if (a.has(
"tolf")) opt.tolf = a.number<
double>(
"tolf");
1124 if (a.has(
"maxiter")) opt.maxiter = a.count(
"maxiter");
1126 a.opt(
"covariates");
1138struct OpInferSmpHazard {
1139 static Json run(Args& a) {
1140 const line::infer::SmpFit fit = read_smp_fit(a.get(
"fit"));
1141 const std::vector<double> t = a.vector<
double>(
"t");
1142 const bool has_z = a.has(
"z");
1143 const std::vector<double>
z = a.vector_or_empty<
double>(
"z");
1145 const std::vector<line::infer::SmpHazard> h =
1147 Json hz = Json::array();
1148 for (
const line::infer::SmpHazard& e : h) {
1164struct OpInferSmpNelsonAalen {
1165 static Json run(Args& a) {
1166 const std::string w =
"infer_smp_nelson_aalen";
1167 const std::vector<std::size_t> from = nonneg_sizes(a.ints(
"from"), w +
": from");
1168 const std::vector<std::size_t> to = nonneg_sizes(a.ints(
"to"), w +
": to");
1169 const std::vector<double> dur = a.vector<
double>(
"dur");
1170 const bool has_e = a.has(
"nstates");
1171 const std::size_t E = has_e ? a.count(
"nstates") : 0;
1174 const std::vector<line::infer::SmpNelsonAalen> r =
1177 Json na = Json::array();
1178 for (
const line::infer::SmpNelsonAalen& e : r) {
1197struct OpInferSmpFamily {
1198 static Json run(Args& a) {
1199 const std::string w =
"infer_smp_family";
1200 const std::string family = string_of(a.get(
"family"), w +
": family");
1201 const std::string mode = string_of(a.get(
"mode"), w +
": mode");
1204 auto theta = [&]() {
1205 const std::vector<double> th = a.vector<
double>(
"THETA");
1206 if (th.size() != npar)
1207 throw InputError(w +
": THETA must have " + std::to_string(npar) +
" entries for '" +
1212 if (mode ==
"npar") {
1215 }
else if (mode ==
"logfs") {
1216 const std::vector<double> th = theta();
1217 const std::vector<double> t = a.vector<
double>(
"T");
1218 const std::vector<double> eta = a.vector_or_empty<
double>(
"ETA");
1219 if (eta.size() > 1 && eta.size() != t.size())
1220 throw InputError(w +
": ETA must be a scalar or have one entry per instant of T");
1222 std::vector<double> logf, logS;
1226 }
else if (mode ==
"natural") {
1227 const std::vector<double> th = theta();
1230 }
else if (mode ==
"theta0") {
1231 const std::vector<double> tev = a.vector<
double>(
"TEV");
1232 const double texp = a.number<
double>(
"TEXP");
1235 }
else if (mode ==
"dist") {
1236 const std::vector<double> th = theta();
1237 const double eta = a.number<
double>(
"ETA");
1241 throw InputError(w +
": Unknown mode '" + mode +
1242 "': use 'npar', 'logfs', 'natural', 'theta0' or 'dist'.");
1256struct OpInferVariational {
1258 static Json run(Args& a) {
1259 const std::string w =
"infer_variational";
1260 const Json& sj = a.get(
"spec");
1261 const Json* oj = a.opt(
"options");
1263 const T nan = num_traits<T>::from_double(std::numeric_limits<double>::quiet_NaN());
1264 const T inf = num_traits<T>::from_double(std::numeric_limits<double>::infinity());
1266 line::infer::VariationalSpec<T> spec;
1268 Args s(sj, w +
": spec");
1269 const Matrix<T> arcs = s.matrix<T>(
"arcs");
1270 if (!arcs.empty() && arcs.cols() != 3)
1271 throw InputError(w +
": spec.arcs must have three columns [i j c].");
1273 const std::vector<std::size_t> arcsz = nonneg_sizes(arcint, w +
": spec.arcs");
1274 for (std::size_t e = 0; e < arcs.rows(); ++e)
1275 spec.
arcs.push_back(std::array<std::size_t, 3>{arcsz[3 * e], arcsz[3 * e + 1], arcsz[3 * e + 2]});
1276 spec.
x0 = s.matrix<T>(
"x0");
1277 spec.
sched = s.ints(
"sched");
1278 spec.
nservers = s.vector<T>(
"nservers");
1279 spec.
routeprob = s.vector<T>(
"routeprob");
1280 spec.
arcparam = nonneg_sizes(s.ints(
"arcparam"), w +
": spec.arcparam");
1281 spec.
arcrate = column_major(matrix_or_fill<T>(s.get(
"arcrate"), w +
": spec.arcrate", nan));
1282 spec.
alpha0 = s.vector<T>(
"alpha0");
1283 spec.
beta0 = s.vector<T>(
"beta0");
1284 spec.
obsTimes = s.vector<T>(
"obsTimes");
1285 spec.
obsData = matrix_or_fill<T>(s.get(
"obsData"), w +
": spec.obsData",
1287 spec.
obsRange = column_major(s.matrix<T>(
"obsRange"));
1288 spec.
epsilon = s.number<T>(
"epsilon");
1289 if (
const Json* c = s.opt(
"capacity"))
1290 spec.
capacity = column_major(matrix_or_fill<T>(*c, w +
": spec.capacity", inf));
1293 line::infer::VariationalOptions<T> opt;
1295 Args o(*oj, w +
": options");
1296 if (o.has(
"verbose")) opt.
verbose = o.required_integer(
"verbose");
1297 if (o.has(
"iter_max")) opt.
iter_max = o.count(
"iter_max");
1298 if (o.has(
"tol")) opt.
tol = o.number<
double>(
"tol");
1299 if (o.has(
"nsamples")) opt.
nsamples = o.count(
"nsamples");
1300 if (o.has(
"delta")) opt.
delta = o.number<
double>(
"delta");
1301 if (o.has(
"floor")) opt.
floor = o.number<
double>(
"floor");
1302 if (o.has(
"rate_max")) opt.
rate_max = o.number<
double>(
"rate_max");
1303 if (o.has(
"rate_cap_factor")) opt.
rate_cap_factor = o.number<
double>(
"rate_cap_factor");
1304 if (o.has(
"unifmax")) opt.
unifmax = o.number<
double>(
"unifmax");
1305 if (o.has(
"unif_tol")) opt.
unif_tol = o.number<
double>(
"unif_tol");
1306 if (o.has(
"unif_max_terms")) opt.
unif_max_terms = o.count(
"unif_max_terms");
1307 if (o.has(
"tmax")) opt.
tmax = o.number<
double>(
"tmax");
1308 if (o.has(
"dt")) opt.
dt = o.number<
double>(
"dt");
1309 if (o.has(
"ngrid")) opt.
ngrid =
static_cast<long>(o.count(
"ngrid"));
1310 if (o.has(
"ymax")) opt.
ymax =
static_cast<long>(o.count(
"ymax"));
1311 for (
const char* k : {
"verbose",
"iter_max",
"tol",
"nsamples",
"delta",
"floor",
1312 "rate_max",
"rate_cap_factor",
"unifmax",
"unif_tol",
1313 "unif_max_terms",
"tmax",
"dt",
"ngrid",
"ymax"})
1317 const line::infer::VariationalResult<T> r =
1342const char*
const kMlpsModelWhy =
1343 "the reference reads the delay rates and the server count off the model; pass them as "
1344 "'muZ' (per-class think rates) and 'nCores' instead";
1346std::vector<line::api::MlpsSample> read_mlps_samples(
Args& a,
const std::string& w) {
1347 const std::vector<double> rt = a.vector<
double>(
"rt");
1348 const std::vector<std::size_t> cls = one_based_sizes(a.ints(
"class"), w +
": class");
1349 const Matrix<double> ql = a.matrix<
double>(
"ql");
1350 if (cls.size() != rt.size() || ql.rows() != rt.size())
1351 throw InputError(w +
": rt, class and ql must have one row per sample");
1352 std::vector<line::api::MlpsSample> samples(rt.size());
1353 for (std::size_t i = 0; i < rt.size(); ++i) {
1354 samples[i].rt = rt[i];
1355 samples[i].cls = cls[i];
1356 samples[i].ql.resize(ql.cols());
1357 for (std::size_t c = 0; c < ql.cols(); ++c) samples[i].ql[c] = ql(i, c);
1363 static Json run(Args& a) {
1364 a.unsupported(
"model", kMlpsModelWhy);
1365 a.unsupported(
"node", kMlpsModelWhy);
1366 const std::vector<double> muZ = a.vector<
double>(
"muZ");
1367 const double nCores = a.number<
double>(
"nCores");
1368 const std::vector<line::api::MlpsSample> samples = read_mlps_samples(a,
"infer_mlps");
1381struct OpInferMinpsSetup {
1382 static Json run(Args& a) {
1383 const std::string w =
"infer_minps_setup";
1384 a.unsupported(
"model", kMlpsModelWhy);
1385 a.unsupported(
"node", kMlpsModelWhy);
1387 throw InputError(w +
": 'V' is not read by the reference, which takes the server count "
1388 "from the node; pass it as 'nCores'");
1390 std::vector<std::vector<double>> at_ms, rt;
1391 read_trace_cells<double>(a.get(
"data"), w +
": data", at_ms, rt);
1392 std::vector<line::api::MinpsClassTrace> traces(at_ms.size());
1393 for (std::size_t k = 0; k < at_ms.size(); ++k) {
1394 traces[k].arrival_ms = at_ms[k];
1395 traces[k].rt = rt[k];
1397 const std::size_t initSample = a.count(
"initSample");
1398 const std::size_t sampleSize = a.count(
"sampleSize");
1399 const std::vector<double> muZ = a.vector<
double>(
"muZ");
1400 const double nCores = a.number<
double>(
"nCores");
1403 if (muZ.size() != st.
classMap.size())
1404 throw InputError(w +
": 'muZ' must have one entry per class with samples (" +
1405 std::to_string(st.
classMap.size()) +
"), in the order of classMap");
1410 out[
"classMap"] = encode_sizes(st.
classMap);
1424struct OpInferGibbs {
1425 static Json run(Args& a) {
1426 const std::string w =
"infer_gibbs";
1427 const Json& data = a.get(
"data");
1428 std::vector<std::vector<double>> at_ms, rt;
1429 read_trace_cells<double>(data, w +
": data", at_ms, rt);
1430 if (data.size() < 6)
1431 throw InputError(w +
": data needs row 6 (the think-time observations) as well as "
1433 std::vector<line::infer::GibbsTrace<double>> traces(at_ms.size());
1434 for (std::size_t k = 0; k < at_ms.size(); ++k) {
1435 traces[k].arrival_ms = at_ms[k];
1436 traces[k].respt_s = rt[k];
1437 traces[k].think_obs =
1440 const double nbCores = a.number<
double>(
"nbCores");
1441 const double tol = a.scalar<
double>(
"tol", 1e-3);
1507 t[
"infer_lqn_jacobian"] =
1508 "its first argument hfun is a function handle (the LQN observation map), which JSON "
1510 t[
"infer_lqn_ekf"] =
1511 "its first argument hfun is a function handle (the LQN observation map), which JSON "
1514 "it calibrates a LayeredNetwork model in place through a solver callable; no line-cli "
1515 "analysis serves LQN inference yet.";
1516 t[
"infer_lqn_setparams"] =
1517 "it writes parameters into a LayeredNetwork model object in place; there is no data "
1518 "result to return.";
1520 "it reads the Network model and the station node (NetworkStruct), not a data argument; "
1521 "no line-cli analysis serves demand inference yet.";
1522 t[
"infer_smp_env"] =
1523 "it takes the per-stage Network models and returns an Environment model object; solve "
1524 "the resulting environment with line-cli -s env.";
Internal to the –api dispatcher: what a per-domain translation unit needs to add entries to the table...
#define LINE_MTRACE_DIRECTED_MOMENT_OP(Name, fn)
#define LINE_MTRACE_CROSS_MOMENT_OP(Name, fn)
#define LINE_TRACE_SCALAR_OP(Name, fn, outkey)
UnsupportedError(const std::string &what)
Named-argument reader over the parsed JSON object.
Per-class queue lengths seen by each arriving job, reconstructed from arrival and response time sampl...
Per-class queue lengths at arrival for the per-class sample format.
Gibbs sampling demand estimator for a closed delay-plus-queue model.
First element of a named LQN container matching a name.
Observation vector of a solved LQN, z = h(a).
Turn a raw per-class trace into the sample set MINPS estimates from.
Maximum-likelihood service-demand estimation at a processor-sharing queue.
Fitting a nonstationary Poisson process from ONE observed sequence of arrival times.
Kolmogorov-Smirnov tests for a non-homogeneous Poisson arrival process.
Queue-length-based maximum-likelihood estimator of the service demands of a closed queueing network.
Convenience factory for the single-layer networks the inference estimators fit.
Regression for Processor Sharing (RPS) demand estimator.
Maximum-likelihood fit of a parametric semi-Markov multi-state model.
Variational inference for Markovian queueing networks.
Backward moments of a marked trace: the moments of the inter-arrival time that PRECEDES an event of e...
Per-class count process of a marked trace on a fixed resolution: the number of events of each class i...
Class-pair covariance matrices of a marked trace.
Class-pair cross moments of a marked trace: the k-th moment of the interval that separates an event o...
Forward moments of a marked trace: the moments of the inter-arrival time that FOLLOWS an event of eac...
Per-class counting processes of a marked trace: for each arrival, how many events of each class fall ...
Class-dependent joint moments of a marked trace,.
Per-type sample mean of a trace.
Superposes two single-class traces into one marked trace, labelling the events of the first stream 1 ...
Empirical class-dependent moments of a marked trace.
Class-pair cross moments of a marked trace.
Class probabilities of a marked trace, p_c = count_c / N.
Two-step class transition frequencies of a marked trace,.
One-step class transition frequencies of a marked trace,.
Splits a marked trace into its per-class traces: for each class, the inter-arrival times BETWEEN CONS...
Descriptor set of a marked trace: the first five raw moments of the inter-arrival times,...
std::vector< double > infer_minps(const std::vector< double > &muZ, double nCores, const std::vector< MlpsSample > &samples)
MINPS: run MLPS and RPS and keep whichever gives the smaller mean demand.
std::vector< double > infer_mlps(const std::vector< double > &muZ, double nCores, const std::vector< MlpsSample > &samples)
MLPS demand estimation at a PS queue.
MinpsSetup infer_minps_setup(const std::vector< MinpsClassTrace > &traces, std::size_t initSample, std::size_t sampleSize)
Turn a raw per-class trace into the sample set MINPS estimates from.
NhppKsResult< Tv > infer_nhpp_ks(const std::vector< Tv > ×, const Tv &T, const std::function< Tv(const Tv &)> &cumRate=std::function< Tv(const Tv &)>(), NhppKsMethod method=NhppKsMethod::Lewis, const Tv &T0=num_traits< Tv >::from_int(0))
Kolmogorov-Smirnov tests for a non-homogeneous Poisson arrival process.
static const std::size_t INFER_LQN_NOT_FOUND
Returned when no element carries the requested name, MATLAB's [].
std::size_t infer_smp_family_npar(const std::string &family)
infer_smp_family(F, 'npar'): the number of parameters, validating the name.
VariationalResult< T > infer_variational(VariationalSpec< T > spec, VariationalOptions< T > opt=VariationalOptions< T >())
Run the variational inference procedure.
std::vector< SmpHazard > infer_smp_hazard(const SmpFit &fit, const std::vector< double > &t, const std::vector< double > &zin=std::vector< double >())
infer_smp_hazard(fit, t, 'z', z): both hazard functions of every arc of a fit on the ascending instan...
std::vector< T > infer_rps(const std::vector< T > &rt, const std::vector< std::size_t > &cls, const Matrix< T > &ql, long V)
Regression for Processor Sharing (RPS) demand estimator.
std::vector< double > infer_smp_family_natural(const std::string &family, const std::vector< double > &th)
infer_smp_family(F, 'natural', THETA): rate | shape, scale | mu, sigma.
qn::Network< T > infer_quick_model(bool is_open, const std::vector< lang::SchedStrategy > &stations, const Matrix< T > &demands, const std::vector< double > &servers=std::vector< double >(), const std::vector< double > &jobs=std::vector< double >(), const std::vector< Matrix< T > > &routing=std::vector< Matrix< T > >())
Build a simple open or closed queueing network.
void infer_smp_family_logfs(const std::string &family, const std::vector< double > &th, const std::vector< double > &t, const std::vector< double > &eta, std::vector< double > &logf, std::vector< double > &logS)
infer_smp_family(F, 'logfs', THETA, T, ETA): log density and log survival at t under the proportional...
std::size_t infer_lqn_findbyname(const std::vector< std::string > &names, const std::string &name)
First element of a named LQN container matching a name.
std::vector< T > infer_gibbs(const std::vector< GibbsTrace< T > > &data, const T &nbCores, const GibbsOptions &opts, pfqn::McRng &rng)
Estimated per-class mean demands.
Matrix< T > infer_qmle(const Matrix< T > &Q, const std::vector< T > &N, const std::vector< T > &Z)
Queue-length-based maximum-likelihood estimator of the service demands of a closed queueing network.
lang::Distrib< double > infer_smp_family_dist(const std::string &family, const std::vector< double > &th, double eta)
infer_smp_family(F, 'dist', THETA, ETA): the LINE distribution of the law with hazard h0(t) exp(eta).
std::vector< double > infer_smp_family_theta0(const std::string &family, const std::vector< double > &tev, double texp)
infer_smp_family(F, 'theta0', TEV, TEXP): the starting point from the event times tev and the total e...
std::vector< Matrix< T > > infer_get_qlen_arrival(const std::vector< std::vector< T > > &at_ms, const std::vector< std::vector< T > > &rt)
Per-class queue lengths at arrival for the per-class sample format.
NhppPowerLawResult< T > infer_nhpp_powerlaw(const std::vector< T > ×, const T &horizon, double alpha=0.05)
Maximum likelihood power-law NHPP fit, Lambda(t) = (a t)^b, from one sample path, with observed-infor...
NhppKsMethod
Which test to run on the conditional-uniform data.
std::vector< T > infer_lqn_getobs(const std::vector< std::string > &names, const LqnMetrics< T > &metrics, const std::vector< LqnObsSpec > &spec)
Observation vector of a solved LQN, z = h(a).
NhppLeemisResult< T > infer_nhpp_leemis(const std::vector< T > ×, const T &horizon, const std::vector< T > &tq=std::vector< T >(), double alpha=0.05)
Nonparametric integrated-rate estimate of an NHPP from one sample path: the step-function estimator w...
Matrix< T > infer_compute_ql_at_arrival(const std::vector< T > &at, const std::vector< long > &at_jobid, const std::vector< T > &rt, const std::vector< long > &rt_jobid, const std::vector< std::size_t > &cls, std::size_t R)
Per-class queue lengths seen by each arriving job, reconstructed from arrival and response time sampl...
SmpFit infer_smp(const std::vector< std::size_t > &from, const std::vector< std::size_t > &to, const std::vector< double > &dur, const SmpOptions &opt=SmpOptions())
infer_smp(from, to, dur, ...): the fit, under opt.approach.
std::vector< SmpNelsonAalen > infer_smp_nelson_aalen(const std::vector< std::size_t > &from, const std::vector< std::size_t > &to, const std::vector< double > &dur, std::size_t nstates=0)
infer_smp_nelson_aalen(from, to, dur, 'nstates', E): the Nelson-Aalen estimate of the cumulative tran...
detail::json network_json_envelope(const qn::NetworkStruct< T > &sn)
The complete model.json envelope: {format, version, model}.
std::string name(const Element *el, const std::string &key="name")
std::mt19937_64 McRng
The generator type every Monte Carlo entry point in this tree accepts.
void register_library_only_trace(LibraryOnlyTable &t)
std::uint64_t required_seed(Args &a, const std::string &fn, const char *spelled="seed")
The seed of a function whose port draws from a caller-owned generator.
Json encode_vectors(const std::vector< std::vector< T > > &v)
A list of vectors, the shape a per-class or per-segment result returns.
std::vector< int > int_vector_from_json(const Json &j, const std::string &where)
An integer vector; a non-integral entry is an error, never a truncation.
Json encode_matrices(const std::vector< Matrix< T > > &v)
A list of matrices, the shape the MMAP/BMAP families return as {D0,D1,...}.
T number_from_json(const Json &j, const std::string &where)
std::vector< T > vector_from_json(const Json &j, const std::string &where)
A flat numeric vector: 1-D array, or a 1-row / 1-column 2-D array.
Json encode_vector(const std::vector< T > &v)
Json encode_matrix(const Matrix< T > &m)
void register_api_trace(DispatchTable &t)
Json encode_scalar(const T &v)
Json encode_count(std::size_t n)
A count.
std::map< std::string, std::string > LibraryOnlyTable
name -> why the function has no named-JSON-argument form.
Json encode_ints(const std::vector< int > &v)
std::map< std::string, Invoker > DispatchTable
MtraceCountResult< T > mtrace_count(const std::vector< T > &Tv, const std::vector< int > &A, const T &t)
Per-class count process of a marked trace on a fixed resolution: the number of events of each class i...
MtraceJointResult< T > mtrace_joint(const std::vector< T > &Tv, const std::vector< int > &A, unsigned i1, unsigned i2)
Class-dependent joint moments of a marked trace, JM(a) = (1/N_a) sum_{j : A_{j+1} = a}...
MtraceMeanResult< T > mtrace_mean(const std::vector< T > &Tv, long ntypes, const std::vector< int > &type)
Per-type sample mean of a trace.
TraceBicovResult< T > trace_bicov(const std::vector< T > &S, const std::vector< int > &grid)
Bicovariance of a trace on a lag grid.
TraceSummary< T > trace_summary(const std::vector< T > &S)
Descriptive summary of a trace: moments, shape, order statistics, autocorrelation and burstiness.
std::vector< std::vector< Matrix< T > > > mtrace_cov(const std::vector< T > &Tv, const std::vector< int > &A)
Class-pair covariance matrices of a marked trace.
TracePmfResult< T > trace_pmf(const std::vector< int > &X)
Empirical probability mass function of a discrete trace (counts, batch sizes, queue-length samples).
TraceBinsResult trace_iat2bins(const std::vector< T > &S, const T &scale)
Bins a trace on a fixed time grid: the number of arrivals falling in each interval ((i-1)*scale,...
Matrix< T > mtrace_sigma2(const std::vector< int > &L)
Two-step class transition frequencies of a marked trace, sigma(i,j,h) = #{t : A_t = i,...
MtraceMergeResult< T > mtrace_merge(const std::vector< T > &t1, const std::vector< T > &t2)
Superposes two single-class traces into one marked trace, labelling the events of the first stream 1 ...
MtraceSummary< T > mtrace_summary(const std::vector< T > &Tv, const std::vector< int > &A, int max_lag=100)
Descriptor set of a marked trace: the first five raw moments of the inter-arrival times,...
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 ...
TraceGammaResult< T > trace_gamma(const std::vector< T > &S, long limit=1000, const std::vector< T > &grid=std::vector< T >())
Autocorrelation decay rate of a trace: the gamma of the geometric model rho(k) = rho0 * gamma^k,...
MtraceSplitResult< T > mtrace_split(const std::vector< T > &Tv, const std::vector< int > &L)
Splits a marked trace into its per-class traces: for each class, the inter-arrival times BETWEEN CONS...
std::vector< T > mtrace_pc(const std::vector< int > &A)
Class probabilities of a marked trace, p_c = count_c / N.
Matrix< T > mtrace_moment(const std::vector< T > &Tv, const std::vector< int > &A, const std::vector< unsigned > &orders, bool after=false, bool norm=false)
Empirical class-dependent moments of a marked trace.
TraceIdiResult< T > trace_idi(const std::vector< T > &S, const std::vector< long > &k_set, long aggregate_n=0, bool drop_trailing_zero=false)
Index of dispersion for intervals, IDI(k) = k * var(S_t + ... + S_{t+k-1}) / mean(S_t + ....
T trace_joint(const std::vector< T > &S, const std::vector< int > &lag, const std::vector< unsigned > &order)
Joint moments of a trace, E[X_i^{k_1} X_{i+l_2}^{k_2} ...].
Matrix< T > mtrace_sigma(const std::vector< int > &L)
One-step class transition frequencies of a marked trace, sigma(i,j) = #{t : A_t = i,...
std::vector< T > trace_acf(const std::vector< T > &S, const std::vector< int > &lags)
Autocorrelation coefficients of a trace at the requested lags.
std::vector< long > trace_iat2counts(const std::vector< T > &S, const T &scale)
Counting process of a trace: the number of arrivals in the window of length scale that starts at each...
Conservation laws of a layered queueing network, enumerated from its structure.
Reader for the LINE model.json interchange (a Network model) into a qn::Network<T> built through the ...
qn::NetworkStruct -> model.json, the inverse of network_reader.h.
std::vector< double > lambda
per-surviving-class think-time rate
std::vector< MlpsSample > samples
sorted by arrival time, window applied
std::vector< std::size_t > classMap
Original 1-based class label of each surviving class, in the new order.
double threads
Wexp, the largest total queue length seen.
T statistic
the KS distance
std::vector< T > uniforms
after the conditional-uniform transformation
std::size_t n
number of arrivals used
T pvalue
asymptotic p-value
std::vector< T > transformed
after the Durbin step (Lewis), or 1-exp(-gap) (Tt)
std::vector< T > tq
query points
std::vector< T > knots
breakpoints [0, times, T], length N+2
T horizon
the observation horizon
std::vector< T > rates
piecewise-constant rate on each gap, length N+1
std::size_t n
number of arrivals N
std::vector< T > knotValues
piecewise-linear estimate at the knots
std::vector< T > cumRate
piecewise-linear estimate at tq
std::vector< T > upper
upper pointwise bound at tq
std::vector< T > step
step-function estimate at tq
std::vector< T > lower
lower pointwise bound at tq, floored at zero
T shape
the power-law shape b
T se[2]
standard errors of (a, b)
T scaleCI[2]
Wald interval for a.
T horizon
the observation horizon
T info[2][2]
observed information, order (a, b)
T shapeCI[2]
Wald interval for b.
T scale
the power-law scale a
T loglik
maximised log-likelihood
std::size_t n
number of arrivals N
std::vector< double > beta
p covariate effects, zero where masked out
std::vector< double > theta
unconstrained parameters
std::vector< double > se
standard errors of [theta; beta]
std::vector< double > params
natural parameters
double prob
Approach I: p_ij; Approach II: the embedded probability at z = 0.
Matrix< double > P
E x E embedded jump chain at z = 0.
std::vector< SmpArc > arcs
std::size_t unif_max_terms
double delta
rate added to every feasible transition by the space expansion.
double rate_max
cap on the variational rates; derived from ymax and tmax when negative.
std::vector< Matrix< T > > nu
std::vector< Matrix< T > > Y
std::vector< T > mean_service_time
std::vector< T > obsRange
(M*R) support size of the uniform contamination.
std::vector< T > arcrate
(T) known rate for transitions with arcparam == 0.
std::vector< T > capacity
(M*R) upper bound on the queue length, empty for none.
std::vector< std::size_t > arcparam
(T) index in 1..P of the rate governing the transition, 0 when known.
Matrix< T > x0
(M x R) initial queue lengths.
Matrix< T > obsData
(K x M*R) observed queue lengths; an unobserved entry is unobserved.
static T unobserved()
Sentinel marking an unobserved entry of obsData.
std::vector< std::array< std::size_t, 3 > > arcs
(T x 3) transitions [i j c]; i==0 external source, j==0 sink.
std::vector< int > sched
(M) discipline codes.
std::vector< T > obsTimes
(K) observation epochs.
std::vector< T > alpha0
(P) Gamma prior shapes and rates.
std::vector< T > nservers
(M) number of servers.
std::vector< T > routeprob
(T) routing probability of each transition.
T epsilon
probability that a reading is faulty.
std::vector< long > count
interior events of each label; 0 = undefined
std::vector< T > jm
one moment per label 1..max(A)
std::vector< T > mean
one mean per type; undefined where count = 0
std::vector< long > count
samples of each type
std::vector< int > labels
1 for the first stream, 2 for the second
std::vector< T > times
inter-arrival times of the merged process
Matrix< T > Pab
one-step class transition frequencies
std::vector< T > Pc
class probabilities
std::vector< T > M
raw moments of order 1..5
Matrix< T > C2
class-pair cross moments of order 1 and 2
Matrix< T > B2
backward moments of order 1 and 2
std::vector< T > acf
autocorrelation at the requested lags
Matrix< T > F2
forward moments of order 1 and 2
std::vector< std::vector< int > > lags
the [1,i,j] increment triples
std::vector< T > bicov
one moment per grid pair
std::vector< long > counts
arrivals per bin
std::vector< long > membership
1-based bin index of each binned arrival
T rho0
(1 - 1/scv)/2, the GE-type lag-0 amplitude
T gamma
best decay rate on the grid
T residuals
sum of squared deviations from the fitted model
std::vector< T > idi
one value per requested k
std::vector< long > support
the number of points each value rests on
std::vector< T > pmf
relative frequency of each distinct value
std::vector< int > values
the distinct values, in increasing order
T mad
median absolute deviation about the median
T kurt_excess
population kurtosis minus 3
std::vector< T > acf
lags 1..4
T skew
bias-corrected skewness, see trace_skew
Autocorrelation coefficients of a trace at the requested lags.
Bicovariance of a trace on a lag grid.
Autocorrelation decay rate of a trace: the gamma of the geometric model rho(k) = rho0 * gamma^k,...
Bins a trace on a fixed time grid: the number of arrivals falling in each interval ((i-1)*scale,...
Counting process of a trace: the number of arrivals in the window of length scale that starts at each...
Index of dispersion for counts, estimated by its asymptotic equality with the index of dispersion for...
Index of dispersion for intervals,.
Joint moments of a trace, E[X_i^{k_1} X_{i+l_2}^{k_2} ...].
Empirical probability mass function of a discrete trace (counts, batch sizes, queue-length samples).
Squared coefficient of variation of a trace, var/mean^2.
Bias-corrected sample skewness (MATLAB's skewness(S,0), equivalently the G1 estimator).
Descriptive summary of a trace: moments, shape, order statistics, autocorrelation and burstiness.
Sample variance of a trace.