LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
line::sim Namespace Reference

Classes

struct  AsymVarResult
 Second-order description of a steady-state estimator. More...
struct  QuestInterval
 A confidence interval, asymmetric about the point estimate in general. More...
struct  QuestOptions
 Procedure constants shared by sim_fquest and sim_firquest. More...
struct  QuestResult
 Point estimate and interval delivered by the QUEST procedures. More...
struct  RunLengthPlan
 The plan of sim_runlength_plan: what the run should have been. More...
struct  RunLengthResult
 Outcome of the run-length plan. More...
struct  ShapiroWilkResult
 Outcome of the Shapiro-Wilk normality test. More...
struct  StsQuantileStats
 Batched-quantile statistics of one sample path. More...
struct  VonNeumannResult
 Outcome of the von Neumann randomness test. More...

Functions

double sim_normcdf (double z)
 Standard normal cumulative distribution function.
double sim_norminv (double p)
 Standard normal quantile function.
double sim_tinv (double p, double nu)
 Quantile function of Student's t distribution.
std::vector< long > sim_firquest_batchcounts (std::size_t R)
 The article's batch counts as a function of the replication count, chosen so that R*b pooled statistics remain enough to test while every replication still contributes at least one batch.
QuestOptions sim_firquest_options (std::size_t R)
 The FIRQUEST defaults at R replications: b0 = 25 and the R-dependent ladder, every other constant as in FQUEST.
template<class T>
QuestResult< T > sim_firquest (const std::vector< std::vector< T > > &Y, double p, double alpha=0.05, const QuestOptions *options=nullptr)
 Fixed-sample-size quantile interval from independent replications.
template<class T>
QuestResult< T > sim_fquest (const std::vector< T > &Y, double p, double alpha=0.05, const QuestOptions &options=QuestOptions())
 Fixed-sample-size confidence interval for a steady-state quantile.
template<class T>
QuestInterval< T > sim_quest_heuristic_ci (const std::vector< T > &bqe, const T &centre, const T &Ap, const T &Np, std::size_t nstar, double alpha, bool useAutocorr)
 Fallback interval used when a QUEST stage test fails.
QuestOptions sim_quest_options (const QuestOptions &options=QuestOptions())
 Validates an option set and returns it.
template<class T>
AsymVarResult< T > sim_asymvar_mm1 (const T &lambda, const T &mu)
 Asymptotic variance of the M/M/1 number-in-system process.
template<class T>
AsymVarResult< T > sim_asymvar_ctmc (const Matrix< T > &A, const std::vector< T > &f, const std::vector< T > &pi=std::vector< T >())
 Asymptotic variance of a reward on a CTMC: 2 sum_x pi(x)g(x)d(x) with g = f - E_pi[f] and A d = -g, pi d = 0.
template<class T>
RunLengthResult< T > sim_runlength (const T &mean, const T &asymVar, const T &relPrecision=num_traits< T >::from_rational(1, 20), const T &confidence=num_traits< T >::from_rational(19, 20), const T &runLength=num_traits< T >::from_int(0))
 Run length for a steady-state estimate of a given relative precision.
template<class T>
RunLengthPlan< T > sim_runlength_plan (const Matrix< T > &means, const Matrix< T > &ciHalfWidth, const T &samplesUsed, const T &relPrecision=num_traits< T >::from_rational(1, 20), const T &confidence=num_traits< T >::from_rational(19, 20))
 How long a simulation run should have been, from the one it already did.
template<class T>
ShapiroWilkResult< T > sim_shapirowilk (const std::vector< T > &x, double alpha=0.05)
 Shapiro-Wilk test for univariate normality.
template<class T>
StsQuantileStats< T > sim_sts_quantile_areas (const std::vector< T > &Y, std::size_t b, std::size_t m, double p, double weight=std::sqrt(12.0))
 Standardized time series areas of the batched quantile process.
