From 608afef6fb69129730f4c18d0e42f5a8ac2078a7 Mon Sep 17 00:00:00 2001 From: Xi Wang Date: Fri, 31 Jul 2020 02:30:25 +0800 Subject: [PATCH] Fix dirichlet flaky tests (#18817) * make parameter smoother * minor changes --- tests/python/unittest/test_gluon_probability_v1.py | 12 ++++++------ tests/python/unittest/test_gluon_probability_v2.py | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/python/unittest/test_gluon_probability_v1.py b/tests/python/unittest/test_gluon_probability_v1.py index c0dd5d54ab9f..0fece99bb6d7 100644 --- a/tests/python/unittest/test_gluon_probability_v1.py +++ b/tests/python/unittest/test_gluon_probability_v1.py @@ -341,7 +341,7 @@ def hybrid_forward(self, F, loc, scale, *args): for shape, hybridize in itertools.product(shapes, [True, False]): loc = np.random.uniform(-1, 1, shape) scale = np.random.uniform(0.5, 1.5, shape) - samples = np.random.uniform(size=shape, high=1.0-1e-4) + samples = np.random.uniform(size=shape, low=1e-4, high=1.0-1e-4) net = TestCauchy("icdf") if hybridize: net.hybridize() @@ -837,7 +837,7 @@ def hybrid_forward(self, F, alpha, *args): dirichlet = mgp.Dirichlet(alpha, F, validate_args=True) return _distribution_method_invoker(dirichlet, self._func, *args) - event_shapes = [2, 5, 10] + event_shapes = [2, 4, 6] batch_shapes = [None, (2, 3)] # Test sampling @@ -845,7 +845,7 @@ def hybrid_forward(self, F, alpha, *args): for hybridize in [True, False]: desired_shape = ( batch_shape if batch_shape is not None else ()) + (event_shape,) - alpha = np.random.uniform(size=desired_shape) + alpha = np.random.uniform(1.0, 5.0, size=desired_shape) net = TestDirichlet("sample") if hybridize: net.hybridize() @@ -862,9 +862,9 @@ def hybrid_forward(self, F, alpha, *args): for hybridize in [True, False]: desired_shape = ( batch_shape if batch_shape is not None else ()) + (event_shape,) - alpha = np.random.uniform(size=desired_shape) + alpha = np.random.uniform(1.0, 5.0, desired_shape) np_samples = _np.random.dirichlet( - [1 / event_shape] * event_shape, size=batch_shape) + [10.0 / event_shape] * event_shape, size=batch_shape) net = TestDirichlet("log_prob") if hybridize: net.hybridize() @@ -879,7 +879,7 @@ def hybrid_forward(self, F, alpha, *args): for func in ['mean', 'variance', 'entropy']: desired_shape = ( batch_shape if batch_shape is not None else ()) + (event_shape,) - alpha = np.random.uniform(size=desired_shape) + alpha = np.random.uniform(1.0, 5.0, desired_shape) net = TestDirichlet(func) if hybridize: net.hybridize() diff --git a/tests/python/unittest/test_gluon_probability_v2.py b/tests/python/unittest/test_gluon_probability_v2.py index ecce63c50e1d..dc8ac1476ea9 100644 --- a/tests/python/unittest/test_gluon_probability_v2.py +++ b/tests/python/unittest/test_gluon_probability_v2.py @@ -837,7 +837,7 @@ def forward(self, alpha, *args): dirichlet = mgp.Dirichlet(alpha, validate_args=True) return _distribution_method_invoker(dirichlet, self._func, *args) - event_shapes = [2, 5, 10] + event_shapes = [2, 4, 6] batch_shapes = [None, (2, 3)] # Test sampling @@ -845,7 +845,7 @@ def forward(self, alpha, *args): for hybridize in [True, False]: desired_shape = ( batch_shape if batch_shape is not None else ()) + (event_shape,) - alpha = np.random.uniform(size=desired_shape) + alpha = np.random.uniform(1.0, 5.0, size=desired_shape) net = TestDirichlet("sample") if hybridize: net.hybridize() @@ -862,9 +862,9 @@ def forward(self, alpha, *args): for hybridize in [True, False]: desired_shape = ( batch_shape if batch_shape is not None else ()) + (event_shape,) - alpha = np.random.uniform(size=desired_shape) + alpha = np.random.uniform(1.0, 5.0, size=desired_shape) np_samples = _np.random.dirichlet( - [1 / event_shape] * event_shape, size=batch_shape) + [10.0 / event_shape] * event_shape, size=batch_shape) net = TestDirichlet("log_prob") if hybridize: net.hybridize() @@ -879,7 +879,7 @@ def forward(self, alpha, *args): for func in ['mean', 'variance', 'entropy']: desired_shape = ( batch_shape if batch_shape is not None else ()) + (event_shape,) - alpha = np.random.uniform(size=desired_shape) + alpha = np.random.uniform(1.0, 5.0, desired_shape) net = TestDirichlet(func) if hybridize: net.hybridize()