Edge strategies that reduce bias near the ends of the data range.

Overview#

Standard LOWESS neighbourhoods become asymmetric at the boundaries: fewer points exist on one side, pulling the local fit toward the data interior. boundaryPolicy controls how the data is padded to mitigate this effect.

Boundary Handling

PolicyPadding StrategyBest For
"extend"Repeat first / last valueMost datasets (default)
"reflect"Mirror data at boundariesPeriodic or symmetric data
"zero"Pad with zerosData known to approach zero
"noboundary"No padding (Cleveland original)Reproducing reference behaviour

Extend (Default)#

Pads beyond both endpoints by replicating the first and last observed values. Prevents the fit from curling toward zero and is a safe default for nearly all use cases.

Use when: No strong prior on boundary behaviour; general-purpose smoothing.

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().boundaryPolicy("extend").build();

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

Reflect#

Mirrors the data about both endpoints before fitting, then discards the reflected region from the output. Preserves continuity of derivatives, making it ideal for periodic or spatially symmetric signals.

Use when: Circular data (e.g., angle, day-of-year), symmetric physical quantities, or when the derivative at the boundary should be near zero.

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().boundaryPolicy("reflect").build();

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

Zero#

Pads with zeros beyond both endpoints. Appropriate when the underlying process is known to be zero outside the observation window (e.g., a pulse signal or a bounded physical quantity).

Use when: Signal decays to zero at both ends; zero is a meaningful boundary value.

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().boundaryPolicy("zero").build();

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

No Boundary#

Applies no padding. Each local fit uses only the points that are actually available, which may be fewer than the requested neighbourhood at the endpoints. This reproduces the original Cleveland (1979) algorithm exactly.

Use when: Reproducing reference results; you prefer the raw LOWESS boundary behaviour.

Note: Without padding, boundary fits can have higher variance and visible edge artefacts, particularly with small fraction values.

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().boundaryPolicy("noboundary").build();

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

Choosing a Policy#

SituationRecommended Policy
General purpose"extend" (default)
Periodic signal (angle, day-of-year)"reflect"
Signal known to be zero at boundaries"zero"
Replicating original Cleveland behaviour"noboundary"

All examples above use the same 100-point noisy sine wave (see Weight Functions for the generation code).