public abstract class AbstractDiscreteDistribution extends Object implements DiscreteDistribution
AbstractDiscreteDistribution provides a default
abstract implementation of discrete distributions. Concrete
subclasses need only implement the probability(long)
method, which returns the probability for each outcome.
The method minOutcome() and maxOutcome() bound
the range of non-zero probabilities. They default to Long.MIN_VALUE and Long.MAX_VALUE respectively. Concrete
subclasses should implement the tightest possible bounds for these
methods, because cumulative probabilities, means, variances and
entropies are implemented by looping between the minimum and
maximum values and evaluating the probability at each point.
| Constructor and Description |
|---|
AbstractDiscreteDistribution()
Construct an abstract discrete distribution.
|
| Modifier and Type | Method and Description |
|---|---|
double |
cumulativeProbability(long lowerBound,
long upperBound)
Returns the cumulative probability of all outcomes between the
specified bounds, inclusive.
|
double |
cumulativeProbabilityGreater(long lowerBound)
Returns the cumulative probability of all outcomes greater than
or equal to the specified lower bound.
|
double |
cumulativeProbabilityLess(long upperBound)
Returns the cumulative probability of all outcomes less
than or equal to the specified upper bound.
|
double |
entropy()
Returns the entropy of this distribution in bits (log 2).
|
double |
log2Probability(long outcome)
Returns the log (base 2) probability of the specified outcome.
|
long |
maxOutcome()
Returns the maximum outcome with non-zero probability for this
distribution.
|
double |
mean()
Returns the mean of this distribution.
|
long |
minOutcome()
Returns the minimum outcome with non-zero probability for this
distribution.
|
abstract double |
probability(long outcome)
Returns the probability of the specified outcome in this
distribution.
|
double |
variance()
Returns the variance of this distribution.
|
public AbstractDiscreteDistribution()
public abstract double probability(long outcome)
probability in interface DiscreteDistributionoutcome - Outcome whose probability is returned.public double cumulativeProbabilityLess(long upperBound)
cumulativeProbabilityLess in interface DiscreteDistributionupperBound - Upper bound of outcome.public double cumulativeProbabilityGreater(long lowerBound)
cumulativeProbabilityGreater in interface DiscreteDistributionlowerBound - Lower bound on outcomes.public double cumulativeProbability(long lowerBound,
long upperBound)
cumulativeProbability in interface DiscreteDistributionlowerBound - Lower bound of outcome set.upperBound - Upper bound of outcome set.public double log2Probability(long outcome)
log2Probability in interface DiscreteDistributionoutcome - Outcome whose log probability is returned.public long minOutcome()
Long.MIN_VALUE. If possible, concrete subclasses should
override this method with a tighter bound.minOutcome in interface DiscreteDistributionpublic long maxOutcome()
Long.MAX_VALUE. If possible, concrete subclasses should
override this method with a tighter bound.maxOutcome in interface DiscreteDistributionpublic double mean()
mean in interface DiscreteDistributionpublic double variance()
variance in interface DiscreteDistributionpublic double entropy()
H(P) = - Σx
P(x) * log2 P(x)
This method is implemented by iterating over the outcomes
between the minimum and maximum and summing their negative
probability weighted log probabilities.entropy in interface DiscreteDistributionCopyright © 2019 Alias-i, Inc.. All rights reserved.