java/com.sap.sailing.domain.common/src/com/sap/sailing/domain/common/confidence/BearingWithConfidence.java
... ...
@@ -2,6 +2,7 @@ package com.sap.sailing.domain.common.confidence;
2 2
3 3
import com.sap.sailing.domain.common.DoublePair;
4 4
import com.sap.sse.common.Bearing;
5
+import com.sap.sse.common.scalablevalue.HasConfidenceAndIsScalable;
5 6
6 7
7 8
public interface BearingWithConfidence<RelativeTo> extends HasConfidenceAndIsScalable<DoublePair, Bearing, RelativeTo> {
java/com.sap.sailing.domain.common/src/com/sap/sailing/domain/common/confidence/BearingWithConfidenceCluster.java
... ...
@@ -8,6 +8,7 @@ import com.sap.sailing.domain.common.DoublePair;
8 8
import com.sap.sailing.domain.common.confidence.impl.BearingWithConfidenceImpl;
9 9
import com.sap.sse.common.Bearing;
10 10
import com.sap.sse.common.Util;
11
+import com.sap.sse.common.scalablevalue.HasConfidence;
11 12
12 13
/**
13 14
* Contains a number of {@link Bearing} objects and maintains the average bearing. For a given {@link Bearing} it
java/com.sap.sailing.domain.common/src/com/sap/sailing/domain/common/confidence/ConfidenceBasedAverager.java
... ...
@@ -2,6 +2,9 @@ package com.sap.sailing.domain.common.confidence;
2 2
3 3
import java.util.Iterator;
4 4
5
+import com.sap.sse.common.scalablevalue.HasConfidence;
6
+import com.sap.sse.common.scalablevalue.HasConfidenceAndIsScalable;
7
+
5 8
public interface ConfidenceBasedAverager<ValueType, BaseType, RelativeTo> {
6 9
/**
7 10
* If a non-<code>null</code> weigher has been set for this averager, <code>at</code> must be a valid reference
java/com.sap.sailing.domain.common/src/com/sap/sailing/domain/common/confidence/HasConfidence.java
... ...
@@ -1,91 +0,0 @@
1
-package com.sap.sailing.domain.common.confidence;
2
-
3
-import java.io.Serializable;
4
-
5
-import com.sap.sse.common.Distance;
6
-import com.sap.sse.common.TimePoint;
7
-import com.sap.sse.common.scalablevalue.ScalableValue;
8
-
9
-/**
10
- * Some values, particularly those obtained from real-world measurements, are not always accurate. Some values are
11
- * derived by interpolating or extrapolating data series obtained through measurement or even estimation. Some values
12
- * are simply guessed by humans and entered into the system.
13
- * <p>
14
- *
15
- * All those values have a certain level of confidence. In case multiple sources of information about the same entity or
16
- * phenomenon are available, knowing the confidence of each value helps in weighing and averaging these values more
17
- * properly than would be possible without a confidence value.
18
- * <p>
19
- *
20
- * In simple cases, the type used to compute a weighed average over the things equipped with a confidence level is the
21
- * same as the type of the things themselves. In particular, this is the case for scalar types such as {@link Double}
22
- * and {@link Distance}. For non-scalar values, averaging may be non-trivial. For example, averaging a bearing cannot
23
- * simply happen by computing the arithmetic average of the bearing's angles. Instead, an intermediate structure
24
- * providing the sinus and cosinus values of the bearing's angle is used to compute the weighed average tangens.
25
- * <p>
26
- *
27
- * Generally, the relationship between the type implementing this interface, the <code>ValueType</code> and the
28
- * <code>AveragesTo</code> type is this: an instance of the implementing type can transform itself into a
29
- * {@link ScalableValue} which is then used for computing a weighed sum. The values' weight is their
30
- * {@link #getConfidence() confidence}. The sum (which is still a {@link ScalableValue} because
31
- * {@link ScalableValue#add(ScalableValue)} returns again a {@link ScalableValue}) is then
32
- * {@link ScalableValue#divide(double) divided} by the sum of the confidences. This "division" is expected to
33
- * produce an object of type <code>AveragesTo</code>. Usually, <code>AveragesTo</code> would be the same as the class
34
- * implementing this interface.
35
- *
36
- * @author Axel Uhl (d043530)
37
- *
38
- * @param <ValueType>
39
- * the type of the scalable value used for scalar operations during aggregation
40
- * @param <RelativeTo>
41
- * the type of the object relative to which the confidence applies; for example, if the
42
- * base type is a position and the <code>RelativeTo</code> type is {@link TimePoint},
43
- * the confidence of the position is relative to a certain time point. Together with
44
- * a correspondingly-typed weigher, such a value with confidence can be aggregated with
45
- * other values, again relative to (maybe a different) time point.
46
- */
47
-public interface HasConfidence<ValueType, BaseType, RelativeTo> extends Serializable {
48
- /**
49
- * A confidence is a number between 0.0 and 1.0 (inclusive) where 0.0 means that the value is randomly guessed while
50
- * 1.0 means the value is authoritatively known for a fact. It represents the weight with which a value is to be
51
- * considered by averaging, interpolation and extrapolation algorithms.
52
- * <p>
53
- *
54
- * An averaging algorithm for a sequence of <code>n</code> tuples <code>(v1, c1), ..., (vn, cn)</code> of a value
55
- * <code>vi</code> with a confidence <code>ci</code> each can for example look like this:
56
- * <code>a := (c1*v1 + ... + cn*vn) / (c1 + ... + cn)</code>. For a single value with a confidence this trivially
57
- * results in <code>c1*v1 / (c1)</code> which is equivalent to <code>v1</code>. As another example, consider two
58
- * values with equal confidence <code>0.8</code>. Then, <code>a := (0.8*v1 + 0.8*vn) / (0.8 + 0.8)</code> which
59
- * resolves to <code>0.5*v1 + 0.5*v2</code> which is obviously the arithmetic mean of the two values. If one value
60
- * has confidence <code>0.8</code> and the other <code>0.4</code>, then
61
- * <code>a := (0.8*v1 + 0.4*vn) / (0.8 + 0.4)</code> which resolves to <code>2/3*v1 + 1/3*v2</code> which is a
62
- * weighed average.
63
- * <p>
64
- *
65
- * Note, that this doesn't exactly take facts for facts. In other words, if one value is provided with a confidence
66
- * of <code>1.0</code>, the average may still be influenced by other values. However, this cleanly resolves otherwise
67
- * mutually contradictory "facts" such a <code>(v1, 1.0), (v2, 1.0)</code> with <code>v1 != v2</code>. It is
68
- * considered bad practice to claim a fact as soon as it results from any kind of measurement or estimation. All
69
- * measurement devices produce some statistical errors, no matter how small (cf. Heisenberg ;-) ).
70
- */
71
- double getConfidence();
72
-
73
- /**
74
- * The confidence attached to a value is usually relative to some reference point, such as a time point or
75
- * a position. For example, when a <code>GPSFixTrack</code> is asked to deliver an estimation for the tracked item's
76
- * {@link Position} at some given {@link TimePoint}, the track computes some average from a number of GPS fixes. The resulting
77
- * position has a certain confidence, depending on the time differences between the fixes and the time point for which
78
- * the position estimation was requested. The result therefore carries this reference time point for which the estimation
79
- * was requested so that when the result is to be used in further estimations it is clear relative to which time point the
80
- * confidence is to be interpreted.<p>
81
- *
82
- * In this context, a single GPS fix is a measurement whose values may also have a confidence attached. This confidence could be
83
- * regarded as relative to the fix's time point.
84
- */
85
- RelativeTo getRelativeTo();
86
-
87
- /**
88
- * The object annotated by a confidence
89
- */
90
- BaseType getObject();
91
-}
java/com.sap.sailing.domain.common/src/com/sap/sailing/domain/common/confidence/HasConfidenceAndIsScalable.java
... ...
@@ -1,7 +0,0 @@
1
-package com.sap.sailing.domain.common.confidence;
2
-
3
-import com.sap.sse.common.scalablevalue.IsScalable;
4
-
5
-public interface HasConfidenceAndIsScalable<ValueType, BaseType, RelativeTo> extends IsScalable<ValueType, BaseType>,
6
- HasConfidence<ValueType, BaseType, RelativeTo> {
7
-}
java/com.sap.sailing.domain.common/src/com/sap/sailing/domain/common/confidence/impl/ConfidenceBasedAveragerImpl.java
... ...
@@ -3,9 +3,9 @@ package com.sap.sailing.domain.common.confidence.impl;
3 3
import java.util.Iterator;
4 4
5 5
import com.sap.sailing.domain.common.confidence.ConfidenceBasedAverager;
6
-import com.sap.sailing.domain.common.confidence.HasConfidence;
7
-import com.sap.sailing.domain.common.confidence.HasConfidenceAndIsScalable;
8 6
import com.sap.sailing.domain.common.confidence.Weigher;
7
+import com.sap.sse.common.scalablevalue.HasConfidence;
8
+import com.sap.sse.common.scalablevalue.HasConfidenceAndIsScalable;
9 9
import com.sap.sse.common.scalablevalue.ScalableValue;
10 10
11 11
java/com.sap.sailing.domain.common/src/com/sap/sailing/domain/common/confidence/impl/HasConfidenceImpl.java
... ...
@@ -1,6 +1,6 @@
1 1
package com.sap.sailing.domain.common.confidence.impl;
2 2
3
-import com.sap.sailing.domain.common.confidence.HasConfidence;
3
+import com.sap.sse.common.scalablevalue.HasConfidence;
4 4
5 5
public class HasConfidenceImpl<ValueType, BaseType, RelativeTo> implements HasConfidence<ValueType, BaseType, RelativeTo> {
6 6
private static final long serialVersionUID = -1635823148449693024L;
java/com.sap.sailing.domain.common/src/com/sap/sailing/domain/common/confidence/impl/ScalableDouble.java
... ...
@@ -1,47 +0,0 @@
1
-package com.sap.sailing.domain.common.confidence.impl;
2
-
3
-import com.sap.sse.common.scalablevalue.AbstractScalarValue;
4
-import com.sap.sse.common.scalablevalue.ScalableValue;
5
-
6
-public class ScalableDouble implements AbstractScalarValue<Double> {
7
- private final double value;
8
-
9
- public ScalableDouble(double value) {
10
- this.value = value;
11
- }
12
-
13
- @Override
14
- public ScalableDouble multiply(double factor) {
15
- return new ScalableDouble(factor*getValue());
16
- }
17
-
18
- @Override
19
- public ScalableDouble add(ScalableValue<Double, Double> t) {
20
- return new ScalableDouble(getValue()+t.getValue());
21
- }
22
-
23
- @Override
24
- public Double divide(double divisor) {
25
- return getValue()/divisor;
26
- }
27
-
28
- @Override
29
- public Double getValue() {
30
- return value;
31
- }
32
-
33
- @Override
34
- public double getDistance(Double other) {
35
- return Math.abs(value-other);
36
- }
37
-
38
- @Override
39
- public String toString() {
40
- return Double.valueOf(value).toString();
41
- }
42
-
43
- @Override
44
- public int compareTo(Double o) {
45
- return Double.valueOf(value).compareTo(o);
46
- }
47
-}
java/com.sap.sailing.domain.common/src/com/sap/sailing/domain/common/confidence/impl/ScalableDoubleWithConfidence.java
... ...
@@ -1,35 +0,0 @@
1
-package com.sap.sailing.domain.common.confidence.impl;
2
-
3
-import com.sap.sailing.domain.common.confidence.HasConfidenceAndIsScalable;
4
-
5
-public class ScalableDoubleWithConfidence<RelativeTo> extends ScalableDouble implements HasConfidenceAndIsScalable<Double, Double, RelativeTo> {
6
- private static final long serialVersionUID = 1042652394404557792L;
7
- private final double confidence;
8
- private final RelativeTo relativeTo;
9
-
10
- public ScalableDoubleWithConfidence(double d, double confidence, RelativeTo relativeTo) {
11
- super(d);
12
- this.confidence = confidence;
13
- this.relativeTo = relativeTo;
14
- }
15
-
16
- @Override
17
- public Double getObject() {
18
- return getValue();
19
- }
20
-
21
- @Override
22
- public RelativeTo getRelativeTo() {
23
- return relativeTo;
24
- }
25
-
26
- @Override
27
- public double getConfidence() {
28
- return confidence;
29
- }
30
-
31
- @Override
32
- public ScalableDouble getScalableValue() {
33
- return this;
34
- }
35
-}
java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/BearingTest.java
... ...
@@ -16,13 +16,13 @@ import com.sap.sailing.domain.common.confidence.BearingWithConfidence;
16 16
import com.sap.sailing.domain.common.confidence.BearingWithConfidenceCluster;
17 17
import com.sap.sailing.domain.common.confidence.ConfidenceBasedAverager;
18 18
import com.sap.sailing.domain.common.confidence.ConfidenceFactory;
19
-import com.sap.sailing.domain.common.confidence.HasConfidence;
20 19
import com.sap.sailing.domain.common.confidence.impl.BearingWithConfidenceImpl;
21 20
import com.sap.sailing.domain.common.impl.DegreePosition;
22 21
import com.sap.sailing.domain.common.impl.RadianBearingImpl;
23 22
import com.sap.sailing.domain.common.scalablevalue.impl.ScalablePosition;
24 23
import com.sap.sse.common.Bearing;
25 24
import com.sap.sse.common.impl.DegreeBearingImpl;
25
+import com.sap.sse.common.scalablevalue.HasConfidence;
26 26
27 27
public class BearingTest {
28 28
@Test
java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/ConfidenceTest.java
... ...
@@ -18,11 +18,8 @@ import com.sap.sailing.domain.common.Wind;
18 18
import com.sap.sailing.domain.common.confidence.BearingWithConfidence;
19 19
import com.sap.sailing.domain.common.confidence.BearingWithConfidenceCluster;
20 20
import com.sap.sailing.domain.common.confidence.ConfidenceBasedAverager;
21
-import com.sap.sailing.domain.common.confidence.HasConfidence;
22
-import com.sap.sailing.domain.common.confidence.HasConfidenceAndIsScalable;
23 21
import com.sap.sailing.domain.common.confidence.Weigher;
24 22
import com.sap.sailing.domain.common.confidence.impl.BearingWithConfidenceImpl;
25
-import com.sap.sailing.domain.common.confidence.impl.ScalableDoubleWithConfidence;
26 23
import com.sap.sailing.domain.common.confidence.impl.ScalableWind;
27 24
import com.sap.sailing.domain.common.impl.DegreePosition;
28 25
import com.sap.sailing.domain.common.impl.KnotSpeedWithBearingImpl;
... ...
@@ -39,6 +36,9 @@ import com.sap.sse.common.Bearing;
39 36
import com.sap.sse.common.TimePoint;
40 37
import com.sap.sse.common.impl.DegreeBearingImpl;
41 38
import com.sap.sse.common.impl.MillisecondsTimePoint;
39
+import com.sap.sse.common.scalablevalue.HasConfidence;
40
+import com.sap.sse.common.scalablevalue.HasConfidenceAndIsScalable;
41
+import com.sap.sse.common.scalablevalue.ScalableDoubleWithConfidence;
42 42
import com.sap.sse.common.scalablevalue.ScalableValue;
43 43
44 44
public class ConfidenceTest {
java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/KMeansTest.java
... ...
@@ -13,7 +13,7 @@ import java.util.Set;
13 13
import org.junit.jupiter.api.Test;
14 14
15 15
import com.sap.sailing.domain.base.ScalableInteger;
16
-import com.sap.sailing.domain.common.confidence.impl.ScalableDouble;
16
+import com.sap.sse.common.scalablevalue.ScalableDouble;
17 17
import com.sap.sse.util.kmeans.Cluster;
18 18
import com.sap.sse.util.kmeans.KMeansClusterer;
19 19
import com.sap.sse.util.kmeans.KMeansClustererWithEquidistantInitialization;
java/com.sap.sailing.domain/src/com/sap/sailing/domain/base/PositionWithConfidence.java
... ...
@@ -1,8 +1,8 @@
1 1
package com.sap.sailing.domain.base;
2 2
3 3
import com.sap.sailing.domain.common.Position;
4
-import com.sap.sailing.domain.common.confidence.HasConfidenceAndIsScalable;
5 4
import com.sap.sailing.domain.common.scalablevalue.impl.ScalablePosition;
5
+import com.sap.sse.common.scalablevalue.HasConfidenceAndIsScalable;
6 6
7 7
/**
8 8
* A position with a confidence attached. The scalable intermediate type represents the x/y/z coordinate of the
java/com.sap.sailing.domain/src/com/sap/sailing/domain/base/SpeedWithBearingWithConfidence.java
... ...
@@ -2,7 +2,7 @@ package com.sap.sailing.domain.base;
2 2
3 3
import com.sap.sailing.domain.common.DoubleTriple;
4 4
import com.sap.sailing.domain.common.SpeedWithBearing;
5
-import com.sap.sailing.domain.common.confidence.HasConfidence;
5
+import com.sap.sse.common.scalablevalue.HasConfidence;
6 6
7 7
public interface SpeedWithBearingWithConfidence<RelativeTo> extends
8 8
HasConfidence<DoubleTriple, SpeedWithBearing, RelativeTo> {
java/com.sap.sailing.domain/src/com/sap/sailing/domain/base/SpeedWithConfidence.java
... ...
@@ -1,7 +1,7 @@
1 1
package com.sap.sailing.domain.base;
2 2
3
-import com.sap.sailing.domain.common.confidence.HasConfidenceAndIsScalable;
4 3
import com.sap.sse.common.Speed;
4
+import com.sap.sse.common.scalablevalue.HasConfidenceAndIsScalable;
5 5
6 6
public interface SpeedWithConfidence<RelativeTo> extends HasConfidenceAndIsScalable<Double, Speed, RelativeTo> {
7 7
}
java/com.sap.sailing.domain/src/com/sap/sailing/domain/confidence/ConfidenceBasedWindAverager.java
... ...
@@ -2,9 +2,9 @@ package com.sap.sailing.domain.confidence;
2 2
3 3
import com.sap.sailing.domain.common.Wind;
4 4
import com.sap.sailing.domain.common.confidence.ConfidenceBasedAverager;
5
-import com.sap.sailing.domain.common.confidence.HasConfidenceAndIsScalable;
6 5
import com.sap.sailing.domain.common.confidence.impl.ScalableWind;
7 6
import com.sap.sailing.domain.tracking.WindWithConfidence;
7
+import com.sap.sse.common.scalablevalue.HasConfidenceAndIsScalable;
8 8
9 9
public interface ConfidenceBasedWindAverager<RelativeTo> extends ConfidenceBasedAverager<ScalableWind, Wind, RelativeTo>{
10 10
@Override
java/com.sap.sailing.domain/src/com/sap/sailing/domain/confidence/impl/ConfidenceBasedWindAveragerImpl.java
... ...
@@ -5,7 +5,6 @@ import java.util.Iterator;
5 5
import com.sap.sailing.domain.common.Wind;
6 6
import com.sap.sailing.domain.common.WindSource;
7 7
import com.sap.sailing.domain.common.WindSourceType;
8
-import com.sap.sailing.domain.common.confidence.HasConfidenceAndIsScalable;
9 8
import com.sap.sailing.domain.common.confidence.Weigher;
10 9
import com.sap.sailing.domain.common.confidence.impl.ConfidenceBasedAveragerImpl;
11 10
import com.sap.sailing.domain.common.confidence.impl.ScalableWind;
... ...
@@ -15,6 +14,7 @@ import com.sap.sailing.domain.confidence.ConfidenceBasedWindAverager;
15 14
import com.sap.sailing.domain.tracking.WindWithConfidence;
16 15
import com.sap.sailing.domain.tracking.impl.WindWithConfidenceImpl;
17 16
import com.sap.sse.common.Speed;
17
+import com.sap.sse.common.scalablevalue.HasConfidenceAndIsScalable;
18 18
19 19
/**
20 20
* In order to enable the aggregation of {@link Wind} objects whose {@link WindSource}'s {@link WindSourceType} suggests
java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/WindWithConfidence.java
... ...
@@ -2,9 +2,9 @@ package com.sap.sailing.domain.tracking;
2 2
3 3
import com.sap.sailing.domain.common.Position;
4 4
import com.sap.sailing.domain.common.Wind;
5
-import com.sap.sailing.domain.common.confidence.HasConfidenceAndIsScalable;
6 5
import com.sap.sailing.domain.common.confidence.impl.ScalableWind;
7 6
import com.sap.sse.common.TimePoint;
7
+import com.sap.sse.common.scalablevalue.HasConfidenceAndIsScalable;
8 8
9 9
/**
10 10
* In order to scale a wind value, a specific type is used: {@link ScalableWind}.
java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/BravoFixTrackImpl.java
... ...
@@ -5,7 +5,6 @@ import java.io.ObjectInputStream;
5 5
import java.io.Serializable;
6 6
import java.util.function.Function;
7 7
8
-import com.sap.sailing.domain.common.confidence.impl.ScalableDouble;
9 8
import com.sap.sailing.domain.common.scalablevalue.impl.ScalableDistance;
10 9
import com.sap.sailing.domain.common.tracking.BravoExtendedFix;
11 10
import com.sap.sailing.domain.common.tracking.BravoFix;
... ...
@@ -25,6 +24,7 @@ import com.sap.sse.common.TimePoint;
25 24
import com.sap.sse.common.Util.Pair;
26 25
import com.sap.sse.common.impl.DegreeBearingImpl;
27 26
import com.sap.sse.common.WithID;
27
+import com.sap.sse.common.scalablevalue.ScalableDouble;
28 28
import com.sap.sse.common.scalablevalue.ScalableValue;
29 29
30 30
/**
java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/DynamicGPSFixMovingTrackImpl.java
... ...
@@ -17,7 +17,6 @@ import com.sap.sailing.domain.common.confidence.BearingWithConfidence;
17 17
import com.sap.sailing.domain.common.confidence.BearingWithConfidenceCluster;
18 18
import com.sap.sailing.domain.common.confidence.ConfidenceBasedAverager;
19 19
import com.sap.sailing.domain.common.confidence.ConfidenceFactory;
20
-import com.sap.sailing.domain.common.confidence.HasConfidence;
21 20
import com.sap.sailing.domain.common.confidence.Weigher;
22 21
import com.sap.sailing.domain.common.confidence.impl.BearingWithConfidenceImpl;
23 22
import com.sap.sailing.domain.common.impl.KnotSpeedWithBearingImpl;
... ...
@@ -32,6 +31,7 @@ import com.sap.sse.common.Distance;
32 31
import com.sap.sse.common.Speed;
33 32
import com.sap.sse.common.TimePoint;
34 33
import com.sap.sse.common.impl.DegreeBearingImpl;
34
+import com.sap.sse.common.scalablevalue.HasConfidence;
35 35
36 36
public class DynamicGPSFixMovingTrackImpl<ItemType> extends GPSFixTrackImpl<ItemType, GPSFixMoving> implements DynamicGPSFixTrack<ItemType, GPSFixMoving> {
37 37
private static final Logger logger = Logger.getLogger(DynamicGPSFixMovingTrackImpl.class.getName());
java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/GPSFixTrackImpl.java
... ...
@@ -24,7 +24,6 @@ import com.sap.sailing.domain.common.confidence.BearingWithConfidence;
24 24
import com.sap.sailing.domain.common.confidence.BearingWithConfidenceCluster;
25 25
import com.sap.sailing.domain.common.confidence.ConfidenceBasedAverager;
26 26
import com.sap.sailing.domain.common.confidence.ConfidenceFactory;
27
-import com.sap.sailing.domain.common.confidence.HasConfidence;
28 27
import com.sap.sailing.domain.common.confidence.Weigher;
29 28
import com.sap.sailing.domain.common.confidence.impl.BearingWithConfidenceImpl;
30 29
import com.sap.sailing.domain.common.impl.KnotSpeedWithBearingImpl;
... ...
@@ -55,6 +54,7 @@ import com.sap.sse.common.impl.DegreeBearingImpl;
55 54
import com.sap.sse.common.impl.MillisecondsDurationImpl;
56 55
import com.sap.sse.common.impl.MillisecondsTimePoint;
57 56
import com.sap.sse.common.impl.TimeRangeImpl;
57
+import com.sap.sse.common.scalablevalue.HasConfidence;
58 58
import com.sap.sse.shared.util.impl.ArrayListNavigableSet;
59 59
60 60
public abstract class GPSFixTrackImpl<ItemType, FixType extends GPSFix> extends MappedTrackImpl<ItemType, FixType>
java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/TrackedRaceImpl.java
... ...
@@ -104,7 +104,6 @@ import com.sap.sailing.domain.common.WindSourceType;
104 104
import com.sap.sailing.domain.common.abstractlog.TimePointSpecificationFoundInLog;
105 105
import com.sap.sailing.domain.common.confidence.BearingWithConfidence;
106 106
import com.sap.sailing.domain.common.confidence.BearingWithConfidenceCluster;
107
-import com.sap.sailing.domain.common.confidence.HasConfidence;
108 107
import com.sap.sailing.domain.common.confidence.Weigher;
109 108
import com.sap.sailing.domain.common.confidence.impl.BearingWithConfidenceImpl;
110 109
import com.sap.sailing.domain.common.confidence.impl.HyperbolicTimeDifferenceWeigher;
... ...
@@ -185,6 +184,7 @@ import com.sap.sse.common.Util;
185 184
import com.sap.sse.common.Util.Pair;
186 185
import com.sap.sse.common.impl.DegreeBearingImpl;
187 186
import com.sap.sse.common.impl.MillisecondsTimePoint;
187
+import com.sap.sse.common.scalablevalue.HasConfidence;
188 188
import com.sap.sse.concurrent.LockUtil;
189 189
import com.sap.sse.concurrent.NamedReentrantReadWriteLock;
190 190
import com.sap.sse.shared.util.impl.ApproximateTime;
java/com.sap.sailing.polars.test/src/com/sap/sailing/polars/windestimation/TestWindEstimationFromManeuversOnAFew505Races.java
... ...
@@ -17,7 +17,6 @@ import org.junit.jupiter.api.Test;
17 17
18 18
import com.sap.sailing.domain.common.ManeuverType;
19 19
import com.sap.sailing.domain.common.Wind;
20
-import com.sap.sailing.domain.common.confidence.impl.ScalableDouble;
21 20
import com.sap.sailing.domain.common.confidence.impl.ScalableWind;
22 21
import com.sap.sailing.domain.common.polars.NotEnoughDataHasBeenAddedException;
23 22
import com.sap.sailing.domain.common.scalablevalue.impl.ScalableBearing;
... ...
@@ -27,6 +26,7 @@ import com.sap.sailing.polars.impl.PolarDataServiceImpl;
27 26
import com.sap.sse.common.Bearing;
28 27
import com.sap.sse.common.Util.Pair;
29 28
import com.sap.sse.common.impl.DegreeBearingImpl;
29
+import com.sap.sse.common.scalablevalue.ScalableDouble;
30 30
import com.sap.sse.util.kmeans.Cluster;
31 31
import com.sap.sse.util.kmeans.KMeansMappingClusterer;
32 32
java/com.sap.sailing.polars/src/com/sap/sailing/polars/windestimation/AbstractManeuverBasedWindEstimationTrackImpl.java
... ...
@@ -17,8 +17,6 @@ import com.sap.sailing.domain.common.ManeuverType;
17 17
import com.sap.sailing.domain.common.Wind;
18 18
import com.sap.sailing.domain.common.confidence.ConfidenceBasedAverager;
19 19
import com.sap.sailing.domain.common.confidence.ConfidenceFactory;
20
-import com.sap.sailing.domain.common.confidence.HasConfidence;
21
-import com.sap.sailing.domain.common.confidence.impl.ScalableDouble;
22 20
import com.sap.sailing.domain.common.impl.WindImpl;
23 21
import com.sap.sailing.domain.common.polars.NotEnoughDataHasBeenAddedException;
24 22
import com.sap.sailing.domain.common.scalablevalue.impl.ScalableBearing;
... ...
@@ -30,6 +28,8 @@ import com.sap.sse.common.Speed;
30 28
import com.sap.sse.common.Util.Pair;
31 29
import com.sap.sse.common.Util.Triple;
32 30
import com.sap.sse.common.impl.DegreeBearingImpl;
31
+import com.sap.sse.common.scalablevalue.HasConfidence;
32
+import com.sap.sse.common.scalablevalue.ScalableDouble;
33 33
import com.sap.sse.util.kmeans.Cluster;
34 34
import com.sap.sse.util.kmeans.KMeansMappingClusterer;
35 35
java/com.sap.sailing.polars/src/com/sap/sailing/polars/windestimation/ManeuverBasedWindEstimationTrack.java
... ...
@@ -5,12 +5,12 @@ import java.util.Set;
5 5
import java.util.stream.Stream;
6 6
7 7
import com.sap.sailing.domain.base.BoatClass;
8
-import com.sap.sailing.domain.common.confidence.impl.ScalableDouble;
9 8
import com.sap.sailing.domain.common.polars.NotEnoughDataHasBeenAddedException;
10 9
import com.sap.sailing.domain.common.scalablevalue.impl.ScalableBearing;
11 10
import com.sap.sailing.domain.tracking.WindTrack;
12 11
import com.sap.sse.common.Bearing;
13 12
import com.sap.sse.common.Util.Pair;
13
+import com.sap.sse.common.scalablevalue.ScalableDouble;
14 14
import com.sap.sse.util.kmeans.Cluster;
15 15
16 16
public interface ManeuverBasedWindEstimationTrack extends WindTrack {
java/com.sap.sailing.polars/src/com/sap/sailing/polars/windestimation/ManeuverBasedWindEstimationTrackImpl.java
... ...
@@ -13,7 +13,6 @@ import com.sap.sailing.domain.base.CompetitorAndBoat;
13 13
import com.sap.sailing.domain.base.Waypoint;
14 14
import com.sap.sailing.domain.base.impl.CompetitorAndBoatImpl;
15 15
import com.sap.sailing.domain.common.ManeuverType;
16
-import com.sap.sailing.domain.common.confidence.impl.ScalableDouble;
17 16
import com.sap.sailing.domain.common.polars.NotEnoughDataHasBeenAddedException;
18 17
import com.sap.sailing.domain.common.scalablevalue.impl.ScalableBearing;
19 18
import com.sap.sailing.domain.polars.PolarDataService;
... ...
@@ -26,6 +25,7 @@ import com.sap.sse.common.Util;
26 25
import com.sap.sse.common.Util.Pair;
27 26
import com.sap.sse.common.impl.DegreeBearingImpl;
28 27
import com.sap.sse.common.impl.MillisecondsTimePoint;
28
+import com.sap.sse.common.scalablevalue.ScalableDouble;
29 29
import com.sap.sse.util.kmeans.Cluster;
30 30
31 31
/**
java/com.sap.sailing.polars/src/com/sap/sailing/polars/windestimation/ManeuverClassificationToHasConfidenceAndIsScalableAdapter.java
... ...
@@ -4,8 +4,8 @@ import java.util.function.Function;
4 4
5 5
import com.sap.sailing.domain.common.ManeuverType;
6 6
import com.sap.sailing.domain.common.confidence.ConfidenceBasedAverager;
7
-import com.sap.sailing.domain.common.confidence.HasConfidenceAndIsScalable;
8 7
import com.sap.sailing.domain.polars.PolarDataService;
8
+import com.sap.sse.common.scalablevalue.HasConfidenceAndIsScalable;
9 9
import com.sap.sse.common.scalablevalue.ScalableValue;
10 10
11 11
/**
java/com.sap.sailing.polars/src/com/sap/sailing/polars/windestimation/ScalableBearingAndScalableDouble.java
... ...
@@ -1,9 +1,9 @@
1 1
package com.sap.sailing.polars.windestimation;
2 2
3
-import com.sap.sailing.domain.common.confidence.impl.ScalableDouble;
4 3
import com.sap.sailing.domain.common.scalablevalue.impl.ScalableBearing;
5 4
import com.sap.sse.common.Bearing;
6 5
import com.sap.sse.common.Util.Pair;
6
+import com.sap.sse.common.scalablevalue.ScalableDouble;
7 7
import com.sap.sse.common.scalablevalue.ScalableValue;
8 8
import com.sap.sse.common.scalablevalue.ScalableValueWithDistance;
9 9
java/com.sap.sailing.server.gateway/src/com/sap/sailing/server/gateway/jaxrs/api/PolarResource.java
... ...
@@ -26,7 +26,6 @@ import com.sap.sailing.domain.base.SpeedWithConfidence;
26 26
import com.sap.sailing.domain.common.LegType;
27 27
import com.sap.sailing.domain.common.Tack;
28 28
import com.sap.sailing.domain.common.Wind;
29
-import com.sap.sailing.domain.common.confidence.impl.ScalableDouble;
30 29
import com.sap.sailing.domain.common.impl.KnotSpeedImpl;
31 30
import com.sap.sailing.domain.common.polars.NotEnoughDataHasBeenAddedException;
32 31
import com.sap.sailing.domain.common.scalablevalue.impl.ScalableBearing;
... ...
@@ -43,6 +42,7 @@ import com.sap.sse.common.Bearing;
43 42
import com.sap.sse.common.Speed;
44 43
import com.sap.sse.common.Util.Pair;
45 44
import com.sap.sse.common.impl.DegreeBearingImpl;
45
+import com.sap.sse.common.scalablevalue.ScalableDouble;
46 46
import com.sap.sse.util.kmeans.Cluster;
47 47
48 48
/**
java/com.sap.sailing.windestimation/src/com/sap/sailing/windestimation/aggregator/clustering/ManeuverClusteringBasedWindEstimationTrackImpl.java
... ...
@@ -7,7 +7,6 @@ import java.util.stream.Stream;
7 7
8 8
import com.sap.sailing.domain.base.BoatClass;
9 9
import com.sap.sailing.domain.common.ManeuverType;
10
-import com.sap.sailing.domain.common.confidence.impl.ScalableDouble;
11 10
import com.sap.sailing.domain.common.scalablevalue.impl.ScalableBearing;
12 11
import com.sap.sailing.domain.polars.PolarDataService;
13 12
import com.sap.sailing.polars.windestimation.AbstractManeuverBasedWindEstimationTrackImpl;
... ...
@@ -22,6 +21,7 @@ import com.sap.sailing.windestimation.model.exception.ModelOperationException;
22 21
import com.sap.sse.common.Bearing;
23 22
import com.sap.sse.common.Speed;
24 23
import com.sap.sse.common.Util.Pair;
24
+import com.sap.sse.common.scalablevalue.ScalableDouble;
25 25
import com.sap.sse.util.kmeans.Cluster;
26 26
27 27
/**
java/com.sap.sse.common.test/src/com/sap/sse/common/test/KadaneExtremeSubarraysFinderTest.java
... ...
@@ -0,0 +1,29 @@
1
+package com.sap.sse.common.test;
2
+
3
+import static org.junit.jupiter.api.Assertions.assertEquals;
4
+
5
+import org.junit.jupiter.api.BeforeEach;
6
+import org.junit.jupiter.api.Test;
7
+
8
+import com.sap.sse.common.scalablevalue.KadaneExtremeSubarraysFinder;
9
+import com.sap.sse.common.scalablevalue.ScalableDouble;
10
+
11
+public class KadaneExtremeSubarraysFinderTest {
12
+ private static final double EPSILON = 0.00000001;
13
+ private KadaneExtremeSubarraysFinder<Double, Double, ScalableDouble> finder;
14
+
15
+ @BeforeEach
16
+ public void setUp() {
17
+ finder = new KadaneExtremeSubarraysFinder<>();
18
+ }
19
+
20
+ @Test
21
+ public void testSimplePositiveSequence() {
22
+ finder.add(new ScalableDouble(1));
23
+ finder.add(new ScalableDouble(2));
24
+ finder.add(new ScalableDouble(3));
25
+ assertEquals(6.0, finder.getMaxSum(), EPSILON);
26
+ assertEquals(0, finder.getStartIndexInclusiveOfMaxSumSequence());
27
+ assertEquals(3, finder.getEndIndexExclusiveOfMaxSumSequence());
28
+ }
29
+}
java/com.sap.sse.common/src/com/sap/sse/common/scalablevalue/HasConfidence.java
... ...
@@ -0,0 +1,90 @@
1
+package com.sap.sse.common.scalablevalue;
2
+
3
+import java.io.Serializable;
4
+
5
+import com.sap.sse.common.Distance;
6
+import com.sap.sse.common.TimePoint;
7
+
8
+/**
9
+ * Some values, particularly those obtained from real-world measurements, are not always accurate. Some values are
10
+ * derived by interpolating or extrapolating data series obtained through measurement or even estimation. Some values
11
+ * are simply guessed by humans and entered into the system.
12
+ * <p>
13
+ *
14
+ * All those values have a certain level of confidence. In case multiple sources of information about the same entity or
15
+ * phenomenon are available, knowing the confidence of each value helps in weighing and averaging these values more
16
+ * properly than would be possible without a confidence value.
17
+ * <p>
18
+ *
19
+ * In simple cases, the type used to compute a weighed average over the things equipped with a confidence level is the
20
+ * same as the type of the things themselves. In particular, this is the case for scalar types such as {@link Double}
21
+ * and {@link Distance}. For non-scalar values, averaging may be non-trivial. For example, averaging a bearing cannot
22
+ * simply happen by computing the arithmetic average of the bearing's angles. Instead, an intermediate structure
23
+ * providing the sinus and cosinus values of the bearing's angle is used to compute the weighed average tangens.
24
+ * <p>
25
+ *
26
+ * Generally, the relationship between the type implementing this interface, the <code>ValueType</code> and the
27
+ * <code>AveragesTo</code> type is this: an instance of the implementing type can transform itself into a
28
+ * {@link ScalableValue} which is then used for computing a weighed sum. The values' weight is their
29
+ * {@link #getConfidence() confidence}. The sum (which is still a {@link ScalableValue} because
30
+ * {@link ScalableValue#add(ScalableValue)} returns again a {@link ScalableValue}) is then
31
+ * {@link ScalableValue#divide(double) divided} by the sum of the confidences. This "division" is expected to
32
+ * produce an object of type <code>AveragesTo</code>. Usually, <code>AveragesTo</code> would be the same as the class
33
+ * implementing this interface.
34
+ *
35
+ * @author Axel Uhl (d043530)
36
+ *
37
+ * @param <ValueType>
38
+ * the type of the scalable value used for scalar operations during aggregation
39
+ * @param <RelativeTo>
40
+ * the type of the object relative to which the confidence applies; for example, if the
41
+ * base type is a position and the <code>RelativeTo</code> type is {@link TimePoint},
42
+ * the confidence of the position is relative to a certain time point. Together with
43
+ * a correspondingly-typed weigher, such a value with confidence can be aggregated with
44
+ * other values, again relative to (maybe a different) time point.
45
+ */
46
+public interface HasConfidence<ValueType, BaseType, RelativeTo> extends Serializable {
47
+ /**
48
+ * A confidence is a number between 0.0 and 1.0 (inclusive) where 0.0 means that the value is randomly guessed while
49
+ * 1.0 means the value is authoritatively known for a fact. It represents the weight with which a value is to be
50
+ * considered by averaging, interpolation and extrapolation algorithms.
51
+ * <p>
52
+ *
53
+ * An averaging algorithm for a sequence of <code>n</code> tuples <code>(v1, c1), ..., (vn, cn)</code> of a value
54
+ * <code>vi</code> with a confidence <code>ci</code> each can for example look like this:
55
+ * <code>a := (c1*v1 + ... + cn*vn) / (c1 + ... + cn)</code>. For a single value with a confidence this trivially
56
+ * results in <code>c1*v1 / (c1)</code> which is equivalent to <code>v1</code>. As another example, consider two
57
+ * values with equal confidence <code>0.8</code>. Then, <code>a := (0.8*v1 + 0.8*vn) / (0.8 + 0.8)</code> which
58
+ * resolves to <code>0.5*v1 + 0.5*v2</code> which is obviously the arithmetic mean of the two values. If one value
59
+ * has confidence <code>0.8</code> and the other <code>0.4</code>, then
60
+ * <code>a := (0.8*v1 + 0.4*vn) / (0.8 + 0.4)</code> which resolves to <code>2/3*v1 + 1/3*v2</code> which is a
61
+ * weighed average.
62
+ * <p>
63
+ *
64
+ * Note, that this doesn't exactly take facts for facts. In other words, if one value is provided with a confidence
65
+ * of <code>1.0</code>, the average may still be influenced by other values. However, this cleanly resolves otherwise
66
+ * mutually contradictory "facts" such a <code>(v1, 1.0), (v2, 1.0)</code> with <code>v1 != v2</code>. It is
67
+ * considered bad practice to claim a fact as soon as it results from any kind of measurement or estimation. All
68
+ * measurement devices produce some statistical errors, no matter how small (cf. Heisenberg ;-) ).
69
+ */
70
+ double getConfidence();
71
+
72
+ /**
73
+ * The confidence attached to a value is usually relative to some reference point, such as a time point or
74
+ * a position. For example, when a <code>GPSFixTrack</code> is asked to deliver an estimation for the tracked item's
75
+ * {@link Position} at some given {@link TimePoint}, the track computes some average from a number of GPS fixes. The resulting
76
+ * position has a certain confidence, depending on the time differences between the fixes and the time point for which
77
+ * the position estimation was requested. The result therefore carries this reference time point for which the estimation
78
+ * was requested so that when the result is to be used in further estimations it is clear relative to which time point the
79
+ * confidence is to be interpreted.<p>
80
+ *
81
+ * In this context, a single GPS fix is a measurement whose values may also have a confidence attached. This confidence could be
82
+ * regarded as relative to the fix's time point.
83
+ */
84
+ RelativeTo getRelativeTo();
85
+
86
+ /**
87
+ * The object annotated by a confidence
88
+ */
89
+ BaseType getObject();
90
+}
java/com.sap.sse.common/src/com/sap/sse/common/scalablevalue/HasConfidenceAndIsScalable.java
... ...
@@ -0,0 +1,5 @@
1
+package com.sap.sse.common.scalablevalue;
2
+
3
+public interface HasConfidenceAndIsScalable<ValueType, BaseType, RelativeTo> extends IsScalable<ValueType, BaseType>,
4
+ HasConfidence<ValueType, BaseType, RelativeTo> {
5
+}
java/com.sap.sse.common/src/com/sap/sse/common/scalablevalue/KadaneExtremeSubarraysFinder.java
... ...
@@ -1,6 +1,7 @@
1 1
package com.sap.sse.common.scalablevalue;
2 2
3 3
import java.io.Serializable;
4
+import java.util.Iterator;
4 5
import java.util.LinkedList;
5 6
import java.util.List;
6 7
... ...
@@ -25,7 +26,7 @@ import java.util.List;
25 26
*
26 27
*/
27 28
public class KadaneExtremeSubarraysFinder<ValueType, AveragesTo extends Comparable<AveragesTo>, T extends ComparableScalableValueWithDistance<ValueType, AveragesTo>>
28
-implements Serializable {
29
+implements Serializable, Iterable<T> {
29 30
private static final long serialVersionUID = 2109193559337714286L;
30 31
31 32
/**
... ...
@@ -35,7 +36,11 @@ implements Serializable {
35 36
36 37
/**
37 38
* The element at index <tt>i</tt> holds the maximum value of the sum of any contiguous sub-sequence ending at index
38
- * <tt>i</tt>.
39
+ * <tt>i</tt>. Outside of {@code synchronized} blocks it holds as many elements as {@link #sequence}. The element
40
+ * at index {@code i} is computed as {@code maxSumEndingAt.get(i-1)+sequence.get(i), max(sequence.get(i))}. This covers
41
+ * the two cases extending the complete induction. Either, the sequence with the maximum sum ending at index {@code i}
42
+ * includes prior elements; or the single element {@code sequence.get(i)} is greater than the sum of it and the maximum
43
+ * sum ending at the previous element {@code i-1}.
39 44
*/
40 45
private final List<AveragesTo> maxSumEndingAt;
41 46
... ...
@@ -55,8 +60,7 @@ implements Serializable {
55 60
private int endIndexExclusiveOfMaxSumSequence;
56 61
57 62
/**
58
- * The element at index <tt>i</tt> holds the minimum value of the sum of any contiguous sub-sequence ending at index
59
- * <tt>i</tt>.
63
+ * See {@code #maxSumEndingAt}, only for the minimum.
60 64
*/
61 65
private final List<AveragesTo> minSumEndingAt;
62 66
... ...
@@ -83,4 +87,51 @@ implements Serializable {
83 87
startIndexInclusiveOfMinSumSequence = -1;
84 88
endIndexExclusiveOfMinSumSequence = -1;
85 89
}
90
+
91
+ public synchronized void add(int index, T t) {
92
+ sequence.add(index, t);
93
+ // TODO update all structures, sums, indices, and invariants
94
+ }
95
+
96
+ public synchronized void remove(int index) {
97
+ sequence.remove(index);
98
+ // TODO update all structures, sums, indices, and invariants
99
+ }
100
+
101
+ public synchronized void add(T t) {
102
+ add(sequence.size(), t);
103
+ }
104
+
105
+ public synchronized void remove(T t) {
106
+ remove(sequence.indexOf(t));
107
+ }
108
+
109
+ public AveragesTo getMaxSum() {
110
+ return maxSum;
111
+ }
112
+
113
+ public AveragesTo getMinSum() {
114
+ return minSum;
115
+ }
116
+
117
+ public int getStartIndexInclusiveOfMaxSumSequence() {
118
+ return startIndexInclusiveOfMaxSumSequence;
119
+ }
120
+
121
+ public int getEndIndexExclusiveOfMaxSumSequence() {
122
+ return endIndexExclusiveOfMaxSumSequence;
123
+ }
124
+
125
+ public int getStartIndexInclusiveOfMinSumSequence() {
126
+ return startIndexInclusiveOfMinSumSequence;
127
+ }
128
+
129
+ public int getEndIndexExclusiveOfMinSumSequence() {
130
+ return endIndexExclusiveOfMinSumSequence;
131
+ }
132
+
133
+ @Override
134
+ public Iterator<T> iterator() {
135
+ return sequence.iterator();
136
+ }
86 137
}
java/com.sap.sse.common/src/com/sap/sse/common/scalablevalue/ScalableDouble.java
... ...
@@ -0,0 +1,44 @@
1
+package com.sap.sse.common.scalablevalue;
2
+
3
+public class ScalableDouble implements AbstractScalarValue<Double> {
4
+ private final double value;
5
+
6
+ public ScalableDouble(double value) {
7
+ this.value = value;
8
+ }
9
+
10
+ @Override
11
+ public ScalableDouble multiply(double factor) {
12
+ return new ScalableDouble(factor*getValue());
13
+ }
14
+
15
+ @Override
16
+ public ScalableDouble add(ScalableValue<Double, Double> t) {
17
+ return new ScalableDouble(getValue()+t.getValue());
18
+ }
19
+
20
+ @Override
21
+ public Double divide(double divisor) {
22
+ return getValue()/divisor;
23
+ }
24
+
25
+ @Override
26
+ public Double getValue() {
27
+ return value;
28
+ }
29
+
30
+ @Override
31
+ public double getDistance(Double other) {
32
+ return Math.abs(value-other);
33
+ }
34
+
35
+ @Override
36
+ public String toString() {
37
+ return Double.valueOf(value).toString();
38
+ }
39
+
40
+ @Override
41
+ public int compareTo(Double o) {
42
+ return Double.valueOf(value).compareTo(o);
43
+ }
44
+}
java/com.sap.sse.common/src/com/sap/sse/common/scalablevalue/ScalableDoubleWithConfidence.java
... ...
@@ -0,0 +1,33 @@
1
+package com.sap.sse.common.scalablevalue;
2
+
3
+public class ScalableDoubleWithConfidence<RelativeTo> extends ScalableDouble implements HasConfidenceAndIsScalable<Double, Double, RelativeTo> {
4
+ private static final long serialVersionUID = 1042652394404557792L;
5
+ private final double confidence;
6
+ private final RelativeTo relativeTo;
7
+
8
+ public ScalableDoubleWithConfidence(double d, double confidence, RelativeTo relativeTo) {
9
+ super(d);
10
+ this.confidence = confidence;
11
+ this.relativeTo = relativeTo;
12
+ }
13
+
14
+ @Override
15
+ public Double getObject() {
16
+ return getValue();
17
+ }
18
+
19
+ @Override
20
+ public RelativeTo getRelativeTo() {
21
+ return relativeTo;
22
+ }
23
+
24
+ @Override
25
+ public double getConfidence() {
26
+ return confidence;
27
+ }
28
+
29
+ @Override
30
+ public ScalableDouble getScalableValue() {
31
+ return this;
32
+ }
33
+}