Exemplo n.º 1
0
def split(rng: np.random.RandomState, n: int, k: int, eps: float) -> List[int]:
    probs = [1 / (n + 1) - eps for _ in range(n + 2)]
    divisors: List[int] = []
    for i, m in enumerate(rng.multinomial(k - 1, probs)):
        for _ in range(m):
            divisors.append(i)
    last = 0
    ks = []
    for divisor in divisors:
        ks.append(divisor - last)
        last = divisor
    ks.append(n - last)
    return ks
Exemplo n.º 2
0
    def _sample(self, rng: np.random.RandomState, n_samples: int) -> np.ndarray:
        """
        The method to sample from the parzen estimator.
        This method needs to be wrapped by a child class.

        Args:
            rng (np.random.RandomState): The random seed
            n_samples (int): The number of samples

        Returns:
            samples (np.ndarray):
                Samples from the parzen estimator.
                The shape is (n_samples, ).
        """
        samples = [
            self.basis[active].sample(rng)
            for active in np.argmax(
                rng.multinomial(n=1, pvals=self.weights, size=n_samples),
                axis=-1
            )
        ]
        return np.array(samples, dtype=self.dtype)