Weight Functions
Kernel functions for distance weighting.
Overview
Section titled “Overview”Weight functions (kernels) determine how neighboring points contribute to each local fit. Points closer to the target receive higher weights.
Available Kernels
Section titled “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)
Section titled “Tricube (Default)”Cleveland’s original choice. Best all-around performance.
Use when: Default choice for most applications.
const { Loess } = require('fastloess-wasm');
const n = 100;const x = Float64Array.from({ length: n }, (_, i) => i * 2 * Math.PI / (n - 1));const y = Float64Array.from(x, (xi, i) => Math.sin(xi) + (((i * 7 + 3) % 17) / 17 - 0.5) * 0.6);
const model = new Loess({ weight_function: "tricube" });const result = model.fit(x, y);console.log("y[0]:", result.y[0].toFixed(4));y[0]: 0.1663Epanechnikov
Section titled “Epanechnikov”Theoretically optimal for kernel density estimation.
Use when: Optimal MSE properties desired.
const { Loess } = require('fastloess-wasm');
const n = 100;const x = Float64Array.from({ length: n }, (_, i) => i * 2 * Math.PI / (n - 1));const y = Float64Array.from(x, (xi, i) => Math.sin(xi) + (((i * 7 + 3) % 17) / 17 - 0.5) * 0.6);
const model = new Loess({ weight_function: "epanechnikov" });const result = model.fit(x, y);console.log("y[0]:", result.y[0].toFixed(4));y[0]: 0.1741Gaussian
Section titled “Gaussian”Infinitely smooth. No boundary effects.
Use when: Maximum smoothness needed, computational cost acceptable.
const { Loess } = require('fastloess-wasm');
const n = 100;const x = Float64Array.from({ length: n }, (_, i) => i * 2 * Math.PI / (n - 1));const y = Float64Array.from(x, (xi, i) => Math.sin(xi) + (((i * 7 + 3) % 17) / 17 - 0.5) * 0.6);
const model = new Loess({ weight_function: "gaussian" });const result = model.fit(x, y);console.log("y[0]:", result.y[0].toFixed(4));y[0]: 0.0808Biweight
Section titled “Biweight”Good balance of efficiency and smoothness.
Use when: Alternative to Tricube with slightly different properties.
const { Loess } = require('fastloess-wasm');
const n = 100;const x = Float64Array.from({ length: n }, (_, i) => i * 2 * Math.PI / (n - 1));const y = Float64Array.from(x, (xi, i) => Math.sin(xi) + (((i * 7 + 3) % 17) / 17 - 0.5) * 0.6);
const model = new Loess({ weight_function: "biweight" });const result = model.fit(x, y);console.log("y[0]:", result.y[0].toFixed(4));y[0]: 0.1678Cosine
Section titled “Cosine”Smooth and computationally efficient.
Use when: Want smooth kernel with simple form.
const { Loess } = require('fastloess-wasm');
const n = 100;const x = Float64Array.from({ length: n }, (_, i) => i * 2 * Math.PI / (n - 1));const y = Float64Array.from(x, (xi, i) => Math.sin(xi) + (((i * 7 + 3) % 17) / 17 - 0.5) * 0.6);
const model = new Loess({ weight_function: "cosine" });const result = model.fit(x, y);console.log("y[0]:", result.y[0].toFixed(4));y[0]: 0.1741Triangle
Section titled “Triangle”Simple linear taper.
Use when: Simple, interpretable weights.
const { Loess } = require('fastloess-wasm');
const n = 100;const x = Float64Array.from({ length: n }, (_, i) => i * 2 * Math.PI / (n - 1));const y = Float64Array.from(x, (xi, i) => Math.sin(xi) + (((i * 7 + 3) % 17) / 17 - 0.5) * 0.6);
const model = new Loess({ weight_function: "triangle" });const result = model.fit(x, y);console.log("y[0]:", result.y[0].toFixed(4));y[0]: 0.1746Uniform
Section titled “Uniform”Equal weights within window. Fastest but least smooth.
Use when: Speed is critical, smoothness less important.
const { Loess } = require('fastloess-wasm');
const n = 100;const x = Float64Array.from({ length: n }, (_, i) => i * 2 * Math.PI / (n - 1));const y = Float64Array.from(x, (xi, i) => Math.sin(xi) + (((i * 7 + 3) % 17) / 17 - 0.5) * 0.6);
const model = new Loess({ weight_function: "uniform" });const result = model.fit(x, y);console.log("y[0]:", result.y[0].toFixed(4));y[0]: 0.1640Choosing a Kernel
Section titled “Choosing 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 |