Optimizer using Grid Search¶
GridSearchOptimizer(traj, optimizee_create_individual, optimizee_fitness_weights, parameters, optimizee_bounding_func=None)¶
This class implements a basic grid search optimizer. It runs the optimizee on a given grid of parameter values and returns the best fitness found. moreover, this can also simply be used to run a grid search and process the results stored in the traj in any manner desired.
Notes regarding what it does -
- This algorithm does not do any kind of adaptive searching and thus the concept of generations does not apply
per se. That said, it is currently implemented as a series of runs in a single generation. All of these runs
are declared in the constructor itself. The
Optimizer.post_process()function simply prints the individual with the maximal fitness.
- This algorithm doesnt make use of self.eval_pop and
Optimizer._expand_trajectory()simply because the cartesian product can be used more efficiently directly. (Imagine having to split a dict of 10000 parameter combinations into 10000 small Individual-Dict`s and storing into eval_pop only to join them and call `traj.f_expand() in
- traj (Trajectory) – Use this trajectory to store the parameters of the specific runs. The parameters should be initialized based on the values in parameters
- optimizee_create_individual – A function which when called returns one instance of parameter (or “individual”)
- optimizee_fitness_weights – The weights which should be multiplied with the fitness returned from the
Optimizee– one for each element of the fitness (fitness can be multi-dimensional). If some element is negative, the Optimizer minimizes that element of fitness instead of maximizing. By default, the Optimizer maximizes all fitness dimensions.
- parameters – An instance of
The current generation number
The population (i.e. list of individuals) to be evaluated at the next iteration
In this optimizer, the post_proces function merely returns the best individual out of the grid and does not expand the trajectory. It also stores any relevant results
Run any code required to clean-up, print final individuals etc.
- This algorithm does not do any kind of adaptive searching and thus the concept of generations does not apply per se. That said, it is currently implemented as a series of runs in a single generation. All of these runs are declared in the constructor itself. The
Parameters: param_grid (dict) –
This is the data structure specifying the grid over which to search. This should be a dictionary as follows:
optimizee_param_grid['param_name'] = (lower_bound, higher_bound, n_steps)
Where the interval [lower_bound, upper_bound] is divided into n_steps intervals thereby providing n_steps + 1 points for the grid.
Note that there must be as many keys as there are in the Individual-Dict returned by the function
Optimizee.create_individual(). Also, if any of the parameters of the individuals is an array, then the above grid specification applies to each element of the array.