Fit
Created on Fri May 24 09:38 2024
@author: MCR
Functions for fitting light curve models to data.
- class exouprf.fit.Dataset(input_parameters, t, lc_model_type, linear_regressors=None, observations=None, gp_regressors=None, ld_model='quadratic', silent=False, custom_lc_functions=None)
Primary exoUPRF class. Stores a set of light curve observations and performs light curve fits.
- fit(output_file, sampler='MCMC', mcmc_start=None, mcmc_ncores=1, mcmc_steps=10000, continue_mcmc=False, dynesty_args=None, force_redo=False, resume_dynesty=False, dynesty_resume_file=None)
Run a light curve fit.
- Parameters:
output_file (str) – Path to file to which to save outputs.
sampler (str) – Sampling to use, either ‘MCMC’ or ‘Nested Sampling’.
mcmc_start (ndarray(float)) – Starting positions for MCMC sampling. MCMC only.
mcmc_steps (int) – Number of steps to take for MCMC sampling. MCMC only.
mcmc_ncores (int) – Number of cores for multiprocessing. MCMC only.
continue_mcmc (bool) – If True, continue from a previous MCMC run saved in output_file. MCMC only.
dynesty_args (dict) – Keyword arguments to pass to the dynesty NestedSampler instance. Nested Sampling only.
force_redo (bool) – If True, will overwrite previous output files.
resume_dynesty (bool) – If True, restart sampling from a previous fit.
dynesty_resume_file (str, None) – Previous dynesty sampling save file from which to resume the fit.
- get_param_dict_from_fit(method='median', mcmc_burnin=None, mcmc_thin=15, drop_chains=None)
Reformat MCMC fit outputs into the parameter dictionary format expected by Model.
- Parameters:
method (str) – Method via which to get best fitting parameters from MCMC chains. Either “median” or “maxlike”.
mcmc_burnin (int) – Number of steps to discard as burn in. Defaults to 75% of chain length. Only for MCMC.
mcmc_thin (int) – Increment by which to thin chains. Only for MCMC.
drop_chains (list(int), None) – Indices of chains to drop.
- Returns:
param_dict – Dictionary of light curve model parameters.
- Return type:
dict
- get_results_from_fit(mcmc_burnin=None, mcmc_thin=15, drop_chains=None)
Extract MCMC posterior sample statistics (median and 1 sigma bounds) for each fitted parameter.
- Parameters:
mcmc_burnin (int) – Number of steps to discard as burn in. Defaults to 75% of chain length.
mcmc_thin (int) – Increment by which to thin chains.
drop_chains (list(int), None) – Indices of chains to drop.
- Returns:
results_dict – Dictionary of posterior medians and 1 sigma bounds for each fitted parameter.
- Return type:
dict
- make_corner_plot(mcmc_burnin=None, mcmc_thin=15, labels=None, outpdf=None, log_params=None, drop_chains=None)
Make a corner plot of fitted posterior distributions.
- Parameters:
mcmc_burnin (int) – Number of steps to discard as burn in. Defaults to 75% of chain length.
mcmc_thin (int) – Increment by which to thin chains.
labels (list(str)) – Fitted parameter names.
outpdf (PdfPages) – File to save plot.
log_params (list(int), None) – Indices of parameters to plot in log-space.
drop_chains (list(int), None) – Indices of chains to drop.
- plot_mcmc_chains(labels=None, log_params=None, highlight_chains=None, drop_chains=None)
Plot MCMC chains.
- Parameters:
labels (list(str)) – Fitted parameter names.
log_params (list(int), None) – Indices of parameters to plot in log-space.
highlight_chains (list(int), None) – Indices of chains to highlight.
drop_chains (list(int), None) – Indices of chains to drop.
- exouprf.fit.fit_dynesty(prior_transform, log_like, ndim, output_file, log_like_args, ptform_kwargs, dynesty_args=None, silent=False, resume=False, resume_file=None)
Run a light curve fit via nested sampling using the dynesty.
- Parameters:
prior_transform (function) – Callable function to evaluate the prior transform.
log_like (function) – Callable function to evaluate the log likelihood.
ndim (int) – Number of sampling dimensions.
output_file (str) – File to which to save outputs.
log_like_args (dict) – Arguments for the log likelihood function.
ptform_kwargs (dict) – Arguments for the prior transform function.
dynesty_args (dict) – Arguments for dynesty NestedSampler instance.
silent (bool) – If True, do not show progress updates.
resume (bool) – If True, restart sampling from a previous fit.
resume_file (str, None) – Previous dynesty save file to restart from.
- Returns:
sampler – dynesty sampler.
- Return type:
dynesty.nestedsamplers.MultiEllipsoidSampler
- exouprf.fit.fit_emcee(log_prob, output_file, initial_pos=None, continue_run=False, silent=False, mcmc_steps=10000, log_probability_args=None, ncores=1)
Run a light curve fit via MCMC using the emcee sampler.
- Parameters:
log_prob (function) – Callable function to evaluate the fit log probability.
output_file (str) – File to which to save outputs. If continuing a run, this should also be the input file containing the previous MCMC chains.
initial_pos (ndarray(float), None) – Starting positions for the MCMC sampling.
continue_run (bool) – If True, continue a run from the state of previous MCMC chains.
silent (bool) – If True, do not show any progress.
mcmc_steps (int) – Number of MCMC steps before stopping.
log_probability_args (tuple) – Arguments for the passed log_prob function.
ncores (int) – Number of cores to use for multiprocessing.
- Returns:
sampler – ecmee sampler.
- Return type:
emcee.ensemble.EnsembleSampler
- exouprf.fit.log_likelihood(theta, param_dict, time, observations, mod_init)
Evaluate the log likelihood for a dataset and a given set of model parameters.
- Parameters:
theta (list(float)) – List of values for each fitted parameter.
param_dict (dict) – Dictionary of input parameter values and prior distributions.
time (dict) – Dictonary of timestamps corresponding to the observations.
observations (dict) – Dictionary of observations.
mod_init (LightCurveModel) – Initialized LightCurveModel class.
- Returns:
log_like – Result of likelihood evaluation.
- Return type:
float
- exouprf.fit.log_probability(theta, param_dict, time, observations, mod_init)
Evaluate the log probability for a dataset and a given set of model parameters.
- Parameters:
theta (list(float)) – List of values for each fitted parameter.
param_dict (dict) – Dictionary of input parameter values and prior distributions.
time (dict) – Dictonary of timestamps corresponding to the observations.
observations (dict) – Dictionary of observations.
mod_init (LightCurveModel) – Initialized LightCurveModel class.
- Returns:
log_prob – Result of probability evaluation.
- Return type:
float
- exouprf.fit.logprior_loguniform(x, hyperparams)
Evaluate log-uniform log prior.
- exouprf.fit.logprior_normal(x, hyperparams)
Evaluate normal log prior.
- exouprf.fit.logprior_truncatednormal(x, hyperparams)
Evaluate trunctaed normal log prior.
- exouprf.fit.logprior_uniform(x, hyperparams)
Evaluate uniform log prior.
- exouprf.fit.set_logprior(theta, param_dict)
Calculate the fit prior based on a set of input values and prior functions.
- Parameters:
theta (list(float)) – List of values for each fitted parameter.
param_dict (dict) – Dictionary of input parameter values and prior distributions.
- Returns:
log_prior – Result of prior evaluation.
- Return type:
float
- exouprf.fit.set_prior_transform(theta, param_dict)
Define the prior transform based on a set of input values and prior functions.
- Parameters:
theta (list(float)) – List of values for each fitted parameter.
param_dict (dict) – Dictionary of input parameter values and prior distributions.
- Returns:
prior_transform – Result of prior evaluation.
- Return type:
list(float)
- exouprf.fit.transform_loguniform(x, hyperparams)
Evaluate log-uniform prior transform.
- exouprf.fit.transform_normal(x, hyperparams)
Evaluate normal prior transform.
- exouprf.fit.transform_truncatednormal(x, hyperparams)
Evaluate truncated normal prior transform.
- exouprf.fit.transform_uniform(x, hyperparams)
Evaluate uniform prior transform.