https://github.com/subatiq/genetica
Minimalistic optimization library based on genetic algorithms. Available via pip.
https://github.com/subatiq/genetica
genetic-algorithm-library optimization optimization-algorithms pip pypi
Last synced: 5 months ago
JSON representation
Minimalistic optimization library based on genetic algorithms. Available via pip.
- Host: GitHub
- URL: https://github.com/subatiq/genetica
- Owner: subatiq
- License: mit
- Created: 2018-11-29T12:23:40.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-07-27T09:34:14.000Z (almost 6 years ago)
- Last Synced: 2025-09-25T11:48:09.399Z (9 months ago)
- Topics: genetic-algorithm-library, optimization, optimization-algorithms, pip, pypi
- Language: Python
- Homepage:
- Size: 28.3 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Genetica
## About
**Genetica** is the minimalistic genetic algorithm library for optimizing class parameters.
This library allows you to take any class with certain business logic, modify it a little and then give it back to Genetica to optimize.
Right now Genetica is a *minimalistic* library. It lacks some of the fancy aspects of genetic algorithms. Nevertheless, the library was created to optimize some aerospace designs for the author's graduation project.
Now you can enjoy the core idea of genetic optimization without much pain of getting into it:
- Turning class parameters into manipulatable genes
- Population generation (any size)
- Crossbreeding with mutations
- Learning process chart (not real-time)
- Real-time learning feedback
- Getting the best and worst species' parameters
## Installation
Genetica is supported by Pyhton 3.x
Install it through pip:
pip install genetica
## Quick start
### Imports
```python
from genetica.model import Genetica
from genetica.dna import genify
```
### Class structure
```python
class ExampleModel:
def __init__(self, dna):
self.dna = dna
# Class parameters that are inputs for optimization
self.a1 = genify(range(1,1890), dna.genes[0])
self.a2 = genify(range(1,2017), dna.genes[1])
# | enum of | just get a
# possible certain gen
# params | to randomize
# | | this parameter|
# | | | |
#self.a2 = genify( range(1,2017), dna.genes[1] )
# Target parameter to optimize
self.result = self.fitness()
def fitness(self):
return self.a1 ** self.a1 + self.a1 * self.a2 + self.a2
```
### Running optimization
```python
model = Genetica(ExampleModel, 2, 1000, lambda x: x.result)
model.run()
```
### Getting results
```python
print("BEST FIT:", model.get_best_fit())
print("PARAMS OF BEST FIT:", model.get_best_specie().a1, model.get_best_specie().a2)
# Getting populations history of best results for each epoch
model.plot()
```