commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject svn commit: r1053032 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/distribution/ test/java/org/apache/commons/math/distribution/
Date Mon, 27 Dec 2010 09:51:58 GMT
Author: mikl
Date: Mon Dec 27 09:51:56 2010
New Revision: 1053032

URL: http://svn.apache.org/viewvc?rev=1053032&view=rev
Log:
Fixes MATH-385

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractContinuousDistribution.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractDistribution.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractIntegerDistribution.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BetaDistributionImpl.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BinomialDistributionImpl.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/CauchyDistributionImpl.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ChiSquaredDistributionImpl.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/Distribution.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ExponentialDistributionImpl.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/FDistributionImpl.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/GammaDistributionImpl.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/HypergeometricDistributionImpl.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/NormalDistributionImpl.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/PascalDistributionImpl.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/PoissonDistributionImpl.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/TDistributionImpl.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/WeibullDistributionImpl.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ZipfDistributionImpl.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/BetaDistributionTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/BinomialDistributionTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/CauchyDistributionTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/ChiSquareDistributionTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/ExponentialDistributionTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/FDistributionTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/GammaDistributionTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/HypergeometricDistributionTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/NormalDistributionTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/PascalDistributionTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/PoissonDistributionTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/TDistributionTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/WeibullDistributionTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/ZipfDistributionTest.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractContinuousDistribution.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractContinuousDistribution.java?rev=1053032&r1=1053031&r2=1053032&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractContinuousDistribution.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractContinuousDistribution.java Mon Dec 27 09:51:56 2010
@@ -219,4 +219,18 @@ public abstract class AbstractContinuous
     protected double getSolverAbsoluteAccuracy() {
         return solverAbsoluteAccuracy;
     }
+
+    /**
+     * Access the lower bound of the support.
+     *
+     * @return lower bound of the support (might be Double.NEGATIVE_INFINITY)
+     */
+    public abstract double getSupportLowerBound();
+    
+    /**
+     * Access the upper bound of the support.
+     *
+     * @return upper bound of the support (might be Double.POSITIVE_INFINITY)
+     */
+    public abstract double getSupportUpperBound();
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractDistribution.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractDistribution.java?rev=1053032&r1=1053031&r2=1053032&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractDistribution.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractDistribution.java Mon Dec 27 09:51:56 2010
@@ -33,6 +33,12 @@ public abstract class AbstractDistributi
     /** Serializable version identifier */
     private static final long serialVersionUID = -38038050983108802L;
 
+    private double numericalMean = Double.NaN;
+    private boolean numericalMeanIsCalculated = false;
+    
+    private double numericalVariance = Double.NaN;
+    private boolean numericalVarianceIsCalculated = false;
+    
     /**
      * Default constructor.
      */
@@ -65,4 +71,93 @@ public abstract class AbstractDistributi
         }
         return cumulativeProbability(x1) - cumulativeProbability(x0);
     }
+    
+    /**
+     * Use this method to actually calculate the mean for the 
+     * specific distribution. Use {@link #getNumericalMean()} 
+     * (which implements caching) to actually get the mean.
+     * 
+     * @return the mean or Double.NaN if it's not defined
+     */
+    protected abstract double calculateNumericalMean();
+    
+    /**
+     * Use this method to get the numerical value of the mean of this 
+     * distribution.
+     *
+     * @return the mean or Double.NaN if it's not defined
+     */
+    public double getNumericalMean() {
+        if (!numericalMeanIsCalculated) {
+            numericalMean = calculateNumericalMean();
+            numericalMeanIsCalculated = true;
+        }
+
+        return numericalMean;
+    }
+    
+    /**
+     * Use this method to actually calculate the variance for the 
+     * specific distribution.  Use {@link #getNumericalVariance()} 
+     * (which implements caching) to actually get the variance. 
+     *
+     * @return the variance or Double.NaN if it's not defined
+     */
+    protected abstract double calculateNumericalVariance();
+    
+    /**
+     * Use this method to get the numerical value of the variance of this 
+     * distribution.
+     *
+     * @return the variance (possibly Double.POSITIVE_INFINITY as 
+     * for certain cases in {@link TDistributionImpl}) or 
+     * Double.NaN if it's not defined
+     */
+    public double getNumericalVariance() {
+        if (!numericalVarianceIsCalculated) {
+            numericalVariance = calculateNumericalVariance();
+            numericalVarianceIsCalculated = true;
+        }
+        
+        return numericalVariance;
+    }    
+    
+    /**
+     * Use this method to get information about whether the lower bound 
+     * of the support is inclusive or not.
+     *
+     * @return whether the lower bound of the support is inclusive or not
+     */
+    public abstract boolean isSupportLowerBoundInclusive();
+    
+    /**
+     * Use this method to get information about whether the upper bound 
+     * of the support is inclusive or not.
+     *
+     * @return whether the upper bound of the support is inclusive or not
+     */
+    public abstract boolean isSupportUpperBoundInclusive();    
+    
+    /**
+     * Use this method to get information about whether the support is connected, 
+     * i.e. whether all values between the lower and upper bound of the support
+     * is included in the support.
+     * 
+     * For {@link AbstractIntegerDistribution} the support is discrete, so
+     * if this is true, then the support is 
+     * {lower bound, lower bound + 1, ..., upper bound}.
+     * 
+     * For {@link AbstractContinuousDistribution} the support is continuous, so
+     * if this is true, then the support is the interval
+     * [lower bound, upper bound]
+     * where the limits are inclusive or not according to 
+     * {@link #isSupportLowerBoundInclusive()} and {@link #isSupportUpperBoundInclusive()} 
+     * (in the example both are true). If both are false, then the support is the interval
+     * (lower bound, upper bound)
+     *
+     * @return whether the support limits given by subclassed methods are connected or not
+     */
+    public boolean isSupportConnected() {
+        return true;
+    }
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractIntegerDistribution.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractIntegerDistribution.java?rev=1053032&r1=1053031&r2=1053032&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractIntegerDistribution.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractIntegerDistribution.java Mon Dec 27 09:51:56 2010
@@ -289,4 +289,42 @@ public abstract class AbstractIntegerDis
      * @return the domain value upper bound, i.e. {@code P(X < 'upper bound') > p}.
      */
     protected abstract int getDomainUpperBound(double p);
