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

Prior: parameter uncertainty as a weighted set of alternative models. More...

#include <algorithm>
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <functional>
#include <memory>
#include <random>
#include <string>
#include <vector>
#include "line/lang/distribution.h"
#include "line/lang/lang_types.h"
#include "line/num/number.h"
#include "line/util/error.h"
Include dependency graph for prior.h:

Go to the source code of this file.

Classes

class  line::lang::PriorRng
 The uniform stream the Monte Carlo design draws from. More...
struct  line::lang::PriorDesign< T >
 A Prior reduced to alternatives and weights; the output of prior_discretize. More...

Namespaces

namespace  line
namespace  line::lang

Functions

template<class T>
Distrib< T > line::lang::prior_discrete (const std::vector< Distrib< T > > &alternatives, const std::vector< T > &probabilities)
 Prior(distributions, probabilities): the discrete form.
template<class T>
Distrib< T > line::lang::prior_continuous (const Distrib< T > &param_dist, const std::function< Distrib< T >(const T &)> &factory)
 Prior(paramDist, distFactory): the continuous form.
template<class T>
Distrib< T > line::lang::prior_from_sample (std::size_t k, const T &s, const std::function< Distrib< T >(const T &)> &factory=std::function< Distrib< T >(const T &)>())
 Prior.fromSample(k, s): the posterior of a rate estimated from lifetime data.
template<class T>
PriorDesign< T > line::lang::prior_discretize (const Distrib< T > &d, std::size_t n, const std::string &method, PriorRng &rng)
 Reduce a Prior to n weighted alternatives, MATLAB Prior.discretize.
template<class T>
PriorDesign< T > line::lang::prior_discretize (const Distrib< T > &d)
 prior_discretize with the defaults of Prior.discretize: 11 quadrature nodes.
template<class T>
line::lang::prior_mean (const Distrib< T > &d)
 E[X] = sum_i p_i E[X_i], MATLAB Prior.getMean.
template<class T>
line::lang::prior_scv (const Distrib< T > &d)
 The SCV by the law of total variance, MATLAB Prior.getSCV.
template<class T>
line::lang::prior_skewness (const Distrib< T > &d)
 The skewness of the mixture, MATLAB Prior.getSkewness.
template<class T>
line::lang::prior_cdf (const Distrib< T > &d, const T &t)
 F(t) = sum_i p_i F_i(t), MATLAB Prior.evalCDF.
template<class T>
line::lang::prior_lst (const Distrib< T > &d, const T &s)
 L(s) = sum_i p_i L_i(s), MATLAB Prior.evalLST.
template<class T>
void line::lang::prior_refresh_moments (Distrib< T > &d)
 Write the mixture moments onto a Prior, the counterpart of dist_refresh_moments for the Markovian families.

Variables

constexpr std::size_t line::lang::kPriorDefaultNodes = 11
 The default number of nodes per continuous Prior, MATLAB options.samples.

Detailed Description

Prior: parameter uncertainty as a weighted set of alternative models.

Port of matlab/src/lang/processes/Prior.m. A Prior is placed where a service or arrival distribution goes and says that the law is not known: it is one of an explicit alternative set with prior weights (the DISCRETE form), or it is generated by a scalar parameter whose density is given together with a map from the parameter to a distribution (the CONTINUOUS form of Trivedi and Bobbio (2017), Sec. 3.4). SolverUQ is the only consumer.

IT IS NOT A MIXTURE, and the difference is not cosmetic. A mixture says each JOB draws its service law afresh; a Prior says the MODEL has one law and we do not know which. The two give different queue lengths, and it is the second that epistemic uncertainty propagation means. The mixture moments are still exposed (prior_mean, prior_scv, prior_skewness, prior_cdf, prior_lst), because the reference's Prior inherits Distribution and answers those questions, and because refresh_rates will lower a Prior to SOME rate if a struct is dumped before SolverUQ has expanded it – but no solver ever reads them: Feature::Prior is declared by SolverUQ alone, so every other solver refuses the model at the gate.

DISCRETIZATION, which is where the two forms meet. prior_discretize reduces either form to (dists, weights): quadrature the discrete form UNCHANGED (it is already exact, and n is ignored); the continuous form at the conditional medians of n equal-mass strata, weights 1/n. The nodes are quantiles, so the rule integrates the parameter density in PROBABILITY space and needs only dist_cdf, which every family has. montecarlo n draws, weights 1/n. For a discrete prior the draw is of the alternative INDEX against its probabilities – returning the alternatives unweighted here would silently drop the prior.

WHERE THE RANDOMNESS COMES FROM, and how it differs from the reference. MATLAB draws with rand and, for the continuous form, with paramDist.sample(n), i.e. each family's own sampler. This port has no per-family sampler at all – Distrib carries none, and SSA generates its clocks internally – so the Monte Carlo design draws a uniform from an explicit MT19937 stream and inverts the CDF. The design points are therefore NOT the reference's for the same seed, exactly as the SSA sample paths are not; the design's LAW is the same, and a quadrature design is identical across the two codebases because it draws nothing.

Definition in file prior.h.