diff --git a/src/main/java/ru/ulstu/services/TimeSeriesService.java b/src/main/java/ru/ulstu/services/TimeSeriesService.java index 4d5578f..06134b6 100644 --- a/src/main/java/ru/ulstu/services/TimeSeriesService.java +++ b/src/main/java/ru/ulstu/services/TimeSeriesService.java @@ -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(); } } diff --git a/src/main/java/ru/ulstu/tsMethods/exponential/AddTrendAddSeason.java b/src/main/java/ru/ulstu/tsMethods/exponential/AddTrendAddSeason.java index fe5f0fb..474cc8a 100644 --- a/src/main/java/ru/ulstu/tsMethods/exponential/AddTrendAddSeason.java +++ b/src/main/java/ru/ulstu/tsMethods/exponential/AddTrendAddSeason.java @@ -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; - private final TimeSeriesMethodParamValue beta; - private final TimeSeriesMethodParamValue gamma; - private final TimeSeriesMethodParamValue season; + private final ExponentialMethodParamValue alpha; + private final ExponentialMethodParamValue beta; + private final ExponentialMethodParamValue gamma; + private final ExponentialMethodParamValue season; private final List sComponent = new ArrayList<>(); private final List tComponent = new ArrayList<>(); private final List iComponent = new ArrayList<>(); public AddTrendAddSeason(TimeSeries timeSeries, - TimeSeriesMethodParamValue alpha, - TimeSeriesMethodParamValue beta, - TimeSeriesMethodParamValue gamma, - TimeSeriesMethodParamValue season) throws ModelingException { + ExponentialMethodParamValue alpha, + ExponentialMethodParamValue beta, + ExponentialMethodParamValue gamma, + ExponentialMethodParamValue season) throws ModelingException { super(timeSeries); this.alpha = alpha; this.beta = beta; diff --git a/src/main/java/ru/ulstu/tsMethods/exponential/AddTrendNoSeason.java b/src/main/java/ru/ulstu/tsMethods/exponential/AddTrendNoSeason.java index 5e3da4e..3f7aa24 100644 --- a/src/main/java/ru/ulstu/tsMethods/exponential/AddTrendNoSeason.java +++ b/src/main/java/ru/ulstu/tsMethods/exponential/AddTrendNoSeason.java @@ -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; - private final TimeSeriesMethodParamValue beta; + private final ExponentialMethodParamValue alpha; + private final ExponentialMethodParamValue beta; private final List sComponent = new ArrayList<>(); private final List tComponent = new ArrayList<>(); public AddTrendNoSeason(TimeSeries timeSeries, - TimeSeriesMethodParamValue alpha, - TimeSeriesMethodParamValue beta) throws ModelingException { + ExponentialMethodParamValue alpha, + ExponentialMethodParamValue beta) throws ModelingException { super(timeSeries); this.alpha = alpha; this.beta = beta; diff --git a/src/main/java/ru/ulstu/tsMethods/exponential/ExponentialMethodParams.java b/src/main/java/ru/ulstu/tsMethods/exponential/ExponentialMethodParams.java deleted file mode 100644 index cb01b10..0000000 --- a/src/main/java/ru/ulstu/tsMethods/exponential/ExponentialMethodParams.java +++ /dev/null @@ -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 paramsValues; - - public ExponentialMethodParams(Map 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)); - } -} diff --git a/src/main/java/ru/ulstu/tsMethods/exponential/ExponentialParamName.java b/src/main/java/ru/ulstu/tsMethods/exponential/ExponentialParamName.java deleted file mode 100644 index 452470f..0000000 --- a/src/main/java/ru/ulstu/tsMethods/exponential/ExponentialParamName.java +++ /dev/null @@ -1,5 +0,0 @@ -package ru.ulstu.tsMethods.exponential; - -public enum ExponentialParamName { - ALPHA, BETA, GAMMA, SEASON -} diff --git a/src/main/java/ru/ulstu/tsMethods/exponential/NoTrendNoSeason.java b/src/main/java/ru/ulstu/tsMethods/exponential/NoTrendNoSeason.java index 5c7a6d1..ef53e91 100644 --- a/src/main/java/ru/ulstu/tsMethods/exponential/NoTrendNoSeason.java +++ b/src/main/java/ru/ulstu/tsMethods/exponential/NoTrendNoSeason.java @@ -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; + private final ExponentialMethodParamValue alpha; private final List sComponent = new ArrayList<>(); - public NoTrendNoSeason(TimeSeries timeSeries, TimeSeriesMethodParamValue alpha) throws ModelingException { + public NoTrendNoSeason(TimeSeries timeSeries, ExponentialMethodParamValue alpha) throws ModelingException { super(timeSeries); this.alpha = alpha; } diff --git a/src/main/java/ru/ulstu/tsMethods/exponential/param/Alpha.java b/src/main/java/ru/ulstu/tsMethods/exponential/param/Alpha.java index bb68013..df5d431 100644 --- a/src/main/java/ru/ulstu/tsMethods/exponential/param/Alpha.java +++ b/src/main/java/ru/ulstu/tsMethods/exponential/param/Alpha.java @@ -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); } diff --git a/src/main/java/ru/ulstu/tsMethods/exponential/param/Beta.java b/src/main/java/ru/ulstu/tsMethods/exponential/param/Beta.java index 9f46cc8..8509593 100644 --- a/src/main/java/ru/ulstu/tsMethods/exponential/param/Beta.java +++ b/src/main/java/ru/ulstu/tsMethods/exponential/param/Beta.java @@ -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); } diff --git a/src/main/java/ru/ulstu/tsMethods/exponential/param/TimeSeriesMethodParam.java b/src/main/java/ru/ulstu/tsMethods/exponential/param/ExponentialMethodParam.java similarity index 74% rename from src/main/java/ru/ulstu/tsMethods/exponential/param/TimeSeriesMethodParam.java rename to src/main/java/ru/ulstu/tsMethods/exponential/param/ExponentialMethodParam.java index cdf0f78..696d93a 100644 --- a/src/main/java/ru/ulstu/tsMethods/exponential/param/TimeSeriesMethodParam.java +++ b/src/main/java/ru/ulstu/tsMethods/exponential/param/ExponentialMethodParam.java @@ -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; diff --git a/src/main/java/ru/ulstu/tsMethods/exponential/param/TimeSeriesMethodParamValue.java b/src/main/java/ru/ulstu/tsMethods/exponential/param/ExponentialMethodParamValue.java similarity index 58% rename from src/main/java/ru/ulstu/tsMethods/exponential/param/TimeSeriesMethodParamValue.java rename to src/main/java/ru/ulstu/tsMethods/exponential/param/ExponentialMethodParamValue.java index 490cd0f..608b959 100644 --- a/src/main/java/ru/ulstu/tsMethods/exponential/param/TimeSeriesMethodParamValue.java +++ b/src/main/java/ru/ulstu/tsMethods/exponential/param/ExponentialMethodParamValue.java @@ -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 { +public class ExponentialMethodParamValue { 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; } diff --git a/src/main/java/ru/ulstu/tsMethods/exponential/param/Gamma.java b/src/main/java/ru/ulstu/tsMethods/exponential/param/Gamma.java index 2f759cc..b739290 100644 --- a/src/main/java/ru/ulstu/tsMethods/exponential/param/Gamma.java +++ b/src/main/java/ru/ulstu/tsMethods/exponential/param/Gamma.java @@ -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); } diff --git a/src/main/java/ru/ulstu/tsMethods/exponential/param/Season.java b/src/main/java/ru/ulstu/tsMethods/exponential/param/Season.java index 6d7cb74..3f39d40 100644 --- a/src/main/java/ru/ulstu/tsMethods/exponential/param/Season.java +++ b/src/main/java/ru/ulstu/tsMethods/exponential/param/Season.java @@ -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() {