-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpartition.py
66 lines (59 loc) · 1.98 KB
/
partition.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
import unittest
from src.dataset import ObliviousDataset, Sample
from src.partition import partition_continuous, partition_binary
from src.secint import secint as s
from tests.reveal import reveal
def sample(*inputs):
return Sample(list(inputs), s(0))
class PartitionTests(unittest.TestCase):
def test_partition_on_continuous_attribute(self):
data = ObliviousDataset.create(
sample(s(1), s(3), s(3), s(1)),
sample(s(3), s(1), s(3), s(3)),
sample(s(1), s(1), s(1), s(3))
)
left, right = partition_continuous(
data, attribute_index=s(2), threshold=s(2))
self.assertEqual(
reveal(left),
[
Sample([1, 1, 1, 3], 0)
]
)
self.assertEqual(
reveal(right),
[
Sample([1, 3, 3, 1], 0),
Sample([3, 1, 3, 3], 0)
]
)
def test_partition_on_continuous_attribute_partial_dataset(self):
data = ObliviousDataset.create(
sample(s(1), s(3), s(3), s(1)),
sample(s(3), s(1), s(3), s(3)),
sample(s(1), s(1), s(1), s(3))
).select([s(1), s(0), s(0)])
left, right = partition_continuous(
data, attribute_index=s(2), threshold=s(2))
self.assertEqual(reveal(left), [])
self.assertEqual(reveal(right), [Sample([1, 3, 3, 1], 0)])
def test_partition_on_binary_attribute(self):
data = ObliviousDataset.create(
sample(s(0), s(1), s(1), s(0)),
sample(s(1), s(0), s(1), s(1)),
sample(s(0), s(0), s(0), s(1))
)
left, right = partition_binary(data, attribute_index=s(2))
self.assertEqual(
reveal(left),
[
Sample([0, 0, 0, 1], 0)
]
)
self.assertEqual(
reveal(right),
[
Sample([0, 1, 1, 0], 0),
Sample([1, 0, 1, 1], 0)
]
)