Genetist: optimization with genetic algorithms
Project description
Genetist: A genetic algorithm powered hyperparameter optimization framework
Genetist is a high level framework that helps optimizing functions using the power of genetic algorithms.
1. Installation
Genetist is available at PyPI
$ pip install genetist
2. Quickstart
2.1. Define Search Space
2.1.1. Fixed Search Space
#defining a fixed set of params for 4 variables
params = {
'x': [35, -51, 0, 1, 2, 3, 4, 66, 11, 50, 90],
'y': [-100, -51, 0, 7, 32, 31, 4, 51, 121, 50, 90, 1000, 231]
'z': [-10, -51, 0, 12, 2, 43, 43, 5, 1231, 50, 90],
'k': [-56, -51, 0, 1, 2, 13, 4, 5, 11, 50, 90]
}
2.1.2. Flexible Search Space
from genetist.params import Params
#defining a 4 variable search space of float values from -100.0 to 100.0
params = {
'x': Params.suggest_float(-100, 100),
'y': Params.suggest_float(-100, 100),
'z': Params.suggest_float(-100, 100),
'k': Params.suggest_float(-100, 100)
}
2.2. Define Objective Function
#defining an objective function
def objective(individual):
x = individual['x']
y = individual['y']
z = individual['z']
k = individual['k']
return (x**2 - 4*y**3 / z**4) * k**3
2.3. Start Optimization
from genetist.environment import Environment
if __name__ == '__main__':
#defining our Environment instance with a population of 100 individuals,
#one-point crossover and a single gene mutation with a 25% probability of mutation
environment = Environment(
params=params,
num_population=100,
crossover_type='one-point',
mutation_type='single-gene',
prob_mutation=0.25,
verbose=1
)
#minimizing the objective function and adding 3 stop criterias (num_generations, timeout, stop_score)
results = environment.optimize(objective=objective, direction='minimize', num_generations=9999, timeout=60, stop_score=-np.inf)
2.4. Show Optimization Results
print()
print(f'EXECUTION TIME={results.execution_time}')
print(f'BEST SCORE={results.best_score}')
print(f'BEST INDIVIDUAL={results.best_individual}')
print('BEST PER GENERATION:')
print(results.best_per_generation_dataframe)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
genetist-0.9.10.tar.gz
(9.2 kB
view hashes)
Built Distribution
Close
Hashes for genetist-0.9.10-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 56600109c114aa86a05f1fc99f0cf2dbdd546bcce55b22dcfaeb2046e0ccbfc6 |
|
MD5 | b294e4b388ecc35bc7e180248831ac10 |
|
BLAKE2b-256 | bc7ed63ba048ff3e2c00e7b6cf621788fbb93e99507da4b00297a5b413b030ee |