def test_nested_sampling(self): test_rel = relationship.Relationship(utils.straight_line, TEST_X, TEST_Y, bounds=((0, 10), (-1, 1))) actual_results = sampling.nested_sampling(test_rel, maxiter=100) assert_equal(isinstance(actual_results, dict), True) assert_equal(isinstance(actual_results["logz"][-1], float), True) assert_equal(isinstance(actual_results["logzerr"][-1], float), True)
def nested_sampling(self, prior_function=None, progress=True, dynamic=False, **kwargs): """ Perform nested sampling, or dynamic nested sampling, to determine the Bayesian natural-log evidence. For keyword arguments see the :func:`dynesty.NestedSampler.run_nested()` documentation. Once run, the result dictionary produced by :func:`dynesty.NestedSampler.run_nested()` is piped into the class variable :py:attr:`nested_sampling_results`. Args: prior_function (:py:attr:`callable`, optional): The function to populate some prior distributions. Default is the broad uniform priors in :func:`~uravu.relationship.Relationship.prior()`. progress (:py:attr:`bool`, optional): Show :py:mod:`tqdm` progress for sampling. Default is :py:attr:`True`. """ self.nested_sampling_results = sampling.nested_sampling(self, prior_function=prior_function, progress=progress, dynamic=dynamic, **kwargs) self.ln_evidence = ufloat(self.nested_sampling_results["logz"][-1], self.nested_sampling_results["logzerr"][-1]) self.variables = self.nested_sampling_results["distributions"]
def test_nested_sampling_b_with_other_prior(self): test_rel = relationship.Relationship(utils.straight_line, TEST_X, TEST_Y, bounds=((0, 10), (-1, 1))) test_rel.max_likelihood('mini') def other_prior(): """ Another potential prior. """ priors = [] for i, variable in enumerate(test_rel.variables): loc = variable.n scale = 1 priors.append(norm(loc=loc, scale=scale)) return priors actual_results = sampling.nested_sampling(test_rel, prior_function=other_prior, maxiter=100) assert_equal(isinstance(actual_results, dict), True) assert_equal(isinstance(actual_results["logz"][-1], float), True) assert_equal(isinstance(actual_results["logzerr"][-1], float), True)