A Python toolbox for performing gradient-free optimization
Project description
Nevergrad - A gradient-free optimization platform
nevergrad
is a Python 3.6+ library. It can be installed with:
pip install nevergrad
You can also install the master branch instead of the latest release with:
pip install git+https://github.com/facebookresearch/nevergrad@master#egg=nevergrad
Alternatively, you can clone the repository and run pip install -e .
from inside the repository folder.
By default, this only installs requirements for the optimization and parametrization subpackages. If you are also interested in the benchmarking part,
you should install with the [benchmark]
flag (example: pip install nevergrad[benchmark]
), and if you also want the test tools, use
the [all]
flag (example: pip install -e .[all]
).
Notes:
- with
zhs
you will need to runpip install 'nevergrad[all]'
instead ofpip install nevergrad[all]
- under Windows, you may need to preinstall torch (for
benchmark
orall
installations) using instructions here.
You can join Nevergrad users Facebook group here.
Goals and structure
The goals of this package are to provide:
- gradient/derivative-free optimization algorithms, including algorithms able to handle noise.
- tools to parametrize any code, making it painless to optimize your parameters/hyperparameters, whether they are continuous, discrete or a mixture of continuous and discrete parameters.
- functions on which to test the optimization algorithms.
- benchmark routines in order to compare algorithms easily.
The structure of the package follows its goal, you will therefore find subpackages:
optimization
: implementing optimization algorithmsparametrization
: specifying what are the parameters you want to optimizefunctions
: implementing both simple and complex benchmark functionsbenchmark
: for running experiments comparing the algorithms on benchmark functionscommon
: a set of tools used throughout the package
Convergence of a population of points to the minima with two-points DE.
Documentation
The following README is very general, here are links to find more details on:
- how to perform optimization using
nevergrad
, including using parallelization and a few recommendation on which algorithm should be used depending on the settings - how to parametrize your problem so that the optimizers are informed of the problem to solve. This also provides a tool to instantiate a script or non-python code into a Python function and be able to tune some of its parameters.
- how to benchmark all optimizers on various test functions.
- benchmark results of some standard optimizers an simple test cases.
- examples of optimization for machine learning.
- how to contribute through issues and pull requests and how to setup your dev environment.
- guidelines of how to contribute by adding a new algorithm.
Basic optimization example
All optimizers assume a centered and reduced prior at the beginning of the optimization (i.e. 0 mean and unitary standard deviation). They are however able to find solutions far from this initial prior.
Optimizing (minimizing!) a function using an optimizer (here OnePlusOne
) can be easily run with:
import nevergrad as ng
def square(x):
return sum((x - .5)**2)
optimizer = ng.optimizers.OnePlusOne(parametrization=2, budget=100)
recommendation = optimizer.minimize(square)
print(recommendation) # optimal args and kwargs
>>> Array{(2,)}[recombination=average,sigma=1.0]:[0.49971112 0.5002944 ]
parametrization=n
is a shortcut to state that the function has only one variable, of dimension n
,
See the parametrization tutorial for more complex parametrizations.
recommendation
holds the optimal value(s) found by the for the provided function. It can be
directly accessed through recommendation.value
which is here a np.ndarray
of size 2.
You can print the full list of optimizers with:
import nevergrad as ng
print(list(sorted(ng.optimizers.registry.keys())))
The optimization documentation contains more information on how to use several workers,
take full control of the optimization through the ask
and tell
interface, perform multiobjective optimization,
as well as pieces of advice on how to choose the proper optimizer for your problem.
Citing
@misc{nevergrad,
author = {J. Rapin and O. Teytaud},
title = {{Nevergrad - A gradient-free optimization platform}},
year = {2018},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://GitHub.com/FacebookResearch/Nevergrad}},
}
License
nevergrad
is released under the MIT license. See LICENSE for additional details about it.
LGPL code is however also included in the multiobjective subpackage.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for nevergrad-0.3.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bdfd9b92c778eb6fb111cb2898581239d26c58f0a9c9900ebe5250eb4aa49d89 |
|
MD5 | 9f16ff22c36c299c6189af4c1571984d |
|
BLAKE2b-256 | dcbdec53853f82e8d6c9137fdefe60f9d64fb1b06b58a7eed49c7678d2fa7225 |