Exemple #1
0
    def uniform_sample(self, n, remove):
        assert n >= 0
        ixs = list(sample_n_k(self.length, n))
        vals = []
        if n > 0:
            for ix in ixs:
                val = self._write(ix, 0.0)
                vals.append(val)

        if not remove:
            for ix, val in zip(ixs, vals):
                self._write(ix, val)

        return ixs, vals
Exemple #2
0
    def uniform_sample(self, n: int,
                       remove: bool) -> Tuple[List[int], List[float]]:
        assert n >= 0
        ixs = list(sample_n_k(self.length, n))
        vals: List[float] = []
        if n > 0:
            for ix in ixs:
                val = self._write(ix, 0.0)
                assert val is not None
                vals.append(val)

        if not remove:
            for ix, val in zip(ixs, vals):
                self._write(ix, val)

        return ixs, vals
Exemple #3
0
 def _uniform_sample_indices_and_probabilities(
         self, n: int) -> Tuple[List[int], List[float]]:
     indices = list(sample_n_k(len(self.data), n))
     probabilities = [1 / len(self)] * len(indices)
     return indices, probabilities
Exemple #4
0
 def sample(self, k):
     return [self[i] for i in sample_n_k(len(self), k)]
Exemple #5
0
 def _uniform_sample_indices_and_probabilities(self, n):
     indices = list(sample_n_k(len(self.data), n))
     probabilities = [1 / len(self)] * len(indices)
     return indices, probabilities
Exemple #6
0
 def test_slow(self):
     self.samples = [sample_n_k(self.n, self.k) for _ in range(10000)]
     self.subtest_total_counts()
     self.subtest_order_counts()
Exemple #7
0
 def test_fast(self):
     self.samples = [sample_n_k(self.n, self.k) for _ in range(200)]
     self.subtest_constraints()