Applied vignette · custom distributions · 0.6.0+
Build a bounded sensor-error law
A sensor reports errors only between −2 and 2 units. Small errors are common and large errors taper exponentially. That domain statement is enough to build a reusable probability distribution.
Available from 0.6.01 · Translate the story
Use a kernel, not a finished density
Let the unnormalized shape be exp(-abs(error) / 0.55) on [−2, 2]. It is nonnegative, symmetric, bounded, and has finite area. We deliberately omit its normalizing constant.
2 · Construct once
Declare the formula and support
import jdistlib.DiagnosticPreset;
import jdistlib.NumericalContinuousDistribution;
NumericalContinuousDistribution error =
NumericalContinuousDistribution.builder()
.kernel(x -> Math.exp(-Math.abs(x) / 0.55))
.support(-2.0, 2.0)
.singularities(0.0)
.diagnosticPreset(DiagnosticPreset.THOROUGH)
.build();
double normalizer = error.getNormalizationConstant();The point at zero is not mathematically singular, but declaring it as an integration breakpoint tells the numerical routine where the derivative changes abruptly.
3 · Ask domain questions
The custom law now has the familiar API
// Probability of meeting a ±0.5-unit accuracy requirement.
double withinTolerance =
error.cumulative(0.5, true, false)
- error.cumulative(-0.5, true, false);
// Central interval containing 95% of modeled errors.
ProbabilityInterval central = error.probabilityInterval(0.95);
// Repeatable simulation for a test or report.
error.setRandomEngine(new MersenneTwister(20260826L));
double[] simulatedErrors = error.random(1_000);4 · Inspect and test
Use structural and data checks together
DistributionAnalysis report = error.analyzeDistribution();
if (report.hasErrors()) {
System.err.println(report);
}
double[] observedErrors = {
-0.82, -0.31, -0.12, -0.03, 0.04, 0.15, 0.37, 0.73
};
double[] cvm = DistributionTest.cramer_von_mises_test(
observedErrors, error, 1_999, new MersenneTwister(7L));The construction report checks numerical behavior of the formula. The Cramér–von Mises test asks whether observations are compatible with this fully specified distribution. They answer different questions, so keep both.
5 · Know what was assumed
The support is a scientific claim
This model assigns exactly zero probability outside [−2, 2]. That is appropriate only if the physical or recording process truly enforces those bounds. If extreme errors are merely rare, use infinite support and justify the tail shape instead.
Next
Go from example to production
Read the full custom-distribution guide for log-kernels, discrete weights, mixtures, transforms, sampling strategies, and troubleshooting.