Coder Social home page Coder Social logo

yjcsivsuk / tengp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jarino/tengp

0.0 0.0 0.0 413 KB

Cartesian Genetic Programming with NumPy or PyTorch

Home Page: https://jarino.github.io/tengp/

License: MIT License

Python 98.34% Makefile 1.66%

tengp's Introduction

TenGP - Cartesian Genetic Programming with NumPy (or PyTorch)

Cartesian Genetic Programming (CGP) based on NumPy arrays.

PyTorch tensors can be used instead of NumPy arrays, thanks to their similar APIs, thus enabling utilization of GPUs for transforming data.

Installation

PyPI in progress. For know, installation is available only from git repo:

pip install git+https://github.com/Jarino/tengp

Or clone repo and install using Makefile:

git clone https://github.com/Jarino/tengp
cd tensor-cgp
make install

Quick start

Symbolic regression example on California Housing dataset:

# load data
from sklearn.datasets import fetch_california_housing

dataset = fetch_california_housing()
X_train = dataset.data
y_train = dataset.target

# set-up CGP system
import numpy as np
import tengp

def protected_division(x, y):
    return np.divide(x, y, out=np.copy(x), where=y!=0)

funset = tengp.FunctionSet()
funset.add(np.add, 2)
funset.add(np.subtract, 2)
funset.add(np.multiply, 2)
funset.add(protected_division, 2)
funset.add(np.sin, 1)

params = tengp.Parameters(n_inputs=X_train.shape[1],
                          n_outputs=1,
                          n_columns=100,
                          n_rows=1,
                          function_set=funset)

# cost function
from sklearn.metrics import mean_squared_error

# run evolution
res = tengp.simple_es(X_train,
                      y_train,
                      mean_squared_error,
                      params,
                      random_state=42,
                      mutation='probabilistic',
                      verbose=100)

# print fitness and phenotype of best individual
print(res[0].fitness)
print(res[0].get_expression())

Features

Simple $(1+n)$ evolution strategy using:

  • point mutation
  • single mutation
  • active mutation
  • probabilistic mutation

Development

Install for development purposes:

make develop

which runs the python setup.py develop command.

If not installed, install pytest (pip install pytest), then:

make test

To build documentation:

make html

tengp's People

Contributors

jarino avatar michalselicky avatar yjcsivsuk avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.