top of page

Optimization in Python using CMA-ES

Fall 2021

Course Info

ME 446: Computational Design & Dynamics of Soft Systems

A project-based class that provided an introduction to genetic algorithms and the covariance-matrix adaptation evolution strategy (CMA-ES) in Python. Also taught modern modeling techniques for systems using soft, elastic structures known as Cosserat rods.

Project Details

For this project, we were tasked with applying two different evolutionary optimization algorithms to a number of defined problems/functions. The two algorithms used were the genetic algorithm (GA) and the covariance matrix adaptation evolution strategy (CMA-ES). The problems that were optimized included the 0/1 knapsack problem, as well as the parabola, rotated hyper-ellipsoid, and the Rastrigin function (in 2D and 5D).


For this project, I developed a simple framework in Python for both genetic algorithms, and then modified the framework to work for each problem. For example, optima of the mathematical functions had to be found as float values to a certain precision; because genetic algorithms typically work with binary values, I had to map float values to binary values and perform evolutionary operations on the binary values. This was not the case for the 0/1 knapsack problem, where 1s and 0s in a binary string represent whether an item is included in the knapsack. I worked mainly with using the NumPy library and the principles of linear algebra; additionally, lots of statistical concepts were used in stochastic universal sampling in the genetic algorithms, as well as holistically in CMA-ES.


This project helped me develop core competencies in Python, working with different libraries and generally with object-oriented programming. Though my algorithms and solutions worked, there is certainly room for improvement in terms of code cleanliness and code efficiency, things which I have been improving upon on my own since the project ended. In the future, I would like to revisit the concept of evolutionary optimization algorithms, as they can be applied to a lot of different systems, from solving a video game level in the fastest time, to programming multiple robots to work in sync to accomplish a task.

bottom of page