Author: erans Date: Mon Sep 27 13:43:59 2010 New Revision: 1001736 URL: http://svn.apache.org/viewvc?rev=1001736&view=rev Log: Removed deprecated code.
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BetaDistributionImpl.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ChiSquaredDistributionImpl.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/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/exception/util/LocalizedFormats.java commons/proper/math/trunk/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/GammaDistributionTest.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BetaDistributionImpl.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BetaDistributionImpl.java?rev=1001736&r1=1001735&r2=1001736&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BetaDistributionImpl.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BetaDistributionImpl.java Mon Sep 27 13:43:59 2010 @@ -89,11 +89,13 @@ public class BetaDistributionImpl } /** {...@inheritdoc} */ + @Override public double getAlpha() { return alpha; } /** {...@inheritdoc} */ + @Override public double getBeta() { return beta; } @@ -108,12 +110,9 @@ public class BetaDistributionImpl } /** - * Return the probability density for a particular point. - * - * @param x Point at which the density should be computed. - * @return the pdf at point x. - * @since 2.1 + * {...@inheritdoc} */ + @Override public double density(double x) { recomputeZ(); if (x < 0 || x > 1) { 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=1001736&r1=1001735&r2=1001736&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ChiSquaredDistributionImpl.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ChiSquaredDistributionImpl.java Mon Sep 27 13:43:59 2010 @@ -27,7 +27,7 @@ import org.apache.commons.math.MathExcep */ public class ChiSquaredDistributionImpl extends AbstractContinuousDistribution - implements ChiSquaredDistribution, Serializable { + implements ChiSquaredDistribution, Serializable { /** * Default inverse cumulative probability accuracy * @since 2.1 @@ -66,16 +66,7 @@ public class ChiSquaredDistributionImpl } /** - * Modify the degrees of freedom. - * @param degreesOfFreedom the new degrees of freedom. - */ - private void setDegreesOfFreedomInternal(double degreesOfFreedom) { - gamma.setAlpha(degreesOfFreedom / 2.0); - } - - /** - * Access the degrees of freedom. - * @return the degrees of freedom. + * {...@inheritdoc} */ public double getDegreesOfFreedom() { return gamma.getAlpha() * 2.0; @@ -181,13 +172,13 @@ public class ChiSquaredDistributionImpl @Override protected double getInitialDomain(double p) { // NOTE: chi squared is skewed to the left - // NOTE: therefore, P(X < μ) > .5 + // NOTE: therefore, P(X < μ) > 0.5 double ret; - if (p < .5) { + if (p < 0.5) { // use 1/2 mean - ret = getDegreesOfFreedom() * .5; + ret = getDegreesOfFreedom() * 0.5; } else { // use mean ret = getDegreesOfFreedom(); @@ -200,7 +191,7 @@ public class ChiSquaredDistributionImpl * 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/ExponentialDistributionImpl.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ExponentialDistributionImpl.java?rev=1001736&r1=1001735&r2=1001736&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ExponentialDistributionImpl.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ExponentialDistributionImpl.java Mon Sep 27 13:43:59 2010 @@ -69,20 +69,15 @@ public class ExponentialDistributionImpl } /** - * Access the mean. - * - * @return the mean. + * {...@inheritdoc} */ + @Override public double getMean() { return mean; } /** - * 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}. - * @since 2.1 + * {...@inheritdoc} */ @Override public double density(double x) { 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=1001736&r1=1001735&r2=1001736&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 Mon Sep 27 13:43:59 2010 @@ -29,39 +29,26 @@ package org.apache.commons.math.distribu * * @version $Revision$ $Date$ */ -public interface GammaDistribution extends ContinuousDistribution, HasDensity<Double> { +public interface GammaDistribution extends ContinuousDistribution { /** - * Modify the shape parameter, alpha. - * @param alpha the new shape parameter. - * @deprecated as of v2.1 - */ - @Deprecated - void setAlpha(double alpha); - - /** - * Access the shape parameter, alpha + * Access the alpha shape parameter. + * * @return alpha. */ double getAlpha(); /** - * Modify the scale parameter, beta. - * @param beta the new scale parameter. - * @deprecated as of v2.1 - */ - @Deprecated - void setBeta(double beta); - - /** - * Access the scale parameter, beta + * Access the beta scale parameter. + * * @return beta. */ double getBeta(); /** * 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. + * + * @param x Point at which the density should be computed.. + * @return the pdf at point {...@code x}. */ - double density(Double 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=1001736&r1=1001735&r2=1001736&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/GammaDistributionImpl.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/GammaDistributionImpl.java Mon Sep 27 13:43:59 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.Gamma; import org.apache.commons.math.util.FastMath; @@ -63,14 +63,23 @@ 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 cumulative probability estimates - * (defaults to {...@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}) + * @param inverseCumAccuracy the 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 GammaDistributionImpl(double alpha, double beta, double inverseCumAccuracy) { - super(); - setAlphaInternal(alpha); - setBetaInternal(beta); + if (alpha <= 0) { + throw new NotStrictlyPositiveException(LocalizedFormats.ALPHA, alpha); + } + if (beta <= 0) { + throw new NotStrictlyPositiveException(LocalizedFormats.BETA, beta); + } + + this.alpha = alpha; + this.beta = beta; solverAbsoluteAccuracy = inverseCumAccuracy; } @@ -94,8 +103,8 @@ public class GammaDistributionImpl exten public double cumulativeProbability(double x) throws MathException{ double ret; - if (x <= 0.0) { - ret = 0.0; + if (x <= 0) { + ret = 0; } else { ret = Gamma.regularizedGammaP(alpha, x / beta); } @@ -105,22 +114,21 @@ public class GammaDistributionImpl exten /** * 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> + * that {...@code P(X < x) = p}. + * Returns 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 IllegalArgumentException if {...@code p} is not a valid + * probability. */ @Override public double inverseCumulativeProbability(final double p) - throws MathException { + throws MathException { if (p == 0) { - return 0d; + return 0; } if (p == 1) { return Double.POSITIVE_INFINITY; @@ -129,92 +137,29 @@ public class GammaDistributionImpl exten } /** - * Modify the shape parameter, alpha. - * @param alpha the new shape parameter. - * @throws IllegalArgumentException if <code>alpha</code> is not positive. - * @deprecated as of 2.1 (class will become immutable in 3.0) - */ - @Deprecated - public void setAlpha(double alpha) { - setAlphaInternal(alpha); - } - - /** - * Modify the shape parameter, alpha. - * @param newAlpha the new shape parameter. - * @throws IllegalArgumentException if <code>newAlpha</code> is not positive. - */ - private void setAlphaInternal(double newAlpha) { - if (newAlpha <= 0.0) { - throw MathRuntimeException.createIllegalArgumentException( - LocalizedFormats.NOT_POSITIVE_ALPHA, - newAlpha); - } - this.alpha = newAlpha; - } - - /** - * Access the shape parameter, alpha - * @return alpha. + * {...@inheritdoc} */ + @Override public double getAlpha() { return alpha; } /** - * Modify the scale parameter, beta. - * @param newBeta the new scale parameter. - * @throws IllegalArgumentException if <code>newBeta</code> is not positive. - * @deprecated as of 2.1 (class will become immutable in 3.0) - */ - @Deprecated - public void setBeta(double newBeta) { - setBetaInternal(newBeta); - } - - /** - * Modify the scale parameter, beta. - * @param newBeta the new scale parameter. - * @throws IllegalArgumentException if <code>newBeta</code> is not positive. - */ - private void setBetaInternal(double newBeta) { - if (newBeta <= 0.0) { - throw MathRuntimeException.createIllegalArgumentException( - LocalizedFormats.NOT_POSITIVE_BETA, - newBeta); - } - this.beta = newBeta; - } - - /** - * Access the scale parameter, beta - * @return beta. + * {...@inheritdoc} */ + @Override public double getBeta() { return beta; } /** - * 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. + * {...@inheritdoc} */ @Override public double density(double x) { if (x < 0) return 0; - return FastMath.pow(x / beta, alpha - 1) / beta * FastMath.exp(-x / beta) / FastMath.exp(Gamma.logGamma(alpha)); - } - - /** - * 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. - * @deprecated - */ - public double density(Double x) { - return density(x.doubleValue()); + return FastMath.pow(x / beta, alpha - 1) / beta * + FastMath.exp(-x / beta) / FastMath.exp(Gamma.logGamma(alpha)); } /** @@ -222,9 +167,8 @@ public class GammaDistributionImpl exten * 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) { @@ -238,8 +182,7 @@ public class GammaDistributionImpl exten * {...@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> + * @return domain value upper bound, i.e. {...@code P(X < 'upper bound') > p}. */ @Override protected double getDomainUpperBound(double p) { @@ -249,7 +192,7 @@ public class GammaDistributionImpl exten double ret; - if (p < .5) { + if (p < 0.5) { // use mean ret = alpha * beta; } else { @@ -261,12 +204,12 @@ public class GammaDistributionImpl exten } /** - * 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) { @@ -275,9 +218,9 @@ public class GammaDistributionImpl exten double ret; - if (p < .5) { + if (p < 0.5) { // use 1/2 mean - ret = alpha * beta * .5; + ret = alpha * beta * 0.5; } else { // use mean ret = alpha * beta; @@ -290,7 +233,7 @@ public class GammaDistributionImpl exten * 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/exception/util/LocalizedFormats.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/LocalizedFormats.java?rev=1001736&r1=1001735&r2=1001736&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/LocalizedFormats.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/LocalizedFormats.java Mon Sep 27 13:43:59 2010 @@ -170,8 +170,8 @@ public enum LocalizedFormats implements NOT_INCREASING_NUMBER_OF_POINTS("points {0} and {1} are not increasing ({2} > {3})"), NOT_INCREASING_SEQUENCE("points {3} and {2} are not increasing ({1} > {0})"), /* keep */ NOT_MULTIPLICATION_COMPATIBLE_MATRICES("{0}x{1} and {2}x{3} matrices are not multiplication compatible"), - NOT_POSITIVE_ALPHA("alpha must be positive ({0})"), - NOT_POSITIVE_BETA("beta must be positive ({0})"), + ALPHA("alpha"), /* keep */ + BETA("beta"), /* keep */ NOT_POSITIVE_COLUMNDIMENSION("invalid column dimension: {0} (must be positive)"), NOT_POSITIVE_DEFINITE_MATRIX("not positive definite matrix"), NOT_POSITIVE_DEGREES_OF_FREEDOM("degrees of freedom must be positive ({0})"), Modified: commons/proper/math/trunk/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties?rev=1001736&r1=1001735&r2=1001736&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties (original) +++ commons/proper/math/trunk/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties Mon Sep 27 13:43:59 2010 @@ -142,8 +142,8 @@ NOT_ENOUGH_POINTS_IN_SPLINE_PARTITION = NOT_INCREASING_NUMBER_OF_POINTS = les points {0} et {1} ne sont pas croissants ({2} > {3}) NOT_INCREASING_SEQUENCE = les points {3} et {2} ne sont pas croissants ({1} > {0}) NOT_MULTIPLICATION_COMPATIBLE_MATRICES = les dimensions {0}x{1} et {2}x{3} sont incompatibles pour la multiplication matricielle -NOT_POSITIVE_ALPHA = alpha doit \u00eatre positif ({0}) -NOT_POSITIVE_BETA = beta doit \u00eatre positif ({0}) +ALPHA = alpha +BETA = beta NOT_POSITIVE_COLUMNDIMENSION = nombre de colonnes invalide : {0} (doit \u00eatre positif) NOT_POSITIVE_DEFINITE_MATRIX = matrice non d\u00e9finie positive NOT_POSITIVE_DEGREES_OF_FREEDOM = les degr\u00e9s de libert\u00e9 doivent \u00eatre positifs ({0}) Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/GammaDistributionTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/GammaDistributionTest.java?rev=1001736&r1=1001735&r2=1001736&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/GammaDistributionTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/GammaDistributionTest.java Mon Sep 27 13:43:59 2010 @@ -17,6 +17,8 @@ package org.apache.commons.math.distribution; +import org.apache.commons.math.exception.NotStrictlyPositiveException; + /** * Test cases for GammaDistribution. * Extends ContinuousDistributionAbstractTest. See class javadoc for @@ -74,22 +76,21 @@ public class GammaDistributionTest exten public void testParameterAccessors() { GammaDistribution distribution = (GammaDistribution) getDistribution(); assertEquals(4d, distribution.getAlpha(), 0); - distribution.setAlpha(3d); - assertEquals(3d, distribution.getAlpha(), 0); assertEquals(2d, distribution.getBeta(), 0); - distribution.setBeta(4d); - assertEquals(4d, distribution.getBeta(), 0); + } + + public void testPreconditions() { try { - distribution.setAlpha(0d); - fail("Expecting IllegalArgumentException for alpha = 0"); - } catch (IllegalArgumentException ex) { - // expected + GammaDistribution distribution = new GammaDistributionImpl(0, 1); + fail("Expecting NotStrictlyPositiveException for alpha = 0"); + } catch (NotStrictlyPositiveException ex) { + // Expected. } try { - distribution.setBeta(0d); - fail("Expecting IllegalArgumentException for beta = 0"); - } catch (IllegalArgumentException ex) { - // expected + GammaDistribution distribution = new GammaDistributionImpl(1, 0); + fail("Expecting NotStrictlyPositiveException for alpha = 0"); + } catch (NotStrictlyPositiveException ex) { + // Expected. } }