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.
Available Kernels
| Kernel | Efficiency | Smoothness | Support |
|---|---|---|---|
| Tricube | 0.998 | Very smooth | Compact |
| Epanechnikov | 1.000 | Smooth | Compact |
| Gaussian | 0.961 | Infinite | Unbounded |
| Biweight | 0.995 | Very smooth | Compact |
| Cosine | 0.999 | Smooth | Compact |
| Triangle | 0.989 | Moderate | Compact |
| Uniform | 0.943 | None | Compact |
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.4426033958974517Epanechnikov
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.46914045663608706Gaussian
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.4470047110244503Biweight
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.43934173343506366Cosine
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.46347502798661183Triangle
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.4489611377379488Uniform
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.5211823940259267Choosing a Kernel
Choose the first row below whose condition applies:
| Condition | Kernel |
|---|---|
| Need maximum smoothness | Gaussian |
| Default is acceptable | Tricube |
| Need optimal asymptotic MSE | Epanechnikov |
| Speed is critical | Uniform |
| None of the above | Biweight |