template<class T>
VonNeumannResult< T > sim_vonneumann (const std::vector< T > &x, double alpha=0.05)
 Von Neumann ratio test for randomness of a sequence.

Function Documentation

◆ sim_asymvar_ctmc()

template<class T>
AsymVarResult< T > line::sim::sim_asymvar_ctmc ( const Matrix< T > & A,
const std::vector< T > & f,
const std::vector< T > & pi = std::vector<T>() )

Asymptotic variance of a reward on a CTMC: 2 sum_x pi(x)g(x)d(x) with g = f - E_pi[f] and A d = -g, pi d = 0.

The normalization is what pins d: A alone is singular, since a constant may be added without changing sigma^2.

Parameters
Athe generator, rows summing to zero
fthe reward attached to each state
pithe stationary distribution; solved for when empty

Definition at line 105 of file sim_runlength.h.

References line::sim::AsymVarResult< T >::asymptoticVariance, line::Matrix< T >::cols(), line::sim::AsymVarResult< T >::deviation, line::InputError::InputError(), line::sim::AsymVarResult< T >::mean, line::num_abs(), line::sim::AsymVarResult< T >::relaxationTime, line::Matrix< T >::rows(), sim_asymvar_ctmc(), line::solve(), and line::sim::AsymVarResult< T >::variance.

Referenced by line::ctmc::ctmc_get_asymptotic_variance(), and sim_asymvar_ctmc().

◆ sim_asymvar_mm1()

template<class T>
AsymVarResult< T > line::sim::sim_asymvar_mm1 ( const T & lambda,
const T & mu )

Asymptotic variance of the M/M/1 number-in-system process.

Parameters
lambdaarrival rate
muservice rate

Definition at line 78 of file sim_runlength.h.

References line::sim::AsymVarResult< T >::asymptoticVariance, line::InputError::InputError(), line::sim::AsymVarResult< T >::mean, line::sim::AsymVarResult< T >::relaxationTime, sim_asymvar_mm1(), and line::sim::AsymVarResult< T >::variance.

Referenced by sim_asymvar_mm1().

◆ sim_firquest()

template<class T>
QuestResult< T > line::sim::sim_firquest ( const std::vector< std::vector< T > > & Y,
double p,
double alpha = 0.05,
const QuestOptions * options = nullptr )

◆ sim_firquest_batchcounts()

std::vector< long > line::sim::sim_firquest_batchcounts ( std::size_t R)
inline

The article's batch counts as a function of the replication count, chosen so that R*b pooled statistics remain enough to test while every replication still contributes at least one batch.

Parameters
Rnumber of replications
Returns
the descending batch-count ladder

Definition at line 87 of file sim_firquest.h.

References sim_firquest_batchcounts().

Referenced by sim_firquest_batchcounts(), and sim_firquest_options().

◆ sim_firquest_options()

QuestOptions line::sim::sim_firquest_options ( std::size_t R)
inline

The FIRQUEST defaults at R replications: b0 = 25 and the R-dependent ladder, every other constant as in FQUEST.

Parameters
Rnumber of replications
Returns
the option set sim_firquest uses when none is supplied

Definition at line 105 of file sim_firquest.h.

References sim_firquest_batchcounts(), and sim_firquest_options().

Referenced by sim_firquest(), and sim_firquest_options().

◆ sim_fquest()

◆ sim_normcdf()

double line::sim::sim_normcdf ( double z)
inline

Standard normal cumulative distribution function.

Parameters
zthe argument
Returns
Phi(z)

Definition at line 52 of file sim_dist.h.

References sim_normcdf().

Referenced by line::trace::mtrace_bootstrap(), sim_normcdf(), sim_shapirowilk(), and sim_vonneumann().

◆ sim_norminv()

double line::sim::sim_norminv ( double p)
inline

Standard normal quantile function.

Parameters
pprobability in [0,1]
Returns
Phi^{-1}(p), infinite at the endpoints

