Differential evolution solutions for the Rosenbrock and Rastigrin functions
Introduction
Mike Croucher’s blog post today,
Which MATLAB Optimization functions can solve my problem?,
demonstrated the solvers()
function in
MATLAB 2022b’s Optimization Toolbox.
This function recommends one of ten MATLAB optimizers based on
the objective function you give it. Pretty cool!
A few months ago I showed how SciPy’s differential evolution function can be called from MATLAB to solve global optimization problems. Mike’s post showed solution metrics for the Rosenbrock and Rastigrin functions for all ten solvers in the Optimization Toolbox. I couldn’t help but wonder how differential evolution stacks up.
TL;DR
Differential evolution is roughly in the middle of the pack for both problems in terms of number of function evaluations. It found the correct solution in both cases but needed a relatively large number of of function evaluations, 4053 for Rosenbrock and 2193 for Rastigrin.
MATLAB/Python Rosenbrock solution
Python:


MATLAB:


I tested the code in MATLAB 2020b and MATLAB 2022b. The results were the same:
MATLAB:
>> rosenbrock
result =
Python dict with no properties.
{'success': True, 'message': 'Optimization terminated successfully.',
'x': array([1., 1.]), 'nfev': 4053}
Use py2mat.m
to get the result as a MATLAB struct:
MATLAB:
>> py2mat(result)
ans =
struct with fields:
success: 1
message: "Optimization terminated successfully."
x: [1.0000 1.0000]
nfev: 4053
MATLAB/Python Rastigrin solution
Python:


MATLAB:


The result:
MATLAB:
>> rastigrin
result =
Python dict with no properties.
{'success': True, 'message': 'Optimization terminated successfully.',
'x': array([2.54892996e10, 2.49528753e09]), 'nfev': 2193}
>> py2mat(result)
ans =
struct with fields:
success: 1
message: "Optimization terminated successfully."
x: [2.5489e10 2.4953e09]
nfev: 2193