Exemplo n.º 1
0
 def should_plot(name):
     return plot_setting(section="fit_quantity", name=name)
Exemplo n.º 2
0
 def should_plot(name):
     return plot_setting(section="ray_tracing", name=name)
Exemplo n.º 3
0
 def should_plot(name):
     return plot_setting(section="hyper", name=name)
Exemplo n.º 4
0
    def visualize_stochastic_histogram(
        self,
        stochastic_log_likelihoods: np.ndarray,
        max_log_evidence: float,
        histogram_bins: int = 10,
    ):
        """
        Certain `Inversion`'s have stochasticity in their log likelihood estimate.

        For example, the `VoronoiBrightnessImage` pixelization, which changes the likelihood depending on how different
        KMeans seeds change the pixel-grid.

        A log likelihood cap can be applied to model-fits performed using these `Inversion`'s to improve error and
        posterior estimates. This log likelihood cap is estimated from a list of stochastic log likelihoods, where
        these log likelihoods are computed using the same model but with different KMeans seeds.

        This function plots a histogram representing the distribution of these stochastic log likelihoods with a 1D
        Gaussian fit to the likelihoods overlaid. This figure can be used to determine how subject the fit to this
        dataset is to the stochastic likelihood effect.

        Parameters
        ----------
        stochastic_log_likelihoods
            The stochastic log likelihood which are used to plot the histogram and Gaussian.
        max_log_evidence
            The maximum log likelihood value of the non-linear search, which will likely be much larger than any of the
            stochastic log likelihoods as it will be boosted high relative to most samples.
        histogram_bins
            The number of bins in the histogram used to visualize the distribution of stochastic log likelihoods.

        Returns
        -------
        float
            A log likelihood cap which is applied in a stochastic model-fit to give improved error and posterior
            estimates.
        """
        if stochastic_log_likelihoods is None:
            return

        if plot_setting("other", "stochastic_histogram"):

            file_path = path.join(self.visualize_path, "other")

            try:
                os.makedirs(file_path)
            except FileExistsError or IsADirectoryError:
                pass

            filename = path.join(file_path, "stochastic_histogram.png")

            if path.exists(filename):
                try:
                    os.rmdir(filename)
                except Exception:
                    pass

            (mu, sigma) = norm.fit(stochastic_log_likelihoods)
            n, bins, patches = plt.hist(
                x=stochastic_log_likelihoods, bins=histogram_bins, density=1
            )
            y = norm.pdf(bins, mu, sigma)
            plt.plot(bins, y, "--")
            plt.xlabel("log evidence")
            plt.title("Stochastic Log Evidence Histogram")
            plt.axvline(max_log_evidence, color="r")
            plt.savefig(filename, bbox_inches="tight")
            plt.close()
Exemplo n.º 5
0
 def should_plot(name):
     return plot_setting(section=["positions"], name=name)