Пример #1
0
def test_private_numerical_hist(example_private_table: PrivateTable):
    """check private hist implementation for numerical column.
    bins:         |.......|.......|.......|
    boundaries:   a0      a1      a2      a3

    """
    bins: List[float] = [20, 30, 40, 50]  # [a0, a1, a2, a3]
    noisy_hist = example_private_table.num_hist('Age', bins,
                                                PrivacyBudget(10000.))
    err = [1, 1, 1]
    noisy_hist.sort()
    assert all(np.abs(noisy_hist - [1, 1, 2]) < err)
    del noisy_hist, bins
Пример #2
0
def test_private_numerical_hist(example_private_table: PrivateTable):
    """check private hist implementation for numerical column of Age in adult dataset.
    bins:         17, 18, 19 ... 90

    """
    bins: List[float] = [int(i) for i in range(17, 91)]
    noisy_hist = example_private_table.num_hist('Age', bins,
                                                PrivacyBudget(10000.))
    err = [int(1) for i in range(1, 74)]
    noisy_hist.sort()
    assert all(
        np.abs(noisy_hist - [
            1, 1, 3, 3, 6, 10, 12, 20, 22, 22, 23, 29, 43, 45, 46, 51, 64, 67,
            72, 89, 108, 120, 150, 151, 178, 208, 230, 258, 300, 312, 355, 358,
            366, 366, 395, 415, 419, 464, 478, 543, 550, 577, 595, 602, 708,
            712, 720, 724, 734, 737, 753, 765, 770, 780, 785, 794, 798, 808,
            813, 816, 827, 828, 835, 841, 858, 861, 867, 875, 876, 877, 886,
            888, 898
        ]) < err)
    del noisy_hist, bins