Skip to content

Python-based multi-gene genetic program designed to manipulate and analyze complex data.

License

Notifications You must be signed in to change notification settings

cjcameron92/CCGP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CCGP

Paper Build Status Discord GitHub Sponsors

Python-based multi-gene genetic program designed to manipulate and analyze complex data.

Table of Contents

Quickstart

Install python library

pip install ccgp

Setup Enviorment

from ccgp import runGP
from sklearn.linear_model import LinearRegression
import numpy as np

random.seed(7246325)
pop_size = 300
num_genes = 4
terminals = ['x']
minInitDepth = 2
maxInitDepth = 5
max_global_depth = 8
max_crossover_growth = 3
max_mutation_growth = 3
mutation_rate = 0.2
crossover_rate = 0.9
num_generations = 50
elitism_size = 1
fitnessType = "Minimize"

ops = {
    'add': add,
    'sub': operator.sub,
    'mul': operator.mul,
    'div': protected_division,
    'sin': math.sin,
    'cos': math.cos,
    'tan': math.tan,
}

arity = {
    'add': 2,
    'sub': 2,
    'mul': 2,
    'div': 2,
    'sin': 1,
    'cos': 1,
    'tan': 1,
}

def multi_gene_fitness(individual, ops, data_points):
    X = np.array([[gene.evaluate(data, ops) for gene in individual] for data in data_points])
    y = np.array([data['actual'] for data in data_points])

    model = LinearRegression()
    model.fit(X, y)

    predictions = model.predict(X)

    mse = np.mean((predictions - y) ** 2)

    return mse, model

seed = 1
paramTuple = (seed, pop_size, num_genes, terminals, arity, ops, multi_gene_fitness,
    minInitDepth, maxInitDepth, max_global_depth, mutation_rate, max_mutation_growth,
    elitism_size, crossover_rate,  max_crossover_growth, num_generations, data_points, fitnessType)

def call_main(args):
    return runGP(*args)        

call_main(paramTuple)

Contributors

About

Python-based multi-gene genetic program designed to manipulate and analyze complex data.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages