Profilers¶
minuit¶
- class desilike.profilers.minuit.MinuitProfiler(*args, gradient=False, **kwargs)[source]¶
Bases:
BaseProfilerWrapper for minuit profiler, used by the high-energy physics community for likelihood profiling.
Reference¶
Initialize profiler.
- Parameters:
likelihood (BaseLikelihood) – Input likelihood.
rng (np.random.RandomState, default=None) – Random state. If
None,seedis used to set random state.seed (int, default=None) – Random seed.
max_tries (int, default=1000) – A
ValueErroris raised after this number of likelihood (+ prior) calls without finite posterior.profiles (str, Path, Profiles) – Path to or profiles, to which new profiling results will be added.
ref_scale (float, default=1.) – Rescale parameters’
Parameter.refreference distribution by this factorrescale (bool, default=False) – If
True, internally rescale parameters such their variation range is ~ unity. Providecovarianceto take parameter variations from; else parameters’Parameter.proposalwill be used.covariance (str, Path, ParameterCovariance, Chain, default=None) – If
rescale, path to or covariance or chain, which is used for rescaling parameters. IfNone, parameters’Parameter.proposalwill be used instead.gradient (bool, default=False) – If
True, try to take the likelihood gradient (requires jax).save_fn (str, Path, default=None) – If not
None, save profiles to this location.mpicomm (mpi.COMM_WORLD, default=None) – MPI communicator. If
None, defaults tolikelihood’sBaseLikelihood.mpicomm
- contour(*args, **kwargs)[source]¶
Compute 2D contours for
likelihood. The following attributes are added toprofiles:Profiles.contour
- Parameters:
params (list, ParameterCollection, default=None) – List of tuples of parameters for which to compute 2D contours. If a list of parameters is provided instead, contours are computed for unique tuples of parameters.
cl (float, int, default=1) – Confidence level for the confidence contour. If not set or None, a standard 68.3 % confidence contour is produced. If 0 < cl < 1, the value is interpreted as the confidence level (a probability). If cl >= 1, it is interpreted as number of standard deviations. For example, cl = 3 produces a 3 sigma contour.
size (int, default=100) – Number of points on the contour to find. Increasing this makes the contour smoother, but requires more computation time.
interpolated (int, default=0) – Number of interpolated points on the contour. If you set this to a value larger than size, cubic spline interpolation is used to generate a smoother curve and the interpolated coordinates are returned. Values smaller than size are ignored. Good results can be obtained with size=20, interpolated=200.
- covariance(**kwargs)¶
Maximize
likelihood. The following attributes are added toprofiles:Profiles.error# parabolic errors at best fit (if made available by the profiler)Profiles.covariance# parameter covariance at best fit (if made available by the profiler).
- grid(*args, **kwargs)[source]¶
Compute best fits on grid for
likelihood. The following attributes are added toprofiles:Profiles.grid
- Parameters:
params (str, Parameter, list, ParameterCollection, default=None) – Parameters for which to compute 1D profiles.
grid (array, list, dict, default=None) – Parameter values on which to compute the profile, for each parameter. If grid is set, size and bound are ignored.
size (int, list, dict, default=1) – Number of scanning points. Ignored if grid is set. Can be specified for each parameter.
cl (int, list, dict, default=2) – If bound is a number, it specifies an interval of N sigmas symmetrically around the minimum. Ignored if grid is set. Can be specified for each parameter.
niterations (int, default=1) – Number of iterations, i.e. of runs of the profiler from independent starting points.
max_iterations (int, default=int(1e5)) – Maximum number of likelihood evaluations.
- interval(*args, **kwargs)[source]¶
Compute confidence intervals for
likelihood. The following attributes are added toprofiles:Profiles.interval
- Parameters:
params (str, Parameter, list, ParameterCollection, default=None) – Parameters for which to estimate confidence intervals.
cl (float, int, default=None) – Confidence level for the confidence interval. If not set or None, a standard 68.3 % confidence interval is produced. If 0 < cl < 1, the value is interpreted as the confidence level (a probability). If cl >= 1, it is interpreted as number of standard deviations. For example, cl = 3 produces a 3 sigma interval.
- maximize(*args, **kwargs)[source]¶
Maximize
likelihood. The following attributes are added toprofiles:Profiles.startProfiles.bestfitProfiles.error# parabolic errors at best fitProfiles.covariance# parameter covariance at best fit
One will typically run several independent likelihood maximizations in parallel, on number of MPI processes - 1 ranks (1 if single process), to make sure the global maximum is found.
- Parameters:
niterations (int, default=None) – Number of iterations, i.e. of runs of the profiler from independent starting points. If
None, defaults tompicomm.size - 1(if > 0, else 1).max_iterations (int, default=int(1e5)) – Maximum number of likelihood evaluations.
- profile(*args, **kwargs)[source]¶
Compute 1D profiles for
likelihood. The following attributes are added toprofiles:Profiles.profile
- Parameters:
params (str, Parameter, list, ParameterCollection, default=None) – Parameters for which to compute 1D profiles.
grid (array, list, default=None) – Parameter values on which to compute the profile, for each parameter. If grid is set, size and bound are ignored.
size (int, list, default=30) – Number of scanning points. Ignored if grid is set. Can be specified for each parameter.
cl (int, list, default=2) – If bound is a number, it specifies an interval of N sigmas symmetrically around the minimum. Ignored if grid is set. Can be specified for each parameter.
niterations (int, default=1) – Number of iterations, i.e. of runs of the profiler from independent starting points.
max_iterations (int, default=int(1e5)) – Maximum number of likelihood evaluations.
bobyqa¶
- class desilike.profilers.bobyqa.BOBYQAProfiler(likelihood, rng=None, seed=None, max_tries=1000, profiles=None, ref_scale=1.0, rescale=False, covariance=None, save_fn=None, mpicomm=None)[source]¶
Bases:
BaseProfilerDesigned for solving bound-constrained general objective minimization, without requiring derivatives of the objective.
Reference¶
Initialize profiler.
- Parameters:
likelihood (BaseLikelihood) – Input likelihood.
rng (np.random.RandomState, default=None) – Random state. If
None,seedis used to set random state.seed (int, default=None) – Random seed.
max_tries (int, default=1000) – A
ValueErroris raised after this number of likelihood (+ prior) calls without finite posterior.profiles (str, Path, Profiles) – Path to or profiles, to which new profiling results will be added.
ref_scale (float, default=1.) – Rescale parameters’
Parameter.refreference distribution by this factorrescale (bool, default=False) – If
True, internally rescale parameters such their variation range is ~ unity. Providecovarianceto take parameter variations from; else parameters’Parameter.proposalwill be used.covariance (str, Path, ParameterCovariance, Chain, default=None) – If
rescale, path to or covariance or chain, which is used for rescaling parameters. IfNone, parameters’Parameter.proposalwill be used instead.save_fn (str, Path, default=None) – If not
None, save profiles to this location.mpicomm (mpi.COMM_WORLD, default=None) – MPI communicator. If
None, defaults tolikelihood’sBaseLikelihood.mpicomm
- contour(params=None, cl=1, niterations=1, **kwargs)¶
Compute 2D contours for
likelihood. The following attributes are added toprofiles:Profiles.contour
- Parameters:
params (list, ParameterCollection, default=None) – List of tuples of parameters for which to compute 2D contours. If a list of parameters is provided instead, contours are computed for unique tuples of parameters.
cl (float, int, default=1) – Confidence level for the confidence contour. If not set or None, a standard 68.3 % confidence contour is produced. If 0 < cl < 1, the value is interpreted as the confidence level (a probability). If cl >= 1, it is interpreted as number of standard deviations. For example, cl = 3 produces a 3 sigma contour.
**kwargs (dict) – Optional arguments for specific profiler.
- covariance(**kwargs)¶
Maximize
likelihood. The following attributes are added toprofiles:Profiles.error# parabolic errors at best fit (if made available by the profiler)Profiles.covariance# parameter covariance at best fit (if made available by the profiler).
- grid(*args, **kwargs)[source]¶
Compute best fits on grid for
likelihood. The following attributes are added toprofiles:Profiles.grid
- Parameters:
params (str, Parameter, list, ParameterCollection, default=None) – Parameters for which to compute 1D profiles.
grid (array, list, dict, default=None) – Parameter values on which to compute the profile, for each parameter. If grid is set, size and bound are ignored.
size (int, list, dict, default=1) – Number of scanning points. Ignored if grid is set. Can be specified for each parameter.
cl (int, list, dict, default=2) – If bound is a number, it specifies an interval of N sigmas symmetrically around the minimum. Ignored if grid is set. Can be specified for each parameter.
niterations (int, default=1) – Number of iterations, i.e. of runs of the profiler from independent starting points.
max_iterations (int, default=int(1e5)) – Maximum number of likelihood evaluations.
- interval(params=None, cl=1, niterations=1, **kwargs)¶
Compute confidence intervals for
likelihood. The following attributes are added toprofiles:Profiles.interval
- Parameters:
params (str, Parameter, list, ParameterCollection, default=None) – Parameters for which to estimate confidence intervals.
**kwargs (dict) – Optional arguments for specific profiler.
- maximize(*args, **kwargs)[source]¶
Maximize
likelihood. The following attributes are added toprofiles:Profiles.startProfiles.bestfitProfiles.error# parabolic errors at best fitProfiles.covariance# parameter covariance at best fit
One will typically run several independent likelihood maximizations in parallel, on number of MPI processes - 1 ranks (1 if single process), to make sure the global maximum is found.
- Parameters:
niterations (int, default=None) – Number of iterations, i.e. of runs of the profiler from independent starting points. If
None, defaults tompicomm.size - 1(if > 0, else 1).max_iterations (int, default=int(1e5)) – Maximum number of likelihood evaluations.
npt (int, default=None) – The number of interpolation points to use; default is 2 * ndim + 1. Py-BOBYQA requires ndim + 1 <= npt <= (ndim + 1)(ndim + 2)/2. Larger values are particularly useful for noisy problems.
rhobeg (float, default=None) – The initial value of the trust region radius default is \(0.1 max(|x_0|_{\infty}, 1)\).
rhoend (float, default=1e-8) – Minimum allowed value of trust region radius, which determines when a successful termination occurs.
seek_global_minimum (bool, default=False) – A flag to indicate whether to search for a global minimum, rather than a local minimum. This is used to set some sensible default parameters, all of which can be overridden by the values provided in user_params. If True, both upper and lower bounds must be set. Note that Py-BOBYQA only implements a heuristic method, so there are no guarantees it will find a global minimum. However, by using this flag, it is more likely to escape local minima if there are better values nearby. The method used is a multiple restart mechanism, where we repeatedly re-initialize Py-BOBYQA from the best point found so far, but where we use a larger trust reigon radius each time (note: this is different to more common multi-start approach to global optimization).
- profile(*args, **kwargs)[source]¶
Compute 1D profiles for
likelihood. The following attributes are added toprofiles:Profiles.profile
- Parameters:
params (str, Parameter, list, ParameterCollection, default=None) – Parameters for which to compute 1D profiles.
grid (array, list, default=None) – Parameter values on which to compute the profile, for each parameter. If grid is set, size and bound are ignored.
size (int, list, default=30) – Number of scanning points. Ignored if grid is set. Can be specified for each parameter.
cl (int, list, default=2) – If bound is a number, it specifies an interval of N sigmas symmetrically around the minimum. Ignored if grid is set. Can be specified for each parameter.
niterations (int, default=1) – Number of iterations, i.e. of runs of the profiler from independent starting points.
max_iterations (int, default=int(1e5)) – Maximum number of likelihood evaluations.
scipy¶
- class desilike.profilers.scipy.ScipyProfiler(*args, method=None, gradient=False, **kwargs)[source]¶
Bases:
BaseProfilerWrapper for the collection of scipy’s profilers.
Reference¶
Initialize profiler.
- Parameters:
likelihood (BaseLikelihood) – Input likelihood.
method (str, default=None) – Type of solver. Should be one of ‘Nelder-Mead’, ‘Powell’, ‘CG’, ‘BFGS’, ‘Newton-CG’, ‘L-BFGS-B’, ‘TNC’, ‘COBYLA’, ‘SLSQP’, ‘trust-constr’, ‘dogleg’, ‘trust-ncg’, ‘trust-exact’, ‘trust-krylov’. If not given, chosen to be one of ‘BFGS‘, ‘L-BFGS-B‘, ‘SLSQP‘, depending on whether or not sompe parameters have bounded priors.
gradient (bool, default=False) – Only for ‘CG‘, ‘BFGS‘, ‘Newton-CG‘, ‘L-BFGS-B‘, ‘TNC‘, ‘SLSQP‘, ‘dogleg‘, ‘trust-ncg‘, ‘trust-krylov‘, ‘trust-exact‘ and ‘trust-constr‘.
rng (np.random.RandomState, default=None) – Random state. If
None,seedis used to set random state.seed (int, default=None) – Random seed.
max_tries (int, default=1000) – A
ValueErroris raised after this number of likelihood (+ prior) calls without finite posterior.profiles (str, Path, Profiles) – Path to or profiles, to which new profiling results will be added.
ref_scale (float, default=1.) – Rescale parameters’
Parameter.refreference distribution by this factorrescale (bool, default=False) – If
True, internally rescale parameters such their variation range is ~ unity. Providecovarianceto take parameter variations from; else parameters’Parameter.proposalwill be used.covariance (str, Path, ParameterCovariance, Chain, default=None) – If
rescale, path to or covariance or chain, which is used for rescaling parameters. IfNone, parameters’Parameter.proposalwill be used instead.save_fn (str, Path, default=None) – If not
None, save profiles to this location.mpicomm (mpi.COMM_WORLD, default=None) – MPI communicator. If
None, defaults tolikelihood’sBaseLikelihood.mpicomm
- contour(params=None, cl=1, niterations=1, **kwargs)¶
Compute 2D contours for
likelihood. The following attributes are added toprofiles:Profiles.contour
- Parameters:
params (list, ParameterCollection, default=None) – List of tuples of parameters for which to compute 2D contours. If a list of parameters is provided instead, contours are computed for unique tuples of parameters.
cl (float, int, default=1) – Confidence level for the confidence contour. If not set or None, a standard 68.3 % confidence contour is produced. If 0 < cl < 1, the value is interpreted as the confidence level (a probability). If cl >= 1, it is interpreted as number of standard deviations. For example, cl = 3 produces a 3 sigma contour.
**kwargs (dict) – Optional arguments for specific profiler.
- covariance(**kwargs)¶
Maximize
likelihood. The following attributes are added toprofiles:Profiles.error# parabolic errors at best fit (if made available by the profiler)Profiles.covariance# parameter covariance at best fit (if made available by the profiler).
- grid(*args, **kwargs)[source]¶
Compute best fits on grid for
likelihood. The following attributes are added toprofiles:Profiles.grid
- Parameters:
params (str, Parameter, list, ParameterCollection, default=None) – Parameters for which to compute 1D profiles.
grid (array, list, dict, default=None) – Parameter values on which to compute the profile, for each parameter. If grid is set, size and bound are ignored.
size (int, list, dict, default=1) – Number of scanning points. Ignored if grid is set. Can be specified for each parameter.
cl (int, list, dict, default=2) – If bound is a number, it specifies an interval of N sigmas symmetrically around the minimum. Ignored if grid is set. Can be specified for each parameter.
niterations (int, default=1) – Number of iterations, i.e. of runs of the profiler from independent starting points.
max_iterations (int, default=int(1e5)) – Maximum number of likelihood evaluations.
- interval(params=None, cl=1, niterations=1, **kwargs)¶
Compute confidence intervals for
likelihood. The following attributes are added toprofiles:Profiles.interval
- Parameters:
params (str, Parameter, list, ParameterCollection, default=None) – Parameters for which to estimate confidence intervals.
**kwargs (dict) – Optional arguments for specific profiler.
- maximize(*args, **kwargs)[source]¶
Maximize
likelihood. The following attributes are added toprofiles:Profiles.startProfiles.bestfitProfiles.error# parabolic errors at best fit (if made available by the solver)Profiles.covariance# parameter covariance at best fit (if made available by the solver).
One will typically run several independent likelihood maximizations in parallel, on number of MPI processes - 1 ranks (1 if single process), to make sure the global maximum is found.
- Parameters:
niterations (int, default=None) – Number of iterations, i.e. of runs of the profiler from independent starting points. If
None, defaults tompicomm.size - 1(if > 0, else 1).max_iterations (int, default=int(1e5)) – Maximum number of likelihood evaluations.
tol (float, default=None) – Tolerance for termination. When
tolis specified, the selected minimization algorithm sets some relevant solver-specific tolerance(s) equal totol. For detailed control, use solver-specific options.kwargs (dict) – Solver-specific options.
- profile(*args, **kwargs)[source]¶
Compute 1D profiles for
likelihood. The following attributes are added toprofiles:Profiles.profile
- Parameters:
params (str, Parameter, list, ParameterCollection, default=None) – Parameters for which to compute 1D profiles.
grid (array, list, default=None) – Parameter values on which to compute the profile, for each parameter. If grid is set, size and bound are ignored.
size (int, list, default=30) – Number of scanning points. Ignored if grid is set. Can be specified for each parameter.
cl (int, list, default=2) – If bound is a number, it specifies an interval of N sigmas symmetrically around the minimum. Ignored if grid is set. Can be specified for each parameter.
niterations (int, default=1) – Number of iterations, i.e. of runs of the profiler from independent starting points.
max_iterations (int, default=int(1e5)) – Maximum number of likelihood evaluations.