How to use the emcee.backends.get_test_backends function in emcee

To help you get started, we’ve selected a few emcee examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dfm / emcee / tests / unit / test_backends.py View on Github external
from __future__ import division, print_function

import os
from itertools import product

import numpy as np

import pytest

from emcee import backends, EnsembleSampler

import h5py

__all__ = ["test_backend", "test_reload"]

all_backends = backends.get_test_backends()
other_backends = all_backends[1:]
dtypes = [
    None,
    [("log_prior", float), ("mean", int)]
]


def normal_log_prob(params):
    return -0.5 * np.sum(params**2)


def normal_log_prob_blobs(params):
    return normal_log_prob(params), 0.1, int(5)


def run_sampler(backend, nwalkers=32, ndim=3, nsteps=25, seed=1234, thin_by=1,
github dfm / emcee / tests / unit / test_sampler.py View on Github external
# -*- coding: utf-8 -*-

from __future__ import division, print_function

import pickle
from itertools import product

import pytest
import numpy as np

from emcee import moves, backends, EnsembleSampler

__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):
github dfm / emcee / tests / unit / test_blobs.py View on Github external
@pytest.mark.parametrize("backend", backends.get_test_backends())
@pytest.mark.parametrize("blob_spec", [
    (True, 5, lambda x: np.random.randn(5)),
    (True, 0, lambda x: np.random.randn()),
    (False, 2, lambda x: (1.0, np.random.randn(3))),
    (False, 0, lambda x: "face"),
    (False, 2, lambda x: (np.random.randn(5), "face")),
])
def test_blob_shape(backend, blob_spec):
    # HDF backends don't support the object type
    if backend in (backends.TempHDFBackend, ) and not blob_spec[0]:
        return

    with backend() as be:
        np.random.seed(42)

        model = BlobLogProb(blob_spec[2])