add AnomalyCompressionScore

This commit is contained in:
Антон Скалкин 2023-04-07 00:09:49 +04:00
parent 259ca3757e
commit cb52a2cce6

View File

@ -0,0 +1,32 @@
package ru.ulstu.score;
import org.springframework.stereotype.Component;
import ru.ulstu.datamodel.exception.ModelingException;
import ru.ulstu.datamodel.ts.TimeSeries;
import ru.ulstu.datamodel.ts.TimeSeriesValue;
import ru.ulstu.target.AnomalyDifferenceSmoothed;
import java.lang.reflect.InvocationTargetException;
import java.time.LocalDateTime;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import static java.lang.Math.abs;
@Component
public class AnomalyCompressionScore extends ScoreMethod {
private final AnomalyDifferenceSmoothed anomalyDifferenceSmoothed;
public AnomalyCompressionScore(AnomalyDifferenceSmoothed anomalyDifferenceSmoothed) {
super("Smape, %");
this.anomalyDifferenceSmoothed = anomalyDifferenceSmoothed;
}
@Override
public Number evaluate(Map<LocalDateTime, Double> tsValues, TimeSeries model) throws ModelingException, ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
var timeSeriesAnomalyResult = anomalyDifferenceSmoothed.calculate(model);
var timeSeriesAnomaly = anomalyDifferenceSmoothed.calculate(tsValues);
// туду: добавить сравнение аномальных точек
return model.getLength()/tsValues.size() + Math.abs(timeSeriesAnomaly.getLength() - timeSeriesAnomalyResult.getLength());
}
}