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.
Installation
MVMO can be installed from PyPI using:
pip install MVMO
MVMO requires numpy and pandas to work.
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. Objective functions can be defined by the user as per requirement. This is shown in examples. The MVMO package provides the following test function benchmarks from Wikipedia:
- Rosenbrock
- Matyas
- Booth
- Himm
- 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.
Binary and Integer variables
MVMO also provides the ablity to define binary and integer variables in optimization decision easily. This can be done by specifying the index of the variables with binary or integer keyword in the optimize function. This is shown in the example later.
Optimization
The optimize() method can be called on the optimizer to perform optimization. It returns a res dictioanry object upon the completion of optimization. This contains:
objective: Provides best objective function value, and where it was obtained.x: The optimized decision vectorconvergence: Provides the list of objective function values over optimization process. This can beused to plot convergence graph.register: A pandas dataframe of the size ofpopulation_sizewhich contains best saved objective function values andXvectors.metrics: Provides the internal mean and variance of stored solutions that was used for optimization.scaling_factors" provides a list of scaling factors used over the iterations.
The convergence graph can be plotted with MVMO.plot(res['convergence']).
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=1, population_size=10)
def func_constr(X):
return True if X[0]**2 + X[1]**2 < 1 else False
bds = [(0,1.5), (1,3.5)]
constr = {'ineq':"(X[0] - 1)**3 - X[1] + 1",
'eq':"X[0]+X[1]-2",
'func':func_constr}
res = optimizer.optimize(obj_fun=function, bounds=bds, constraints=constr, binary=[0], integer=[1])
print(res['x')
MVMO.plot(res['convergence'])
Metadata
Release files for MVMO 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| MVMO-1.1.0.tar.gz | 5.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| MVMO-1.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.9 kB
Release files / MVMO-1.1.0.tar.gz
| Download URL | MVMO-1.1.0.tar.gz |
|---|---|
| Size | 5.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6cbaeb532bf9b98d752e8bb5d8f06b2e3e26bffe4b2ecb60f1360427a8b23d02
|
|
BLAKE2b-256 checksum How to use checksums |
2beeb4bee427d156e8f6062a6a0b33a1a2891d29dad4940868d711c02e482e5b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4
|
Release files / MVMO-1.1.0-py3-none-any.whl
| Download URL | MVMO-1.1.0-py3-none-any.whl |
|---|---|
| Size | 7.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b33ed9592549716029989e1456d4827de263c7966996bcf3348bcd761b6313b9
|
|
BLAKE2b-256 checksum How to use checksums |
02b4839e750b490fb5aeb06e7201ec883bc8a4f4134afa5442e859c488823a0d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4
|
Security for MVMO 1.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.