A high-performance genetic algorithm library implemented in Rust with Python bindings
Project description
GeneAlgoLib
A blazingly fast genetic algorithm library implemented in Rust with Python bindings via PyO3.
Features
- High Performance: Rust implementation provides significant speedup over pure Python/NumPy implementations
- Simple API: Easy-to-use Python interface
- Tournament Selection: Efficient selection mechanism with configurable tournament size
- Elitism: Preserves best individuals across generations
- Configurable: Adjustable population size, mutation rate, and gene count
Installation
pip install genealgolib
Quick Start
import numpy as np
from fast_ga import GeneticAlgorithm
# Initialize GA
ga = GeneticAlgorithm(
pop_size=1000, # Population size
num_genes=10, # Number of genes per individual
mutation_rate=0.05 # Mutation probability
)
# Evolution loop
for generation in range(100):
# Get current population
population = ga.get_population()
# Calculate fitness scores (example: sum to 10.0)
sums = np.sum(population, axis=1)
fitness_scores = 1.0 / (np.abs(10.0 - sums) + 1e-6)
# Evolve to next generation
ga.evolve(fitness_scores)
# Get final population
final_pop = ga.get_population()
Performance
GeneAlgoLib significantly outperforms highly optimized NumPy implementations:
- Average Speedup: 2-5x faster than vectorized NumPy
- Scales Well: Better performance with larger populations
- Memory Efficient: Optimized memory usage in Rust
API Reference
GeneticAlgorithm(pop_size, num_genes, mutation_rate)
Initialize a genetic algorithm instance.
Parameters:
pop_size(int): Number of individuals in the populationnum_genes(int): Number of genes per individualmutation_rate(float): Probability of mutation (0.0 to 1.0)
get_population()
Returns the current population as a NumPy array of shape (pop_size, num_genes).
evolve(fitness_scores)
Evolve the population to the next generation.
Parameters:
fitness_scores(np.ndarray): 1D array of fitness scores for each individual
License
MIT License
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file genealgolib-0.1.0.tar.gz.
File metadata
- Download URL: genealgolib-0.1.0.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6108fe5cce4bcd119d23ef2dbbcf3a8794c3328f00c528495d7f92dd0d30f37d
|
|
| MD5 |
b2b0bad26a3cdd8a57f83e3efe8cd5a5
|
|
| BLAKE2b-256 |
6e6267421930dd4acaa3d855667e034eedbdd31d89cca69462affffb628d74cb
|
File details
Details for the file genealgolib-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: genealgolib-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 261.5 kB
- Tags: CPython 3.12, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8973348d9eab298b50d40a3dd1d2d1600c46732e4d0d36edbdb3c4002570c9de
|
|
| MD5 |
a19e357429c2f43e75131f99dda4f8c3
|
|
| BLAKE2b-256 |
dabdbb3df3ff6a6d4aadfaac49d824f5470f6ca9a0a7868a9c8a689a4b677ae4
|