code cleanup in GeometricDistribution.java as proposed by Gilles:

* removed needless declaration of a local variable "p" with the same
value as the "probabilityOfSuccess" field
* remove needless local variable "ret" ("return" statements can be used
directly in each way of the alternatives)
This commit is contained in:
Otmar Ertl 2015-09-20 20:11:47 +02:00
parent fb0078159d
commit 73351b6adb
1 changed files with 8 additions and 19 deletions

View File

@ -82,40 +82,31 @@ public class GeometricDistribution extends AbstractIntegerDistribution {
/** {@inheritDoc} */
@Override
public double probability(int x) {
double ret;
if (x < 0) {
ret = 0.0;
return 0.0;
} else {
final double p = probabilityOfSuccess;
ret = FastMath.pow(1 - p, x) * p;
return FastMath.pow(1 - probabilityOfSuccess, x) * probabilityOfSuccess;
}
return ret;
}
/** {@inheritDoc} */
@Override
public double logProbability(int x) {
double ret;
if (x < 0) {
ret = Double.NEGATIVE_INFINITY;
return Double.NEGATIVE_INFINITY;
} else {
final double p = probabilityOfSuccess;
ret = x * FastMath.log1p(-p) + FastMath.log(p);
return x * FastMath.log1p(-probabilityOfSuccess) + FastMath.log(probabilityOfSuccess);
}
return ret;
}
/** {@inheritDoc} */
@Override
public double cumulativeProbability(int x) {
double ret;
if (x < 0) {
ret = 0.0;
return 0.0;
} else {
final double p = probabilityOfSuccess;
ret = 1.0 - FastMath.pow(1 - p, x + 1);
return 1.0 - FastMath.pow(1 - probabilityOfSuccess, x + 1);
}
return ret;
}
/**
@ -125,8 +116,7 @@ public class GeometricDistribution extends AbstractIntegerDistribution {
*/
@Override
public double getNumericalMean() {
final double p = probabilityOfSuccess;
return (1 - p) / p;
return (1 - probabilityOfSuccess) / probabilityOfSuccess;
}
/**
@ -137,8 +127,7 @@ public class GeometricDistribution extends AbstractIntegerDistribution {
*/
@Override
public double getNumericalVariance() {
final double p = probabilityOfSuccess;
return (1 - p) / (p * p);
return (1 - probabilityOfSuccess) / (probabilityOfSuccess * probabilityOfSuccess);
}
/**