Package jline.lang.processes
Class Prior
java.lang.Object
jline.lang.processes.Distribution
jline.lang.processes.Prior
- All Implemented Interfaces:
Serializable,Copyable
Prior distribution representing parameter uncertainty over alternative distributions.
Prior represents parameter uncertainty by specifying a discrete set of
alternative distributions with associated probabilities. When used with
setService or setArrival, it causes the UQ solver to expand the
model into a family of networks, one for each alternative.
This is NOT a mixture distribution - each alternative represents a
separate model realization with its associated prior probability.
A Prior also has a CONTINUOUS form,
new Prior(paramDist, distFactory): a
density over a scalar parameter theta plus a factory theta -> Distribution.
It has no alternatives until discretize(int, java.lang.String, java.util.Random) reduces it, which UQ does.
Example usage:
List<Distribution> dists = Arrays.asList(new Exp(1.0), new Exp(2.0), new Erlang(1.5, 2));
double[] probs = {0.4, 0.35, 0.25};
Prior prior = new Prior(dists, probs);
queue.setService(jobclass, prior);
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA prior reduced to weighted alternatives, i.e. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected SerializableFunction<Double,Distribution> Factory theta -> Distribution (continuous form), else nullprotected List<Distribution>Cell array of alternative distributionsprotected DistributionDistribution over the scalar parameter (continuous form), else nullprotected double[]Vector of prior probabilities (must sum to 1) -
Constructor Summary
ConstructorsConstructorDescriptionPrior(List<Distribution> distributions, double[] probabilities) Creates a Prior distribution with specified alternatives and probabilities.Prior(Distribution[] distributions, double[] probabilities) Convenience constructor for array-based input.Prior(Distribution paramDist, SerializableFunction<Double, Distribution> distFactory) Creates a Prior in its continuous form: a parameter density and the factory it feeds. -
Method Summary
Modifier and TypeMethodDescriptiondiscretize(int n, String method, Random random) Reduce the prior to n weighted alternatives.doubleevalCDF(double t) Evaluates the mixture CDF at t.doubleevalLST(double s) Evaluates the mixture Laplace-Stieltjes transform.static PriorfromSample(int k, double s) Continuous prior for a rate estimated from lifetime data, with an Exp factory.static PriorfromSample(int k, double s, SerializableFunction<Double, Distribution> distFactory) Continuous prior for a rate estimated from lifetime data.getAlternative(int idx) Returns the distribution at the specified index.Returns the list of all distributions.doublegetMean()Gets the prior-weighted mean (expected mean over alternatives).intReturns the number of alternative distributions.double[]Returns the array of all probabilities.doublegetProbability(int idx) Returns the probability of the alternative at the specified index.doublegetSCV()Gets the prior-weighted SCV using law of total variance.doubleGets the prior-weighted skewness.booleanReturns true if the prior is specified by a parameter density.booleanisPrior()Returns true indicating this is a Prior distribution.static booleanStatic method to check if a distribution is a Prior.static doublequantile(Distribution dist, double p) Numerical inverse CDF by bisection, using only evalCDF.double[]Generates random samples from the Prior (mixture sampling).Methods inherited from class jline.lang.processes.Distribution
evalLST, evalProbInterval, getFeatureName, getName, getNumParams, getNumParams, getParam, getParam, getParams, getRate, getSupport, getVar, hasParam, isContinuous, isDisabled, isDiscrete, isImmediate, isMarkovian, mean, name, numParams, param, rate, sample, scv, setNumParams, setParam, skewness, support, var, withDefect, withMassAtOrigin
-
Field Details
-
distributions
Cell array of alternative distributions -
probabilities
protected double[] probabilitiesVector of prior probabilities (must sum to 1) -
paramDist
Distribution over the scalar parameter (continuous form), else null -
distFactory
Factory theta -> Distribution (continuous form), else null
-
-
Constructor Details
-
Prior
Creates a Prior distribution with specified alternatives and probabilities.- Parameters:
distributions- list of alternative Distribution objectsprobabilities- array of probabilities (must sum to 1 and be non-negative)- Throws:
RuntimeException- if validation fails
-
Prior
Creates a Prior in its continuous form: a parameter density and the factory it feeds.- Parameters:
paramDist- distribution of the scalar parameter thetadistFactory- function mapping theta to the Distribution it parameterizes; it must be serializable because UQ copies the model
-
Prior
Convenience constructor for array-based input.- Parameters:
distributions- array of alternative Distribution objectsprobabilities- array of probabilities
-
-
Method Details
-
fromSample
Continuous prior for a rate estimated from lifetime data, with an Exp factory.- Parameters:
k- number of observations (positive integer)s- sum of the observed lifetimes (positive)- Returns:
- the continuous prior
-
fromSample
public static Prior fromSample(int k, double s, SerializableFunction<Double, Distribution> distFactory) Continuous prior for a rate estimated from lifetime data. Given k i.i.d. observations of an exponential random variable summing to s, the Jeffreys improper prior f(lambda) = s/lambda yields the posterior density f(lambda|s) = lambda^(k-1) s^k exp(-lambda s) / (k-1)!, an Erlang density with k phases and phase rate s (Trivedi and Bobbio, 2017, Eq. 3.71).- Parameters:
k- number of observations (positive integer)s- sum of the observed lifetimes (positive)distFactory- factory theta -> Distribution- Returns:
- the continuous prior
-
quantile
Numerical inverse CDF by bisection, using only evalCDF.- Parameters:
dist- distributionp- probability level in (0,1)- Returns:
- x with F(x) = p
-
isContinuousPrior
public boolean isContinuousPrior()Returns true if the prior is specified by a parameter density. Note that the base class isContinuous() refers to the support of the distribution itself.- Returns:
- true for the continuous form
-
getParamDist
- Returns:
- the parameter law of a continuous prior, null for a discrete one
-
getDistFactory
- Returns:
- the factory of a continuous prior, null for a discrete one
-
getNumAlternatives
public int getNumAlternatives()Returns the number of alternative distributions.- Returns:
- number of alternatives
-
getAlternative
Returns the distribution at the specified index.- Parameters:
idx- 0-based index- Returns:
- the distribution at index idx
- Throws:
IndexOutOfBoundsException- if idx is out of bounds
-
getProbability
public double getProbability(int idx) Returns the probability of the alternative at the specified index.- Parameters:
idx- 0-based index- Returns:
- the probability at index idx
- Throws:
IndexOutOfBoundsException- if idx is out of bounds
-
getProbabilities
public double[] getProbabilities()Returns the array of all probabilities.- Returns:
- copy of probability array
-
getDistributions
Returns the list of all distributions.- Returns:
- list of distributions (unmodifiable view recommended)
-
getMean
public double getMean()Gets the prior-weighted mean (expected mean over alternatives). E[X] = sum_i p_i * E[X_i]- Specified by:
getMeanin classDistribution- Returns:
- the weighted mean
-
getSCV
public double getSCV()Gets the prior-weighted SCV using law of total variance. Var(X) = E[Var(X|D)] + Var(E[X|D]) SCV = Var(X) / E[X]^2- Specified by:
getSCVin classDistribution- Returns:
- the weighted SCV
-
getSkewness
public double getSkewness()Gets the prior-weighted skewness. Uses mixture formula with moment calculations.- Specified by:
getSkewnessin classDistribution- Returns:
- the weighted skewness
-
sample
Generates random samples from the Prior (mixture sampling). Each sample is drawn from one of the alternatives selected according to the prior probabilities.- Specified by:
samplein classDistribution- Parameters:
n- number of samplesrandom- the random number generator- Returns:
- array of samples
-
evalCDF
public double evalCDF(double t) Evaluates the mixture CDF at t. F(t) = sum_i p_i * F_i(t)- Specified by:
evalCDFin classDistribution- Parameters:
t- the point at which to evaluate- Returns:
- the CDF value
-
evalLST
public double evalLST(double s) Evaluates the mixture Laplace-Stieltjes transform. L(s) = sum_i p_i * L_i(s)- Specified by:
evalLSTin classDistribution- Parameters:
s- the transform variable- Returns:
- the LST value
-
discretize
Reduce the prior to n weighted alternatives.The method is honoured, which is what makes SolverUQ's own 'quad'/'mc' methods mean anything:
quad-- for a discrete prior the alternatives and their probabilities unchanged, and n is ignored: a discrete set is already exact. For a continuous prior, the stratified quantile midpoints of the parameter law, weights 1/n; each node is the conditional median of an equal-mass stratum, so only evalCDF is needed.mc-- n i.i.d. draws, weights 1/n: of the ALTERNATIVE INDEX against its probabilities for a discrete prior (returning the alternatives unweighted here would silently drop the prior), of the parameter for a continuous one.
Mirrors
Prior.discretizein MATLAB, both branches.- Parameters:
n- number of alternatives (ignored by 'quad')method- 'quad' or 'mc'random- the stream the draws are taken from- Returns:
- the design points and their weights
-
isPrior
public boolean isPrior()Returns true indicating this is a Prior distribution. Used for detection by UQ solver.- Returns:
- true
-
isPriorDistribution
Static method to check if a distribution is a Prior.- Parameters:
dist- the distribution to check- Returns:
- true if dist is a Prior
-