Release v.0.1.6
Release notes
- NEW: Hyperparameter search tools - #20, #25, #28
- IMPROVED: Updated structure of Base classes for higher extensibility
- IMPROVED: More robust tests for
PlotEnvironment
Hyperparameter Search Tools
PySwarms now implements a native version of GridSearch
and RandomSearch
to help you find the best hyperparameters in your swarm. To use this feature, simply call the RandomSearch
and GridSearch
classes from the pyswarms.utils.search
module.
import numpy as np
import pyswarms as ps
from pyswarms.utils.search import RandomSearch
from pyswarms.utils.functions import single_obj as fx
# Set-up choices for the parameters
options = {
'c1': (1,5),
'c2': (6,10),
'w': (2,5),
'k': (11, 15),
'p': 1
}
# Create a RandomSearch object
# n_selection_iters is the number of iterations to run the searcher
# iters is the number of iterations to run the optimizer
g = RandomSearch(ps.single.LocalBestPSO, n_particles=40,
dimensions=20, options=options, objective_func=fx.sphere_func,
iters=10, n_selection_iters=100)
best_score, best_options = g.search()
This then returns the best score found during optimization and the hyperparameter options that enabled it.
>>> best_score
1.41978545901
>>> best_options['c1']
1.543556887693
>>> best_options['c2']
9.504769054771
Improved Library API
Most of the swarm classes now inherit the base class in order to demonstrate its extensibility. If you are a developer or a swarm researcher planning to implement your own algorithms, simply inherit from these Base Classes and implement the optimize()
method.