[MATH-1039] Avoid code duplication by calling logDensity itself.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1533990 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Thomas Neidhart 2013-10-20 21:24:45 +00:00
parent 422fc2a426
commit fb3a167582
1 changed files with 2 additions and 18 deletions

View File

@ -136,24 +136,8 @@ public class BetaDistribution extends AbstractRealDistribution {
/** {@inheritDoc} */
public double density(double x) {
recomputeZ();
if (x < 0 || x > 1) {
return 0;
} else if (x == 0) {
if (alpha < 1) {
throw new NumberIsTooSmallException(LocalizedFormats.CANNOT_COMPUTE_BETA_DENSITY_AT_0_FOR_SOME_ALPHA, alpha, 1, false);
}
return 0;
} else if (x == 1) {
if (beta < 1) {
throw new NumberIsTooSmallException(LocalizedFormats.CANNOT_COMPUTE_BETA_DENSITY_AT_1_FOR_SOME_BETA, beta, 1, false);
}
return 0;
} else {
double logX = FastMath.log(x);
double log1mX = FastMath.log1p(-x);
return FastMath.exp((alpha - 1) * logX + (beta - 1) * log1mX - z);
}
final double logDensity = logDensity(x);
return logDensity == Double.NEGATIVE_INFINITY ? 0 : FastMath.exp(logDensity);
}
/** {@inheritDoc} **/