Issues
https://issues.apache.org/jira/browse/MATH-348 https://issues.apache.org/jira/browse/MATH-349 git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@920852 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
09a4643e10
commit
2e3e082984
8
pom.xml
8
pom.xml
|
@ -102,6 +102,11 @@
|
|||
<id>brentworden</id>
|
||||
<email>brentworden at apache dot org</email>
|
||||
</developer>
|
||||
<developer>
|
||||
<name>Gilles Sadowski</name>
|
||||
<id>erans</id>
|
||||
<email>erans at apache dot org</email>
|
||||
</developer>
|
||||
</developers>
|
||||
<contributors>
|
||||
<contributor>
|
||||
|
@ -191,9 +196,6 @@
|
|||
<contributor>
|
||||
<name>Matthew Rowles</name>
|
||||
</contributor>
|
||||
<contributor>
|
||||
<name>Gilles Sadowski</name>
|
||||
</contributor>
|
||||
<contributor>
|
||||
<name>Joni Salonen</name>
|
||||
</contributor>
|
||||
|
|
|
@ -27,10 +27,12 @@ import org.apache.commons.math.MathException;
|
|||
*/
|
||||
public interface BetaDistribution extends ContinuousDistribution, HasDensity<Double> {
|
||||
/**
|
||||
* Modify the shape parameter, alpha.
|
||||
* @param alpha the new shape parameter.
|
||||
*/
|
||||
void setAlpha(double alpha);
|
||||
* Modify the shape parameter, alpha.
|
||||
* @param alpha the new shape parameter.
|
||||
* @deprecated as of 2.1
|
||||
*/
|
||||
@Deprecated
|
||||
void setAlpha(double alpha);
|
||||
|
||||
/**
|
||||
* Access the shape parameter, alpha
|
||||
|
@ -41,7 +43,9 @@ public interface BetaDistribution extends ContinuousDistribution, HasDensity<Dou
|
|||
/**
|
||||
* Modify the shape parameter, beta.
|
||||
* @param beta the new scale parameter.
|
||||
* @deprecated as of 2.1
|
||||
*/
|
||||
@Deprecated
|
||||
void setBeta(double beta);
|
||||
|
||||
/**
|
||||
|
|
|
@ -60,7 +60,10 @@ public class BetaDistributionImpl
|
|||
z = Double.NaN;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
/** {@inheritDoc}
|
||||
* @deprecated as of 2.1 (class will become immutable in 3.0)
|
||||
*/
|
||||
@Deprecated
|
||||
public void setAlpha(double alpha) {
|
||||
this.alpha = alpha;
|
||||
z = Double.NaN;
|
||||
|
@ -71,7 +74,10 @@ public class BetaDistributionImpl
|
|||
return alpha;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
/** {@inheritDoc}
|
||||
* @deprecated as of 2.1 (class will become immutable in 3.0)
|
||||
*/
|
||||
@Deprecated
|
||||
public void setBeta(double beta) {
|
||||
this.beta = beta;
|
||||
z = Double.NaN;
|
||||
|
|
|
@ -45,12 +45,16 @@ public interface BinomialDistribution extends IntegerDistribution {
|
|||
/**
|
||||
* Change the number of trials for this distribution.
|
||||
* @param trials the new number of trials.
|
||||
* @deprecated as of v2.1
|
||||
*/
|
||||
@Deprecated
|
||||
void setNumberOfTrials(int trials);
|
||||
|
||||
/**
|
||||
* Change the probability of success for this distribution.
|
||||
* @param p the new probability of success.
|
||||
* @deprecated as of v2.1
|
||||
*/
|
||||
@Deprecated
|
||||
void setProbabilityOfSuccess(double p);
|
||||
}
|
||||
|
|
|
@ -48,8 +48,8 @@ public class BinomialDistributionImpl extends AbstractIntegerDistribution
|
|||
*/
|
||||
public BinomialDistributionImpl(int trials, double p) {
|
||||
super();
|
||||
setNumberOfTrials(trials);
|
||||
setProbabilityOfSuccess(p);
|
||||
setNumberOfTrialsInternal(trials);
|
||||
setProbabilityOfSuccessInternal(p);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -76,8 +76,20 @@ public class BinomialDistributionImpl extends AbstractIntegerDistribution
|
|||
* @param trials the new number of trials.
|
||||
* @throws IllegalArgumentException if <code>trials</code> is not a valid
|
||||
* number of trials.
|
||||
* @deprecated as of 2.1 (class will become immutable in 3.0)
|
||||
*/
|
||||
@Deprecated
|
||||
public void setNumberOfTrials(int trials) {
|
||||
setNumberOfTrialsInternal(trials);
|
||||
}
|
||||
/**
|
||||
* Change the number of trials for this distribution.
|
||||
*
|
||||
* @param trials the new number of trials.
|
||||
* @throws IllegalArgumentException if <code>trials</code> is not a valid
|
||||
* number of trials.
|
||||
*/
|
||||
private void setNumberOfTrialsInternal(int trials) {
|
||||
if (trials < 0) {
|
||||
throw MathRuntimeException.createIllegalArgumentException(
|
||||
"number of trials must be non-negative ({0})", trials);
|
||||
|
@ -91,8 +103,20 @@ public class BinomialDistributionImpl extends AbstractIntegerDistribution
|
|||
* @param p the new probability of success.
|
||||
* @throws IllegalArgumentException if <code>p</code> is not a valid
|
||||
* probability.
|
||||
* @deprecated as of 2.1 (class will become immutable in 3.0)
|
||||
*/
|
||||
@Deprecated
|
||||
public void setProbabilityOfSuccess(double p) {
|
||||
setProbabilityOfSuccessInternal(p);
|
||||
}
|
||||
/**
|
||||
* Change the probability of success for this distribution.
|
||||
*
|
||||
* @param p the new probability of success.
|
||||
* @throws IllegalArgumentException if <code>p</code> is not a valid
|
||||
* probability.
|
||||
*/
|
||||
private void setProbabilityOfSuccessInternal(double p) {
|
||||
if (p < 0.0 || p > 1.0) {
|
||||
throw MathRuntimeException.createIllegalArgumentException(
|
||||
"{0} out of [{1}, {2}] range", p, 0.0, 1.0);
|
||||
|
@ -123,7 +147,7 @@ public class BinomialDistributionImpl extends AbstractIntegerDistribution
|
|||
*/
|
||||
@Override
|
||||
protected int getDomainUpperBound(double p) {
|
||||
return getNumberOfTrials();
|
||||
return numberOfTrials;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -139,11 +163,11 @@ public class BinomialDistributionImpl extends AbstractIntegerDistribution
|
|||
double ret;
|
||||
if (x < 0) {
|
||||
ret = 0.0;
|
||||
} else if (x >= getNumberOfTrials()) {
|
||||
} else if (x >= numberOfTrials) {
|
||||
ret = 1.0;
|
||||
} else {
|
||||
ret = 1.0 - Beta.regularizedBeta(getProbabilityOfSuccess(),
|
||||
x + 1.0, getNumberOfTrials() - x);
|
||||
x + 1.0, numberOfTrials - x);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -156,7 +180,7 @@ public class BinomialDistributionImpl extends AbstractIntegerDistribution
|
|||
*/
|
||||
public double probability(int x) {
|
||||
double ret;
|
||||
if (x < 0 || x > getNumberOfTrials()) {
|
||||
if (x < 0 || x > numberOfTrials) {
|
||||
ret = 0.0;
|
||||
} else {
|
||||
ret = Math.exp(SaddlePointExpansion.logBinomialProbability(x,
|
||||
|
|
|
@ -48,12 +48,16 @@ public interface CauchyDistribution extends ContinuousDistribution {
|
|||
/**
|
||||
* 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);
|
||||
}
|
||||
|
|
|
@ -55,8 +55,8 @@ public class CauchyDistributionImpl extends AbstractContinuousDistribution
|
|||
*/
|
||||
public CauchyDistributionImpl(double median, double s){
|
||||
super();
|
||||
setMedian(median);
|
||||
setScale(s);
|
||||
setMedianInternal(median);
|
||||
setScaleInternal(s);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -115,8 +115,17 @@ public class CauchyDistributionImpl extends AbstractContinuousDistribution
|
|||
/**
|
||||
* 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 median for this distribution
|
||||
*/
|
||||
private void setMedianInternal(double median) {
|
||||
this.median = median;
|
||||
}
|
||||
|
||||
|
@ -124,8 +133,18 @@ public class CauchyDistributionImpl extends AbstractContinuousDistribution
|
|||
* 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(
|
||||
"scale must be positive ({0})", s);
|
||||
|
@ -149,7 +168,7 @@ public class CauchyDistributionImpl extends AbstractContinuousDistribution
|
|||
if (p < .5) {
|
||||
ret = -Double.MAX_VALUE;
|
||||
} else {
|
||||
ret = getMedian();
|
||||
ret = median;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -169,7 +188,7 @@ public class CauchyDistributionImpl extends AbstractContinuousDistribution
|
|||
double ret;
|
||||
|
||||
if (p < .5) {
|
||||
ret = getMedian();
|
||||
ret = median;
|
||||
} else {
|
||||
ret = Double.MAX_VALUE;
|
||||
}
|
||||
|
@ -190,11 +209,11 @@ public class CauchyDistributionImpl extends AbstractContinuousDistribution
|
|||
double ret;
|
||||
|
||||
if (p < .5) {
|
||||
ret = getMedian() - getScale();
|
||||
ret = median - scale;
|
||||
} else if (p > .5) {
|
||||
ret = getMedian() + getScale();
|
||||
ret = median + scale;
|
||||
} else {
|
||||
ret = getMedian();
|
||||
ret = median;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -33,7 +33,9 @@ public interface ChiSquaredDistribution extends ContinuousDistribution, HasDensi
|
|||
/**
|
||||
* Modify the degrees of freedom.
|
||||
* @param degreesOfFreedom the new degrees of freedom.
|
||||
* @deprecated as of v2.1
|
||||
*/
|
||||
@Deprecated
|
||||
void setDegreesOfFreedom(double degreesOfFreedom);
|
||||
|
||||
/**
|
||||
|
|
|
@ -48,19 +48,31 @@ public class ChiSquaredDistributionImpl
|
|||
* @param df degrees of freedom.
|
||||
* @param g the underlying gamma distribution used to compute probabilities.
|
||||
* @since 1.2
|
||||
* @deprecated as of 2.1 (to avoid possibly inconsistent state, the
|
||||
* "GammaDistribution" will be instantiated internally)
|
||||
*/
|
||||
@Deprecated
|
||||
public ChiSquaredDistributionImpl(double df, GammaDistribution g) {
|
||||
super();
|
||||
setGamma(g);
|
||||
setDegreesOfFreedom(df);
|
||||
setGammaInternal(g);
|
||||
setDegreesOfFreedomInternal(df);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
getGamma().setAlpha(degreesOfFreedom / 2.0);
|
||||
setDegreesOfFreedomInternal(degreesOfFreedom);
|
||||
}
|
||||
/**
|
||||
* Modify the degrees of freedom.
|
||||
* @param degreesOfFreedom the new degrees of freedom.
|
||||
*/
|
||||
private void setDegreesOfFreedomInternal(double degreesOfFreedom) {
|
||||
gamma.setAlpha(degreesOfFreedom / 2.0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -68,7 +80,7 @@ public class ChiSquaredDistributionImpl
|
|||
* @return the degrees of freedom.
|
||||
*/
|
||||
public double getDegreesOfFreedom() {
|
||||
return getGamma().getAlpha() * 2.0;
|
||||
return gamma.getAlpha() * 2.0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -89,7 +101,7 @@ public class ChiSquaredDistributionImpl
|
|||
* computed due to convergence or other numerical errors.
|
||||
*/
|
||||
public double cumulativeProbability(double x) throws MathException {
|
||||
return getGamma().cumulativeProbability(x);
|
||||
return gamma.cumulativeProbability(x);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -128,7 +140,7 @@ public class ChiSquaredDistributionImpl
|
|||
*/
|
||||
@Override
|
||||
protected double getDomainLowerBound(double p) {
|
||||
return Double.MIN_VALUE * getGamma().getBeta();
|
||||
return Double.MIN_VALUE * gamma.getBeta();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -189,8 +201,19 @@ public class ChiSquaredDistributionImpl
|
|||
* insuring the gamma distribution has the proper parameter settings.
|
||||
* @param g the new distribution.
|
||||
* @since 1.2 made public
|
||||
* @deprecated as of 2.1 (class will become immutable in 3.0)
|
||||
*/
|
||||
@Deprecated
|
||||
public void setGamma(GammaDistribution g) {
|
||||
setGammaInternal(g);
|
||||
}
|
||||
/**
|
||||
* Modify the underlying gamma distribution. The caller is responsible for
|
||||
* insuring the gamma distribution has the proper parameter settings.
|
||||
* @param g the new distribution.
|
||||
* @since 1.2 made public
|
||||
*/
|
||||
private void setGammaInternal(GammaDistribution g) {
|
||||
this.gamma = g;
|
||||
|
||||
}
|
||||
|
|
|
@ -33,7 +33,9 @@ public interface ExponentialDistribution extends ContinuousDistribution, HasDens
|
|||
/**
|
||||
* Modify the mean.
|
||||
* @param mean the new mean.
|
||||
* @deprecated as of v2.1
|
||||
*/
|
||||
@Deprecated
|
||||
void setMean(double mean);
|
||||
|
||||
/**
|
||||
|
|
|
@ -41,15 +41,25 @@ public class ExponentialDistributionImpl extends AbstractContinuousDistribution
|
|||
*/
|
||||
public ExponentialDistributionImpl(double mean) {
|
||||
super();
|
||||
setMean(mean);
|
||||
setMeanInternal(mean);
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify the mean.
|
||||
* @param mean the new mean.
|
||||
* @throws IllegalArgumentException if <code>mean</code> is not positive.
|
||||
* @deprecated as of 2.1 (class will become immutable in 3.0)
|
||||
*/
|
||||
@Deprecated
|
||||
public void setMean(double mean) {
|
||||
setMeanInternal(mean);
|
||||
}
|
||||
/**
|
||||
* Modify the mean.
|
||||
* @param mean the new mean.
|
||||
* @throws IllegalArgumentException if <code>mean</code> is not positive.
|
||||
*/
|
||||
private void setMeanInternal(double mean) {
|
||||
if (mean <= 0.0) {
|
||||
throw MathRuntimeException.createIllegalArgumentException(
|
||||
"mean must be positive ({0})", mean);
|
||||
|
@ -75,7 +85,7 @@ public class ExponentialDistributionImpl extends AbstractContinuousDistribution
|
|||
if (x < 0) {
|
||||
return 0;
|
||||
}
|
||||
return Math.exp(-x / getMean()) / getMean();
|
||||
return Math.exp(-x / mean) / mean;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -98,7 +108,7 @@ public class ExponentialDistributionImpl extends AbstractContinuousDistribution
|
|||
if (x <= 0.0) {
|
||||
ret = 0.0;
|
||||
} else {
|
||||
ret = 1.0 - Math.exp(-x / getMean());
|
||||
ret = 1.0 - Math.exp(-x / mean);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -125,7 +135,7 @@ public class ExponentialDistributionImpl extends AbstractContinuousDistribution
|
|||
} else if (p == 1.0) {
|
||||
ret = Double.POSITIVE_INFINITY;
|
||||
} else {
|
||||
ret = -getMean() * Math.log(1.0 - p);
|
||||
ret = -mean * Math.log(1.0 - p);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -159,7 +169,7 @@ public class ExponentialDistributionImpl extends AbstractContinuousDistribution
|
|||
|
||||
if (p < .5) {
|
||||
// use mean
|
||||
return getMean();
|
||||
return mean;
|
||||
} else {
|
||||
// use max
|
||||
return Double.MAX_VALUE;
|
||||
|
@ -181,10 +191,10 @@ public class ExponentialDistributionImpl extends AbstractContinuousDistribution
|
|||
// Exponential is skewed to the left, therefore, P(X < μ) > .5
|
||||
if (p < .5) {
|
||||
// use 1/2 mean
|
||||
return getMean() * .5;
|
||||
return mean * .5;
|
||||
} else {
|
||||
// use mean
|
||||
return getMean();
|
||||
return mean;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,9 @@ 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);
|
||||
|
||||
/**
|
||||
|
@ -45,7 +47,9 @@ public interface FDistribution extends ContinuousDistribution {
|
|||
/**
|
||||
* Modify the denominator degrees of freedom.
|
||||
* @param degreesOfFreedom the new denominator degrees of freedom.
|
||||
* @deprecated as of v2.1
|
||||
*/
|
||||
@Deprecated
|
||||
void setDenominatorDegreesOfFreedom(double degreesOfFreedom);
|
||||
|
||||
/**
|
||||
|
|
|
@ -51,10 +51,10 @@ public class FDistributionImpl
|
|||
* @param denominatorDegreesOfFreedom the denominator degrees of freedom.
|
||||
*/
|
||||
public FDistributionImpl(double numeratorDegreesOfFreedom,
|
||||
double denominatorDegreesOfFreedom) {
|
||||
double denominatorDegreesOfFreedom) {
|
||||
super();
|
||||
setNumeratorDegreesOfFreedom(numeratorDegreesOfFreedom);
|
||||
setDenominatorDegreesOfFreedom(denominatorDegreesOfFreedom);
|
||||
setNumeratorDegreesOfFreedomInternal(numeratorDegreesOfFreedom);
|
||||
setDenominatorDegreesOfFreedomInternal(denominatorDegreesOfFreedom);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -77,8 +77,8 @@ public class FDistributionImpl
|
|||
if (x <= 0.0) {
|
||||
ret = 0.0;
|
||||
} else {
|
||||
double n = getNumeratorDegreesOfFreedom();
|
||||
double m = getDenominatorDegreesOfFreedom();
|
||||
double n = numeratorDegreesOfFreedom;
|
||||
double m = denominatorDegreesOfFreedom;
|
||||
|
||||
ret = Beta.regularizedBeta((n * x) / (m + n * x),
|
||||
0.5 * n,
|
||||
|
@ -151,7 +151,7 @@ public class FDistributionImpl
|
|||
@Override
|
||||
protected double getInitialDomain(double p) {
|
||||
double ret = 1.0;
|
||||
double d = getDenominatorDegreesOfFreedom();
|
||||
double d = denominatorDegreesOfFreedom;
|
||||
if (d > 2.0) {
|
||||
// use mean
|
||||
ret = d / (d - 2.0);
|
||||
|
@ -164,8 +164,20 @@ public class FDistributionImpl
|
|||
* @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(
|
||||
NON_POSITIVE_DEGREES_OF_FREEDOM_MESSAGE, degreesOfFreedom);
|
||||
|
@ -186,8 +198,20 @@ public class FDistributionImpl
|
|||
* @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(
|
||||
NON_POSITIVE_DEGREES_OF_FREEDOM_MESSAGE, degreesOfFreedom);
|
||||
|
|
|
@ -33,7 +33,9 @@ public interface GammaDistribution extends ContinuousDistribution, HasDensity<Do
|
|||
/**
|
||||
* Modify the shape parameter, alpha.
|
||||
* @param alpha the new shape parameter.
|
||||
* @deprecated as of v2.1
|
||||
*/
|
||||
@Deprecated
|
||||
void setAlpha(double alpha);
|
||||
|
||||
/**
|
||||
|
@ -45,7 +47,9 @@ public interface GammaDistribution extends ContinuousDistribution, HasDensity<Do
|
|||
/**
|
||||
* Modify the scale parameter, beta.
|
||||
* @param beta the new scale parameter.
|
||||
* @deprecated as of v2.1
|
||||
*/
|
||||
@Deprecated
|
||||
void setBeta(double beta);
|
||||
|
||||
/**
|
||||
|
|
|
@ -46,8 +46,8 @@ public class GammaDistributionImpl extends AbstractContinuousDistribution
|
|||
*/
|
||||
public GammaDistributionImpl(double alpha, double beta) {
|
||||
super();
|
||||
setAlpha(alpha);
|
||||
setBeta(beta);
|
||||
setAlphaInternal(alpha);
|
||||
setBetaInternal(beta);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -73,7 +73,7 @@ public class GammaDistributionImpl extends AbstractContinuousDistribution
|
|||
if (x <= 0.0) {
|
||||
ret = 0.0;
|
||||
} else {
|
||||
ret = Gamma.regularizedGammaP(getAlpha(), x / getBeta());
|
||||
ret = Gamma.regularizedGammaP(alpha, x / beta);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -108,8 +108,19 @@ public class GammaDistributionImpl extends AbstractContinuousDistribution
|
|||
* 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 alpha the new shape parameter.
|
||||
* @throws IllegalArgumentException if <code>alpha</code> is not positive.
|
||||
*/
|
||||
private void setAlphaInternal(double alpha) {
|
||||
if (alpha <= 0.0) {
|
||||
throw MathRuntimeException.createIllegalArgumentException(
|
||||
"alpha must be positive ({0})",
|
||||
|
@ -130,8 +141,19 @@ public class GammaDistributionImpl extends AbstractContinuousDistribution
|
|||
* Modify the scale parameter, beta.
|
||||
* @param beta the new scale parameter.
|
||||
* @throws IllegalArgumentException if <code>beta</code> is not positive.
|
||||
* @deprecated as of 2.1 (class will become immutable in 3.0)
|
||||
*/
|
||||
@Deprecated
|
||||
public void setBeta(double beta) {
|
||||
setBetaInternal(beta);
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify the scale parameter, beta.
|
||||
* @param beta the new scale parameter.
|
||||
* @throws IllegalArgumentException if <code>beta</code> is not positive.
|
||||
*/
|
||||
private void setBetaInternal(double beta) {
|
||||
if (beta <= 0.0) {
|
||||
throw MathRuntimeException.createIllegalArgumentException(
|
||||
"beta must be positive ({0})",
|
||||
|
@ -156,7 +178,7 @@ public class GammaDistributionImpl extends AbstractContinuousDistribution
|
|||
*/
|
||||
public double density(Double x) {
|
||||
if (x < 0) return 0;
|
||||
return Math.pow(x / getBeta(), getAlpha() - 1) / getBeta() * Math.exp(-x / getBeta()) / Math.exp(Gamma.logGamma(getAlpha()));
|
||||
return Math.pow(x / beta, alpha - 1) / beta * Math.exp(-x / beta) / Math.exp(Gamma.logGamma(alpha));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -193,7 +215,7 @@ public class GammaDistributionImpl extends AbstractContinuousDistribution
|
|||
|
||||
if (p < .5) {
|
||||
// use mean
|
||||
ret = getAlpha() * getBeta();
|
||||
ret = alpha * beta;
|
||||
} else {
|
||||
// use max value
|
||||
ret = Double.MAX_VALUE;
|
||||
|
@ -219,10 +241,10 @@ public class GammaDistributionImpl extends AbstractContinuousDistribution
|
|||
|
||||
if (p < .5) {
|
||||
// use 1/2 mean
|
||||
ret = getAlpha() * getBeta() * .5;
|
||||
ret = alpha * beta * .5;
|
||||
} else {
|
||||
// use mean
|
||||
ret = getAlpha() * getBeta();
|
||||
ret = alpha * beta;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -53,19 +53,24 @@ public interface HypergeometricDistribution extends IntegerDistribution {
|
|||
/**
|
||||
* Modify the number of successes.
|
||||
* @param num the new number of successes.
|
||||
* @deprecated as of v2.1
|
||||
*/
|
||||
@Deprecated
|
||||
void setNumberOfSuccesses(int num);
|
||||
|
||||
/**
|
||||
* Modify the population size.
|
||||
* @param size the new population size.
|
||||
* @deprecated as of v2.1
|
||||
*/
|
||||
@Deprecated
|
||||
void setPopulationSize(int size);
|
||||
|
||||
/**
|
||||
* Modify the sample size.
|
||||
* @param size the new sample size.
|
||||
* @deprecated as of v2.1
|
||||
*/
|
||||
@Deprecated
|
||||
void setSampleSize(int size);
|
||||
|
||||
}
|
||||
|
|
|
@ -65,9 +65,10 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
|
|||
"sample size ({0}) must be less than or equal to population size ({1})",
|
||||
sampleSize, populationSize);
|
||||
}
|
||||
setPopulationSize(populationSize);
|
||||
setSampleSize(sampleSize);
|
||||
setNumberOfSuccesses(numberOfSuccesses);
|
||||
|
||||
setPopulationSizeInternal(populationSize);
|
||||
setSampleSizeInternal(sampleSize);
|
||||
setNumberOfSuccessesInternal(numberOfSuccesses);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -80,17 +81,14 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
|
|||
public double cumulativeProbability(int x) {
|
||||
double ret;
|
||||
|
||||
int n = getPopulationSize();
|
||||
int m = getNumberOfSuccesses();
|
||||
int k = getSampleSize();
|
||||
|
||||
int[] domain = getDomain(n, m, k);
|
||||
int[] domain = getDomain(populationSize, numberOfSuccesses, sampleSize);
|
||||
if (x < domain[0]) {
|
||||
ret = 0.0;
|
||||
} else if (x >= domain[1]) {
|
||||
ret = 1.0;
|
||||
} else {
|
||||
ret = innerCumulativeProbability(domain[0], x, 1, n, m, k);
|
||||
ret = innerCumulativeProbability(domain[0], x, 1, populationSize,
|
||||
numberOfSuccesses, sampleSize);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -119,8 +117,7 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
|
|||
*/
|
||||
@Override
|
||||
protected int getDomainLowerBound(double p) {
|
||||
return getLowerDomain(getPopulationSize(), getNumberOfSuccesses(),
|
||||
getSampleSize());
|
||||
return getLowerDomain(populationSize, numberOfSuccesses, sampleSize);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -133,7 +130,7 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
|
|||
*/
|
||||
@Override
|
||||
protected int getDomainUpperBound(double p) {
|
||||
return getUpperDomain(getSampleSize(), getNumberOfSuccesses());
|
||||
return getUpperDomain(sampleSize, numberOfSuccesses);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -197,23 +194,19 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
|
|||
public double probability(int x) {
|
||||
double ret;
|
||||
|
||||
int m = getPopulationSize();
|
||||
int s = getNumberOfSuccesses();
|
||||
int f = m - s;
|
||||
int k = getSampleSize();
|
||||
|
||||
int[] domain = getDomain(m, s, k);
|
||||
int[] domain = getDomain(populationSize, numberOfSuccesses, sampleSize);
|
||||
if (x < domain[0] || x > domain[1]) {
|
||||
ret = 0.0;
|
||||
} else {
|
||||
double p = (double) sampleSize / (double) m;
|
||||
double q = (double) (m - sampleSize) / (double) m;
|
||||
double p = (double) sampleSize / (double) populationSize;
|
||||
double q = (double) (populationSize - sampleSize) / (double) populationSize;
|
||||
double p1 = SaddlePointExpansion.logBinomialProbability(x,
|
||||
numberOfSuccesses, p, q);
|
||||
double p2 =
|
||||
SaddlePointExpansion.logBinomialProbability(sampleSize - x, f, p, q);
|
||||
SaddlePointExpansion.logBinomialProbability(sampleSize - x,
|
||||
populationSize - numberOfSuccesses, p, q);
|
||||
double p3 =
|
||||
SaddlePointExpansion.logBinomialProbability(sampleSize, m, p, q);
|
||||
SaddlePointExpansion.logBinomialProbability(sampleSize, populationSize, p, q);
|
||||
ret = Math.exp(p1 + p2 - p3);
|
||||
}
|
||||
|
||||
|
@ -241,8 +234,19 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
|
|||
*
|
||||
* @param num the new number of successes.
|
||||
* @throws IllegalArgumentException if <code>num</code> is negative.
|
||||
* @deprecated as of 2.1 (class will become immutable in 3.0)
|
||||
*/
|
||||
@Deprecated
|
||||
public void setNumberOfSuccesses(int num) {
|
||||
setNumberOfSuccessesInternal(num);
|
||||
}
|
||||
/**
|
||||
* Modify the number of successes.
|
||||
*
|
||||
* @param num the new number of successes.
|
||||
* @throws IllegalArgumentException if <code>num</code> is negative.
|
||||
*/
|
||||
private void setNumberOfSuccessesInternal(int num) {
|
||||
if (num < 0) {
|
||||
throw MathRuntimeException.createIllegalArgumentException(
|
||||
"number of successes must be non-negative ({0})", num);
|
||||
|
@ -255,8 +259,19 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
|
|||
*
|
||||
* @param size the new population size.
|
||||
* @throws IllegalArgumentException if <code>size</code> is not positive.
|
||||
* @deprecated as of 2.1 (class will become immutable in 3.0)
|
||||
*/
|
||||
@Deprecated
|
||||
public void setPopulationSize(int size) {
|
||||
setPopulationSizeInternal(size);
|
||||
}
|
||||
/**
|
||||
* Modify the population size.
|
||||
*
|
||||
* @param size the new population size.
|
||||
* @throws IllegalArgumentException if <code>size</code> is not positive.
|
||||
*/
|
||||
private void setPopulationSizeInternal(int size) {
|
||||
if (size <= 0) {
|
||||
throw MathRuntimeException.createIllegalArgumentException(
|
||||
"population size must be positive ({0})", size);
|
||||
|
@ -269,8 +284,19 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
|
|||
*
|
||||
* @param size the new sample size.
|
||||
* @throws IllegalArgumentException if <code>size</code> is negative.
|
||||
* @deprecated as of 2.1 (class will become immutable in 3.0)
|
||||
*/
|
||||
@Deprecated
|
||||
public void setSampleSize(int size) {
|
||||
setSampleSizeInternal(size);
|
||||
}
|
||||
/**
|
||||
* Modify the sample size.
|
||||
*
|
||||
* @param size the new sample size.
|
||||
* @throws IllegalArgumentException if <code>size</code> is negative.
|
||||
*/
|
||||
private void setSampleSizeInternal(int size) {
|
||||
if (size < 0) {
|
||||
throw MathRuntimeException.createIllegalArgumentException(
|
||||
"sample size must be positive ({0})", size);
|
||||
|
@ -288,17 +314,13 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
|
|||
public double upperCumulativeProbability(int x) {
|
||||
double ret;
|
||||
|
||||
int n = getPopulationSize();
|
||||
int m = getNumberOfSuccesses();
|
||||
int k = getSampleSize();
|
||||
|
||||
int[] domain = getDomain(n, m, k);
|
||||
final int[] domain = getDomain(populationSize, numberOfSuccesses, sampleSize);
|
||||
if (x < domain[0]) {
|
||||
ret = 1.0;
|
||||
} else if (x > domain[1]) {
|
||||
ret = 0.0;
|
||||
} else {
|
||||
ret = innerCumulativeProbability(domain[1], x, -1, n, m, k);
|
||||
ret = innerCumulativeProbability(domain[1], x, -1, populationSize, numberOfSuccesses, sampleSize);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -39,7 +39,9 @@ public interface NormalDistribution extends ContinuousDistribution, HasDensity<D
|
|||
/**
|
||||
* Modify the mean.
|
||||
* @param mean for this distribution
|
||||
* @deprecated as of v2.1
|
||||
*/
|
||||
@Deprecated
|
||||
void setMean(double mean);
|
||||
/**
|
||||
* Access the standard deviation.
|
||||
|
@ -49,7 +51,9 @@ public interface NormalDistribution extends ContinuousDistribution, HasDensity<D
|
|||
/**
|
||||
* Modify the standard deviation.
|
||||
* @param sd standard deviation for this distribution
|
||||
* @deprecated as of v2.1
|
||||
*/
|
||||
@Deprecated
|
||||
void setStandardDeviation(double sd);
|
||||
|
||||
/**
|
||||
|
|
|
@ -70,8 +70,8 @@ public class NormalDistributionImpl extends AbstractContinuousDistribution
|
|||
*/
|
||||
public NormalDistributionImpl(double mean, double sd, double inverseCumAccuracy) {
|
||||
super();
|
||||
this.mean = mean;
|
||||
this.standardDeviation = sd;
|
||||
setMeanInternal(mean);
|
||||
setStandardDeviationInternal(sd);
|
||||
solverAbsoluteAccuracy = inverseCumAccuracy;
|
||||
}
|
||||
|
||||
|
@ -94,8 +94,17 @@ public class NormalDistributionImpl extends AbstractContinuousDistribution
|
|||
/**
|
||||
* Modify the mean.
|
||||
* @param mean for this distribution
|
||||
* @deprecated as of 2.1 (class will become immutable in 3.0)
|
||||
*/
|
||||
@Deprecated
|
||||
public void setMean(double mean) {
|
||||
setMeanInternal(mean);
|
||||
}
|
||||
/**
|
||||
* Modify the mean.
|
||||
* @param mean for this distribution
|
||||
*/
|
||||
private void setMeanInternal(double mean) {
|
||||
this.mean = mean;
|
||||
}
|
||||
|
||||
|
@ -111,8 +120,18 @@ public class NormalDistributionImpl extends AbstractContinuousDistribution
|
|||
* Modify the standard deviation.
|
||||
* @param sd standard deviation 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 setStandardDeviation(double sd) {
|
||||
setStandardDeviationInternal(sd);
|
||||
}
|
||||
/**
|
||||
* Modify the standard deviation.
|
||||
* @param sd standard deviation for this distribution
|
||||
* @throws IllegalArgumentException if <code>sd</code> is not positive.
|
||||
*/
|
||||
private void setStandardDeviationInternal(double sd) {
|
||||
if (sd <= 0.0) {
|
||||
throw MathRuntimeException.createIllegalArgumentException(
|
||||
"standard deviation must be positive ({0})",
|
||||
|
@ -128,8 +147,8 @@ public class NormalDistributionImpl extends AbstractContinuousDistribution
|
|||
* @return The pdf at point x.
|
||||
*/
|
||||
public double density(Double x) {
|
||||
double x0 = x - getMean();
|
||||
return Math.exp(-x0 * x0 / (2 * getStandardDeviation() * getStandardDeviation())) / (getStandardDeviation() * SQRT2PI);
|
||||
double x0 = x - mean;
|
||||
return Math.exp(-x0 * x0 / (2 * standardDeviation * standardDeviation)) / (standardDeviation * SQRT2PI);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -208,7 +227,7 @@ public class NormalDistributionImpl extends AbstractContinuousDistribution
|
|||
if (p < .5) {
|
||||
ret = -Double.MAX_VALUE;
|
||||
} else {
|
||||
ret = getMean();
|
||||
ret = mean;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -228,7 +247,7 @@ public class NormalDistributionImpl extends AbstractContinuousDistribution
|
|||
double ret;
|
||||
|
||||
if (p < .5) {
|
||||
ret = getMean();
|
||||
ret = mean;
|
||||
} else {
|
||||
ret = Double.MAX_VALUE;
|
||||
}
|
||||
|
@ -249,11 +268,11 @@ public class NormalDistributionImpl extends AbstractContinuousDistribution
|
|||
double ret;
|
||||
|
||||
if (p < .5) {
|
||||
ret = getMean() - getStandardDeviation();
|
||||
ret = mean - standardDeviation;
|
||||
} else if (p > .5) {
|
||||
ret = getMean() + getStandardDeviation();
|
||||
ret = mean + standardDeviation;
|
||||
} else {
|
||||
ret = getMean();
|
||||
ret = mean;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -57,13 +57,17 @@ public interface PascalDistribution extends IntegerDistribution {
|
|||
* Change the number of successes for this distribution.
|
||||
*
|
||||
* @param successes the new number of successes
|
||||
* @deprecated as of v2.1
|
||||
*/
|
||||
@Deprecated
|
||||
void setNumberOfSuccesses(int successes);
|
||||
|
||||
/**
|
||||
* Change the probability of success for this distribution.
|
||||
*
|
||||
* @param p the new probability of success
|
||||
* @deprecated as of v2.1
|
||||
*/
|
||||
@Deprecated
|
||||
void setProbabilityOfSuccess(double p);
|
||||
}
|
||||
|
|
|
@ -48,8 +48,8 @@ public class PascalDistributionImpl extends AbstractIntegerDistribution
|
|||
*/
|
||||
public PascalDistributionImpl(int r, double p) {
|
||||
super();
|
||||
setNumberOfSuccesses(r);
|
||||
setProbabilityOfSuccess(p);
|
||||
setNumberOfSuccessesInternal(r);
|
||||
setProbabilityOfSuccessInternal(p);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -73,8 +73,19 @@ public class PascalDistributionImpl extends AbstractIntegerDistribution
|
|||
* @param successes the new number of successes
|
||||
* @throws IllegalArgumentException if <code>successes</code> is not
|
||||
* positive.
|
||||
* @deprecated as of 2.1 (class will become immutable in 3.0)
|
||||
*/
|
||||
@Deprecated
|
||||
public void setNumberOfSuccesses(int successes) {
|
||||
setNumberOfSuccessesInternal(successes);
|
||||
}
|
||||
/**
|
||||
* Change the number of successes for this distribution.
|
||||
* @param successes the new number of successes
|
||||
* @throws IllegalArgumentException if <code>successes</code> is not
|
||||
* positive.
|
||||
*/
|
||||
private void setNumberOfSuccessesInternal(int successes) {
|
||||
if (successes < 0) {
|
||||
throw MathRuntimeException.createIllegalArgumentException(
|
||||
"number of successes must be non-negative ({0})",
|
||||
|
@ -88,8 +99,19 @@ public class PascalDistributionImpl extends AbstractIntegerDistribution
|
|||
* @param p the new probability of success
|
||||
* @throws IllegalArgumentException if <code>p</code> is not a valid
|
||||
* probability.
|
||||
* @deprecated as of 2.1 (class will become immutable in 3.0)
|
||||
*/
|
||||
@Deprecated
|
||||
public void setProbabilityOfSuccess(double p) {
|
||||
setProbabilityOfSuccessInternal(p);
|
||||
}
|
||||
/**
|
||||
* Change the probability of success for this distribution.
|
||||
* @param p the new probability of success
|
||||
* @throws IllegalArgumentException if <code>p</code> is not a valid
|
||||
* probability.
|
||||
*/
|
||||
private void setProbabilityOfSuccessInternal(double p) {
|
||||
if (p < 0.0 || p > 1.0) {
|
||||
throw MathRuntimeException.createIllegalArgumentException(
|
||||
"{0} out of [{1}, {2}] range", p, 0.0, 1.0);
|
||||
|
@ -135,8 +157,8 @@ public class PascalDistributionImpl extends AbstractIntegerDistribution
|
|||
if (x < 0) {
|
||||
ret = 0.0;
|
||||
} else {
|
||||
ret = Beta.regularizedBeta(getProbabilityOfSuccess(),
|
||||
getNumberOfSuccesses(), x + 1);
|
||||
ret = Beta.regularizedBeta(probabilityOfSuccess,
|
||||
numberOfSuccesses, x + 1);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -152,9 +174,9 @@ public class PascalDistributionImpl extends AbstractIntegerDistribution
|
|||
ret = 0.0;
|
||||
} else {
|
||||
ret = MathUtils.binomialCoefficientDouble(x +
|
||||
getNumberOfSuccesses() - 1, getNumberOfSuccesses() - 1) *
|
||||
Math.pow(getProbabilityOfSuccess(), getNumberOfSuccesses()) *
|
||||
Math.pow(1.0 - getProbabilityOfSuccess(), x);
|
||||
numberOfSuccesses - 1, numberOfSuccesses - 1) *
|
||||
Math.pow(probabilityOfSuccess, numberOfSuccesses) *
|
||||
Math.pow(1.0 - probabilityOfSuccess, x);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -47,7 +47,9 @@ public interface PoissonDistribution extends IntegerDistribution {
|
|||
*
|
||||
* @param p the mean
|
||||
* @throws IllegalArgumentException if p ≤ 0
|
||||
* @deprecated as of v2.1
|
||||
*/
|
||||
@Deprecated
|
||||
void setMean(double p);
|
||||
|
||||
/**
|
||||
|
|
|
@ -121,11 +121,13 @@ public class PoissonDistributionImpl extends AbstractIntegerDistribution
|
|||
* @param z a normal distribution used to compute normal approximations.
|
||||
* @throws IllegalArgumentException if p ≤ 0
|
||||
* @since 1.2
|
||||
* @deprecated as of 2.1 (to avoid possibly inconsistent state, the
|
||||
* "NormalDistribution" will be instantiated internally)
|
||||
*/
|
||||
@Deprecated
|
||||
public PoissonDistributionImpl(double p, NormalDistribution z) {
|
||||
super();
|
||||
setNormal(z);
|
||||
setMean(p);
|
||||
setNormalAndMeanInternal(z, p);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -134,7 +136,7 @@ public class PoissonDistributionImpl extends AbstractIntegerDistribution
|
|||
* @return the Poisson mean for the distribution.
|
||||
*/
|
||||
public double getMean() {
|
||||
return this.mean;
|
||||
return mean;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -143,13 +145,28 @@ public class PoissonDistributionImpl extends AbstractIntegerDistribution
|
|||
*
|
||||
* @param p the Poisson mean value
|
||||
* @throws IllegalArgumentException if p ≤ 0
|
||||
* @deprecated as of 2.1 (class will become immutable in 3.0)
|
||||
*/
|
||||
@Deprecated
|
||||
public void setMean(double p) {
|
||||
setNormalAndMeanInternal(normal, p);
|
||||
}
|
||||
/**
|
||||
* Set the Poisson mean for the distribution. The mean value must be
|
||||
* positive; otherwise an <code>IllegalArgument</code> is thrown.
|
||||
*
|
||||
* @param z the new distribution
|
||||
* @param p the Poisson mean value
|
||||
* @throws IllegalArgumentException if p ≤ 0
|
||||
*/
|
||||
private void setNormalAndMeanInternal(NormalDistribution z,
|
||||
double p) {
|
||||
if (p <= 0) {
|
||||
throw MathRuntimeException.createIllegalArgumentException(
|
||||
"the Poisson mean must be positive ({0})", p);
|
||||
}
|
||||
this.mean = p;
|
||||
mean = p;
|
||||
normal = z;
|
||||
normal.setMean(p);
|
||||
normal.setStandardDeviation(Math.sqrt(p));
|
||||
}
|
||||
|
@ -248,9 +265,10 @@ public class PoissonDistributionImpl extends AbstractIntegerDistribution
|
|||
*
|
||||
* @param value the new distribution
|
||||
* @since 1.2
|
||||
* @deprecated as of 2.1 (class will become immutable in 3.0)
|
||||
*/
|
||||
@Deprecated
|
||||
public void setNormal(NormalDistribution value) {
|
||||
normal = value;
|
||||
setNormalAndMeanInternal(value, mean);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -33,7 +33,9 @@ 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);
|
||||
|
||||
/**
|
||||
|
|
|
@ -44,14 +44,23 @@ public class TDistributionImpl
|
|||
*/
|
||||
public TDistributionImpl(double degreesOfFreedom) {
|
||||
super();
|
||||
setDegreesOfFreedom(degreesOfFreedom);
|
||||
setDegreesOfFreedomInternal(degreesOfFreedom);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 degreesOfFreedom the new degrees of freedom.
|
||||
*/
|
||||
private void setDegreesOfFreedomInternal(double degreesOfFreedom) {
|
||||
if (degreesOfFreedom <= 0.0) {
|
||||
throw MathRuntimeException.createIllegalArgumentException(
|
||||
"degrees of freedom must be positive ({0})",
|
||||
|
@ -82,8 +91,8 @@ public class TDistributionImpl
|
|||
} else {
|
||||
double t =
|
||||
Beta.regularizedBeta(
|
||||
getDegreesOfFreedom() / (getDegreesOfFreedom() + (x * x)),
|
||||
0.5 * getDegreesOfFreedom(),
|
||||
degreesOfFreedom / (degreesOfFreedom + (x * x)),
|
||||
0.5 * degreesOfFreedom,
|
||||
0.5);
|
||||
if (x < 0.0) {
|
||||
ret = 0.5 * t;
|
||||
|
|
|
@ -51,12 +51,16 @@ public interface WeibullDistribution extends ContinuousDistribution {
|
|||
/**
|
||||
* 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);
|
||||
}
|
||||
|
|
|
@ -48,8 +48,8 @@ public class WeibullDistributionImpl extends AbstractContinuousDistribution
|
|||
*/
|
||||
public WeibullDistributionImpl(double alpha, double beta){
|
||||
super();
|
||||
setShape(alpha);
|
||||
setScale(beta);
|
||||
setShapeInternal(alpha);
|
||||
setScaleInternal(beta);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -62,7 +62,7 @@ public class WeibullDistributionImpl extends AbstractContinuousDistribution
|
|||
if (x <= 0.0) {
|
||||
ret = 0.0;
|
||||
} else {
|
||||
ret = 1.0 - Math.exp(-Math.pow(x / getScale(), getShape()));
|
||||
ret = 1.0 - Math.exp(-Math.pow(x / scale, shape));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ public class WeibullDistributionImpl extends AbstractContinuousDistribution
|
|||
} else if (p == 1) {
|
||||
ret = Double.POSITIVE_INFINITY;
|
||||
} else {
|
||||
ret = getScale() * Math.pow(-Math.log(1.0 - p), 1.0 / getShape());
|
||||
ret = scale * Math.pow(-Math.log(1.0 - p), 1.0 / shape);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -114,8 +114,17 @@ public class WeibullDistributionImpl extends AbstractContinuousDistribution
|
|||
/**
|
||||
* 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(
|
||||
"shape must be positive ({0})",
|
||||
|
@ -127,8 +136,17 @@ public class WeibullDistributionImpl extends AbstractContinuousDistribution
|
|||
/**
|
||||
* 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(
|
||||
"scale must be positive ({0})",
|
||||
|
@ -176,6 +194,6 @@ public class WeibullDistributionImpl extends AbstractContinuousDistribution
|
|||
@Override
|
||||
protected double getInitialDomain(double p) {
|
||||
// use median
|
||||
return Math.pow(getScale() * Math.log(2.0), 1.0 / getShape());
|
||||
return Math.pow(scale * Math.log(2.0), 1.0 / shape);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,9 @@ public interface ZipfDistribution extends IntegerDistribution {
|
|||
*
|
||||
* @param n the number of elements
|
||||
* @throws IllegalArgumentException if n ≤ 0
|
||||
* @deprecated as of v2.1
|
||||
*/
|
||||
@Deprecated
|
||||
void setNumberOfElements(int n);
|
||||
|
||||
/**
|
||||
|
@ -62,7 +64,8 @@ public interface ZipfDistribution extends IntegerDistribution {
|
|||
*
|
||||
* @param s the exponent
|
||||
* @throws IllegalArgumentException if s ≤ 0.0
|
||||
* @deprecated as of v2.1
|
||||
*/
|
||||
@Deprecated
|
||||
void setExponent(double s);
|
||||
|
||||
}
|
||||
|
|
|
@ -49,8 +49,8 @@ public class ZipfDistributionImpl extends AbstractIntegerDistribution
|
|||
*/
|
||||
public ZipfDistributionImpl(final int numberOfElements, final double exponent)
|
||||
throws IllegalArgumentException {
|
||||
setNumberOfElements(numberOfElements);
|
||||
setExponent(exponent);
|
||||
setNumberOfElementsInternal(numberOfElements);
|
||||
setExponentInternal(exponent);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -69,8 +69,21 @@ public class ZipfDistributionImpl extends AbstractIntegerDistribution
|
|||
*
|
||||
* @param n the number of elements
|
||||
* @exception IllegalArgumentException if n ≤ 0
|
||||
* @deprecated as of 2.1 (class will become immutable in 3.0)
|
||||
*/
|
||||
public void setNumberOfElements(final int n)
|
||||
@Deprecated
|
||||
public void setNumberOfElements(final int n) {
|
||||
setNumberOfElementsInternal(n);
|
||||
}
|
||||
/**
|
||||
* Set the number of elements (e.g. corpus size) for the distribution.
|
||||
* The parameter value must be positive; otherwise an
|
||||
* <code>IllegalArgumentException</code> is thrown.
|
||||
*
|
||||
* @param n the number of elements
|
||||
* @exception IllegalArgumentException if n ≤ 0
|
||||
*/
|
||||
private void setNumberOfElementsInternal(final int n)
|
||||
throws IllegalArgumentException {
|
||||
if (n <= 0) {
|
||||
throw MathRuntimeException.createIllegalArgumentException(
|
||||
|
@ -96,8 +109,21 @@ public class ZipfDistributionImpl extends AbstractIntegerDistribution
|
|||
*
|
||||
* @param s the exponent
|
||||
* @exception IllegalArgumentException if s ≤ 0.0
|
||||
* @deprecated as of 2.1 (class will become immutable in 3.0)
|
||||
*/
|
||||
public void setExponent(final double s)
|
||||
@Deprecated
|
||||
public void setExponent(final double s) {
|
||||
setExponentInternal(s);
|
||||
}
|
||||
/**
|
||||
* Set the exponent characterising the distribution.
|
||||
* The parameter value must be positive; otherwise an
|
||||
* <code>IllegalArgumentException</code> is thrown.
|
||||
*
|
||||
* @param s the exponent
|
||||
* @exception IllegalArgumentException if s ≤ 0.0
|
||||
*/
|
||||
private void setExponentInternal(final double s)
|
||||
throws IllegalArgumentException {
|
||||
if (s <= 0.0) {
|
||||
throw MathRuntimeException.createIllegalArgumentException(
|
||||
|
@ -114,7 +140,7 @@ public class ZipfDistributionImpl extends AbstractIntegerDistribution
|
|||
* @return the value of the probability mass function at x
|
||||
*/
|
||||
public double probability(final int x) {
|
||||
if (x <= 0 || x > getNumberOfElements()) {
|
||||
if (x <= 0 || x > numberOfElements) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
|
@ -132,7 +158,7 @@ public class ZipfDistributionImpl extends AbstractIntegerDistribution
|
|||
public double cumulativeProbability(final int x) {
|
||||
if (x <= 0) {
|
||||
return 0.0;
|
||||
} else if (x >= getNumberOfElements()) {
|
||||
} else if (x >= numberOfElements) {
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue