rhayes777 / PyAutoFit

PyAutoFit: Classy Probabilistic Programming
https://pyautofit.readthedocs.io/
MIT License
60 stars 11 forks source link

Improve `model.start` string #1030

Open Jammy2211 opened 3 months ago

Jammy2211 commented 3 months ago

The following info attribute is used to show the starting point of an initializer:

def info_from_model(self, model : AbstractPriorModel) -> str:
    """
    Returns a string showing the bounds of the parameters in the initializer.
    """
    info = "Total Free Parameters = " + str(model.prior_count) + "\n"
    info += "Total Starting Points = " + str(len(self.parameter_dict)) + "\n\n"
    for prior in model.priors_ordered_by_id:

        key = ".".join(model.path_for_prior(prior))

        try:

            value = self.info_value_from(self.parameter_dict[prior])

            info += f"{key}: Start[{value}]\n"

        except KeyError:

            info += f"{key} : {prior})\n"

    return info

It appears as follows:

Total Free Parameters = 13
Total Starting Points = 13

galaxies.lens.bulge.effective_radius: Start[0.4]
galaxies.lens.bulge.sersic_index: Start[4.3]
galaxies.lens.mass.centre.centre_0: Start[0.0]
galaxies.lens.mass.centre.centre_1: Start[0.0]
galaxies.lens.mass.ell_comps.ell_comps_0: Start[-0.01765]
galaxies.lens.mass.ell_comps.ell_comps_1: Start[-0.0419127]
galaxies.lens.mass.einstein_radius: Start[0.5961714]
galaxies.source.bulge.centre.centre_0: Start[0.0]
galaxies.source.bulge.centre.centre_1: Start[0.0]
galaxies.source.bulge.ell_comps.ell_comps_0: Start[0.0]
galaxies.source.bulge.ell_comps.ell_comps_1: Start[0.0]
galaxies.source.bulge.effective_radius: Start[0.05]
galaxies.source.bulge.sersic_index: Start[1.0]

This API is not as nice as how the same model.info appears, lacking the whitespace and indenting:

Total Free Parameters = 13

model                                                                           Collection (N=13)
    galaxies                                                                    Collection (N=13)
        lens                                                                    Galaxy (N=7)
            mass                                                                Isothermal (N=5)
        source                                                                  Galaxy (N=6)
        lens - source
            bulge                                                               Sersic (N=6)

galaxies
    lens
        redshift                                                                0.5
        bulge - mass
            centre
                centre_0                                                        GaussianPrior [90], mean = 0.0, sigma = 0.1
                centre_1                                                        GaussianPrior [91], mean = 0.0, sigma = 0.1
            ell_comps
                ell_comps_0                                                     GaussianPrior [92], mean = 0.0, sigma = 0.3
                ell_comps_1                                                     GaussianPrior [93], mean = 0.0, sigma = 0.3
        bulge
            effective_radius                                                    UniformPrior [88], lower_limit = 0.0, upper_limit = 30.0
            sersic_index                                                        UniformPrior [89], lower_limit = 0.8, upper_limit = 5.0
        mass
            einstein_radius                                                     UniformPrior [94], lower_limit = 0.0, upper_limit = 8.0
    source
        redshift                                                                1.0
        bulge
            centre
                centre_0                                                        GaussianPrior [95], mean = 0.0, sigma = 0.3
                centre_1                                                        GaussianPrior [96], mean = 0.0, sigma = 0.3
            ell_comps
                ell_comps_0                                                     GaussianPrior [97], mean = 0.0, sigma = 0.3
                ell_comps_1                                                     GaussianPrior [98], mean = 0.0, sigma = 0.3
            effective_radius                                                    UniformPrior [99], lower_limit = 0.0, upper_limit = 30.0
            sersic_index                                                        UniformPrior [100], lower_limit = 0.8, upper_limit = 5.0

Can you update the method model_info_from so it appears like the model.info, so something liek:

Total Free Parameters = 13
Total Starting Points = 13

model                                                                           Collection (N=13)
    galaxies                                                                    Collection (N=13)
        lens                                                                    Galaxy (N=7)
            mass                                                                Isothermal (N=5)
        source                                                                  Galaxy (N=6)
        lens - source
            bulge                                                               Sersic (N=6)

galaxies
    lens
        redshift                                                                0.5
        bulge - mass
            centre
                centre_0                                                        Start[0.0]
                centre_1                                                        Start[0.0]
            ell_comps
                ell_comps_0                                                     Start[0.0]
                ell_comps_1                                                     Start[0.0]
        bulge
            effective_radius                                                    Start[0.4]
            sersic_index                                                        Start[0.4]
        mass
            einstein_radius                                                    Start[0.4]
    source
        redshift                                                                1.0
        bulge
            centre
                centre_0                                                        Start[0.0]
                centre_1                                                        Start[0.0]
            ell_comps
                ell_comps_0                                                   Start[0.0]
                ell_comps_1                                                   Start[0.0]
            effective_radius                                                 Start[0.1]
            sersic_index                                                       Start[1.0]