def test_normal_gaussian_nd(mode, factor, **kwargs): ndim = 3 kwargs["nsteps"] = 8000 # Isotropic. _test_normal( moves.GaussianMove(0.5, factor=factor, mode=mode), ndim=ndim, **kwargs ) # Axis-aligned. _test_normal( moves.GaussianMove(0.5 * np.ones(ndim), factor=factor, mode=mode), ndim=ndim, **kwargs, ) with pytest.raises(ValueError): _test_normal( moves.GaussianMove( 0.5 * np.ones(ndim - 1), factor=factor, mode=mode ), ndim=ndim, **kwargs, ) # Full matrix. if mode == "vector": _test_normal( moves.GaussianMove( np.diag(0.5 * np.ones(ndim)), factor=factor, mode=mode ), ndim=ndim, **kwargs, ) with pytest.raises(ValueError): _test_normal( moves.GaussianMove(np.diag(0.5 * np.ones(ndim - 1))), ndim=ndim, **kwargs, ) else: with pytest.raises(ValueError): _test_normal( moves.GaussianMove( np.diag(0.5 * np.ones(ndim)), factor=factor, mode=mode ), ndim=ndim, **kwargs, )
__all__ = ["test_shapes", "test_errors", "test_thin", "test_vectorize"] all_backends = backends.get_test_backends() def normal_log_prob(params): return -0.5 * np.sum(params**2) @pytest.mark.parametrize( "backend, moves", product( all_backends, [ None, moves.GaussianMove(0.5), [moves.StretchMove(), moves.GaussianMove(0.5)], [(moves.StretchMove(), 0.3), (moves.GaussianMove(0.5), 0.1)], ], ), ) def test_shapes(backend, moves, nwalkers=32, ndim=3, nsteps=10, seed=1234): # Set up the random number generator. np.random.seed(seed) with backend() as be: # Initialize the ensemble, moves and sampler. coords = np.random.randn(nwalkers, ndim) sampler = EnsembleSampler(nwalkers, ndim, normal_log_prob,
def test_uniform_gaussian(mode, factor, **kwargs): _test_uniform(moves.GaussianMove(0.5, factor=factor, mode=mode), **kwargs)
def test_normal_gaussian(mode, factor, **kwargs): _test_normal(moves.GaussianMove(0.5, mode=mode, factor=factor), **kwargs)