Skip to content

Commit

Permalink
fit: fix polynomial regression for d >= 4
Browse files Browse the repository at this point in the history
This stumbled over the classic capturing-the-loop-variable bug so all
terms from degree 3 and on used the highest degree.
  • Loading branch information
aclements committed Feb 10, 2017
1 parent 03302a9 commit 033754a
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions fit/lsquares.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ func PolynomialRegression(xs, ys, weights []float64, degree int) PolynomialRegre
}
}
for d := 3; d < len(terms); d++ {
d := d
terms[d] = func(xs, termOut []float64) {
for i, x := range xs {
termOut[i] = math.Pow(x, float64(d+1))
Expand Down

0 comments on commit 033754a

Please sign in to comment.