Esempio n. 1
0
    def positions_fit_for_tracer(self, tracer, hyper_image_sky,
                                 hyper_background_noise):

        return fit.FitImaging(
            masked_imaging=self.masked_dataset,
            tracer=tracer,
            hyper_image_sky=hyper_image_sky,
            hyper_background_noise=hyper_background_noise,
        )
Esempio n. 2
0
    def masked_imaging_fit_for_tracer(
        self, tracer, hyper_image_sky, hyper_background_noise
    ):

        return fit.FitImaging(
            masked_imaging=self.masked_dataset,
            tracer=tracer,
            hyper_image_sky=hyper_image_sky,
            hyper_background_noise=hyper_background_noise,
            settings_pixelization=self.settings.settings_pixelization,
            settings_inversion=self.settings.settings_inversion,
        )
Esempio n. 3
0
    def stochastic_log_evidences_for_instance(self, instance):

        instance = self.associate_hyper_images(instance=instance)
        tracer = self.tracer_for_instance(instance=instance)

        if not tracer.has_pixelization:
            return

        if not isinstance(
            tracer.pixelizations_of_planes[-1], pix.VoronoiBrightnessImage
        ):
            return

        hyper_image_sky = self.hyper_image_sky_for_instance(instance=instance)

        hyper_background_noise = self.hyper_background_noise_for_instance(
            instance=instance
        )

        settings_pixelization = (
            self.settings.settings_pixelization.settings_with_is_stochastic_true()
        )

        log_evidences = []

        for i in range(self.settings.settings_lens.stochastic_samples):

            try:
                log_evidence = fit.FitImaging(
                    masked_imaging=self.masked_dataset,
                    tracer=tracer,
                    hyper_image_sky=hyper_image_sky,
                    hyper_background_noise=hyper_background_noise,
                    settings_pixelization=settings_pixelization,
                    settings_inversion=self.settings.settings_inversion,
                ).log_evidence
            except (
                PixelizationException,
                InversionException,
                GridException,
                OverflowError,
            ) as e:
                log_evidence = None

            if log_evidence is not None:
                log_evidences.append(log_evidence)

        return log_evidences
Esempio n. 4
0
    def masked_imaging_fit_for_tracer(self,
                                      tracer,
                                      hyper_image_sky,
                                      hyper_background_noise,
                                      use_hyper_scalings=True):

        return fit.FitImaging(
            masked_imaging=self.masked_dataset,
            tracer=tracer,
            hyper_image_sky=hyper_image_sky,
            hyper_background_noise=hyper_background_noise,
            use_hyper_scaling=use_hyper_scalings,
            settings_pixelization=self.settings.settings_pixelization,
            settings_inversion=self.settings.settings_inversion,
            preloads=self.preloads,
        )
Esempio n. 5
0
    def log_likelihood_function(self, instance):
        """
        Determine the fit of a lens galaxy and source galaxy to the masked_imaging in this lens.

        Parameters
        ----------
        instance
            A model instance with attributes

        Returns
        -------
        fit : Fit
            A fractional value indicating how well this model fit and the model masked_imaging itself
        """

        self.associate_hyper_images(instance=instance)
        tracer = self.tracer_for_instance(instance=instance)

        self.settings.settings_lens.check_positions_trace_within_threshold_via_tracer(
            tracer=tracer, positions=self.masked_dataset.positions)

        hyper_image_sky = self.hyper_image_sky_for_instance(instance=instance)

        hyper_background_noise = self.hyper_background_noise_for_instance(
            instance=instance)

        if self.settings.settings_lens.stochastic_likelihood_resamples is None:

            try:
                return self.masked_imaging_fit_for_tracer(
                    tracer=tracer,
                    hyper_image_sky=hyper_image_sky,
                    hyper_background_noise=hyper_background_noise,
                ).figure_of_merit
            except (
                    PixelizationException,
                    InversionException,
                    GridException,
                    OverflowError,
            ) as e:
                raise FitException from e

        else:

            figures_of_merit = []

            for i in range(self.settings.settings_lens.
                           stochastic_likelihood_resamples):

                settings_pixelization = copy.deepcopy(
                    self.settings.settings_pixelization)

                settings_pixelization.kmeans_seed = i
                #       settings_pixelization.is_stochastic = True

                try:
                    figures_of_merit.append(
                        fit.FitImaging(
                            masked_imaging=self.masked_dataset,
                            tracer=tracer,
                            hyper_image_sky=hyper_image_sky,
                            hyper_background_noise=hyper_background_noise,
                            settings_pixelization=settings_pixelization,
                            settings_inversion=self.settings.
                            settings_inversion,
                        ).log_evidence)
                except (
                        PixelizationException,
                        InversionException,
                        GridException,
                        OverflowError,
                ) as e:
                    raise FitException from e

            return np.mean(figures_of_merit)