#2 -- use class for model time series
This commit is contained in:
parent
cf46bb0bd6
commit
cfb0782825
@ -16,4 +16,12 @@ public class ModelTimeSeries {
|
|||||||
public TimeSeries getModelTimeSeries() {
|
public TimeSeries getModelTimeSeries() {
|
||||||
return modelTimeSeries;
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,6 @@ public class TimeSeriesService {
|
|||||||
NoTrendNoSeason nn = new NoTrendNoSeason(timeSeries, countForecast);
|
NoTrendNoSeason nn = new NoTrendNoSeason(timeSeries, countForecast);
|
||||||
nn.setAlpa(0.1);
|
nn.setAlpa(0.1);
|
||||||
nn.createModel();
|
nn.createModel();
|
||||||
return nn.getForecastTimeSeries();
|
return nn.getForecast();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package ru.ulstu.tsMethods;
|
package ru.ulstu.tsMethods;
|
||||||
|
|
||||||
import ru.ulstu.models.Forecast;
|
import ru.ulstu.models.Forecast;
|
||||||
|
import ru.ulstu.models.ModelTimeSeries;
|
||||||
import ru.ulstu.models.TimeSeries;
|
import ru.ulstu.models.TimeSeries;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -8,26 +9,26 @@ import java.util.Map;
|
|||||||
|
|
||||||
public abstract class TimeSeriesMethod {
|
public abstract class TimeSeriesMethod {
|
||||||
protected TimeSeries originalTimeSeries;
|
protected TimeSeries originalTimeSeries;
|
||||||
protected TimeSeries modelTimeSeries;
|
protected ModelTimeSeries model;
|
||||||
protected Forecast forecastTimeSeries;
|
protected Forecast forecast;
|
||||||
protected int countForecast;
|
protected int countForecast;
|
||||||
protected Map<Param, Double> parameters = new HashMap<>();
|
protected Map<Param, Double> parameters = new HashMap<>();
|
||||||
|
|
||||||
protected void init() {
|
protected void init() {
|
||||||
modelTimeSeries = new TimeSeries("Model time series of '" + originalTimeSeries.getName() + "'");
|
model = new ModelTimeSeries(originalTimeSeries);
|
||||||
forecastTimeSeries = new Forecast(originalTimeSeries);
|
forecast = new Forecast(originalTimeSeries);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TimeSeries getOriginalTimeSeries() {
|
public TimeSeries getOriginalTimeSeries() {
|
||||||
return originalTimeSeries;
|
return originalTimeSeries;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TimeSeries getModelTimeSeries() {
|
public ModelTimeSeries getModel() {
|
||||||
return modelTimeSeries;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Forecast getForecastTimeSeries() {
|
public Forecast getForecast() {
|
||||||
return forecastTimeSeries;
|
return forecast;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void createModel();
|
public abstract void createModel();
|
||||||
|
@ -16,8 +16,8 @@ public class NoTrendNoSeason extends TimeSeriesMethod {
|
|||||||
@Override
|
@Override
|
||||||
protected void init() {
|
protected void init() {
|
||||||
super.init();
|
super.init();
|
||||||
modelTimeSeries.addValue(originalTimeSeries.getValues().get(0));
|
model.addValue(originalTimeSeries.getValues().get(0));
|
||||||
forecastTimeSeries.addValue(originalTimeSeries.getValues().get(0));
|
forecast.addValue(originalTimeSeries.getValues().get(0));
|
||||||
parameters.put(Param.ALPHA, 1.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++) {
|
for (int t = 0; t < originalTimeSeries.getValues().size() - 1 + countForecast; t++) {
|
||||||
// пока не дошли до конца ряда - сглаживаем, иначе строим прогноз
|
// пока не дошли до конца ряда - сглаживаем, иначе строим прогноз
|
||||||
if (t < originalTimeSeries.getValues().size()) {
|
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 {
|
} else {
|
||||||
e = 0;
|
e = 0;
|
||||||
}
|
}
|
||||||
modelTimeSeries.addValue(modelTimeSeries.getLastValue(), modelTimeSeries.getValues().get(t).getValue() + parameters.get(Param.ALPHA) * e); // уровень
|
model.addValue(model.getModelTimeSeries().getLastValue(),
|
||||||
forecastTimeSeries.addValue(modelTimeSeries.getLastValue()); // прогноз
|
model.getModelTimeSeries().getValues().get(t).getValue() + parameters.get(Param.ALPHA) * e); // уровень
|
||||||
|
forecast.addValue(model.getModelTimeSeries().getLastValue()); // прогноз
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user