NearestScatterSurface Class

Represents an N-dimensional scattered data interpolant using nearest-neighbor interpolation.

Definition

Namespace: Numerics.NET.Curves.Surfaces
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 10.1.0
C#
public sealed class NearestScatterSurface : Surface
Inheritance
Object  →  Surface  →  NearestScatterSurface

Remarks

The NearestScatterSurface class implements the simplest form of scattered data interpolation: for any query point x, it returns the function value fᵢ associated with the nearest sample point pᵢ.

Interpolation method: Given N sample points pᵢ ∈ ℝᴰ with values fᵢ, the interpolant is defined as:

s(x) = f_nearest, where nearest = argminᵢ ||x - pᵢ||

This produces a piecewise constant function with Voronoi-like regions around each data point. The interpolant is discontinuous at the boundaries between regions.

Properties:

  • Works in any number of dimensions.
  • Defined everywhere in ℝⁿ (no extrapolation concerns).
  • Produces discontinuous, piecewise constant output.
  • Gradient is zero almost everywhere (except at measure-zero boundaries).

Performance: The current implementation uses brute-force linear search with O(N) evaluation cost per query, where N is the number of sample points. In case of ties (multiple points at the same minimum distance), the point with the smallest index is selected.

Note: Future versions may implement spatial indexing (e.g., k-d tree) to improve query performance to O(log N).

Use cases: Nearest-neighbor interpolation is useful for:

  • Categorical or discrete data where smooth interpolation is inappropriate.
  • Fast lookups when continuity is not required.
  • Initial prototyping or as a fallback method.
  • Debugging or visualization of sample point coverage.

The NearestScatterSurface class inherits from Surface and works in arbitrary dimensions. Create instances using the ScatteredNearestInterpolator(Matrix<Double>, Vector<Double>) factory methods.

Properties

Dimension Gets the number of dimensions of the input space.
(Inherited from Surface)

Methods

EqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
Evaluate(Double[]) Evaluates the surface at the specified point.
(Inherited from Surface)
Evaluate(IReadOnlyList<Double>) Evaluates the surface at the specified point.
(Inherited from Surface)
Evaluate(ReadOnlySpan<Double>) Evaluates the surface at the specified point.
(Overrides Surface.Evaluate(ReadOnlySpan<Double>))
Evaluate(IReadOnlyList<Vector<Double>>, Span<Double>) Evaluates the surface at multiple points specified by a list of vectors.
(Inherited from Surface)
Evaluate(ReadOnlySpan<Vector<Double>>, Span<Double>) Evaluates the surface at multiple points specified by a read-only span of vectors.
(Inherited from Surface)
Evaluate(Int32, ReadOnlySpan2D<Double>, Span<Double>) Evaluates the surface at multiple points stored in column-major layout.
(Inherited from Surface)
GetHashCodeServes as the default hash function.
(Inherited from Object)
GetTypeGets the Type of the current instance.
(Inherited from Object)
Gradient(Vector<Double>) Computes the gradient of the surface at the specified point.
(Inherited from Surface)
Gradient(Double, Double) Computes the gradient of a 2D surface at the specified point.
(Inherited from Surface)
Gradient(ReadOnlySpan<Double>, Span<Double>) Computes the gradient of the surface at the specified point.
(Overrides Surface.Gradient(ReadOnlySpan<Double>, Span<Double>))
Gradient(Vector<Double>, Vector<Double>) Computes the gradient of the surface at the specified point.
(Inherited from Surface)
Gradients(Matrix<Double>) Computes the gradients of the surface at multiple points.
(Inherited from Surface)
Gradients(Matrix<Double>, Matrix<Double>) Computes the gradients of the surface at multiple points.
(Inherited from Surface)
Hessian Computes the Hessian matrix of the surface at the specified point.
(Inherited from Surface)
ToStringReturns a string that represents the current object.
(Inherited from Object)

See Also