fix exponential method params classes

This commit is contained in:
Anton Romanov 2021-05-27 14:31:23 +04:00
parent 8bfb0b854f
commit 8f66d7229a
12 changed files with 120 additions and 80 deletions

View File

@ -1,3 +1,11 @@
/*
*
* * Copyright (C) 2021 Anton Romanov - All Rights Reserved
* * You may use, distribute and modify this code, please write to: romanov73@gmail.com.
*
*
*/
package ru.ulstu.services;
import org.slf4j.Logger;
@ -10,9 +18,9 @@ import ru.ulstu.tsMethods.exponential.AddTrendAddSeason;
import ru.ulstu.tsMethods.exponential.NoTrendNoSeason;
import ru.ulstu.tsMethods.exponential.param.Alpha;
import ru.ulstu.tsMethods.exponential.param.Beta;
import ru.ulstu.tsMethods.exponential.param.ExponentialMethodParamValue;
import ru.ulstu.tsMethods.exponential.param.Gamma;
import ru.ulstu.tsMethods.exponential.param.Season;
import ru.ulstu.tsMethods.exponential.param.TimeSeriesMethodParamValue;
@Service
@ -21,24 +29,24 @@ public class TimeSeriesService {
public TimeSeries getForecast(TimeSeries timeSeries, int countPoints) throws ModelingException {
TimeSeriesMethod method;
method = new NoTrendNoSeason(timeSeries, new TimeSeriesMethodParamValue<>(new Alpha(), 0.8));
method = new NoTrendNoSeason(timeSeries, new ExponentialMethodParamValue<>(new Alpha(), 0.8));
method = new AddTrendAddSeason(timeSeries,
new TimeSeriesMethodParamValue<>(new Alpha(), 0.5),
new TimeSeriesMethodParamValue<>(new Beta(), 0.5),
new TimeSeriesMethodParamValue<>(new Gamma(), 0.5),
new TimeSeriesMethodParamValue<>(new Season(), 17));
new ExponentialMethodParamValue<>(new Alpha(), 0.5),
new ExponentialMethodParamValue<>(new Beta(), 0.5),
new ExponentialMethodParamValue<>(new Gamma(), 0.5),
new ExponentialMethodParamValue<>(new Season(), 17));
return method.getForecast(countPoints);
}
public TimeSeries smoothTimeSeries(TimeSeries timeSeries) throws ModelingException {
//NoTrendNoSeason nn = new NoTrendNoSeason(timeSeries, ExponentialMethodParams.of(ExponentialParamName.ALPHA, 0.8));
TimeSeriesMethod method;
method = new NoTrendNoSeason(timeSeries, new TimeSeriesMethodParamValue<>(new Alpha(), 0.8));
method = new NoTrendNoSeason(timeSeries, new ExponentialMethodParamValue<>(new Alpha(), 0.8));
method = new AddTrendAddSeason(timeSeries,
new TimeSeriesMethodParamValue<>(new Alpha(), 0.5),
new TimeSeriesMethodParamValue<>(new Beta(), 0.5),
new TimeSeriesMethodParamValue<>(new Gamma(), 0.5),
new TimeSeriesMethodParamValue<>(new Season(), 17));
new ExponentialMethodParamValue<>(new Alpha(), 0.5),
new ExponentialMethodParamValue<>(new Beta(), 0.5),
new ExponentialMethodParamValue<>(new Gamma(), 0.5),
new ExponentialMethodParamValue<>(new Season(), 17));
return method.getModel();
}
}

View File

