1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.irurueta.navigation.inertial.calibration.intervals.thresholdfactor;
17
18 import com.irurueta.navigation.LockedException;
19 import com.irurueta.navigation.NotReadyException;
20 import com.irurueta.navigation.inertial.calibration.StandardDeviationBodyMagneticFluxDensity;
21 import com.irurueta.navigation.inertial.calibration.magnetometer.MagnetometerCalibratorMeasurementType;
22 import com.irurueta.navigation.inertial.calibration.magnetometer.MagnetometerNonLinearCalibrator;
23
24
25
26
27
28
29
30
31
32
33
34 public class ExhaustiveMagnetometerIntervalDetectorThresholdFactorOptimizer extends
35 MagnetometerIntervalDetectorThresholdFactorOptimizer {
36
37
38
39
40 public static final double DEFAULT_STEP = 1.0;
41
42
43
44
45
46 private double thresholdFactorStep = DEFAULT_STEP;
47
48
49
50
51 public ExhaustiveMagnetometerIntervalDetectorThresholdFactorOptimizer() {
52 super();
53 }
54
55
56
57
58
59
60 public ExhaustiveMagnetometerIntervalDetectorThresholdFactorOptimizer(
61 final MagnetometerIntervalDetectorThresholdFactorOptimizerDataSource dataSource) {
62 super(dataSource);
63 }
64
65
66
67
68
69
70
71
72
73 public ExhaustiveMagnetometerIntervalDetectorThresholdFactorOptimizer(
74 final MagnetometerNonLinearCalibrator calibrator) {
75 super(calibrator);
76 }
77
78
79
80
81
82
83
84
85
86
87 public ExhaustiveMagnetometerIntervalDetectorThresholdFactorOptimizer(
88 final MagnetometerIntervalDetectorThresholdFactorOptimizerDataSource dataSource,
89 final MagnetometerNonLinearCalibrator calibrator) {
90 super(dataSource, calibrator);
91 }
92
93
94
95
96
97
98
99 public double getThresholdFactorStep() {
100 return thresholdFactorStep;
101 }
102
103
104
105
106
107
108
109
110
111 public void setThresholdFactorStep(final double thresholdStep) throws LockedException {
112 if (running) {
113 throw new LockedException();
114 }
115 if (thresholdStep <= 0.0) {
116 throw new IllegalArgumentException();
117 }
118
119 thresholdFactorStep = thresholdStep;
120 }
121
122
123
124
125
126
127
128
129
130
131
132
133 @Override
134 public double optimize() throws NotReadyException, LockedException,
135 IntervalDetectorThresholdFactorOptimizerException {
136 if (running) {
137 throw new LockedException();
138 }
139
140 if (!isReady()) {
141 throw new NotReadyException();
142 }
143
144 var hasResult = false;
145 minMse = Double.MAX_VALUE;
146 try {
147 running = true;
148
149 initProgress();
150 final var progressStep = (float) (thresholdFactorStep
151 / (thresholdFactorStep + maxThresholdFactor - minThresholdFactor));
152
153 if (listener != null) {
154 listener.onOptimizeStart(this);
155 }
156
157 for (var thresholdFactor = minThresholdFactor;
158 thresholdFactor <= maxThresholdFactor;
159 thresholdFactor += thresholdFactorStep) {
160 try {
161 evaluateForThresholdFactor(thresholdFactor);
162 hasResult = true;
163 } catch (final Exception ignore) {
164
165 }
166
167 progress += progressStep;
168 checkAndNotifyProgress();
169 }
170
171 if (!hasResult) {
172 throw new IntervalDetectorThresholdFactorOptimizerException();
173 }
174
175 if (listener != null) {
176 listener.onOptimizeEnd(this);
177 }
178
179 } finally {
180 running = false;
181 }
182
183 return optimalThresholdFactor;
184 }
185 }