Skip to main content

CircleCI

Nevergrad - A gradient-free optimization platform

Nevergrad

nevergrad is a Python 3.6+ library. It can be installed with:

pip install nevergrad

More installation options, including windows installation, and complete instructions are available in the "Getting started" section of the documentation.

You can join Nevergrad users Facebook group here.

Minimizing a function using an optimizer (here NGOpt) is straightforward:

import nevergrad as ng

def square(x):
    return sum((x - .5)**2)

optimizer = ng.optimizers.NGOpt(parametrization=2, budget=100)
recommendation = optimizer.minimize(square)
print(recommendation.value)  # recommended value
>>> [0.49971112 0.5002944]

nevergrad can also support bounded continuous variables as well as discrete variables, and mixture of those. To do this, one can specify the input space:

import nevergrad as ng

def fake_training(learning_rate: float, batch_size: int, architecture: str) -> float:
    # optimal for learning_rate=0.2, batch_size=4, architecture="conv"
    return (learning_rate - 0.2)**2 + (batch_size - 4)**2 + (0 if architecture == "conv" else 10)

# Instrumentation class is used for functions with multiple inputs
# (positional and/or keywords)
parametrization = ng.p.Instrumentation(
    # a log-distributed scalar between 0.001 and 1.0
    learning_rate=ng.p.Log(lower=0.001, upper=1.0),
    # an integer from 1 to 12
    batch_size=ng.p.Scalar(lower=1, upper=12).set_integer_casting(),
    # either "conv" or "fc"
    architecture=ng.p.Choice(["conv", "fc"])
)

optimizer = ng.optimizers.NGOpt(parametrization=parametrization, budget=100)
recommendation = optimizer.minimize(fake_training)

# show the recommended keyword arguments of the function
print(recommendation.kwargs)
>>> {'learning_rate': 0.1998, 'batch_size': 4, 'architecture': 'conv'}

Learn more on parametrization in the documentation!

Example of optimization

Convergence of a population of points to the minima with two-points DE.

Documentation

Check out our documentation! It's still a work in progress, don't hesitate to submit issues and/or PR to update it and make it clearer!

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. See also our Terms of Use and Privacy Policy.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nevergrad-0.4.3.post8.tar.gz (312.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nevergrad-0.4.3.post8-py3-none-any.whl (404.6 kB view details)

Uploaded Python 3

File details

Details for the file nevergrad-0.4.3.post8.tar.gz.

File metadata

  • Download URL: nevergrad-0.4.3.post8.tar.gz
  • Upload date:
  • Size: 312.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.7.11

File hashes

Hashes for nevergrad-0.4.3.post8.tar.gz
Algorithm Hash digest
SHA256 be1476c638625cef4c80493458418f84cd8ffb0d1bfa5acb83d1864ff27b2997
MD5 f92983f60514b562bf6beef9c1405214
BLAKE2b-256 cd0842f929119aa9e71bf503d21ac31cf62fa0c0b2a5f45957815eabf14c1736

See more details on using hashes here.

File details

Details for the file nevergrad-0.4.3.post8-py3-none-any.whl.

File metadata

  • Download URL: nevergrad-0.4.3.post8-py3-none-any.whl
  • Upload date:
  • Size: 404.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.7.11

File hashes

Hashes for nevergrad-0.4.3.post8-py3-none-any.whl
Algorithm Hash digest
SHA256 794a3a5b0bcf2a483dd15b2303c7c09034f9e8cff09b6820f7c52b07083ac62d
MD5 19f093bd143e6f6946e14babbb9f21a3
BLAKE2b-256 a47a0e35d7d48d4a44327205cdb44a72e3ce21280ca12b126dc7c14502609c0b

See more details on using hashes here.

Release history Release notifications | RSS feed

1.0.12

2 files

1.0.11

2 files

1.0.8

2 files

1.0.5

2 files

1.0.4

2 files

1.0.3

2 files

1.0.2

2 files

1.0.1

2 files

1.0.0

2 files

0.14.0

2 files

0.13.0

2 files

0.12.0

2 files

0.11.0

2 files

0.10.0

2 files

0.8.0

2 files

0.7.0

2 files

0.6.0

2 files

0.5.0

2 files

0.4.3.post10

2 files

0.4.3.post9

2 files

This release

0.4.3.post8 This release

2 files

0.4.3.post7

2 files

0.4.3.post4

2 files

0.4.3.post3

2 files

0.4.3.post2

2 files

0.4.3.post1

2 files

0.4.3

2 files

0.4.2.post6

2 files

0.4.2.post5

2 files

0.4.2.post2

2 files

0.4.2.post1

2 files

0.4.2

2 files

0.4.1.post5

2 files

0.4.1.post4

2 files

0.4.1.post3

2 files

0.4.1.post2

2 files

0.4.1

2 files

0.4.0.post3

2 files

0.4.0

2 files

0.3.2

2 files

0.3.1

2 files

0.3.0

2 files

0.2.3

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page