🧬 Lexicase Selection Library
A fast, vectorized lexicase selection implementation supporting both NumPy and JAX backends.
🎯 What it does
Lexicase selection is a parent selection method used in evolutionary computation that evaluates individuals on test cases in random order, keeping only those that perform best on each case. This library provides efficient implementations of several lexicase variants:
- Base Lexicase: Standard lexicase selection algorithm
- Epsilon Lexicase: Allows individuals within epsilon of the best to be considered equally good
- Downsampled Lexicase: Uses random subsets of test cases to increase diversity
TODOs:
- Add some demo notebooks
- Add informed down-sampling
- Add MAD calculation for automatic epsilon selection
📦 Installation
NumPy Backend
pip install .[numpy]
JAX Backend
pip install .[jax]
Development Installation
pip install .[dev] # Includes pytest and coverage tools
🚀 Quick Start
import numpy as np
import lexicase
# Create a fitness matrix (individuals × test cases)
# Higher values = better performance
fitness_matrix = np.array([
[10, 5, 8], # Individual 0
[8, 9, 6], # Individual 1
[6, 7, 9], # Individual 2
[4, 3, 7] # Individual 3
])
# Select 5 individuals using standard lexicase
selected = lexicase.lexicase_selection(
fitness_matrix,
num_selected=5,
seed=42
)
print(f"Selected individuals: {selected}")
# Use epsilon lexicase for more diversity
selected_eps = lexicase.epsilon_lexicase_selection(
fitness_matrix,
num_selected=5,
epsilon=1.0,
seed=42
)
print(f"Epsilon lexicase selected: {selected_eps}")
🔧 Backend Selection
Switch between NumPy and JAX backends:
import lexicase
# Use NumPy backend (default)
lexicase.set_backend("numpy")
# Use JAX backend for GPU acceleration
lexicase.set_backend("jax")
# Check current backend
print(f"Current backend: {lexicase.get_backend()}")
📊 All Selection Methods
Standard Lexicase
selected = lexicase.lexicase_selection(fitness_matrix, num_selected=10, seed=42)
Epsilon Lexicase
selected = lexicase.epsilon_lexicase_selection(
fitness_matrix,
num_selected=10,
epsilon=0.5, # Tolerance for "equal" performance
seed=42
)
Downsampled Lexicase
selected = lexicase.downsample_lexicase_selection(
fitness_matrix,
num_selected=10,
downsample_size=5, # Use only 5 random test cases per selection
seed=42
)
🧪 Testing
Run the test suite:
pytest tests/
Run with coverage:
pytest tests/ --cov=lexicase --cov-report=html
🔬 Algorithm Details
Lexicase Selection Process:
- Shuffle the order of test cases
- Start with all individuals as candidates
- For each test case (in shuffled order):
- Find the best performance on this case
- Keep only individuals matching the best performance
- If only one individual remains, select it
- If multiple individuals remain after all cases, select randomly
Epsilon Lexicase: Considers individuals within epsilon of the best performance as equally good.
Downsampled Lexicase: Uses only a random subset of test cases, increasing selection diversity.
📈 Performance Tips
- Use JAX backend for large matrices and GPU acceleration
- Downsampled variants are faster and often more diverse
- Set appropriate epsilon values (typically 0.1-1.0 of fitness range)
- Use seeds for reproducible results
📚 Citation
If you use this library in your research, please cite:
@software{lexicase_selection,
title={Lexicase Selection Library},
author={Ryan Bahlous-Boldi},
year={2024},
url={https://github.com/ryanboldi/lexicase}
}
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
🔗 References
- Spector, L. (2012). Assessment of problem modality by differential performance of lexicase selection in genetic programming. GECCO.
- La Cava, W., et al. (2019). Epsilon-lexicase selection for regression. GECCO.
- Hernandez, J. G., et al. (2019). Random subsampling improves performance in lexicase selection. GECCO.
Metadata
Release files for lexicase 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| lexicase-0.1.0.tar.gz | 9.0 kB | Without provenance | Details for lexicase-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lexicase-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for lexicase-0.1.0-py3-none-any.whl |
Total release size: 18.6 kB
Release files / lexicase-0.1.0.tar.gz
| Download URL | lexicase-0.1.0.tar.gz |
|---|---|
| Size | 9.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
145ab444e3a1c96e57c82297f10f3f52d8d7f8b4866dff929e8cfc3f725a68c4
|
|
BLAKE2b-256 checksum How to use checksums |
f708f4ce8f82641a2470177757220765ed22580e542f6ac8ccf3a37ae0e479bc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.2
|
Release files / lexicase-0.1.0-py3-none-any.whl
| Download URL | lexicase-0.1.0-py3-none-any.whl |
|---|---|
| Size | 9.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
caab4e44b82178ee05dfa740535d4662aab9ae02d41be4a045a4d9da70e00d87
|
|
BLAKE2b-256 checksum How to use checksums |
cfdc1c5a50e0a00620f8896ddfadc3e0419e34b6a3f6acf3c3e50fae4358c08f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.2
|
Security for lexicase 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.