Exemple #1
0
    def test__samples_from_model(self):

        emcee = af.Emcee()
        emcee.paths = af.DirectoryPaths(
            path_prefix=path.join("non_linear", "emcee"))
        emcee.paths._identifier = "tag"

        model = af.ModelMapper(mock_class=af.m.MockClassx4)
        model.mock_class.two = af.LogUniformPrior(lower_limit=1e-8,
                                                  upper_limit=10.0)

        samples = emcee.samples_from(model=model)

        assert isinstance(samples.parameter_lists, list)
        assert isinstance(samples.parameter_lists[0], list)
        assert isinstance(samples.log_likelihood_list, list)
        assert isinstance(samples.log_prior_list, list)
        assert isinstance(samples.log_posterior_list, list)
        assert isinstance(samples.weight_list, list)

        assert samples.parameter_lists[0] == pytest.approx(
            [0.173670, 0.162607, 3095.28, 0.62104], 1.0e-4)
        assert samples.log_likelihood_list[0] == pytest.approx(
            -17257775239.32677, 1.0e-4)
        assert samples.log_prior_list[0] == pytest.approx(
            1.6102016075510708, 1.0e-4)
        assert samples.weight_list[0] == pytest.approx(1.0, 1.0e-4)
        assert samples.total_steps == 1000
        assert samples.total_walkers == 10
        assert samples.auto_correlations.times[0] == pytest.approx(
            31.98507, 1.0e-4)
Exemple #2
0
    def test__loads_from_config_file_correct(self):

        emcee = af.Emcee(
            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),
            number_of_cores=2,
        )

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

        emcee = af.Emcee()

        assert emcee.prior_passer.sigma == 3.0
        assert emcee.prior_passer.use_errors is True
        assert emcee.prior_passer.use_widths is True
        assert emcee.config_dict_search["nwalkers"] == 50
        assert emcee.config_dict_run["nsteps"] == 2000
        assert isinstance(emcee.initializer, af.InitializerPrior)
        assert emcee.auto_correlations_settings.check_for_convergence is True
        assert emcee.auto_correlations_settings.check_size == 100
        assert emcee.auto_correlations_settings.required_length == 50
        assert emcee.auto_correlations_settings.change_threshold == 0.01
        assert emcee.number_of_cores == 1
Exemple #3
0
    def test__median_pdf_parameters(self):
        emcee = af.Emcee()
        emcee.paths = af.DirectoryPaths(
            path_prefix=path.join("non_linear", "emcee"))
        emcee.paths._identifier = "tag"

        model = af.ModelMapper(mock_class=af.m.MockClassx4)
        model.mock_class.two = af.LogUniformPrior(lower_limit=1e-8,
                                                  upper_limit=10.0)

        samples = emcee.samples_from(model=model)

        assert samples.median_pdf_vector == pytest.approx(
            [0.008422, -0.026413, 9.9579656, 0.494618], 1.0e-3)
Exemple #4
0
    def test__autocorrelation_times(self):
        emcee = af.Emcee()
        emcee.paths = af.DirectoryPaths(
            path_prefix=path.join("non_linear", "emcee"))
        emcee.paths._identifier = "tag"

        model = af.ModelMapper(mock_class=af.m.MockClassx4)
        model.mock_class.two = af.LogUniformPrior(lower_limit=1e-8,
                                                  upper_limit=10.0)

        samples = emcee.samples_from(model=model)

        assert samples.auto_correlations.previous_times == pytest.approx(
            [31.1079, 36.0910, 72.44768, 65.86194], 1.0e-4)
        assert samples.auto_correlations.times == pytest.approx(
            [31.98507, 36.51001, 73.47629, 67.67495], 1.0e-4)
Exemple #5
0
    def test__vector_at_sigma__uses_output_files(self):
        emcee = af.Emcee()
        emcee.paths = af.DirectoryPaths(
            path_prefix=path.join("non_linear", "emcee"))
        emcee.paths._identifier = "tag"

        model = af.ModelMapper(mock_class=af.m.MockClassx4)
        model.mock_class.two = af.LogUniformPrior(lower_limit=1e-8,
                                                  upper_limit=10.0)

        samples = emcee.samples_from(model=model)

        parameters = samples.vector_at_sigma(sigma=3.0)

        assert parameters[0][0:2] == pytest.approx((-0.003197, 0.019923), 1e-2)

        parameters = samples.vector_at_sigma(sigma=1.0)

        assert parameters[0][0:2] == pytest.approx((0.0042278, 0.01087681),
                                                   1e-2)
