@property
def samples_cls(self):
raise NotImplementedError()
def samples_from(self, model: AbstractPriorModel, search_internal=None) -> Samples:
"""
Loads the samples of a non-linear search from its output files.
The samples can be loaded from one of two files, which are attempted to be loading in the following order:
1) Load via the internal results of the non-linear search, which are specified to that search's outputs
(e.g. the .hdf file output by the MCMC method `emcee`).
2) Load via the `samples.csv` and `samples_info.json` files of the search, which are outputs that are the
same for all non-linear searches as they are homogenized by autofit.
Parameters
----------
model
The model which generates instances for different points in parameter space.
"""
try:
return self.samples_via_internal_from(
model=model, search_internal=search_internal
)
except (FileNotFoundError, NotImplementedError, AttributeError):
return self.samples_via_csv_from(model=model)
def samples_via_internal_from(
self, model: AbstractPriorModel, search_internal=None
):
raise NotImplementedError
def samples_via_csv_from(self, model: AbstractPriorModel) -> Samples:
"""
Returns a `Samples` object from the `samples.csv` and `samples_info.json` files.
The samples contain all information on the parameter space sampling (e.g. the parameters,
log likelihoods, etc.).
The samples in csv format are already converted to the autofit format, where samples are lists of values
(e.g. `parameter_lists`, `log_likelihood_list`).
Parameters
----------
model
Maps input vectors of unit parameter values to physical values and model instances via priors.
"""
return self.samples_cls.from_csv(
paths=self.paths,
model=model,
)
search.pyhas a lot of annoying similar methods to do with samples:samples_clsis particularly annoying, and associated with searches based on their type.We can simplify this as follows:
Remove
samples_via_csv_fromand move its functionality tosamples_from.Make a factory in
Sampleswhich has all functionality insamples_from. This will inspect the type of the inputsearch_internaland return theSamplesobject based on its type (e.g. ifsearch_internalis aNestSearchthen returnSamplesNest).The function
samples_via_internal_frommust still stay insearch, we commonly overwrite it to map the internal search parameter / likelihood values to autofit values and layout.