+    
+    /**
+     * Access the lower bound of the support.
+     *
+     * @return lower bound of the support (Integer.MIN_VALUE for negative infinity)
+     */
+    public abstract int getSupportLowerBound();
+    
+    /**
+     * Access the upper bound of the support.
+     *
+     * @return upper bound of the support (Integer.MAX_VALUE for positive infinity)
+     */
+    public abstract int getSupportUpperBound();
+    
+    /**
+     * Use this method to get information about whether the lower bound 
+     * of the support is inclusive or not. For discrete support,
+     * only true here is meaningful.
+     *
+     * @return true (always but at Integer.MIN_VALUE because of the nature of discrete support) 
+     */
+    @Override
+    public boolean isSupportLowerBoundInclusive() {
+        return true;
+    }
+    
+    /**
+     * Use this method to get information about whether the upper bound 
+     * of the support is inclusive or not. For discrete support,
+     * only true here is meaningful.
+     *
+     * @return true (always but at Integer.MAX_VALUE because of the nature of discrete support) 
+     */
+    @Override
+    public boolean isSupportUpperBoundInclusive() {
+        return true;
+    }    
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BetaDistributionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BetaDistributionImpl.java?rev=1053032&r1=1053031&r2=1053032&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BetaDistributionImpl.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BetaDistributionImpl.java Mon Dec 27 09:51:56 2010
@@ -184,4 +184,71 @@ public class BetaDistributionImpl
     protected double getSolverAbsoluteAccuracy() {
         return solverAbsoluteAccuracy;
     }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * The lower bound of the support is always 0 no matter the parameters.
