コード例 #1
0
 def test_ln_likelihood(self):
     test_rel = relationship.Relationship(utils.straight_line, TEST_X,
                                          TEST_Y)
     expected_lnl = -3
     actual_lnl = optimize.ln_likelihood([1., 0.], test_rel.function,
                                         test_rel.x, test_rel.y)
     assert_almost_equal(actual_lnl, expected_lnl, decimal=0)
コード例 #2
0
ファイル: relationship.py プロジェクト: j-m-dean/uravu
    def bayesian_information_criteria(self):
        """
        Calculate the `Bayesian information criteria`_ for the relationship.

        Returns:
            :py:attr:`float`: Bayesian information criteria.

        .. _Bayesian information criteria: https://en.wikipedia.org/wiki/Bayesian_information_criterion
        """
        self.max_likelihood('diff_evo')
        l_hat = optimize.ln_likelihood(self.variable_medians, self.function, self.abscissa, self.ordinate)
        return np.log(self.x.size) * self.len_parameters - 2 * l_hat
コード例 #3
0
ファイル: sampling.py プロジェクト: vishalbelsare/uravu
def ln_probability(variables, function, abscissa, ordinate, priors):
    """
    Determine the natural log probability for a given set of variables, by
    summing the prior and likelihood.

    Args:
        variables (:py:attr:`array_like`): Variables for the function evaluation.
        function (:py:attr:`callable`): The function to be evaluated.
        abscissa (:py:attr:`array_like`): The abscissa values.
        ordinate (:py:attr:`array_like`): The ordinate values.
        unaccounted_uncertainty (:py:attr:`bool`): Should an unaccounted uncertainty parameter be considered.
        prior_function (:py:attr:`callable`, optional): The function to populated some prior distributions. Default is :func:`~uravu.relationship.Relationship.prior()`.

    Returns:
        :py:attr:`float`: Negative natural log-probability between model and data, considering priors.
    """
    log_prior = 0
    for i, var in enumerate(variables):
        log_prior += priors[i].logpdf(var)
    lnl = optimize.ln_likelihood(variables, function, abscissa, ordinate)
    return log_prior + lnl