Author: celestin
Date: Sat Dec 3 18:23:02 2011
New Revision: 1209963
URL: http://svn.apache.org/viewvc?rev=1209963&view=rev
Log:
- In distribution.AbstractRealDistribution, removed superfluous methods
getDomainLowerBound(double), getDomainUpperBound(double) and
getInitialDomain(double p) (MATH-699).
- Resolved checkstyle issues in the distribution package.
- Improved Javadoc of RealDistribution.getSupportLowerBound(),
RealDistribution.getSupportUpperBound() and
AbstractRealDistribution.inverseCumulativeDistribution(double).
Modified:
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/AbstractRealDistribution.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BetaDistribution.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BinomialDistribution.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/CauchyDistribution.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ChiSquaredDistribution.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ExponentialDistribution.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/FDistribution.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/GammaDistribution.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/HypergeometricDistribution.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/IntegerDistribution.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/KolmogorovSmirnovDistribution.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/NormalDistribution.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/PascalDistribution.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/PoissonDistribution.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/RealDistribution.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/TDistribution.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/WeibullDistribution.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ZipfDistribution.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/AbstractRealDistributionTest.java
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=1209963&r1=1209962&r2=1209963&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
Sat Dec 3 18:23:02 2011
@@ -43,11 +43,11 @@ implements IntegerDistribution, Serializ
protected final RandomDataImpl randomData = new RandomDataImpl();
/** Default constructor. */
- protected AbstractIntegerDistribution() {}
+ protected AbstractIntegerDistribution() { }
/**
* {@inheritDoc}
- *
+ *
* The default implementation uses the identity
* <p>{@code P(x0 <= X <= x1) = P(X <= x1) - P(X <= x0 - 1)}</p>
*/
@@ -136,7 +136,7 @@ implements IntegerDistribution, Serializ
/**
* {@inheritDoc}
- *
+ *
* The default implementation uses the
* <a href="http://en.wikipedia.org/wiki/Inverse_transform_sampling">
* inversion method</a>.
@@ -147,7 +147,7 @@ implements IntegerDistribution, Serializ
/**
* {@inheritDoc}
- *
+ *
* The default implementation generates the sample by calling
* {@link #sample()} in a loop.
*/
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractRealDistribution.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractRealDistribution.java?rev=1209963&r1=1209962&r2=1209963&view=diff
==============================================================================
---
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractRealDistribution.java
(original)
+++
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractRealDistribution.java
Sat Dec 3 18:23:02 2011
@@ -37,12 +37,12 @@ import org.apache.commons.math.util.Fast
*/
public abstract class AbstractRealDistribution
implements RealDistribution, Serializable {
- /** Serializable version identifier */
- private static final long serialVersionUID = -38038050983108802L;
-
/** Default accuracy. */
public static final double SOLVER_DEFAULT_ABSOLUTE_ACCURACY = 1e-6;
+ /** Serializable version identifier */
+ private static final long serialVersionUID = -38038050983108802L;
+
/** Solver absolute accuracy for inverse cumulative computation */
private double solverAbsoluteAccuracy = SOLVER_DEFAULT_ABSOLUTE_ACCURACY;
@@ -50,7 +50,7 @@ implements RealDistribution, Serializabl
protected final RandomDataImpl randomData = new RandomDataImpl();
/** Default constructor. */
- protected AbstractRealDistribution() {}
+ protected AbstractRealDistribution() { }
/**
* {@inheritDoc}
@@ -66,8 +66,44 @@ implements RealDistribution, Serializabl
return cumulativeProbability(x1) - cumulativeProbability(x0);
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ *
+ * The default implementation returns
+ * <ul>
+ * <li>{@link #getSupportLowerBound()} for {@code p = 0},</li>
+ * <li>{@link #getSupportUpperBound()} for {@code p = 1}.</li>
+ * </ul>
+ */
public double inverseCumulativeProbability(final double p) throws
OutOfRangeException {
+ /*
+ * IMPLEMENTATION NOTES
+ * --------------------
+ * Where applicable, use is made of the one-sided Chebyshev inequality
+ * to bracket the root. This inequality states that
+ * P(X - mu >= k * sig) <= 1 / (1 + k^2),
+ * mu: mean, sig: standard deviation. Equivalently
+ * 1 - P(X < mu + k * sig) <= 1 / (1 + k^2),
+ * F(mu + k * sig) >= k^2 / (1 + k^2).
+ *
+ * For k = sqrt(p / (1 - p)), we find
+ * F(mu + k * sig) >= p,
+ * and (mu + k * sig) is an upper-bound for the root.
+ *
+ * Then, introducing Y = -X, mean(Y) = -mu, sd(Y) = sig, and
+ * P(Y >= -mu + k * sig) <= 1 / (1 + k^2),
+ * P(-X >= -mu + k * sig) <= 1 / (1 + k^2),
+ * P(X <= mu - k * sig) <= 1 / (1 + k^2),
+ * F(mu - k * sig) <= 1 / (1 + k^2).
+ *
+ * For k = sqrt((1 - p) / p), we find
+ * F(mu - k * sig) <= p,
+ * and (mu - k * sig) is a lower-bound for the root.
+ *
+ * In cases where the Chebyshev inequality does not apply, geometric
+ * progressions 1, 2, 4, ... and -1, -2, -4, ... are used to bracket
+ * the root.
+ */
if (p < 0.0 || p > 1.0) {
throw new OutOfRangeException(p, 0, 1);
}
@@ -145,39 +181,6 @@ implements RealDistribution, Serializabl
}
/**
- * Access the initial domain value, based on {@code p}, used to
- * bracket a CDF root. This method is used by
- * {@link #inverseCumulativeProbability(double)} to find critical values.
- *
- * @param p Desired probability for the critical value.
- * @return the initial domain value.
- * TODO to be deleted when applying MATH-699
- */
- protected abstract double getInitialDomain(double p);
-
- /**
- * Access the domain value lower bound, based on {@code p}, used to
- * bracket a CDF root. This method is used by
- * {@link #inverseCumulativeProbability(double)} to find critical values.
- *
- * @param p Desired probability for the critical value.
- * @return the domain value lower bound, i.e. {@code P(X < 'lower bound')
< p}.
- * TODO to be deleted when applying MATH-699
- */
- protected abstract double getDomainLowerBound(double p);
-
- /**
- * Access the domain value upper bound, based on {@code p}, used to
- * bracket a CDF root. This method is used by
- * {@link #inverseCumulativeProbability(double)} to find critical values.
- *
- * @param p Desired probability for the critical value.
- * @return the domain value upper bound, i.e. {@code P(X < 'upper bound')
> p}.
- * TODO to be deleted when applying MATH-699
- */
- protected abstract double getDomainUpperBound(double p);
-
- /**
* Returns the solver absolute accuracy for inverse cumulative computation.
* You can override this method in order to use a Brent solver with an
* absolute accuracy different from the default.
@@ -195,7 +198,7 @@ implements RealDistribution, Serializabl
/**
* {@inheritDoc}
- *
+ *
* The default implementation uses the
* <a href="http://en.wikipedia.org/wiki/Inverse_transform_sampling">
* inversion method.
@@ -207,7 +210,7 @@ implements RealDistribution, Serializabl
/**
* {@inheritDoc}
- *
+ *
* The default implementation generates the sample by calling
* {@link #sample()} in a loop.
*/
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BetaDistribution.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BetaDistribution.java?rev=1209963&r1=1209962&r2=1209963&view=diff
==============================================================================
---
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BetaDistribution.java
(original)
+++
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BetaDistribution.java
Sat Dec 3 18:23:02 2011
@@ -146,24 +146,6 @@ public class BetaDistribution extends Ab
}
/** {@inheritDoc} */
- @Override
- protected double getInitialDomain(double p) {
- return p;
- }
-
- /** {@inheritDoc} */
- @Override
- protected double getDomainLowerBound(double p) {
- return 0;
- }
-
- /** {@inheritDoc} */
- @Override
- protected double getDomainUpperBound(double p) {
- return 1;
- }
-
- /** {@inheritDoc} */
public double cumulativeProbability(double x) {
if (x <= 0) {
return 0;
@@ -245,9 +227,9 @@ public class BetaDistribution extends Ab
/**
* {@inheritDoc}
- *
+ *
* The support of this distribution is connected.
- *
+ *
* @return {@code true}
*/
public boolean isSupportConnected() {
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BinomialDistribution.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BinomialDistribution.java?rev=1209963&r1=1209962&r2=1209963&view=diff
==============================================================================
---
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BinomialDistribution.java
(original)
+++
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BinomialDistribution.java
Sat Dec 3 18:23:02 2011
@@ -182,9 +182,9 @@ public class BinomialDistribution extend
/**
* {@inheritDoc}
- *
+ *
* The support of this distribution is connected.
- *
+ *
* @return {@code true}
*/
public boolean isSupportConnected() {
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/CauchyDistribution.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/CauchyDistribution.java?rev=1209963&r1=1209962&r2=1209963&view=diff
==============================================================================
---
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/CauchyDistribution.java
(original)
+++
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/CauchyDistribution.java
Sat Dec 3 18:23:02 2011
@@ -146,50 +146,6 @@ public class CauchyDistribution extends
/** {@inheritDoc} */
@Override
- protected double getDomainLowerBound(double p) {
- double ret;
-
- if (p < 0.5) {
- ret = -Double.MAX_VALUE;
- } else {
- ret = median;
- }
-
- return ret;
- }
-
- /** {@inheritDoc} */
- @Override
- protected double getDomainUpperBound(double p) {
- double ret;
-
- if (p < 0.5) {
- ret = median;
- } else {
- ret = Double.MAX_VALUE;
- }
-
- return ret;
- }
-
- /** {@inheritDoc} */
- @Override
- protected double getInitialDomain(double p) {
- double ret;
-
- if (p < 0.5) {
- ret = median - scale;
- } else if (p > 0.5) {
- ret = median + scale;
- } else {
- ret = median;
- }
-
- return ret;
- }
-
- /** {@inheritDoc} */
- @Override
protected double getSolverAbsoluteAccuracy() {
return solverAbsoluteAccuracy;
}
@@ -252,9 +208,9 @@ public class CauchyDistribution extends
/**
* {@inheritDoc}
- *
+ *
* The support of this distribution is connected.
- *
+ *
* @return {@code true}
*/
public boolean isSupportConnected() {
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ChiSquaredDistribution.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ChiSquaredDistribution.java?rev=1209963&r1=1209962&r2=1209963&view=diff
==============================================================================
---
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ChiSquaredDistribution.java
(original)
+++
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ChiSquaredDistribution.java
Sat Dec 3 18:23:02 2011
@@ -110,50 +110,6 @@ public class ChiSquaredDistribution exte
/** {@inheritDoc} */
@Override
- protected double getDomainLowerBound(double p) {
- return Double.MIN_VALUE * gamma.getBeta();
- }
-
- /** {@inheritDoc} */
- @Override
- protected double getDomainUpperBound(double p) {
- // NOTE: chi squared is skewed to the left
- // NOTE: therefore, P(X < μ) > .5
-
- double ret;
-
- if (p < .5) {
- // use mean
- ret = getDegreesOfFreedom();
- } else {
- // use max
- ret = Double.MAX_VALUE;
- }
-
- return ret;
- }
-
- /** {@inheritDoc} */
- @Override
- protected double getInitialDomain(double p) {
- // NOTE: chi squared is skewed to the left
- // NOTE: therefore, P(X < μ) > 0.5
-
- double ret;
-
- if (p < 0.5) {
- // use 1/2 mean
- ret = getDegreesOfFreedom() * 0.5;
- } else {
- // use mean
- ret = getDegreesOfFreedom();
- }
-
- return ret;
- }
-
- /** {@inheritDoc} */
- @Override
protected double getSolverAbsoluteAccuracy() {
return solverAbsoluteAccuracy;
}
@@ -175,7 +131,7 @@ public class ChiSquaredDistribution exte
* @return {@inheritDoc}
*/
public double getNumericalVariance() {
- return 2*getDegreesOfFreedom();
+ return 2 * getDegreesOfFreedom();
}
/**
@@ -214,9 +170,9 @@ public class ChiSquaredDistribution exte
/**
* {@inheritDoc}
- *
+ *
* The support of this distribution is connected.
- *
+ *
* @return {@code true}
*/
public boolean isSupportConnected() {
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ExponentialDistribution.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ExponentialDistribution.java?rev=1209963&r1=1209962&r2=1209963&view=diff
==============================================================================
---
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ExponentialDistribution.java
(original)
+++
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ExponentialDistribution.java
Sat Dec 3 18:23:02 2011
@@ -60,7 +60,7 @@ public class ExponentialDistribution ext
* @since 2.1
*/
public ExponentialDistribution(double mean, double inverseCumAccuracy)
- throws NotStrictlyPositiveException{
+ throws NotStrictlyPositiveException {
if (mean <= 0) {
throw new NotStrictlyPositiveException(LocalizedFormats.MEAN,
mean);
}
@@ -155,44 +155,6 @@ public class ExponentialDistribution ext
/** {@inheritDoc} */
@Override
- protected double getDomainLowerBound(double p) {
- return 0;
- }
-
- /** {@inheritDoc} */
- @Override
- protected double getDomainUpperBound(double p) {
- // NOTE: exponential is skewed to the left
- // NOTE: therefore, P(X < μ) > .5
-
- if (p < 0.5) {
- // use mean
- return mean;
- } else {
- // use max
- return Double.MAX_VALUE;
- }
- }
-
- /** {@inheritDoc} */
- @Override
- protected double getInitialDomain(double p) {
- // TODO: try to improve on this estimate
- // TODO: what should really happen here is not derive from
- // AbstractContinuousDistribution
- // TODO: because the inverse cumulative distribution is simple.
- // Exponential is skewed to the left, therefore, P(X < μ) > .5
- if (p < 0.5) {
- // use 1/2 mean
- return mean * 0.5;
- } else {
- // use mean
- return mean;
- }
- }
-
- /** {@inheritDoc} */
- @Override
protected double getSolverAbsoluteAccuracy() {
return solverAbsoluteAccuracy;
}
@@ -251,9 +213,9 @@ public class ExponentialDistribution ext
/**
* {@inheritDoc}
- *
+ *
* The support of this distribution is connected.
- *
+ *
* @return {@code true}
*/
public boolean isSupportConnected() {
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/FDistribution.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/FDistribution.java?rev=1209963&r1=1209962&r2=1209963&view=diff
==============================================================================
---
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/FDistribution.java
(original)
+++
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/FDistribution.java
Sat Dec 3 18:23:02 2011
@@ -31,15 +31,15 @@ import org.apache.commons.math.util.Fast
* @version $Id$
*/
public class FDistribution extends AbstractRealDistribution {
- /** Serializable version identifier. */
- private static final long serialVersionUID = -8516354193418641566L;
-
/**
* Default inverse cumulative probability accuracy.
* @since 2.1
*/
public static final double DEFAULT_INVERSE_ABSOLUTE_ACCURACY = 1e-9;
+ /** Serializable version identifier. */
+ private static final long serialVersionUID = -8516354193418641566L;
+
/** The numerator degrees of freedom. */
private final double numeratorDegreesOfFreedom;
@@ -172,30 +172,6 @@ public class FDistribution extends Abstr
return super.inverseCumulativeProbability(p);
}
- /** {@inheritDoc} */
- @Override
- protected double getDomainLowerBound(double p) {
- return 0;
- }
-
- /** {@inheritDoc} */
- @Override
- protected double getDomainUpperBound(double p) {
- return Double.MAX_VALUE;
- }
-
- /** {@inheritDoc} */
- @Override
- protected double getInitialDomain(double p) {
- double ret = 1;
- double d = denominatorDegreesOfFreedom;
- if (d > 2) {
- // use mean
- ret = d / (d - 2);
- }
- return ret;
- }
-
/**
* Access the numerator degrees of freedom.
*
@@ -262,7 +238,7 @@ public class FDistribution extends Abstr
/**
* used by {@link #getNumericalVariance()}
- *
+ *
* @return the variance of this distribution
*/
protected double calculateNumericalVariance() {
@@ -314,9 +290,9 @@ public class FDistribution extends Abstr
/**
* {@inheritDoc}
- *
+ *
* The support of this distribution is connected.
- *
+ *
* @return {@code true}
*/
public boolean isSupportConnected() {
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/GammaDistribution.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/GammaDistribution.java?rev=1209963&r1=1209962&r2=1209963&view=diff
==============================================================================
---
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/GammaDistribution.java
(original)
+++
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/GammaDistribution.java
Sat Dec 3 18:23:02 2011
@@ -163,52 +163,6 @@ public class GammaDistribution extends A
/** {@inheritDoc} */
@Override
- protected double getDomainLowerBound(double p) {
- // TODO: try to improve on this estimate
- return Double.MIN_VALUE;
- }
-
- /** {@inheritDoc} */
- @Override
- protected double getDomainUpperBound(double p) {
- // TODO: try to improve on this estimate
- // NOTE: gamma is skewed to the left
- // NOTE: therefore, P(X < μ) > .5
-
- double ret;
-
- if (p < 0.5) {
- // use mean
- ret = alpha * beta;
- } else {
- // use max value
- ret = Double.MAX_VALUE;
- }
-
- return ret;
- }
-
- /** {@inheritDoc} */
- @Override
- protected double getInitialDomain(double p) {
- // TODO: try to improve on this estimate
- // Gamma is skewed to the left, therefore, P(X < μ) > .5
-
- double ret;
-
- if (p < 0.5) {
- // use 1/2 mean
- ret = alpha * beta * 0.5;
- } else {
- // use mean
- ret = alpha * beta;
- }
-
- return ret;
- }
-
- /** {@inheritDoc} */
- @Override
protected double getSolverAbsoluteAccuracy() {
return solverAbsoluteAccuracy;
}
@@ -271,9 +225,9 @@ public class GammaDistribution extends A
/**
* {@inheritDoc}
- *
+ *
* The support of this distribution is connected.
- *
+ *
* @return {@code true}
*/
public boolean isSupportConnected() {
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/HypergeometricDistribution.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/HypergeometricDistribution.java?rev=1209963&r1=1209962&r2=1209963&view=diff
==============================================================================
---
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/HypergeometricDistribution.java
(original)
+++
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/HypergeometricDistribution.java
Sat Dec 3 18:23:02 2011
@@ -280,7 +280,7 @@ public class HypergeometricDistribution
* size {@code n}, the mean is {@code n * m / N}.
*/
public double getNumericalMean() {
- return (double)(getSampleSize() * getNumberOfSuccesses()) /
(double)getPopulationSize();
+ return (double) (getSampleSize() * getNumberOfSuccesses()) / (double)
getPopulationSize();
}
/**
@@ -300,14 +300,14 @@ public class HypergeometricDistribution
/**
* Used by {@link #getNumericalVariance()}.
- *
+ *
* @return the variance of this distribution
*/
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)) );
+ return ( n * m * (N - n) * (N - m) ) / ( (N * N * (N - 1)) );
}
/**
@@ -338,9 +338,9 @@ public class HypergeometricDistribution
/**
* {@inheritDoc}
- *
+ *
* The support of this distribution is connected.
- *
+ *
* @return {@code true}
*/
public boolean isSupportConnected() {
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/IntegerDistribution.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/IntegerDistribution.java?rev=1209963&r1=1209962&r2=1209963&view=diff
==============================================================================
---
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/IntegerDistribution.java
(original)
+++
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/IntegerDistribution.java
Sat Dec 3 18:23:02 2011
@@ -93,9 +93,8 @@ public interface IntegerDistribution {
* Use this method to get the numerical value of the variance of this
* distribution.
*
- * @return the variance (possibly {@code Double.POSITIVE_INFINITY} as
- * for certain cases in {@link TDistributionImpl}) or
- * {@code Double.NaN} if it is not defined
+ * @return the variance (possibly {@code Double.POSITIVE_INFINITY} or
+ * {@code Double.NaN} if it is not defined)
*/
double getNumericalVariance();
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/KolmogorovSmirnovDistribution.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/KolmogorovSmirnovDistribution.java?rev=1209963&r1=1209962&r2=1209963&view=diff
==============================================================================
---
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/KolmogorovSmirnovDistribution.java
(original)
+++
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/KolmogorovSmirnovDistribution.java
Sat Dec 3 18:23:02 2011
@@ -246,7 +246,7 @@ public class KolmogorovSmirnovDistributi
double pFrac = Hpower.getEntry(k - 1, k - 1);
for (int i = 1; i <= n; ++i) {
- pFrac *= (double)i / (double)n;
+ pFrac *= (double) i / (double) n;
}
return pFrac;
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/NormalDistribution.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/NormalDistribution.java?rev=1209963&r1=1209962&r2=1209963&view=diff
==============================================================================
---
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/NormalDistribution.java
(original)
+++
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/NormalDistribution.java
Sat Dec 3 18:23:02 2011
@@ -174,50 +174,6 @@ public class NormalDistribution extends
/** {@inheritDoc} */
@Override
- protected double getDomainLowerBound(double p) {
- double ret;
-
- if (p < 0.5) {
- ret = -Double.MAX_VALUE;
- } else {
- ret = mean;
- }
-
- return ret;
- }
-
- /** {@inheritDoc} */
- @Override
- protected double getDomainUpperBound(double p) {
- double ret;
-
- if (p < 0.5) {
- ret = mean;
- } else {
- ret = Double.MAX_VALUE;
- }
-
- return ret;
- }
-
- /** {@inheritDoc} */
- @Override
- protected double getInitialDomain(double p) {
- double ret;
-
- if (p < 0.5) {
- ret = mean - standardDeviation;
- } else if (p > 0.5) {
- ret = mean + standardDeviation;
- } else {
- ret = mean;
- }
-
- return ret;
- }
-
- /** {@inheritDoc} */
- @Override
protected double getSolverAbsoluteAccuracy() {
return solverAbsoluteAccuracy;
}
@@ -279,9 +235,9 @@ public class NormalDistribution extends
/**
* {@inheritDoc}
- *
+ *
* The support of this distribution is connected.
- *
+ *
* @return {@code true}
*/
public boolean isSupportConnected() {
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/PascalDistribution.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/PascalDistribution.java?rev=1209963&r1=1209962&r2=1209963&view=diff
==============================================================================
---
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/PascalDistribution.java
(original)
+++
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/PascalDistribution.java
Sat Dec 3 18:23:02 2011
@@ -206,9 +206,9 @@ public class PascalDistribution extends
/**
* {@inheritDoc}
- *
+ *
* The support of this distribution is connected.
- *
+ *
* @return {@code true}
*/
public boolean isSupportConnected() {
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/PoissonDistribution.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/PoissonDistribution.java?rev=1209963&r1=1209962&r2=1209963&view=diff
==============================================================================
---
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/PoissonDistribution.java
(original)
+++
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/PoissonDistribution.java
Sat Dec 3 18:23:02 2011
@@ -139,9 +139,9 @@ public class PoissonDistribution extends
} else if (x == 0) {
ret = FastMath.exp(-mean);
} else {
- ret = FastMath.exp(-SaddlePointExpansion.getStirlingError(x)
- - SaddlePointExpansion.getDeviancePart(x, mean))
- / FastMath.sqrt(MathUtils.TWO_PI * x);
+ ret = FastMath.exp(-SaddlePointExpansion.getStirlingError(x) -
+ SaddlePointExpansion.getDeviancePart(x, mean)) /
+ FastMath.sqrt(MathUtils.TWO_PI * x);
}
return ret;
}
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/RealDistribution.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/RealDistribution.java?rev=1209963&r1=1209962&r2=1209963&view=diff
==============================================================================
---
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/RealDistribution.java
(original)
+++
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/RealDistribution.java
Sat Dec 3 18:23:02 2011
@@ -105,13 +105,16 @@ public interface RealDistribution {
* distribution.
*
* @return the variance (possibly {@code Double.POSITIVE_INFINITY} as
- * for certain cases in {@link TDistributionImpl}) or
- * {@code Double.NaN} if it is not defined
+ * for certain cases in {@link TDistribution}) or {@code Double.NaN} if it
+ * is not defined
*/
double getNumericalVariance();
/**
- * Access the lower bound of the support.
+ * Access the lower bound of the support. This method must return the same
+ * value as {@code inverseCumulativeProbability(0)}. In other words, this
+ * method must return
+ * <p><code>inf {x in R | P(X <= x) > 0}</code>.</p>
*
* @return lower bound of the support (might be
* {@code Double.NEGATIVE_INFINITY})
@@ -119,7 +122,10 @@ public interface RealDistribution {
double getSupportLowerBound();
/**
- * Access the upper bound of the support.
+ * Access the upper bound of the support. This method must return the same
+ * value as {@code inverseCumulativeProbability(1)}. In other words, this
+ * method must return
+ * <p><code>inf {x in R | P(X <= x) = 1}</code>.</p>
*
* @return upper bound of the support (might be
* {@code Double.POSITIVE_INFINITY})
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/TDistribution.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/TDistribution.java?rev=1209963&r1=1209962&r2=1209963&view=diff
==============================================================================
---
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/TDistribution.java
(original)
+++
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/TDistribution.java
Sat Dec 3 18:23:02 2011
@@ -98,11 +98,11 @@ public class TDistribution extends Abstr
public double density(double x) {
final double n = degreesOfFreedom;
final double nPlus1Over2 = (n + 1) / 2;
- return FastMath.exp(Gamma.logGamma(nPlus1Over2)
- - 0.5 * (FastMath.log(FastMath.PI)
- + FastMath.log(n))
- - Gamma.logGamma(n/2)
- - nPlus1Over2 * FastMath.log(1 + x * x /n));
+ return FastMath.exp(Gamma.logGamma(nPlus1Over2) -
+ 0.5 * (FastMath.log(FastMath.PI) +
+ FastMath.log(n)) -
+ Gamma.logGamma(n / 2) -
+ nPlus1Over2 * FastMath.log(1 + x * x / n));
}
/** {@inheritDoc} */
@@ -145,24 +145,6 @@ public class TDistribution extends Abstr
/** {@inheritDoc} */
@Override
- protected double getDomainLowerBound(double p) {
- return -Double.MAX_VALUE;
- }
-
- /** {@inheritDoc} */
- @Override
- protected double getDomainUpperBound(double p) {
- return Double.MAX_VALUE;
- }
-
- /** {@inheritDoc} */
- @Override
- protected double getInitialDomain(double p) {
- return 0;
- }
-
- /** {@inheritDoc} */
- @Override
protected double getSolverAbsoluteAccuracy() {
return solverAbsoluteAccuracy;
}
@@ -249,9 +231,9 @@ public class TDistribution extends Abstr
/**
* {@inheritDoc}
- *
+ *
* The support of this distribution is connected.
- *
+ *
* @return {@code true}
*/
public boolean isSupportConnected() {
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/WeibullDistribution.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/WeibullDistribution.java?rev=1209963&r1=1209962&r2=1209963&view=diff
==============================================================================
---
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/WeibullDistribution.java
(original)
+++
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/WeibullDistribution.java
Sat Dec 3 18:23:02 2011
@@ -35,21 +35,21 @@ import org.apache.commons.math.util.Fast
* @version $Id$
*/
public class WeibullDistribution extends AbstractRealDistribution {
- /** Serializable version identifier. */
- private static final long serialVersionUID = 8589540077390120676L;
-
/**
* Default inverse cumulative probability accuracy.
* @since 2.1
*/
public static final double DEFAULT_INVERSE_ABSOLUTE_ACCURACY = 1e-9;
-
+
+ /** Serializable version identifier. */
+ private static final long serialVersionUID = 8589540077390120676L;
+
/** The shape parameter. */
private final double shape;
-
+
/** The scale parameter. */
private final double scale;
-
+
/** Inverse cumulative probability accuracy. */
private final double solverAbsoluteAccuracy;
@@ -188,25 +188,6 @@ public class WeibullDistribution extends
return ret;
}
- /** {@inheritDoc} */
- @Override
- protected double getDomainLowerBound(double p) {
- return 0;
- }
-
- /** {@inheritDoc} */
- @Override
- protected double getDomainUpperBound(double p) {
- return Double.MAX_VALUE;
- }
-
- /** {@inheritDoc} */
- @Override
- protected double getInitialDomain(double p) {
- // use median
- return FastMath.pow(scale * FastMath.log(2.0), 1.0 / shape);
- }
-
/**
* Return the absolute accuracy setting of the solver used to estimate
* inverse cumulative probabilities.
@@ -235,7 +216,7 @@ public class WeibullDistribution extends
/**
* used by {@link #getNumericalMean()}
- *
+ *
* @return the mean of this distribution
*/
protected double calculateNumericalMean() {
@@ -261,7 +242,7 @@ public class WeibullDistribution extends
/**
* used by {@link #getNumericalVariance()}
- *
+ *
* @return the variance of this distribution
*/
protected double calculateNumericalVariance() {
@@ -269,8 +250,8 @@ public class WeibullDistribution extends
final double sc = getScale();
final double mn = getNumericalMean();
- return (sc * sc) * FastMath.exp(Gamma.logGamma(1 + (2 / sh)))
- - (mn * mn);
+ return (sc * sc) * FastMath.exp(Gamma.logGamma(1 + (2 / sh))) -
+ (mn * mn);
}
/**
@@ -309,9 +290,9 @@ public class WeibullDistribution extends
/**
* {@inheritDoc}
- *
+ *
* The support of this distribution is connected.
- *
+ *
* @return {@code true}
*/
public boolean isSupportConnected() {
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ZipfDistribution.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ZipfDistribution.java?rev=1209963&r1=1209962&r2=1209963&view=diff
==============================================================================
---
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ZipfDistribution.java
(original)
+++
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ZipfDistribution.java
Sat Dec 3 18:23:02 2011
@@ -143,7 +143,7 @@ public class ZipfDistribution extends Ab
/**
* Used by {@link #getNumericalMean()}.
- *
+ *
* @return the mean of this distribution
*/
protected double calculateNumericalMean() {
@@ -177,7 +177,7 @@ public class ZipfDistribution extends Ab
/**
* used by {@link #getNumericalVariance()}
- *
+ *
* @return the variance of this distribution
*/
protected double calculateNumericalVariance() {
@@ -232,9 +232,9 @@ public class ZipfDistribution extends Ab
/**
* {@inheritDoc}
- *
+ *
* The support of this distribution is connected.
- *
+ *
* @return {@code true}
*/
public boolean isSupportConnected() {
Modified:
commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/AbstractRealDistributionTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/AbstractRealDistributionTest.java?rev=1209963&r1=1209962&r2=1209963&view=diff
==============================================================================
---
commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/AbstractRealDistributionTest.java
(original)
+++
commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/AbstractRealDistributionTest.java
Sat Dec 3 18:23:02 2011
@@ -64,21 +64,6 @@ public class AbstractRealDistributionTes
return 0.0;
}
- @Override
- protected double getDomainLowerBound(final double p) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- protected double getDomainUpperBound(final double p) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- protected double getInitialDomain(final double p) {
- throw new UnsupportedOperationException();
- }
-
public double getNumericalMean() {
return ((x0 + x1) * p12 + (x2 + x3) * (1.0 - p12)) / 2.0;
}
@@ -164,21 +149,6 @@ public class AbstractRealDistributionTes
}
}
- @Override
- protected double getDomainLowerBound(final double p) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- protected double getDomainUpperBound(final double p) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- protected double getInitialDomain(final double p) {
- throw new UnsupportedOperationException();
- }
-
public double getNumericalMean() {
final UnivariateFunction f = new UnivariateFunction() {