Skip to main content

Evolutionary Optimization

Project description

Evolutionary Algorithm Optimization (EAO)

Package for optimization using Evolutionary Algorithms (EA), providing base classes for individuals and an evaluation module.

Version History

  • 0.4 Removed necessity to manually assign loss_ attribute
  • 0.5 Added extensive logging capabilities; will be cleaned up a little in later versions
  • 0.6 Fixed critical bug that affects optimization with more than one parent
  • 0.7 Made logging much cleaner; added plus-selection

Documentation

eao (Evolutionary Algorithm Optimization)

This library provides a function minimizer using a simple modular evolutionary algorithm scheme that can be adapted to all kinds of target domains. The algorithm performs optimization steps (generations) on a population of solutions by iteratively creating offspring through recombination and mutation, evaluation the offspring using a customizable fitness function and selecting new parents for the next generation, either through plus selection (best individuals from offspring plus previous parents) or comma selection (best individuals from offspring only). Additionally, eao has useful logging capabilities, that allow to fully retrace each optimization run for further analysis.

In its core, eao requires the user to extend 2 classes:

  • Individual: Class representing the target domain, e.g. real numbers, vectors, bit strings or more complex objects
  • Evaluator: Class containing the evaluation method, which takes an object of Individual and assigns it a loss value (or inverse fitness value) according to which it is ranked

The following sections will explain how to implement these classes and how to use them with the optimizer. As an example, we will implement an optimization problem on real vectors.

Individual

In a first step, we will create a subclass of Individual called RealVector that will represent vectors of float values with fixed size. I'll be using numpy arrays as the actual internal data structure and write a wrapper that implements the methods required for individuals. For a minimal implementation we will need the following methods:

copy() : This method returns a (deep) copy of the object. This is necessary because objects are copied between populations internally, and this method allows us to manually copy internal class attributes that require manual deep copying on their own, such as numpy arrays.

random() : This is a static method (@classmethod) and returns a random instance of our data type

mutate(*kwargs) : This method performs mutation in-place, i.e. it introduces a little variation to the individual. For real vectors, we will add some random noise to one of the elements. Additional parameters can be passed to this function, which can be set via the configuration dict, more on this later.

cross(other, *kwargs) : This performs crossover (recombination) in-place, taking another individual as input. For our example, we will perform one-point crossover, meaning we'll sample a cutting point and take one part from either parent. Just as mutate, this method can take custom parameters. Also, if you don't want to use crossover, you can skip this method.

After implementing these methods for our example application, the RealVector class looks like this:

import numpy as np
from eao import Individual, Evaluator, Optimizer

class RealVector(Individual):

    def __init__(self, vec):
        self.vec = vec

    def copy(self):
        return RealVector(self.vec.copy())

    @classmethod
    def random(cls):
        return cls(np.random.uniform(-1, 1, size=16))

    def mutate(self):
        index = np.random.choice(16)
        self.vec[index] += np.random.normal(loc=0, scale=0.1)

    def cross(self, other):
        index = np.random.choice(17)
        self.vec[ix:] = other.vec[ix:]

As you can see we'll be working with RealVectors of size 16, and random instances will have elements uniformly distributed between -1 and 1. When implementing random, make sure the initial individuals are not unreasonable, e.g. much too large or too small - this will make it difficult to reach the solution by small mutations.

Evaluator

  • Coming soon!

Configuration

  • Coming soon!

Project details


Download files

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

Source Distribution

eao-0.7.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

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

eao-0.7-py3-none-any.whl (21.9 kB view details)

Uploaded Python 3

File details

Details for the file eao-0.7.tar.gz.

File metadata

  • Download URL: eao-0.7.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.8.5

File hashes

Hashes for eao-0.7.tar.gz
Algorithm Hash digest
SHA256 e67284dca4bfa7dfe049a54eed5d3d613d4470415f1776a87e33e4f10cdd2a12
MD5 4d6c2cdd4b674f0ee415017f41b8ca16
BLAKE2b-256 9b8790ab1bb630134786c2e199d9f277bd3030e97b046dd574f3e016054f256a

See more details on using hashes here.

File details

Details for the file eao-0.7-py3-none-any.whl.

File metadata

  • Download URL: eao-0.7-py3-none-any.whl
  • Upload date:
  • Size: 21.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.8.5

File hashes

Hashes for eao-0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 6b1993c8597d7b81cea6122ea389d0681acbc3a2cb29f1bb2255145dce7cd15c
MD5 e35c8544dc2cba04b1a4f01e65aec318
BLAKE2b-256 e9a91e573d3e118c53417076cb1d9842b63b1d3e14ff664838d79fa5abbcc053

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page