Multi-start and hyper-parameter optimization in pure Julia
Description
Hyperopt.jl is a Julia library that implements a number of hyperparameter optimization algorithms which can be used to optimize the starting point of the optimization. NonconvexHyperopt.jl allows the use of the algorithms in Hyperopt.jl as meta-algorithms using the HyperoptAlg struct.
Quick start
Given a model model and an initial solution x0, the following can be used to optimize the model using Hyperopt.
using NonconvexMultistart
alg = HyperoptAlg(IpoptAlg())
options = HyperoptOptions(sub_options = IpoptOptions(), sampler = RandomSampler())
result = optimize(model, alg, x0, options = options)Hyperopt is an optional dependency of Nonconvex so you need to import it in order to use it. HyperoptAlg can wrap any other algorithm in Nonconvex, e.g. IpoptAlg(). When the algorithm is a HyperoptAlg, the options keyword argument must of type HyperoptOptions. For more on the options available see below.
Construct an instance
To construct an instance of the Hyperopt + Ipopt algorithm, use:
alg = HyperoptAlg(IpoptAlg())HyperoptAlg can wrap any other algorithm in Nonconvex, e.g. NLoptAlg(:LD_MMA) or AugLag().
Options
The options keyword argument to the optimize function shown above must be an instance of the HyperoptOptions struct when the algorihm is a HyperoptAlg. To specify options, use keyword arguments in the constructor of HyperoptOptions. The sampler keyword argument determines the sampling algorithm used to propose new starting points in the multi-start procedure. The sub_options keyword argument can be used to pass in the options for the sub-optimizer. There are 2 different ways to pass the sub-options depending on the sampler type.
The sampler argument can be of type:
RandomSamplerLHSamplerCLHSamplerHyperband
When optimizing the starting point, the upper and lower bounds on the initial solution must be finite, or finite bounds must be passed in to the options constructor. All the options that can be passed to the HyperoptOptions constructor are listed below:
sub_options: the options of the sub-optimizer, or a function from the number of iterations to the sub-optimizer options when the sampler is aHyperband.lbandub: the lower and upper bounds of the starting point search. Whennothing(the default), the bounds of the model variables are used.iters: the number of candidate starting points that are evaluated,40by default.searchspace_size: the number of potential starting points that are generated. It defaults toiters.LHSamplerandCLHSamplerrequiresearchspace_size == iters.sampler: the starting point sampler,RandomSampler()by default.ctol: the infeasibility tolerance for accepting a solution as feasible,1e-5by default.keep_all: whentrue(the default), all the sub-problem results are kept in theresultsfield of the returnedHyperoptResult; whenfalse, only the best result is returned.
Results
When multiple starting points are searched, the result of optimize is a HyperoptResult with the following fields:
minimum: the optimal value among all searches.minimizer: the optimal solution found.results: all the search results (whenkeep_all = true).optimal_ind: the index of the optimal solution inresults.
For example:
r = optimize(model, alg, x0, options = options)
r.minimum
r.minimizer
r.results
r.optimal_indSampler choice
RandomSampler, LHSampler and CLHSampler
All the sampler constructors are functions defined in NonconvexMultistart wrapping the Hyperopt alternatives to define defaults. All the arguments that can be passed to the sampler constructor can be found in the Hyperopt documentation. Example:
options = HyperoptOptions(sub_options = IpoptOptions(), sampler = LHSampler())
GPSamplerwas removed in NonconvexMultistart 0.2.0 because Hyperopt removedGPSamplerupstream (Hyperopt >= 0.5). CallingGPSampler()raises an error. UseRandomSampler,LHSamplerorCLHSamplerinstead.
Hyperband
The Hyperband algorithm in Hyperopt requires a different way to pass in the sub-options. The Hyperband algorithm tries to optimize the allocation of resources. The sub_options argument must be a function with input as the "resources" and output as the sub-solver options. The Hyperband constructor accepts 3 arguments:
- The maximum resources
R ηwhich roughly determines the proportion of trials discarded between each round of successive halvinginnerwhich specifies an inner sampler of typeRandomSampler,LHSamplerorCLHSampler.
Example:
options = HyperoptOptions(
sub_options = max_iter -> IpoptOptions(max_iter = max_iter),
sampler = Hyperband(R=100, η=3, inner=RandomSampler()),
)