Exemplo n.º 1
0
    def test_marginalisation_const(self):
        A = np.array([[1,2,3],[3,2,1]]).T
        C_D_inv = np.array([1,1,1])
        d = np.array([1,2,3])
        result, cov_error, image = de_lens.get_param_WLS(A, C_D_inv, d)
        logL_marg = de_lens.marginalisation_const(cov_error)
        npt.assert_almost_equal(logL_marg, -2.2821740957339181, decimal=8)

        M_inv = np.array([[1,0],[0,1]])
        marg_const = de_lens.marginalisation_const(M_inv)
        assert marg_const == 0
Exemplo n.º 2
0
    def likelihood_data_given_model(self,
                                    kwargs_lens,
                                    kwargs_source,
                                    kwargs_lens_light,
                                    kwargs_ps,
                                    source_marg=False,
                                    compute_bool=None):
        """

        computes the likelihood of the data given a model
        This is specified with the non-linear parameters and a linear inversion and prior marginalisation.

        :param kwargs_lens: list of keyword arguments corresponding to the superposition of different lens profiles
        :param kwargs_source: list of keyword arguments corresponding to the superposition of different source light profiles
        :param kwargs_lens_light: list of keyword arguments corresponding to different lens light surface brightness profiles
        :param kwargs_ps: keyword arguments corresponding to "other" parameters, such as external shear and point source image positions
        :return: log likelihood (natural logarithm)
        """
        # generate image
        im_sim, model_error, cov_matrix, param = self.image_linear_solve(
            kwargs_lens,
            kwargs_source,
            kwargs_lens_light,
            kwargs_ps,
            inv_bool=source_marg)
        # compute X^2
        logL = self.Data.log_likelihood(im_sim, self.ImageNumerics.mask,
                                        model_error)
        if cov_matrix is not None and source_marg:
            marg_const = de_lens.marginalisation_const(cov_matrix)
            #if marg_const + logL > 0:
            #logL = np.log(np.exp(logL) + np.exp(marg_const))
            logL += marg_const
        return logL
Exemplo n.º 3
0
 def likelihood_data_given_model(self,
                                 kwargs_lens,
                                 kwargs_source,
                                 kwargs_lens_light,
                                 kwargs_ps,
                                 source_marg=False,
                                 compute_bool=None):
     """
     computes the likelihood of the data given a model
     This is specified with the non-linear parameters and a linear inversion and prior marginalisation.
     :param kwargs_lens:
     :param kwargs_source:
     :param kwargs_lens_light:
     :param kwargs_ps:
     :return: log likelihood (natural logarithm) (sum of the log likelihoods of the individual images)
     """
     # generate image
     im_sim_list, model_error_list, cov_matrix, param = self.image_linear_solve(
         kwargs_lens,
         kwargs_source,
         kwargs_lens_light,
         kwargs_ps,
         inv_bool=source_marg)
     # compute X^2
     logL = 0
     for i in range(self._num_bands):
         logL += self._imageModel_list[i].Data.log_likelihood(
             im_sim_list[i], self._imageModel_list[i].ImageNumerics.mask,
             model_error_list[i])
     if cov_matrix is not None and source_marg:
         marg_const = de_lens.marginalisation_const(cov_matrix)
         logL += marg_const
     return logL
Exemplo n.º 4
0
    def test_margnialization_new(self):
        M_inv = np.array([[1, -0.5, 1], [-0.5, 3, 0], [1, 0, 2]])
        d_prior = 1000
        m = len(M_inv)
        log_det = DeLens.marginalization_new(M_inv, d_prior=d_prior)
        log_det_old = DeLens.marginalisation_const(M_inv)
        npt.assert_almost_equal(log_det,
                                log_det_old + m / 2. * np.log(np.pi / 2.) -
                                m * np.log(d_prior),
                                decimal=9)

        M_inv = np.array([[1, 1, 1], [0., 1., 0.], [1., 2., 1.]])
        log_det = DeLens.marginalization_new(M_inv, d_prior=10)
        log_det_old = DeLens.marginalisation_const(M_inv)
        npt.assert_almost_equal(log_det, log_det_old, decimal=9)
        npt.assert_almost_equal(log_det, -10**(15), decimal=10)

        log_det = DeLens.marginalization_new(M_inv, d_prior=None)
        log_det_old = DeLens.marginalisation_const(M_inv)
        npt.assert_almost_equal(log_det, log_det_old, decimal=9)