A particle swarm optimizer for discrete optimization
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!
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")
Officially Python 3.6 and above
PSOpt can be installed via pip from PyPI
pip install psopt
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]
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