Exemple #6
0
For users familiar with Markov Chain Monte Carlo (MCMC) non-linear samplers, PyAutoFit supports the non-linear
search *Emcee* (af.Emcee). We have found this to be less effective at lens modeling than Dynesty and PySwarms,
but it is sill pretty successful. I've included an example run of Emcee below.
"""

# %%
phase_mcmc = al.PhaseImaging(
    phase_name="phase_t7_mcmc",
    settings=settings,
    galaxies=dict(
        lens=al.GalaxyModel(
            redshift=0.5, light=al.lp.EllipticalSersic, mass=al.mp.EllipticalIsothermal
        ),
        source=al.GalaxyModel(redshift=1.0, light=al.lp.EllipticalSersic),
    ),
    search=af.Emcee(nwalkers=50, nsteps=1000),
)

print(
    "Emcee 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_mcmc = phase_mcmc.run(dataset=imaging, mask=mask)

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

# # aplt.FitImaging.subplot_fit_imaging(fit=result_mcmc.max_log_likelihood_fit)
(In our convention, a mask value of 'True' means it IS masked and thus removed from the fit).
"""

# %%
mask = np.full(fill_value=False, shape=dataset.data.shape)
mask[-30:] = True

# %%
"""
Lets now reperform the fit from tutorial 4, but with a masked dataset and visualization.
"""

# %%
phase = htf.Phase(phase_name="phase_t5",
                  gaussian=af.PriorModel(htf.Gaussian),
                  search=af.Emcee())

print(
    "Emcee has begun running - checkout the autofit_workspace/howtofit/chapter_1_introduction/output/phase_t4"
    "folder for live output of the results."
    "This Jupyter notebook cell with progress once Emcee has completed - this could take a few minutes!"
)

# %%
"""
Note that we are passing our mask to the phase run function, which we did not in previous tutorials.
"""

# %%
phase.run(dataset=dataset, mask=mask)
- data_trim_right:

  This behaves the same as data_trim_left, however data is removed from the right (e.g. 1D index values from the
  shape of the 1D data).

For our first phase, we will omit both the phase setting (by setting it to None) and perform the fit from tutorial
4 where we fit a single Gaussian profile to data composed of a single Gaussian (unlike tutorial 4, we'll use a
CollectionPriorModel to do this).
"""

# %%
phase = htf.Phase(
    phase_name="phase_t7",
    profiles=af.CollectionPriorModel(gaussian=htf.profiles.Gaussian),
    settings=htf.PhaseSettings(data_trim_left=None, data_trim_right=None),
    search=af.Emcee(),
)

# %%
"""
Import the simulator module, set up the Dataset and mask and set up the dataset.
"""

# %%
from autofit_workspace.howtofit.simulators.chapter_1 import gaussian_x1

dataset = htf.Dataset(data=gaussian_x1.data, noise_map=gaussian_x1.noise_map)
mask = np.full(fill_value=False, shape=dataset.data.shape)

print(
    "Emcee has begun running - checkout the autofit_workspace/howtofit/chapter_1_introduction/output/phase_t6"
Exemple #9
0
https://github.com/dfm/emcee
https://emcee.readthedocs.io/en/stable/

**PyAutoFit** extends **emcee** by providing an option to check the auto-correlation length of the samples
during the run and terminating sampling early if these meet a specified threshold. See this page
(https://emcee.readthedocs.io/en/stable/tutorials/autocorr/#autocorr) for a description of how this is implemented.
"""

# %%
emcee = af.Emcee(
    nwalkers=50,
    nsteps=2000,
    initializer=af.InitializerBall(lower_limit=0.49, upper_limit=0.51),
    auto_correlation_check_for_convergence=True,
    auto_correlation_check_size=100,
    auto_correlation_required_length=50,
    auto_correlation_change_threshold=0.01,
    number_of_cores=1,
    paths=af.Paths(folders=["examples", "complex"]),
)

# %%
result = emcee.fit(model=model, analysis=analysis)

