How to use the orbitize.lnlike 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_chi2_lnlike.py View on Github external
def test_2x2_analytical_solution():
    """
    Tests that our analytical solution to the 2x2 covariance matrix is correct
    """
    residuals = np.array([[5,-4], [3,-2], [1,0] ])

    errs = np.array([[2,2], [2,2], [2,2]])
    covs = np.array([1, 0.25, 0.25])
    corrs = covs/errs[:,0]/errs[:,1]

    chi2s = lnlike._chi2_2x2cov(np.array([residuals]), np.array([errs**2]), corrs)

    # compare to numpy solution
    for res, err, cov, chi2 in zip(residuals, errs, covs, chi2s[0]):
        cov_matrix = np.array([[err[0]**2, cov], [cov, err[1]**2]])
        cov_inv = np.linalg.inv(cov_matrix)
        cov_inv_dot_diff = np.dot(cov_inv, res)
        logdet = np.linalg.slogdet(cov_matrix)[1]
        res_cov_res = res.dot(cov_inv_dot_diff)
        numpy_chi2 = -0.5 * (res_cov_res + logdet) 

        assert np.sum(chi2) == numpy_chi2
github sblunt / orbitize / tests / test_chi2_lnlike.py View on Github external
def test_chi2lnlike():
    """
    Test the ability of ``orbitize.lnlike.chi2_lnlike()``
    to work properly on arrays.
    """
    # test with a single model
    model = np.zeros((3, 2))
    jitter = np.zeros((3, 2))
    data = np.ones((3, 2))
    errors = np.ones((3, 2))

    seppa_indices = [np.array([1])]

    chi2 = lnlike.chi2_lnlike(data, errors, None, model, jitter, seppa_indices)
    assert chi2.shape == (3, 2)
    assert (chi2 == -0.5 * np.ones((3, 2)) - np.log(np.sqrt(2*np.pi*np.ones((3, 2))))).all()

    # test with multiple models
    model = np.zeros((3, 2, 5))
    jitter = np.zeros((3, 2, 5))
    data = np.ones((3, 2))
    errors = np.ones((3, 2))

    seppa_indices = [np.array([1])]

    chi2 = lnlike.chi2_lnlike(data, errors, None, model, jitter, seppa_indices)
    assert chi2.shape == (3, 2, 5)
    assert (chi2 == -0.5 * np.ones((3, 2, 5)) - np.log(np.sqrt(2*np.pi*np.ones((3, 2, 5))))).all()
github sblunt / orbitize / orbitize / sampler.py View on Github external
def __init__(self, system, like='chi2_lnlike', custom_lnlike=None):
        self.system = system

        # check if `like` is a string or a function
        if callable(like):
            self.lnlike = like
        else:
            self.lnlike = getattr(orbitize.lnlike, like)

        self.custom_lnlike = custom_lnlike
github sblunt / orbitize / orbitize / sampler.py View on Github external
def __init__(self, system, like='chi2_lnlike', custom_lnlike=None):
        self.system = system

        # check if `like` is a string or a function
        if callable(like):
            self.lnlike = like
        else:
            self.lnlike = getattr(orbitize.lnlike, like)

        self.custom_lnlike = custom_lnlike