Weight Functions

Kernel functions for distance weighting.

Overview

Weight functions (kernels) determine how neighboring points contribute to each local fit. Points closer to the target receive higher weights.

Weight Functions


Available Kernels

KernelEfficiencySmoothnessSupport
Tricube0.998Very smoothCompact
Epanechnikov1.000SmoothCompact
Gaussian0.961InfiniteUnbounded
Biweight0.995Very smoothCompact
Cosine0.999SmoothCompact
Triangle0.989ModerateCompact
Uniform0.943NoneCompact

Efficiency = AMISE relative to Epanechnikov (1.0 = optimal)


Tricube (Default)

Cleveland's original choice. Best all-around performance.

\[w(u) = (1 - |u|^3)^3\]

Use when: Default choice for most applications.

using FastLOWESS
using Random, Statistics

rng = MersenneTwister(42)
x = collect(range(0, 2π, length=100))
y = sin.(x) .+ randn(rng, 100) .* 0.3

model = Lowess(; weight_function="tricube")
result = fit(model, x, y)
println("First smoothed value (tricube kernel): ", result.y[1])
First smoothed value (tricube kernel): 0.4426033958974517

Epanechnikov

Theoretically optimal for kernel density estimation.

\[w(u) = \frac{3}{4}(1 - u^2)\]

Use when: Optimal MSE properties desired.

using FastLOWESS
using Random, Statistics

rng = MersenneTwister(42)
x = collect(range(0, 2π, length=100))
y = sin.(x) .+ randn(rng, 100) .* 0.3

model = Lowess(; weight_function="epanechnikov")
result = fit(model, x, y)
println("First smoothed value (epanechnikov kernel): ", result.y[1])
First smoothed value (epanechnikov kernel): 0.46914045663608706

Gaussian

Infinitely smooth. No boundary effects.

\[w(u) = \exp(-u^2/2)\]

Use when: Maximum smoothness needed, computational cost acceptable.

using FastLOWESS
using Random, Statistics

rng = MersenneTwister(42)
x = collect(range(0, 2π, length=100))
y = sin.(x) .+ randn(rng, 100) .* 0.3

model = Lowess(; weight_function="gaussian")
result = fit(model, x, y)
println("First smoothed value (gaussian kernel): ", result.y[1])
First smoothed value (gaussian kernel): 0.4470047110244503

Biweight

Good balance of efficiency and smoothness.

\[w(u) = (1 - u^2)^2\]

Use when: Alternative to Tricube with slightly different properties.

using FastLOWESS
using Random, Statistics

rng = MersenneTwister(42)
x = collect(range(0, 2π, length=100))
y = sin.(x) .+ randn(rng, 100) .* 0.3

model = Lowess(; weight_function="biweight")
result = fit(model, x, y)
println("First smoothed value (biweight kernel): ", result.y[1])
First smoothed value (biweight kernel): 0.43934173343506366

Cosine

Smooth and computationally efficient.

\[w(u) = \cos(\pi u / 2)\]

Use when: Want smooth kernel with simple form.

using FastLOWESS
using Random, Statistics

rng = MersenneTwister(42)
x = collect(range(0, 2π, length=100))
y = sin.(x) .+ randn(rng, 100) .* 0.3

model = Lowess(; weight_function="cosine")
result = fit(model, x, y)
println("First smoothed value (cosine kernel): ", result.y[1])
First smoothed value (cosine kernel): 0.46347502798661183

Triangle

Simple linear taper.

\[w(u) = 1 - |u|\]

Use when: Simple, interpretable weights.

using FastLOWESS
using Random, Statistics

rng = MersenneTwister(42)
x = collect(range(0, 2π, length=100))
y = sin.(x) .+ randn(rng, 100) .* 0.3

model = Lowess(; weight_function="triangle")
result = fit(model, x, y)
println("First smoothed value (triangle kernel): ", result.y[1])
First smoothed value (triangle kernel): 0.4489611377379488

Uniform

Equal weights within window. Fastest but least smooth.

\[w(u) = 1\]

Use when: Speed is critical, smoothness less important.

using FastLOWESS
using Random, Statistics

rng = MersenneTwister(42)
x = collect(range(0, 2π, length=100))
y = sin.(x) .+ randn(rng, 100) .* 0.3

model = Lowess(; weight_function="uniform")
result = fit(model, x, y)
println("First smoothed value (uniform kernel): ", result.y[1])
First smoothed value (uniform kernel): 0.5211823940259267

Choosing a Kernel

Choose the first row below whose condition applies:

ConditionKernel
Need maximum smoothnessGaussian
Default is acceptableTricube
Need optimal asymptotic MSEEpanechnikov
Speed is criticalUniform
None of the aboveBiweight
Recommendation

Stick with Tricube (default) unless you have specific requirements. The differences between kernels are usually small in practice.