Skip to main content

No project description provided

Project description

genepro

art of a juniper, 'ginepro' in Italian
Art of a juniper, "ginepro" in Italian, made with the genetic drawing repo by @anopara.

In brief

genepro is a Python library providing a baseline implementation of genetic programming, an evolutionary algorithm specialized to evolve programs. This library includes a classifier and regressor that are compatible with scitik-learn (see examples of usage below).

Evolving programs are represented as trees. The leaf nodes (also called terminals) of such trees represent some form of input, e.g., a feature for classification or regression, or a type of environmental observation for reinforcement learning. The internal nodes represent possible atomic instructions, e.g., summation, subtraction, multiplication, division, but also if-then-else or similar programming constructs.

Genetic programming operates on a population of trees, typically initialized at random. Every iteration (called generation), promising trees undergo random modifications (e.g., forms of crossover, mutation, and tuning) that result in a population of offspring trees. This new population is then used for the next generation.

animation of genepro finding a symbolic regression solution
Example of 1D symbolic regression (made with this gist)

Installation

For classification or regression, genepro relies only on a few libraries (numpy, joblib, and scikit-learn). However, additional libraries (e.g., gym) are required to run the reinforcement learning example. Thus, you can choose to perform a minimal or full installation.

Minimal installation

To perform a minimal installation, run:

pip install genepro

Full installation

For a full installation, clone this repo locally, and make use of the file requirements.txt, as follows:

git clone https://github.com/marcovirgolin/genepro
cd genepro
pip install -r requirements.txt .

Wish to use conda?

A conda virtual enviroment can easily be set up with:

git clone https://github.com/marcovirgolin/genepro
cd genepro
conda env create
conda activate genepro
pip install .

Examples of usage

Classification and regression

The notebook classification and regression.ipynb shows how to use genepro for classification and regression, via scikit-learn estimators.

These estimators are intended for data sets with a small number of (relevant) features, as the evolved program can be written as a compact (and potentially interpretable) symbolic expression.

...
gen: 39,	best of gen fitness: -2952.999,	best of gen size: 46
gen: 40,	best of gen fitness: -2950.453,	best of gen size: 44
The mean squared error on the test set is 2964.646 (respective R^2 score is 0.512)
Obtained by the (simplified) model: 146.527 + -5.797*(-x_2**2 - 4*x_2 - 3*x_3 + 2*x_4 - x_5 - x_6*(x_4 - x_5) + x_6 - 5*x_8)

Example of output of a symbolic regression model discovered for the Diabetes data set.

Reinforcement learning

The notebook gym.ipynb shows how genepro can be used to evolve a controller for the CartPole-v1 environment of the OpenAI gym library.

animation displaying a random cart pole controller
Left: random cart pole controller; Right: evolved symbolic cart pole controller:

(x2 + x3) * (x2*x3 + x3 + x4 + 1) * log(abs(x2))^2 * log(abs(x3))^2 < 0.5? 'left' else 'right'

Citation

If you use this software, please cite it with:

@software{Virgolin_genepro_2022,
  author = {Virgolin, Marco},
  month = {9},
  title = {{genepro}},
  url = {https://github.com/marcovirgolin/genepro},
  version = {0.1.1},
  year = {2024}
}

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

genepro-0.1.1.tar.gz (28.0 kB view details)

Uploaded Source

Built Distribution

genepro-0.1.1-py3-none-any.whl (28.3 kB view details)

Uploaded Python 3

File details

Details for the file genepro-0.1.1.tar.gz.

File metadata

  • Download URL: genepro-0.1.1.tar.gz
  • Upload date:
  • Size: 28.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.5

File hashes

Hashes for genepro-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e6b203a1143d3cb0e62dcc2fa5e5f2e9f0e4d64f0951aefd73f5b2dc30508162
MD5 967a62e54c7e9c378cfd7b76f025d092
BLAKE2b-256 0ee3d906fc0a6217c79046977fe198656b0acecf205fdca9b2ebd3d89d66e394

See more details on using hashes here.

File details

Details for the file genepro-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: genepro-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 28.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.5

File hashes

Hashes for genepro-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8193601c49f6b990a6c0286e1116ae9f31113207f52e14894cbc6bd74ef535f6
MD5 22031f6f2abc4208444c8312d8ab17ef
BLAKE2b-256 8e879ff4c807f60c5f5de80079f4baccba38c81448da8205e5d7cd6135ff444a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page