Skip to content

Commit

Permalink
restore fit_from
Browse files Browse the repository at this point in the history
  • Loading branch information
Jammy2211 committed Oct 3, 2024
1 parent 9cd4e70 commit c322507
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
44 changes: 44 additions & 0 deletions autogalaxy/imaging/model/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,50 @@ def log_likelihood_function(self, instance: af.ModelInstance) -> float:
) as e:
raise exc.FitException from e

def fit_from(
self,
instance: af.ModelInstance,
run_time_dict: Optional[Dict] = None,
) -> FitImaging:
"""
Given a model instance create a `FitImaging` object.
This function is used in the `log_likelihood_function` to fit the model to the imaging data and compute the
log likelihood.
Parameters
----------
instance
An instance of the model that is being fitted to the data by this analysis (whose parameters have been set
via a non-linear search).
preload_overwrite
If a `Preload` object is input this is used instead of the preloads stored as an attribute in the analysis.
run_time_dict
A dictionary which times functions called to fit the model to data, for profiling.
Returns
-------
FitImaging
The fit of the galaxies to the imaging dataset, which includes the log likelihood.
"""

galaxies = self.galaxies_via_instance_from(
instance=instance, run_time_dict=run_time_dict
)

dataset_model = self.dataset_model_via_instance_from(instance=instance)

adapt_images = self.adapt_images_via_instance_from(instance=instance)

return FitImaging(
dataset=self.dataset,
galaxies=galaxies,
dataset_model=dataset_model,
adapt_images=adapt_images,
settings_inversion=self.settings_inversion,
run_time_dict=run_time_dict,
)

def save_attributes(self, paths: af.DirectoryPaths):
"""
Before the non-linear search begins, this routine saves attributes of the `Analysis` object to the `files`
Expand Down
40 changes: 40 additions & 0 deletions autogalaxy/interferometer/model/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,46 @@ def log_likelihood_function(self, instance: af.ModelInstance) -> float:
) as e:
raise exc.FitException from e

def fit_from(
self,
instance: af.ModelInstance,
run_time_dict: Optional[Dict] = None,
) -> FitInterferometer:
"""
Given a model instance create a `FitInterferometer` object.
This function is used in the `log_likelihood_function` to fit the model to the interferometer data and compute
the log likelihood.
Parameters
----------
instance
An instance of the model that is being fitted to the data by this analysis (whose parameters have been set
via a non-linear search).
preload_overwrite
If a `Preload` object is input this is used instead of the preloads stored as an attribute in the analysis.
run_time_dict
A dictionary which times functions called to fit the model to data, for profiling.
Returns
-------
FitInterferometer
The fit of the galaxies to the interferometer dataset, which includes the log likelihood.
"""
galaxies = self.galaxies_via_instance_from(
instance=instance, run_time_dict=run_time_dict
)

adapt_images = self.adapt_images_via_instance_from(instance=instance)

return FitInterferometer(
dataset=self.dataset,
galaxies=galaxies,
adapt_images=adapt_images,
settings_inversion=self.settings_inversion,
run_time_dict=run_time_dict,
)

def save_attributes(self, paths: af.DirectoryPaths):
"""
Before the model-fit begins, this routine saves attributes of the `Analysis` object to the `files` folder
Expand Down

0 comments on commit c322507

Please sign in to comment.