Skip to content

Commit

Permalink
Merge #95392
Browse files Browse the repository at this point in the history
95392: sql/stats: add TODOs to simple linear regression functions r=rharding6373 a=michae2

Leave some TODOs about switching the simple linear regression functions used by stats forecasting to a more efficient one-pass algorithm.

Release note: None

Co-authored-by: Michael Erickson <[email protected]>
  • Loading branch information
craig[bot] and michae2 committed Jan 17, 2023
2 parents 6fd5b04 + f7e4d38 commit 15c4bff
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/sql/stats/simple_linear_regression.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ func float64SimpleLinearRegression(x, y []float64, xₙ float64) (yₙ, r2 float
// See https://en.wikipedia.org/wiki/Simple_linear_regression and
// https://en.wikipedia.org/wiki/Coefficient_of_determination for
// background.
//
// Note that this uses a naive two-pass algorithm. We expect there to be less
// than a dozen observations, so this is fine.
// TODO(michae2): Switch to a one-pass algorithm based on Welford-Knuth, see:
// https://www.johndcook.com/blog/running_regression/

if len(x) != len(y) {
panic(errors.AssertionFailedf("x and y had different numbers of observations"))
Expand Down Expand Up @@ -143,6 +148,11 @@ func quantileSimpleLinearRegression(
//
// See the paper, https://en.wikipedia.org/wiki/Wasserstein_metric and also
// https://en.wikipedia.org/wiki/Earth_mover%27s_distance for some background.
//
// Note that this uses a naive two-pass algorithm. We expect there to be less
// than a dozen observations, so this is fine.
// TODO(michae2): Switch to a one-pass algorithm based on Welford-Knuth, see:
// https://www.johndcook.com/blog/running_regression/

if len(x) != len(y) {
panic(errors.AssertionFailedf("x and y had different numbers of observations"))
Expand Down

0 comments on commit 15c4bff

Please sign in to comment.