KernelDensity.Fit Method

Fits a reusable kernel density estimate with optional relative observation weights.

Definition

Namespace: Numerics.NET.Statistics
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 10.9.0
C#
public static KernelDensityEstimate Fit(
	Vector<double> input,
	KernelDensityOptions? options = null,
	Vector<double>? weights = null
)

Parameters

input  Vector<Double>
A nonempty vector of finite observations, including any zero-weight entries.
options  KernelDensityOptions  (Optional)
Kernel and bandwidth settings, or null for Gaussian normal-reference selection.
weights  Vector<Double>  (Optional)
Finite nonnegative relative masses matched by position to the observations, or null for equal mass. At least one mass must be positive.

Return Value

KernelDensityEstimate
A fitted estimate owning snapshots of the observations and weights and the resolved bandwidth.

Remarks

Input vectors and labels are not modified. Zero-weight observations do not affect evaluation, grid bounds, bandwidth selection or sampling. Common weight scaling does not change the fit. Weights are relative masses, rather than replication counts.

Automatic selection uses effective sample size and weighted population spread. Weighted quartiles interpolate Weibull plotting positions as described in the KDE guide. Equal positive weights preserve the existing unweighted bandwidth convention. At least two positive-weight observations with positive spread are required; fixed bandwidth also permits a single observation or constant data.

Bandwidth adjustment is applied once. Custom kernel delegates must remain stable and safe for concurrent calls.

Exceptions

ArgumentNullExceptioninput is null.
ArgumentExceptionObservations or weights are invalid or unsuitable for automatic bandwidth selection.
ArgumentOutOfRangeExceptionThe selected or adjusted bandwidth is not finite and positive.
InvalidOperationExceptionThe kernel normalization is not finite and positive.
NotSupportedExceptionThe kernel does not support the requested bandwidth rule.

See Also