Remix.run Logo
Show HN: O(1) Recursive Moving Linear Regression
1 points by Pierdimi 5 hours ago | 4 comments

Constant time recursive filter for moving linear regression. Works for any window size k. Formula in the first comment.

rzzzwilson 5 hours ago | parent | next [-]

Interesting. A "zero code" implementation?

Pierdimi 3 hours ago | parent [-]

Yes. The moving linear regression reduces to a fixed‑cost O(1) recurrence, in a way analogous to a recursive moving average. The internal state requires only the two previous estimates y1_hat(n−1) and y1_hat(n−2), the current sample y(n), the previous sample y(n−1), and a circular buffer of length k+1 to access the samples leaving the window, y(n−k) and y(n−k−1). There is no need to rescan the window, both the computational cost and the additional memory remain constant as k increases.

Pierdimi an hour ago | parent [-]

[dead]

Pierdimi 5 hours ago | parent | prev [-]

[dead]