fix exponential method params classes
This commit is contained in:
parent
8bfb0b854f
commit
8f66d7229a
@ -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;
|
package ru.ulstu.services;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
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.NoTrendNoSeason;
|
||||||
import ru.ulstu.tsMethods.exponential.param.Alpha;
|
import ru.ulstu.tsMethods.exponential.param.Alpha;
|
||||||
import ru.ulstu.tsMethods.exponential.param.Beta;
|
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.Gamma;
|
||||||
import ru.ulstu.tsMethods.exponential.param.Season;
|
import ru.ulstu.tsMethods.exponential.param.Season;
|
||||||
import ru.ulstu.tsMethods.exponential.param.TimeSeriesMethodParamValue;
|
|
||||||
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@ -21,24 +29,24 @@ public class TimeSeriesService {
|
|||||||
|
|
||||||
public TimeSeries getForecast(TimeSeries timeSeries, int countPoints) throws ModelingException {
|
public TimeSeries getForecast(TimeSeries timeSeries, int countPoints) throws ModelingException {
|
||||||
TimeSeriesMethod method;
|
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,
|
method = new AddTrendAddSeason(timeSeries,
|
||||||
new TimeSeriesMethodParamValue<>(new Alpha(), 0.5),
|
new ExponentialMethodParamValue<>(new Alpha(), 0.5),
|
||||||
new TimeSeriesMethodParamValue<>(new Beta(), 0.5),
|
new ExponentialMethodParamValue<>(new Beta(), 0.5),
|
||||||
new TimeSeriesMethodParamValue<>(new Gamma(), 0.5),
|
new ExponentialMethodParamValue<>(new Gamma(), 0.5),
|
||||||
new TimeSeriesMethodParamValue<>(new Season(), 17));
|
new ExponentialMethodParamValue<>(new Season(), 17));
|
||||||
return method.getForecast(countPoints);
|
return method.getForecast(countPoints);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TimeSeries smoothTimeSeries(TimeSeries timeSeries) throws ModelingException {
|
public TimeSeries smoothTimeSeries(TimeSeries timeSeries) throws ModelingException {
|
||||||
//NoTrendNoSeason nn = new NoTrendNoSeason(timeSeries, ExponentialMethodParams.of(ExponentialParamName.ALPHA, 0.8));
|
//NoTrendNoSeason nn = new NoTrendNoSeason(timeSeries, ExponentialMethodParams.of(ExponentialParamName.ALPHA, 0.8));
|
||||||
TimeSeriesMethod method;
|
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,
|
method = new AddTrendAddSeason(timeSeries,
|
||||||
new TimeSeriesMethodParamValue<>(new Alpha(), 0.5),
|
new ExponentialMethodParamValue<>(new Alpha(), 0.5),
|
||||||
new TimeSeriesMethodParamValue<>(new Beta(), 0.5),
|
new ExponentialMethodParamValue<>(new Beta(), 0.5),
|
||||||
new TimeSeriesMethodParamValue<>(new Gamma(), 0.5),
|
new ExponentialMethodParamValue<>(new Gamma(), 0.5),
|
||||||
new TimeSeriesMethodParamValue<>(new Season(), 17));
|
new ExponentialMethodParamValue<>(new Season(), 17));
|
||||||
return method.getModel();
|
return method.getModel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
package ru.ulstu.tsMethods.exponential;
|
||||||
|
|
||||||
import ru.ulstu.models.TimeSeries;
|
import ru.ulstu.models.TimeSeries;
|
||||||
import ru.ulstu.models.exceptions.ModelingException;
|
import ru.ulstu.models.exceptions.ModelingException;
|
||||||
import ru.ulstu.models.exceptions.TimeSeriesValidateException;
|
import ru.ulstu.models.exceptions.TimeSeriesValidateException;
|
||||||
import ru.ulstu.tsMethods.TimeSeriesMethod;
|
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.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class AddTrendAddSeason extends TimeSeriesMethod {
|
public class AddTrendAddSeason extends TimeSeriesMethod {
|
||||||
private final TimeSeriesMethodParamValue<Alpha> alpha;
|
private final ExponentialMethodParamValue<Alpha> alpha;
|
||||||
private final TimeSeriesMethodParamValue<Beta> beta;
|
private final ExponentialMethodParamValue<Beta> beta;
|
||||||
private final TimeSeriesMethodParamValue<Gamma> gamma;
|
private final ExponentialMethodParamValue<Gamma> gamma;
|
||||||
private final TimeSeriesMethodParamValue<Season> season;
|
private final ExponentialMethodParamValue<Season> season;
|
||||||
private final List<Double> sComponent = new ArrayList<>();
|
private final List<Double> sComponent = new ArrayList<>();
|
||||||
private final List<Double> tComponent = new ArrayList<>();
|
private final List<Double> tComponent = new ArrayList<>();
|
||||||
private final List<Double> iComponent = new ArrayList<>();
|
private final List<Double> iComponent = new ArrayList<>();
|
||||||
|
|
||||||
public AddTrendAddSeason(TimeSeries timeSeries,
|
public AddTrendAddSeason(TimeSeries timeSeries,
|
||||||
TimeSeriesMethodParamValue<Alpha> alpha,
|
ExponentialMethodParamValue<Alpha> alpha,
|
||||||
TimeSeriesMethodParamValue<Beta> beta,
|
ExponentialMethodParamValue<Beta> beta,
|
||||||
TimeSeriesMethodParamValue<Gamma> gamma,
|
ExponentialMethodParamValue<Gamma> gamma,
|
||||||
TimeSeriesMethodParamValue<Season> season) throws ModelingException {
|
ExponentialMethodParamValue<Season> season) throws ModelingException {
|
||||||
super(timeSeries);
|
super(timeSeries);
|
||||||
this.alpha = alpha;
|
this.alpha = alpha;
|
||||||
this.beta = beta;
|
this.beta = beta;
|
||||||
|
@ -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;
|
package ru.ulstu.tsMethods.exponential;
|
||||||
|
|
||||||
import ru.ulstu.models.TimeSeries;
|
import ru.ulstu.models.TimeSeries;
|
||||||
@ -5,20 +13,20 @@ import ru.ulstu.models.exceptions.ModelingException;
|
|||||||
import ru.ulstu.tsMethods.TimeSeriesMethod;
|
import ru.ulstu.tsMethods.TimeSeriesMethod;
|
||||||
import ru.ulstu.tsMethods.exponential.param.Alpha;
|
import ru.ulstu.tsMethods.exponential.param.Alpha;
|
||||||
import ru.ulstu.tsMethods.exponential.param.Beta;
|
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.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class AddTrendNoSeason extends TimeSeriesMethod {
|
public class AddTrendNoSeason extends TimeSeriesMethod {
|
||||||
private final TimeSeriesMethodParamValue<Alpha> alpha;
|
private final ExponentialMethodParamValue<Alpha> alpha;
|
||||||
private final TimeSeriesMethodParamValue<Beta> beta;
|
private final ExponentialMethodParamValue<Beta> beta;
|
||||||
private final List<Double> sComponent = new ArrayList<>();
|
private final List<Double> sComponent = new ArrayList<>();
|
||||||
private final List<Double> tComponent = new ArrayList<>();
|
private final List<Double> tComponent = new ArrayList<>();
|
||||||
|
|
||||||
public AddTrendNoSeason(TimeSeries timeSeries,
|
public AddTrendNoSeason(TimeSeries timeSeries,
|
||||||
TimeSeriesMethodParamValue<Alpha> alpha,
|
ExponentialMethodParamValue<Alpha> alpha,
|
||||||
TimeSeriesMethodParamValue<Beta> beta) throws ModelingException {
|
ExponentialMethodParamValue<Beta> beta) throws ModelingException {
|
||||||
super(timeSeries);
|
super(timeSeries);
|
||||||
this.alpha = alpha;
|
this.alpha = alpha;
|
||||||
this.beta = beta;
|
this.beta = beta;
|
||||||
|
@ -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));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,5 +0,0 @@
|
|||||||
package ru.ulstu.tsMethods.exponential;
|
|
||||||
|
|
||||||
public enum ExponentialParamName {
|
|
||||||
ALPHA, BETA, GAMMA, SEASON
|
|
||||||
}
|
|
@ -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;
|
package ru.ulstu.tsMethods.exponential;
|
||||||
|
|
||||||
import ru.ulstu.models.TimeSeries;
|
import ru.ulstu.models.TimeSeries;
|
||||||
import ru.ulstu.models.exceptions.ModelingException;
|
import ru.ulstu.models.exceptions.ModelingException;
|
||||||
import ru.ulstu.tsMethods.TimeSeriesMethod;
|
import ru.ulstu.tsMethods.TimeSeriesMethod;
|
||||||
import ru.ulstu.tsMethods.exponential.param.Alpha;
|
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.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class NoTrendNoSeason extends TimeSeriesMethod {
|
public class NoTrendNoSeason extends TimeSeriesMethod {
|
||||||
private final TimeSeriesMethodParamValue<Alpha> alpha;
|
private final ExponentialMethodParamValue<Alpha> alpha;
|
||||||
private final List<Double> sComponent = new ArrayList<>();
|
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);
|
super(timeSeries);
|
||||||
this.alpha = alpha;
|
this.alpha = alpha;
|
||||||
}
|
}
|
||||||
|
@ -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;
|
package ru.ulstu.tsMethods.exponential.param;
|
||||||
|
|
||||||
public class Alpha extends TimeSeriesMethodParam {
|
public class Alpha extends ExponentialMethodParam {
|
||||||
public Alpha() {
|
public Alpha() {
|
||||||
super("ALPHA", 0, 1, DEFAULT_OPTIMIZATION_STEP);
|
super("ALPHA", 0, 1, DEFAULT_OPTIMIZATION_STEP);
|
||||||
}
|
}
|
||||||
|
@ -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;
|
package ru.ulstu.tsMethods.exponential.param;
|
||||||
|
|
||||||
public class Beta extends TimeSeriesMethodParam {
|
public class Beta extends ExponentialMethodParam {
|
||||||
public Beta() {
|
public Beta() {
|
||||||
super("BETA", 0, 1, DEFAULT_OPTIMIZATION_STEP);
|
super("BETA", 0, 1, DEFAULT_OPTIMIZATION_STEP);
|
||||||
}
|
}
|
||||||
|
@ -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;
|
package ru.ulstu.tsMethods.exponential.param;
|
||||||
|
|
||||||
public abstract class TimeSeriesMethodParam {
|
public abstract class ExponentialMethodParam {
|
||||||
public static final Float DEFAULT_OPTIMIZATION_STEP = 0.01f;
|
public static final Float DEFAULT_OPTIMIZATION_STEP = 0.01f;
|
||||||
private final String key;
|
private final String key;
|
||||||
private final Number minValue;
|
private final Number minValue;
|
||||||
private final Number maxValue;
|
private final Number maxValue;
|
||||||
private final Number optimizationStep;
|
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.key = key;
|
||||||
this.minValue = minValue;
|
this.minValue = minValue;
|
||||||
this.maxValue = maxValue;
|
this.maxValue = maxValue;
|
@ -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;
|
package ru.ulstu.tsMethods.exponential.param;
|
||||||
|
|
||||||
public class TimeSeriesMethodParamValue<T extends TimeSeriesMethodParam> {
|
public class ExponentialMethodParamValue<T extends ExponentialMethodParam> {
|
||||||
private final T param;
|
private final T param;
|
||||||
private final Number value;
|
private final Number value;
|
||||||
|
|
||||||
public TimeSeriesMethodParamValue(T param, Number value) {
|
public ExponentialMethodParamValue(T param, Number value) {
|
||||||
this.param = param;
|
this.param = param;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
@ -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;
|
package ru.ulstu.tsMethods.exponential.param;
|
||||||
|
|
||||||
public class Gamma extends TimeSeriesMethodParam {
|
public class Gamma extends ExponentialMethodParam {
|
||||||
public Gamma() {
|
public Gamma() {
|
||||||
super("Gamma", 0, 1, DEFAULT_OPTIMIZATION_STEP);
|
super("Gamma", 0, 1, DEFAULT_OPTIMIZATION_STEP);
|
||||||
}
|
}
|
||||||
|
@ -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;
|
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;
|
private final static int DEFAULT_SEASON_OPTIMIZATION_STEP = 1;
|
||||||
|
|
||||||
public Season() {
|
public Season() {
|
||||||
|
Loading…
Reference in New Issue
Block a user