GeneticPy is an optimizer that uses a genetic algorithm to quickly search through custom parameter spaces for optimal solutions.
GeneticPy requires Python 3.10+
pip install geneticpyThis project uses uv for fast dependency management and hatchling as the build backend.
# Run tests
make test
# Build the package
make buildA brief example to get you started is included below:
import geneticpy
def loss_function(params):
if params['type'] == 'add':
return params['x'] + params['y']
elif params['type'] == 'multiply':
return params['x'] * params['y']
param_space = {'type': geneticpy.ChoiceDistribution(choice_list=['add', 'multiply']),
'x': geneticpy.UniformDistribution(low=5, high=10, q=1),
'y': geneticpy.GaussianDistribution(mean=0, standard_deviation=1)}
results = geneticpy.optimize(loss_function, param_space, size=200, generation_count=500, verbose=True)
best_params = results.best_params
loss = results.best_score
total_time = results.total_timehttps://pypi.org/project/geneticpy/
Please feel free to email me at [email protected] with any questions or feedback.