# %%
"""
__Result__

The result object returned by Emcee's fit is similar in structure to the Dynesty result above - it again provides
us with the maximum log likelihood instance.
import autofit as af
import autolens as al
import autolens.plot as aplt

"""
First, lets create a result via emcee 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 emcee.
"""
dataset_name = "mass_sie__source_sersic"

search = af.Emcee(
    path_prefix=path.join("plot"),
    name="EmceePlotter",
    unique_tag=dataset_name,
    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
It is worth noting that the name of this config file, 'gaussian.json', is not a conincedence. It is named after the
module we imported to create the _PriorModel_, the 'gaussian.py' module. Thus, our the json_config files we use to
set up the default priors of different model components share the name of the module they are in! 

Although we don't in this tutorial, we could of course over write the priors with new priors as we did in the previous
tutorial.

Lets instantiate and run a phase, which reduces the task of performing a model-fit in PyAutoFit to just two lines. 
The results are output to the path 'autofit_workspace/howtofit/chapter_1_introduction/output/phase_t4/emcee', which in 
contrast to the previous tutorial includes the phase name in the path structure.
"""

# %%
phase = htf.Phase(
    phase_name="phase_t4", gaussian=af.PriorModel(htf.Gaussian), search=af.Emcee()
)

print(
    "Emcee has begun running - checkout the autofit_workspace/howtofit/chapter_1_introduction/output/phase_t4/emcee"
    "folder for live output of the results."
    "This Jupyter notebook cell with progress once Emcee has completed - this could take a few minutes!"
)

result = phase.run(dataset=dataset)

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

# %%
"""
The phase returns a Result object, just like the model-fit performed in the previous tutorial did. However, in
"""
__Analysis__

We now set up our Analysis, using the class described in `analysis.py`. The analysis describes how given an instance
of our model (a `Gaussian` + Exponential) we fit the data and return a log likelihood value. For this simple example,
we only have to pass it the data and its noise-map.
"""
analysis = a.Analysis(data=data, noise_map=noise_map)

"""Returns the non-linear object for emcee and perform the fit."""
emcee = af.Emcee(
    nwalkers=50,
    nsteps=2000,
    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,
    ),
    number_of_cores=1,
)

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

"""
__RESULT__

Here, we'll look in detail at how the information contained in the result changes when we fit a more complex model. If
you are unfamiliar with the result object, first read through `overview/simple/result.py`.

First, we can note that the parameters list of lists now has 6 entries in the parameters column, given the 
"""
To perform the non-linear search using Emcee, we simply compose our model using a PriorModel, instantiate the Analysis
class and pass them to an instance of the Emcee class.

We manually set the priors on the model, in the next tutorial we'll cover how this can be performed automatically.
"""

# %%
model = af.PriorModel(Gaussian)
model.centre = af.UniformPrior(lower_limit=0.0, upper_limit=100.0)
model.intensity = af.UniformPrior(lower_limit=0.0, upper_limit=1e2)
model.sigma = af.UniformPrior(lower_limit=0.0, upper_limit=50.0)

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

emcee = af.Emcee()

# %%
"""
We begin the non-linear search by calling its fit method, it  will take a minute or so to run (which is very fast for a 
model-fit). Whilst you're waiting, checkout the folder:

'autofit_workspace/howtofit/chapter_1_introduction/output/emcee'

Here, the results of the model-fit are output to your hard-disk (on-the-fly) and you can inspect them as the non-linear
search runs. In particular, you'll find:

 - model.info: A file listing every model component, parameter and prior in your model-fit.

 - model.results: A file giving the latest best-fit model, parameter estimates and errors of the fit.
 
end with Dynesty for robust errors. Here, we choose our non-linear searches based on what result we want!
"""

# %%
"""
__MCMC__

For users familiar with Markov Chain Monte Carlo (MCMC) non-linear samplers, PyAutoFit supports the non-linear
search *Emcee* (af.Emcee). We have found this to be less effective at lens modeling than Dynesty and PySwarms,
but it is sill pretty successful. I've included an example run of Emcee below.
"""

# %%
phase_mcmc = al.PhaseImaging(
    search=af.Emcee(path_prefix="howtolens",
                    name="phase_t6_mcmc",
                    nwalkers=50,
                    nsteps=1000),
    settings=settings,
    galaxies=af.CollectionPriorModel(
        lens=al.GalaxyModel(redshift=0.5,
                            bulge=al.lp.EllipticalSersic,
                            mass=al.mp.EllipticalIsothermal),
        source=al.GalaxyModel(redshift=1.0, bulge=al.lp.EllipticalSersic),
    ),
)

print(
    "Emcee 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!"
)
            title="Chi-Squared Map",
            ylabel="Chi-Squareds",
            color="k",
            output_path=paths.image_path,
            output_filename="chi_squared_map",
        )


