25package umontreal.ssj.randvarmulti;
27import umontreal.ssj.probdist.GammaDist;
28import umontreal.ssj.randvar.RandomVariateGen;
29import umontreal.ssj.randvar.GammaAcceptanceRejectionGen;
30import umontreal.ssj.rng.RandomStream;
59 private double[] alphas;
62 private static final double ALPHA_THRESHOLD = 0.1;
66 private boolean useLogGamma =
false;
80 throw new NullPointerException(
"stream is null");
82 dimension = alphas.length;
84 for (
int k = 0; k < alphas.length; k++)
87 this.alphas =
new double[alphas.length];
88 System.arraycopy(alphas, 0, this.alphas, 0, alphas.length);
89 useLogGamma = canUseLogGamma(alphas);
116 if (canUseLogGamma(alphas)) {
117 nextPointUsingLog(stream, alphas, p);
122 for (
int i = 0; i < alphas.length; i++) {
126 for (
int i = 0; i < alphas.length; i++)
137 nextPointUsingLog(stream, alphas, p);
141 int n = ggens.length;
143 for (
int i = 0; i < n; i++) {
144 p[i] = ggens[i].nextDouble();
147 for (
int i = 0; i < n; i++)
155 private static void nextPointUsingLog(
RandomStream stream,
double[] alphas,
double[] p) {
157 double[] log =
new double[p.length];
160 for (
int i = 0; i < alphas.length; i++) {
165 for (
int i = 0; i < alphas.length; i++) {
167 for (
int j = 0; j < alphas.length; j++)
168 total += Math.exp(log[j] - log[i]);
177 private static boolean canUseLogGamma(
double[] alphas) {
178 for (
int i = 0; i < alphas.length; i++)
179 if (alphas[i] >= ALPHA_THRESHOLD)
Extends the class ContinuousDistribution for the gamma distribution tjoh95a (page 337) with shape pa...
This class implements gamma random variate generators using a method that combines acceptance-rejecti...
double nextDoubleLog()
Returns the natural log value of a new gamma variate.
static double nextDouble(RandomStream s, RandomStream aux, double alpha, double lambda)
Generates a new gamma variate with parameters  alpha and  lambda, using main stream s and auxilia...
void nextPoint(double[] p)
Generates a point from the Dirichlet distribution.
static void nextPoint(RandomStream stream, double[] alphas, double[] p)
Generates a new point from the Dirichlet distribution with parameters alphas, using the stream stream...
double getAlpha(int i)
Returns the parameter for this Dirichlet generator.
DirichletGen(RandomStream stream, double[] alphas)
Constructs a new Dirichlet generator with parameters  alphas[i], for , and the stream stream.
This class is the multivariate counterpart of.
This interface defines the basic structures to handle multiple streams of uniform (pseudo)random numb...