Exemplo n.º 1
0
    def _likelihood_data_given_model(self, kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None,
                                     kwargs_extinction=None, kwargs_special=None, source_marg=False, linear_prior=None,
                                     check_positive_flux=False):
        """

        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
        :param source_marg: bool, performs a marginalization over the linear parameters
        :param linear_prior: linear prior width in eigenvalues
        :param check_positive_flux: bool, if True, checks whether the linear inversion resulted in non-negative flux
         components and applies a punishment in the likelihood if so.
        :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, kwargs_extinction, kwargs_special,
                                                                          inv_bool=source_marg)
        # compute X^2
        logL = self.Data.log_likelihood(im_sim, self.likelihood_mask, model_error)

        if self._pixelbased_bool is False:
            if cov_matrix is not None and source_marg:
                marg_const = de_lens.marginalization_new(cov_matrix, d_prior=linear_prior)
                logL += marg_const
        if check_positive_flux is True:
            bool_ = self.check_positive_flux(kwargs_source, kwargs_lens_light, kwargs_ps)
            if bool_ is False:
                logL -= 10**8
        return logL
Exemplo n.º 2
0
    def likelihood_data_given_model(self, kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None,
                                    kwargs_extinction=None, kwargs_special=None, source_marg=False, linear_prior=None,
                                    check_positive_flux=False):
        """
        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:
        :param check_positive_flux: bool, if True, checks whether the linear inversion resulted in non-negative flux
         components and applies a punishment in the likelihood if so.
        :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,
                                                                                   kwargs_extinction, kwargs_special,
                                                                                   inv_bool=source_marg)
        # compute X^2
        logL = 0
        index = 0
        for i in range(self._num_bands):
            if self._compute_bool[i] is True:
                logL += self._imageModel_list[i].Data.log_likelihood(im_sim_list[index], self._imageModel_list[i].likelihood_mask, model_error_list[index])
                index += 1
        if cov_matrix is not None and source_marg:
            marg_const = de_lens.marginalization_new(cov_matrix, d_prior=linear_prior)
            logL += marg_const
        if check_positive_flux is True and self._num_bands > 0:
            bool_ = self._imageModel_list[0].check_positive_flux(kwargs_source, kwargs_lens_light, kwargs_ps)
            if bool_ is False:
                logL -= 10 ** 5
        return logL
Exemplo n.º 3
0
 def likelihood_data_given_model(self, kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None,
                                 kwargs_extinction=None, kwargs_special=None, source_marg=False, linear_prior=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,
                                                                                kwargs_extinction, kwargs_special,
                                                                                inv_bool=source_marg)
     # compute X^2
     logL = 0
     index = 0
     for i in range(self._num_bands):
         if self._compute_bool[i] is True:
             logL += self._imageModel_list[i].Data.log_likelihood(im_sim_list[index], self._imageModel_list[i].likelihood_mask, model_error_list[index])
             index += 1
     if cov_matrix is not None and source_marg:
         marg_const = de_lens.marginalization_new(cov_matrix, d_prior=linear_prior)
         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)