public class BayesianUtil
extends java.lang.Object
Constructor and Description |
---|
BayesianUtil() |
Modifier and Type | Method and Description |
---|---|
static <ObservationType> |
deviance(ComputableDistribution<ObservationType> conditional,
java.lang.Iterable<? extends ObservationType> observations)
Computes the deviance of the model, which is
-2log(p(observations|parameter)).
|
static <ObservationType,ParameterType> |
expectedDeviance(BayesianParameter<ParameterType,? extends ComputableDistribution<ObservationType>,?> predictiveDistribution,
java.lang.Iterable<? extends ObservationType> observations,
java.util.Random random,
int numSamples)
Computes the expected deviance of the model by sampling parameters from
the posterior and then computing the deviance using the conditional
distribution.
|
static UnivariateGaussian |
getMean(java.util.Collection<? extends java.lang.Double> samples)
Computes the Monte Carlo distribution of the given samples.
|
static <ObservationType> |
logLikelihood(ComputableDistribution<? super ObservationType> distribution,
java.lang.Iterable<? extends ObservationType> observations)
Computes the log likelihood of the i.i.d.
|
static <ObservationType,ParameterType> |
sample(BayesianParameter<ParameterType,? extends Distribution<ObservationType>,? extends Distribution<ParameterType>> parameter,
java.util.Random random,
int numSamples)
Samples from the given BayesianParameter by first sampling the prior
distribution, then updating the conditional distribution, then sampling
from the updated conditional distribution.
|
static <ObservationType,ParameterType> |
sample(ClosedFormDistribution<ObservationType> conditional,
java.lang.String parameterName,
Distribution<ParameterType> prior,
java.util.Random random,
int numSamples)
Samples from the given BayesianParameter by first sampling the prior
distribution, then updating the conditional distribution, then sampling
from the updated conditional distribution.
|
public static <ObservationType> double logLikelihood(ComputableDistribution<? super ObservationType> distribution, java.lang.Iterable<? extends ObservationType> observations)
ObservationType
- Type of observations to considerdistribution
- Computable distribution from which to get the probability function
(a pdf or pmf) used to compute the likelihood.observations
- Observations to compute the log likelihood of.public static <ObservationType,ParameterType> java.util.ArrayList<? extends ObservationType> sample(ClosedFormDistribution<ObservationType> conditional, java.lang.String parameterName, Distribution<ParameterType> prior, java.util.Random random, int numSamples)
ObservationType
- Type of observations generated by the conditional distributionParameterType
- Type of parameters generated by the prior distribution, used to
update the conditional distributionconditional
- Conditional distribution that generates observationsparameterName
- Name of the parameter in the conditional distribution that is
generated according to the prior distributionprior
- Prior distribution of parameter valuesrandom
- Random number generatornumSamples
- Number of samples to generatepublic static <ObservationType,ParameterType> java.util.ArrayList<ObservationType> sample(BayesianParameter<ParameterType,? extends Distribution<ObservationType>,? extends Distribution<ParameterType>> parameter, java.util.Random random, int numSamples)
ObservationType
- Type of observations generated by the conditional distributionParameterType
- Type of parameters generated by the prior distribution, used to
update the conditional distributionparameter
- BayesianParameter that links the conditional distribution via a
parameter to a prior distribution.random
- Random number generatornumSamples
- Number of samples to generate@PublicationReference(author={"Andrew Gelman","John B. Carlin","Hal S. Stern","Donald B. Rubin"}, title="Bayesian Data Analysis, Second Edition", type=Book, year=2004, pages={180,181}, notes="Equation 6.6") public static <ObservationType> double deviance(ComputableDistribution<ObservationType> conditional, java.lang.Iterable<? extends ObservationType> observations)
ObservationType
- conditional
- Conditional distribution that generates observations.observations
- Observations to consider@PublicationReference(author={"Andrew Gelman","John B. Carlin","Hal S. Stern","Donald B. Rubin"}, title="Bayesian Data Analysis, Second Edition", type=Book, year=2004, pages={180,181}, notes="Equation 6.9") public static <ObservationType,ParameterType> UnivariateGaussian expectedDeviance(BayesianParameter<ParameterType,? extends ComputableDistribution<ObservationType>,?> predictiveDistribution, java.lang.Iterable<? extends ObservationType> observations, java.util.Random random, int numSamples)
ObservationType
- Type of observations generated by the conditional distribution.ParameterType
- Type of parameters generated by the posterior distribution.predictiveDistribution
- Relationship between the posterior (parameters) and the conditional
(observations).observations
- Observations to consider when computing the deviancerandom
- Random number generatornumSamples
- Number of samples to use in the expectation.public static UnivariateGaussian getMean(java.util.Collection<? extends java.lang.Double> samples)
samples
- Samples to consider.