Definition at line 62 of file sim_dist.h.

References line::InputError::InputError(), and sim_norminv().

Referenced by line::trace::mtrace_bootstrap(), and sim_norminv().

◆ sim_quest_heuristic_ci()

template<class T>
QuestInterval< T > line::sim::sim_quest_heuristic_ci ( const std::vector< T > & bqe,
const T & centre,
const T & Ap,
const T & Np,
std::size_t nstar,
double alpha,
bool useAutocorr )

Fallback interval used when a QUEST stage test fails.

Parameters
bqethe K batched quantile estimators, pooled over replications for sim_firquest
centrethe full-sample empirical quantile
ApSTS area variance-parameter estimator
NpNBQ variance-parameter estimator, may be NaN
nstarnumber of observations Ap and Np were computed from
alphanominal non-coverage
useAutocorrapply the lag-1 correction to the asymmetric arms

Definition at line 109 of file sim_quest_heuristic_ci.h.

References line::InputError::InputError(), line::sim::QuestInterval< T >::lower, line::num_abs(), sim_quest_heuristic_ci(), sim_tinv(), and line::sim::QuestInterval< T >::upper.

Referenced by sim_firquest(), sim_fquest(), and sim_quest_heuristic_ci().

◆ sim_quest_options()

QuestOptions line::sim::sim_quest_options ( const QuestOptions & options = QuestOptions())
inline

Validates an option set and returns it.

Parameters
optionsthe constants to check
Returns
the same constants, once every admissibility condition holds

Definition at line 57 of file sim_quest_options.h.

References line::InputError::InputError(), and sim_quest_options().

Referenced by sim_firquest(), sim_fquest(), and sim_quest_options().

◆ sim_runlength()

template<class T>
RunLengthResult< T > line::sim::sim_runlength ( const T & mean,
const T & asymVar,
const T & relPrecision = num_traits<T>::from_rational(1, 20),
const T & confidence = num_traits<T>::from_rational(19, 20),
const T & runLength = num_traits<T>::from_int(0) )

Run length for a steady-state estimate of a given relative precision.

Parameters
meanthe steady-state mean being estimated
asymVarsigma^2 of that estimator
relPrecisionthe target half-width as a fraction of the mean
confidencethe confidence level of the interval
runLengthan actual run length, to report the precision it buys; non-positive to skip

Definition at line 179 of file sim_runlength.h.

References line::sim::RunLengthResult< T >::achievedRelPrecision, line::sim::RunLengthResult< T >::halfWidth, line::sim::RunLengthResult< T >::hasRun, line::InputError::InputError(), line::num_abs(), line::sim::RunLengthResult< T >::requiredRunLength, sim_runlength(), and line::sim::RunLengthResult< T >::z.

Referenced by sim_runlength(), and sim_runlength_plan().

◆ sim_runlength_plan()

template<class T>
RunLengthPlan< T > line::sim::sim_runlength_plan ( const Matrix< T > & means,
const Matrix< T > & ciHalfWidth,
const T & samplesUsed,
const T & relPrecision = num_traits<T>::from_rational(1, 20),
const T & confidence = num_traits<T>::from_rational(19, 20) )

How long a simulation run should have been, from the one it already did.

A batch-means half-width H at confidence 1-alpha over a run of N samples pins the ASYMPTOTIC variance of the estimator,

sigma^2 = (H/z)^2 N, z = Phi^-1((1+confidence)/2),

and that is the quantity a run length is planned from – NOT the stationary variance, which on M/M/1 differs from it by a factor blowing up like (1-rho)^-2. sim_runlength then turns it into the sample count that reaches a requested RELATIVE precision.

An entry with a non-positive mean or half-width is left NaN, since there is nothing to plan from there.

Reference: W. Whitt (1989). Planning queueing simulations. Management Science 35(11), 1341-1366.

Definition at line 249 of file sim_runlength.h.

