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
moving_avg
forecasts should not include current point
#11641
Conversation
double[] predictions = new double[numPredictions]; | ||
|
||
// If there are no values, we can't do anything. Return an array of NaNs. | ||
if (values.size() == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
values.isEmpty()
moving_avg
forecasts should not include current point
@@ -41,6 +42,29 @@ | |||
protected static final ParseField NAME_FIELD = new ParseField("linear"); | |||
|
|||
@Override | |||
public <T extends Number> double[] predict(Collection<T> values, int numPredictions) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The two checks (values.size == 0
and numPredictions < 1
) seem to be done in all the models, maybe we should move them to the super class and have the sub-classes implement doPredict()
which is called from the predict()
method in the super class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in fact, to make all the models work in the same way, we could make MovAvgModel
declare the following abstract method:
public abstract <T extends Number> double[] next(Collection<T> values, int numForecasts);
Then the predict
and next
methods can just be declared in MovAvgModel
and be the following:
public final <T extends Number> double[] predict(Collection<T> values, int numPredictions) {
return next(values, numPredictions);
}
public final <T extends Number> double next(Collection<T> values) {
return next(values, 1)[0];
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went with the first suggestion, rolling the checks/assertion into predict()
which then calls down to doPredict()
.
I couldn't do the second suggestion, because not all the models follow that pattern. Simple / Linear / Ewma only know how to forecast one value at a time. E.g. they always return a single value, not an array. Which also means their prediction code needs to fill the array of predictions with that last value, whereas HL/HW generate new predictions at each point.
If we want less code c/p, going back to the old solution is probably best (concrete predict()
for simple/linear/ewma and have HL/HW override it).
9280da5
to
513a673
Compare
@uboness @colings86 Sorry for delay, fixes applied As an aside, the work I've been doing on the optimizer is going to need a fair amount of change to the |
LGTM |
…apoint. - Fixes tests, and removes a few special snowflake, fragile tests. - Removes concrete implementation of predict() and moves it into each model so that the logic is clearer. Because there is some shared checks/assertions, those remain in predict() and the main prediction happens in doPredict()
513a673
to
5d94feb
Compare
Aggregations: Moving average forecasts should not include current point
predict()
, which makes things simpler / more intuitive