-
Notifications
You must be signed in to change notification settings - Fork 155
/
Copy pathtest_lof.py
67 lines (58 loc) · 1.83 KB
/
test_lof.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
66
67
import lof
instances = (
(1, 1, 1, 1),
(2, 2, 2, 2),
(3, 3, 3, 3),
(2, 1, 1, 1),
(1, 2, 1, 1),
(13, 13, 13, 13)
)
instance = (1, 1, 1, 2)
def test_LOF_normalize_instances():
l = lof.LOF(((1,1),(2,2)), normalize=True)
assert l.instances == [(0.0,0.0),(1.0,1.0)]
l = lof.LOF(((1,1),(2,2),(3,3)), normalize=True)
assert l.instances == [(0.0,0.0),(0.5,0.5),(1.0,1.0)]
def test_distance():
assert 1 == lof.distance_euclidean((1,1), (2,2))
def test_k_distance():
instances = ((1,1),(2,2),(3,3))
d = lof.k_distance(1,(2,2),instances)
assert d == (0.0, [(2,2)])
d = lof.k_distance(1,(2.2,2.2),instances)
assert d == (0.20000000000000018, [(2,2)])
d = lof.k_distance(1,(2.5,2.5),instances)
assert d == (0.5, [(2,2),(3,3)])
d = lof.k_distance(5,(2.2,2.2),instances)
assert d == (1.2000000000000002, [(2, 2), (3, 3), (1, 1)])
def test_reachability_distance():
instances = ((1,1),(2,2),(3,3))
lof.reachability_distance(1, (1,1), (2,2), instances)
def test_outliers():
lof.outliers(1, instances)
def test_normalization_problems():
# see issue https://github.com/damjankuznar/pylof/issues/7
instances = [(1.,2.,3.),(2.,3.,4.),(1.,2.,4.),(1.,2.,1.)]
l = lof.outliers(1, instances)
def test_duplicate_instances():
instances = (
(1, 1, 1, 1),
(2, 2, 2, 2),
(3, 3, 3, 3),
(2, 1, 1, 1),
(1, 2, 1, 1),
(2, 2, 2, 2),
(2, 2, 2, 2),
(1, 1, 1, 1),
(1, 1, 1, 1),
(13, 13, 13, 13)
)
lof.outliers(1, instances)
if __name__ == "__main__":
print("Running tests, nothing more should appear if everything goes well.")
test_LOF_normalize_instances()
test_distance()
test_k_distance()
test_reachability_distance()
test_outliers()
test_normalization_problems()