optunity.solvers.RandomSearch module¶
-
class
optunity.solvers.RandomSearch.
RandomSearch
(num_evals, **kwargs)[source]¶ Bases:
optunity.solvers.util.Solver
Please refer to Random Search for more details about this algorithm.
Initializes the solver with bounds and a number of allowed evaluations. kwargs must be a dictionary of parameter-bound pairs representing the box constraints. Bounds are a 2-element list: [lower_bound, upper_bound].
>>> s = RandomSearch(x=[0, 1], y=[-1, 2], num_evals=50) >>> s.bounds['x'] [0, 1] >>> s.bounds['y'] [-1, 2] >>> s.num_evals 50
-
bounds
¶ Returns a dictionary containing the box constraints.
-
desc_brief
= 'random parameter tuples sampled uniformly within box constraints'¶
-
desc_full
= ['Tests random parameter tuples sampled uniformly within the box constraints.', ' ', 'This function requires the following arguments:', '- num_evals :: number of tuples to test', '- box constraints via keywords: constraints are lists [lb, ub]', ' ', 'This solver performs num_evals function evaluations.', ' ', 'This solver implements the technique described here:', 'Bergstra, James, and Yoshua Bengio. Random search for hyper-parameter optimization. Journal of Machine Learning Research 13 (2012): 281-305.']¶
-
lower
¶ Returns the lower bound of par.
-
maximize
(f, pmap=<built-in function map>)¶ Maximizes f.
Parameters: - f (callable) – the objective function
- pmap (callable) – the map() function to use
Returns: - the arguments which optimize
f
- an optional solver report, can be None
-
minimize
(f, pmap=<built-in function map>)¶ Minimizes
f
.Parameters: - f (callable) – the objective function
- pmap (callable) – the map() function to use
Returns: - the arguments which optimize
f
- an optional solver report, can be None
-
name
= 'random search'¶
-
num_evals
¶ Returns the number of evaluations this solver may do.
-
optimize
(f, maximize=True, pmap=<built-in function map>)[source]¶ Optimizes
f
.Parameters: - f (callable) – the objective function
- maximize (boolean) – do we want to maximizes?
- pmap (callable) – the map() function to use
Returns: - the arguments which optimize
f
- an optional solver report, can be None
-
static
suggest_from_box
(num_evals, **kwargs)[source]¶ Creates a RandomSearch solver that uses
num_evals
evaluations within given bounds (lb, ub). The bounds are first tightened, resulting in new bounds covering 99% of the area.>>> s = RandomSearch.suggest_from_box(30, x=[0, 1], y=[-1, 0], z=[-1, 1]) >>> s['x'] [0.005, 0.995] >>> s['y'] [-0.995, -0.005] >>> s['z'] [-0.99, 0.99] >>> s['num_evals'] 30
Verify that we can effectively make a solver from box.
>>> s = RandomSearch.suggest_from_box(30, x=[0, 1], y=[-1, 0], z=[-1, 1]) >>> solver = RandomSearch(**s)
-
upper
¶ Returns the upper bound of par.
-