smefit.optimize package
- class smefit.optimize.NumpyEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]
Bases:
JSONEncoder
- default(o)[source]
Implement this method in a subclass such that it returns a serializable object for
o
, or calls the base implementation (to raise aTypeError
).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o)
- class smefit.optimize.Optimizer(results_path, loaded_datasets, coefficients, use_quad, single_parameter_fits, use_multiplicative_prescription, external_chi2=None, rgemat=None, rge_dict=None)[source]
Bases:
object
Common interface for Chi2 profile, NS and MC and A optimizers.
- Parameters:
results_path (pathlib.path) – path to result folder
loaded_datasets (DataTuple,) – dataset tuple
coefficients (smefit.coefficients.CoefficientManager) – instance of CoefficientManager with all the relevant coefficients to fit
use_quad (bool) – if True includes also HO correction
single_parameter_fits (bool) – True for single parameter fits
use_multiplicative_prescription – if True uses the multiplicative prescription for the EFT corrections.
external_chi2 (dict) – dict of external chi2
rgemat (numpy.ndarray) – solution matrix of the RGE
rge_dict (dict) – dictionary with the RGE input parameter options
- chi2_func(use_replica=False, print_log=True)[source]
Wrap the math:chi^2 in a function for the optimizer. Pass noise and data info as args. Log the math:chi^2 value and values of the coefficients.
- Returns:
current_chi2 – computed \(\chi^2\)
- Return type:
np.ndarray
- dump_fit_result(fit_result_file, values)[source]
Dumps the fit results to a json file.
dump_fit_result gets called repeatedly for single parameter fits, once for each parameter. values contains the samples of the current fit, while previous fit results get loaded into tmp and updated with the current samples. The updated values are then written back to the file.
- Parameters:
fit_result_file (PosixPath) – path to the fit results file
values (dict) – dictionary containing the current fit results
- property free_parameters
Returns the free parameters entering fit
- print_rate = 500
Submodules
smefit.optimize.analytic module
Solve the linear plolem to get the best analytic bounds.
- class smefit.optimize.analytic.ALOptimizer(loaded_datasets, coefficients, result_path, result_ID, single_parameter_fits, n_samples)[source]
Bases:
Optimizer
Optimizer specification for the linear analytic solution.
- Parameters:
loaded_datasets (smefit.loader.DataTuple,) – dataset tuple
coefficients (smefit.coefficients.CoefficientManager) – instance of CoefficientManager with all the relevant coefficients to fit
result_path (pathlib.Path) – path to result folder
result_ID (str) – result name
single_parameter_fits (bool) – True for individual scan fits
n_samples – number of replica to sample
smefit.optimize.mc module
Fitting the Wilson coefficients with MC.
- class smefit.optimize.mc.MCOptimizer(loaded_datasets, coefficients, result_path, use_quad, result_ID, replica, single_parameter_fits, use_bounds, minimizer_specs, use_multiplicative_prescription, external_chi2=None)[source]
Bases:
Optimizer
Optimizer specification for MC.
- Parameters:
loaded_datasets (smefit.loader.DataTuple) – dataset tuple
coefficients (smefit.coefficients.CoefficientManager) – instance of CoefficientManager with all the relevant coefficients to fit
result_path (pathlib.Path) – path to result folder
use_quad (bool) – If True use also HO corrections
result_ID (str) – result name
single_parameter_fits (bool) – True for individual scan fits
use_multiplicative_prescription (bool) – if True uses the multiplicative prescription for the EFT corrections
replica (int) – replica number
use_bounds (bool) – If true start the minimization with the specified values of min and max for each coeffient
minimizer_specs (dict) –
minimizer options. The allowed optrions are:
Args:
mc_minimiser: minimizer alogrithm: ‘cma’, ‘dual_annealing’, ‘trust-constr’.
maxiter: number of maximium iterations.
restarts: only for cma, number of restarts (< 9).
- initial_temp: only for dual_annealing.
The initial temperature, use higher values to facilitates a wider search of the energy landscape, allowing dual_annealing to escape local minima that it is trapped in. Default value is 5230. Range is (0.01, 5.e4].
- restart_temp_ratio: only for dual_annealing.
During the annealing process, temperature is decreasing, when it reaches initial_temp * restart_temp_ratio, the reannealing process is triggered. Default value of the ratio is 2e-5. Range is (0, 1).
See also cma.fmin, scipy.optimize.minimize, scipy.optimize.dual_annealing.
- chi2_func_mc(params, print_log=True)[source]
Wrap the chi2 in a function for the optimizer. Pass noise and data info as args. Log the chi2 value and values of the coefficients.
- Parameters:
params (np.ndarray) – noise and data info
- Returns:
chi2 value
- Return type:
np.ndarray
smefit.optimize.ultranest module
Fitting the Wilson coefficients with NS
- class smefit.optimize.ultranest.USOptimizer(loaded_datasets, coefficients, result_path, use_quad, result_ID, single_parameter_fits, pairwise_fits, use_multiplicative_prescription, live_points=500, lepsilon=0.001, target_evidence_unc=0.5, target_post_unc=0.5, frac_remain=0.01, store_raw=False, vectorized=False, float64=False, external_chi2=None, rgemat=None, rge_dict=None)[source]
Bases:
Optimizer
Optimizer specification for Ultra nest.
- Parameters:
loaded_datasets (smefit.loader.DataTuple,) – dataset tuple
coefficients (smefit.coefficients.CoefficientManager) – instance of CoefficientManager with all the relevant coefficients to fit
result_path (pathlib.Path) – path to result folder
use_quad (bool) – If True use also HO corrections
result_ID (str) – result name
single_parameter_fits (bool) – True for single parameter fits
pairwise_fits (bool) – True for pairwise parameter fits
use_multiplicative_prescription (bool) – if True uses the multiplicative prescription for the EFT corrections
live_points (int) – number of NS live points
lepsilon (float) – sampling tollerance. Terminate when live point likelihoods are all the same, within Lepsilon tolerance. Increase this when your likelihood function is inaccurate,
target_evidence_unc (float) – target evidence uncertainty.
target_post_unc (float) – target posterior uncertainty.
frac_remain (float) – integrate until this fraction of the integral is left in the remainder. Set to a higher number (0.5) if you know the posterior is simple.
store_raw (bool) – if True store the result to eventually resume the job
vectorized (bool) – if True use jax vectorization
float64 (bool) – if True use float64 precision
external_chi2 (dict) – dict of external chi2
rgemat (numpy.ndarray) – solution matrix of the RGE
rge_dict (dict) – dictionary with the RGE input parameter options
- chi2_func_ns(params)[source]
Compute the chi2 function for NS. It is simplified with respect to the one in the Optimizer class, so that it can be compiled with jax.jit. :param params: Wilson coefficients :type params: jnp.ndarray
- flat_prior(hypercube)[source]
Update the prior function.
- Parameters:
hypercube (np.ndarray) – hypercube prior
- Returns:
flat_prior – updated hypercube prior
- Return type:
np.ndarray
- gaussian_loglikelihood(params)[source]
Multi gaussian log likelihood function.
- Parameters:
params (np.ndarray) – params prior
- Returns:
-0.5 * chi2 – multi gaussian log likelihood
- Return type:
np.ndarray
- print_rate = 5000