Пример #1
0
    def __init__(self, likelihood_module, prior_type, prior_means,
                 prior_sigmas, width_scale, sigma_scale):
        """
        :param likelihood_module: likelihood_module like in likelihood.py (should be callable)
        :param prior_type: 'uniform' of 'gaussian', for converting the unit hypercube to param cube
        :param prior_means: if prior_type is 'gaussian', mean for each param
        :param prior_sigmas: if prior_type is 'gaussian', std dev for each param
        :param width_scale: scale the widths of the parameters space by this factor
        :param sigma_scale: if prior_type is 'gaussian', scale the gaussian sigma by this factor
        """
        self._ll = likelihood_module
        self.n_dims, self.param_names = self._ll.param.num_param()

        lowers, uppers = self._ll.param_limits
        if width_scale < 1:
            self.lowers, self.uppers = utils.scale_limits(
                lowers, uppers, width_scale)
        else:
            self.lowers, self.uppers = lowers, uppers

        if prior_type == 'gaussian':
            if prior_means is None or prior_sigmas is None:
                raise ValueError(
                    "For gaussian prior type, means and sigmas are required")
            self.means, self.sigmas = prior_means, prior_sigmas * sigma_scale
            self.lowers, self.uppers = lowers, uppers
        elif prior_type != 'uniform':
            raise ValueError(
                "Sampling type {} not supported".format(prior_type))
        self.prior_type = prior_type
        self._has_warned = False
Пример #2
0
def test_scale_limits():
    lowers_list, uppers_list = [0, -1, 5], [10, 9, 15]
    lowers, uppers = np.array(lowers_list), np.array(uppers_list)
    widths = uppers - lowers
    scale_factor = 0.5
    lowers_s, uppers_s = sampling_util.scale_limits(lowers_list, uppers_list, scale_factor)
    npt.assert_equal(lowers_s, np.array([2.5, 1.5, 7.5]))
    npt.assert_equal(uppers_s, np.array([7.5, 6.5, 12.5]))
    npt.assert_equal(widths*scale_factor, (uppers_s - lowers_s))