Пример #1
0
    def test_sample_positive_constant_distribution(self):
        """Returns a constant positive sample distribution."""
        constant_dist = Distribution(dist_type="constant", constant=1)
        sample = constant_dist.sample_positive()
        expected = constant_dist.constant*ones(1)

        assert sample == expected
Пример #2
0
    def test_sample_positivie_numpy(self):
        """Returns a numpy positive sample distribution."""
        numpy_dist = Distribution(
            dist_type="numpy",
            dist_name="normal",
            loc=-10, scale=0.2
            )

        sample = numpy_dist.sample_positive()
        expected = abs(
            random.default_rng(
                seed=numpy_dist.seed
                ).normal(-10, 0.2)
            )

        assert sample == expected
Пример #3
0
    def test_sample_positive_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_positive(5)
        expected_sample = abs(
            random.default_rng(int(time())).choice(
                a=pytest.data_2D[:, 0], p=pytest.data_2D[:, 1], size=5
                )
            )

        assert all(sample == expected_sample)
Пример #4
0
    def test_sample_positive_empirical_distribution_file(
        self,
        fixture_empirical_distribution
    ):
        """Returns an empirical sample distribution from a file."""
        empirical_dist = Distribution(
            dist_type="empirical",
            filename=pytest.filename,
            kernel="gaussian",
            bandwidth=0.1
            )

        sample = empirical_dist.sample_positive(5)

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

        assert all(sample == expected_sample)