References line::sim::RunLengthPlan< T >::asymptoticVariance, line::Matrix< T >::cols(), line::sim::RunLengthPlan< T >::confidence, line::InputError::InputError(), line::Matrix< T >::Matrix(), line::sim::RunLengthPlan< T >::relPrecision, line::sim::RunLengthPlan< T >::requiredSamples, line::Matrix< T >::rows(), line::sim::RunLengthPlan< T >::samplesUsed, sim_runlength(), and sim_runlength_plan().

Referenced by line::ldes::engine::batch_means_ci(), and sim_runlength_plan().

◆ sim_shapirowilk()

template<class T>
ShapiroWilkResult< T > line::sim::sim_shapirowilk ( const std::vector< T > & x,
double alpha = 0.05 )

Shapiro-Wilk test for univariate normality.

Parameters
xthe sample, 3 to 5000 finite observations, order irrelevant
alphasignificance level in (0,1), 0.05 by default

Definition at line 122 of file sim_shapirowilk.h.

References line::InputError::InputError(), line::sim::ShapiroWilkResult< T >::nobs, line::sim::ShapiroWilkResult< T >::pvalue, line::sim::ShapiroWilkResult< T >::reject, sim_normcdf(), sim_shapirowilk(), line::sim::ShapiroWilkResult< T >::W, and line::sim::ShapiroWilkResult< T >::zscore.

Referenced by sim_firquest(), sim_fquest(), and sim_shapirowilk().

◆ sim_sts_quantile_areas()

template<class T>
StsQuantileStats< T > line::sim::sim_sts_quantile_areas ( const std::vector< T > & Y,
std::size_t b,
std::size_t m,
double p,
double weight = std::sqrt(12.0) )

Standardized time series areas of the batched quantile process.

Parameters
Yexactly b*m finite observations, in sample-path order
bbatch count, positive
mbatch size, positive
pquantile order in (0,1)
weightconstant STS weight function, sqrt(12) by default

Definition at line 131 of file sim_sts_quantile_areas.h.

References line::sim::StsQuantileStats< T >::Ap, line::sim::StsQuantileStats< T >::areas, line::sim::StsQuantileStats< T >::b, line::sim::StsQuantileStats< T >::bqe, line::InputError::InputError(), line::sim::StsQuantileStats< T >::m, line::sim::StsQuantileStats< T >::n, line::sim::StsQuantileStats< T >::Np, line::sim::StsQuantileStats< T >::quantile, sim_sts_quantile_areas(), and line::sim::StsQuantileStats< T >::Vp.

Referenced by sim_firquest(), sim_fquest(), and sim_sts_quantile_areas().

◆ sim_tinv()

double line::sim::sim_tinv ( double p,
double nu )
inline

Quantile function of Student's t distribution.

Parameters
pprobability in [0,1]
nudegrees of freedom, positive
Returns
the p-quantile of t with nu degrees of freedom

Definition at line 77 of file sim_dist.h.

References line::InputError::InputError(), and sim_tinv().

Referenced by sim_firquest(), sim_fquest(), sim_quest_heuristic_ci(), and sim_tinv().

◆ sim_vonneumann()

template<class T>
VonNeumannResult< T > line::sim::sim_vonneumann ( const std::vector< T > & x,
double alpha = 0.05 )

Von Neumann ratio test for randomness of a sequence.

Parameters
xthe sequence, at least 3 finite observations
alphasignificance level in (0,1), 0.05 by default

Definition at line 70 of file sim_vonneumann.h.

References line::InputError::InputError(), line::sim::VonNeumannResult< T >::nobs, line::sim::VonNeumannResult< T >::pvalue, line::sim::VonNeumannResult< T >::ratio, line::sim::VonNeumannResult< T >::reject, sim_normcdf(), sim_vonneumann(), and line::sim::VonNeumannResult< T >::zscore.

Referenced by sim_firquest(), sim_fquest(), and sim_vonneumann().