コード例 #1
0
 def test_load_from_private_reader_path_connect(self):
     priv = PrivateReader.from_connection(pums,
                                          privacy=privacy,
                                          metadata=meta_path)
     assert (isinstance(priv.reader, PandasReader))
     res = priv.execute("SELECT COUNT(age) FROM PUMS.PUMS GROUP BY sex")
     assert (len(res) == 3)
コード例 #2
0
 def test_count_query(self):
     priv = PrivateReader.from_connection(pums,
                                          privacy=privacy,
                                          metadata=meta_path)
     assert (priv.odometer.spent == (0.0, 0.0))
     assert (priv.odometer.k == 0)
     res = priv.execute("SELECT COUNT(age) FROM PUMS.PUMS GROUP BY educ")
     assert (priv.odometer.k == 2)
コード例 #3
0
 def test_count_query(self):
     priv = PrivateReader.from_connection(pums,
                                          privacy=privacy,
                                          metadata=meta_path)
     res = priv._get_mechanism_costs(
         "SELECT COUNT(age) FROM PUMS.PUMS GROUP BY educ")
     res = [r for r in res if r]
     assert (len(res) == 2)
コード例 #4
0
 def test_variance(self):
     meta_obj['PUMS.PUMS'].row_privacy = True
     meta_obj['PUMS.PUMS']['pid'].is_key = False
     meta_obj['PUMS.PUMS'].censor_dims = True
     priv = PrivateReader.from_connection(pums,
                                          privacy=privacy,
                                          metadata=meta_obj)
     res = priv.execute("SELECT VAR(age) FROM PUMS.PUMS GROUP BY educ")
     assert (priv.odometer.k == 3)
コード例 #5
0
 def test_count_row_privacy(self):
     meta_obj['PUMS.PUMS'].row_privacy = True
     meta_obj['PUMS.PUMS']['pid'].is_key = False
     priv = PrivateReader.from_connection(pums,
                                          privacy=privacy,
                                          metadata=meta_obj)
     assert (priv.odometer.spent == (0.0, 0.0))
     assert (priv.odometer.k == 0)
     res = priv.execute("SELECT COUNT(*) FROM PUMS.PUMS GROUP BY educ")
     assert (priv.odometer.k == 1)
コード例 #6
0
 def test_count_row_privacy(self):
     meta_obj['PUMS.PUMS'].row_privacy = True
     meta_obj['PUMS.PUMS']['pid'].is_key = False
     priv = PrivateReader.from_connection(pums,
                                          privacy=privacy,
                                          metadata=meta_obj)
     res = priv._get_mechanism_costs(
         "SELECT COUNT(*) FROM PUMS.PUMS GROUP BY educ")
     res = [r for r in res if r]
     assert (len(res) == 1)
コード例 #7
0
 def test_sum(self):
     meta_obj['PUMS.PUMS'].row_privacy = True
     meta_obj['PUMS.PUMS']['pid'].is_key = False
     meta_obj['PUMS.PUMS'].censor_dims = True
     priv = PrivateReader.from_connection(pums,
                                          privacy=privacy,
                                          metadata=meta_obj)
     res = priv._get_mechanism_costs(
         "SELECT SUM(age) FROM PUMS.PUMS GROUP BY educ")
     res = [r for r in res if r]
     assert (len(res) == 2)
コード例 #8
0
 def test_count_row_privacy_col_quantifier(self):
     meta_obj['PUMS.PUMS'].row_privacy = True
     meta_obj['PUMS.PUMS']['pid'].is_key = False
     meta_obj['PUMS.PUMS'].censor_dims = True
     priv = PrivateReader.from_connection(pums,
                                          privacy=privacy,
                                          metadata=meta_obj)
     assert (priv.odometer.spent == (0.0, 0.0))
     assert (priv.odometer.k == 0)
     res = priv.execute(
         "SELECT COUNT(DISTINCT age) FROM PUMS.PUMS GROUP BY educ")
     assert (priv.odometer.k == 2)
コード例 #9
0
 def test_two_var(self):
     meta_obj['PUMS.PUMS'].row_privacy = True
     meta_obj['PUMS.PUMS']['pid'].is_key = False
     meta_obj['PUMS.PUMS'].censor_dims = True
     priv = PrivateReader.from_connection(pums,
                                          privacy=privacy,
                                          metadata=meta_obj)
     query = "SELECT VAR(age), VAR(income) FROM PUMS.PUMS GROUP BY sex"
     res = priv._get_mechanism_costs(query)
     res = [r for r in res if r]
     assert (len(res) == 5)
     eps, _ = priv.get_privacy_cost(query)
     assert (eps <= 5.0)
コード例 #10
0
 def test_load_from_private_reader_path(self):
     reader = PandasReader(pums, meta_path)
     priv = PrivateReader(reader, meta_path, privacy=Privacy(epsilon=1.0))
     res = priv.execute("SELECT COUNT(age) FROM PUMS.PUMS GROUP BY sex")
     assert (len(res) == 3)