예제 #1
0
 def column(self, index):
     if isinstance(index, Share):
         is_selected = mpc.unit_vector(index, self.number_of_attributes)
         return self.map(lambda sample: ObliviousArray.create(sample.inputs)
                         .select(is_selected).sum())
     else:
         return self.map(lambda sample: sample.inputs[index])
예제 #2
0
 def create(cls, *samples, continuous=None, labels=None):
     samples = ObliviousArray.create(samples)
     number_of_attributes = len(samples[0]) if len(samples) > 0 else 0
     if not continuous:
         continuous = [False for i in range(number_of_attributes)]
     if not labels:
         labels = [secint(i) for i in range(number_of_attributes)]
     return ObliviousDataset(samples, number_of_attributes, continuous,
                             labels)
예제 #3
0
 def test_getitem_with_secret_index(self):
     array = ObliviousArray.create(s(10), s(20), s(30))
     item = array.getitem(s(1))
     self.assertEqual(reveal(item), 20)
예제 #4
0
 def test_initialize_with_list(self):
     self.assertEqual(reveal(ObliviousArray.create(s(1), s(2))),
                      reveal(ObliviousArray([s(1), s(2)])))
     self.assertEqual(reveal(ObliviousArray.create(s(1))),
                      reveal(ObliviousArray([s(1)])))
예제 #5
0
 def test_sum_on_selected_elements(self):
     array = ObliviousArray.create(s(10), s(20), s(30))
     array = array.select(s(1), s(0), s(1))
     sum = array.sum()
     self.assertEqual(reveal(sum), 40)
예제 #6
0
 def test_len_of_subset(self):
     dataset = ObliviousArray.create(s(0), s(1), s(2))
     dataset = dataset.select(s(1), s(0), s(1))
     self.assertEqual(reveal(dataset.len()), 2)
예제 #7
0
 def is_continuous(self, attribute_index):
     if isinstance(attribute_index, Share):
         continuous = ObliviousArray(list(map(secint, self.continuous)))
         return continuous.getitem(attribute_index)
     else:
         return self.continuous[attribute_index]
예제 #8
0
def sort_array(column, outcomes):
    values, outcome_values = sort_lists(column.values, outcomes.values)
    return (ObliviousArray(values), ObliviousArray(outcome_values))
예제 #9
0
 def test_map_on_selected_elements(self):
     array = ObliviousArray.create(s(10), s(20), s(30))
     array = array.select(s(1), s(0), s(1))
     array = array.map(lambda x: 2 * x)
     self.assertEqual(reveal(array), [20, 60])
예제 #10
0
 def test_map(self):
     array = ObliviousArray.create(s(10), s(20), s(30))
     array = array.map(lambda x: 2 * x)
     self.assertEqual(reveal(array), [20, 40, 60])
예제 #11
0
 def test_select_with_selection_as_argument(self):
     array = ObliviousArray.create(s(10), s(20), s(30))
     included = ObliviousArray.create(s(1), s(0), s(1))
     included = included.select(s(0), s(0), s(1))
     array = array.select(included)
     self.assertEqual(reveal(array), [30])
예제 #12
0
 def test_select_and_select_again(self):
     array = ObliviousArray.create(s(10), s(20), s(30))
     array = array.select(s(1), s(0), s(1))
     array = array.select(s(0), s(1), s(1))
     self.assertEqual(reveal(array), [30])
예제 #13
0
 def test_reveal_selected_elements(self):
     array = ObliviousArray.create(s(10), s(20), s(30))
     array = array.select(s(0), s(1), s(0))
     self.assertEqual(reveal(array), [20])
예제 #14
0
 def test_reveal_all_elements(self):
     array = ObliviousArray.create(s(10), s(20), s(30))
     self.assertEqual(reveal(array), [10, 20, 30])
예제 #15
0
 def test_getitem_on_selected_elements(self):
     array = ObliviousArray.create(s(10), s(20), s(30))
     selection = array.select(s(1), s(0), s(1))
     self.assertEqual(reveal(selection.getitem(s(0))), 10)
     self.assertEqual(reveal(selection.getitem(s(1))), 0)
     self.assertEqual(reveal(selection.getitem(s(2))), 30)
예제 #16
0
def arr(*values):
    return ObliviousArray([*values])
예제 #17
0
 def test_reduce(self):
     array = ObliviousArray.create(s(10), s(20), s(30))
     product = array.reduce(s(1), operator.mul)
     self.assertEqual(reveal(product), 6000)
예제 #18
0
 def test_reduce_on_selected_elements(self):
     array = ObliviousArray.create(s(10), s(20), s(30))
     array = array.select(s(1), s(0), s(1))
     product = array.reduce(s(1), operator.mul)
     self.assertEqual(reveal(product), 300)
예제 #19
0
 def test_reduce_with_initial_value(self):
     array = ObliviousArray.create()
     product = array.reduce(s(1), operator.mul, initial=s(42))
     self.assertEqual(reveal(product), 42)
예제 #20
0
 def label(self, attribute_index):
     labels = ObliviousArray(self.labels)
     return labels.getitem(attribute_index)
예제 #21
0
 def test_sum(self):
     array = ObliviousArray.create(s(10), s(20), s(30))
     sum = array.sum()
     self.assertEqual(reveal(sum), 60)
예제 #22
0
def select_best_attribute(samples):
    (gains, thresholds) = calculate_gains(samples)
    (_, index) = maximum(ObliviousArray.create(gains))
    threshold = ObliviousArray(thresholds).getitem(index)
    return (index, threshold)
예제 #23
0
 def test_len(self):
     self.assertEqual(reveal(ObliviousArray.create().len()), 0)
     self.assertEqual(reveal(ObliviousArray([s(0), s(1), s(2)]).len()), 3)