45 lines
1.8 KiB
Java
45 lines
1.8 KiB
Java
package ru.ulstu.tsMethods.exponential;
|
|
|
|
import ru.ulstu.models.TimeSeries;
|
|
import ru.ulstu.models.exceptions.ModelingException;
|
|
import ru.ulstu.tsMethods.TimeSeriesMethod;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import static ru.ulstu.tsMethods.exponential.ExponentialParamName.ALPHA;
|
|
|
|
public class NoTrendNoSeason extends TimeSeriesMethod {
|
|
private final ExponentialMethodParams exponentialMethodParams;
|
|
private final List<Double> sComponent = new ArrayList<>();
|
|
|
|
public NoTrendNoSeason(TimeSeries timeSeries, ExponentialMethodParams exponentialMethodParams) throws ModelingException {
|
|
super(timeSeries);
|
|
this.exponentialMethodParams = exponentialMethodParams;
|
|
}
|
|
|
|
@Override
|
|
protected TimeSeries getModelOfValidTimeSeries() throws ModelingException {
|
|
sComponent.clear();
|
|
sComponent.add(originalTimeSeries.getFirstValue().getValue());
|
|
TimeSeries model = new TimeSeries("Model of " + originalTimeSeries.getName());
|
|
model.addValue(originalTimeSeries.getFirstValue());
|
|
//выполняется проход модели по сглаживанию
|
|
for (int t = 1; t < originalTimeSeries.getValues().size(); t++) {
|
|
sComponent.add(sComponent.get(t - 1)
|
|
+ exponentialMethodParams.getValue(ALPHA)
|
|
* (originalTimeSeries.getNumericValue(t) - sComponent.get(t - 1)));
|
|
model.addValue(originalTimeSeries.getValues().get(t), sComponent.get(sComponent.size() - 1));
|
|
}
|
|
return model;
|
|
}
|
|
|
|
@Override
|
|
protected TimeSeries makeForecast(TimeSeries forecast) {
|
|
for (int t = 1; t < forecast.getLength(); t++) {
|
|
forecast.getValues().get(t).setValue(forecast.getValues().get(t - 1).getValue());
|
|
}
|
|
return forecast;
|
|
}
|
|
}
|