Skip to main content

Numerical optimization framework

Project description

Indago

Indago is a Python 3 module for numerical optimization.

Installation

For easiest install use

pip3 install indago

In order to obtain Indago code, clone Gitlab repository by executing following command in the directory where you want to loacte Indago root directory:

git clone https://gitlab.com/sivic/indago.git

For building and installing Indago package into your Python environment

python setup.py build
python setup.py install

Or for continous testing/developing:

python setup.py clean build install

Dependencies

A following packages should be installed using aptitude:

  • python3
  • python3-pip
  • python3-tk
sudo apt install python3 python3-pip python3-tk

After packages installation using above command, additional python packages should be installed using pip from requirements.txt

pip install -r requirements.txt

Algorithms

Indago is a Python module for numerical optimization of real fitness function over a real parameter domain. It was developed at the Department for Fluid Mechanics and Computational Engineering of the University of Rijeka, Faculty of Engineering, by Stefan Ivić, Siniša Družeta, and others.

Indago is developed for in-house research and teaching purposes and is not officially supported in any way, it is not properly documented and probably needs more testing. But hey, we use it, it works for us, and it's free! Anyway, proceed with caution, as you would with any other beta-level software.

As of now, Indago consists of three stochastic swarm-based optimizers, namely Particle Swarm Optimization (PSO), Fireworks Algorithm (FWA) and Squirrel Search Algorithm (SSA). They are all available through the same API, which was designed to be as accessible as possible. Indago relies heavily on NumPy, so the inputs and outputs of the optimizers are mostly NumPy arrays. Besides NumPy and a couple of other stuff here and there (such as a few SciPy functions), Indago is pure Python. Indago optimizers also include some of our original research improvements, so feel free to try those as well. And don't forget to cite. :)

Particle Swarm Optimization

Using Indago is easy. Let us use PSO as an example. First, we need to import NumPy and Indago PSO, and then initialize an optimizer object:

import numpy as np
from indago.pso import PSO
pso = PSO()

Then, we must provide a goal function which needs to be minimized, say:

def goalfun(x):	# must take 1d np.array
    return np.sum(x**2) # must return scalar number
pso.evaluation_function = goalfun

Now we can define optimizer inputs:

pso.method = 'Vanilla' # we will use Standard PSO, the other available option is 'TVAC' [1]
pso.dimensions = 20 # number of variables in the design vector (x)
pso.swarm_size = 15 # number of PSO particles
pso.iterations = int(1000 * pso.dimensions / pso.swarm_size) # any integer will do, but 10³D function calls is possibly a good choice
pso.target_fitness = 10**-3 # optional fitness threshold; when reached, optimization is stopped (if it didn't already stop due to exhausted pso.iterations)
pso.lb = np.ones(pso.dimensions) * -1 # 1d np.array of lower bound values
pso.ub = np.ones(pso.dimensions) * 1 # 1d np.array of upper bound values

Also, we must provide optimization method parameters:

pso.params['cognitive_rate'] = 1.0 # PSO parameter also known as c1 (ranges from 0.0 to 2.0)
pso.params['social_rate'] = 1.0 # PSO parameter also known as c2 (ranges from 0.0 to 2.0)
pso.params['inertia'] = 0.72 # PSO parameter known as inertia weight w (ranges from 0.5 to 1.0), the other available options are 'LDIW' (w linearly decreasing from 1.0 to 0.4) and 'anakatabatic'

If we want to use our novel adaptive inertia weight technique [2], we invoke it by:

pso.params['inertia'] = 'anakatabatic'

then we need to also specify the anakatabatic model:

pso.params['akb_model'] = 'Languid' # [3,4], other options are 'FlyingStork', 'MessyTie', 'RightwardPeaks', 'OrigamiSnake' [2]

Optionally, we can also enable parallel swarm evaluation. Note that it scales well only on relatively slow goal functions. Also keep in mind that Python multiprocessing sometimes does not work when initiated from imported code, so you need to have the optimization run call wrapped in if __name__ == '__main__':.

pso.number_of_processes = 4 # use 'maximum' for employing all available processors/cores

Finally, we can start the optimization and get the results:

result = pso.run()
min_f = result.f # fitness at minimum, scalar number
x_min = result.X # design vector at minimum, 1d np.array

And that's it!

Fireworks Algorithm

If we want to use FWA [5], we just have to import it instead of PSO:

from indago.fwa import FWA
fwa = FWA()

Now we can proceed in the same manner as with PSO. For FWA, the only method available is basic FWA:

