Skip to main content
Join the official 2020 Python Developers SurveyStart the survey!

Evolutionary Strategies made simple

Project description

evopy

Build Status PyPI Docs

Evolutionary Strategies made simple!

Use evopy to easily optimize a vector of floats in Python.

🏗 Installation

All you need to use evopy is Python 3! Run this command to fetch evopy from PyPI:

pip install evopy

Then you can import EvoPy like this:

from evopy import EvoPy

⏩ Usage

One-Dimensional Example

Let's say we wanted to find the optimum of a parabola, without using exact methods from calculus! With Evopy, this is as easy as writing the following two lines:

evopy = EvoPy(lambda x: pow(x, 2), 1)
best_coordinates = evopy.run()

The main ingredient here is the fitness function (the lambda). This can also be a normal function reference, just make sure that it accepts a float or an array of floats and outputs a single float. The other ingredient is the 1 at the end of the first line: This is the dimensionality of the inputs that you expect in your fitness function. best_coordinates will contain an array with a single element, which is the best x value the algorithm could find in the default number of generations.

Multi-Dimensional Example

If the previous example seemed too simple to you, we can also look at the optimum of a more complex, two-dimensional function, like the Rastrigin function. We don't have to modify much in our previous code snippet to get this to work:

evopy = EvoPy(lambda X: 5 + sum([(x**2 - 5 * np.cos(2 * np.pi * x)) for x in X]), 2, generations=1000, population_size=100)
best_coordinates = evopy.run()

Compared to the first example, we have interchanged the fitness function for a more complex one, set the dimensionality to 2, and given the algorithm more time to find an optimum by setting a higher generation and individual count than the default.

Docs

For more detailed information on evopy's functionality, have a look at the docs!

⛏ Development

Clone this repository and fetch all dependencies from within the cloned directory:

pip install .

Run all tests with:

nosetests

To check your code style, run:

pylint evopy

Project details


Download files

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

Files for evopy, version 0.2
Filename, size File type Python version Upload date Hashes
Filename, size evopy-0.2-py3-none-any.whl (7.4 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size evopy-0.2.tar.gz (6.3 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page