Skip to main content

Python package for heuristic optimization

Project description

Mean Variance Mapping Optimization Algorithm

MVMO is a Python package to perform heuristic optimization on constrained and unconsrained optimization problems whose convexity and/or linearity may not be fully known. It is based on swarm optimization principles, and uses a continuously updated mean and variance of best solutions from optimization process. Note: since this is a heuristic algorithm, it does not provide the optimal solution, but near optimal solution. This is however done in a very quick time compared to traditional optimization solvers.

Usage

Initialisation

The MVMO optimizer can be called with arguments iterations, num_mutation, and population_size. This defines key parameters for MVMO.

Defining objective function

MVMO by default optimizes the objective function for minimum. For maximisation, the objective function will need to be modified. The MVMO package provides the following test function benchmarks from Wikipedia:

  1. Rosenbrock
  2. Matyas
  3. Booth
  4. Himm
  5. Easom

Constraint definition

Constraints can be inequality or equality. The constraints are passed as a dictionary object with keywords ineq, eq, or func to symbolise whether the specified constraint is inequality, equality or a function definition. Inequality and equality contraints are specified in str format, and must follow the convention:

g(x) <= 0   #inequality constraint
h(x) = 0    #equality constraint

Complex constraints can also be defined as python functions. An example of how to use the MVMO package for constrained optimization is shown later. It uses all three constraint defintions.

Optimization

The optimize() method can be called on the optimizer to perform optimization. It returns the following upon completion of optimization:

  1. res: Provides best objective function value, and where it was obtained. [obf_value, x]
  2. conv: Provides the list of objective function values over optimization process. This can beused to plot convergence graph.
  3. sol: provides the internal mean and variance of stored solutions that was used for optimization. The size of this matrix is x X num_population.

The convergence graph can be plotted with MVMO.plot(conv).

The following example shows minimization of constrained Rosenbrock function:

from MVMO import MVMO
from MVMO import test_functions
function = test_functions.rosen
optimizer = MVMO(iterations=5000, num_mutation=3, population_size=10)

def func_constr(x):
	return True if x[0]**2 + x[1]**2 < 1 else False

bds = [(-1.5,1.5), (-0.5,2.5)]
constr = {'ineq':"(x[0] - 1)**3 - x[1] + 1",
		  'eq':"x[0]+x[1]-2",
		  'func':func_constr}
res, conv, sol = optimizer.optimize(obj_fun=function, bounds=bds, constraints=constr)

MVMO.plot(conv)

Project details


Release history Release notifications

This version

1.0.3

Download files

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

Files for MVMO, version 1.0.3
Filename, size File type Python version Upload date Hashes
Filename, size MVMO-1.0.3-py3-none-any.whl (5.7 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size MVMO-1.0.3.tar.gz (5.4 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page