Beispiel #1
0
def test_simple_gmm_data():
    test_data = data_gen_helper(100, 2)
    test_labels = np.random.choice([0, 1], size=100, p=[1. / 2, 1. / 2])
    test_ron_gauss_instance = ron_gauss.RONGauss(algorithm="gmm")
    dp_data = test_ron_gauss_instance.generate_dpdata(test_data, 1,
                                                      test_labels)
    assert normality_test_helper(dp_data)
Beispiel #2
0
def test_normalize_sample_wise():
    number_of_trials = 30
    for i in range(number_of_trials):
        test_data = np.random.normal(size=(100, 10))
        benchmark = preprocessing.normalize(test_data)
        new_implementation = ron_gauss.RONGauss()._normalize_sample_wise(
            test_data)
        assert (np.abs(new_implementation - benchmark) < 1e-15).all()
Beispiel #3
0
def test_data_preprocessing():
    test_data = np.load('./tests/test_data/test_data_preprocessing.npz')
    input = test_data['input']
    output = test_data['output']
    prng = np.random.RandomState(seed=7)
    x_bar, mu_dp = ron_gauss.RONGauss()._data_preprocessing(input,
                                                            epsilon_mean=1.0,
                                                            prng=prng)
    assert check_element_diff(output[0], x_bar) and check_element_diff(
        output[1], mu_dp)
Beispiel #4
0
def test_simple_supervised_data():
    test_data = data_gen_helper(1000, 3)
    test_labels = np.random.choice([0, 1], size=1000, p=[1. / 2, 1. / 2])
    test_ron_gauss_instance = ron_gauss.RONGauss(algorithm="supervised")
    # Implicit testing of successful execution with "supervised" option.
    dp_data = test_ron_gauss_instance.generate_dpdata(X=test_data,
                                                      dimension=2,
                                                      y=test_labels,
                                                      maxY=np.array(1))
    assert normality_test_helper(dp_data)
Beispiel #5
0
def test_dimensionality_agnostic_execution():
    for i in np.arange(2, 101):
        rand_num_pts = np.random.randint(100) + 100
        # Generate a random number of normally distributed data points in
        # the range of 101-200 in i dimensions.
        test_data = data_gen_helper(rand_num_pts, i)
        # Simulate DP-safe lower dimensionality data.
        test_ron_gauss_instance = ron_gauss.RONGauss(algorithm="unsupervised")
        dims_reduced = int(np.ceil((i - 1) * (rand_num_pts / 200)))
        dp_data = test_ron_gauss_instance.generate_dpdata(
            test_data, dims_reduced)
        # Test dimensions are as expected.
        assert dp_data[0].shape[0] == rand_num_pts
        assert dp_data[0].shape[1] == dims_reduced

        # Test that the reconstruct parameter is working regardless of projection dimension
        dp_data = test_ron_gauss_instance.generate_dpdata(test_data,
                                                          dims_reduced,
                                                          reconstruct=True)
        # Test dimensions are as expected.
        assert dp_data[0].shape[0] == rand_num_pts
        assert dp_data[0].shape[1] == i
Beispiel #6
0
def test_simple_unsupervised_data():
    test_data = data_gen_helper(100, 2)
    test_ron_gauss_instance = ron_gauss.RONGauss(algorithm="unsupervised")
    dp_data = test_ron_gauss_instance.generate_dpdata(test_data, 1)
    assert normality_test_helper(dp_data)
Beispiel #7
0
def test_defaults():
    test_ron_gauss_instance = ron_gauss.RONGauss()
    assert (test_ron_gauss_instance.algorithm == "supervised")
    assert (test_ron_gauss_instance.epsilonCov == 1.0)
    assert (test_ron_gauss_instance.epsilonMean == 1.0)