Skip to content

fix: holt-winters train.go runs off end of series and panics if start > 0 #73

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions forecast/algs/hw/train.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ func (hw *HoltWinters) trainSeries(ctx context.Context, start, end int) error {
)

y := hw.sf.Values[start : end+1]
y_start := 0
y_end := len(y) - 1

seasonals := initialSeasonalComponents(y, period, hw.cfg.SeasonalMethod)

Expand All @@ -39,14 +41,14 @@ func (hw *HoltWinters) trainSeries(ctx context.Context, start, end int) error {
var mse float64 // mean squared error

// Training smoothing Level
for i := start; i < end+1; i++ {
for i := y_start; i < y_end+1; i++ {
if err := ctx.Err(); err != nil {
return err
}

xt := y[i]

if i == start { // Set initial smooth
if i == y_start { // Set initial smooth
st = xt
hw.tstate.initialSmooth = xt
} else {
Expand Down