Package jdistlib
Class NumericalContinuousDistribution
java.lang.Object
jdistlib.generic.GenericDistribution
jdistlib.NumericalContinuousDistribution
- All Implemented Interfaces:
SupportedDistribution
public class NumericalContinuousDistribution
extends GenericDistribution
implements SupportedDistribution
A continuous distribution obtained by numerically normalizing a nonnegative
kernel over a real interval.
If kernel is g, this class uses the density
g(x) / Z, where Z = integral(g(x), lower, upper). Bounds may
be finite or infinite. The normalization integral is evaluated once during
construction; CDF values and quantiles are evaluated numerically on demand.
The supplied function must remain deterministic and thread-safe if the
distribution is shared between threads.
Successful numerical integration cannot prove that an arbitrary function
is nonnegative or integrable everywhere. Kernel values encountered by the
integrator are checked, and the normalization result is available through
getNormalizationResult() for inspection.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classFluent construction with optional analysis and sampling configuration. -
Field Summary
Fields inherited from class jdistlib.generic.GenericDistribution
random -
Constructor Summary
ConstructorsConstructorDescriptionNumericalContinuousDistribution(UnivariateFunction kernel, double lower, double upper) Constructs a distribution using distribution-oriented integration defaults: relative tolerance1e-10, 300 subdivisions, a finite evaluation budget, and automatic finite-interval tanh-sinh fallback.NumericalContinuousDistribution(UnivariateFunction kernel, double lower, double upper, double epsabs, double epsrel, int subdivisions) Constructs a distribution with explicit QUADPACK tolerances.NumericalContinuousDistribution(UnivariateFunction kernel, double lower, double upper, IntegrationOptions options) Constructs a distribution with hardened integration options. -
Method Summary
Modifier and TypeMethodDescriptionanalyze(UnivariateFunction kernel, double lower, double upper) Analyzes a kernel and attempts construction using the analyzer's integration settings plus any suggested breakpoints.analyze(UnivariateFunction kernel, double lower, double upper, ConstructionPolicy policy) Analyzes using defaults and an explicit construction policy.analyze(UnivariateFunction kernel, double lower, double upper, FunctionAnalysisOptions analysisOptions) Analyzes and attempts construction with explicit analysis settings.Runs CDF, quantile, tail, normalization, and moment diagnostics.analyzeDistribution(MomentAnalysisOptions settings) Runs diagnostics with user-selected absolute-moment orders and tail split.analyzeLogKernel(UnivariateFunction logKernel, double lower, double upper) Analyzes a log-kernel in log space and attempts construction using the default settings.analyzeLogKernel(UnivariateFunction logKernel, double lower, double upper, ConstructionPolicy policy) Analyzes a log-kernel with defaults and an explicit policy.analyzeLogKernel(UnivariateFunction logKernel, double lower, double upper, FunctionAnalysisOptions analysisOptions) Analyzes and attempts log-kernel construction with explicit settings.builder()Returns a fluent builder for a custom continuous distribution.centralMoment(double order) Numerically evaluates E[(X-E[X])^order].voidvoidDrops the table so the next CDF or central quantile call rebuilds it.voidRestores inverse-CDF sampling.voidconfigureAdaptiveRejectionSampling(UnivariateFunction logDerivative, int maximumKnots, int maximumAttempts, double... initialPoints) Configures adaptive rejection under a caller-certified log-concavity promise.voidconfigureRejectionSampling(RejectionEnvelope envelope, int maxAttempts) Configures rejection-envelope sampling for subsequentrandom()calls.voidconfigureUniformRejectionSampling(double logDensityUpperBound, int maxAttempts) Configures a uniform rejection envelope over this finite support.doublecumulative(double x, boolean lowerTail, boolean logP) doublecumulativeCached(double x, boolean lowerTail, boolean logP) Evaluates through the reusable CDF table.voidcumulativeInto(double[] input, int inputOffset, double[] output, int outputOffset, int length, boolean lowerTail, boolean logP) Batch CDF evaluation reuses the monotone table for ordinary probabilities.doubledensity(double x, boolean log) entropy()Numerically evaluates differential entropy, -E[log f(X)].expectation(UnivariateFunction function) Numerically evaluates E[g(X)] with immutable integration diagnostics.fromLogKernel(UnivariateFunction logKernel, double lower, double upper) Constructs from a log-kernel, automatically selecting a finite reference value from deterministic interior probes.fromLogKernel(UnivariateFunction logKernel, double lower, double upper, double referenceLogValue, IntegrationOptions options) Constructs from a log-kernel with a user-supplied finite scaling reference.fromLogKernel(UnivariateFunction logKernel, double lower, double upper, IntegrationOptions options) Constructs from a log-kernel with explicit integration options.Returns the lazily built reusable monotone CDF table.Returns immutable normalization diagnostics without retaining the kernel.Returns the immutable integration settings used by this distribution.doubleReturns the logarithm of the cached normalization constant.intNumber of independently scaled regions used for an automatic log-kernel.doubleReturns the lower support bound.doubleReturns the cached normalization constant.Returns a defensive copy of the normalization diagnostics.doubleReturns the upper support bound.booleanbooleandoublemode()Returns the best mode observed by transformed-grid search and refinement.probabilityInterval(double probability) Returns the equal-tail interval containing the requested probability.doublequantile(double p, boolean lowerTail, boolean logP) doublerandom()doublerandom(RejectionEnvelope envelope, int maxAttempts) Draws one value using an explicit rejection envelope.rawMoment(double order) Numerically evaluates E[X^order].rebuildCdfTable(CdfTableOptions settings) Rebuilds and installs the reusable CDF table with explicit settings.Methods inherited from class jdistlib.generic.GenericDistribution
copyBackward, cumulative, cumulative, cumulative, cumulative_hazard, cumulative_hazard, density, density, densityInto, getRandomEngine, hazard, hazard, inverse_survival, inverse_survival, quantile, quantile, quantile, quantileInto, random, random, randomInto, setRandomEngine, survival, survival, survival
-
Constructor Details
-
NumericalContinuousDistribution
Constructs a distribution using distribution-oriented integration defaults: relative tolerance1e-10, 300 subdivisions, a finite evaluation budget, and automatic finite-interval tanh-sinh fallback.- Parameters:
kernel- nonnegative unnormalized densitylower- lower support bound, possibly negative infinityupper- upper support bound, possibly positive infinity- Throws:
IllegalArgumentException- if the support or normalization is invalid
-
NumericalContinuousDistribution
public NumericalContinuousDistribution(UnivariateFunction kernel, double lower, double upper, double epsabs, double epsrel, int subdivisions) Constructs a distribution with explicit QUADPACK tolerances.- Parameters:
kernel- nonnegative unnormalized densitylower- lower support bound, possibly negative infinityupper- upper support bound, possibly positive infinityepsabs- absolute integration toleranceepsrel- relative integration tolerancesubdivisions- maximum number of integration subdivisions- Throws:
IllegalArgumentException- if the inputs or normalization are invalid
-
NumericalContinuousDistribution
public NumericalContinuousDistribution(UnivariateFunction kernel, double lower, double upper, IntegrationOptions options) Constructs a distribution with hardened integration options.
-
-
Method Details
-
builder
Returns a fluent builder for a custom continuous distribution. -
fromLogKernel
public static NumericalContinuousDistribution fromLogKernel(UnivariateFunction logKernel, double lower, double upper) Constructs from a log-kernel, automatically selecting a finite reference value from deterministic interior probes. -
fromLogKernel
public static NumericalContinuousDistribution fromLogKernel(UnivariateFunction logKernel, double lower, double upper, IntegrationOptions options) Constructs from a log-kernel with explicit integration options. -
fromLogKernel
public static NumericalContinuousDistribution fromLogKernel(UnivariateFunction logKernel, double lower, double upper, double referenceLogValue, IntegrationOptions options) Constructs from a log-kernel with a user-supplied finite scaling reference. -
analyze
public static NumericalDistributionBuildResult analyze(UnivariateFunction kernel, double lower, double upper) Analyzes a kernel and attempts construction using the analyzer's integration settings plus any suggested breakpoints. The retained report remains advisory rather than a proof of validity. -
analyze
public static NumericalDistributionBuildResult analyze(UnivariateFunction kernel, double lower, double upper, ConstructionPolicy policy) Analyzes using defaults and an explicit construction policy. -
analyze
public static NumericalDistributionBuildResult analyze(UnivariateFunction kernel, double lower, double upper, FunctionAnalysisOptions analysisOptions) Analyzes and attempts construction with explicit analysis settings. -
analyzeLogKernel
public static NumericalDistributionBuildResult analyzeLogKernel(UnivariateFunction logKernel, double lower, double upper) Analyzes a log-kernel in log space and attempts construction using the default settings. Negative infinity is accepted as zero mass. -
analyzeLogKernel
public static NumericalDistributionBuildResult analyzeLogKernel(UnivariateFunction logKernel, double lower, double upper, ConstructionPolicy policy) Analyzes a log-kernel with defaults and an explicit policy. -
analyzeLogKernel
public static NumericalDistributionBuildResult analyzeLogKernel(UnivariateFunction logKernel, double lower, double upper, FunctionAnalysisOptions analysisOptions) Analyzes and attempts log-kernel construction with explicit settings. -
analyzeDistribution
Runs CDF, quantile, tail, normalization, and moment diagnostics. -
analyzeDistribution
Runs diagnostics with user-selected absolute-moment orders and tail split. -
getLowerBound
public double getLowerBound()Returns the lower support bound.- Specified by:
getLowerBoundin interfaceSupportedDistribution
-
getUpperBound
public double getUpperBound()Returns the upper support bound.- Specified by:
getUpperBoundin interfaceSupportedDistribution
-
getIntegrationOptions
Returns the immutable integration settings used by this distribution. -
getLogScalingRegionCount
public int getLogScalingRegionCount()Number of independently scaled regions used for an automatic log-kernel. -
getNormalizationConstant
public double getNormalizationConstant()Returns the cached normalization constant. -
getLogNormalizationConstant
public double getLogNormalizationConstant()Returns the logarithm of the cached normalization constant. -
getNormalizationResult
Returns a defensive copy of the normalization diagnostics. For a log-kernel, its result and error describe the scaled integral actually sent to the quadrature routine;getLogNormalizationConstant()describes the original formula's normalizer. -
getImmutableNormalizationResult
Returns immutable normalization diagnostics without retaining the kernel. -
getCdfTable
Returns the lazily built reusable monotone CDF table. -
rebuildCdfTable
Rebuilds and installs the reusable CDF table with explicit settings. -
clearCdfTable
public void clearCdfTable()Drops the table so the next CDF or central quantile call rebuilds it. -
density
public double density(double x, boolean log) - Specified by:
densityin classGenericDistribution
-
cumulative
public double cumulative(double x, boolean lowerTail, boolean logP) - Specified by:
cumulativein classGenericDistribution
-
cumulativeInto
public void cumulativeInto(double[] input, int inputOffset, double[] output, int outputOffset, int length, boolean lowerTail, boolean logP) Batch CDF evaluation reuses the monotone table for ordinary probabilities.- Overrides:
cumulativeIntoin classGenericDistribution
-
cumulativeCached
public double cumulativeCached(double x, boolean lowerTail, boolean logP) Evaluates through the reusable CDF table. Extreme or logged tails fall back to direct integration to avoid subtractive loss. -
quantile
public double quantile(double p, boolean lowerTail, boolean logP) - Specified by:
quantilein classGenericDistribution
-
random
public double random()- Specified by:
randomin classGenericDistribution
-
configureRejectionSampling
Configures rejection-envelope sampling for subsequentrandom()calls. The caller is responsible for the envelope's global majorization promise; sampled violations are detected and rejected with an exception. -
configureUniformRejectionSampling
public void configureUniformRejectionSampling(double logDensityUpperBound, int maxAttempts) Configures a uniform rejection envelope over this finite support. -
clearRejectionSampling
public void clearRejectionSampling()Restores inverse-CDF sampling. -
isRejectionSamplingConfigured
public boolean isRejectionSamplingConfigured() -
configureAdaptiveRejectionSampling
public void configureAdaptiveRejectionSampling(UnivariateFunction logDerivative, int maximumKnots, int maximumAttempts, double... initialPoints) Configures adaptive rejection under a caller-certified log-concavity promise. -
clearAdaptiveRejectionSampling
public void clearAdaptiveRejectionSampling() -
isAdaptiveRejectionSamplingConfigured
public boolean isAdaptiveRejectionSamplingConfigured() -
getSamplingStrategy
-
getSamplingStrategyExplanation
-
expectation
Numerically evaluates E[g(X)] with immutable integration diagnostics. -
rawMoment
Numerically evaluates E[X^order]. Fractional orders require nonnegative support. -
centralMoment
Numerically evaluates E[(X-E[X])^order]. Orders must be integers. -
entropy
Numerically evaluates differential entropy, -E[log f(X)]. -
mode
public double mode()Returns the best mode observed by transformed-grid search and refinement. -
probabilityInterval
Returns the equal-tail interval containing the requested probability. -
random
Draws one value using an explicit rejection envelope.
-