"""
Lets now repeat the fit of the previous tutorial, but with visualization.
"""
import gaussian as g

model = af.Model(g.Gaussian)

emcee = af.Emcee(path_prefix=path.join("howtofit", "chapter_1"),
                 name="tutorial_4_visualization")

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

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

print(
    "Emcee has begun running - checkout the autofit_workspace/output/howtofit/tutorial_4_visualization"
    " folder for live output of the results."
    "This Jupyter notebook cell with progress once Emcee has completed - this could take a few minutes!"
)

print("Emcee has finished run - you may now continue the notebook.")
"""
Lets check that this model-fit performs visualization. Navigate to the folder `image` in the directory 
`autofit_workspace/output/howtofit. You should see `.png` files containing images of the data, 
Exemple #16
0
    """
    In all examples so far, our results have gone to the default path, which was the '/output/' folder and a folder
    name after the non linear search. However, we can manually specify the path of the results in the 'output' folder.
    
    We do this belo, using the Paths class and the input parameters 'folders' and 'non_linear_name'. These
    define the names of folders that the phase goes in, in this case:

    '/path/to/autofit_workspace/output/aggregator_example/gaussian_x1_0/emcee/'
    """

    emcee = af.Emcee(
        paths=af.Paths(folders=["aggregator_example", dataset_names[index]]),
        nwalkers=30,
        nsteps=1000,
        initializer=af.InitializerBall(lower_limit=0.49, upper_limit=0.51),
        auto_correlation_check_for_convergence=True,
        auto_correlation_check_size=100,
        auto_correlation_required_length=50,
        auto_correlation_change_threshold=0.01,
        number_of_cores=1,
    )

    print(
        f"Emcee has begun running - checkout the autofit_workspace/output/{dataset_names[index]} folder for live "
        f"output of the results. This Jupyter notebook cell with progress once Emcee has completed - this could take a "
        f"few minutes!")

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

print("Emcee has finished run - you may now continue the notebook.")
For a full description of Emcee, checkout its Github and readthedocs webpages:

https://github.com/dfm/emcee
https://emcee.readthedocs.io/en/stable/

**PyAutoFit** extends **emcee** by providing an option to check the auto-correlation length of the samples
during the run and terminating sampling early if these meet a specified threshold. See this page
(https://emcee.readthedocs.io/en/stable/tutorials/autocorr/#autocorr) for a description of how this is implemented.
"""
emcee = af.Emcee(
    path_prefix=path.join("overview", "complex", "fit"),
    nwalkers=50,
    nsteps=2000,
    initializer=af.InitializerBall(lower_limit=0.49, upper_limit=0.51),
    auto_correlation_check_for_convergence=True,
    auto_correlation_check_size=100,
    auto_correlation_required_length=50,
    auto_correlation_change_threshold=0.01,
    number_of_cores=1,
    session=session,
)

result = emcee.fit(model=model, analysis=analysis)
"""
__Result__

The result object returned by Emcee`s fit is similar in structure to the Dynesty result above - it again provides
us with the maximum log likelihood instance.
"""
instance = result.max_log_likelihood_instance
        )


"""
__Model Fit__

Now lets run the non-linear search to get ourselves a `Result`.
"""
import profiles as p

model = af.Collection(gaussian=p.Gaussian)

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

emcee = af.Emcee(
    name="tutorial_6_results_and_samples",
    path_prefix=path.join("howtofit", "chapter_1"),
)

print(
    "Emcee has begun running. \n"
    "Checkout the autofit_workspace/output/howtofit/tutorial_6__results_and_samples \n"
    "folder for live output of the results.\n"
    "This Jupyter notebook cell with progress once Emcee has completed - this could take a few minutes!"
)

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

print("Emcee has finished run - you may now continue the notebook.")
"""
__Result__
Exemple #19
0
"""
analysis = al.AnalysisImaging(dataset=imaging)
"""
__Search__

Below we use emcee to fit the lens model, using the model with start points as described above. See the Emcee docs
for a description of what the input parameters below do.
"""
search = af.Emcee(
    path_prefix=path.join("imaging", "searches"),
    name="Emcee",
    unique_tag=dataset_name,
    nwalkers=30,
    nsteps=500,
    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,
    ),
    iterations_per_update=5000,
    number_of_cores=1,
)

