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