Random Search (RS)¶
RandomSearch ¶
RandomSearch(*, max_archive=None, **kwargs)
Pure random search: every iteration samples pop_size new points uniformly.
A baseline for comparisons, for single and multi-objective problems. The result keeps the best solution found (or, with several objectives, the front).
Parameters
pop_size: number of random points per iteration (default 100)max_archive: with several objectives, the largest size ofResult.front. None (default) keeps every non-dominated solution.
Example¶
import ypea
problem = ypea.Problem(
ypea.Real("x", shape=20, lb=-10, ub=10),
lambda sol: ypea.benchmarks.sphere(sol.x),
vectorized=True,
name="sphere",
)
alg = ypea.RandomSearch(max_nfe=20_000)
result = alg.solve(problem, seed=1)
print(result.summary())
RS on sphere
best objective value: 174.659
feasible: True (violation 0)
evaluations: 20000, iterations: 199, time: 0.0629 s, stopped by: max_nfe
Differs from Python: MATLAB draws its own random numbers, so the best value differs from Python's.
problem = ypea.Problem( ...
vars=ypea.Real("x", shape=20, lb=-10, ub=10), ...
objective=@(sol) ypea.benchmarks.sphere(sol.x), ...
vectorized=true, ...
name="sphere");
alg = ypea.RandomSearch(max_nfe=20000);
result = alg.solve(problem, seed=1);
disp(result.summary())
RS on sphere
best objective value: 217.948
feasible: true (violation 0)
evaluations: 20000, iterations: 199, time: 0.0915 s, stopped by: max_nfe
Search on Rastrigin¶