Commit 6a880f31 authored by Sören Henning's avatar Sören Henning

hopefully fixed issue with infinity weights on exponential weighted

forecaster
parent aa2f5379
......@@ -32,8 +32,9 @@ public class WeightedForecaster implements Forecaster {
// more recent entry means more weight
int position = 1; // Position > 0, because logarithmic forecast method
int size = timeSeries.size();
for (TimeSeriesPoint point : timeSeries) {
final double weight = getWeight(position);
final double weight = getWeight(position, size);
totalWeights += weight;
weightedSum += point.getValue() * weight;
position++;
......@@ -42,15 +43,14 @@ public class WeightedForecaster implements Forecaster {
return weightedSum / totalWeights;
}
private double getWeight(final int position) {
private double getWeight(final int position, final int size) {
switch (this.weightMethod) {
case LOGARITHMIC:
return Math.log(position);
case LINEAR:
return position;
case EXPONENTIAL:
// TODO use position - numberOfElements to avoid Infinity
return Math.exp(position);
return Math.exp(position - size);
default:
return position;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment