def __init__(self,
                 threshold,
                 eps,
                 delta,
                 sampling_method,
                 pickle_dir,
                 print_progress=True):
        self.sample = private_sampling.PrivateThresholdSampleWithFrequencies(
            threshold, eps, delta, sampling_method, store_every=1)
        file_name = "private_sampling_%s_t%s_e%s_d%s" % (
            sampling_method.__name__, threshold, eps, 1 / delta)
        self.file_path = os.path.join(pickle_dir, file_name)
        self.print_progress = print_progress

        if os.path.exists(self.file_path):
            self._load()
  def test_valid_reported_frequency_distribution(self):
    """Checks that the distribution of reported frequencies is valid.

    Computes the distribution of frequencies that are reported (when computing
    a private sample) and checks that it is valid: all probabilities are between
    0 and 1, and they sum up to 1.
    """
    s = private_sampling.PrivateThresholdSampleWithFrequencies(
        threshold=0.5, eps=0.1, delta=0.5**20)
    freq_dists = [
        s.compute_reported_frequency_dist(i) for i in range(100, 1001, 100)
    ]
    for dist in freq_dists:
      self.assertAlmostEqual(sum(dist.values()), 1.0)
      for x in dist.values():
        self.assertGreaterEqual(x, 0.0)