-
Notifications
You must be signed in to change notification settings - Fork 12
/
boundary_test.py
119 lines (103 loc) · 3.55 KB
/
boundary_test.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
'''
Tests boundary similarity (B).
.. moduleauthor:: Chris Fournier <chris.m.fournier@gmail.com>
'''
import unittest
from decimal import Decimal
from .boundary import boundary_similarity
from .weight import weight_a, weight_s, weight_t
from ..format import BoundaryFormat
from ..util import SegmentationMetricError
from ..compute import summarize
from ..data.samples import (MULTIPLE_BOUNDARY_TYPES, HEARST_1997_STARGAZER,
HYPOTHESIS_STARGAZER)
class TestBoundary(unittest.TestCase):
'''
Test segmenation boundary comparison functions.
'''
def test_fn(self):
'''
Test false negative.
'''
value = boundary_similarity([2, 3, 6], [5, 6])
self.assertEqual(0.5, value)
def test_fp(self):
'''
Test false negative.
'''
value = boundary_similarity([2, 3, 6], [2, 3, 3, 3])
self.assertAlmostEquals(Decimal('0.66666'), value, 4)
def test_near_miss(self):
'''
Test near miss.
'''
value = boundary_similarity([2, 3, 6], [2, 2, 7])
self.assertEqual(0.75, value)
def test_one_minus(self):
'''
Test one minus.
'''
value = boundary_similarity([2, 3, 6], [2, 2, 7], one_minus=True)
self.assertEqual(Decimal('0.25'), value)
def test_clustered_fps(self):
'''
Test clustered fps.
'''
value = boundary_similarity([2, 3, 6], [1, 1, 3, 1, 5])
self.assertEqual(0.5, value)
def test_positions(self):
'''
Test false negative.
'''
a = [1,1,1,1,1,1,1,1,1,1,1,1,1]
b = [1,1,1,1,2,2,2,2,3,3,3,3,3]
value = boundary_similarity(a, b, boundary_format=
BoundaryFormat.position)
self.assertEqual(0, value)
def test_format_exception(self):
'''
Test false negative.
'''
a = [1,1,1,1,1,1,1,1,1,1,1,1,1]
b = [1,1,1,1,2,2,2,2,3,3,3,3,3]
self.assertRaises(SegmentationMetricError, boundary_similarity, a, b,
boundary_format=None)
def test_arg_exception(self):
'''
Test false negative.
'''
a = [1,1,1,1,1,1,1,1,1,1,1,1,1]
b = [1,1,1,1,2,2,2,2,3,3,3,3,3]
c = 0
self.assertRaises(SegmentationMetricError, boundary_similarity, a, b,
c)
def test_weight_t(self):
'''
Test false negative.
'''
value = boundary_similarity([2, 3, 6], [5, 6],
weight=(weight_a, weight_s, weight_t))
self.assertEqual(0.5, value)
def test_multiple_boundary_types(self):
'''
Test false negative.
'''
value = summarize(boundary_similarity(MULTIPLE_BOUNDARY_TYPES))
self.assertEqual((0.375,
0.125,
0.015625,
Decimal('0.08838834764831844055010554528'),
2),
value)
def test_b_datasets(self):
'''
Test B upon two datasets.
'''
hypothesis = HYPOTHESIS_STARGAZER
reference = HEARST_1997_STARGAZER
value = boundary_similarity(hypothesis, reference)
# Precision
self.assertAlmostEquals(float(value['stargazer,h1,1']), 0.57142857)
self.assertAlmostEquals(float(value['stargazer,h2,1']), 0.38888888)
self.assertAlmostEquals(float(value['stargazer,h1,2']), 0.42857142)
self.assertAlmostEquals(float(value['stargazer,h2,2']), 0.33333333)