def test_equal_sizes_trivial_overlap(self): data = communicate({'0': 10000, '1': 10000}, {'0': 0.0, '1': 0.0}) mi_est1 = wke(data).calculate_mi(k=NN_K) mi_est2 = plain_calculate_mi(data=data, k=NN_K) mi_exact = 0.0 self.assertAlmostEqual(mi_est1, mi_exact, delta=ATOL) self.assertAlmostEqual(mi_est1, mi_est2, delta=ATOL)
def test_unequal_sizes(self): data = communicate({'0': 5000, '1': 10000}, {'0': 0.0, '1': 1.0}) mi_est1 = wke(data).calculate_mi(k=NN_K) mi_est2 = plain_calculate_mi(data=data, k=NN_K) mi_exact = -(log2(2 / 3) * 2 / 3 + log2(1 / 3) * 1 / 3) self.assertAlmostEqual((mi_est1 - mi_exact) / mi_exact, 0, delta=RTOL) self.assertAlmostEqual((mi_est1 - mi_est2) / mi_exact, 0, delta=RTOL)
def test_unequal_sizes(self): data = communicate({'A': 2500, 'B': 5000}, {'A': 0.0, 'B': 1.0}) cap_est, opt_ws = wke(data).calculate_maximized_mi(k=NN_K) cap_exact = 1.0 self.assertAlmostEqual((cap_est - cap_exact) / cap_exact, 0, delta=RTOL) self.assertAlmostEqual(opt_ws['A'], 0.5, delta=ATOL) self.assertAlmostEqual(opt_ws['B'], 0.5, delta=ATOL)
def test_equal_sizes(self): data = communicate(input_counts={ 'A': 5000, 'B': 5000 }, output_values={ 'A': 0.0, 'B': 1.0 }) weights = {'A': 1 / 3, 'B': 2 / 3} mi_est = wke(data).calculate_weighted_mi(weights, k=NN_K) mi_exact = -(log2(2 / 3) * 2 / 3 + log2(1 / 3) * 1 / 3) self.assertAlmostEqual((mi_est - mi_exact) / mi_exact, 0, delta=RTOL)
def test_equal_sizes_trivial_separate(self): data = communicate(input_counts={ '0': 10000, '1': 10000 }, output_values={ '0': 0.0, '1': 1.0 }) mi_est1 = wke(data).calculate_mi(k=NN_K) mi_est2 = plain_calculate_mi(data=data, k=NN_K) mi_exact = 1.0 self.assertAlmostEqual((mi_est1 - mi_exact) / mi_exact, 0, delta=RTOL) self.assertAlmostEqual((mi_est1 - mi_est2) / mi_est2, 0, delta=RTOL)
def test_output_overlap(self): data = communicate({ 'A': 2500, 'B': 2500, 'C': 2500 }, { 'A': 0, 'B': 0, 'C': 1 }) weights = {'A': 1 / 3, 'B': 1 / 3, 'C': 1 / 3} mi_est = wke(data).calculate_weighted_mi(weights, k=NN_K) mi_exact = -(log2(2 / 3) * 2 / 3 + log2(1 / 3) * 1 / 3) self.assertAlmostEqual((mi_est - mi_exact) / mi_exact, 0, delta=RTOL)
def test_equal_sizes_partial_overlap(self): data = communicate({ 'A': 2500, 'B': 2500, 'C': 2500 }, { 'A': 0, 'B': 0, 'C': 1 }) cap_est, opt_ws = wke(data).calculate_maximized_mi(k=NN_K) cap_exact = 1.0 self.assertAlmostEqual((cap_est - cap_exact) / cap_exact, 0, delta=RTOL) self.assertAlmostEqual(opt_ws['C'], 0.5, delta=ATOL)
def test_unequal_sizes_trivial_overlap(self): data = communicate({'A': 2500, 'B': 5000}, {'A': 0.0, 'B': 0.0}) weights = {'A': 1 / 2, 'B': 1 / 2} mi_est = wke(data).calculate_weighted_mi(weights, k=NN_K) mi_exact = 0.0 self.assertAlmostEqual(mi_est, mi_exact, delta=ATOL)
def test_unequal_sizes(self): data = communicate({'A': 2500, 'B': 5000}, {'A': 0.0, 'B': 1.0}) weights = {'A': 1 / 2, 'B': 1 / 2} mi_est = wke(data).calculate_weighted_mi(weights, k=NN_K) mi_exact = 1.0 self.assertAlmostEqual((mi_est - mi_exact) / mi_exact, 0, delta=RTOL)