Пример #1
0
def test_live_dangerously(nwalkers=32, nsteps=3000, seed=1234):
    warnings.filterwarnings("error")

    # Set up the random number generator.
    np.random.seed(seed)
    coords = np.random.randn(nwalkers, 2 * nwalkers)
    proposal = moves.StretchMove()

    # Test to make sure that the error is thrown if there aren't enough
    # walkers.
    with pytest.raises(RuntimeError):
        proposal.propose(coords, np.random.randn(nwalkers), None, lambda x:
                         (np.zeros(len(x)), None), np.random)

    # Living dangerously...
    proposal.live_dangerously = True
    proposal.propose(coords, np.random.randn(nwalkers), None, lambda x:
                     (np.zeros(len(x)), None), np.random)
Пример #2
0
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,
                                  moves=moves,
Пример #3
0
def test_randomize_stretch(**kwargs):
    _test_normal(moves.StretchMove(randomize_split=True), **kwargs)
Пример #4
0
def test_nsplits_stretch(**kwargs):
    _test_normal(moves.StretchMove(nsplits=5), **kwargs)
Пример #5
0
def test_uniform_stretch(**kwargs):
    _test_uniform(moves.StretchMove(), **kwargs)
Пример #6
0
def test_normal_stretch(**kwargs):
    _test_normal(moves.StretchMove(), **kwargs)
Пример #7
0
def test_normal_stretch(blobs, **kwargs):
    kwargs["blobs"] = blobs
    _test_normal(moves.StretchMove(), **kwargs)
Пример #8
0
v_systemic = 100  #changed to 100 to equal exactly what we used in mathematica

# In[3]:

# x and y dims are switched in ds9 fits display versus np array shape
fits_ydim, fits_xdim = fits.open(observed_2d_vel_field_fits_file)[0].data.shape

mask_sigma = 1.
random_seed = 1234

mcmc_nwalkers = 65
mcmc_niter = 2000
mcmc_ndim = num_bins  # Do not change this if fitting one ring at a time
mcmc_nthreads = 40
# Try increasing stretch scale factor a. version must be >=3 for this to be used.
mcmc_moves = moves.StretchMove(a=2)
mcmc_version = float(emcee.__version__[0])

# Option to save every batch_size iterations in case of crash<br>
# Increase this; 2 is a very low value just for testing

batch_size = 50

# option to save outputs in a particular directory
save_dir = "/Users/stephencoffey/Downloads/little-things/notebooks/stephen/fit_piecewise/bb_comparison/31bins_4/"

# In[4]:

galaxy = Galaxy(
    name=name,
    distance=distance,