Fast Algorithms for Segmented Regression

Jayadev Acharya, Ilias Diakonikolas, Jerry Li, Ludwig Schmidt

Overview

This paper introduces new, nearly linear-time algorithms for segmented regression, a task traditionally dominated by slow, quadratic-time dynamic programming. By employing an iterative greedy merging strategy, the authors achieve speedups of up to 1,000x on large datasets while maintaining a mean-squared error within a small constant factor of the theoretical optimum.

The Challenge of Segmented Regression

Segmented regression (also known as piecewise linear regression) is the task of fitting a function to data where the underlying relationship changes at unknown "breakpoints." Imagine a stock price that trends upward for a month, stays flat for two weeks, and then crashes—a single straight line cannot model this, but a series of connected or disconnected line segments can.

Dow Jones data and its piecewise linear approximation.

The "gold standard" for solving this problem is Dynamic Programming (DP). While DP is statistically efficient and finds the best possible fit, it suffers from a major computational flaw: its running time scales quadratically ($O(n^2)$) with the number of data points $n$. In the era of "Big Data," where $n$ might be in the millions, an $O(n^2)$ algorithm is effectively unusable.

The authors tackle this computational bottleneck by asking: Can we create an algorithm that is nearly as accurate as DP but runs in nearly linear time ($O(n \log n)$)?

A Bottom-Up Merging Strategy

To bypass the quadratic time complexity of DP, the authors propose two primary algorithms based on a "bottom-up" merging strategy:

  1. GREEDYMERGE: The algorithm starts by treating every single data point as its own tiny segment. It then iteratively merges neighboring segments. To decide which segments to merge, it calculates a "merging error" based on a least-squares fit combined with a regularizer that accounts for noise variance ($s^2$). It keeps segments with high errors (indicating potential "jumps" or complex areas) and merges those with low errors.

  2. BUCKETGREEDYMERGE: This is a more robust version that does not require knowing the noise variance in advance. It groups candidate intervals into "buckets" based on their lengths (powers of 2) and ensures that the best candidates from each length scale are preserved.

Because the greedy approach might leave behind slightly more segments than the target $k$, the authors include a post-processing step to trim the output down to $2k+1$ segments without sacrificing statistical guarantees.

Key Results: The Computational-Statistical Tradeoff

The core philosophy of this work is that as data grows, we should favor faster algorithms. Even if an algorithm is "less efficient" per sample, the ability to process 100x more data in the same amount of time often leads to a better final model.

  • Massive Speedups: On a dataset of $n=10,000$ points, the new algorithms were roughly 1,000x faster than the traditional DP approach.
  • Competitive Accuracy: While the DP approach technically has a lower Mean Squared Error (MSE), the greedy algorithms were only off by a factor of 2x to 4x.
  • Better Scaling: To achieve the same MSE as the DP approach, the greedy algorithm needs more samples. However, because it is so much faster, it can process those extra samples and still finish 100x faster than DP would on the smaller sample set.
Speed-up of the proposed algorithms compared to Dynamic Programming as the number of samples increases.

When tested on real-world Dow Jones stock market data, the algorithm successfully identified the same major trends as the DP approach but in a fraction of a second (0.013s vs 3.2s).

Limitations and Future Work

While highly effective, the approach has a few limitations. The basic GREEDYMERGE requires an estimate of the noise variance. While BUCKETGREEDYMERGE addresses this, it adds implementation complexity. Additionally, the algorithms assume the number of segments $k$ is known. In many real-world scenarios, $k$ must be estimated via cross-validation, which adds computational overhead. Finally, the post-processing step's complexity scales with $k^3$, which could become a bottleneck if $k$ is exceptionally large relative to $n$, though for most applications $k \ll n$.

Summary updated

BibTeX
@inproceedings{acharya2016fast,
  author = {Jayadev Acharya and Ilias Diakonikolas and Jerry Li and Ludwig Schmidt},
  title = {{Fast Algorithms for Segmented Regression}},
  booktitle = {International Conference on Machine Learning},
  year = {2016},
  url = {https://openreview.net/forum?id=HJ-O8iZ_WB},
}
Figure