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 a TypeError).

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

generate_chi2_table(chi2_dict, chi2_tot)[source]

Generate log \(\chi^2\) table

load_external_chi2(external_chi2)[source]

Loads the external chi2 modules

Parameters:

external_chi2 (dict) – dict of external chi2s, with the name of the function object as key and the path to the external script as value

Returns:

ext_chi2_modules – List of external chi2 objects that can be evaluated by passing a coefficients instance

Return type:

list

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

classmethod from_dict(config)[source]

Create object from theory dictionary.

Parameters:

config (dict) – configuration dictionary

Returns:

cls – created object

Return type:

Optimizer

log_result(coeff_best, coeff_covmat)[source]

Log a table with solution.

run_sampling()[source]

Run sapmling accordying to the analytic solution.

save(result)[source]

Save samples to json inside a dictionary: {coff: [replicas values]}. Saving also some basic information about the fit.

Parameters:

samples (np.array) – raw samples with shape (n_samples, n_free_param)

smefit.optimize.analytic.is_semi_pos_def(x)[source]

Check is a matrix is positive-semidefinite.

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

classmethod from_dict(config)[source]

Create object from theory dictionary. The default minimizer is trust-constr.

The minimizer options have to be specified with:

` mc_minimiser: 'cma' maxiter: 100000 restarts: 0 `

Parameters:

config (dict) – configuration dictionary

Returns:

created object

Return type:

Optimizer

get_status(chi2)[source]
run_sampling()[source]

Run the minimization with MC.

save()[source]

Save MC replicas to json inside a dictionary: {coff: replica values}

Parameters:

result (dict) – result dictionary

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

compute_fixed_coeff(constrain, param_dict)[source]

Compute the fixed coefficient.

flat_prior(hypercube)[source]

Update the prior function.

Parameters:

hypercube (np.ndarray) – hypercube prior

Returns:

flat_prior – updated hypercube prior

Return type:

np.ndarray

classmethod from_dict(config)[source]

Create object from theory dictionary.

Parameters:

config (dict) – configuration dictionary

Returns:

cls – created object

Return type:

Optimizer

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
produce_all_params(params)[source]

Produce all parameters from the free parameters.

Parameters:

params (jnp.ndarray) – free parameters

Returns:

all_params – all parameters

Return type:

jnp.ndarray

run_sampling()[source]

Run the minimization with Ultra nest.

save(result)[source]

Save NS replicas to json inside a dictionary: {coff: [replicas values]}. Saving also some basic information about the fit.

Parameters:

result (dict) – result dictionary