Class Prior

All Implemented Interfaces:
Serializable, Copyable

public class Prior extends Distribution implements Serializable
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:
  • Field Details

    • distributions

      protected List<Distribution> distributions
      Cell array of alternative distributions
    • probabilities

      protected double[] probabilities
      Vector of prior probabilities (must sum to 1)
    • paramDist

      protected Distribution paramDist
      Distribution over the scalar parameter (continuous form), else null
    • distFactory

      protected SerializableFunction<Double,Distribution> distFactory
      Factory theta -> Distribution (continuous form), else null
  • Constructor Details

    • Prior

      public Prior(List<Distribution> distributions, double[] probabilities)
      Creates a Prior distribution with specified alternatives and probabilities.
      Parameters:
      distributions - list of alternative Distribution objects
      probabilities - array of probabilities (must sum to 1 and be non-negative)
      Throws:
      RuntimeException - if validation fails
    • Prior

      public Prior(Distribution paramDist, SerializableFunction<Double,Distribution> distFactory)
      Creates a Prior in its continuous form: a parameter density and the factory it feeds.
      Parameters:
      paramDist - distribution of the scalar parameter theta
      distFactory - function mapping theta to the Distribution it parameterizes; it must be serializable because UQ copies the model
    • Prior

      public Prior(Distribution[] distributions, double[] probabilities)
      Convenience constructor for array-based input.
      Parameters:
      distributions - array of alternative Distribution objects
      probabilities - array of probabilities
  • Method Details

    • fromSample

      public static Prior fromSample(int k, double s)
      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

      public static double quantile(Distribution dist, double p)
      Numerical inverse CDF by bisection, using only evalCDF.
      Parameters:
      dist - distribution
      p - 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

      public Distribution getParamDist()
      Returns:
      the parameter law of a continuous prior, null for a discrete one
    • getDistFactory

      public SerializableFunction<Double,Distribution> 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

      public Distribution getAlternative(int idx)
      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

      public List<Distribution> 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:
      getMean in class Distribution
      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:
      getSCV in class Distribution
      Returns:
      the weighted SCV
    • getSkewness

      public double getSkewness()
      Gets the prior-weighted skewness. Uses mixture formula with moment calculations.
      Specified by:
      getSkewness in class Distribution
      Returns:
      the weighted skewness
    • sample

      public double[] sample(int n, Random random)
      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:
      sample in class Distribution
      Parameters:
      n - number of samples
      random - 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:
      evalCDF in class Distribution
      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:
      evalLST in class Distribution
      Parameters:
      s - the transform variable
      Returns:
      the LST value
    • discretize

      public Prior.Design discretize(int n, String method, Random random)
      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.discretize in 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

      public static boolean isPriorDistribution(Distribution dist)
      Static method to check if a distribution is a Prior.
      Parameters:
      dist - the distribution to check
      Returns:
      true if dist is a Prior