performance improvements
This commit is contained in:
parent
f7666b085e
commit
0196a478da
@ -11,6 +11,9 @@ import ru.ulstu.datamodel.exception.ModelingException;
|
|||||||
import ru.ulstu.datamodel.ts.TimeSeries;
|
import ru.ulstu.datamodel.ts.TimeSeries;
|
||||||
import ru.ulstu.datamodel.ts.TimeSeriesValue;
|
import ru.ulstu.datamodel.ts.TimeSeriesValue;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public abstract class ScoreMethod {
|
public abstract class ScoreMethod {
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
@ -18,11 +21,11 @@ public abstract class ScoreMethod {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Score getScore(TimeSeries original, TimeSeries model) throws ModelingException {
|
public Score getScore(Map<LocalDateTime, Double> tsValues, TimeSeries model) throws ModelingException {
|
||||||
return new Score(this, evaluate(original, model));
|
return new Score(this, evaluate(tsValues, model));
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract Number evaluate(TimeSeries original, TimeSeries model) throws ModelingException;
|
public abstract Number evaluate(Map<LocalDateTime, Double> tsValues, TimeSeries model) throws ModelingException;
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
|
@ -10,6 +10,10 @@ import ru.ulstu.datamodel.exception.ModelingException;
|
|||||||
import ru.ulstu.datamodel.ts.TimeSeries;
|
import ru.ulstu.datamodel.ts.TimeSeries;
|
||||||
import ru.ulstu.datamodel.ts.TimeSeriesValue;
|
import ru.ulstu.datamodel.ts.TimeSeriesValue;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import static java.lang.Math.abs;
|
import static java.lang.Math.abs;
|
||||||
|
|
||||||
public class Smape extends ScoreMethod {
|
public class Smape extends ScoreMethod {
|
||||||
@ -18,10 +22,13 @@ public class Smape extends ScoreMethod {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Number evaluate(TimeSeries original, TimeSeries model) throws ModelingException {
|
public Number evaluate(Map<LocalDateTime, Double> tsValues, TimeSeries model) throws ModelingException {
|
||||||
double sum = 0;
|
double sum = 0;
|
||||||
for (TimeSeriesValue modelValue : model.getValues()) {
|
for (TimeSeriesValue modelValue : model.getValues()) {
|
||||||
double actualValue = getValueOnSameDate(modelValue, original).getValue();
|
//double actualValue = getValueOnSameDate(modelValue, original).getValue();
|
||||||
|
double actualValue = Optional.ofNullable(tsValues.get(modelValue.getDate()))
|
||||||
|
.orElseThrow(() -> new ModelingException("Значение модельного ряда не найдено в оригинальном ряде: "
|
||||||
|
+ modelValue.getDate()));
|
||||||
sum += abs(modelValue.getValue() - actualValue)
|
sum += abs(modelValue.getValue() - actualValue)
|
||||||
/ ((abs(actualValue) + abs(modelValue.getValue())) / 2);
|
/ ((abs(actualValue) + abs(modelValue.getValue())) / 2);
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ import ru.ulstu.datamodel.Model;
|
|||||||
import ru.ulstu.datamodel.ModelingResult;
|
import ru.ulstu.datamodel.ModelingResult;
|
||||||
import ru.ulstu.datamodel.exception.ModelingException;
|
import ru.ulstu.datamodel.exception.ModelingException;
|
||||||
import ru.ulstu.datamodel.ts.TimeSeries;
|
import ru.ulstu.datamodel.ts.TimeSeries;
|
||||||
|
import ru.ulstu.datamodel.ts.TimeSeriesValue;
|
||||||
import ru.ulstu.method.Method;
|
import ru.ulstu.method.Method;
|
||||||
import ru.ulstu.method.MethodParamValue;
|
import ru.ulstu.method.MethodParamValue;
|
||||||
import ru.ulstu.method.MethodParameter;
|
import ru.ulstu.method.MethodParameter;
|
||||||
@ -18,6 +19,7 @@ import ru.ulstu.score.ScoreMethod;
|
|||||||
import ru.ulstu.score.Smape;
|
import ru.ulstu.score.Smape;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -47,6 +49,10 @@ public class MethodParamBruteForce {
|
|||||||
final int countPoints = (countPointsForecast > timeSeries.getLength()) ? timeSeries.getLength() / 3 : countPointsForecast;
|
final int countPoints = (countPointsForecast > timeSeries.getLength()) ? timeSeries.getLength() / 3 : countPointsForecast;
|
||||||
TimeSeries reducedTimeSeries = new TimeSeries(timeSeries.getValues().stream().limit(timeSeries.getLength() - countPoints).collect(Collectors.toList()),
|
TimeSeries reducedTimeSeries = new TimeSeries(timeSeries.getValues().stream().limit(timeSeries.getLength() - countPoints).collect(Collectors.toList()),
|
||||||
"test part of " + timeSeries.getName());
|
"test part of " + timeSeries.getName());
|
||||||
|
|
||||||
|
Map<LocalDateTime, Double> tsValues = timeSeries.getValues().stream()
|
||||||
|
.collect(Collectors.toMap(TimeSeriesValue::getDate, TimeSeriesValue::getValue));
|
||||||
|
|
||||||
for (Method method : methods) {
|
for (Method method : methods) {
|
||||||
List<List<MethodParamValue>> availableParametersValues = getAvailableParametersValues(method.getAvailableParameters());
|
List<List<MethodParamValue>> availableParametersValues = getAvailableParametersValues(method.getAvailableParameters());
|
||||||
for (List<MethodParamValue> parametersValues : availableParametersValues) {
|
for (List<MethodParamValue> parametersValues : availableParametersValues) {
|
||||||
@ -56,7 +62,7 @@ public class MethodParamBruteForce {
|
|||||||
TimeSeries forecast = methodInstance.getForecast(reducedTimeSeries, parametersValues, countPoints);
|
TimeSeries forecast = methodInstance.getForecast(reducedTimeSeries, parametersValues, countPoints);
|
||||||
return new ModelingResult(forecast,
|
return new ModelingResult(forecast,
|
||||||
parametersValues,
|
parametersValues,
|
||||||
scoreMethod.getScore(timeSeries, forecast),
|
scoreMethod.getScore(tsValues, forecast),
|
||||||
methodInstance);
|
methodInstance);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
@ -87,6 +93,10 @@ public class MethodParamBruteForce {
|
|||||||
public ModelingResult getSmoothedTimeSeries(TimeSeries timeSeries) throws ExecutionException, InterruptedException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
|
public ModelingResult getSmoothedTimeSeries(TimeSeries timeSeries) throws ExecutionException, InterruptedException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
|
||||||
List<Future<ModelingResult>> results = new ArrayList<>();
|
List<Future<ModelingResult>> results = new ArrayList<>();
|
||||||
List<ModelingResult> results2 = new CopyOnWriteArrayList<>();
|
List<ModelingResult> results2 = new CopyOnWriteArrayList<>();
|
||||||
|
|
||||||
|
Map<LocalDateTime, Double> tsValues = timeSeries.getValues().stream()
|
||||||
|
.collect(Collectors.toMap(TimeSeriesValue::getDate, TimeSeriesValue::getValue));
|
||||||
|
|
||||||
for (Method method : methods) {
|
for (Method method : methods) {
|
||||||
List<List<MethodParamValue>> availableParametersValues = getAvailableParametersValues(method.getAvailableParameters());
|
List<List<MethodParamValue>> availableParametersValues = getAvailableParametersValues(method.getAvailableParameters());
|
||||||
for (List<MethodParamValue> parametersValues : availableParametersValues) {
|
for (List<MethodParamValue> parametersValues : availableParametersValues) {
|
||||||
@ -96,7 +106,7 @@ public class MethodParamBruteForce {
|
|||||||
Model model = methodInstance.getModel(timeSeries, parametersValues);
|
Model model = methodInstance.getModel(timeSeries, parametersValues);
|
||||||
return new ModelingResult(model.getTimeSeriesModel(),
|
return new ModelingResult(model.getTimeSeriesModel(),
|
||||||
parametersValues,
|
parametersValues,
|
||||||
scoreMethod.getScore(timeSeries, model.getTimeSeriesModel()),
|
scoreMethod.getScore(tsValues, model.getTimeSeriesModel()),
|
||||||
methodInstance);
|
methodInstance);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user