Exemple #1
0
 def parse_priors(self, priors):
     if isinstance(priors, str):
         try:
             result = joblib.load(priors)
         except IOError:
             self.logger.error(
                 f"Priors could not be loaded from path {priors}. Terminating..."
             )
             sys.exit(1)
     else:
         result = []
         for i, p in enumerate(priors):
             prior_str = re.findall(r"(\w+)\(", p)[0]
             prior_param_strings = re.findall(r"\((.*?)\)", p)[0].split(",")
             keys = [x.split("=")[0].strip() for x in prior_param_strings]
             vals = [
                 float(x.split("=")[1].strip()) for x in prior_param_strings
             ]
             if prior_str == "roundflat":
                 prior = (lambda x, keys=keys, vals=vals: roundflat(
                     np.exp(x), **dict(zip(keys, vals))) + x)
             else:
                 dist = getattr(scipy.stats,
                                prior_str)(**dict(zip(keys, vals)))
                 if i == 0 or i == len(priors) - 1:
                     # The signal variance and the signal noise are in positive,
                     # sqrt domain
                     prior = (lambda x, dist=dist: dist.logpdf(
                         np.sqrt(np.exp(x))) + x / 2.0 - np.log(2.0))
                 else:
                     # The lengthscale(s) are in positive domain
                     prior = lambda x, dist=dist: dist.logpdf(np.exp(
                         x)) + x  # noqa: E731
             result.append(prior)
     return result
Exemple #2
0
def test_roundflat():
    assert_almost_equal(roundflat(0.3), 0.0, decimal=0.1)

    assert roundflat(0.0) == -np.inf
    assert roundflat(-1.0) == -np.inf
def test_roundflat():
    assert roundflat(0.3) == approx(0.0, abs=1e-6)
    assert roundflat(0.0) == -np.inf
    assert roundflat(-1.0) == -np.inf