Nested Sampling#
Nested Sampling Engine#
Orchestrates the nested-sampling run with support for nestle, PyMultiNest, and UltraNest back-ends.
- class ForMoSA.nested_sampling.nested_sampling.NestedSampling(algorithm, npoints, logL_type, config_NS, observations, subgrids, parameters, wave_fit=None, interp_method='linear', bounds_lsq=None, logger=None, log_level='INFO')[source]#
Bases:
objectForMoSA Nested_Sampling class, which provides easy access to the parameters of the nested sampling algorithm
- Parameters:
algorithm (
NestedAlgorithm) – Algorithm used for the nested sampling (‘nestle’, ‘ultranest’ or ‘pymultinest’)npoints (
int) – Number of living points used for the nested samplinglogL_type (
list[LogLikelihoodType]) – List of loglikelihood types used in the nested samplingconfig_NS (
Config_NS) – Instance of class Config_NS containing parameters of ns algorithms for each of the algorithmobservations (
ObservationSet) – Instance of ObservationSetsubgrids (
SubGridSet) – Instance of SubGridSetparameters (
ParameterSet) – Instance of ParameterSetwave_fit (
list[str] |None) – List of wavelength grid used for fittinginterp_method (
str) – Interpolation method (‘linear’, ‘cubic’, ‘spline’, …)bounds_lsq (
list[tuple[float,float]] |None) – List of bounds used for the least squares (used for high contrast)log_level (
str) – Level of the Logger
Notes
Authors: Allan Denis
- property observations: ObservationSet#
Set of observations.
- property subgrids: SubGridSet#
Set of subgrids.
- property parameters: ParameterSet#
Priors parameters.
- property restricted_observations: ObservationSet#
Set of restricted observations according to wave_fit.
- property restricted_subgrids: SubGridSet#
Set of restricted subgrids according to wave_fit.
- classmethod from_dict(data, observations, subgrids, logger=None, log_level='INFO')[source]#
Reconstruct an instance of NestedSampling from a dictionary of NestedSampling.
- Parameters:
data (
dict) – Dictionary representation NestedSampling parametersobservations (
ObservationSet) – Instance of ObservationSetsubgrids (
SubGridSet) – Instance of SubGridSetlog_level (
str) – Level of the Logger
- Return type:
- Returns:
‘NestedSampling’ – An instance of class NestedSampling
Notes
Authors: Allan Denis
- classmethod from_json(path, observations, subgrids, logger=None, log_level='INFO')[source]#
Reconstruct an instance of NestedSampling from the folder containing the NestedSampling parameters.
- Parameters:
path (
str|PathLike) – Dictionary representation NestedSampling parametersobservations (
ObservationSet) – Instance of ObservationSetsubgrids (
SubGridSet) – Instance of SubGridSetlog_level (
str) – Level of the Logger
- Return type:
- Returns:
‘NestedSampling’ – An instance of class NestedSampling
Notes
Authors: Allan Denis
- run(results_path)[source]#
Method to run the nested sampling algorithm using the model, observation and nested sampling parameters.
Notes
Authors: Simon Petrus, Matthieu Ravet and Allan Denis
- prior_transform(theta)[source]#
ransform theta in [0,1]^N into physical values for free parameters.
- Parameters:
theta (
ndarray[float]) – List of the parameters drawn by the nested sampling algorithm- Return type:
- Returns:
np.ndarray[float] – Transformed values
Notes
Authors: Allan Denis
- build_models_from_theta(theta)[source]#
Build the models from the values of the free parameters drawn by the Nested Sampling
- Parameters:
theta (
ndarray[float]) – List of values picked by the Nested Sampling for the free parameters- Return type:
- Returns:
list[ObservedModel] – List of instances of class ObservedModel
Notes
Authors: Allan Denis
NS Analysis#
Post-processing of nested-sampling products: best-fit reconstruction, CCF computation, RV–v sin i maps, and confidence intervals.
- class ForMoSA.nested_sampling.ns_analysis.NSAnalysis(ns, logger=None, log_level='INFO')[source]#
Bases:
objectClass used to subsequent analysis of nested sampling products. It includes the reconstructions of models, best fit, computations of ccf, …
- Parameters:
ns (
NestedSampling) – Instance of class NestedSamplinglog_level (
str) – Level of the Logger
Notes
Authors: Allan Denis
- property ns: NestedSampling#
Instance of NestedSampling.
- property best_fit: list[ObservedModel]#
Best fit.
- property native_best_fit: ObservedModel#
Best fit parameters applied to the native model.
- build_models_from_theta(theta)[source]#
Build the models from the values of the free parameters drawn by the Nested Sampling
- Parameters:
theta (np.ndarray[float]) – List of values picked by the Nested Sampling for the free parameters
- Returns:
list[ObservedModel] – List of instances of class ObservedModel
Notes
Authors: Allan Denis
- best_fit_interval(perc=0.68)[source]#
Confidence interval of the native best fit.
- Parameters:
perc (
float) – Percentile value between 0 and 1 (0.68 for 1 sigma, 0.95 for 2 sigmas)- Return type:
- Returns:
tuple[ObservedModel, ObservedModel] – lower and higher values of the flux for the confidence interval
Notes
Authors: Allan Denis
- compute_ccf(rv_grid, index=0, theta=None)[source]#
Compute and optionally plot the Cross-Correlation Function (CCF).
- Parameters:
- Return type:
- Returns:
dict[str, np.ndarray] – Dictionary of CCF results keyed by observation name
Notes
Authors: Bhavesh Rajpoot and Allan Denis
- compute_rv_vsini_map(rv_grid, vsini_grid, index=0, theta=None)[source]#
Compute and optionally plot the RV vs v.sin(i) loglikelihood map.
- Parameters:
- Return type:
- Returns:
dict[str, np.ndarray] – Dictionary of RV-vsini map results keyed by observation name
Notes
Authors: Bhavesh Rajpoot and Allan Denis
Results#
Data container that stores the raw output of a nested-sampling run.
- class ForMoSA.nested_sampling.results.NSResults(samples, weights, logl, logvol, logz, free_parameters, burn_in=0)[source]#
Bases:
objectDataclass to handle reading and storing results of the Nested Sampling algorithm
Notes
Authors: Allan Denis
- Parameters:
- classmethod from_dict(data)[source]#
Load NSResults from dictionary.
- Parameters:
- Return type:
- Returns:
NSResults – Instance of class NSResults
Notes
Authors: Allan Denis
- classmethod from_nestle(res, free_parameters)[source]#
Return an instance of NSResults based on the results of a Nestle algorithm.
- Parameters:
- Return type:
- Returns:
NestleResults – An instance of NSResults
Notes
Authors: Allan Denis
- classmethod from_pymultinest(results_path, free_parameters)[source]#
Return an instance of NSResults based on the results of a PyMultinest algorithm.
- Parameters:
- Return type:
- Returns:
NSResults – An instance of NSResults
Notes
Authors: Allan Denis
Prior Functions#
Low-level prior sampling functions used internally by the
prior classes.
- ForMoSA.utils.prior_functions.uniform_prior(bounds, theta)[source]#
Uniform prior for nested sampling.
- Parameters:
- Return type:
- Returns:
float – Evaluated prior
Notes
Authors: Simon Petrus
- ForMoSA.utils.prior_functions.loguniform_prior(prior_fct_arg, theta)[source]#
LogUniform prior for nested sampling.
- Parameters:
- Return type:
- Returns:
float – Evaluated prior
Notes
Authors: Simon Petrus
Likelihood Functions#
Log-likelihood functions available for nested sampling.
- ForMoSA.utils.logL_functions.logL_chi2(delta_flx, err, full=False)[source]#
Function to compute logL based on the classical chi2 under the assumption of gaussian and spectrally uncorrelated noise.
- Parameters:
delta_flx (array) – residual data-model as a function of wavelength
err (array) – error (=standard deviation) of the observed spectrum as a function of wavelength
full (bool) – True or False to add the usual constant terms
- Returns:
float – the loglikelihood value
Notes
Authors: Matthieu Ravet
- ForMoSA.utils.logL_functions.logL_chi2_covariance(delta_flx, cov, inv_cov, full=False)[source]#
Function to compute logL based on the generalized chi2 under the assumption of gaussian and spectrally correlated noise.
- Parameters:
delta_flx (array) – residual data-model as a function of wavelength
cov (n-array) – Covariance matrix of the observed spectrum as a function of wavelength
inv_cov (n-array) – inverse of the covariance matrix of the observed spectrum as a function of wavelength
full (bool) – True or False to add the usual constant terms
- Returns:
float – the loglikelihood value
Notes
Authors: Matthieu Ravet
- ForMoSA.utils.logL_functions.logL_chi2_noisescaling(delta_flx, err, full=False)[source]#
Function to compute logL based on the chi2 with a fitted noise scaling s (marginalized) under the assumption of gaussian and spectrally uncorrelated noise.
- Parameters:
delta_flx (array) – residual data-model as a function of wavelength
err (array) – error (=standard deviation) of the observed spectrum as a function of wavelength
full (bool) – True or False to add the usual constant terms
- Returns:
float – the loglikelihood value
Notes
Authors: Allan Denis and Matthieu Ravet
- ForMoSA.utils.logL_functions.logL_chi2_noisescaling_covariance(delta_flx, cov, inv_cov, full=False)[source]#
Function to compute logL based on the chi2 with a fitted noise scaling s (marginalized) under the assumption of gaussian and spectrally correlated noise.
- Parameters:
delta_flx (array) – residual data-model as a function of wavelength
cov (n-array) – Covariance matrix of the observed spectrum as a function of wavelength
inv_cov (n-array) – inverse of the covariance matrix of the observed spectrum as a function of wavelength
full (bool) – True or False to add the usual constant terms
- Returns:
float – the loglikelihood value
Notes
Authors: Allan Denis and Matthieu Ravet
- ForMoSA.utils.logL_functions.logL_CCF_Brogi(flx_obs, flx_mod)[source]#
Function to compute logL based on the CCF mapping from Brogi et al. 2019 under the assumption of gaussian and spectrally constant noise.
- Parameters:
flx_obs (array) – flux of the observation as a function of wavelength
flx_mod (array) – flux of the model as a function of wavelength
- Returns:
float – the loglikelihood value
Notes
Authors: Matthieu Ravet
- ForMoSA.utils.logL_functions.logL_CCF_Zucker(flx_obs, flx_mod)[source]#
Function to compute logL based on the CCF mapping from Zucker 2003 under the assumption of gaussian and spectrally constant noise.
- Parameters:
flx_obs (array) – flux of the observation as a function of wavelength
flx_mod (array) – flux of the model as a function of wavelength
- Returns:
float – the loglikelihood value
Notes
Authors: Matthieu Ravet
- ForMoSA.utils.logL_functions.logL_CCF_custom(flx_obs, flx_mod, err_obs)[source]#
Function to compute logL based on the custom CCF mapping from Me under the assumption of gaussian and spectrally constant noise.
- Parameters:
flx_obs (array) – flux of the observation as a function of wavelength
flx_mod (array) – flux of the model as a function of wavelength
err_obs (array) – errors of the observation as a function of wavelength
- Returns:
float – the loglikelihood value
Notes
Authors: Matthieu Ravet