Skip to content

Commit

Permalink
Merge pull request #380 from TaroKingCN/main
Browse files Browse the repository at this point in the history
add test_enes.py
  • Loading branch information
Evolutionary-Intelligence authored Jul 4, 2024
2 parents e12c9a9 + 5cf237d commit e8df8df
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pypop7/optimizers/nes/test_enes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def test_optimize():
import numpy # engine for numerical computing
from pypop7.benchmarks.base_functions import rosenbrock # function to be minimized
from pypop7.optimizers.nes.enes import ENES
problem = {'fitness_function': rosenbrock, # to define problem arguments
'ndim_problem': 2,
'lower_boundary': -5.0 * numpy.ones((2,)),
'upper_boundary': 5.0 * numpy.ones((2,))}
options = {'max_function_evaluations': 5000, # to set optimizer options
'seed_rng': 2022,
'mean': 3.0 * numpy.ones((2,)),
'sigma': 3.0} # global step-size may need to be tuned for optimality
enes = ENES(problem, options) # to initialize the optimizer class
results = enes.optimize() # to run the optimization process
assert results['n_function_evaluations'] == 5000
assert results['best_so_far_y'] < 1.0

0 comments on commit e8df8df

Please sign in to comment.