Skip to main content

No project description provided

Project description

genepro

DOI

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 ndoes 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.

Installation

To run, genepro relies only on a few libraries to run (numpy, joblib, and scikit-learn). However, additional libraries (e.g., gym) are required to run some examples. 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: 38,	best of gen fitness: -3010.345,	best of gen size: 43
gen: 39,	best of gen fitness: -2998.565,	best of gen size: 43
gen: 40,	best of gen fitness: -2986.394,	best of gen size: 45
The negative mean squared error on the test set is -2757.157 (respective R^2 score is 0.546)
Obtained by the (simplified) model: 
5*x2 + 3*x3 - x6 + 3*x8 + log(abs(x9)) + log(abs(2*x2 + x8 + 1.44)) - 9.266

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},
  doi = {10.5281/zenodo.6335294},
  month = {2},
  title = {{genepro}},
  url = {https://github.com/marcovirgolin/genepro},
  version = {0.0.7},
  year = {2022}
}

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.0.7.tar.gz (26.9 kB view details)

Uploaded Source

Built Distribution

genepro-0.0.7-py3-none-any.whl (27.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: genepro-0.0.7.tar.gz
  • Upload date:
  • Size: 26.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for genepro-0.0.7.tar.gz
Algorithm Hash digest
SHA256 6f2bb87f862cbc959876b937b1784b45f1bf5205e68d17c2d7b91877afffb57e
MD5 4b4771999339bcfc398385d8f990592b
BLAKE2b-256 bb7be489957c809e1a9d2ef1958b690b2537717ea395f20426bedbe840bd8a3a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: genepro-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 27.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for genepro-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 24aeac2ad741fb0578ce012ba47f26daef80f8bf27a066f734f0f81c4fbbe1ab
MD5 3b8a1076c10f919cc10f0de0d983dcf5
BLAKE2b-256 77418ced941cc3497a62008f1cf2f6e0b50ff50a958ce50468499ec982274c51

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