-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patherror_measures.py
65 lines (45 loc) · 2.42 KB
/
error_measures.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from ctypes import ArgumentError
from case_study import CaseStudy
from cells.processing.cell import CellsToDistancesWithEnergies, DistMatrix
def count_distances_outside_tolerance_treshold(test: CellsToDistancesWithEnergies, ref: CellsToDistancesWithEnergies, tolerance: int):
if len(test) != len(ref):
print(f"lengths mismatch: {len(test)} vs. {len(ref)} for test vs. ref data")
cnt: int = 0
for cell_id in ref:
if cell_id not in test:
print(f"cell {cell_id} is missing in test data")
raise ArgumentError(f"missing {cell_id} in test data")
cnt = cnt if abs( ref[cell_id][0] - test[cell_id][0] ) <= tolerance else cnt+1
return cnt
def count_distances_outside_tolerance_treshold__matrix(test: DistMatrix, ref: DistMatrix, tolerance: int):
cnt = 0
for cell_id in ref:
if cell_id not in test:
print(f"cell {cell_id} is missing in test data")
raise ArgumentError(f"missing {cell_id} in test data")
cnt += count_distances_outside_tolerance_treshold(test[cell_id], ref[cell_id], tolerance)
return cnt
def count_distances_outside_tolerance_treshold__study(case_study: CaseStudy, tolerance: int):
return count_distances_outside_tolerance_treshold__matrix(case_study.distances, case_study.distances_gt, tolerance)
def count_rank_mismatches(test: CellsToDistancesWithEnergies, ref: CellsToDistancesWithEnergies):
if len(test) != len(ref):
print(f"lengths mismatch: {len(test)} vs. {len(ref)} for test vs. ref data")
test_sorted = list( sorted(test, key=lambda k: test[k][0]) )
ref_sorted = list( sorted(ref, key=lambda k: ref[k][0]) )
cnt: int = 0
for idx,cell_id in enumerate(ref_sorted):
if cell_id not in test:
print(f"cell {cell_id} is missing in test data")
raise ArgumentError(f"missing {cell_id} in test data")
cnt = cnt if ref_sorted[idx] == test_sorted[idx] else cnt+1
return cnt
def count_rank_mismatches__matrix(test: DistMatrix, ref: DistMatrix):
cnt = 0
for cell_id in ref:
if cell_id not in test:
print(f"cell {cell_id} is missing in test data")
raise ArgumentError(f"missing {cell_id} in test data")
cnt += count_rank_mismatches(test[cell_id], ref[cell_id])
return cnt
def count_rank_mismatches__study(case_study: CaseStudy):
return count_rank_mismatches__matrix(case_study.distances, case_study.distances_gt)