mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-13 22:15:26 +00:00
Improved exception handling
This commit is contained in:
1 parent
2f60c38e96
commit
846e91fcba
24 files changed
+148
-33
No files matched your search
+1
-1
@@ -21,7 +21,7 @@ public class SimpleConfigurableManeuverBasedWindEstimationComponentImpl extends
|
||||
|
||||
private static final int MODEL_CACHE_KEEP_ALIVE_MILLIS = 3600000;
|
||||
private static final HmmTransitionProbabilitiesCalculator transitionProbabilitiesCalculatorType = HmmTransitionProbabilitiesCalculator.INTERSECTED;
|
||||
private static final boolean propagateIntersectedWindRangeOfHeadupAndBearAway = true;
|
||||
private static final boolean propagateIntersectedWindRangeOfHeadupAndBearAway = false;
|
||||
|
||||
public SimpleConfigurableManeuverBasedWindEstimationComponentImpl(ManeuverFeatures maneuverFeatures,
|
||||
ModelStore modelStore, PolarDataService polarService,
|
||||
|
||||
+2
-1
@@ -16,6 +16,7 @@ import com.sap.sailing.polars.windestimation.ScalableBearingAndScalableDouble;
|
||||
import com.sap.sailing.windestimation.data.CompetitorTrackWithEstimationData;
|
||||
import com.sap.sailing.windestimation.data.RaceWithEstimationData;
|
||||
import com.sap.sailing.windestimation.model.classifier.maneuver.ManeuverWithProbabilisticTypeClassification;
|
||||
import com.sap.sailing.windestimation.model.exception.ModelOperationException;
|
||||
import com.sap.sse.common.Bearing;
|
||||
import com.sap.sse.common.Speed;
|
||||
import com.sap.sse.common.Util.Pair;
|
||||
@@ -111,7 +112,7 @@ public class ManeuverClusteringBasedWindEstimationTrackImpl extends AbstractMane
|
||||
result = Math.min(1.0, averageJibeLikelihood
|
||||
* (1.0 + BOOST_FACTOR_FOR_JIBE_TACK_SPEED_RATIO_LIKELIHOOD * tackJibeSpeedRatioLikelihood));
|
||||
} else {
|
||||
throw new RuntimeException(
|
||||
throw new ModelOperationException(
|
||||
"Internal error: no maneuvers in jibe cluster candidate but still a valid weighted average speed "
|
||||
+ jibeClusterWeightedAverageSpeed);
|
||||
}
|
||||
|
||||
+7
-1
@@ -4,6 +4,9 @@ import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import com.sap.sailing.windestimation.model.exception.ModelLoadingException;
|
||||
import com.sap.sailing.windestimation.model.exception.ModelNotFoundException;
|
||||
import com.sap.sailing.windestimation.model.exception.ModelPersistenceException;
|
||||
import com.sap.sailing.windestimation.model.store.ModelStore;
|
||||
|
||||
public class ModelLoader<InstanceType, T extends ContextSpecificModelMetadata<InstanceType>, ModelType extends TrainableModel<InstanceType, T>> {
|
||||
@@ -24,10 +27,13 @@ public class ModelLoader<InstanceType, T extends ContextSpecificModelMetadata<In
|
||||
ModelType model = modelFactory.getNewModel(modelMetadata);
|
||||
try {
|
||||
model = modelStore.loadPersistedState(model);
|
||||
if (model != null && model.hasSupportForProvidedFeatures()) {
|
||||
if (model.hasSupportForProvidedFeatures()) {
|
||||
loadedModels.add(model);
|
||||
}
|
||||
} catch (ModelNotFoundException e) {
|
||||
// ignore, because no model might be available for the specified model metadata
|
||||
} catch (ModelPersistenceException e) {
|
||||
throw new ModelLoadingException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
@@ -2,6 +2,7 @@ package com.sap.sailing.windestimation.model.classifier;
|
||||
|
||||
import com.sap.sailing.windestimation.model.AbstractModelCache;
|
||||
import com.sap.sailing.windestimation.model.ContextSpecificModelMetadata;
|
||||
import com.sap.sailing.windestimation.model.exception.ModelLoadingException;
|
||||
import com.sap.sailing.windestimation.model.store.ModelStore;
|
||||
|
||||
public abstract class AbstractClassifiersCache<InstanceType, T extends ContextSpecificModelMetadata<InstanceType>, ClassificationResultType>
|
||||
@@ -19,6 +20,9 @@ public abstract class AbstractClassifiersCache<InstanceType, T extends ContextSp
|
||||
public ClassificationResultType classifyInstance(InstanceType instance) {
|
||||
T modelMetadata = getContextSpecificModelMetadata(instance);
|
||||
TrainableClassificationModel<InstanceType, T> bestClassifierModel = getBestModel(modelMetadata);
|
||||
if (bestClassifierModel == null) {
|
||||
throw new ModelLoadingException("No model available for: " + modelMetadata);
|
||||
}
|
||||
double[] likelihoods = bestClassifierModel.classifyWithProbabilities(instance);
|
||||
ClassificationResultType result = classificationResultMapper.mapToClassificationResult(likelihoods, instance,
|
||||
modelMetadata);
|
||||
|
||||
+2
-5
@@ -84,8 +84,6 @@ public class ManeuverClassifierModelMetadata extends ContextSpecificModelMetadat
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
ManeuverClassifierModelMetadata other = (ManeuverClassifierModelMetadata) obj;
|
||||
if (boatClass == null) {
|
||||
if (other.boatClass != null)
|
||||
@@ -119,7 +117,7 @@ public class ManeuverClassifierModelMetadata extends ContextSpecificModelMetadat
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public int getOtherTypes() {
|
||||
return otherTypes;
|
||||
}
|
||||
@@ -133,7 +131,6 @@ public class ManeuverClassifierModelMetadata extends ContextSpecificModelMetadat
|
||||
inputVector[i++] = maneuver.getLowestSpeedVsExitingSpeedRatio();
|
||||
inputVector[i++] = maneuver.getSpeedGainRatio();
|
||||
inputVector[i++] = maneuver.getMaxTurningRateInDegreesPerSecond();
|
||||
inputVector[i++] = maneuver.getSpeedWithBearingBefore().getMetersPerSecond() / maneuver.getSpeedWithBearingAfter().getMetersPerSecond();
|
||||
if (maneuverFeatures.isPolarsInformation()) {
|
||||
inputVector[i++] = maneuver.getDeviationFromOptimalTackAngleInDegrees();
|
||||
inputVector[i++] = maneuver.getDeviationFromOptimalJibeAngleInDegrees();
|
||||
@@ -150,7 +147,7 @@ public class ManeuverClassifierModelMetadata extends ContextSpecificModelMetadat
|
||||
|
||||
@Override
|
||||
public int getNumberOfInputFeatures() {
|
||||
int numberOfFeatures = 6;
|
||||
int numberOfFeatures = 5;
|
||||
if (maneuverFeatures.isPolarsInformation()) {
|
||||
numberOfFeatures += 2;
|
||||
}
|
||||
|
||||
+3
-2
@@ -9,6 +9,7 @@ public class NeuralNetworkClassifier<InstanceType, T extends ContextSpecificMode
|
||||
extends AbstractSmileClassificationModel<InstanceType, T> {
|
||||
|
||||
private static final long serialVersionUID = -3364152319152090775L;
|
||||
private static final int EPOCHS = 20;
|
||||
|
||||
public NeuralNetworkClassifier(T contextSpecificModelMetadata) {
|
||||
super(new PreprocessingConfigBuilder().scaling().build(), contextSpecificModelMetadata);
|
||||
@@ -29,12 +30,12 @@ public class NeuralNetworkClassifier<InstanceType, T extends ContextSpecificMode
|
||||
numUnits);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 20; i++) {
|
||||
for (int i = 0; i < EPOCHS; i++) {
|
||||
net.learn(x, y);
|
||||
}
|
||||
return net;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public double[] classifyWithProbabilities(double[] x) {
|
||||
int k = getContextSpecificModelMetadata().getNumberOfPossibleTargetValues();
|
||||
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package com.sap.sailing.windestimation.model.exception;
|
||||
|
||||
public class ModelLoadingException extends ModelRuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 9129472285700533042L;
|
||||
|
||||
public ModelLoadingException() {
|
||||
}
|
||||
|
||||
public ModelLoadingException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ModelLoadingException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public ModelLoadingException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public ModelLoadingException(String message, Throwable cause, boolean enableSuppression,
|
||||
boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.sap.sailing.windestimation.model.exception;
|
||||
|
||||
import com.sap.sailing.windestimation.model.ContextSpecificModelMetadata;
|
||||
|
||||
public class ModelNotFoundException extends ModelPersistenceException {
|
||||
|
||||
private static final long serialVersionUID = 2426127713965713226L;
|
||||
private final ContextSpecificModelMetadata<?> modelMetadata;
|
||||
|
||||
public ModelNotFoundException(ContextSpecificModelMetadata<?> modelMetadata) {
|
||||
this.modelMetadata = modelMetadata;
|
||||
}
|
||||
|
||||
public ModelNotFoundException(ContextSpecificModelMetadata<?> modelMetadata, Throwable e) {
|
||||
super(e);
|
||||
this.modelMetadata = modelMetadata;
|
||||
}
|
||||
|
||||
public ContextSpecificModelMetadata<?> getModelMetadata() {
|
||||
return modelMetadata;
|
||||
}
|
||||
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package com.sap.sailing.windestimation.model.exception;
|
||||
|
||||
public class ModelOperationException extends ModelRuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 7308703386832127467L;
|
||||
|
||||
public ModelOperationException() {
|
||||
}
|
||||
|
||||
public ModelOperationException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ModelOperationException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public ModelOperationException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public ModelOperationException(String message, Throwable cause, boolean enableSuppression,
|
||||
boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.sap.sailing.windestimation.model;
|
||||
package com.sap.sailing.windestimation.model.exception;
|
||||
|
||||
public class ModelPersistenceException extends Exception {
|
||||
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package com.sap.sailing.windestimation.model.exception;
|
||||
|
||||
public class ModelRuntimeException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 170716968865186247L;
|
||||
|
||||
public ModelRuntimeException() {
|
||||
}
|
||||
|
||||
public ModelRuntimeException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ModelRuntimeException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public ModelRuntimeException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public ModelRuntimeException(String message, Throwable cause, boolean enableSuppression,
|
||||
boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
|
||||
}
|
||||
+4
-3
@@ -6,6 +6,7 @@ import com.sap.sailing.domain.polars.NotEnoughDataHasBeenAddedException;
|
||||
import com.sap.sailing.polars.regression.IncrementalLeastSquares;
|
||||
import com.sap.sailing.polars.regression.impl.IncrementalAnyOrderLeastSquaresImpl;
|
||||
import com.sap.sailing.windestimation.model.ContextSpecificModelMetadata;
|
||||
import com.sap.sailing.windestimation.model.exception.ModelOperationException;
|
||||
|
||||
public class IncrementalSingleDimensionPolynomialRegressor<InstanceType, T extends ContextSpecificModelMetadata<InstanceType>>
|
||||
extends AbstractRegressorModel<InstanceType, T>
|
||||
@@ -35,7 +36,7 @@ public class IncrementalSingleDimensionPolynomialRegressor<InstanceType, T exten
|
||||
try {
|
||||
polynomialFunction = regression.getOrCreatePolynomialFunction();
|
||||
} catch (NotEnoughDataHasBeenAddedException e) {
|
||||
throw new RuntimeException(e);
|
||||
throw new ModelOperationException(e);
|
||||
}
|
||||
double value = polynomialFunction.value(x[0]);
|
||||
return value;
|
||||
@@ -46,7 +47,7 @@ public class IncrementalSingleDimensionPolynomialRegressor<InstanceType, T exten
|
||||
try {
|
||||
polynomialFunction = regression.getOrCreatePolynomialFunction();
|
||||
} catch (NotEnoughDataHasBeenAddedException e) {
|
||||
throw new RuntimeException(e);
|
||||
throw new ModelOperationException(e);
|
||||
}
|
||||
double value = polynomialFunction.value(x);
|
||||
return value;
|
||||
@@ -71,7 +72,7 @@ public class IncrementalSingleDimensionPolynomialRegressor<InstanceType, T exten
|
||||
polynomialFunction = regression.getOrCreatePolynomialFunction();
|
||||
return polynomialFunction.toString();
|
||||
} catch (NotEnoughDataHasBeenAddedException e) {
|
||||
throw new RuntimeException(e);
|
||||
throw new ModelOperationException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -7,8 +7,9 @@ import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
|
||||
import com.sap.sailing.windestimation.model.ContextSpecificModelMetadata;
|
||||
import com.sap.sailing.windestimation.model.ModelPersistenceException;
|
||||
import com.sap.sailing.windestimation.model.TrainableModel;
|
||||
import com.sap.sailing.windestimation.model.exception.ModelNotFoundException;
|
||||
import com.sap.sailing.windestimation.model.exception.ModelPersistenceException;
|
||||
|
||||
public class FileSystemModelStore implements ModelStore {
|
||||
|
||||
@@ -55,7 +56,7 @@ public class FileSystemModelStore implements ModelStore {
|
||||
throw new ModelPersistenceException(e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
throw new ModelNotFoundException(newModel.getContextSpecificModelMetadata());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -1,8 +1,8 @@
|
||||
package com.sap.sailing.windestimation.model.store;
|
||||
|
||||
import com.sap.sailing.windestimation.model.ContextSpecificModelMetadata;
|
||||
import com.sap.sailing.windestimation.model.ModelPersistenceException;
|
||||
import com.sap.sailing.windestimation.model.TrainableModel;
|
||||
import com.sap.sailing.windestimation.model.exception.ModelPersistenceException;
|
||||
|
||||
public interface ModelStore {
|
||||
<T extends PersistableModel<?, ?>> void persistState(T trainedModel) throws ModelPersistenceException;
|
||||
|
||||
+3
-2
@@ -8,8 +8,9 @@ import com.mongodb.client.gridfs.GridFSBucket;
|
||||
import com.mongodb.client.gridfs.GridFSBuckets;
|
||||
import com.mongodb.client.gridfs.GridFSDownloadStream;
|
||||
import com.sap.sailing.windestimation.model.ContextSpecificModelMetadata;
|
||||
import com.sap.sailing.windestimation.model.ModelPersistenceException;
|
||||
import com.sap.sailing.windestimation.model.TrainableModel;
|
||||
import com.sap.sailing.windestimation.model.exception.ModelNotFoundException;
|
||||
import com.sap.sailing.windestimation.model.exception.ModelPersistenceException;
|
||||
|
||||
public class MongoDbModelStore implements ModelStore {
|
||||
|
||||
@@ -43,7 +44,7 @@ public class MongoDbModelStore implements ModelStore {
|
||||
}
|
||||
return loadedModel;
|
||||
} catch (MongoException e) {
|
||||
throw new ModelPersistenceException(e);
|
||||
throw new ModelNotFoundException(newModel.getContextSpecificModelMetadata(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ package com.sap.sailing.windestimation.model.store;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import com.sap.sailing.windestimation.model.ModelPersistenceException;
|
||||
import com.sap.sailing.windestimation.model.exception.ModelPersistenceException;
|
||||
|
||||
public interface PersistenceSupport {
|
||||
String getPersistenceKey();
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ import java.io.ObjectOutputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import com.sap.sailing.domain.base.DomainFactory;
|
||||
import com.sap.sailing.windestimation.model.ModelPersistenceException;
|
||||
import com.sap.sailing.windestimation.model.exception.ModelPersistenceException;
|
||||
|
||||
public class SerializationBasedPersistenceSupport implements PersistenceSupport {
|
||||
|
||||
|
||||
Reference in new issue
Block a user