Пример #1
0
import numpy as np

from emcee import backends, EnsembleSampler

__all__ = ["test_blob_shape"]


class BlobLogProb(object):
    def __init__(self, blob_function):
        self.blob_function = blob_function

    def __call__(self, params):
        return -0.5 * np.sum(params**2), self.blob_function(params)


@pytest.mark.parametrize("backend", backends.get_test_backends())
def test_blob_shape(backend):
    with backend() as be:
        np.random.seed(42)

        nblobs = 5
        model = BlobLogProb(lambda x: np.random.randn(nblobs))

        coords = np.random.randn(32, 3)
        nwalkers, ndim = coords.shape
        sampler = EnsembleSampler(nwalkers, ndim, model, backend=be)
        nsteps = 10
        sampler.run_mcmc(coords, nsteps)
        assert sampler.get_blobs().shape == (nsteps, nwalkers, nblobs)

        model = BlobLogProb(lambda x: np.random.randn())
Пример #2
0
# -*- 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):
Пример #3
0
# -*- coding: utf-8 -*-

import os
from itertools import product

import h5py
import numpy as np
import pytest

from emcee import EnsembleSampler, backends

__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,
Пример #4
0
from emcee import backends, EnsembleSampler

__all__ = ["test_blob_shape"]


class BlobLogProb(object):

    def __init__(self, blob_function):
        self.blob_function = blob_function

    def __call__(self, params):
        return -0.5 * np.sum(params**2), self.blob_function(params)


@pytest.mark.parametrize("backend", backends.get_test_backends())
def test_blob_shape(backend):
    with backend() as be:
        np.random.seed(42)

        nblobs = 5
        model = BlobLogProb(lambda x: np.random.randn(nblobs))

        coords = np.random.randn(32, 3)
        nwalkers, ndim = coords.shape
        sampler = EnsembleSampler(nwalkers, ndim, model, backend=be)
        nsteps = 10
        sampler.run_mcmc(coords, nsteps)
        assert sampler.get_blobs().shape == (nsteps, nwalkers, nblobs)

        model = BlobLogProb(lambda x: np.random.randn())