Skip to content

Weight Functions

Kernel functions for distance weighting.

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

Weight Functions


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)


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

w(u)=(1−∣u∣3)3w(u) = (1 - |u|^3)^3

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.1663

Theoretically optimal for kernel density estimation.

w(u)=34(1−u2)w(u) = \frac{3}{4}(1 - u^2)

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.1741

Infinitely smooth. No boundary effects.

w(u)=exp⁡(−u2/2)w(u) = \exp(-u^2/2)

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.0808

Good balance of efficiency and smoothness.

w(u)=(1−u2)2w(u) = (1 - u^2)^2

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.1678

Smooth and computationally efficient.

w(u)=cos⁡(πu/2)w(u) = \cos(\pi u / 2)

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.1741

Simple linear taper.

w(u)=1−∣u∣w(u) = 1 - |u|

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.1746

Equal weights within window. Fastest but least smooth.

w(u)=1w(u) = 1

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.1640

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