Ejemplo n.º 1
0
    def test__loads_from_config_file_correct(self):

        zeus = af.Zeus(
            prior_passer=af.PriorPasser(sigma=2.0,
                                        use_errors=False,
                                        use_widths=False),
            nwalkers=51,
            nsteps=2001,
            initializer=af.InitializerBall(lower_limit=0.2, upper_limit=0.8),
            auto_correlations_settings=af.AutoCorrelationsSettings(
                check_for_convergence=False,
                check_size=101,
                required_length=51,
                change_threshold=0.02),
            tune=False,
            number_of_cores=2,
        )

        assert zeus.prior_passer.sigma == 2.0
        assert zeus.prior_passer.use_errors is False
        assert zeus.prior_passer.use_widths is False
        assert zeus.config_dict_search["nwalkers"] == 51
        assert zeus.config_dict_run["nsteps"] == 2001
        assert zeus.config_dict_run["tune"] == False
        assert isinstance(zeus.initializer, af.InitializerBall)
        assert zeus.initializer.lower_limit == 0.2
        assert zeus.initializer.upper_limit == 0.8
        assert zeus.auto_correlations_settings.check_for_convergence is False
        assert zeus.auto_correlations_settings.check_size == 101
        assert zeus.auto_correlations_settings.required_length == 51
        assert zeus.auto_correlations_settings.change_threshold == 0.02
        assert zeus.number_of_cores == 2

        zeus = af.Zeus()

        assert zeus.prior_passer.sigma == 3.0
        assert zeus.prior_passer.use_errors is True
        assert zeus.prior_passer.use_widths is True
        assert zeus.config_dict_search["nwalkers"] == 50
        assert zeus.config_dict_run["nsteps"] == 2000
        assert zeus.config_dict_run["tune"] == True
        assert isinstance(zeus.initializer, af.InitializerPrior)
        assert zeus.auto_correlations_settings.check_for_convergence is True
        assert zeus.auto_correlations_settings.check_size == 100
        assert zeus.auto_correlations_settings.required_length == 50
        assert zeus.auto_correlations_settings.change_threshold == 0.01
        assert zeus.number_of_cores == 1
Ejemplo n.º 2
0
Below we use zeus to fit the lens model, using the model with start points as described above. See the Zeus docs
for a description of what the input parameters below do.
"""
search = af.Zeus(
    path_prefix=path.join("imaging", "searches"),
    name="Zeus",
    unique_tag=dataset_name,
    nwalkers=30,
    nsteps=200,
    initializer=af.InitializerBall(lower_limit=0.49, upper_limit=0.51),
    auto_correlations_settings=af.AutoCorrelationsSettings(
        check_for_convergence=True,
        check_size=100,
        required_length=50,
        change_threshold=0.01,
    ),
    tune=False,
    tolerance=0.05,
    patience=5,
    maxsteps=10000,
    mu=1.0,
    maxiter=10000,
    vectorize=False,
    check_walkers=True,
    shuffle_ensemble=True,
    light_mode=False,
    iterations_per_update=5000,
    number_of_cores=1,
)

result = search.fit(model=model, analysis=analysis)
"""
bulge.elliptical_comps.elliptical_comps_1 = af.UniformPrior(
    lower_limit=-0.3, upper_limit=0.3
)
bulge.intensity = af.UniformPrior(lower_limit=0.1, upper_limit=0.5)
bulge.effective_radius = af.UniformPrior(lower_limit=0.0, upper_limit=0.4)
bulge.sersic_index = af.UniformPrior(lower_limit=0.5, upper_limit=2.0)

lens = af.Model(al.Galaxy, redshift=0.5, mass=mass, shear=shear)
source = af.Model(al.Galaxy, redshift=1.0, bulge=bulge)

model = af.Collection(galaxies=af.Collection(lens=lens, source=source))

search = af.Zeus(
    path_prefix=path.join("howtolens", "chapter_2"),
    name="tutorial_searches_zeus",
    unique_tag=dataset_name,
    nwalkers=50,
    nsteps=1000,
)

print(
    "Zeus has begun running - checkout the workspace/output"
    "  folder for live output of the results, images and lens model."
    "  This Jupyter notebook cell with progress once Dynesty has completed - this could take some time!"
)

result_zeus = search.fit(model=model, analysis=analysis)

print("Zeus has finished run - you may now continue the notebook.")

fit_imaging_plotter = aplt.FitImagingPlotter(fit=result_zeus.max_log_likelihood_fit)
Ejemplo n.º 4
0
dataset_path = path.join("dataset", "example_1d", "gaussian_x1")
data = af.util.numpy_array_from_json(
    file_path=path.join(dataset_path, "data.json"))
noise_map = af.util.numpy_array_from_json(
    file_path=path.join(dataset_path, "noise_map.json"))

model = af.Model(m.Gaussian)

model.centre = af.UniformPrior(lower_limit=0.0, upper_limit=100.0)
model.intensity = af.UniformPrior(lower_limit=1e-2, upper_limit=1e2)
model.sigma = af.UniformPrior(lower_limit=0.0, upper_limit=30.0)

analysis = a.Analysis(data=data, noise_map=noise_map)

zeus = af.Zeus(path_prefix=path.join("plot"),
               name="ZeusPlotter",
               nwalkers=100,
               nsteps=10000)

result = zeus.fit(model=model, analysis=analysis)

samples = result.samples
"""
We now pass the samples to a `ZeusPlotter` which will allow us to use dynesty's in-built plotting libraries to 
make figures.

The zeus readthedocs describes fully all of the methods used below 

 - https://zeus-mcmc.readthedocs.io/en/latest/api/plotting.html#cornerplot
 - https://zeus-mcmc.readthedocs.io/en/latest/notebooks/normal_distribution.html
 
 The plotter wraps the `corner` method of the library `corner.py` to make corner plots of the PDF:
Ejemplo n.º 5
0
from os import path

import autofit as af
import autolens as al
import autolens.plot as aplt
"""
First, lets create a result via zeus by repeating the simple model-fit that is performed in 
the `modeling/mass_total__source_parametric.py` example.

We use a model with an initialized starting point, which is necessary for lens modeling with zeus.
"""
dataset_name = "mass_sie__source_sersic"

search = af.Zeus(
    path_prefix=path.join("plot", "ZeusPlotter"),
    name="ZeusPlotter",
    nwalkers=30,
    nsteps=500,
)

dataset_path = path.join("dataset", "imaging", "no_lens_light", dataset_name)

imaging = al.Imaging.from_fits(
    image_path=path.join(dataset_path, "image.fits"),
    psf_path=path.join(dataset_path, "psf.fits"),
    noise_map_path=path.join(dataset_path, "noise_map.fits"),
    pixel_scales=0.1,
)

mask = al.Mask2D.circular(shape_native=imaging.shape_native,
                          pixel_scales=imaging.pixel_scales,
                          radius=3.0)