![]() |
LINE Solver (C++)
Templated C++ port of the LINE queueing solver
|
Maximum-likelihood fit of a parametric semi-Markov multi-state model. More...
#include <algorithm>#include <cctype>#include <cmath>#include <cstddef>#include <functional>#include <limits>#include <string>#include <vector>#include "line/api/mc/smp_stage_cif.h"#include "line/api/mc/smp_stage_quad.h"#include "line/api/pfqn/pfqn_sjn.h"#include "line/lang/lang_types.h"#include "line/lang/qn/environment.h"#include "line/lang/qn/network_struct.h"#include "line/util/error.h"#include "line/util/matrix.h"Go to the source code of this file.
Classes | |
| struct | line::infer::SmpOptions |
| Options of infer_smp, the reference's name/value pairs. More... | |
| struct | line::infer::SmpArc |
| One fitted transition. More... | |
| struct | line::infer::SmpFit |
| What infer_smp returns. More... | |
| struct | line::infer::SmpEnvOptions |
| Options of infer_smp_env. More... | |
| struct | line::infer::SmpHazard |
| Both hazard functions of one transition, rows aligned with the instants asked for. More... | |
| struct | line::infer::SmpNelsonAalen |
| One Nelson-Aalen estimate, on the distinct event times of its transition. More... | |
Namespaces | |
| namespace | line |
| Conservation laws of a layered queueing network, enumerated from its structure. | |
| namespace | line::infer |
| namespace | line::infer::smp_infer_detail |
Typedefs | |
| using | line::infer::smp_infer_detail::Objective = std::function<double(const std::vector<double>&)> |
Functions | |
| std::string | line::infer::smp_family_name (const std::string &f) |
| Lower-case copy of a family name. | |
| std::size_t | line::infer::infer_smp_family_npar (const std::string &family) |
| infer_smp_family(F, 'npar'): the number of parameters, validating the name. | |
| void | line::infer::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-hazards factor exp(eta): H = H0 exp(eta), log h = log h0 + eta, log f = log h - H. | |
| std::vector< double > | line::infer::infer_smp_family_natural (const std::string &family, const std::vector< double > &th) |
| infer_smp_family(F, 'natural', THETA): rate | shape, scale | mu, sigma. | |
| std::vector< double > | line::infer::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 exposure texp. | |
| lang::Distrib< double > | line::infer::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). | |
| double | line::infer::smp_infer_detail::nanmax (const std::vector< double > &v) |
| MATLAB's max over a vector: NaNs ignored, NaN when every entry is one. | |
| void | line::infer::smp_infer_detail::nm_run (const Objective &f, const std::vector< double > &x0, double tolx, double tolf, std::size_t maxit, std::vector< double > &xb, double &fb) |
| One run of the reference's Nelder-Mead (nmRun). | |
| std::vector< double > | line::infer::smp_infer_detail::nelder_mead (const Objective &f, const std::vector< double > &x0, const SmpOptions &opt) |
| nelderMead: restart nm_run from its own optimum, at most four runs. | |
| std::vector< double > | line::infer::smp_infer_detail::hessian_se (const Objective &f, const std::vector< double > &x) |
| hessianSE: central-difference Hessian with steps 1e-4 max(1, |x|), its Cholesky factor H = R'R, and se = sqrt(rowsum((R \ I). | |
| std::vector< double > | line::infer::smp_infer_detail::linpred (const Matrix< double > &Z, const std::vector< std::size_t > &rows, const std::vector< std::size_t > &cov, const double *beta) |
| Z(rows, cov) * beta, one value per row. | |
| void | line::infer::smp_infer_detail::fit_intensity_arc (const std::string &family, const std::vector< double > &t, const std::vector< char > &ev, const Matrix< double > &Z, const std::vector< std::size_t > &rows, const std::vector< std::size_t > &cov, const SmpOptions &opt, std::vector< double > &th, std::vector< double > &be, std::vector< double > &se, double &ll) |
| fitIntensityArc: one transition of Approach II, its events ev among the sojourns t. | |
| std::vector< double > | line::infer::smp_infer_detail::expand_beta (const std::vector< double > &be, const std::vector< std::size_t > &cov, std::size_t p) |
| expandBeta: the effects of the selected covariates, zero elsewhere. | |
| void | line::infer::smp_infer_detail::fit_sojourn_state (std::size_t i, const std::vector< std::size_t > &dests, const std::vector< std::vector< std::string > > &fam, const std::vector< double > &t, const std::vector< std::size_t > &to, const Matrix< double > &Z, const std::vector< std::size_t > &rows, const std::vector< std::vector< std::vector< bool > > > &mask, std::size_t p, const SmpOptions &opt, std::vector< SmpArc > &arcs, double &ll, std::size_t &np) |
| fitSojournState: state i of Approach I. | |
| SmpFit | line::infer::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. | |
| env::Environment< double > | line::infer::infer_smp_env (const SmpFit &fit, const std::vector< qn::NetworkStruct< double > > &models, const SmpEnvOptions &opt=SmpEnvOptions()) |
| infer_smp_env(fit, models, ...): the Environment of a fit, models[e] the network of stage e. | |
| std::vector< SmpHazard > | line::infer::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 instants t > 0 (Asanjarani et al., Eqs. | |
| std::vector< SmpNelsonAalen > | line::infer::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 transition intensity of every observed transition, on the clock reset at each jump. | |
Maximum-likelihood fit of a parametric semi-Markov multi-state model.
Port of matlab/src/api/infer/infer_smp.m and its four companions, infer_smp_family.m, infer_smp_env.m, infer_smp_hazard.m and infer_smp_nelson_aalen.m, which this header carries together.
DATA. One row per observed sojourn: the process entered state from[k], stayed dur[k] > 0, and then moved to state to[k], or was still in from[k] when observation stopped, coded to[k] = 0 (right censoring). States are 1..E, as in the reference, since 0 is the censoring code.
THE TWO APPROACHES of Asanjarani, Liquet and Nazarathy (arXiv:2005.14462, 2020). intensity (Approach II, the default) fits each transition i -> j as a latent clock with its own law, so the likelihood splits into one censored two-state likelihood per transition, every sojourn out of i that did not end in j counting as censored for i -> j. sojourn (Approach I) fits the embedded chain p_ij and the law F_ij of a sojourn that ends in j; a censored sojourn contributes S_i(U) = sum_j p_ij S_ij(U), which couples the parameters of a state, so a state with censored rows is fitted jointly (p by a softmax over the logits of destinations 2..m) and one without in closed form for p.
FAMILIES, in unconstrained coordinates THETA (infer_smp_family_*): exp THETA = log(rate) weibull THETA = [log(shape), log(scale)] gamma THETA = [log(shape), log(scale)] lognormal THETA = [mu, log(sigma)] Covariates enter as a proportional-hazards factor exp(beta' z).
THE MAXIMIZER is the reference's deterministic Nelder-Mead (the Lagarias et al. variant of fminsearch, restarted from its own optimum until it stops improving), step for step, so the four codebases walk the same simplex; an exponential transition without covariates has its closed-form MLE. Standard errors come from the central-difference Hessian of the negative log-likelihood in THETA coordinates, NaN when it is not positive definite.
Definition in file infer_smp.h.