LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
ctmc_hitting_dist.h File Reference

Distribution of the hitting time of a rarely visited set by regenerative simulation of a continuous-time Markov chain, with the five estimators of Glynn, Nakayama and Tuffin (WSC 2020): exponential, convolution, corrected convolution, gamma and bootstrap. More...

#include <array>
#include <cctype>
#include <cmath>
#include <cstddef>
#include <cstdio>
#include <functional>
#include <limits>
#include <string>
#include <vector>
#include <boost/math/special_functions/gamma.hpp>
#include "line/api/sim/sim_dist.h"
#include "line/util/error.h"
#include "line/util/matrix.h"
#include "line/util/rng_ssj.h"
Include dependency graph for ctmc_hitting_dist.h:

Go to the source code of this file.

Classes

struct  line::mc::HittingDistSuccessors
 Successor states of a state and their rates (function form). More...
struct  line::mc::HittingDistOptions
 Options, with the MATLAB defaults. More...
struct  line::mc::HittingDistResult
 Estimates and diagnostics; every vector over t has one entry per time. More...
struct  line::mc::detail_hit::Checked

Namespaces

namespace  line
 Conservation laws of a layered queueing network, enumerated from its structure.
namespace  line::mc
namespace  line::mc::detail_hit

Typedefs

using line::mc::HittingDistTransition = std::function<HittingDistSuccessors(const std::vector<double>&)>
 Transition function of the function form.
using line::mc::HittingDistTarget = std::function<bool(const std::vector<double>&)>
 Target-set predicate of the function form.
using line::mc::HittingDistImportance
 Change of measure of the function form: given the state x, the successors Y and their rates as the transition function gave them (after dropping zero rates and self-loops), the importance rate of each successor.

Functions

void line::mc::detail_hit::input (const char *kind, const std::string &msg)
void line::mc::detail_hit::numerical (const char *kind, const std::string &msg)
std::string line::mc::detail_hit::fmt_g (double v)
void line::mc::detail_hit::seed_stream (rng::Mrg32k3a &g, long long seed)
 Six MRG32k3a seeds from one integer, the affine map of sim_prio_tailquantile.
double line::mc::detail_hit::vsum (const std::vector< double > &x)
long long line::mc::detail_hit::pick (const std::vector< double > &w, double u)
 Index drawn from the weights w by the uniform u, by a left-to-right scan; -1 if none is positive.
double line::mc::detail_hit::var (const std::vector< double > &x)
 Sample variance with the n - 1 denominator.
Checked line::mc::detail_hit::check_options (const std::vector< double > &t, const HittingDistOptions &opt)
 The option and time checks MATLAB runs before looking at the chain, in its order.
template<class State, class Step, class IsRates, class Target>
void line::mc::detail_hit::run_cycle (const Step &step, const IsRates &isr, bool useIS, const Target &target, const State &x0, double maxsteps, rng::Mrg32k3a &g, double &a, bool &hit, double &L)
 One regenerative cycle from x0: a = T ^ tau, hit = I(T < tau) and L the likelihood ratio of the path (1 without a change of measure).
template<class State, class Step, class IsRates, class Target>
HittingDistResult line::mc::detail_hit::estimate (const Step &step, const IsRates &isr, bool hasIS, const Target &target, const State &x0, const std::vector< double > &t, const Checked &c, const HittingDistOptions &opt)
 The cycles and the five estimators, common to both forms.
HittingDistResult line::mc::detail_hit::generator_form (const Matrix< double > &Q, int x0, const std::function< std::vector< char >(std::size_t)> &makeMask, const std::vector< double > &t, const HittingDistOptions &opt)
 Generator form after the target has been turned into a mask by makeMask(n).
Matrix< double > line::mc::detail_hit::to_matrix (const std::vector< std::vector< double > > &Q)
std::function< std::vector< char >(std::size_t)> line::mc::detail_hit::index_mask (const std::vector< int > &target)
std::function< std::vector< char >(std::size_t)> line::mc::detail_hit::bool_mask (const std::vector< bool > &target)
HittingDistResult line::mc::ctmc_hitting_dist (const HittingDistTransition &trans, const std::vector< double > &x0, const HittingDistTarget &target, const std::vector< double > &t, const HittingDistOptions &opt=HittingDistOptions())
 Hitting-time distribution of a target set, function form.
