-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmetrics.py
More file actions
37 lines (31 loc) · 818 Bytes
/
metrics.py
File metadata and controls
37 lines (31 loc) · 818 Bytes
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
"""
Metrics for measuring performance of models.
"""
def is_permutation(a, b):
"""
Returns if a and b are permutations of one another.
"""
if len(a) != len(b):
return False
member = [True for _ in range(len(a))]
for item in a:
found = False
for i in range(len(b)):
if item == b[i] and member[i]:
member[i], found = False, True
break
if not found:
return False
return not any(member)
def nondecreasing(a):
"""
Returns # of pairs of elements of a not in nondecreasing order.
"""
incorrect = 0
for i in range(len(a) - 1):
if a[i] > a[i+1]:
incorrect += 1
return incorrect
if __name__ == "__main__":
from tests.metrics import run_tests
run_tests()