コード例 #1
0
    def prior(self, cube, ndim, nparams):
        """
        compute the mapping between the unit cube and parameter cube (in-place)

        :param cube: unit hypercube, sampled by the algorithm
        :param ndim: number of sampled parameters
        :param nparams: total number of parameters
        """
        cube_py = self._multinest2python(cube, ndim)
        if self.prior_type == 'gaussian':
            utils.cube2args_gaussian(cube_py, self.lowers, self.uppers, 
                                     self.means, self.sigmas, self.n_dims)
        elif self.prior_type == 'uniform':
            utils.cube2args_uniform(cube_py, self.lowers, self.uppers, self.n_dims)
        for i in range(self.n_dims):
            cube[i] = cube_py[i]
コード例 #2
0
ファイル: dynesty_sampler.py プロジェクト: aymgal/lenstronomy
    def prior(self, u):
        """
        compute the mapping between the unit cube and parameter cube

        :param u: unit hypercube, sampled by the algorithm
        :return: hypercube in parameter space
        """
        if self.prior_type == 'gaussian':
            p = utils.cube2args_gaussian(u,
                                         self.lowers,
                                         self.uppers,
                                         self.means,
                                         self.sigmas,
                                         self.n_dims,
                                         copy=True)
        elif self.prior_type == 'uniform':
            p = utils.cube2args_uniform(u,
                                        self.lowers,
                                        self.uppers,
                                        self.n_dims,
                                        copy=True)
        else:
            raise ValueError(
                'prior type %s not supported! Chose "gaussian" or "uniform".')
        return p
コード例 #3
0
def test_cube2args_gaussian():
    n_dims = 3
    l, u = -5., 15.
    m, s = 5., 1.
    lowers, uppers = [l] * n_dims, [u] * n_dims
    means, sigmas = [m] * n_dims, [s] * n_dims
    truth = [l, m, u]

    cube = [0, 0.5, 1]
    sampling_util.cube2args_gaussian(cube,
                                     lowers,
                                     uppers,
                                     means,
                                     sigmas,
                                     n_dims,
                                     copy=False)
    npt.assert_equal(cube, truth)

    cube = [0, 0.5, 1]
    sampling_util.cube2args_gaussian(cube,
                                     lowers,
                                     uppers,
                                     means,
                                     sigmas,
                                     n_dims,
                                     copy=True)
    # they should NOT be equal because cube was not modified in-place
    npt.assert_equal(np.any(np.not_equal(cube, truth)), True)

    cube = sampling_util.cube2args_gaussian(cube,
                                            lowers,
                                            uppers,
                                            means,
                                            sigmas,
                                            n_dims,
                                            copy=True)
    # here they should
    npt.assert_equal(cube, truth)
コード例 #4
0
    def prior(self, cube):
        """
        compute the mapping between the unit cube and parameter cube

        'copy=True' below because cube can not be modified in-place (read-only)

        :param cube: unit hypercube, sampled by the algorithm
        :return: hypercube in parameter space
        """
        if self.prior_type == 'gaussian':
            p = utils.cube2args_gaussian(cube, self.lowers, self.uppers,
                                         self.means, self.sigmas, self.n_dims,
                                         copy=True)
        elif self.prior_type == 'uniform':
            p = utils.cube2args_uniform(cube, self.lowers, self.uppers, 
                                        self.n_dims, copy=True)
        return p