Grid Search Algorithm

GridSearch hyperparameter optimizer

class orion.algo.gridsearch.GridSearch(space: Space, n_values: int | dict[str, int] = 100)[source]

Grid Search algorithm

Parameters
n_values: int or dict

Number of trials for each dimensions, or dictionary specifying number of trials for each dimension independently (name, n_values). For categorical dimensions, n_values will not be used, and all categories will be used to build the grid.

Attributes
configuration

Return tunable elements of this algorithm in a dictionary form appropriate for saving.

is_done

Return True when all grid has been covered.

requires_dist
requires_type
state_dict

Return a state dict that can be used to reset the state of the algorithm.

Methods

build_grid(space, n_values[, max_trials])

Build a grid of trials

set_state(state_dict)

Reset the state of the algorithm based on the given state_dict

suggest(num)

Return the entire grid of suggestions

static build_grid(space: Space, n_values: dict[str, int], max_trials: int = 10000)[source]

Build a grid of trials

Parameters
n_values: int or dict

Dictionary specifying number of trials for each dimension independently (name, n_values). For categorical dimensions, n_values will not be used, and all categories will be used to build the grid.

max_trials: int

Maximum number of trials for the grid. If n_values lead to more trials than max_trials, the n_values will be adjusted down. Will raise ValueError if it is impossible to build a grid smaller than max_trials (for instance if choices are too large).

property configuration

Return tunable elements of this algorithm in a dictionary form appropriate for saving.

property is_done

Return True when all grid has been covered.

set_state(state_dict: dict) None[source]

Reset the state of the algorithm based on the given state_dict

Parameters
state_dict: dict

Dictionary representing state of an algorithm

property state_dict: dict

Return a state dict that can be used to reset the state of the algorithm.

suggest(num)[source]

Return the entire grid of suggestions

Returns
list of trials or None

A list of lists representing trials suggested by the algorithm. The algorithm may opt out if it cannot make a good suggestion at the moment (it may be waiting for other trials to complete), in which case it will return None.

orion.algo.gridsearch.categorical_grid(dim: Categorical, num: int)[source]

Build categorical grid, that is, all categories

orion.algo.gridsearch.discrete_grid(dim: Integer, num: int)[source]

Build discretized real grid

orion.algo.gridsearch.grid(dim: Dimension, num: int)[source]

Build a one-dim grid of num points

orion.algo.gridsearch.real_grid(dim: Real, num: int)[source]

Build real grid