How to use the orbitize.sampler.MCMC function in orbitize

To help you get started, we’ve selected a few orbitize 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 sblunt / orbitize / tests / test_mcmc.py View on Github external
Tests the PTMCMC sampler by making sure it even runs
    """
    # use the test_csv dir
    testdir = os.path.dirname(os.path.abspath(__file__))
    input_file = os.path.join(testdir, 'test_val.csv')
    data_table = read_input.read_file(input_file)
    # Manually set 'object' column of data table
    data_table['object'] = 1

    # construct the system
    orbit = system.System(1, data_table, 1, 0.01)

    # construct sampler
    n_temps=2
    n_walkers=100
    mcmc = sampler.MCMC(orbit, n_temps, n_walkers, num_threads=num_threads)

    # run it a little (tests 0 burn-in steps)
    mcmc.run_sampler(100)
    # run it a little more
    mcmc.run_sampler(1000, 1)
    # run it a little more (tests adding to results object)
    mcmc.run_sampler(1000, 1)
github sblunt / orbitize / tests / test_api.py View on Github external
testdir = orbitize.DATADIR
    input_file = os.path.join(testdir, 'GJ504.csv')
    data_table = read_input.read_file(input_file)
    # Manually set 'object' column of data table
    data_table['object'] = 1

    # construct the system
    orbit = system.System(1, data_table, 1, 0.01)

    # construct custom likelihood function
    def my_likelihood(params):
        return -5

    # construct sampler
    n_walkers = 100
    mcmc1 = sampler.MCMC(orbit, 0, n_walkers, num_threads=1)
    mcmc2 = sampler.MCMC(orbit, 0, n_walkers, num_threads=1, custom_lnlike=my_likelihood)

    param = np.array([2, 0.5, 0.5, 0.5, 0.5, 0.5, 1, 0.01])

    logl1 = mcmc1._logl(param)
    logl2 = mcmc2._logl(param)

    assert logl1 == logl2 + 5
github sblunt / orbitize / tests / test_mcmc.py View on Github external
"""
    Tests the EnsembleMCMC sampler by making sure it even runs
    """
    # use the test_csv dir
    testdir = os.path.dirname(os.path.abspath(__file__))
    input_file = os.path.join(testdir, 'test_val.csv')
    data_table = read_input.read_file(input_file)
    # Manually set 'object' column of data table
    data_table['object'] = 1

    # construct the system
    orbit = system.System(1, data_table, 1, 0.01)

    # construct sampler
    n_walkers=100
    mcmc = sampler.MCMC(orbit, 0, n_walkers, num_threads=num_threads)


    # run it a little (tests 0 burn-in steps)
    mcmc.run_sampler(100)
    # run it a little more
    mcmc.run_sampler(1000, burn_steps=1)
    # run it a little more (tests adding to results object)
    mcmc.run_sampler(1000, burn_steps=1)
github sblunt / orbitize / tests / test_api.py View on Github external
input_file = os.path.join(testdir, 'GJ504.csv')
    data_table = read_input.read_file(input_file)
    # Manually set 'object' column of data table
    data_table['object'] = 1

    # construct the system
    orbit = system.System(1, data_table, 1, 0.01)

    # construct custom likelihood function
    def my_likelihood(params):
        return -5

    # construct sampler
    n_walkers = 100
    mcmc1 = sampler.MCMC(orbit, 0, n_walkers, num_threads=1)
    mcmc2 = sampler.MCMC(orbit, 0, n_walkers, num_threads=1, custom_lnlike=my_likelihood)

    param = np.array([2, 0.5, 0.5, 0.5, 0.5, 0.5, 1, 0.01])

    logl1 = mcmc1._logl(param)
    logl2 = mcmc2._logl(param)

    assert logl1 == logl2 + 5
github sblunt / orbitize / orbitize / sampler.py View on Github external
def __init__(self, system, num_temps=20, num_walkers=1000, num_threads=1, like='chi2_lnlike', custom_lnlike=None):

        super(MCMC, self).__init__(system, like=like, custom_lnlike=custom_lnlike)

        self.num_temps = num_temps
        self.num_walkers = num_walkers
        self.num_threads = num_threads

        # create an empty results object
        self.results = orbitize.results.Results(
            sampler_name=self.__class__.__name__,
            post=None,
            lnlike=None,
            tau_ref_epoch=system.tau_ref_epoch,
            num_secondary_bodies=system.num_secondary_bodies
        )

        if self.num_temps > 1:
            self.use_pt = True