Pure Random Search (PRS)

class pypop7.optimizers.rs.prs.PRS(problem, options)

Pure Random Search (PRS).


PRS is one of the simplest and earliest black-box optimizers, dating back to at least 1950s. Although recently it has been successfully applied in several relatively low-dimensional problems (particularly hyper-parameter optimization), it generally suffers from the famous curse of dimensionality for large-scale black-box optimization (LSBBO), owing to the lack of adaptation, a highly desirable property for most sophisticated search algorithms. Therefore, it is highly recommended to first attempt more advanced (e.g. population-based) methods for LSBBO.

Here we include it mainly for benchmarking purpose. As pointed out in Probabilistic Machine Learning, “this should always be tried as a baseline”.

  • problem (dict) –

    problem arguments with the following common settings (keys):
    • ’fitness_function’ - objective function to be minimized (func),

    • ’ndim_problem’ - number of dimensionality (int),

    • ’upper_boundary’ - upper boundary of search range (array_like),

    • ’lower_boundary’ - lower boundary of search range (array_like).

  • options (dict) –

    optimizer options with the following common settings (keys):
    • ’max_function_evaluations’ - maximum of function evaluations (int, default: np.Inf),

    • ’max_runtime’ - maximal runtime to be allowed (float, default: np.Inf),

    • ’seed_rng’ - seed for random number generation needed to be explicitly set (int).


Use the PRS optimizer to minimize the well-known test function Rosenbrock:

 1>>> import numpy
 2>>> from pypop7.benchmarks.base_functions import rosenbrock  # function to be minimized
 3>>> from pypop7.optimizers.rs.prs import PRS
 4>>> problem = {'fitness_function': rosenbrock,  # define problem arguments
 5...            'ndim_problem': 2,
 6...            'lower_boundary': -5*numpy.ones((2,)),
 7...            'upper_boundary': 5*numpy.ones((2,))}
 8>>> options = {'max_function_evaluations': 5000,  # set optimizer options
 9...            'seed_rng': 2022}
10>>> prs = PRS(problem, options)  # initialize the optimizer class
11>>> results = prs.optimize()  # run the optimization process
12>>> # return the number of used function evaluations and found best-so-far fitness
13>>> print(f"PRS: {results['n_function_evaluations']}, {results['best_so_far_y']}")
14PRS: 5000, 0.11497678820610932

For its correctness checking of coding, refer to this code-based repeatability report for more details.


Bergstra, J. and Bengio, Y., 2012. Random search for hyper-parameter optimization. Journal of Machine Learning Research, 13(2). https://www.jmlr.org/papers/v13/bergstra12a.html

Schmidhuber, J., Hochreiter, S. and Bengio, Y., 2001. Evaluating benchmark problems by random guessing. A Field Guide to Dynamical Recurrent Networks, pp.231-235. https://ml.jku.at/publications/older/ch9.pdf

Brooks, S.H., 1958. A discussion of random methods for seeking maxima. Operations Research, 6(2), pp.244-251. https://pubsonline.informs.org/doi/abs/10.1287/opre.6.2.244