:encoding: utf-8 :imagesdir: tutorials/img :cpp: C++
= fcmaes - a Python 3 gradient-free optimization library
https://gitter.im/fast-cma-es/community[image:https://badges.gitter.im/Join%20Chat.svg[]]
image::logo.gif[]
fcmaes complements https://docs.scipy.org/doc/scipy/reference/optimize.html[scipy optimize] by providing additional optimization methods, faster {cpp}/Eigen based implementations and a coordinated parallel retry mechanism. It supports the multi threaded application of different gradient free optimization algorithms. There are 35 real world https://github.com/dietmarwo/fast-cma-es/blob/master/tutorials/Tutorials.adoc[tutorials] showing in detail how to use fcmaes. See https://github.com/dietmarwo/fast-cma-es/blob/master/tutorials/Performance.adoc[performance] for detailed fcmaes performance figures.
fcmaes started as a fast CMA-ES implementation combined with a new smart parallel retry mechanism aimed to solve hard optimization problems from the space flight planning domain. It evolved to a general library of state-of-the-art gradient free optimization algorithms applicable to all kind of real world problems covering multi-objective and constrained problems. Its main algorithms are implemented both in Python and C++ and support both parallel fitness function evaluation and a parallel retry mechanism.
=== https://github.com/dietmarwo/fast-cma-es/blob/master/tutorials/Tutorials.adoc[Tutorials]
=== https://github.com/dietmarwo/fast-cma-es/blob/master/tutorials/Performance.adoc[Performance]
=== Features
=== Changes from version 1.6.3:
=== Changes from version 1.4.0:
Derivative free optimization of machine learning models often have several thousand decision variables and require GPU/TPU based parallelization both of the fitness evaluation and the optimization algorithm. CR-FM-NES, PGPE and the QD-Diversifier applied to CR-FM-NES (CR-FM-NES-ME) are excellent choices in this domain. Since fcmaes has a different focus (parallel optimizations and parallel fitness evaluations) we contributed these algorithms to https://github.com/google/evojax/tree/main/evojax/algo[EvoJax] which utilizes https://github.com/google/jax[JAX] for GPU/TPU execution.
=== Optimization algorithms
To utilize modern many-core processors all single-objective algorithms should be used with the parallel retry for cheap fitness functions, otherwise use parallel function evaluation.
MO-DE: A new multi-objective optimization algorithm merging concepts from differential evolution and NSGA. Implemented both in https://github.com/dietmarwo/fast-cma-es/blob/master/fcmaes/mode.py[Python] and in https://github.com/dietmarwo/fast-cma-es/blob/master/_fcmaescpp/modeoptimizer.cpp[C++]. Provides an ask/tell interface and supports constraints and parallel function evaluation. Can also be applied to single-objective problems with constraints. Supports mixed integer problems (see https://github.com/dietmarwo/fast-cma-es/blob/master/tutorials/FluidDynamics.adoc[CFD] for details)
CVT-map-elites/CMA: A new Python implementation of CVT-map-elites including a CMA-ES emitter providing low algorithm overhead and excellent multi-core scaling even for fast fitness functions. Enables "drill down" for specific selected niches. See https://github.com/dietmarwo/fast-cma-es/blob/master/fcmaes/mapelites.py[mapelites.py] and https://github.com/dietmarwo/fast-cma-es/blob/master/tutorials/MapElites.adoc[Map-Elites].
Diversifier: A new Python meta-algorithm based on CVT-map-elites archives generalizing ideas from https://arxiv.org/pdf/1912.02400.pdf[CMA-ME] to other wrapped algorithms. See https://github.com/dietmarwo/fast-cma-es/blob/master/fcmaes/diversifier.py[diversifier.py] and https://github.com/dietmarwo/fast-cma-es/blob/master/tutorials/Diversity.adoc[Quality Diversity].
BiteOpt algorithm from Aleksey Vaneev https://github.com/avaneev/biteopt[BiteOpt]. Only a C++ version is provided. If your problem is single objective and if you have no clue what algorithm to apply, try this first. Works well with almost all problems. For constraints you have to use weighted penalties.
Differential Evolution: Implemented both in https://github.com/dietmarwo/fast-cma-es/blob/master/fcmaes/de.py[Python] and in https://github.com/dietmarwo/fast-cma-es/blob/master/_fcmaescpp/deoptimizer.cpp[C++]. Additional concepts implemented are https://www.researchgate.net/publication/309179699_Differential_evolution_for_protein_folding_optimization_based_on_a_three-dimensional_AB_off-lattice_model[temporal locality], stochastic reinitialization of individuals based on their age and oscillating CR/F parameters. Provides an ask/tell interface and supports parallel function evaluation. Supports mixed integer problems (see https://github.com/dietmarwo/fast-cma-es/blob/master/tutorials/FluidDynamics.adoc[CFD] for details)
CMA-ES: Implemented both in https://github.com/dietmarwo/fast-cma-es/blob/master/fcmaes/cmaes.py[Python] and in https://github.com/dietmarwo/fast-cma-es/blob/master/_fcmaescpp/acmaesoptimizer.cpp[C++]. Provides an ask/tell interface and supports parallel function evaluation. Good option for low number of decision variables (< 500).
CR-FM-NES: Fast Moving Natural Evolution Strategy for High-Dimensional Problems, see https://arxiv.org/abs/2201.11422. Derived from https://github.com/nomuramasahir0/crfmnes . Implemented both in https://github.com/dietmarwo/fast-cma-es/blob/master/fcmaes/crfmnes.py[Python] and in https://github.com/dietmarwo/fast-cma-es/blob/master/_fcmaescpp/crfmnes.cpp[C++]. Both implementations provide parallel function evaluation and an ask/tell interface. Good option for high number of decision variables (> 100).
PGPE Parameter Exploring Policy Gradients, see http://mediatum.ub.tum.de/doc/1099128/631352.pdf . Implemented in https://github.com/dietmarwo/fast-cma-es/blob/master/_fcmaescpp/pgpe.cpp[C++]. Provides parallel function evaluation and an ask/tell interface. Good option for very high number of decision variables (> 1000) and for machine learning tasks. An equivalent Python implementation can be found at https://github.com/google/evojax/blob/main/evojax/algo/pgpe.py[pgpe.py], use this on GPUs/TPUs.
Wrapper for https://github.com/CyberAgentAILab/cmaes[cmaes] which provides different CMA-ES variants implemented in Python like separable CMA-ES and CMA-ES with Margin (see https://arxiv.org/abs/2205.13482) which improves support for mixed integer problems. The wrapper additionally supports parallel function evaluation.
Dual Annealing: Eigen based implementation in https://github.com/dietmarwo/fast-cma-es/blob/master/_fcmaescpp/daoptimizer.cpp[C++]. Use the https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.dual_annealing.html[scipy implementation] if you prefer a pure Python variant or need more configuration options.
GCL-DE: Eigen based implementation in https://github.com/dietmarwo/fast-cma-es/blob/master/_fcmaescpp/gcldeoptimizer.cpp[C++]. See "A case learning-based differential evolution algorithm for global optimization of interplanetary trajectory design, Mingcheng Zuo, Guangming Dai, Lei Peng, Maocai Wang, Zhengquan Liu", https://doi.org/10.1016/j.asoc.2020.106451[doi].
Expressions: There are two operators for constructing expressions over optimization algorithms: Sequence and random choice. Not only the single objective algorithms above, but also scipy and NLopt optimization methods and custom algorithms can be used for defining algorithm expressions.
=== Installation
==== Linux
pip install fcmaes
. To use the {cpp} optimizers a gcc-9.3 (or newer) runtime is required. This is the default on newer Linux versions. If you are on an old Linux distribution you need to install gcc-9 or a newer version. On ubuntu this is:
Alternatively if you use Anaconda:
conda install -c conda-forge gxx_linux-64==9.5.0
Recommended Python environment: https://repo.anaconda.com/archive/Anaconda3-2022.05-Linux-x86_64.sh[Anaconda3-2022.05] or newer. At least Python 3.7 is required.
==== Windows
pip install fcmaes
Install {cpp} runtime libraries https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads
Recommended Python environment: https://repo.anaconda.com/archive/Anaconda3-2022.05-Windows-x86_64.exe[Anaconda3-2022.05] or newer.
For parallel fitness function evaluation use the native Python optimizers or the ask/tell interface of the {cpp} ones. Python multiprocessing works better on Linux. To get optimal scaling from parallel retry and parallel function evaluation use:
The Linux subsystem can read/write NTFS, so you can do your development on a NTFS partition. Just the Python call is routed to Linux. If performance of the fitness function is an issue and you don't want to use the Linux subsystem for Windows, think about using the fcmaes java port: https://github.com/dietmarwo/fcmaes-java[fcmaes-java].
==== MacOS
pip install fcmaes
The {cpp} shared library is outdated, use the native Python optimizers.
=== Usage
Usage is similar to https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html[scipy.optimize.minimize].
For parallel retry use:
The retry logs mean and standard deviation of the results, so it can be used to test and compare optimization algorithms: You may choose different algorithms for the retry:
Here https://github.com/dietmarwo/fast-cma-es/blob/master/examples you find more examples. Check the https://github.com/dietmarwo/fast-cma-es/blob/master/tutorials/Tutorials.adoc[tutorials] for more details.
=== Dependencies
Runtime:
Compile time (binaries for Linux and Windows are included):
Optional dependencies:
Example dependencies:
=== Citing