You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2010/09/30 14:55:03 UTC
svn commit: r1003048 [1/2] - in /commons/proper/math/trunk/src:
main/java/org/apache/commons/math/distribution/
main/java/org/apache/commons/math/exception/
main/java/org/apache/commons/math/exception/util/
main/java/org/apache/commons/math/stat/infere...
Author: erans
Date: Thu Sep 30 12:55:02 2010
New Revision: 1003048
URL: http://svn.apache.org/viewvc?rev=1003048&view=rev
Log:
ade all distribution classes immutable (as per the conclusion of MATH-349).
Modified two classes in the "stat" package where some code conflicted with
ditribution immutability.
Replaced instances of "IllegalArgumentException" with an appropriate stateful
exception.
Cleaned up Javadoc comments.
Removed:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/HasDensity.java
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/BetaDistribution.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/CauchyDistributionImpl.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/ChiSquaredDistributionImpl.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ContinuousDistribution.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/ExponentialDistributionImpl.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/FDistributionImpl.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/GammaDistributionImpl.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/NormalDistributionImpl.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/TDistributionImpl.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/WeibullDistributionImpl.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/OutOfRangeException.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/LocalizedFormats.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/TTestImpl.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/regression/SimpleRegression.java
commons/proper/math/trunk/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties
commons/proper/math/trunk/src/site/xdoc/changes.xml
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/FDistributionTest.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
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=1003048&r1=1003047&r2=1003048&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 Thu Sep 30 12:55:02 2010
@@ -21,11 +21,12 @@ import java.io.Serializable;
import org.apache.commons.math.ConvergenceException;
import org.apache.commons.math.FunctionEvaluationException;
import org.apache.commons.math.MathException;
-import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.analysis.UnivariateRealFunction;
import org.apache.commons.math.analysis.solvers.BrentSolver;
import org.apache.commons.math.analysis.solvers.UnivariateRealSolverUtils;
import org.apache.commons.math.exception.util.LocalizedFormats;
+import org.apache.commons.math.exception.OutOfRangeException;
+import org.apache.commons.math.exception.NotStrictlyPositiveException;
import org.apache.commons.math.random.RandomDataImpl;
import org.apache.commons.math.util.FastMath;
@@ -39,57 +40,42 @@ import org.apache.commons.math.util.Fast
public abstract class AbstractContinuousDistribution
extends AbstractDistribution
implements ContinuousDistribution, Serializable {
-
/** Serializable version identifier */
private static final long serialVersionUID = -38038050983108802L;
-
/**
* RandomData instance used to generate samples from the distribution
* @since 2.2
*/
protected final RandomDataImpl randomData = new RandomDataImpl();
-
/**
* Solver absolute accuracy for inverse cum computation
* @since 2.1
*/
private double solverAbsoluteAccuracy = BrentSolver.DEFAULT_ABSOLUTE_ACCURACY;
-
/**
* Default constructor.
*/
- protected AbstractContinuousDistribution() {
- super();
- }
+ protected AbstractContinuousDistribution() {}
/**
- * Return the probability density for a particular point.
- * @param x The point at which the density should be computed.
- * @return The pdf at point x.
- * @throws MathRuntimeException if the specialized class hasn't implemented this function
- * @since 2.1
+ * {@inheritDoc}
*/
- public double density(double x) throws MathRuntimeException {
- throw new MathRuntimeException(new UnsupportedOperationException(),
- LocalizedFormats.NO_DENSITY_FOR_THIS_DISTRIBUTION);
- }
+ public abstract double density(double x);
/**
- * For this distribution, X, this method returns the critical point x, such
- * that P(X < x) = <code>p</code>.
+ * For this distribution, {@code X}, this method returns the critical
+ * point {@code x}, such that {@code P(X < x) = p}.
*
- * @param p the desired probability
- * @return x, such that P(X < x) = <code>p</code>
+ * @param p Desired probability.
+ * @return {@code x}, such that {@code P(X < x) = p}.
* @throws MathException if the inverse cumulative probability can not be
- * computed due to convergence or other numerical errors.
- * @throws IllegalArgumentException if <code>p</code> is not a valid
- * probability.
+ * computed due to convergence or other numerical errors.
+ * @throws OutOfRangeException if {@code p} is not a valid probability.
*/
public double inverseCumulativeProbability(final double p)
throws MathException {
if (p < 0.0 || p > 1.0) {
- throw MathRuntimeException.createIllegalArgumentException(
- LocalizedFormats.OUT_OF_RANGE_SIMPLE, p, 0.0, 1.0);
+ throw new OutOfRangeException(p, 0, 1);
}
// by default, do simple root finding using bracketing and default solver.
@@ -101,7 +87,8 @@ public abstract class AbstractContinuous
try {
ret = cumulativeProbability(x) - p;
} catch (MathException ex) {
- throw new FunctionEvaluationException(ex, x, ex.getLocalizablePattern(), ex.getArguments());
+ throw new FunctionEvaluationException(ex, x, ex.getLocalizablePattern(),
+ ex.getArguments());
}
if (Double.isNaN(ret)) {
throw new FunctionEvaluationException(x,
@@ -119,7 +106,7 @@ public abstract class AbstractContinuous
bracket = UnivariateRealSolverUtils.bracket(
rootFindingFunction, getInitialDomain(p),
lowerBound, upperBound);
- } catch (ConvergenceException ex) {
+ } catch (ConvergenceException ex) {
/*
* Check domain endpoints to see if one gives value that is within
* the default solver's defaultAbsoluteAccuracy of 0 (will be the
@@ -144,9 +131,9 @@ public abstract class AbstractContinuous
}
/**
- * Reseeds the random generator used to generate samples.
+ * Reseed the random generator used to generate samples.
*
- * @param seed the new seed
+ * @param seed New seed.
* @since 2.2
*/
public void reseedRandomGenerator(long seed) {
@@ -154,31 +141,34 @@ public abstract class AbstractContinuous
}
/**
- * Generates a random value sampled from this distribution. The default
+ * Generate a random value sampled from this distribution. The default
* implementation uses the
- * <a href="http://en.wikipedia.org/wiki/Inverse_transform_sampling"> inversion method.</a>
+ * <a href="http://en.wikipedia.org/wiki/Inverse_transform_sampling">
+ * inversion method.
+ * </a>
*
- * @return random value
+ * @return a random value.
+ * @throws MathException if an error occurs generating the random value.
* @since 2.2
- * @throws MathException if an error occurs generating the random value
*/
public double sample() throws MathException {
return randomData.nextInversionDeviate(this);
}
/**
- * Generates a random sample from the distribution. The default implementation
+ * Generate a random sample from the distribution. The default implementation
* generates the sample by calling {@link #sample()} in a loop.
*
- * @param sampleSize number of random values to generate
+ * @param sampleSize Number of random values to generate.
+ * @return an array representing the random sample.
+ * @throws MathException if an error occurs generating the sample.
+ * @throws NotStrictlyPositiveException if {@code sampleSize} is not positive.
* @since 2.2
- * @return an array representing the random sample
- * @throws MathException if an error occurs generating the sample
- * @throws IllegalArgumentException if sampleSize is not positive
*/
public double[] sample(int sampleSize) throws MathException {
if (sampleSize <= 0) {
- MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NOT_POSITIVE_SAMPLE_SIZE, sampleSize);
+ throw new NotStrictlyPositiveException(LocalizedFormats.NUMBER_OF_SAMPLES,
+ sampleSize);
}
double[] out = new double[sampleSize];
for (int i = 0; i < sampleSize; i++) {
@@ -188,34 +178,32 @@ public abstract class AbstractContinuous
}
/**
- * Access the initial domain value, based on <code>p</code>, used to
+ * 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 the desired probability for the critical value
- * @return initial domain value
+ * @param p Desired probability for the critical value.
+ * @return the initial domain value.
*/
protected abstract double getInitialDomain(double p);
/**
- * Access the domain value lower bound, based on <code>p</code>, used to
+ * 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 the desired probability for the critical value
- * @return domain value lower bound, i.e.
- * P(X < <i>lower bound</i>) < <code>p</code>
+ * @param p Desired probability for the critical value.
+ * @return the domain value lower bound, i.e. {@code P(X < 'lower bound') < p}.
*/
protected abstract double getDomainLowerBound(double p);
/**
- * Access the domain value upper bound, based on <code>p</code>, used to
+ * 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 the desired probability for the critical value
- * @return domain value upper bound, i.e.
- * P(X < <i>upper bound</i>) > <code>p</code>
+ * @param p Desired probability for the critical value.
+ * @return the domain value upper bound, i.e. {@code P(X < 'upper bound') > p}.
*/
protected abstract double getDomainUpperBound(double p);
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=1003048&r1=1003047&r2=1003048&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 Thu Sep 30 12:55:02 2010
@@ -37,12 +37,4 @@ public interface BetaDistribution extend
* @return beta.
*/
double getBeta();
-
- /**
- * Return the probability density for a particular point.
- *
- * @param x Point at which the density should be computed.
- * @return the pdf at point {@code x}.
- */
- double density(double x);
}
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=1003048&r1=1003047&r2=1003048&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 Thu Sep 30 12:55:02 2010
@@ -23,8 +23,9 @@ package org.apache.commons.math.distribu
* <p>
* References:
* <ul>
- * <li><a href="http://mathworld.wolfram.com/CauchyDistribution.html">
- * Cauchy Distribution</a></li>
+ * <li><a href="http://mathworld.wolfram.com/CauchyDistribution.html">
+ * Cauchy Distribution</a>
+ * </li>
* </ul>
* </p>
*
@@ -32,32 +33,17 @@ package org.apache.commons.math.distribu
* @version $Revision$ $Date$
*/
public interface CauchyDistribution extends ContinuousDistribution {
-
/**
* Access the median.
- * @return median for this distribution
+ *
+ * @return the median for this distribution.
*/
double getMedian();
/**
* Access the scale parameter.
- * @return scale parameter for this distribution
+ *
+ * @return the scale parameter for this distribution.
*/
double getScale();
-
- /**
- * Modify the median.
- * @param median for this distribution
- * @deprecated as of v2.1
- */
- @Deprecated
- void setMedian(double median);
-
- /**
- * Modify the scale parameter.
- * @param s scale parameter for this distribution
- * @deprecated as of v2.1
- */
- @Deprecated
- void setScale(double s);
}
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=1003048&r1=1003047&r2=1003048&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 Thu Sep 30 12:55:02 2010
@@ -19,7 +19,8 @@ package org.apache.commons.math.distribu
import java.io.Serializable;
-import org.apache.commons.math.MathRuntimeException;
+import org.apache.commons.math.exception.NotStrictlyPositiveException;
+import org.apache.commons.math.exception.OutOfRangeException;
import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.util.FastMath;
@@ -32,22 +33,17 @@ import org.apache.commons.math.util.Fast
*/
public class CauchyDistributionImpl extends AbstractContinuousDistribution
implements CauchyDistribution, Serializable {
-
/**
* 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 median of this distribution. */
private double median = 0;
-
/** The scale of this distribution. */
private double scale = 1;
-
/** Inverse cumulative probability accuracy */
private final double solverAbsoluteAccuracy;
@@ -55,65 +51,67 @@ public class CauchyDistributionImpl exte
* Creates cauchy distribution with the medain equal to zero and scale
* equal to one.
*/
- public CauchyDistributionImpl(){
- this(0.0, 1.0);
+ public CauchyDistributionImpl() {
+ this(0, 1);
}
/**
* Create a cauchy distribution using the given median and scale.
- * @param median median for this distribution
- * @param s scale parameter for this distribution
+ *
+ * @param median Median for this distribution.
+ * @param scale Scale parameter for this distribution.
*/
- public CauchyDistributionImpl(double median, double s){
- this(median, s, DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
+ public CauchyDistributionImpl(double median, double scale) {
+ this(median, scale, DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
}
/**
* Create a cauchy distribution using the given median and scale.
- * @param median median for this distribution
- * @param s scale parameter for this distribution
- * @param inverseCumAccuracy the maximum absolute error in inverse cumulative probability estimates
- * (defaults to {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY})
+ *
+ * @param median Median for this distribution.
+ * @param scale Scale parameter for this distribution.
+ * @param inverseCumAccuracy Maximum absolute error in inverse
+ * cumulative probability estimates
+ * (defaults to {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}).
+ * @throws NotStrictlyPositiveException if {@code s <= 0}.
* @since 2.1
*/
- public CauchyDistributionImpl(double median, double s, double inverseCumAccuracy) {
- super();
- setMedianInternal(median);
- setScaleInternal(s);
+ public CauchyDistributionImpl(double median, double scale,
+ double inverseCumAccuracy) {
+ if (scale <= 0) {
+ throw new NotStrictlyPositiveException(LocalizedFormats.SCALE, scale);
+ }
+ this.scale = scale;
+ this.median = median;
solverAbsoluteAccuracy = inverseCumAccuracy;
}
/**
- * For this distribution, X, this method returns P(X < <code>x</code>).
- * @param x the value at which the CDF is evaluated.
- * @return CDF evaluted at <code>x</code>.
+ * For this distribution, {@code X}, this method returns {@code P(X < x)}.
+ *
+ * @param x Value at which the CDF is evaluated.
+ * @return CDF evaluted at {@code x}.
*/
public double cumulativeProbability(double x) {
return 0.5 + (FastMath.atan((x - median) / scale) / FastMath.PI);
}
/**
- * Access the median.
- * @return median for this distribution
+ * {@inheritDoc}
*/
public double getMedian() {
return median;
}
/**
- * Access the scale parameter.
- * @return scale parameter for this distribution
+ * {@inheritDoc}
*/
public double getScale() {
return scale;
}
/**
- * Returns the probability density for a particular point.
- *
- * @param x The point at which the density should be computed.
- * @return The pdf at point x.
- * @since 2.1
+ * {@inheritDoc}
*/
@Override
public double density(double x) {
@@ -122,23 +120,20 @@ public class CauchyDistributionImpl exte
}
/**
- * For this distribution, X, this method returns the critical point x, such
- * that P(X < x) = <code>p</code>.
- * <p>
- * Returns <code>Double.NEGATIVE_INFINITY</code> for p=0 and
- * <code>Double.POSITIVE_INFINITY</code> for p=1.</p>
- *
- * @param p the desired probability
- * @return x, such that P(X < x) = <code>p</code>
- * @throws IllegalArgumentException if <code>p</code> is not a valid
- * probability.
+ * For this distribution, {@code X}, this method returns the critical
+ * point {@code x}, such that {@code P(X < x) = p}.
+ * It will return {@code Double.NEGATIVE_INFINITY} when p = 0 and
+ * {@code Double.POSITIVE_INFINITY} when p = 1.
+ *
+ * @param p Desired probability.
+ * @return {@code x}, such that {@code P(X < x) = p}.
+ * @throws OutOfRangeException if {@code p} is not a valid probability.
*/
@Override
public double inverseCumulativeProbability(double p) {
double ret;
- if (p < 0.0 || p > 1.0) {
- throw MathRuntimeException.createIllegalArgumentException(
- LocalizedFormats.OUT_OF_RANGE_SIMPLE, p, 0.0, 1.0);
+ if (p < 0 || p > 1) {
+ throw new OutOfRangeException(p, 0, 1);
} else if (p == 0) {
ret = Double.NEGATIVE_INFINITY;
} else if (p == 1) {
@@ -150,59 +145,18 @@ public class CauchyDistributionImpl exte
}
/**
- * Modify the median.
- * @param median for this distribution
- * @deprecated as of 2.1 (class will become immutable in 3.0)
- */
- @Deprecated
- public void setMedian(double median) {
- setMedianInternal(median);
- }
- /**
- * Modify the median.
- * @param newMedian for this distribution
- */
- private void setMedianInternal(double newMedian) {
- this.median = newMedian;
- }
-
- /**
- * Modify the scale parameter.
- * @param s scale parameter for this distribution
- * @throws IllegalArgumentException if <code>sd</code> is not positive.
- * @deprecated as of 2.1 (class will become immutable in 3.0)
- */
- @Deprecated
- public void setScale(double s) {
- setScaleInternal(s);
- }
- /**
- * Modify the scale parameter.
- * @param s scale parameter for this distribution
- * @throws IllegalArgumentException if <code>sd</code> is not positive.
- */
- private void setScaleInternal(double s) {
- if (s <= 0.0) {
- throw MathRuntimeException.createIllegalArgumentException(
- LocalizedFormats.NOT_POSITIVE_SCALE, s);
- }
- scale = s;
- }
-
- /**
- * Access the domain value lower bound, based on <code>p</code>, used to
+ * 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 the desired probability for the critical value
- * @return domain value lower bound, i.e.
- * P(X < <i>lower bound</i>) < <code>p</code>
+ * @param p Desired probability for the critical value.
+ * @return domain value lower bound, i.e. {@code P(X < 'lower bound') < p}.
*/
@Override
protected double getDomainLowerBound(double p) {
double ret;
- if (p < .5) {
+ if (p < 0.5) {
ret = -Double.MAX_VALUE;
} else {
ret = median;
@@ -216,15 +170,14 @@ public class CauchyDistributionImpl exte
* bracket a CDF root. This method is used by
* {@link #inverseCumulativeProbability(double)} to find critical values.
*
- * @param p the desired probability for the critical value
- * @return domain value upper bound, i.e.
- * P(X < <i>upper bound</i>) > <code>p</code>
+ * @param p Desired probability for the critical value.
+ * @return domain value lower bound, i.e. {@code P(X < 'upper bound') > p}.
*/
@Override
protected double getDomainUpperBound(double p) {
double ret;
- if (p < .5) {
+ if (p < 0.5) {
ret = median;
} else {
ret = Double.MAX_VALUE;
@@ -234,20 +187,20 @@ public class CauchyDistributionImpl exte
}
/**
- * Access the initial domain value, based on <code>p</code>, used to
+ * 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 the desired probability for the critical value
- * @return initial domain value
+ * @param p Desired probability for the critical value.
+ * @return the initial domain value.
*/
@Override
protected double getInitialDomain(double p) {
double ret;
- if (p < .5) {
+ if (p < 0.5) {
ret = median - scale;
- } else if (p > .5) {
+ } else if (p > 0.5) {
ret = median + scale;
} else {
ret = median;
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=1003048&r1=1003047&r2=1003048&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 Thu Sep 30 12:55:02 2010
@@ -31,15 +31,9 @@ package org.apache.commons.math.distribu
*/
public interface ChiSquaredDistribution extends ContinuousDistribution {
/**
- * Access the degrees of freedom.
+ * Access the number of degrees of freedom.
+ *
* @return the degrees of freedom.
*/
double getDegreesOfFreedom();
-
- /**
- * Return the probability density for a particular point.
- * @param x The point at which the density should be computed.
- * @return The pdf at point x.
- */
- double density(double x);
}
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=1003048&r1=1003047&r2=1003048&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 Thu Sep 30 12:55:02 2010
@@ -73,11 +73,7 @@ public class ChiSquaredDistributionImpl
}
/**
- * Return the probability density for a particular point.
- *
- * @param x The point at which the density should be computed.
- * @return The pdf at point x.
- * @since 2.1
+ * {@inheritDoc}
*/
@Override
public double density(double x) {
@@ -85,28 +81,29 @@ public class ChiSquaredDistributionImpl
}
/**
- * For this distribution, X, this method returns P(X < x).
+ * For this distribution, {@code X}, this method returns {@code P(X < x)}.
+ *
* @param x the value at which the CDF is evaluated.
* @return CDF for this distribution.
- * @throws MathException if the cumulative probability can not be
- * computed due to convergence or other numerical errors.
+ * @throws MathException if the cumulative probability cannot be
+ * computed due to convergence or other numerical errors.
*/
public double cumulativeProbability(double x) throws MathException {
return gamma.cumulativeProbability(x);
}
/**
- * For this distribution, X, this method returns the critical point x, such
- * that P(X < x) = <code>p</code>.
- * <p>
- * Returns 0 for p=0 and <code>Double.POSITIVE_INFINITY</code> for p=1.</p>
+ * For this distribution, X, this method returns the critical point
+ * {@code x}, such that {@code P(X < x) = p}.
+ * It will return 0 when p = 0 and {@code Double.POSITIVE_INFINITY}
+ * when p = 1.
*
- * @param p the desired probability
- * @return x, such that P(X < x) = <code>p</code>
+ * @param p Desired probability.
+ * @return {@code x}, such that {@code P(X < x) = p}.
* @throws MathException if the inverse cumulative probability can not be
- * computed due to convergence or other numerical errors.
- * @throws IllegalArgumentException if <code>p</code> is not a valid
- * probability.
+ * computed due to convergence or other numerical errors.
+ * @throws org.apache.commons.math.exception.OutOfRangeException if
+ * {@code p} is not a valid probability.
*/
@Override
public double inverseCumulativeProbability(final double p)
@@ -121,13 +118,12 @@ public class ChiSquaredDistributionImpl
}
/**
- * Access the domain value lower bound, based on <code>p</code>, used to
+ * 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 the desired probability for the critical value
- * @return domain value lower bound, i.e.
- * P(X < <i>lower bound</i>) < <code>p</code>
+ * @return domain value lower bound, i.e. {@code P(X < 'lower bound') < p}.
*/
@Override
protected double getDomainLowerBound(double p) {
@@ -135,13 +131,12 @@ public class ChiSquaredDistributionImpl
}
/**
- * Access the domain value upper bound, based on <code>p</code>, used to
+ * 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 the desired probability for the critical value
- * @return domain value upper bound, i.e.
- * P(X < <i>upper bound</i>) > <code>p</code>
+ * @param p Desired probability for the critical value.
+ * @return domain value upper bound, i.e. {@code P(X < 'upper bound') > p}.
*/
@Override
protected double getDomainUpperBound(double p) {
@@ -162,12 +157,12 @@ public class ChiSquaredDistributionImpl
}
/**
- * Access the initial domain value, based on <code>p</code>, used to
+ * 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 the desired probability for the critical value
- * @return initial domain value
+ * @param p Desired probability for the critical value.
+ * @return the initial domain value.
*/
@Override
protected double getInitialDomain(double p) {
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ContinuousDistribution.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ContinuousDistribution.java?rev=1003048&r1=1003047&r2=1003048&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ContinuousDistribution.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ContinuousDistribution.java Thu Sep 30 12:55:02 2010
@@ -19,25 +19,27 @@ package org.apache.commons.math.distribu
import org.apache.commons.math.MathException;
/**
- * <p>Base interface for continuous distributions.</p>
- *
- * <p>Note: this interface will be extended in version 3.0 to include
- * <br/><code>public double density(double x)</code><br/>
- * that is, from version 3.0 forward, continuous distributions <strong>must</strong>
- * include implementations of probability density functions. As of version
- * 2.1, all continuous distribution implementations included in commons-math
- * provide implementations of this method.</p>
+ * Base interface for continuous distributions.
*
* @version $Revision$ $Date$
*/
public interface ContinuousDistribution extends Distribution {
-
/**
- * For this distribution, X, this method returns x such that P(X < x) = p.
- * @param p the cumulative probability.
- * @return x.
- * @throws MathException if the inverse cumulative probability can not be
- * computed due to convergence or other numerical errors.
+ * For a distribution, {@code X}, compute {@code x} such that
+ * {@code P(X < x) = p}.
+ *
+ * @param p Cumulative probability.
+ * @return {@code x} such that {@code P(X < x) = p}.
+ * @throws MathException if the inverse cumulative probability cannot be
+ * computed due to convergence or other numerical errors.
*/
double inverseCumulativeProbability(double p) throws MathException;
+
+ /**
+ * Probability density for a particular point.
+ *
+ * @param x Point at which the density should be computed.
+ * @return the pdf at point {@code x}.
+ */
+ double density(double x);
}
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=1003048&r1=1003047&r2=1003048&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 Thu Sep 30 12:55:02 2010
@@ -36,12 +36,4 @@ public interface ExponentialDistribution
* @return the mean.
*/
double getMean();
-
- /**
- * Return the probability density for a particular point.
- *
- * @param x Point at which the density should be computed.
- * @return the pdf at point {@code x}.
- */
- double density(double x);
}
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=1003048&r1=1003047&r2=1003048&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 Thu Sep 30 12:55:02 2010
@@ -53,8 +53,9 @@ public class ExponentialDistributionImpl
/**
* Create a exponential distribution with the given mean.
- * @param mean mean of this distribution.
- * @param inverseCumAccuracy the maximum absolute error in inverse
+ *
+ * @param mean Mean of this distribution.
+ * @param inverseCumAccuracy Maximum absolute error in inverse
* cumulative probability estimates (defaults to
* {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}).
* @throws NotStrictlyPositiveException if {@code mean <= 0}.
@@ -96,7 +97,7 @@ public class ExponentialDistributionImpl
* Exponential Distribution</a>, equation (1).</li>
* </ul>
*
- * @param x the value at which the CDF is evaluated.
+ * @param x Value at which the CDF is evaluated.
* @return the CDF for this distribution.
* @throws MathException if the cumulative probability can not be
* computed due to convergence or other numerical errors.
@@ -114,9 +115,10 @@ public class ExponentialDistributionImpl
/**
* For this distribution, X, this method returns the critical point x, such
* that {@code P(X < x) = p}.
- * Returns 0 when p = 0 and {@code Double.POSITIVE_INFINITY} when p = 1.
+ * It will return 0 when p = 0 and {@code Double.POSITIVE_INFINITY}
+ * when p = 1.
*
- * @param p the desired probability
+ * @param p Desired probability.
* @return {@code x}, such that {@code P(X < x) = p}.
* @throws MathException if the inverse cumulative probability can not be
* computed due to convergence or other numerical errors.
@@ -167,7 +169,7 @@ public class ExponentialDistributionImpl
}
/**
- * Access the domain value upper bound, based on <code>p</code>, used to
+ * Access the domain value upper bound, based on {@code p}, used to
* bracket a CDF root.
*
* @param p Desired probability for the critical value.
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=1003048&r1=1003047&r2=1003048&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 Thu Sep 30 12:55:02 2010
@@ -31,29 +31,15 @@ package org.apache.commons.math.distribu
*/
public interface FDistribution extends ContinuousDistribution {
/**
- * Modify the numerator degrees of freedom.
- * @param degreesOfFreedom the new numerator degrees of freedom.
- * @deprecated as of v2.1
- */
- @Deprecated
- void setNumeratorDegreesOfFreedom(double degreesOfFreedom);
-
- /**
* Access the numerator degrees of freedom.
+ *
* @return the numerator degrees of freedom.
*/
double getNumeratorDegreesOfFreedom();
/**
- * Modify the denominator degrees of freedom.
- * @param degreesOfFreedom the new denominator degrees of freedom.
- * @deprecated as of v2.1
- */
- @Deprecated
- void setDenominatorDegreesOfFreedom(double degreesOfFreedom);
-
- /**
* Access the denominator degrees of freedom.
+ *
* @return the denominator degrees of freedom.
*/
double getDenominatorDegreesOfFreedom();
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=1003048&r1=1003047&r2=1003048&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 Thu Sep 30 12:55:02 2010
@@ -14,12 +14,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.commons.math.distribution;
import java.io.Serializable;
import org.apache.commons.math.MathException;
-import org.apache.commons.math.MathRuntimeException;
+import org.apache.commons.math.exception.NotStrictlyPositiveException;
import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.special.Beta;
import org.apache.commons.math.util.FastMath;
@@ -33,48 +34,58 @@ import org.apache.commons.math.util.Fast
public class FDistributionImpl
extends AbstractContinuousDistribution
implements FDistribution, Serializable {
-
/**
* 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 double numeratorDegreesOfFreedom;
-
/** The numerator degrees of freedom*/
private double denominatorDegreesOfFreedom;
-
/** Inverse cumulative probability accuracy */
private final double solverAbsoluteAccuracy;
/**
* Create a F distribution using the given degrees of freedom.
- * @param numeratorDegreesOfFreedom the numerator degrees of freedom.
- * @param denominatorDegreesOfFreedom the denominator degrees of freedom.
+ * @param numeratorDegreesOfFreedom Numerator degrees of freedom.
+ * @param denominatorDegreesOfFreedom Denominator degrees of freedom.
+ * @throws NotStrictlyPositiveException if {@code numeratorDegreesOfFreedom <= 0}
+ * or {@code denominatorDegreesOfFreedom <= 0}.
*/
public FDistributionImpl(double numeratorDegreesOfFreedom,
double denominatorDegreesOfFreedom) {
- this(numeratorDegreesOfFreedom, denominatorDegreesOfFreedom, DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
+ this(numeratorDegreesOfFreedom, denominatorDegreesOfFreedom,
+ DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
}
/**
- * Create a F distribution using the given degrees of freedom and inverse cumulative probability accuracy.
- * @param numeratorDegreesOfFreedom the numerator degrees of freedom.
- * @param denominatorDegreesOfFreedom the denominator degrees of freedom.
- * @param inverseCumAccuracy the maximum absolute error in inverse cumulative probability estimates
+ * Create an F distribution using the given degrees of freedom
+ * and inverse cumulative probability accuracy.
+ * @param numeratorDegreesOfFreedom Numerator degrees of freedom.
+ * @param denominatorDegreesOfFreedom Denominator degrees of freedom.
+ * @param inverseCumAccuracy the maximum absolute error in inverse
+ * cumulative probability estimates.
* (defaults to {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY})
+ * @throws NotStrictlyPositiveException if {@code numeratorDegreesOfFreedom <= 0}
+ * or {@code denominatorDegreesOfFreedom <= 0}.
* @since 2.1
*/
- public FDistributionImpl(double numeratorDegreesOfFreedom, double denominatorDegreesOfFreedom,
- double inverseCumAccuracy) {
- super();
- setNumeratorDegreesOfFreedomInternal(numeratorDegreesOfFreedom);
- setDenominatorDegreesOfFreedomInternal(denominatorDegreesOfFreedom);
+ public FDistributionImpl(double numeratorDegreesOfFreedom,
+ double denominatorDegreesOfFreedom,
+ double inverseCumAccuracy) {
+ if (numeratorDegreesOfFreedom <= 0) {
+ throw new NotStrictlyPositiveException(LocalizedFormats.DEGREES_OF_FREEDOM,
+ numeratorDegreesOfFreedom);
+ }
+ if (denominatorDegreesOfFreedom <= 0) {
+ throw new NotStrictlyPositiveException(LocalizedFormats.DEGREES_OF_FREEDOM,
+ denominatorDegreesOfFreedom);
+ }
+ this.numeratorDegreesOfFreedom = numeratorDegreesOfFreedom;
+ this.denominatorDegreesOfFreedom = denominatorDegreesOfFreedom;
solverAbsoluteAccuracy = inverseCumAccuracy;
}
@@ -92,30 +103,33 @@ public class FDistributionImpl
final double logx = FastMath.log(x);
final double logn = FastMath.log(numeratorDegreesOfFreedom);
final double logm = FastMath.log(denominatorDegreesOfFreedom);
- final double lognxm = FastMath.log(numeratorDegreesOfFreedom * x + denominatorDegreesOfFreedom);
- return FastMath.exp(nhalf*logn + nhalf*logx - logx + mhalf*logm - nhalf*lognxm -
- mhalf*lognxm - Beta.logBeta(nhalf, mhalf));
+ final double lognxm = FastMath.log(numeratorDegreesOfFreedom * x +
+ denominatorDegreesOfFreedom);
+ return FastMath.exp(nhalf * logn + nhalf * logx - logx +
+ mhalf * logm - nhalf * lognxm - mhalf * lognxm -
+ Beta.logBeta(nhalf, mhalf));
}
/**
- * For this distribution, X, this method returns P(X < x).
+ * For this distribution, {@code X}, this method returns {@code P(X < x)}.
*
- * The implementation of this method is based on:
+ * The implementation of this method is based on
* <ul>
- * <li>
- * <a href="http://mathworld.wolfram.com/F-Distribution.html">
- * F-Distribution</a>, equation (4).</li>
+ * <li>
+ * <a href="http://mathworld.wolfram.com/F-Distribution.html">
+ * F-Distribution</a>, equation (4).
+ * </li>
* </ul>
*
- * @param x the value at which the CDF is evaluated.
+ * @param x Value at which the CDF is evaluated.
* @return CDF for this distribution.
- * @throws MathException if the cumulative probability can not be
- * computed due to convergence or other numerical errors.
+ * @throws MathException if the cumulative probability cannot be
+ * computed due to convergence or other numerical errors.
*/
public double cumulativeProbability(double x) throws MathException {
double ret;
- if (x <= 0.0) {
- ret = 0.0;
+ if (x <= 0) {
+ ret = 0;
} else {
double n = numeratorDegreesOfFreedom;
double m = denominatorDegreesOfFreedom;
@@ -128,23 +142,22 @@ public class FDistributionImpl
}
/**
- * For this distribution, X, this method returns the critical point x, such
- * that P(X < x) = <code>p</code>.
- * <p>
- * Returns 0 for p=0 and <code>Double.POSITIVE_INFINITY</code> for p=1.</p>
- *
- * @param p the desired probability
- * @return x, such that P(X < x) = <code>p</code>
- * @throws MathException if the inverse cumulative probability can not be
- * computed due to convergence or other numerical errors.
- * @throws IllegalArgumentException if <code>p</code> is not a valid
- * probability.
+ * For this distribution, {@code X}, this method returns the critical
+ * point {@code x}, such that {@code P(X < x) = p}.
+ * Returns 0 when p = 0 and {@code Double.POSITIVE_INFINITY} when p = 1.
+ *
+ * @param p Desired probability.
+ * @return {@code x}, such that {@code P(X < x) = p}.
+ * @throws MathException if the inverse cumulative probability cannot be
+ * computed due to convergence or other numerical errors.
+ * @throws IllegalArgumentException if {@code p} is not a valid
+ * probability.
*/
@Override
public double inverseCumulativeProbability(final double p)
throws MathException {
if (p == 0) {
- return 0d;
+ return 0;
}
if (p == 1) {
return Double.POSITIVE_INFINITY;
@@ -153,27 +166,25 @@ public class FDistributionImpl
}
/**
- * Access the domain value lower bound, based on <code>p</code>, used to
+ * 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 the desired probability for the critical value
- * @return domain value lower bound, i.e.
- * P(X < <i>lower bound</i>) < <code>p</code>
+ * @param p Desired probability for the critical value.
+ * @return the domain value lower bound, i.e. {@code P(X < 'lower bound') < p}.
*/
@Override
protected double getDomainLowerBound(double p) {
- return 0.0;
+ return 0;
}
/**
- * Access the domain value upper bound, based on <code>p</code>, used to
+ * 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 the desired probability for the critical value
- * @return domain value upper bound, i.e.
- * P(X < <i>upper bound</i>) > <code>p</code>
+ * @param p Desired probability for the critical value.
+ * @return the domain value upper bound, i.e. {@code P(X < 'upper bound') > p}.
*/
@Override
protected double getDomainUpperBound(double p) {
@@ -181,87 +192,33 @@ public class FDistributionImpl
}
/**
- * Access the initial domain value, based on <code>p</code>, used to
+ * 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 the desired probability for the critical value
- * @return initial domain value
+ * @param p Desired probability for the critical value.
+ * @return the initial domain value.
*/
@Override
protected double getInitialDomain(double p) {
- double ret = 1.0;
+ double ret = 1;
double d = denominatorDegreesOfFreedom;
- if (d > 2.0) {
+ if (d > 2) {
// use mean
- ret = d / (d - 2.0);
+ ret = d / (d - 2);
}
return ret;
}
/**
- * Modify the numerator degrees of freedom.
- * @param degreesOfFreedom the new numerator degrees of freedom.
- * @throws IllegalArgumentException if <code>degreesOfFreedom</code> is not
- * positive.
- * @deprecated as of 2.1 (class will become immutable in 3.0)
- */
- @Deprecated
- public void setNumeratorDegreesOfFreedom(double degreesOfFreedom) {
- setNumeratorDegreesOfFreedomInternal(degreesOfFreedom);
- }
-
- /**
- * Modify the numerator degrees of freedom.
- * @param degreesOfFreedom the new numerator degrees of freedom.
- * @throws IllegalArgumentException if <code>degreesOfFreedom</code> is not
- * positive.
- */
- private void setNumeratorDegreesOfFreedomInternal(double degreesOfFreedom) {
- if (degreesOfFreedom <= 0.0) {
- throw MathRuntimeException.createIllegalArgumentException(
- LocalizedFormats.NOT_POSITIVE_DEGREES_OF_FREEDOM, degreesOfFreedom);
- }
- this.numeratorDegreesOfFreedom = degreesOfFreedom;
- }
-
- /**
- * Access the numerator degrees of freedom.
- * @return the numerator degrees of freedom.
+ * {@inheritDoc}
*/
public double getNumeratorDegreesOfFreedom() {
return numeratorDegreesOfFreedom;
}
/**
- * Modify the denominator degrees of freedom.
- * @param degreesOfFreedom the new denominator degrees of freedom.
- * @throws IllegalArgumentException if <code>degreesOfFreedom</code> is not
- * positive.
- * @deprecated as of 2.1 (class will become immutable in 3.0)
- */
- @Deprecated
- public void setDenominatorDegreesOfFreedom(double degreesOfFreedom) {
- setDenominatorDegreesOfFreedomInternal(degreesOfFreedom);
- }
-
- /**
- * Modify the denominator degrees of freedom.
- * @param degreesOfFreedom the new denominator degrees of freedom.
- * @throws IllegalArgumentException if <code>degreesOfFreedom</code> is not
- * positive.
- */
- private void setDenominatorDegreesOfFreedomInternal(double degreesOfFreedom) {
- if (degreesOfFreedom <= 0.0) {
- throw MathRuntimeException.createIllegalArgumentException(
- LocalizedFormats.NOT_POSITIVE_DEGREES_OF_FREEDOM, degreesOfFreedom);
- }
- this.denominatorDegreesOfFreedom = degreesOfFreedom;
- }
-
- /**
- * Access the denominator degrees of freedom.
- * @return the denominator degrees of freedom.
+ * {@inheritDoc}
*/
public double getDenominatorDegreesOfFreedom() {
return denominatorDegreesOfFreedom;
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=1003048&r1=1003047&r2=1003048&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 Thu Sep 30 12:55:02 2010
@@ -43,12 +43,4 @@ public interface GammaDistribution exten
* @return beta.
*/
double getBeta();
-
- /**
- * Return the probability density for a particular point.
- *
- * @param x Point at which the density should be computed..
- * @return the pdf at point {@code x}.
- */
- double density(double x);
}
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=1003048&r1=1003047&r2=1003048&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 Thu Sep 30 12:55:02 2010
@@ -61,9 +61,10 @@ public class GammaDistributionImpl exten
/**
* Create a new gamma distribution with the given alpha and beta values.
- * @param alpha the shape parameter.
- * @param beta the scale parameter.
- * @param inverseCumAccuracy the maximum absolute error in inverse
+ *
+ * @param alpha Shape parameter.
+ * @param beta Scale parameter.
+ * @param inverseCumAccuracy Maximum absolute error in inverse
* cumulative probability estimates (defaults to
* {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}).
* @throws NotStrictlyPositiveException if {@code alpha <= 0} or
@@ -84,21 +85,23 @@ public class GammaDistributionImpl exten
}
/**
- * For this distribution, X, this method returns P(X < x).
+ * For this distribution, {@code X}, this method returns {@code P(X < x)}.
*
* The implementation of this method is based on:
* <ul>
- * <li>
- * <a href="http://mathworld.wolfram.com/Chi-SquaredDistribution.html">
- * Chi-Squared Distribution</a>, equation (9).</li>
- * <li>Casella, G., & Berger, R. (1990). <i>Statistical Inference</i>.
- * Belmont, CA: Duxbury Press.</li>
+ * <li>
+ * <a href="http://mathworld.wolfram.com/Chi-SquaredDistribution.html">
+ * Chi-Squared Distribution</a>, equation (9).
+ * </li>
+ * <li>Casella, G., & Berger, R. (1990). <i>Statistical Inference</i>.
+ * Belmont, CA: Duxbury Press.
+ * </li>
* </ul>
*
- * @param x the value at which the CDF is evaluated.
+ * @param x Value at which the CDF is evaluated.
* @return CDF for this distribution.
* @throws MathException if the cumulative probability can not be
- * computed due to convergence or other numerical errors.
+ * computed due to convergence or other numerical errors.
*/
public double cumulativeProbability(double x) throws MathException{
double ret;
@@ -113,16 +116,17 @@ public class GammaDistributionImpl exten
}
/**
- * For this distribution, X, this method returns the critical point x, such
- * that {@code P(X < x) = p}.
- * Returns 0 when p = 0 and {@code Double.POSITIVE_INFINITY} when p = 1.
+ * For this distribution, {@code X}, this method returns the critical
+ * point {@code x}, such that {@code P(X < x) = p}.
+ * It will return 0 when p = 0 and {@code Double.POSITIVE_INFINITY}
+ * when p = 1.
*
* @param p Desired probability.
* @return {@code x}, such that {@code P(X < x) = p}.
- * @throws MathException if the inverse cumulative probability can not be
+ * @throws MathException if the inverse cumulative probability cannot be
* computed due to convergence or other numerical errors.
- * @throws IllegalArgumentException if {@code p} is not a valid
- * probability.
+ * @throws org.apache.commons.math.exception.OutOfRangeException if
+ * {@code p} is not a valid probability.
*/
@Override
public double inverseCumulativeProbability(final double p)
@@ -161,7 +165,7 @@ public class GammaDistributionImpl exten
}
/**
- * Access the domain value lower bound, based on <code>p</code>, used to
+ * 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.
*
@@ -175,12 +179,12 @@ public class GammaDistributionImpl exten
}
/**
- * Access the domain value upper bound, based on <code>p</code>, used to
+ * 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 the desired probability for the critical value
- * @return domain value upper bound, i.e. {@code P(X < 'upper bound') > p}.
+ * @param p Desired probability for the critical value.
+ * @return the domain value upper bound, i.e. {@code P(X < 'upper bound') > p}.
*/
@Override
protected double getDomainUpperBound(double p) {
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=1003048&r1=1003047&r2=1003048&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 Thu Sep 30 12:55:02 2010
@@ -44,12 +44,4 @@ public interface NormalDistribution exte
* @return the standard deviation for this distribution.
*/
double getStandardDeviation();
-
- /**
- * Return the probability density for a particular point.
- *
- * @param x Point at which the density should be computed.
- * @return the pdf at point {@code x}.
- */
- double density(double x);
}
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=1003048&r1=1003047&r2=1003048&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 Thu Sep 30 12:55:02 2010
@@ -52,8 +52,9 @@ public class NormalDistributionImpl exte
/**
* Create a normal distribution using the given mean and standard deviation.
- * @param mean mean for this distribution
- * @param sd standard deviation for this distribution
+ *
+ * @param mean Mean for this distribution.
+ * @param sd Standard deviation for this distribution.
*/
public NormalDistributionImpl(double mean, double sd){
this(mean, sd, DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
@@ -65,7 +66,7 @@ public class NormalDistributionImpl exte
*
* @param mean Mean for this distribution.
* @param sd Standard deviation for this distribution.
- * @param inverseCumAccuracy inverse cumulative probability accuracy.
+ * @param inverseCumAccuracy Inverse cumulative probability accuracy.
* @throws NotStrictlyPositiveException if {@code sd <= 0}.
* @since 2.1
*/
@@ -73,7 +74,7 @@ public class NormalDistributionImpl exte
if (sd <= 0) {
throw new NotStrictlyPositiveException(LocalizedFormats.STANDARD_DEVIATION, sd);
}
-
+
this.mean = mean;
standardDeviation = sd;
solverAbsoluteAccuracy = inverseCumAccuracy;
@@ -104,6 +105,7 @@ public class NormalDistributionImpl exte
/**
* {@inheritDoc}
*/
+ @Override
public double density(double x) {
final double x0 = x - mean;
final double x1 = x0 / standardDeviation;
@@ -138,7 +140,7 @@ public class NormalDistributionImpl exte
* Return the absolute accuracy setting of the solver used to estimate
* inverse cumulative probabilities.
*
- * @return the solver absolute accuracy
+ * @return the solver absolute accuracy.
* @since 2.1
*/
@Override
@@ -147,17 +149,17 @@ public class NormalDistributionImpl exte
}
/**
- * For this distribution, X, this method returns the critical point
+ * For this distribution, X, this method returns the critical point
* {@code x}, such that {@code P(X < x) = p}.
- * Returns {@code Double.NEGATIVE_INFINITY} when p = 0 and
+ * It will return {@code Double.NEGATIVE_INFINITY} when p = 0 and
* {@code Double.POSITIVE_INFINITY} for p = 1.
*
- * @param p the desired probability
+ * @param p Desired probability.
* @return {@code x}, such that {@code P(X < x) = p}.
- * @throws MathException if the inverse cumulative probability can not be
- * computed due to convergence or other numerical errors.
- * @throws IllegalArgumentException if <code>p</code> is not a valid
- * probability.
+ * @throws MathException if the inverse cumulative probability cannot be
+ * computed due to convergence or other numerical errors.
+ * @throws org.apache.commons.math.exception.OutOfRangeException if
+ * {@code p} is not a valid probability.
*/
@Override
public double inverseCumulativeProbability(final double p)
@@ -172,11 +174,11 @@ public class NormalDistributionImpl exte
}
/**
- * Generates a random value sampled from this distribution.
+ * Generate a random value sampled from this distribution.
*
- * @return random value
+ * @return a random value.
* @since 2.2
- * @throws MathException if an error occurs generating the random value
+ * @throws MathException if an error occurs generating the random value.
*/
@Override
public double sample() throws MathException {
@@ -188,8 +190,8 @@ public class NormalDistributionImpl exte
* bracket a CDF root. This method is used by
* {@link #inverseCumulativeProbability(double)} to find critical values.
*
- * @param p the desired probability for the critical value
- * @return domain value lower bound, i.e. {@code P(X < 'lower bound') < p}.
+ * @param p Desired probability for the critical value.
+ * @return the domain value lower bound, i.e. {@code P(X < 'lower bound') < p}.
*/
@Override
protected double getDomainLowerBound(double p) {
@@ -209,8 +211,8 @@ public class NormalDistributionImpl exte
* bracket a CDF root. This method is used by
* {@link #inverseCumulativeProbability(double)} to find critical values.
*
- * @param p the desired probability for the critical value
- * @return domain value upper bound, i.e. {@code P(X < 'upper bound') > p}.
+ * @param p Desired probability for the critical value.
+ * @return the domain value upper bound, i.e. {@code P(X < 'upper bound') > p}.
*/
@Override
protected double getDomainUpperBound(double p) {
@@ -230,8 +232,8 @@ public class NormalDistributionImpl exte
* bracket a CDF root. This method is used by
* {@link #inverseCumulativeProbability(double)} to find critical values.
*
- * @param p the desired probability for the critical value
- * @return initial domain value
+ * @param p Desired probability for the critical value.
+ * @return the initial domain value.
*/
@Override
protected double getInitialDomain(double p) {
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=1003048&r1=1003047&r2=1003048&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 Thu Sep 30 12:55:02 2010
@@ -31,15 +31,8 @@ package org.apache.commons.math.distribu
*/
public interface TDistribution extends ContinuousDistribution {
/**
- * Modify the degrees of freedom.
- * @param degreesOfFreedom the new degrees of freedom.
- * @deprecated as of v2.1
- */
- @Deprecated
- void setDegreesOfFreedom(double degreesOfFreedom);
-
- /**
- * Access the degrees of freedom.
+ * Access the number of degrees of freedom.
+ *
* @return the degrees of freedom.
*/
double getDegreesOfFreedom();
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=1003048&r1=1003047&r2=1003048&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 Thu Sep 30 12:55:02 2010
@@ -19,7 +19,7 @@ package org.apache.commons.math.distribu
import java.io.Serializable;
import org.apache.commons.math.MathException;
-import org.apache.commons.math.MathRuntimeException;
+import org.apache.commons.math.exception.NotStrictlyPositiveException;
import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.special.Beta;
import org.apache.commons.math.special.Gamma;
@@ -34,69 +34,50 @@ import org.apache.commons.math.util.Fast
public class TDistributionImpl
extends AbstractContinuousDistribution
implements TDistribution, Serializable {
-
/**
- * Default inverse cumulative probability accuracy
+ * 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 = -5852615386664158222L;
-
- /** The degrees of freedom*/
+ /** The degrees of freedom. */
private double degreesOfFreedom;
-
- /** Inverse cumulative probability accuracy */
+ /** Inverse cumulative probability accuracy. */
private final double solverAbsoluteAccuracy;
/**
* Create a t distribution using the given degrees of freedom and the
* specified inverse cumulative probability absolute accuracy.
*
- * @param degreesOfFreedom the degrees of freedom.
- * @param inverseCumAccuracy the maximum absolute error in inverse cumulative probability estimates
- * (defaults to {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY})
+ * @param degreesOfFreedom Degrees of freedom.
+ * @param inverseCumAccuracy the maximum absolute error in inverse
+ * cumulative probability estimates
+ * (defaults to {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}).
+ * @throws NotStrictlyPositiveException if {@code degreesOfFreedom <= 0}
* @since 2.1
*/
public TDistributionImpl(double degreesOfFreedom, double inverseCumAccuracy) {
- super();
- setDegreesOfFreedomInternal(degreesOfFreedom);
+ if (degreesOfFreedom <= 0) {
+ throw new NotStrictlyPositiveException(LocalizedFormats.DEGREES_OF_FREEDOM,
+ degreesOfFreedom);
+ }
+ this.degreesOfFreedom = degreesOfFreedom;
solverAbsoluteAccuracy = inverseCumAccuracy;
}
/**
* Create a t distribution using the given degrees of freedom.
- * @param degreesOfFreedom the degrees of freedom.
+ *
+ * @param degreesOfFreedom Degrees of freedom.
*/
public TDistributionImpl(double degreesOfFreedom) {
this(degreesOfFreedom, DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
}
/**
- * Modify the degrees of freedom.
- * @param degreesOfFreedom the new degrees of freedom.
- * @deprecated as of 2.1 (class will become immutable in 3.0)
- */
- @Deprecated
- public void setDegreesOfFreedom(double degreesOfFreedom) {
- setDegreesOfFreedomInternal(degreesOfFreedom);
- }
- /**
- * Modify the degrees of freedom.
- * @param newDegreesOfFreedom the new degrees of freedom.
- */
- private void setDegreesOfFreedomInternal(double newDegreesOfFreedom) {
- if (newDegreesOfFreedom <= 0.0) {
- throw MathRuntimeException.createIllegalArgumentException(
- LocalizedFormats.NOT_POSITIVE_DEGREES_OF_FREEDOM,
- newDegreesOfFreedom);
- }
- this.degreesOfFreedom = newDegreesOfFreedom;
- }
-
- /**
* Access the degrees of freedom.
+ *
* @return the degrees of freedom.
*/
public double getDegreesOfFreedom() {
@@ -104,30 +85,28 @@ public class TDistributionImpl
}
/**
- * Returns the probability density for a particular point.
- *
- * @param x The point at which the density should be computed.
- * @return The pdf at point x.
- * @since 2.1
+ * {@inheritDoc}
*/
@Override
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));
}
/**
- * For this distribution, X, this method returns P(X < <code>x</code>).
- * @param x the value at which the CDF is evaluated.
- * @return CDF evaluated at <code>x</code>.
+ * For this distribution, X, this method returns {@code P(X < x}).
+ *
+ * @param x Value at which the CDF is evaluated.
+ * @return CDF evaluated at {@code x}.
* @throws MathException if the cumulative probability can not be
- * computed due to convergence or other numerical errors.
+ * computed due to convergence or other numerical errors.
*/
public double cumulativeProbability(double x) throws MathException{
double ret;
- if (x == 0.0) {
+ if (x == 0) {
ret = 0.5;
} else {
double t =
@@ -146,18 +125,17 @@ public class TDistributionImpl
}
/**
- * For this distribution, X, this method returns the critical point x, such
- * that P(X < x) = <code>p</code>.
- * <p>
- * Returns <code>Double.NEGATIVE_INFINITY</code> for p=0 and
- * <code>Double.POSITIVE_INFINITY</code> for p=1.</p>
- *
- * @param p the desired probability
- * @return x, such that P(X < x) = <code>p</code>
- * @throws MathException if the inverse cumulative probability can not be
- * computed due to convergence or other numerical errors.
- * @throws IllegalArgumentException if <code>p</code> is not a valid
- * probability.
+ * For this distribution, {@code X}, this method returns the critical
+ * point {@code x}, such that {@code P(X < x) = p}.
+ * Returns {@code Double.NEGATIVE_INFINITY} when p = 0 and
+ * {@code Double.POSITIVE_INFINITY} when p = 1.
+ *
+ * @param p Desired probability.
+ * @return {@code x}, such that {@code P(X < x) = p}.
+ * @throws MathException if the inverse cumulative probability cannot be
+ * computed due to convergence or other numerical errors.
+ * @throws org.apache.commons.math.exception.OutOfRangeException if
+ * {@code p} is not a valid probability.
*/
@Override
public double inverseCumulativeProbability(final double p)
@@ -172,13 +150,12 @@ public class TDistributionImpl
}
/**
- * Access the domain value lower bound, based on <code>p</code>, used to
+ * 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 the desired probability for the critical value
- * @return domain value lower bound, i.e.
- * P(X < <i>lower bound</i>) < <code>p</code>
+ * @param p Desired probability for the critical value
+ * @return the domain value lower bound, i.e. {@code P(X < 'lower bound') > p}.
*/
@Override
protected double getDomainLowerBound(double p) {
@@ -186,13 +163,12 @@ public class TDistributionImpl
}
/**
- * Access the domain value upper bound, based on <code>p</code>, used to
+ * 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 the desired probability for the critical value
- * @return domain value upper bound, i.e.
- * P(X < <i>upper bound</i>) > <code>p</code>
+ * @param p Desired probability for the critical value.
+ * @return the domain value upper bound, i.e. {@code P(X < 'upper bound') > p}.
*/
@Override
protected double getDomainUpperBound(double p) {
@@ -200,23 +176,23 @@ public class TDistributionImpl
}
/**
- * Access the initial domain value, based on <code>p</code>, used to
+ * 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 the desired probability for the critical value
- * @return initial domain value
+ * @param p Desired probability for the critical value.
+ * @return the initial domain value.
*/
@Override
protected double getInitialDomain(double p) {
- return 0.0;
+ return 0;
}
/**
* Return the absolute accuracy setting of the solver used to estimate
* inverse cumulative probabilities.
*
- * @return the solver absolute accuracy
+ * @return the solver absolute accuracy.
* @since 2.1
*/
@Override
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=1003048&r1=1003047&r2=1003048&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 Thu Sep 30 12:55:02 2010
@@ -35,32 +35,17 @@ package org.apache.commons.math.distribu
* @version $Revision$ $Date$
*/
public interface WeibullDistribution extends ContinuousDistribution {
-
/**
* Access the shape parameter.
+ *
* @return the shape parameter.
*/
double getShape();
/**
* Access the scale parameter.
+ *
* @return the scale parameter.
*/
double getScale();
-
- /**
- * Modify the shape parameter.
- * @param alpha The new shape parameter value.
- * @deprecated as of v2.1
- */
- @Deprecated
- void setShape(double alpha);
-
- /**
- * Modify the scale parameter.
- * @param beta The new scale parameter value.
- * @deprecated as of v2.1
- */
- @Deprecated
- void setScale(double beta);
}
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=1003048&r1=1003047&r2=1003048&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 Thu Sep 30 12:55:02 2010
@@ -19,7 +19,8 @@ package org.apache.commons.math.distribu
import java.io.Serializable;
-import org.apache.commons.math.MathRuntimeException;
+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.util.FastMath;
@@ -32,55 +33,64 @@ import org.apache.commons.math.util.Fast
*/
public class WeibullDistributionImpl extends AbstractContinuousDistribution
implements WeibullDistribution, Serializable {
-
/**
* 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 double shape;
-
/** The scale parameter. */
private double scale;
-
- /** Inverse cumulative probability accuracy */
+ /** Inverse cumulative probability accuracy. */
private final double solverAbsoluteAccuracy;
/**
- * Creates weibull distribution with the given shape and scale and a
+ * Create a Weibull distribution with the given shape and scale and a
* location equal to zero.
- * @param alpha the shape parameter.
- * @param beta the scale parameter.
+ *
+ * @param alpha Shape parameter.
+ * @param beta Scale parameter.
*/
- public WeibullDistributionImpl(double alpha, double beta){
+ public WeibullDistributionImpl(double alpha, double beta) {
this(alpha, beta, DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
}
/**
- * Creates weibull distribution with the given shape, scale and inverse
+ * Create a Weibull distribution with the given shape, scale and inverse
* cumulative probability accuracy and a location equal to zero.
- * @param alpha the shape parameter.
- * @param beta the scale parameter.
- * @param inverseCumAccuracy the maximum absolute error in inverse cumulative probability estimates
- * (defaults to {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY})
+ *
+ * @param alpha Shape parameter.
+ * @param beta Scale parameter.
+ * @param inverseCumAccuracy Maximum absolute error in inverse
+ * cumulative probability estimates
+ * (defaults to {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}).
+ * @throws NotStrictlyPositiveException if {@code alpha <= 0} or
+ * {@code beta <= 0}.
* @since 2.1
*/
- public WeibullDistributionImpl(double alpha, double beta, double inverseCumAccuracy){
- super();
- setShapeInternal(alpha);
- setScaleInternal(beta);
+ public WeibullDistributionImpl(double alpha, double beta,
+ double inverseCumAccuracy) {
+ if (alpha <= 0) {
+ throw new NotStrictlyPositiveException(LocalizedFormats.SHAPE,
+ alpha);
+ }
+ if (beta <= 0) {
+ throw new NotStrictlyPositiveException(LocalizedFormats.SCALE,
+ beta);
+ }
+ scale = beta;
+ shape = alpha;
solverAbsoluteAccuracy = inverseCumAccuracy;
}
/**
- * For this distribution, X, this method returns P(X < <code>x</code>).
- * @param x the value at which the CDF is evaluated.
- * @return CDF evaluted at <code>x</code>.
+ * For this distribution, {@code X}, this method returns {@code P(X < x)}.
+ *
+ * @param x Value at which the CDF is evaluated.
+ * @return the CDF evaluted at {@code x}.
*/
public double cumulativeProbability(double x) {
double ret;
@@ -93,27 +103,21 @@ public class WeibullDistributionImpl ext
}
/**
- * Access the shape parameter.
- * @return the shape parameter.
+ * {@inheritDoc}
*/
public double getShape() {
return shape;
}
/**
- * Access the scale parameter.
- * @return the scale parameter.
+ * {@inheritDoc}
*/
public double getScale() {
return scale;
}
/**
- * Returns the probability density for a particular point.
- *
- * @param x The point at which the density should be computed.
- * @return The pdf at point x.
- * @since 2.1
+ * {@inheritDoc}
*/
@Override
public double density(double x) {
@@ -135,23 +139,20 @@ public class WeibullDistributionImpl ext
}
/**
- * For this distribution, X, this method returns the critical point x, such
- * that P(X < x) = <code>p</code>.
- * <p>
- * Returns <code>Double.NEGATIVE_INFINITY</code> for p=0 and
- * <code>Double.POSITIVE_INFINITY</code> for p=1.</p>
- *
- * @param p the desired probability
- * @return x, such that P(X < x) = <code>p</code>
- * @throws IllegalArgumentException if <code>p</code> is not a valid
- * probability.
+ * For this distribution, {@code X}, this method returns the critical
+ * point {@code x}, such that {@code P(X < x) = p}.
+ * It will return {@code Double.NEGATIVE_INFINITY} when p = 0 and
+ * {@code Double.POSITIVE_INFINITY} when p = 1.
+ *
+ * @param p Desired probability.
+ * @return {@code x}, such that {@code P(X < x) = p}.
+ * @throws OutOfRangeException if {@code p} is not a valid probability.
*/
@Override
public double inverseCumulativeProbability(double p) {
double ret;
if (p < 0.0 || p > 1.0) {
- throw MathRuntimeException.createIllegalArgumentException(
- LocalizedFormats.OUT_OF_RANGE_SIMPLE, p, 0.0, 1.0);
+ throw new OutOfRangeException(p, 0.0, 1.0);
} else if (p == 0) {
ret = 0.0;
} else if (p == 1) {
@@ -162,72 +163,27 @@ public class WeibullDistributionImpl ext
return ret;
}
- /**
- * Modify the shape parameter.
- * @param alpha the new shape parameter value.
- * @deprecated as of 2.1 (class will become immutable in 3.0)
- */
- @Deprecated
- public void setShape(double alpha) {
- setShapeInternal(alpha);
- }
- /**
- * Modify the shape parameter.
- * @param alpha the new shape parameter value.
- */
- private void setShapeInternal(double alpha) {
- if (alpha <= 0.0) {
- throw MathRuntimeException.createIllegalArgumentException(
- LocalizedFormats.NOT_POSITIVE_SHAPE,
- alpha);
- }
- this.shape = alpha;
- }
-
- /**
- * Modify the scale parameter.
- * @param beta the new scale parameter value.
- * @deprecated as of 2.1 (class will become immutable in 3.0)
- */
- @Deprecated
- public void setScale(double beta) {
- setScaleInternal(beta);
- }
- /**
- * Modify the scale parameter.
- * @param beta the new scale parameter value.
- */
- private void setScaleInternal(double beta) {
- if (beta <= 0.0) {
- throw MathRuntimeException.createIllegalArgumentException(
- LocalizedFormats.NOT_POSITIVE_SCALE,
- beta);
- }
- this.scale = beta;
- }
/**
- * Access the domain value lower bound, based on <code>p</code>, used to
+ * 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 the desired probability for the critical value
- * @return domain value lower bound, i.e.
- * P(X < <i>lower bound</i>) < <code>p</code>
+ * @param p Desired probability for the critical value.
+ * @return the domain value lower bound, i.e. {@code P(X < 'lower bound') < p}.
*/
@Override
protected double getDomainLowerBound(double p) {
- return 0.0;
+ return 0;
}
/**
- * Access the domain value upper bound, based on <code>p</code>, used to
+ * 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 the desired probability for the critical value
- * @return domain value upper bound, i.e.
- * P(X < <i>upper bound</i>) > <code>p</code>
+ * @param p Desired probability for the critical value.
+ * @return the domain value upper bound, i.e. {@code P(X < 'upper bound') > p}.
*/
@Override
protected double getDomainUpperBound(double p) {
@@ -235,12 +191,12 @@ public class WeibullDistributionImpl ext
}
/**
- * Access the initial domain value, based on <code>p</code>, used to
+ * 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 the desired probability for the critical value
- * @return initial domain value
+ * @param p Desired probability for the critical value.
+ * @return the initial domain value.
*/
@Override
protected double getInitialDomain(double p) {
@@ -252,7 +208,7 @@ public class WeibullDistributionImpl ext
* Return the absolute accuracy setting of the solver used to estimate
* inverse cumulative probabilities.
*
- * @return the solver absolute accuracy
+ * @return the solver absolute accuracy.
* @since 2.1
*/
@Override