cma-es

Covariance Matrix Adaptation Evolution Strategy (CMA-ES)

https://github.com/srom/cma-es

Science Score: 10.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
    Links to: arxiv.org
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (12.3%) to scientific vocabulary

Keywords

numerical-optimization optimization optimization-algorithms python tensorflow
Last synced: 6 months ago · JSON representation

Repository

Covariance Matrix Adaptation Evolution Strategy (CMA-ES)

Basic Info
  • Host: GitHub
  • Owner: srom
  • License: mit
  • Language: Jupyter Notebook
  • Default Branch: master
  • Homepage:
  • Size: 2.48 MB
Statistics
  • Stars: 66
  • Watchers: 3
  • Forks: 15
  • Open Issues: 0
  • Releases: 0
Topics
numerical-optimization optimization optimization-algorithms python tensorflow
Created over 6 years ago · Last pushed about 4 years ago
Metadata Files
Readme License

README.md

Covariance Matrix Adaptation Evolution Strategy (CMA-ES)

A TensorFlow 2 implementation.

What is CMA-ES?

The CMA-ES (Covariance Matrix Adaptation Evolution Strategy) is an evolutionary algorithm for difficult non-linear non-convex black-box optimisation problems in continuous domain. It is considered as state-of-the-art in evolutionary computation and has been adopted as one of the standard tools for continuous optimisation in many (probably hundreds of) research labs and industrial environments around the world.

The CMA Evolution Strategy

Installation

The package is available on PyPI and can be installed with pip:

sh pip install cma-es

Alternatively, cma-es can also be installed from conda-forge:

sh conda install -c conda-forge cma-es

Example Usage

1. Define the fitness function

CMA attempts to minimize a user-defined fitness function.

Function signature:

```
Args: x: tf.Tensor of shape (M, N)

Returns: Fitness evaluations: tf.Tensor of shape (M,) ```

Where M is the number of solutions to evaluate and N is the dimension of a single solution.

python def fitness_fn(x): """ Six-Hump Camel Function https://www.sfu.ca/~ssurjano/camel6.html """ return ( (4 - 2.1 * x[:,0]**2 + x[:,0]**4 / 3) * x[:,0]**2 + x[:,0] * x[:,1] + (-4 + 4 * x[:,1]**2) * x[:,1]**2 )

Figure1: Six-Hump Camel Function

2. Configure CMA-ES

```python from cma import CMA

cma = CMA( initialsolution=[1.5, -0.4], initialstepsize=1.0, fitnessfunction=fitness_fn, ) ```

The initial solution and initial step size (i.e. initial standard deviation of the search distribution) are problem specific.

The population size is automatically set by default, but it can be overidden by specifying the parameter population_size.

For bounded constraint optimization problems, the parameter enforce_bounds can be set, e.g. enforce_bounds=[[-2, 2], [-1, 1]] for a 2D function.

3. Run the optimizer

The search method runs until the maximum number of generation is reached or until one of the early termination criteria is met. By default, the maximum number of generations is 500.

python best_solution, best_fitness = cma.search()

The notebook Example 1 - Six Hump Camel Function goes into more details, including ways to plot the optimization path such as in the figure below.

Figure 2: Optimization path

Logging

A user-defined callback function can be specified to inspect variables during the search.

It is mainly intended for logging purpose, e.g:

```python max_epochs = 500

def loggingfunction(cma, logger): if cma.generation % 10 == 0: fitness = cma.bestfitness() logger.info(f'Generation {cma.generation} - fitness {fitness}')

if cma.termination_criterion_met or cma.generation == max_epochs:
    sol = cma.best_solution()
    fitness = cma.best_fitness()
    logger.info(f'Final solution at gen {cma.generation}: {sol} (fitness: {fitness})')

cma = CMA( initialsolution=[1.5, -0.4], initialstepsize=1.0, fitnessfunction=fitnessfn, callbackfunction=loggingfunction, ) cma.search(maxepochs) ```

Check out an example logging progress to TensorBoard: tensorboard_example.py

Running on GPU

By virtue of using TensorFlow, CMA should make use of available GPUs without any code change.

If you run into issues, check the official TF documentation.

More examples

Resources

Owner

  • Name: Romain Strock
  • Login: srom
  • Kind: user
  • Location: London, UK

Scientist, AI enthusiast, Bioinformatics PhD student @ Imperial College

GitHub Events

Total
  • Watch event: 15
  • Fork event: 2
Last Year
  • Watch event: 15
  • Fork event: 2

Committers

Last synced: over 1 year ago

All Time
  • Total Commits: 78
  • Total Committers: 3
  • Avg Commits per committer: 26.0
  • Development Distribution Score (DDS): 0.192
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
srom r****k@g****m 63
Romain Strock s****m 14
Niklas Pirnay n****s@p****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 7 months ago

All Time
  • Total issues: 1
  • Total pull requests: 1
  • Average time to close issues: 9 days
  • Average time to close pull requests: 3 minutes
  • Total issue authors: 1
  • Total pull request authors: 1
  • Average comments per issue: 3.0
  • Average comments per pull request: 0.0
  • Merged pull requests: 1
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • n1kn4x (1)
Pull Request Authors
  • srom (1)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 2
  • Total downloads:
    • pypi 80 last-month
  • Total dependent packages: 0
    (may contain duplicates)
  • Total dependent repositories: 2
    (may contain duplicates)
  • Total versions: 7
  • Total maintainers: 1
pypi.org: cma-es

Covariance Matrix Adaptation Evolution Strategy (CMA-ES) implemented with TensorFlow

  • Versions: 6
  • Dependent Packages: 0
  • Dependent Repositories: 2
  • Downloads: 80 Last month
Rankings
Dependent packages count: 10.0%
Stargazers count: 10.2%
Forks count: 10.5%
Dependent repos count: 11.6%
Average: 12.1%
Downloads: 18.3%
Maintainers (1)
Last synced: 6 months ago
conda-forge.org: cma-es
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 34.0%
Stargazers count: 40.1%
Average: 42.2%
Forks count: 43.4%
Dependent packages count: 51.2%
Last synced: 6 months ago

Dependencies

requirements.txt pypi
  • tensorflow >=2.0
requirements_notebook.txt pypi
  • jupyter *
  • matplotlib *
  • scipy *
  • seaborn *
setup.py pypi
  • tensorflow *