Skip to content

artur-deluca/psopt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

93 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Documentation Status codecov Maintainability Codacy Badge DOI

A particle swarm optimizer for discrete optimization

Project Information

psopt is released under the MIT, its documentation lives at Read the Docs, the code on GitHub, and the latest release on PyPI.

If you'd like to contribute to psopt you're most welcome. We've created a little guide to get you started!

How to use

from psopt import Permutation

# define an objective function to optimize
def obj_func(x):
    return sum([a / (i + 1) for i, a in enumerate(x)])

# list of possible candidates
candidates = list(range(1, 11))

# instantiate the optimizer
opt = Permutation(obj_func, candidates, metrics="l2")

# minimize the obj function
result = opt.minimize(selection_size=5, verbose=1, threshold=5, population=20)

# visualize the progress
result.history.plot("l2")
result.history.plot("global_best")

Installation

Python version support

Officially Python 3.6 and above

Installing from PyPI

PSOpt can be installed via pip from PyPI

pip install psopt

Installing from source

Clone the repository via:

git clone https://github.com/artur-deluca/psopt/ --depth=1

Activate your virtual environment and run:

python setup.py install
# or alternatively
pip install -e .

If you wish to install the development dependencies, run:

python setup.py build
# or alternatively
pip install -e.[all]

Running the test suite

To run the tests written for psopt, make sure you have pytest installed in your venv. Additionally, if you wish to run coverage analysis as well, make sure to have pytest-cov installed as well.

# to simply execute the tests run:
pytest
# to run coverage as well run:
pytest --cov=psopt
# or alternatively:
make test