result = search.fit(model=model, analysis=analysis)
"""
__Result__

We can use an `EmceePlotter` to create a corner plot, which shows the probability density function (PDF) of every
parameter in 1D and 2D.
"""
dataset_path = path.join("dataset", "example_1d",
                         "gaussian_x1__exponential_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 Fit__

Lets now perform the fit using our model which is composed of two profile's. You'll note that the `Emcee`
dimensionality has increased from N=3 to N=6, given that we are now fitting two `Profile`'s each with 3 free parameters.
"""
analysis = Analysis(data=data, noise_map=noise_map)

emcee = af.Emcee(
    path_prefix=path.join("howtofit", "chapter_1"),
    name="tutorial_5__gaussian_x1__exponential_x1",
)

print(
    "Emcee has begun running. \n"
    "Checkout the autofit_workspace/output/howtofit/tutorial_5__gaussian_x1__exponential_x1 \n"
    "folder for live output of the results.\n"
    "This Jupyter notebook cell with progress once Emcee has completed - this could take a few minutes!"
)

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

print("Emcee has finished run - you may now continue the notebook.")
"""
Inspect the results of the fit by going to the folder 
`autofit_workspace/output/howtofit/tutorial_5__gaussian_x1__exponential_x1`. The fit takes longer to run than 
Exemple #21
0
"""

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

# %%
"""
Create the non-linear object for emcee and perform the fit.
"""

# %%
emcee = af.Emcee(
    nwalkers=30,
    nsteps=1000,
    initializer=af.InitializerBall(lower_limit=0.49, upper_limit=0.51),
    auto_correlation_check_for_convergence=True,
    auto_correlation_check_size=100,
    auto_correlation_required_length=50,
    auto_correlation_change_threshold=0.01,
    number_of_cores=1,
)

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

# %%
"""
__Result__

Here, we'll look in detail at what information is contained in the result.

It contains a *Samples* object, which contains information on the non-linear sampling, for example the parameters. 
The parameters are stored as a a list of lists, where the first entry corresponds to the sample index and second entry
    "  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)
fit_imaging_plotter.subplot_fit_imaging()


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

print(
    "Emcee 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_emcee = search.fit(model=model, analysis=analysis)

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

fit_imaging_plotter = aplt.FitImagingPlotter(fit=result_emcee.max_log_likelihood_fit)
    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)

emcee = af.Emcee(
    path_prefix=path.join("plot"),
    name="EmceePlotter",
    nwalkers=100,
    nsteps=500,
    iterations_per_update=50000,
)

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

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

The emcee readthedocs describes fully all of the methods used below 

 - https://emcee.readthedocs.io/en/stable/user/sampler/
 
"""
To perform the `NonLinearSearch` using `Emcee`, we simply compose our model using a `Model`, instantiate the 
`Analysis` class and pass them to an instance of the `Emcee` class. 

We also pass a `name` and `path_prefrix`, which specifies that when the results are output to the folder 
`autofit_workspace/output` they'll also be written to the folder `howtofit/chapter_1/tutorial_3`.
"""
model = af.Model(g.Gaussian)
model.centre = af.UniformPrior(lower_limit=0.0, upper_limit=100.0)
model.intensity = af.UniformPrior(lower_limit=0.0, upper_limit=1e2)
model.sigma = af.UniformPrior(lower_limit=0.0, upper_limit=50.0)

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

emcee = af.Emcee(path_prefix=path.join("howtofit", "chapter_1"),
                 name="tutorial_3_non_linear_search")
"""
We begin the `NonLinearSearch` by calling its `fit` method. This will take a minute or so to run (which is very fast 
for a model-fit). Whilst you're waiting, checkout the folder:

`autofit_workspace/output/howtofit`

Here, the results of the model-fit are output to your hard-disk (on-the-fly) and you can inspect them as the non-linear
search runs. 

__Unique Identifier__

In the output folder, you will note that results are in a folder which is a collection of random characters. This acts 
as a `unique_identifier` of the model-fit, where this identifier is generated based on the model and search that are 
used in the fit.
 
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.normalization = 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)

emcee = af.Emcee(
    path_prefix=path.join("plot"), name="EmceePlotter", nwalkers=100, nsteps=500
)

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

samples = result.samples

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

The emcee readthedocs describes fully all of the methods used below 

 - https://emcee.readthedocs.io/en/stable/user/sampler/
 
 The plotter wraps the `corner` method of the library `corner.py` to make corner plots of the PDF: