#2 -- add params for method

This commit is contained in:
Anton Romanov 2020-11-02 17:04:49 +04:00
parent d38c759fba
commit 44fde5c80d
6 changed files with 46 additions and 15 deletions

View File

@ -8,6 +8,8 @@ import ru.ulstu.models.Forecast;
import ru.ulstu.models.TimeSeries;
import ru.ulstu.models.TimeSeriesValue;
import ru.ulstu.models.exceptions.ModelingException;
import ru.ulstu.tsMethods.exponential.ExponentialMethodParams;
import ru.ulstu.tsMethods.exponential.ExponentialParamName;
import ru.ulstu.tsMethods.exponential.NoTrendNoSeason;
import java.time.LocalDateTime;
@ -31,7 +33,7 @@ public class TimeSeriesService {
}
public Forecast getForecast(TimeSeries timeSeries, int countPoints) throws ModelingException {
NoTrendNoSeason nn = new NoTrendNoSeason(0.8);
NoTrendNoSeason nn = new NoTrendNoSeason(ExponentialMethodParams.of(ExponentialParamName.ALPHA, 0.8));
return nn.getForecast(timeSeries, countPoints);
}

View File

@ -1,5 +0,0 @@
package ru.ulstu.tsMethods;
public enum Param {
ALPHA
}

View File

@ -24,7 +24,7 @@ public abstract class TimeSeriesMethod {
* @return модель временного ряда
* @throws TimeSeriesValidateException
*/
public Model getModel(TimeSeries timeSeries) throws TimeSeriesValidateException {
public Model getModel(TimeSeries timeSeries) throws ModelingException {
validateTimeSeries(timeSeries);
return getModelOfValidTimeSeries(timeSeries);
}
@ -36,7 +36,7 @@ public abstract class TimeSeriesMethod {
* @param timeSeries исходный временной ряд подлежащий моделированию
* @return
*/
protected abstract Model getModelOfValidTimeSeries(TimeSeries timeSeries);
protected abstract Model getModelOfValidTimeSeries(TimeSeries timeSeries) throws ModelingException;
/**
* Выполняет построение прогноза временного ряда. Даты спрогнозированных точек будут сгенерированы по модельным точкам.

View File

@ -0,0 +1,26 @@
package ru.ulstu.tsMethods.exponential;
import com.google.common.collect.ImmutableMap;
import ru.ulstu.models.exceptions.ModelingException;
import java.util.Map;
public class ExponentialMethodParams {
Map<ExponentialParamName, Double> paramsValues;
public ExponentialMethodParams(Map<ExponentialParamName, Double> paramsValues) {
this.paramsValues = paramsValues;
}
public Double getValue(ExponentialParamName paramName) throws ModelingException {
if (paramsValues.containsKey(paramName)) {
return paramsValues.get(paramName);
} else {
throw new ModelingException("Неизвестное название параметра для метода экспоненциального сглаживания");
}
}
public static ExponentialMethodParams of(ExponentialParamName param1, Double value1) {
return new ExponentialMethodParams(ImmutableMap.of(param1, value1));
}
}

View File

@ -0,0 +1,5 @@
package ru.ulstu.tsMethods.exponential;
public enum ExponentialParamName {
ALPHA, BETA, GAMMA
}

View File

@ -3,24 +3,27 @@ package ru.ulstu.tsMethods.exponential;
import ru.ulstu.models.Forecast;
import ru.ulstu.models.Model;
import ru.ulstu.models.TimeSeries;
import ru.ulstu.models.exceptions.ModelingException;
import ru.ulstu.tsMethods.TimeSeriesMethod;
public class NoTrendNoSeason extends TimeSeriesMethod {
private double alpha;
import static ru.ulstu.tsMethods.exponential.ExponentialParamName.ALPHA;
public NoTrendNoSeason(double alpha) {
this.alpha = alpha;
public class NoTrendNoSeason extends TimeSeriesMethod {
private ExponentialMethodParams exponentialMethodParams;
public NoTrendNoSeason(ExponentialMethodParams exponentialMethodParams) {
this.exponentialMethodParams = exponentialMethodParams;
}
@Override
protected Model getModelOfValidTimeSeries(TimeSeries timeSeries) {
protected Model getModelOfValidTimeSeries(TimeSeries timeSeries) throws ModelingException {
Model model = new Model(timeSeries);
model.addValue(timeSeries.getFirstValue());
//выполняется проход модели по сглаживанию
for (int t = 1; t < timeSeries.getValues().size(); t++) {
model.addValue(timeSeries.getValues().get(t),
(1 - alpha) * timeSeries.getNumericValue(t)
+ alpha * model.getModelTimeSeries().getValues().get(t - 1).getValue());
(1 - exponentialMethodParams.getValue(ALPHA)) * timeSeries.getNumericValue(t)
+ exponentialMethodParams.getValue(ALPHA) * model.getModelTimeSeries().getValues().get(t - 1).getValue());
}
return model;
}