Esempio n. 1
0
    def test_sample_constant_distribution(self):
        """Returns a constant sample distribution."""
        constant_dist = Distribution(dist_type="constant", constant=1)
        sample = constant_dist.sample(5)
        expected_sample = constant_dist.constant*ones(5)

        assert all(sample == expected_sample)
Esempio n. 2
0
    def test_sample_None_distribution(self):
        """Returns a None sample distribution."""
        None_dist = Distribution(dist_type=None)
        sample = None_dist.sample(size=10)
        expected_sample = full(10, None)

        assert all(sample == expected_sample)
Esempio n. 3
0
    def test_sample_numpy_distribution(self):
        """Returns a numpy sample distribution."""
        numpy_dist = Distribution(
            dist_type="numpy",
            dist_name="beta",
            a=1, b=1
            )

        sample = numpy_dist.sample(5)
        expected = random.default_rng(seed=numpy_dist.seed).beta(1, 1, 5)

        assert all(sample == expected)
Esempio n. 4
0
    def test_sample_weights_distribution_data(
        self,
        fixture_weights_distribution
    ):
        """Returns a weights sample distribution from a data array."""
        weights_dist = Distribution(
            dist_type="weights",
            data=pytest.data_2D
            )

        sample = weights_dist.sample(5)
        expected_sample = random.default_rng(int(time())).choice(
            a=pytest.data_2D[:, 0],
            p=pytest.data_2D[:, 1],
            size=5
            )

        assert all(sample == expected_sample)
Esempio n. 5
0
    def test_sample_empirical_distribution_file(
        self,
        fixture_empirical_distribution
    ):
        """Returns an empirical sample distribution from a file."""
        empirical_dist = Distribution(
            dist_type="empirical",
            data=pytest.data_1D,
            kernel="gaussian",
            bandwidth=0.1
            )

        sample = empirical_dist.sample(5)

        expected_sample = KernelDensity(
            kernel="gaussian",
            bandwidth=0.1
            ).fit(pytest.data_1D.reshape(-1, 1)).sample(
                n_samples=5, random_state=int(time())
                ).flatten()

        assert all(sample == expected_sample)