fwa.method = 'Vanilla'

In FWA, we do not use the swarm_size parameter and we have to set the following method parameters:

fwa.params['n'] = 20
fwa.params['m1'] = 10
fwa.params['m2'] = 10

Squirrel Search Algorithm

Lastly, if we want to try our luck with SSA [6], we initialize it like this:

from indago.ssa import SSA
ssa = SSA()

In SSA, the only available method is 'Vanilla', and we need to provide the swarm_size parameter. Also, there is only one mandatory method parameter:

ssa.params['acorn_tree_attraction'] = 0.5 # ranges from 0.0 to 1.0

Optionally, we can define a few other SSA parameters:

ssa.params['predator_presence_probability'] = 0.1
ssa.params['gliding_constant'] = 1.9 
ssa.params['gliding_distance_limits'] = [0.5, 1.11] 

CEC 2014

Among other stuff, Indago also includes the CEC 2014 test suite [7], comprising 30 test functions for real optimization methods. You can use it by importing it like this:

from indago.benchmarks import CEC2014

Then, you have to initialize it for a specific dimensionality of the test functions:

test = CEC2014(20) # initialization od 20-dimension functions, you can also use 10, 50 and 100

Now you can use specific test functions (test.F1(), test.F2(), ...up to test.F30()), they all take 1d np.array of size 10/20/50/100 and return a scalar number. Alternatively, you can iterate through the built-in list of them all:

test_results = []
for f in test.functions:
    optimizer.evaluation_function = f
    test_results.append(optimizer.run().f)

Have fun!

References:

  1. Ratnaweera, A., Halgamuge, S. K., & Watson, H. C. (2004). Self-organizing hierarchical particle swarm optimizer with time-varying acceleration coefficients. IEEE Transactions on evolutionary computation, 8(3), 240-255.

  2. Družeta, S., & Ivić, S. (2020). Anakatabatic Inertia: Particle-wise Adaptive Inertia for PSO, arXiv:2008.00979 [cs.NE].

  3. Družeta, S., & Ivić, S. (2017). Examination of benefits of personal fitness improvement dependent inertia for Particle Swarm Optimization. Soft Computing, 21(12), 3387-3400.

  4. Družeta, S., Ivić, S., Grbčić, L., & Lučin, I. (2019). Introducing languid particle dynamics to a selection of PSO variants. Egyptian Informatics Journal, 21(2), 119-129.

  5. Tan, Y., & Zhu, Y. (2010, June). Fireworks algorithm for optimization. In International conference in swarm intelligence (pp. 355-364). Springer, Berlin, Heidelberg.

  6. Jain, M., Singh, V., & Rani, A. (2019). A novel nature-inspired algorithm for optimization: Squirrel search algorithm. Swarm and evolutionary computation, 44, 148-175.

  7. Liang, J. J., Qu, B. Y., & Suganthan, P. N. (2013). Problem definitions and evaluation criteria for the CEC 2014 special session and competition on single objective real-parameter numerical optimization. Computational Intelligence Laboratory, Zhengzhou University, Zhengzhou China and Technical Report, Nanyang Technological University, Singapore, 635.

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

Indago-0.1.3.tar.gz (22.9 kB view details)

Uploaded Source

Built Distribution

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

Indago-0.1.3-py3-none-any.whl (28.0 kB view details)

Uploaded Python 3

File details

Details for the file Indago-0.1.3.tar.gz.

File metadata

  • Download URL: Indago-0.1.3.tar.gz
  • Upload date:
  • Size: 22.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.6.0.post20201009 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.7.8

File hashes

Hashes for Indago-0.1.3.tar.gz
Algorithm Hash digest
SHA256 e44b4ea1bb5e3aa9e80c3462b8479d6e2de9483fbc97b3ca40d3e41e3e3cb35d
MD5 09c6241df16538aca051ff373243739e
BLAKE2b-256 851a49d03c9991360b91a6637a4f390ecaa54e3c8581c9a145b0f2434bb718eb

See more details on using hashes here.

File details

Details for the file Indago-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: Indago-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 28.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.6.0.post20201009 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.7.8

File hashes

Hashes for Indago-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 1d4f90d0698e1d2d15e2e4190daede94fe5807437a870157250032723d453529
MD5 5fd6d0e6b8c6a83b9da785be0fb36bab
BLAKE2b-256 5f88a5db8ea891a82520757918abdda6214d9ba41b780e58ce253e305c7aad99

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