HittingDistResult line::mc::ctmc_hitting_dist (const Matrix< double > &Q, int x0, const std::vector< int > &target, const std::vector< double > &t, const HittingDistOptions &opt=HittingDistOptions())
 Hitting-time distribution of a target set, generator form.
HittingDistResult line::mc::ctmc_hitting_dist (const Matrix< double > &Q, int x0, const std::vector< bool > &target, const std::vector< double > &t, const HittingDistOptions &opt=HittingDistOptions())
 Generator form with the target given as a mask over the rows.
HittingDistResult line::mc::ctmc_hitting_dist (const std::vector< std::vector< double > > &Q, int x0, const std::vector< int > &target, const std::vector< double > &t, const HittingDistOptions &opt=HittingDistOptions())
 Generator form with Q as nested rows and the target as 0-based row indices.
HittingDistResult line::mc::ctmc_hitting_dist (const std::vector< std::vector< double > > &Q, int x0, const std::vector< bool > &target, const std::vector< double > &t, const HittingDistOptions &opt=HittingDistOptions())
 Generator form with Q as nested rows and the target as a mask over the rows.

Detailed Description

Distribution of the hitting time of a rarely visited set by regenerative simulation of a continuous-time Markov chain, with the five estimators of Glynn, Nakayama and Tuffin (WSC 2020): exponential, convolution, corrected convolution, gamma and bootstrap.

Port of matlab/src/api/mc/ctmc_hitting_dist.m, cross-checked against python/line_solver/api/mc/hitting_dist.py.

METHOD. The chain starts in the regeneration state x0, and a cycle ends at its first return to x0. With T the hitting time of the target set A and tau the cycle length, T = S + V, where S is the geometric sum of the M cycles completed before the first one that reaches A and V is the time to reach A inside that cycle. Every estimator needs p = P(T < tau), which is small, and some cycle statistics under the original law. They come from measure-specific importance sampling (Goyal et al. 1992): nCS = floor(gamma*n + 0.5) cycles of crude simulation estimate the cycle statistics, and the other nIS = n - nCS cycles, run under the change of measure, estimate p and the law H of V.

"exp" F(t) = 1 - exp(-t/mu), mu = E[T ^ tau]/p (eq. 6) "conv" exponential law of S, mean eta, convolved with H (eq. 10) "corr" Blanchet-Glynn corrected exponential law of S with H (Est. 3) "gamma" gamma law with the first two moments of T, E[T^2] from Proposition 1 (Est. 4) "boot" semi-parametric bootstrap of S + V (Est. 5)

The convolutions are evaluated as E[I(V <= t) G(t - V)]. The printed form of Estimator 3 writes G((t - V)^+) without the indicator, which is the same thing only for a law of S with no mass at 0; the corrected law has some. The change of measure acts on the embedded jump chain only: holding times are drawn from the original total rate, so the likelihood ratio of a path is the product of P(x,y)/P'(x,y) over its jumps. A field is NaN when its estimator is undefined on the sample: corr needs a crude cycle that returned before reaching A, gamma a positive variance estimate.

TWO FORMS. In function form a state is a vector of doubles, the transition function returns its successors and their rates (successors equal to the state and zero rates are dropped, keeping the order of the rest), the target is a predicate and the change of measure is HittingDistOptions::istrans. In generator form a state is a 0-BASED row index of a dense generator Q, its successors are the columns with a positive off-diagonal rate in ASCENDING column order, the target is a list of 0-based row indices or a mask over the rows, and the change of measure is the importance generator HittingDistOptions::isgen of the same size.

RANDOM NUMBERS. All draws come from one MRG32k3a stream (line::rng::Mrg32k3a, L'Ecuyer's double-precision form, SSJ's nextValue), seeded from options.seed by the affine map of sim_prio_tailquantile and consumed in a fixed order: crude cycles, then importance cycles, then the bootstrap; in a cycle each jump takes the holding time first and the successor second. MATLAB, Python and the JAR consume the same stream in the same order, so a seed gives the same estimates everywhere up to last-ulp differences of log() and exp().

Reference: P. W. Glynn, M. K. Nakayama, B. Tuffin, "Comparing regenerative- simulation-based estimators of the distribution of the hitting time to a rarely visited set", Proc. Winter Simulation Conference 2020, 421-432.

Definition in file ctmc_hitting_dist.h.