partial bad code
This commit is contained in:
parent
8f66d7229a
commit
ce8fd32642
29
src/main/java/ru/ulstu/models/ModelingResult.java
Normal file
29
src/main/java/ru/ulstu/models/ModelingResult.java
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package ru.ulstu.models;
|
||||||
|
|
||||||
|
import ru.ulstu.tsMethods.exponential.param.TimeSeriesMethodParamValue;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ModelingResult {
|
||||||
|
private final TimeSeries timeSeries;
|
||||||
|
private final List<TimeSeriesMethodParamValue> paramValues;
|
||||||
|
private final Score score;
|
||||||
|
|
||||||
|
public ModelingResult(TimeSeries timeSeries, List<TimeSeriesMethodParamValue> paramValues, Score score) {
|
||||||
|
this.timeSeries = timeSeries;
|
||||||
|
this.paramValues = paramValues;
|
||||||
|
this.score = score;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TimeSeries getTimeSeries() {
|
||||||
|
return timeSeries;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<TimeSeriesMethodParamValue> getParamValues() {
|
||||||
|
return paramValues;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Score getScore() {
|
||||||
|
return score;
|
||||||
|
}
|
||||||
|
}
|
21
src/main/java/ru/ulstu/models/Score.java
Normal file
21
src/main/java/ru/ulstu/models/Score.java
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package ru.ulstu.models;
|
||||||
|
|
||||||
|
import ru.ulstu.score.ScoreMethod;
|
||||||
|
|
||||||
|
public class Score {
|
||||||
|
private final ScoreMethod scoreMethod;
|
||||||
|
private final Number value;
|
||||||
|
|
||||||
|
public Score(ScoreMethod scoreMethod, Number value) {
|
||||||
|
this.scoreMethod = scoreMethod;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ScoreMethod getScoreMethod() {
|
||||||
|
return scoreMethod;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Number getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
7
src/main/java/ru/ulstu/score/ScoreMethod.java
Normal file
7
src/main/java/ru/ulstu/score/ScoreMethod.java
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package ru.ulstu.score;
|
||||||
|
|
||||||
|
import ru.ulstu.models.TimeSeries;
|
||||||
|
|
||||||
|
public abstract class ScoreMethod {
|
||||||
|
public abstract Number evaluate(TimeSeries originalTimeSeries, TimeSeries modelTimeSeries);
|
||||||
|
}
|
60
src/main/java/ru/ulstu/services/MethodParamBruteForce.java
Normal file
60
src/main/java/ru/ulstu/services/MethodParamBruteForce.java
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
package ru.ulstu.services;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import ru.ulstu.models.ModelingResult;
|
||||||
|
import ru.ulstu.models.TimeSeries;
|
||||||
|
import ru.ulstu.tsMethods.TimeSeriesMethod;
|
||||||
|
import ru.ulstu.tsMethods.exponential.param.TimeSeriesMethodParam;
|
||||||
|
import ru.ulstu.tsMethods.exponential.param.TimeSeriesMethodParamValue;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class MethodParamBruteForce {
|
||||||
|
private final List<TimeSeriesMethod> methods;
|
||||||
|
private ExecutorService executors = Executors.newFixedThreadPool(10);
|
||||||
|
|
||||||
|
public MethodParamBruteForce(List<TimeSeriesMethod> methods) {
|
||||||
|
this.methods = methods;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TimeSeries getForecast(TimeSeries timeSeries) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public TimeSeries getForecastWithOptimalLength(TimeSeries timeSeries) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public TimeSeries getSmoothedTimeSeries(TimeSeries timeSeries) {
|
||||||
|
List<Future<ModelingResult>> results = new ArrayList<>();
|
||||||
|
for (TimeSeriesMethod method : methods) {
|
||||||
|
List<TimeSeriesMethodParam> availableParams = method.getAvailableParams();
|
||||||
|
Map<TimeSeriesMethodParam, List<Number>> paramsAvailableValues = new HashMap<>();
|
||||||
|
for (TimeSeriesMethodParam param : availableParams) {
|
||||||
|
paramsAvailableValues.put(param, param.getAvailableValues());
|
||||||
|
}
|
||||||
|
List<TimeSeriesMethodParamValue> paramValues = new ArrayList<>();
|
||||||
|
results.add(executors.submit(() -> {
|
||||||
|
return new ModelingResult(method.getModel(),
|
||||||
|
method.createFor(timeSeries)
|
||||||
|
.setAvailableParams(paramValues)
|
||||||
|
.getModel());
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
TimeSeries result = null;
|
||||||
|
try {
|
||||||
|
result = results.get(0).get();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
@ -6,8 +6,11 @@ import ru.ulstu.models.TimeSeriesValue;
|
|||||||
import ru.ulstu.models.exceptions.ForecastValidateException;
|
import ru.ulstu.models.exceptions.ForecastValidateException;
|
||||||
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.exponential.param.TimeSeriesMethodParam;
|
||||||
|
import ru.ulstu.tsMethods.exponential.param.TimeSeriesMethodParamValue;
|
||||||
|
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Наиболее общая логика моделировани и прогнозирования временных рядов
|
* Наиболее общая логика моделировани и прогнозирования временных рядов
|
||||||
@ -16,9 +19,7 @@ public abstract class TimeSeriesMethod {
|
|||||||
protected TimeSeries originalTimeSeries;
|
protected TimeSeries originalTimeSeries;
|
||||||
private TimeSeries model;
|
private TimeSeries model;
|
||||||
|
|
||||||
public TimeSeriesMethod(TimeSeries originalTimeSeries) throws ModelingException {
|
public abstract TimeSeriesMethod createFor(TimeSeries originalTimeSeries);
|
||||||
this.originalTimeSeries = originalTimeSeries;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Возвращает модельное представление временного ряда: для тех же точек времени что и в параметре timeSeries
|
* Возвращает модельное представление временного ряда: для тех же точек времени что и в параметре timeSeries
|
||||||
@ -117,4 +118,8 @@ public abstract class TimeSeriesMethod {
|
|||||||
}
|
}
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract List<TimeSeriesMethodParam> getAvailableParams();
|
||||||
|
|
||||||
|
public abstract TimeSeriesMethod setAvailableParams(List<TimeSeriesMethodParamValue> params);
|
||||||
}
|
}
|
||||||
|
@ -8,22 +8,31 @@
|
|||||||
|
|
||||||
package ru.ulstu.tsMethods.exponential;
|
package ru.ulstu.tsMethods.exponential;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
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.ExponentialMethodParam;
|
||||||
import ru.ulstu.tsMethods.exponential.param.ExponentialMethodParamValue;
|
import ru.ulstu.tsMethods.exponential.param.ExponentialMethodParamValue;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@Component
|
||||||
public class NoTrendNoSeason extends TimeSeriesMethod {
|
public class NoTrendNoSeason extends TimeSeriesMethod {
|
||||||
private final ExponentialMethodParamValue<Alpha> alpha;
|
private ExponentialMethodParamValue<Alpha> alpha;
|
||||||
private final List<Double> sComponent = new ArrayList<>();
|
private final List<Double> sComponent = new ArrayList<>();
|
||||||
|
|
||||||
public NoTrendNoSeason(TimeSeries timeSeries, ExponentialMethodParamValue<Alpha> alpha) throws ModelingException {
|
public NoTrendNoSeason createFor(TimeSeries timeSeries) {
|
||||||
super(timeSeries);
|
this.originalTimeSeries = timeSeries;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NoTrendNoSeason setAlpha(ExponentialMethodParamValue<Alpha> alpha) {
|
||||||
this.alpha = alpha;
|
this.alpha = alpha;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -49,4 +58,19 @@ public class NoTrendNoSeason extends TimeSeriesMethod {
|
|||||||
}
|
}
|
||||||
return forecast;
|
return forecast;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ExponentialMethodParam> getAvailableParams() {
|
||||||
|
return Collections.singletonList(alpha.getParam());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TimeSeriesMethod setAvailableParams(List<ExponentialMethodParamValue> params) {
|
||||||
|
for (ExponentialMethodParamValue param : params) {
|
||||||
|
if (param.getParam() instanceof Alpha) {
|
||||||
|
alpha.setValue(param.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ package ru.ulstu.tsMethods.exponential.param;
|
|||||||
|
|
||||||
public class ExponentialMethodParamValue<T extends ExponentialMethodParam> {
|
public class ExponentialMethodParamValue<T extends ExponentialMethodParam> {
|
||||||
private final T param;
|
private final T param;
|
||||||
private final Number value;
|
private Number value;
|
||||||
|
|
||||||
public ExponentialMethodParamValue(T param, Number value) {
|
public ExponentialMethodParamValue(T param, Number value) {
|
||||||
this.param = param;
|
this.param = param;
|
||||||
@ -32,4 +32,8 @@ public class ExponentialMethodParamValue<T extends ExponentialMethodParam> {
|
|||||||
public int getIntValue() {
|
public int getIntValue() {
|
||||||
return value.intValue();
|
return value.intValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setValue(Number value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user