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

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)

All examples below use the same 100-point noisy sine wave (x[i] = i * 2 * Math.PI / (n - 1); y[i] = Math.sin(x[i]) + 0.1, n = 100).


Tricube (Default)

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

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

Use when: Default choice for most applications.

import fastlowess.Lowess;
import fastlowess.Options;
import fastlowess.Result;

public class Example {
    public static void main(String[] args) {
        int n = 100;
        double[] x = new double[n];
        double[] y = new double[n];
        for (int i = 0; i < n; i++) {
            x[i] = i * 2 * Math.PI / (n - 1);
            y[i] = Math.sin(x[i]) + 0.1;
        }

        Options options = Options.builder().weightFunction("tricube").build();

        try (Lowess model = new Lowess(options)) {
            Result result = model.fit(x, y);
            System.out.println("First smoothed value (tricube kernel): " + result.y()[0]);
        }
    }
}
First smoothed value (tricube kernel): 0.3808839002538159

Epanechnikov

Theoretically optimal for kernel density estimation.

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

Use when: Optimal MSE properties desired.

import fastlowess.Lowess;
import fastlowess.Options;
import fastlowess.Result;

public class Example {
    public static void main(String[] args) {
        int n = 100;
        double[] x = new double[n];
        double[] y = new double[n];
        for (int i = 0; i < n; i++) {
            x[i] = i * 2 * Math.PI / (n - 1);
            y[i] = Math.sin(x[i]) + 0.1;
        }

        Options options = Options.builder().weightFunction("epanechnikov").build();

        try (Lowess model = new Lowess(options)) {
            Result result = model.fit(x, y);
            System.out.println("First smoothed value (epanechnikov kernel): " + result.y()[0]);
        }
    }
}
First smoothed value (epanechnikov kernel): 0.4069232787228461

Gaussian

Infinitely smooth. No boundary effects.

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

Use when: Maximum smoothness needed, computational cost acceptable.

import fastlowess.Lowess;
import fastlowess.Options;
import fastlowess.Result;

public class Example {
    public static void main(String[] args) {
        int n = 100;
        double[] x = new double[n];
        double[] y = new double[n];
        for (int i = 0; i < n; i++) {
            x[i] = i * 2 * Math.PI / (n - 1);
            y[i] = Math.sin(x[i]) + 0.1;
        }

        Options options = Options.builder().weightFunction("gaussian").build();

        try (Lowess model = new Lowess(options)) {
            Result result = model.fit(x, y);
            System.out.println("First smoothed value (gaussian kernel): " + result.y()[0]);
        }
    }
}
First smoothed value (gaussian kernel): 0.3540140546455968

Biweight

Good balance of efficiency and smoothness.

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

Use when: Alternative to Tricube with slightly different properties.

import fastlowess.Lowess;
import fastlowess.Options;
import fastlowess.Result;

public class Example {
    public static void main(String[] args) {
        int n = 100;
        double[] x = new double[n];
        double[] y = new double[n];
        for (int i = 0; i < n; i++) {
            x[i] = i * 2 * Math.PI / (n - 1);
            y[i] = Math.sin(x[i]) + 0.1;
        }

        Options options = Options.builder().weightFunction("biweight").build();

        try (Lowess model = new Lowess(options)) {
            Result result = model.fit(x, y);
            System.out.println("First smoothed value (biweight kernel): " + result.y()[0]);
        }
    }
}
First smoothed value (biweight kernel): 0.37439545631024396

Cosine

Smooth and computationally efficient.

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

Use when: Want smooth kernel with simple form.

import fastlowess.Lowess;
import fastlowess.Options;
import fastlowess.Result;

public class Example {
    public static void main(String[] args) {
        int n = 100;
        double[] x = new double[n];
        double[] y = new double[n];
        for (int i = 0; i < n; i++) {
            x[i] = i * 2 * Math.PI / (n - 1);
            y[i] = Math.sin(x[i]) + 0.1;
        }

        Options options = Options.builder().weightFunction("cosine").build();

        try (Lowess model = new Lowess(options)) {
            Result result = model.fit(x, y);
            System.out.println("First smoothed value (cosine kernel): " + result.y()[0]);
        }
    }
}
First smoothed value (cosine kernel): 0.40076911201975357

Triangle

Simple linear taper.

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

Use when: Simple, interpretable weights.

import fastlowess.Lowess;
import fastlowess.Options;
import fastlowess.Result;

public class Example {
    public static void main(String[] args) {
        int n = 100;
        double[] x = new double[n];
        double[] y = new double[n];
        for (int i = 0; i < n; i++) {
            x[i] = i * 2 * Math.PI / (n - 1);
            y[i] = Math.sin(x[i]) + 0.1;
        }

        Options options = Options.builder().weightFunction("triangle").build();

        try (Lowess model = new Lowess(options)) {
            Result result = model.fit(x, y);
            System.out.println("First smoothed value (triangle kernel): " + result.y()[0]);
        }
    }
}
First smoothed value (triangle kernel): 0.3810290710717598

Uniform

Equal weights within window. Fastest but least smooth.

\[w(u) = 1\]

Use when: Speed is critical, smoothness less important.

import fastlowess.Lowess;
import fastlowess.Options;
import fastlowess.Result;

public class Example {
    public static void main(String[] args) {
        int n = 100;
        double[] x = new double[n];
        double[] y = new double[n];
        for (int i = 0; i < n; i++) {
            x[i] = i * 2 * Math.PI / (n - 1);
            y[i] = Math.sin(x[i]) + 0.1;
        }

        Options options = Options.builder().weightFunction("uniform").build();

        try (Lowess model = new Lowess(options)) {
            Result result = model.fit(x, y);
            System.out.println("First smoothed value (uniform kernel): " + result.y()[0]);
        }
    }
}
First smoothed value (uniform kernel): 0.45455195196938875

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

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