@ -1,28 +1,40 @@
/*
*
* * Copyright (C) 2021 Anton Romanov - All Rights Reserved
* * You may use, distribute and modify this code, please write to: romanov73@gmail.com.
*
*
*/
package ru.ulstu.tsMethods.exponential;
import ru.ulstu.models.TimeSeries;
import ru.ulstu.models.exceptions.ModelingException;
import ru.ulstu.models.exceptions.TimeSeriesValidateException;
import ru.ulstu.tsMethods.TimeSeriesMethod;
import ru.ulstu.tsMethods.exponential.param.*;
import ru.ulstu.tsMethods.exponential.param.Alpha;
import ru.ulstu.tsMethods.exponential.param.Beta;
import ru.ulstu.tsMethods.exponential.param.ExponentialMethodParamValue;
import ru.ulstu.tsMethods.exponential.param.Gamma;
import ru.ulstu.tsMethods.exponential.param.Season;
import java.util.ArrayList;
import java.util.List;
public class AddTrendAddSeason extends TimeSeriesMethod {
private final TimeSeriesMethodParamValue<Alpha> alpha;
private final TimeSeriesMethodParamValue<Beta> beta;
private final TimeSeriesMethodParamValue<Gamma> gamma;
private final TimeSeriesMethodParamValue<Season> season;
private final ExponentialMethodParamValue<Alpha> alpha;
private final ExponentialMethodParamValue<Beta> beta;
private final ExponentialMethodParamValue<Gamma> gamma;
private final ExponentialMethodParamValue<Season> season;
private final List<Double> sComponent = new ArrayList<>();
private final List<Double> tComponent = new ArrayList<>();
private final List<Double> iComponent = new ArrayList<>();
public AddTrendAddSeason(TimeSeries timeSeries,
TimeSeriesMethodParamValue<Alpha> alpha,
TimeSeriesMethodParamValue<Beta> beta,
TimeSeriesMethodParamValue<Gamma> gamma,
TimeSeriesMethodParamValue<Season> season) throws ModelingException {
ExponentialMethodParamValue<Alpha> alpha,
ExponentialMethodParamValue<Beta> beta,
ExponentialMethodParamValue<Gamma> gamma,
ExponentialMethodParamValue<Season> season) throws ModelingException {
super(timeSeries);
this.alpha = alpha;
this.beta = beta;

View File

@ -1,3 +1,11 @@
/*
*
* * Copyright (C) 2021 Anton Romanov - All Rights Reserved
* * You may use, distribute and modify this code, please write to: romanov73@gmail.com.
*
*
*/
package ru.ulstu.tsMethods.exponential;
import ru.ulstu.models.TimeSeries;
@ -5,20 +13,20 @@ import ru.ulstu.models.exceptions.ModelingException;
import ru.ulstu.tsMethods.TimeSeriesMethod;
import ru.ulstu.tsMethods.exponential.param.Alpha;
import ru.ulstu.tsMethods.exponential.param.Beta;
import ru.ulstu.tsMethods.exponential.param.TimeSeriesMethodParamValue;
import ru.ulstu.tsMethods.exponential.param.ExponentialMethodParamValue;
import java.util.ArrayList;
import java.util.List;
public class AddTrendNoSeason extends TimeSeriesMethod {
private final TimeSeriesMethodParamValue<Alpha> alpha;
private final TimeSeriesMethodParamValue<Beta> beta;
private final ExponentialMethodParamValue<Alpha> alpha;
private final ExponentialMethodParamValue<Beta> beta;
private final List<Double> sComponent = new ArrayList<>();
private final List<Double> tComponent = new ArrayList<>();
public AddTrendNoSeason(TimeSeries timeSeries,
TimeSeriesMethodParamValue<Alpha> alpha,
TimeSeriesMethodParamValue<Beta> beta) throws ModelingException {
ExponentialMethodParamValue<Alpha> alpha,
ExponentialMethodParamValue<Beta> beta) throws ModelingException {
super(timeSeries);
this.alpha = alpha;
this.beta = beta;

View File

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

View File

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

View File

@ -1,19 +1,27 @@
/*
*
* * Copyright (C) 2021 Anton Romanov - All Rights Reserved
* * You may use, distribute and modify this code, please write to: romanov73@gmail.com.
*
*
*/
package ru.ulstu.tsMethods.exponential;
import ru.ulstu.models.TimeSeries;
import ru.ulstu.models.exceptions.ModelingException;
import ru.ulstu.tsMethods.TimeSeriesMethod;
import ru.ulstu.tsMethods.exponential.param.Alpha;
import ru.ulstu.tsMethods.exponential.param.TimeSeriesMethodParamValue;
import ru.ulstu.tsMethods.exponential.param.ExponentialMethodParamValue;
import java.util.ArrayList;
import java.util.List;
public class NoTrendNoSeason extends TimeSeriesMethod {
private final TimeSeriesMethodParamValue<Alpha> alpha;
private final ExponentialMethodParamValue<Alpha> alpha;
private final List<Double> sComponent = new ArrayList<>();
public NoTrendNoSeason(TimeSeries timeSeries, TimeSeriesMethodParamValue<Alpha> alpha) throws ModelingException {
public NoTrendNoSeason(TimeSeries timeSeries, ExponentialMethodParamValue<Alpha> alpha) throws ModelingException {
super(timeSeries);
this.alpha = alpha;
}

View File

@ -1,6 +1,14 @@
/*
*
* * Copyright (C) 2021 Anton Romanov - All Rights Reserved
* * You may use, distribute and modify this code, please write to: romanov73@gmail.com.
*
*
*/
package ru.ulstu.tsMethods.exponential.param;
public class Alpha extends TimeSeriesMethodParam {
public class Alpha extends ExponentialMethodParam {
public Alpha() {
super("ALPHA", 0, 1, DEFAULT_OPTIMIZATION_STEP);
}

View File

@ -1,6 +1,14 @@
/*
*
* * Copyright (C) 2021 Anton Romanov - All Rights Reserved
* * You may use, distribute and modify this code, please write to: romanov73@gmail.com.
*
*
*/
package ru.ulstu.tsMethods.exponential.param;
public class Beta extends TimeSeriesMethodParam {
public class Beta extends ExponentialMethodParam {
public Beta() {
super("BETA", 0, 1, DEFAULT_OPTIMIZATION_STEP);
}

View File

@ -1,13 +1,21 @@
/*
*
* * Copyright (C) 2021 Anton Romanov - All Rights Reserved
* * You may use, distribute and modify this code, please write to: romanov73@gmail.com.
*
*
*/
package ru.ulstu.tsMethods.exponential.param;
public abstract class TimeSeriesMethodParam {
public abstract class ExponentialMethodParam {
public static final Float DEFAULT_OPTIMIZATION_STEP = 0.01f;
private final String key;
private final Number minValue;
private final Number maxValue;
private final Number optimizationStep;
public TimeSeriesMethodParam(String key, Number minValue, Number maxValue, Number optimizationStep) {
public ExponentialMethodParam(String key, Number minValue, Number maxValue, Number optimizationStep) {
this.key = key;
this.minValue = minValue;
this.maxValue = maxValue;

View File

@ -1,10 +1,18 @@
/*
*
* * Copyright (C) 2021 Anton Romanov - All Rights Reserved
* * You may use, distribute and modify this code, please write to: romanov73@gmail.com.
*
*
*/
package ru.ulstu.tsMethods.exponential.param;
public class TimeSeriesMethodParamValue<T extends TimeSeriesMethodParam> {
public class ExponentialMethodParamValue<T extends ExponentialMethodParam> {
private final T param;
private final Number value;
public TimeSeriesMethodParamValue(T param, Number value) {
public ExponentialMethodParamValue(T param, Number value) {
this.param = param;
this.value = value;
}

View File

@ -1,6 +1,14 @@
/*
*
* * Copyright (C) 2021 Anton Romanov - All Rights Reserved
* * You may use, distribute and modify this code, please write to: romanov73@gmail.com.
*
*
*/
package ru.ulstu.tsMethods.exponential.param;
public class Gamma extends TimeSeriesMethodParam {
public class Gamma extends ExponentialMethodParam {
public Gamma() {
super("Gamma", 0, 1, DEFAULT_OPTIMIZATION_STEP);
}

View File

@ -1,6 +1,14 @@
/*
*
* * Copyright (C) 2021 Anton Romanov - All Rights Reserved
* * You may use, distribute and modify this code, please write to: romanov73@gmail.com.
*
*
*/
package ru.ulstu.tsMethods.exponential.param;
public class Season extends TimeSeriesMethodParam {
public class Season extends ExponentialMethodParam {
private final static int DEFAULT_SEASON_OPTIMIZATION_STEP = 1;
public Season() {