InverseDistanceWeightingInterpolator

Aliases:

  • petres.interpolators.IDWInterpolator


class petres.interpolators.InverseDistanceWeightingInterpolator[source]

Bases: BaseInterpolator

Inverse Distance Weighting (IDW) interpolator.

Parameters:
  • power (float, default 2.0) – Weight exponent p. Larger values make the interpolation more local. Common values: 1.0–3.0.

  • eps (float, default 1e-12) – Small value to avoid division-by-zero and stabilize near-zero distances.

  • neighbors (int or None, optional) – If provided, use only the k nearest samples per query; otherwise use all samples.

  • mode ({'average', 'sum'}, default 'average') – Weighting mode. 'average' computes normalized weighted averages; 'sum' returns the weighted sum (rarely used).

  • dtype (numpy.dtype or str, default numpy.float64) – Storage dtype for cached arrays and outputs.

Initialize the interpolator with validated IDW configuration.

Raises:

ValueError – If power <= 0, eps <= 0, neighbors is not positive when provided, or mode is not one of 'average' or 'sum'.

Notes

When an exact coordinate match is found during prediction, the interpolator returns the matching sample value directly (or the mean of duplicate exact matches), independent of mode.

Examples

>>> interp = InverseDistanceWeightingInterpolator(power=2.0, neighbors=8)
>>> interp.fit([[0.0, 0.0], [1.0, 1.0]], [10.0, 20.0])
>>> interp.predict([[0.5, 0.5]]).shape
(1,)
__init__(power=2.0, eps=1e-12, neighbors=None, mode='average', dtype=<class 'numpy.float64'>)[source]

Initialize the interpolator with validated IDW configuration.

Raises:

ValueError – If power <= 0, eps <= 0, neighbors is not positive when provided, or mode is not one of 'average' or 'sum'.

Notes

When an exact coordinate match is found during prediction, the interpolator returns the matching sample value directly (or the mean of duplicate exact matches), independent of mode.

Examples

>>> interp = InverseDistanceWeightingInterpolator(power=2.0, neighbors=8)
>>> interp.fit([[0.0, 0.0], [1.0, 1.0]], [10.0, 20.0])
>>> interp.predict([[0.5, 0.5]]).shape
(1,)