+     *
+     * @return lower bound of the support (always 0)
+     */
+    @Override
+    public double getSupportLowerBound() {
+        return 0;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * The upper bound of the support is always 1 no matter the parameters.
+     *
+     * @return upper bound of the support (always 1)
+     */
+    @Override
+    public double getSupportUpperBound() {
+        return 1;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * For first shape parameter <code>s1</code> and 
+     * second shape parameter <code>s2</code>, the mean is
+     * <code>s1 / (s1 + s2)</code>
+     *
+     * @return {@inheritDoc}
+     */
+    @Override
+    protected double calculateNumericalMean() {
+        final double alpha = getAlpha();
+        return alpha / (alpha + getBeta());
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * For first shape parameter <code>s1</code> and 
+     * second shape parameter <code>s2</code>, 
+     * the variance is
+     * <code>[ s1 * s2 ] / [ (s1 + s2)^2 * (s1 + s2 + 1) ]</code>
+     *
+     * @return {@inheritDoc}
+     */
+    @Override
+    protected double calculateNumericalVariance() {
+        final double alpha = getAlpha();
+        final double beta = getBeta();        
+        final double alphabetasum = alpha + beta;
+        return (alpha * beta) / ((alphabetasum * alphabetasum) * (alphabetasum + 1));
+    }
+
+    @Override
+    public boolean isSupportLowerBoundInclusive() {
+        return false;
+    }
+
+    @Override
+    public boolean isSupportUpperBoundInclusive() {
+        return false;
+    }
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BinomialDistributionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BinomialDistributionImpl.java?rev=1053032&r1=1053031&r2=1053032&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BinomialDistributionImpl.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BinomialDistributionImpl.java Mon Dec 27 09:51:56 2010
@@ -164,4 +164,58 @@ public class BinomialDistributionImpl ex
         // use default bisection impl
         return super.inverseCumulativeProbability(p);
     }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * The lower bound of the support is always 0 no matter the number of trials 
+     * and probability parameter.
+     *
+     * @return lower bound of the support (always 0)
+     */
+    @Override
+    public int getSupportLowerBound() {
+        return 0;
+    }
+    
+    /**
+     * {@inheritDoc}
+     * 
+     * The upper bound of the support is the number of trials.
+     *
+     * @return upper bound of the support (equal to number of trials)
+     */
+    @Override
+    public int getSupportUpperBound() {
+        return getNumberOfTrials();
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * For <code>n</code> number of trials and 
+     * probability parameter <code>p</code>, the mean is
+     * <code>n * p</code>
+     *
+     * @return {@inheritDoc}
+     */
+    @Override
+    protected double calculateNumericalMean() {
+        return (double)getNumberOfTrials() * getProbabilityOfSuccess();
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * For <code>n</code> number of trials and 
+     * probability parameter <code>p</code>, the variance is
+     * <code>n * p * (1 - p)</code>
+     *
+     * @return {@inheritDoc}
+     */
+    @Override
+    protected double calculateNumericalVariance() {
+        final double p = getProbabilityOfSuccess();
+        return (double)getNumberOfTrials() * p * (1 - p);
+    }
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/CauchyDistributionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/CauchyDistributionImpl.java?rev=1053032&r1=1053031&r2=1053032&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/CauchyDistributionImpl.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/CauchyDistributionImpl.java Mon Dec 27 09:51:56 2010
@@ -163,7 +163,7 @@ public class CauchyDistributionImpl exte
         }
 
         return ret;
-    }
+    }    
 
     /**
      * Access the domain value upper bound, based on <code>p</code>, used to
@@ -220,4 +220,64 @@ public class CauchyDistributionImpl exte
     protected double getSolverAbsoluteAccuracy() {
         return solverAbsoluteAccuracy;
     }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * The lower bound of the support is always negative infinity no matter 
+     * the parameters.
+     *
+     * @return lower bound of the support (always Double.NEGATIVE_INFINITY)
+     */
+    @Override
+    public double getSupportLowerBound() {
+        return Double.NEGATIVE_INFINITY;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * The upper bound of the support is always positive infinity no matter 
+     * the parameters.
+     *
+     * @return upper bound of the support (always Double.POSITIVE_INFINITY)
+     */
+    @Override
+    public double getSupportUpperBound() {
+        return Double.POSITIVE_INFINITY;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * The mean is always undefined no matter the parameters.
+     *
+     * @return mean (always Double.NaN)
+     */
+    @Override
+    protected double calculateNumericalMean() {
+        return Double.NaN;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * The variance is always undefined no matter the parameters.
+     *
+     * @return variance (always Double.NaN)
+     */
+    @Override
+    protected double calculateNumericalVariance() {
+        return Double.NaN;
+    }
+
+    @Override
+    public boolean isSupportLowerBoundInclusive() {
+        return false;
+    }
+
+    @Override
+    public boolean isSupportUpperBoundInclusive() {
+        return false;
+    }
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ChiSquaredDistributionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ChiSquaredDistributionImpl.java?rev=1053032&r1=1053031&r2=1053032&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ChiSquaredDistributionImpl.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ChiSquaredDistributionImpl.java Mon Dec 27 09:51:56 2010
@@ -193,4 +193,66 @@ public class ChiSquaredDistributionImpl
     protected double getSolverAbsoluteAccuracy() {
         return solverAbsoluteAccuracy;
     }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * The lower bound of the support is always 0 no matter the 
+     * degrees of freedom.
+     *
+     * @return lower bound of the support (always 0)
+     */
+    @Override
+    public double getSupportLowerBound() {
+        return 0;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * The upper bound of the support is always positive infinity no matter the 
+     * degrees of freedom.
+     *
+     * @return upper bound of the support (always Double.POSITIVE_INFINITY)
+     */
+    @Override
+    public double getSupportUpperBound() {
+        return Double.POSITIVE_INFINITY;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * For <code>k</code> degrees of freedom, the mean is
+     * <code>k</code>
+     *
+     * @return {@inheritDoc}
+     */
+    @Override
+    protected double calculateNumericalMean() {
+        return getDegreesOfFreedom();
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * For <code>k</code> degrees of freedom, the variance is
+     * <code>2 * k</code>
+     *
+     * @return {@inheritDoc}
+     */
+    @Override
+    protected double calculateNumericalVariance() {
+        return 2*getDegreesOfFreedom();
+    }
+
+    @Override
+    public boolean isSupportLowerBoundInclusive() {
+        return true;
+    }
+
+    @Override
+    public boolean isSupportUpperBoundInclusive() {
+        return false;
+    }
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/Distribution.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/Distribution.java?rev=1053032&r1=1053031&r2=1053032&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/Distribution.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/Distribution.java Mon Dec 27 09:51:56 2010
@@ -52,4 +52,59 @@ public interface Distribution {
      * @throws IllegalArgumentException if <code>x0 > x1</code>
      */
     double cumulativeProbability(double x0, double x1) throws MathException;
+    
+    /**
+     * Use this method to get the numerical value of the mean of this 
+     * distribution.
+     *
+     * @return the mean or Double.NaN if it's not defined
+     */
+    double getNumericalMean();
+    
+    /**
+     * Use this method to get the numerical value of the variance of this 
+     * distribution.
+     *
+     * @return the variance (possibly Double.POSITIVE_INFINITY as 
+     * for certain cases in {@link TDistributionImpl}) or 
+     * Double.NaN if it's not defined
+     */
+    double getNumericalVariance(); 
+    
+    /**
+     * Use this method to get information about whether the lower bound 
+     * of the support is inclusive or not.
+     *
+     * @return whether the lower bound of the support is inclusive or not
+     */
+    boolean isSupportLowerBoundInclusive();
+    
+    /**
+     * Use this method to get information about whether the upper bound 
+     * of the support is inclusive or not.
+     *
+     * @return whether the upper bound of the support is inclusive or not
+     */
+    boolean isSupportUpperBoundInclusive();    
+    
+    /**
+     * Use this method to get information about whether the support is connected, 
+     * i.e. whether all values between the lower and upper bound of the support
+     * is included in the support.
+     * 
+     * For {@link AbstractIntegerDistribution} the support is discrete, so
+     * if this is true, then the support is 
+     * {lower bound, lower bound + 1, ..., upper bound}.
+     * 
+     * For {@link AbstractContinuousDistribution} the support is continuous, so
+     * if this is true, then the support is the interval
+     * [lower bound, upper bound]
+     * where the limits are inclusive or not according to 
+     * {@link #isSupportLowerBoundInclusive()} and {@link #isSupportUpperBoundInclusive()} 
+     * (in the example both are true). If both are false, then the support is the interval
+     * (lower bound, upper bound)
+     *
+     * @return whether the support limits given by subclassed methods are connected or not
+     */
+    boolean isSupportConnected();
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ExponentialDistributionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ExponentialDistributionImpl.java?rev=1053032&r1=1053031&r2=1053032&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ExponentialDistributionImpl.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ExponentialDistributionImpl.java Mon Dec 27 09:51:56 2010
@@ -222,4 +222,66 @@ public class ExponentialDistributionImpl
     protected double getSolverAbsoluteAccuracy() {
         return solverAbsoluteAccuracy;
     }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * The lower bound of the support is always 0 no matter the mean parameter.
+     *
+     * @return lower bound of the support (always 0)
+     */
+    @Override
+    public double getSupportLowerBound() {
+        return 0;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * The upper bound of the support is always positive infinity 
+     * no matter the mean parameter.
+     *
+     * @return upper bound of the support (always Double.POSITIVE_INFINITY)
+     */
+    @Override
+    public double getSupportUpperBound() {
+        return Double.POSITIVE_INFINITY;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * For mean parameter <code>k</code>, the mean is
+     * <code>k</code>
+     *
+     * @return {@inheritDoc}
+     */
+    @Override
+    protected double calculateNumericalMean() {
+        return getMean();
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * For mean parameter <code>k</code>, the variance is
+     * <code>k^2</code>
+     *
+     * @return {@inheritDoc}
+     */
+    @Override
+    protected double calculateNumericalVariance() {
+        final double mean = getMean();
+        return mean * mean;
+    }
+
+    @Override
+    public boolean isSupportLowerBoundInclusive() {
+        return true;
+    }
+
+    @Override
+    public boolean isSupportUpperBoundInclusive() {
+        return false;
+    }
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/FDistributionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/FDistributionImpl.java?rev=1053032&r1=1053031&r2=1053032&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/FDistributionImpl.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/FDistributionImpl.java Mon Dec 27 09:51:56 2010
@@ -235,4 +235,93 @@ public class FDistributionImpl
     protected double getSolverAbsoluteAccuracy() {
         return solverAbsoluteAccuracy;
     }
+    
+    /**
+     * {@inheritDoc}
+     * 
+     * The lower bound of the support is always 0 no matter the parameters.
+     *
+     * @return lower bound of the support (always 0)
+     */
+    @Override
+    public double getSupportLowerBound() {
+        return 0;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * The upper bound of the support is always positive infinity 
+     * no matter the parameters.
+     *
+     * @return upper bound of the support (always Double.POSITIVE_INFINITY)
+     */
+    @Override
+    public double getSupportUpperBound() {
+        return Double.POSITIVE_INFINITY;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * For denominator degrees of freedom parameter <code>b</code>, 
+     * the mean is
+     * <ul>
+     *  <li>if <code>b &gt; 2</code> then <code>b / (b - 2)</code></li>
+     *  <li>else <code>undefined</code>
+     * </ul>
+     *
+     * @return {@inheritDoc}
+     */    
+    @Override
+    protected double calculateNumericalMean() {        
+        final double denominatorDF = getDenominatorDegreesOfFreedom();
+
+        if (denominatorDF > 2) {
+            return denominatorDF / (denominatorDF - 2);     
+        }
+        
+        return Double.NaN;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * For numerator degrees of freedom parameter <code>a</code> 
+     * and denominator degrees of freedom parameter <code>b</code>, 
+     * the variance is
+     * <ul>
+     *  <li>
+     *    if <code>b &gt; 4</code> then 
+     *    <code>[ 2 * b^2 * (a + b - 2) ] / [ a * (b - 2)^2 * (b - 4) ]</code>
+     *  </li>
+     *  <li>else <code>undefined</code>
+     * </ul>
+     *
+     * @return {@inheritDoc}
+     */
+    @Override
+    protected double calculateNumericalVariance() {
+        final double denominatorDF = getDenominatorDegreesOfFreedom();
+
+        if (denominatorDF > 4) {
+            final double numeratorDF = getNumeratorDegreesOfFreedom();
+            final double denomDFMinusTwo = denominatorDF - 2;
+            
+            return ( 2 * (denominatorDF * denominatorDF) * (numeratorDF + denominatorDF - 2) )
+                   / ( (numeratorDF * (denomDFMinusTwo * denomDFMinusTwo) * (denominatorDF - 4)) );
+        }
+        
+        return Double.NaN;        
+    }
+
+    @Override
+    public boolean isSupportLowerBoundInclusive() {
+        return true;
+    }
+
+    @Override
+    public boolean isSupportUpperBoundInclusive() {
+        return false;
+    }
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/GammaDistributionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/GammaDistributionImpl.java?rev=1053032&r1=1053031&r2=1053032&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/GammaDistributionImpl.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/GammaDistributionImpl.java Mon Dec 27 09:51:56 2010
@@ -237,4 +237,68 @@ public class GammaDistributionImpl exten
     protected double getSolverAbsoluteAccuracy() {
         return solverAbsoluteAccuracy;
     }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * The lower bound of the support is always 0 no matter the parameters.
+     *
+     * @return lower bound of the support (always 0)
+     */
+    @Override
+    public double getSupportLowerBound() {
+        return 0;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * The upper bound of the support is always positive infinity 
+     * no matter the parameters.
+     *
+     * @return upper bound of the support (always Double.POSITIVE_INFINITY)
+     */
+    @Override
+    public double getSupportUpperBound() {
+        return Double.POSITIVE_INFINITY;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * For shape parameter <code>alpha</code> and scale 
+     * parameter <code>beta</code>, the mean is
+     * <code>alpha * beta</code>
+     *
+     * @return {@inheritDoc}
+     */
+    @Override
+    protected double calculateNumericalMean() {
+        return getAlpha() * getBeta();
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * For shape parameter <code>alpha</code> and scale 
+     * parameter <code>beta</code>, the variance is
+     * <code>alpha * beta^2</code>
+     *
+     * @return {@inheritDoc}
+     */
+    @Override
+    protected double calculateNumericalVariance() {
+        final double beta = getBeta();        
+        return getAlpha() * beta * beta;
+    }
+
+    @Override
+    public boolean isSupportLowerBoundInclusive() {
+        return true;
+    }
+
+    @Override
+    public boolean isSupportUpperBoundInclusive() {
+        return false;
+    }
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/HypergeometricDistributionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/HypergeometricDistributionImpl.java?rev=1053032&r1=1053031&r2=1053032&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/HypergeometricDistributionImpl.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/HypergeometricDistributionImpl.java Mon Dec 27 09:51:56 2010
@@ -284,4 +284,69 @@ public class HypergeometricDistributionI
         }
         return ret;
     }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * For population size <code>N</code>, 
+     * number of successes <code>m</code>, and 
+     * sample size <code>n</code>, 
+     * the lower bound of the support is
+     * <code>max(0, n + m - N)</code>
+     *
+     * @return lower bound of the support
+     */
+    @Override
+    public int getSupportLowerBound() {
+        return FastMath.max(0, 
+                getSampleSize() + getNumberOfSuccesses() - getPopulationSize());
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * For number of successes <code>m</code> and 
+     * sample size <code>n</code>, 
+     * the upper bound of the support is
+     * <code>min(m, n)</code>
+     *
+     * @return upper bound of the support
+     */
+    @Override
+    public int getSupportUpperBound() {
+        return FastMath.min(getNumberOfSuccesses(), getSampleSize());
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * For population size <code>N</code>, 
+     * number of successes <code>m</code>, and 
+     * sample size <code>n</code>, the mean is
+     * <code>n * m / N</code>
+     *
+     * @return {@inheritDoc}
+     */
+    @Override
+    protected double calculateNumericalMean() {
+        return (double)(getSampleSize() * getNumberOfSuccesses()) / (double)getPopulationSize();
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * For population size <code>N</code>, 
+     * number of successes <code>m</code>, and 
+     * sample size <code>n</code>, the variance is
+     * <code>[ n * m * (N - n) * (N - m) ] / [ N^2 * (N - 1) ]</code>
+     *
+     * @return {@inheritDoc}
+     */
+    @Override
+    protected double calculateNumericalVariance() {
+        final double N = getPopulationSize();
+        final double m = getNumberOfSuccesses();
+        final double n = getSampleSize();
+        return ( n * m * (N - n) * (N - m) ) / ( (N*N * (N - 1)) );
+    }
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/NormalDistributionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/NormalDistributionImpl.java?rev=1053032&r1=1053031&r2=1053032&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/NormalDistributionImpl.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/NormalDistributionImpl.java Mon Dec 27 09:51:56 2010
@@ -241,4 +241,66 @@ public class NormalDistributionImpl exte
 
         return ret;
     }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * The lower bound of the support is always negative infinity 
+     * no matter the parameters.
+     *
+     * @return lower bound of the support (always Double.NEGATIVE_INFINITY)
+     */
+    @Override
+    public double getSupportLowerBound() {
+        return Double.NEGATIVE_INFINITY;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * The upper bound of the support is always positive infinity 
+     * no matter the parameters.
+     *
+     * @return upper bound of the support (always Double.POSITIVE_INFINITY)
+     */
+    @Override
+    public double getSupportUpperBound() {
+        return Double.POSITIVE_INFINITY;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * For mean parameter <code>mu</code>, the mean is <code>mu</code>
+     *
+     * @return {@inheritDoc}
+     */
+    @Override
+    protected double calculateNumericalMean() {
+        return getMean();
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * For standard deviation parameter <code>s</code>, 
+     * the variance is <code>s^2</code>
+     *
+     * @return {@inheritDoc}
+     */
+    @Override
+    protected double calculateNumericalVariance() {
+        final double s = getStandardDeviation();
+        return s * s;
+    }
+
+    @Override
+    public boolean isSupportLowerBoundInclusive() {
+        return false;
+    }
+
+    @Override
+    public boolean isSupportUpperBoundInclusive() {
+        return false;
+    }
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/PascalDistributionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/PascalDistributionImpl.java?rev=1053032&r1=1053031&r2=1053032&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/PascalDistributionImpl.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/PascalDistributionImpl.java Mon Dec 27 09:51:56 2010
@@ -165,4 +165,69 @@ public class PascalDistributionImpl exte
 
         return ret;
     }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * The lower bound of the support is always 0 no matter the parameters.
+     *
+     * @return lower bound of the support (always 0)
+     */
+    @Override
+    public int getSupportLowerBound() {
+        return 0;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * The upper bound of the support is always positive infinity 
+     * no matter the parameters. Positive infinity is symbolised 
+     * by <code>Integer.MAX_VALUE</code> together with 
+     * {@link #isSupportUpperBoundInclusive()} being <code>false</code>
+     *
+     * @return upper bound of the support (always <code>Integer.MAX_VALUE</code> for positive infinity)
+     */
+    @Override
+    public int getSupportUpperBound() {
+        return Integer.MAX_VALUE;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * For number of successes <code>r</code> and 
+     * probability of success <code>p</code>, the mean is
+     * <code>( r * p ) / ( 1 - p )</code>
+     *
+     * @return {@inheritDoc}
+     */
+    @Override
+    protected double calculateNumericalMean() {
+        final double p = getProbabilityOfSuccess();
+        final double r = getNumberOfSuccesses();
+        return ( r * p ) / ( 1 - p );
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * For number of successes <code>r</code> and 
+     * probability of success <code>p</code>, the mean is
+     * <code>( r * p ) / ( 1 - p )^2</code>
+     *
+     * @return {@inheritDoc}
+     */
+    @Override
+    protected double calculateNumericalVariance() {
+        final double p = getProbabilityOfSuccess();
+        final double r = getNumberOfSuccesses();
+        final double pInv = 1 - p;
+        return ( r * p ) / (pInv * pInv);
+    }
+    
+    @Override
+    public boolean isSupportUpperBoundInclusive() {
+        return false;
+    }
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/PoissonDistributionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/PoissonDistributionImpl.java?rev=1053032&r1=1053031&r2=1053032&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/PoissonDistributionImpl.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/PoissonDistributionImpl.java Mon Dec 27 09:51:56 2010
@@ -230,4 +230,60 @@ public class PoissonDistributionImpl ext
     protected int getDomainUpperBound(double p) {
         return Integer.MAX_VALUE;
     }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * The lower bound of the support is always 0 no matter the mean parameter.
+     *
+     * @return lower bound of the support (always 0)
+     */
+    @Override
+    public int getSupportLowerBound() {
+        return 0;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * The upper bound of the support is positive infinity, 
+     * regardless of the parameter values. There is no integer infinity, 
+     * so this method returns <code>Integer.MAX_VALUE</code> and
+     * {@link #isSupportUpperBoundInclusive()} returns <code>true</code>.
+     *
+     * @return upper bound of the support (always <code>Integer.MAX_VALUE</code> for positive infinity)
+     */
+    @Override
+    public int getSupportUpperBound() {
+        return Integer.MAX_VALUE;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * For mean parameter <code>p</code>, the mean is <code>p</code>
+     *
+     * @return {@inheritDoc}
+     */
+    @Override
+    protected double calculateNumericalMean() {
+        return getMean();
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * For mean parameter <code>p</code>, the variance is <code>p</code>
+     *
+     * @return {@inheritDoc}
+     */
+    @Override
+    protected double calculateNumericalVariance() {
+        return getMean();
+    }
+    
+    @Override
+    public boolean isSupportUpperBoundInclusive() {
+        return true;
+    }
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/TDistributionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/TDistributionImpl.java?rev=1053032&r1=1053031&r2=1053032&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/TDistributionImpl.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/TDistributionImpl.java Mon Dec 27 09:51:56 2010
@@ -199,4 +199,89 @@ public class TDistributionImpl
     protected double getSolverAbsoluteAccuracy() {
         return solverAbsoluteAccuracy;
     }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * The lower bound of the support is always negative infinity 
+     * no matter the parameters.
+     *
+     * @return lower bound of the support (always Double.NEGATIVE_INFINITY)
+     */
+    @Override
+    public double getSupportLowerBound() {
+        return Double.NEGATIVE_INFINITY;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * The upper bound of the support is always positive infinity 
+     * no matter the parameters.
+     *
+     * @return upper bound of the support (always Double.POSITIVE_INFINITY)
+     */
+    @Override
+    public double getSupportUpperBound() {
+        return Double.POSITIVE_INFINITY;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * For degrees of freedom parameter df, the mean is
+     * <ul>
+     *  <li>if <code>df &gt; 1</code> then <code>0</code></li>
+     * <li>else <code>undefined</code></li>
+     * </ul>
+     *
+     * @return {@inheritDoc}
+     */
+    @Override
+    protected double calculateNumericalMean() {
+        final double df = getDegreesOfFreedom();
+        
+        if (df > 1) {
+            return 0;
+        }
+        
+        return Double.NaN;        
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * For degrees of freedom parameter df, the variance is
+     * <ul>
+     *  <li>if <code>df &gt; 2</code> then <code>df / (df - 2)</code> </li>
+     *  <li>if <code>1 &lt; df &lt;= 2</code> then <code>positive infinity</code></li>
+     *  <li>else <code>undefined</code></li>
+     * </ul>
+     *
+     * @return {@inheritDoc}
+     */
+    @Override
+    protected double calculateNumericalVariance() {
+        final double df = getDegreesOfFreedom();        
+
+        if (df > 2) {
+            return df / (df - 2);
+        }
+
+        if (df > 1 && df <= 2) {
+            return Double.POSITIVE_INFINITY;
+        }
+        
+        return Double.NaN;
+    }
+
+    @Override
+    public boolean isSupportLowerBoundInclusive() {
+        return false;
+    }
+
+    @Override
+    public boolean isSupportUpperBoundInclusive() {
+        return false;
+    }
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/WeibullDistributionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/WeibullDistributionImpl.java?rev=1053032&r1=1053031&r2=1053032&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/WeibullDistributionImpl.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/WeibullDistributionImpl.java Mon Dec 27 09:51:56 2010
@@ -22,6 +22,7 @@ import java.io.Serializable;
 import org.apache.commons.math.exception.OutOfRangeException;
 import org.apache.commons.math.exception.NotStrictlyPositiveException;
 import org.apache.commons.math.exception.util.LocalizedFormats;
+import org.apache.commons.math.special.Gamma;
 import org.apache.commons.math.util.FastMath;
 
 /**
@@ -215,4 +216,75 @@ public class WeibullDistributionImpl ext
     protected double getSolverAbsoluteAccuracy() {
         return solverAbsoluteAccuracy;
     }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * The lower bound of the support is always 0 no matter the parameters.
+     *
+     * @return lower bound of the support (always 0)
+     */
+    @Override
+    public double getSupportLowerBound() {
+        return 0;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * The upper bound of the support is always positive infinity 
+     * no matter the parameters.
+     *
+     * @return upper bound of the support (always Double.POSITIVE_INFINITY)
+     */
+    @Override
+    public double getSupportUpperBound() {
+        return Double.POSITIVE_INFINITY;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * The mean is <code>scale * Gamma(1 + (1 / shape))</code>
+     * where <code>Gamma(...)</code> is the Gamma-function
+     *
+     * @return {@inheritDoc}
+     */
+    @Override
+    protected double calculateNumericalMean() {
+        final double shape = getShape();
+        final double scale = getScale();
+
+        return scale * FastMath.exp(Gamma.logGamma(1 + (1 / shape)));
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * The variance is 
+     * <code>scale^2 * Gamma(1 + (2 / shape)) - mean^2</code> 
+     * where <code>Gamma(...)</code> is the Gamma-function
+     *
+     * @return {@inheritDoc}
+     */
+    @Override
+    protected double calculateNumericalVariance() {
+        final double shape = getShape();
+        final double scale = getScale();
+        final double mean = getNumericalMean();
+
+        return (scale * scale) * 
+            FastMath.exp(Gamma.logGamma(1 + (2 / shape))) -
+            (mean * mean);
+    }
+
+    @Override
+    public boolean isSupportLowerBoundInclusive() {
+        return true;
+    }
+
+    @Override
+    public boolean isSupportUpperBoundInclusive() {
+        return false;
+    }
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ZipfDistributionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ZipfDistributionImpl.java?rev=1053032&r1=1053031&r2=1053032&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ZipfDistributionImpl.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ZipfDistributionImpl.java Mon Dec 27 09:51:56 2010
@@ -147,4 +147,76 @@ public class ZipfDistributionImpl extend
         }
         return value;
     }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * The lower bound of the support is always 1 no matter the parameters.
+     *
+     * @return lower bound of the support (always 1)
+     */
+    @Override
+    public int getSupportLowerBound() {        
+        return 1;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * The upper bound of the support is the number of elements
+     *
+     * @return upper bound of the support
+     */
+    @Override
+    public int getSupportUpperBound() {
+        return getNumberOfElements();
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * For number of elements N and exponent s, the mean is
+     * <code>Hs1 / Hs</code> where 
+     * <ul>
+     *  <li><code>Hs1 = generalizedHarmonic(N, s - 1)</code></li> 
+     *  <li><code>Hs = generalizedHarmonic(N, s)</code></li>
+     * </ul>
+     *
+     * @return {@inheritDoc}
+     */
+    @Override
+    protected double calculateNumericalMean() {
+        final int N = getNumberOfElements();
+        final double s = getExponent();
+        
+        final double Hs1 = generalizedHarmonic(N, s - 1);
+        final double Hs = generalizedHarmonic(N, s);
+
+        return Hs1 / Hs;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * For number of elements N and exponent s, the mean is
+     * <code>(Hs2 / Hs) - (Hs1^2 / Hs^2)</code> where 
+     * <ul>
+     *  <li><code>Hs2 = generalizedHarmonic(N, s - 2)</code></li>
+     *  <li><code>Hs1 = generalizedHarmonic(N, s - 1)</code></li> 
+     *  <li><code>Hs = generalizedHarmonic(N, s)</code></li>
+     * </ul>
+     * 
+     * @return {@inheritDoc}
+     */
+    @Override
+    protected double calculateNumericalVariance() {
+        final int N = getNumberOfElements();
+        final double s = getExponent();
+        
+        final double Hs2 = generalizedHarmonic(N, s - 2);
+        final double Hs1 = generalizedHarmonic(N, s - 1);
+        final double Hs = generalizedHarmonic(N, s);
+
+        return (Hs2 / Hs) - ((Hs1 * Hs1) / (Hs * Hs));
+    }
 }

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/BetaDistributionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/BetaDistributionTest.java?rev=1053032&r1=1053031&r2=1053032&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/BetaDistributionTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/BetaDistributionTest.java Mon Dec 27 09:51:56 2010
@@ -18,6 +18,7 @@ package org.apache.commons.math.distribu
 
 import junit.framework.TestCase;
 import org.apache.commons.math.MathException;
+import org.apache.commons.math.util.FastMath;
 
 public class BetaDistributionTest extends TestCase {
     public void testCumulative() throws MathException {
@@ -286,4 +287,17 @@ public class BetaDistributionTest extend
             assertEquals(String.format("density at x=%.1f for alpha=%.1f, beta=%.1f", x[i], alpha, beta), expected[i], d.density(x[i]), 1e-5);
         }
     }
+
+    public void testMomonts() {
+        final double tol = 1e-9;
+        BetaDistribution dist;
+        
+        dist = new BetaDistributionImpl(1, 1);
+        assertEquals(dist.getNumericalMean(), 0.5, tol);
+        assertEquals(dist.getNumericalVariance(), 1.0 / 12.0, tol); 
+        
+        dist = new BetaDistributionImpl(2, 5);
+        assertEquals(dist.getNumericalMean(), 2.0 / 7.0, tol);
+        assertEquals(dist.getNumericalVariance(), 10.0 / (49.0 * 8.0), tol); 
+    }
 }

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/BinomialDistributionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/BinomialDistributionTest.java?rev=1053032&r1=1053031&r2=1053032&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/BinomialDistributionTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/BinomialDistributionTest.java Mon Dec 27 09:51:56 2010
@@ -113,4 +113,17 @@ public class BinomialDistributionTest ex
         verifyInverseCumulativeProbabilities();
     }
 
+    public void testMomonts() {
+        final double tol = 1e-9;
+        BinomialDistribution dist;
+        
+        dist = new BinomialDistributionImpl(10, 0.5);
+        assertEquals(dist.getNumericalMean(), 10d * 0.5d, tol);
+        assertEquals(dist.getNumericalVariance(), 10d * 0.5d * 0.5d, tol); 
+        
+        dist = new BinomialDistributionImpl(30, 0.3);
+        assertEquals(dist.getNumericalMean(), 30d * 0.3d, tol);
+        assertEquals(dist.getNumericalVariance(), 30d * 0.3d * (1d - 0.3d), tol);
+    }
+
 }

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/CauchyDistributionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/CauchyDistributionTest.java?rev=1053032&r1=1053031&r2=1053032&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/CauchyDistributionTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/CauchyDistributionTest.java Mon Dec 27 09:51:56 2010
@@ -107,4 +107,17 @@ public class CauchyDistributionTest exte
             // Expected.
         }
     }
+
+    public void testMomonts() {
+        final double tol = 1e-9;
+        CauchyDistribution dist;
+        
+        dist = new CauchyDistributionImpl(10.2, 0.15);
+        assertEquals(dist.getNumericalMean(), Double.NaN, tol);
+        assertEquals(dist.getNumericalVariance(), Double.NaN, tol); 
+        
+        dist = new CauchyDistributionImpl(23.12, 2.12);
+        assertEquals(dist.getNumericalMean(), Double.NaN, tol);
+        assertEquals(dist.getNumericalVariance(), Double.NaN, tol);
+    }
 }

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/ChiSquareDistributionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/ChiSquareDistributionTest.java?rev=1053032&r1=1053031&r2=1053032&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/ChiSquareDistributionTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/ChiSquareDistributionTest.java Mon Dec 27 09:51:56 2010
@@ -124,4 +124,17 @@ public class ChiSquareDistributionTest e
         }
     }
 
+    public void testMomonts() {
+        final double tol = 1e-9;
+        ChiSquaredDistribution dist;
+        
+        dist = new ChiSquaredDistributionImpl(1500);
+        assertEquals(dist.getNumericalMean(), 1500, tol);
+        assertEquals(dist.getNumericalVariance(), 3000, tol); 
+        
+        dist = new ChiSquaredDistributionImpl(1.12);
+        assertEquals(dist.getNumericalMean(), 1.12, tol);
+        assertEquals(dist.getNumericalVariance(), 2.24, tol);
+    }
+
 }

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/ExponentialDistributionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/ExponentialDistributionTest.java?rev=1053032&r1=1053031&r2=1053032&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/ExponentialDistributionTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/ExponentialDistributionTest.java Mon Dec 27 09:51:56 2010
@@ -122,4 +122,17 @@ public class ExponentialDistributionTest
             // Expected.
         }
     }
+
+    public void testMomonts() {
+        final double tol = 1e-9;
+        ExponentialDistribution dist;
+        
+        dist = new ExponentialDistributionImpl(11d);
+        assertEquals(dist.getNumericalMean(), 11d, tol);
+        assertEquals(dist.getNumericalVariance(), 11d * 11d, tol);
+        
+        dist = new ExponentialDistributionImpl(10.5d);
+        assertEquals(dist.getNumericalMean(), 10.5d, tol);
+        assertEquals(dist.getNumericalVariance(), 10.5d * 10.5d, tol);
+    }
 }

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/FDistributionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/FDistributionTest.java?rev=1053032&r1=1053031&r2=1053032&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/FDistributionTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/FDistributionTest.java Mon Dec 27 09:51:56 2010
@@ -124,4 +124,21 @@ public class FDistributionTest extends C
         x = fd.inverseCumulativeProbability(p);
         assertEquals(0.975, x, 1.0e-5);
     }
+
+    public void testMomonts() {
+        final double tol = 1e-9;
+        FDistribution dist;
+        
+        dist = new FDistributionImpl(1, 2);
+        assertEquals(dist.getNumericalMean(), Double.NaN, tol);
+        assertEquals(dist.getNumericalVariance(), Double.NaN, tol); 
+        
+        dist = new FDistributionImpl(1, 3);
+        assertEquals(dist.getNumericalMean(), 3d / (3d - 2d), tol);
+        assertEquals(dist.getNumericalVariance(), Double.NaN, tol);
+        
+        dist = new FDistributionImpl(1, 5);
+        assertEquals(dist.getNumericalMean(), 5d / (5d - 2d), tol);
+        assertEquals(dist.getNumericalVariance(), (2d * 5d * 5d * 4d) / 9d, tol);        
+    }
 }

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/GammaDistributionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/GammaDistributionTest.java?rev=1053032&r1=1053031&r2=1053032&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/GammaDistributionTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/GammaDistributionTest.java Mon Dec 27 09:51:56 2010
@@ -153,4 +153,17 @@ public class GammaDistributionTest exten
         setInverseCumulativeTestValues(new double[] {0, Double.POSITIVE_INFINITY});
         verifyInverseCumulativeProbabilities();
     }
+
+    public void testMomonts() {
+        final double tol = 1e-9;
+        GammaDistribution dist;
+        
+        dist = new GammaDistributionImpl(1, 2);
+        assertEquals(dist.getNumericalMean(), 2, tol);
+        assertEquals(dist.getNumericalVariance(), 4, tol); 
+        
+        dist = new GammaDistributionImpl(1.1, 4.2);
+        assertEquals(dist.getNumericalMean(), 1.1d * 4.2d, tol);
+        assertEquals(dist.getNumericalVariance(), 1.1d * 4.2d * 4.2d, tol);
+    }
 }

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/HypergeometricDistributionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/HypergeometricDistributionTest.java?rev=1053032&r1=1053031&r2=1053032&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/HypergeometricDistributionTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/HypergeometricDistributionTest.java Mon Dec 27 09:51:56 2010
@@ -242,4 +242,17 @@ public class HypergeometricDistributionT
         };
         testHypergeometricDistributionProbabilities(populationSize, sampleSize, numberOfSucceses, data);
     }
+
+    public void testMomonts() {
+        final double tol = 1e-9;
+        HypergeometricDistribution dist;
+        
+        dist = new HypergeometricDistributionImpl(1500, 40, 100);
+        assertEquals(dist.getNumericalMean(), 40d * 100d / 1500d, tol);
+        assertEquals(dist.getNumericalVariance(), ( 100d * 40d * (1500d - 100d) * (1500d - 40d) ) / ( (1500d * 1500d * 1499d) ), tol); 
+        
+        dist = new HypergeometricDistributionImpl(3000, 55, 200);
+        assertEquals(dist.getNumericalMean(), 55d * 200d / 3000d, tol);
+        assertEquals(dist.getNumericalVariance(), ( 200d * 55d * (3000d - 200d) * (3000d - 55d) ) / ( (3000d * 3000d * 2999d) ), tol);
+    }
 }

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/NormalDistributionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/NormalDistributionTest.java?rev=1053032&r1=1053031&r2=1053032&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/NormalDistributionTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/NormalDistributionTest.java Mon Dec 27 09:51:56 2010
@@ -190,4 +190,20 @@ public class NormalDistributionTest exte
         assertEquals(2.0, result, defaultTolerance);
     }
 
+    public void testMomonts() {
+        final double tol = 1e-9;
+        NormalDistribution dist;
+        
+        dist = new NormalDistributionImpl(0, 1);        
+        assertEquals(dist.getNumericalMean(), 0, tol);
+        assertEquals(dist.getNumericalVariance(), 1, tol);        
+ 
+        dist = new NormalDistributionImpl(2.2, 1.4);
+        assertEquals(dist.getNumericalMean(), 2.2, tol);
+        assertEquals(dist.getNumericalVariance(), 1.4 * 1.4, tol);
+        
+        dist = new NormalDistributionImpl(-2000.9, 10.4);
+        assertEquals(dist.getNumericalMean(), -2000.9, tol);
+        assertEquals(dist.getNumericalVariance(), 10.4 * 10.4, tol);
+    }
 }

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/PascalDistributionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/PascalDistributionTest.java?rev=1053032&r1=1053031&r2=1053032&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/PascalDistributionTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/PascalDistributionTest.java Mon Dec 27 09:51:56 2010
@@ -119,4 +119,17 @@ public class PascalDistributionTest exte
         verifyCumulativeProbabilities();
         verifyInverseCumulativeProbabilities();
     }
+
+    public void testMomonts() {
+        final double tol = 1e-9;
+        PascalDistribution dist;
+        
+        dist = new PascalDistributionImpl(10, 0.5);
+        assertEquals(dist.getNumericalMean(), ( 10d * 0.5d ) / 0.5d, tol);
+        assertEquals(dist.getNumericalVariance(), ( 10d * 0.5d ) / (0.5d * 0.5d), tol); 
+        
+        dist = new PascalDistributionImpl(25, 0.3);
+        assertEquals(dist.getNumericalMean(), ( 25d * 0.3d ) / 0.7d, tol);
+        assertEquals(dist.getNumericalVariance(), ( 25d * 0.3d ) / (0.7d * 0.7d), tol);
+    }
 }

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/PoissonDistributionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/PoissonDistributionTest.java?rev=1053032&r1=1053031&r2=1053032&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/PoissonDistributionTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/PoissonDistributionTest.java Mon Dec 27 09:51:56 2010
@@ -218,4 +218,17 @@ public class PoissonDistributionTest ext
             mean *= 10.0;
         }
     }
+
+    public void testMomonts() {
+        final double tol = 1e-9;
+        PoissonDistribution dist;
+        
+        dist = new PoissonDistributionImpl(1);
+        assertEquals(dist.getNumericalMean(), 1, tol);
+        assertEquals(dist.getNumericalVariance(), 1, tol); 
+        
+        dist = new PoissonDistributionImpl(11.23);
+        assertEquals(dist.getNumericalMean(), 11.23, tol);
+        assertEquals(dist.getNumericalVariance(), 11.23, tol);
+    }
 }

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/TDistributionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/TDistributionTest.java?rev=1053032&r1=1053031&r2=1053032&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/TDistributionTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/TDistributionTest.java Mon Dec 27 09:51:56 2010
@@ -118,4 +118,21 @@ public class TDistributionTest extends C
             // expected
         }
     }
+    
+    public void testMomonts() {
+        final double tol = 1e-9;
+        TDistribution dist;
+        
+        dist = new TDistributionImpl(1);
+        assertEquals(dist.getNumericalMean(), Double.NaN, tol);
+        assertEquals(dist.getNumericalVariance(), Double.NaN, tol); 
+        
+        dist = new TDistributionImpl(1.5);
+        assertEquals(dist.getNumericalMean(), 0, tol);
+        assertEquals(dist.getNumericalVariance(), Double.POSITIVE_INFINITY, tol);
+        
+        dist = new TDistributionImpl(5);
+        assertEquals(dist.getNumericalMean(), 0, tol);
+        assertEquals(dist.getNumericalVariance(), 5d / (5d - 2d), tol);        
+    }
 }

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/WeibullDistributionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/WeibullDistributionTest.java?rev=1053032&r1=1053031&r2=1053032&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/WeibullDistributionTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/WeibullDistributionTest.java Mon Dec 27 09:51:56 2010
@@ -17,6 +17,8 @@
 
 package org.apache.commons.math.distribution;
 
+import org.apache.commons.math.special.Gamma;
+import org.apache.commons.math.util.FastMath;
 import org.apache.commons.math.exception.NotStrictlyPositiveException;
 
 /**
@@ -95,4 +97,22 @@ public class WeibullDistributionTest ext
             // Expected.
         }
     }
+
+    public void testMomonts() {
+        final double tol = 1e-9;
+        WeibullDistribution dist;
+        
+        dist = new WeibullDistributionImpl(2.5, 3.5);
+        // In R: 3.5*gamma(1+(1/2.5)) (or emperically: mean(rweibull(10000, 2.5, 3.5)))
+        assertEquals(dist.getNumericalMean(), 3.5 * FastMath.exp(Gamma.logGamma(1 + (1 / 2.5))), tol);
+        assertEquals(dist.getNumericalVariance(), (3.5 * 3.5) * 
+                FastMath.exp(Gamma.logGamma(1 + (2 / 2.5))) -
+                (dist.getNumericalMean() * dist.getNumericalMean()), tol); 
+        
+        dist = new WeibullDistributionImpl(10.4, 2.222);
+        assertEquals(dist.getNumericalMean(), 2.222 * FastMath.exp(Gamma.logGamma(1 + (1 / 10.4))), tol);
+        assertEquals(dist.getNumericalVariance(), (2.222 * 2.222) * 
+                FastMath.exp(Gamma.logGamma(1 + (2 / 10.4))) -
+                (dist.getNumericalMean() * dist.getNumericalMean()), tol);
+    }
 }

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/ZipfDistributionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/ZipfDistributionTest.java?rev=1053032&r1=1053031&r2=1053032&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/ZipfDistributionTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/ZipfDistributionTest.java Mon Dec 27 09:51:56 2010
@@ -19,6 +19,8 @@ package org.apache.commons.math.distribu
 
 import org.apache.commons.math.exception.NotStrictlyPositiveException;
 
+import org.apache.commons.math.util.FastMath;
+
 /**
  * Test cases for {@link ZipfDistribution}.
  * Extends IntegerDistributionAbstractTest.  See class javadoc for
@@ -92,4 +94,13 @@ public class ZipfDistributionTest extend
     public int[] makeInverseCumulativeTestValues() {
         return new int[] {0, 0, 0, 0, 0, 0, 1, 9, 9, 9, 8, 7, 10};
     }
+
+    public void testMomonts() {
+        final double tol = 1e-9;
+        ZipfDistribution dist;
+        
+        dist = new ZipfDistributionImpl(2, 0.5);
+        assertEquals(dist.getNumericalMean(), FastMath.sqrt(2), tol);
+        assertEquals(dist.getNumericalVariance(), 0.24264068711928521, tol); 
+    }
 }



Mime
View raw message