#2 -- use class for model time series

This commit is contained in:
Anton Romanov 2020-09-12 16:13:31 +04:00
parent cf46bb0bd6
commit cfb0782825
4 changed files with 24 additions and 14 deletions

View File

@ -16,4 +16,12 @@ public class ModelTimeSeries {
public TimeSeries getModelTimeSeries() {
return modelTimeSeries;
}
public void addValue(TimeSeriesValue timeSeriesValue) {
modelTimeSeries.addValue(timeSeriesValue);
}
public void addValue(TimeSeriesValue basedOnValue, double value) {
modelTimeSeries.getValues().add(new TimeSeriesValue(basedOnValue.getDate().plusDays(1), value));
}
}

View File

@ -25,6 +25,6 @@ public class TimeSeriesService {
NoTrendNoSeason nn = new NoTrendNoSeason(timeSeries, countForecast);
nn.setAlpa(0.1);
nn.createModel();
return nn.getForecastTimeSeries();
return nn.getForecast();
}
}

View File

@ -1,6 +1,7 @@
package ru.ulstu.tsMethods;
import ru.ulstu.models.Forecast;
import ru.ulstu.models.ModelTimeSeries;
import ru.ulstu.models.TimeSeries;
import java.util.HashMap;
@ -8,26 +9,26 @@ import java.util.Map;
public abstract class TimeSeriesMethod {
protected TimeSeries originalTimeSeries;
protected TimeSeries modelTimeSeries;
protected Forecast forecastTimeSeries;
protected ModelTimeSeries model;
protected Forecast forecast;
protected int countForecast;
protected Map<Param, Double> parameters = new HashMap<>();
protected void init() {
modelTimeSeries = new TimeSeries("Model time series of '" + originalTimeSeries.getName() + "'");
forecastTimeSeries = new Forecast(originalTimeSeries);
model = new ModelTimeSeries(originalTimeSeries);
forecast = new Forecast(originalTimeSeries);
}
public TimeSeries getOriginalTimeSeries() {
return originalTimeSeries;
}
public TimeSeries getModelTimeSeries() {
return modelTimeSeries;
public ModelTimeSeries getModel() {
return model;
}
public Forecast getForecastTimeSeries() {
return forecastTimeSeries;
public Forecast getForecast() {
return forecast;
}
public abstract void createModel();

View File

@ -16,8 +16,8 @@ public class NoTrendNoSeason extends TimeSeriesMethod {
@Override
protected void init() {
super.init();
modelTimeSeries.addValue(originalTimeSeries.getValues().get(0));
forecastTimeSeries.addValue(originalTimeSeries.getValues().get(0));
model.addValue(originalTimeSeries.getValues().get(0));
forecast.addValue(originalTimeSeries.getValues().get(0));
parameters.put(Param.ALPHA, 1.0);
}
@ -34,12 +34,13 @@ public class NoTrendNoSeason extends TimeSeriesMethod {
for (int t = 0; t < originalTimeSeries.getValues().size() - 1 + countForecast; t++) {
// пока не дошли до конца ряда - сглаживаем, иначе строим прогноз
if (t < originalTimeSeries.getValues().size()) {
e = originalTimeSeries.getValues().get(t).getValue() - forecastTimeSeries.getForecast().getValues().get(t).getValue();
e = originalTimeSeries.getValues().get(t).getValue() - forecast.getForecast().getValues().get(t).getValue();
} else {
e = 0;
}
modelTimeSeries.addValue(modelTimeSeries.getLastValue(), modelTimeSeries.getValues().get(t).getValue() + parameters.get(Param.ALPHA) * e); // уровень
forecastTimeSeries.addValue(modelTimeSeries.getLastValue()); // прогноз
model.addValue(model.getModelTimeSeries().getLastValue(),
model.getModelTimeSeries().getValues().get(t).getValue() + parameters.get(Param.ALPHA) * e); // уровень
forecast.addValue(model.getModelTimeSeries().getLastValue()); // прогноз
}
}
}