Skip to content

Commit 3b5b9e7

Browse files
committed
adding test coverage
1 parent 52a30e4 commit 3b5b9e7

2 files changed

Lines changed: 34 additions & 33 deletions

File tree

gnss_lib_py/algorithms/fde.py

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,9 @@ def fde_edm(navdata, max_faults=None, threshold=1.0, verbose=False,
148148
or (max_faults is not None and len(fault_idxs) == max_faults):
149149
break
150150

151-
try:
152-
edm_detect = np.delete(np.delete(edm,fault_idxs,0),fault_idxs,1)
153-
detection_statistic_detect, svd_u, svd_s, _ = _edm_detection_statistic(edm_detect)
154-
detection_statistic = detection_statistic_detect[0]
155-
except Exception as exception:
156-
if verbose:
157-
print(exception)
158-
break
151+
edm_detect = np.delete(np.delete(edm,fault_idxs,0),fault_idxs,1)
152+
detection_statistic_detect, svd_u, svd_s, _ = _edm_detection_statistic(edm_detect)
153+
detection_statistic = detection_statistic_detect[0]
159154

160155
if verbose:
161156
print("detection statistic:",detection_statistic)
@@ -393,14 +388,19 @@ def evaluate_fde(navdata, method, fault_truth_row="fault_gt",
393388
Parameters
394389
----------
395390
navdata : gnss_lib_py.parsers.navdata.NavData
396-
NavData of GNSS measurements which must include the receiver's
397-
estimated state: x_rx*_m, y_rx*_m, z_rx*_m, b_rx*_m as well as
398-
the satellite states: x_sv_m, y_sv_m, z_sv_m, b_sv_m as well
391+
NavData of GNSS measurements which must include the satellite
392+
positions: x_sv_m, y_sv_m, z_sv_m, b_sv_m as well
399393
as timing "gps_millis" and the corrected pseudorange corr_pr_m.
394+
Additionally, the ground truth fault row must exist as indicated
395+
by the fault the ``fault_truth_row`` variable.
400396
method : string
401397
Method for fault detection and exclusion either "residual" for
402398
residual-based, "ss" for solution separation or "edm" for
403399
Euclidean Distance Matrix-based.
400+
fault_truth_row : string
401+
Row that indicates the ground truth for the fault status. This
402+
row is used to provide results on how well each method performs
403+
at fault detection and exclusion.
404404
time_fde : bool
405405
Additional debugging info added like timing
406406
verbose : bool
@@ -463,30 +463,21 @@ def evaluate_fde(navdata, method, fault_truth_row="fault_gt",
463463
+ missed_detection + unknown
464464

465465
# compute accuracy metrics
466-
try:
467-
tpr = true_positive / (true_positive + missed_detection)
468-
except ZeroDivisionError:
469-
tpr = 0.0
470-
try:
471-
tnr = true_negative / (true_negative + false_alarm)
472-
except ZeroDivisionError:
473-
tnr = 0.0
474-
try:
475-
mdr = missed_detection / (missed_detection + true_positive)
476-
except ZeroDivisionError:
477-
mdr = 0.0
478-
try:
479-
far = false_alarm / (false_alarm + true_negative)
480-
except ZeroDivisionError:
481-
far = 0.0
466+
tpr = true_positive / (true_positive + missed_detection) \
467+
if (true_positive + missed_detection) else 0.
468+
tnr = true_negative / (true_negative + false_alarm) \
469+
if (true_negative + false_alarm) else 0.
470+
mdr = missed_detection / (missed_detection + true_positive) \
471+
if (missed_detection + true_positive) else 0.
472+
far = false_alarm / (false_alarm + true_negative) \
473+
if (false_alarm + true_negative) else 0.
482474

483475
accuracy = (true_positive + true_negative) / (true_positive \
484476
+ true_negative + missed_detection + false_alarm)
485477
balanced_accuracy = (tpr + tnr) / 2.
486-
try:
487-
precision = true_positive / (true_positive + false_alarm)
488-
except ZeroDivisionError:
489-
precision = 0
478+
479+
precision = true_positive / (true_positive + false_alarm) \
480+
if (true_positive + false_alarm) else 0.
490481
recall = tpr
491482

492483

@@ -540,10 +531,10 @@ def evaluate_fde(navdata, method, fault_truth_row="fault_gt",
540531
metrics["precision"] = precision
541532
metrics["recall"] = recall
542533
metrics["accuracy"] = accuracy
534+
metrics["balanced_accuracy"] = balanced_accuracy
543535

544536
# compute timing metrics
545537
if "compute_times" in timing_info:
546-
metrics["balanced_accuracy"] = balanced_accuracy
547538
metrics["timestep_min_ms"] = np.min(timing_info["compute_times"])*1000
548539
metrics["timestep_mean_ms"] = np.mean(timing_info["compute_times"])*1000
549540
metrics["timestep_median_ms"] = np.median(timing_info["compute_times"])*1000

tests/algorithms/test_fde.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,14 @@ def test_evaluate_fde(derived, method):
164164
evaluate_fde(navdata,
165165
method=method,
166166
fault_truth_row="MultipathIndicator",
167-
verbose=True)
167+
verbose=True,
168+
time_fde=True,
169+
)
170+
171+
if method == "edm":
172+
evaluate_fde(navdata,
173+
method=method,
174+
fault_truth_row="MultipathIndicator",
175+
verbose=False,
176+
time_fde=False,
177+
)

0 commit comments

Comments
 (0)