package umontreal.iro.lecuyer.probdistmulti;
/**
* Classes implementing multi-dimensional discrete distributions over the integers
* should inherit from this class.
* It specifies the signature of methods for computing the mass function
* (or probability)
* p(x1, x2,…, xd) = P[X1 = x1, X2 = x2,…, Xd = xd] and the cumulative probabilities
* for a random vector X with a discrete distribution over the integers.
*
*/
public abstract class DiscreteDistributionIntMulti {
protected int dimension;
/**
* Returns the probability mass function
* p(x1, x2,…, xd),
* which should be a real number in [0, 1].
*
* @param x value at which the mass function must be evaluated
*
* @return the mass function evaluated at x
*
*/
public abstract double prob (int[] x);
/**
* Computes the cumulative probability function F of the distribution evaluated
* at x, assuming the lowest values start at 0, i.e. computes
*
*
*
* F(x1, x2,…, xd) = ∑s1=0x1∑s2=0x2 ... ∑sd=0xdp(s1, s2,…, sd).
*
* Uses the naive implementation, is very inefficient and may underflows.
*
*/
public double cdf (int x[]) {
int is[] = new int[x.length];
for (int i = 0; i < is.length; i++)
is[i] = 0;
boolean end = false;
double sum = 0.0;
int j;
while (!end) {
sum += prob (is);
is[0]++;
if (is[0] > x[0]) {
is[0] = 0;
j = 1;
while (j < x.length && is[j] == x[j])
is[j++] = 0;
if (j == x.length)
end = true;
else
is[j]++;
}
}
return sum;
}
/**
* Returns the dimension d of the distribution.
*
*/
public int getDimension() {
return dimension;
}
/**
* Returns the mean vector of the distribution, defined as
* μi = E[Xi].
*
*/
public abstract double[] getMean();
/**
* Returns the variance-covariance matrix of the distribution, defined as
*
* σij = E[(Xi - μi)(Xj - μj)].
*
*/
public abstract double[][] getCovariance();
/**
* Returns the correlation matrix of the distribution, defined as
*
* ρij = σij/(σ_iiσ_jj)1/2.
*
*/
public abstract double[][] getCorrelation();
}
Ads help maintain this website.