Skip to content

Commit 3f8ce4d

Browse files
Jammy2211Jammy2211
authored andcommitted
docs
1 parent 57ed16b commit 3f8ce4d

1 file changed

Lines changed: 51 additions & 13 deletions

File tree

docs/overview/the_basics.rst

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -573,31 +573,69 @@ Multiple Datasets
573573
Many model-fitting problems require multiple datasets to be fitted simultaneously in order to provide the best
574574
constraints on the model.
575575

576-
In **PyAutoFit**, all you have to do to fit multiple datasets is sum your ``Analysis`` classes together:
576+
In **PyAutoFit**, all you have to do to fit multiple datasets is combine them with the model via ``AnalysisFactor``
577+
objects.
577578

578579
.. code-block:: python
579580
580-
analysis_0 = Analysis(data=data_0, noise_map=noise_map_0)
581-
analysis_1 = Analysis(data=data_1, noise_map=noise_map_1)
581+
analysis_0 = Analysis(data=data, noise_map=noise_map)
582+
analysis_1 = Analysis(data=data, noise_map=noise_map)
582583
583-
# This means the model is fitted to both datasets simultaneously.
584+
analysis_list = [analysis_0, analysis_1]
584585
585-
analysis = analysis_0 + analysis_1
586+
analysis_factor_list = []
586587
587-
# summing a list of analysis objects is also a valid API:
588+
for analysis in analysis_list:
588589
589-
analysis = sum([analysis_0, analysis_1])
590+
# The model can be customized here so that different model parameters are tied to each analysis.
591+
model_analysis = model.copy()
590592
591-
By summing analysis objects the log likelihood values computed by the ``log_likelihood_function`` of each individual
592-
analysis class are summed to give an overall log likelihood value that the non-linear search samples when model-fitting.
593+
analysis_factor = af.AnalysisFactor(prior_model=model_analysis, analysis=analysis)
594+
595+
analysis_factor_list.append(analysis_factor)
596+
597+
All ``AnalysisFactor`` objects are combined into a ``FactorGraphModel``, which represents a global model fit to
598+
multiple datasets using a graphical model structure.
599+
600+
The key outcomes of this setup are:
601+
602+
- The individual log likelihoods from each ``Analysis`` object are summed to form the total log likelihood
603+
evaluated during the model-fitting process.
604+
605+
- Results from all datasets are output to a unified directory, with subdirectories for visualizations
606+
from each analysis object, as defined by their ``visualize`` methods.
607+
608+
This is a basic use of **PyAutoFit**'s graphical modeling capabilities, which support advanced hierarchical
609+
and probabilistic modeling for large, multi-dataset analyses.
610+
611+
To inspect the model, we print ``factor_graph.global_prior_model.info``.
612+
613+
.. code-block:: python
614+
615+
print(factor_graph.global_prior_model.info)
616+
617+
To fit multiple datasets, we pass the ``FactorGraphModel`` to a non-linear search.
618+
619+
Unlike single-dataset fitting, we now pass the ``factor_graph.global_prior_model`` as the model and
620+
the ``factor_graph`` itself as the analysis object.
621+
622+
This structure enables simultaneous fitting of multiple datasets in a consistent and scalable way.
623+
624+
.. code-block:: python
625+
626+
search = af.DynestyStatic(
627+
nlive=100,
628+
)
629+
630+
result_list = search.fit(model=factor_graph.global_prior_model, analysis=factor_graph)
593631
594632
.. note::
595633

596634
In the simple example above, instances of the same ``Analysis`` class (``analysis_0`` and ``analysis_1``) were
597-
summed. However, different ``Analysis`` classes can also be summed together. This is useful when fitting different
598-
datasets that each require a unique ``log_likelihood_function`` to be fitted simultaneously. For more detailed
599-
information and a dedicated API for customizing how the model changes across different datasets, refer to
600-
the [multiple datasets cookbook](https://pyautofit.readthedocs.io/en/latest/cookbooks/multiple_datasets.html).
635+
combined. However, different ``Analysis`` classes can also be combined. This is useful when fitting different
636+
datasets that each require a unique ``log_likelihood_function`` to be fitted simultaneously. For more detailed
637+
information and a dedicated API for customizing how the model changes across different datasets, refer to
638+
the [multiple datasets cookbook](https://pyautofit.readthedocs.io/en/latest/cookbooks/multiple_datasets.html).
601639

602640
Wrap Up
603641
-------

0 commit comments

Comments
 (0)