in commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/ParetoDistribution.java [59:90]
private ParetoDistribution(double scale,
double shape) {
this.scale = scale;
this.shape = shape;
// The Pareto distribution approaches a Dirac delta function when shape -> inf.
// Parameterisations can also lead to underflow in the standard computation.
// Extract the PDF and CDF to specialized implementations to handle edge cases.
// Pre-compute factors for the standard computation
final double shapeByScalePowShape = shape * Math.pow(scale, shape);
final double logShapePlusShapeByLogScale = Math.log(shape) + Math.log(scale) * shape;
if (shapeByScalePowShape < Double.POSITIVE_INFINITY &&
shapeByScalePowShape >= Double.MIN_NORMAL) {
// Standard computation
pdf = x -> shapeByScalePowShape / Math.pow(x, shape + 1);
logpdf = x -> logShapePlusShapeByLogScale - Math.log(x) * (shape + 1);
} else {
// Standard computation overflow; underflow to sub-normal or zero; or nan (pow(1.0, inf))
if (Double.isFinite(logShapePlusShapeByLogScale)) {
// Log computation is valid
logpdf = x -> logShapePlusShapeByLogScale - Math.log(x) * (shape + 1);
pdf = x -> Math.exp(logpdf.applyAsDouble(x));
} else {
// Assume Dirac function
logpdf = x -> x > scale ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY;
// PDF has infinite value at lower bound
pdf = x -> x > scale ? 0 : Double.POSITIVE_INFINITY;
}
}
}