Skip to content

Instantly share code, notes, and snippets.

@DMTSource
DMTSource / deap_multi_objective_pyplot_example.py
Last active January 6, 2021 13:58
DEAP multi objective plotting example
# Example of multi objective plotting in Deap
# Derek M Tishler - 2018
import numpy as np
import matplotlib.pyplot as plt
plt.rc('xtick', labelsize=8)
plt.rc('ytick', labelsize=8)
@DMTSource
DMTSource / deap_ga_array_constrained.py
Last active January 21, 2020 10:36
GA example of an array of constrained value items with crossover and mutation, from question https://groups.google.com/forum/#!topic/deap-users/bu3v9Ozez8E
# GA example of an array of constrained value items with crossover and mutation,
# from question https://groups.google.com/forum/#!topic/deap-users/bu3v9Ozez8E
# Derek M Tishler - 2019
# Started with example and modified to keep as simple as possible:
# https://raw.githubusercontent.com/DEAP/deap/454b4f65a9c944ea2c90b38a75d384cddf524220/examples/ga/onemax_np.py
import random
@DMTSource
DMTSource / deap_diversity_plot.py
Last active December 7, 2019 18:08
Example on how to extract and plot fitness diversity for a population, hall of fame, or frontier using histogram and probability curves. From question https://groups.google.com/forum/#!topic/deap-users/Y8JX4AKwzhk
# Examples on how to extract and plot fitness diversity for a population, hall of fame, or
# frontier using histogram and probability curves. Mostly working with multi objective fitness as per
# question from https://groups.google.com/forum/#!topic/deap-users/Y8JX4AKwzhk
# Derek M Tishler - 2019
import array
import random
@DMTSource
DMTSource / deap_ray_np_symbreg.py
Last active April 19, 2023 10:00
Example of deap symbreg(GP) via Ray for cluster and local machine scaling with efficient memory objects
# This file is part of EAP.
#
# EAP is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
#
# EAP is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ITS GONE!
I generalized the code and created examples for use in GA and GP:
https://github.com/DMTSource/deap_ray
@DMTSource
DMTSource / history_pop_eample_onemax_base.py
Last active July 24, 2020 09:33
Examples of Deap History applied to onemax and Symbreg examples. See: https://deap.readthedocs.io/en/master/api/tools.html#deap.tools.History
# This file is part of DEAP.
#
# DEAP is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
#
# DEAP is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@DMTSource
DMTSource / one_max_short_large_init_and_dataframes.py
Last active August 3, 2020 04:42
Example of onemax_short.py, but this includes a large init pop with selection before starting the evolution via local eaSimple for mutability going forward. At end we mess with dataframes and select via log to give options for analysis.
# Derek Tishler
# Aug 3 2020
# Based On:
# https://github.com/DEAP/deap/blob/master/examples/ga/onemax_short.py
# V2
import array
import random
import numpy as np
# Derek Tishler, answering a question from Deap Discussions:
# For Ning's question: https://groups.google.com/forum/#!topic/deap-users/W8wacFPyj9Y
# Based on symbreg example: https://github.com/DEAP/deap/blob/master/examples/gp/symbreg.py
# eaSimpleWithElitism from: https://github.com/PacktPublishing/Hands-On-Genetic-Algorithms-with-Python/blob/master/Chapter04/elitism.py
import operator
import math
@DMTSource
DMTSource / onemax_numpy_selTournamentDCD.py
Created October 19, 2020 01:56
Example of using selTournamentDCD requireing assignCrowdingDist in Deap,based on Onemax Numpy example.
# Example of using selTournamentDCD requiring assignCrowdingDist
# Based on deap/examples/ga/onemax_numpy.py
# https://github.com/DEAP/deap/blob/master/examples/ga/onemax_numpy.py
# Discussion:
# https://groups.google.com/forum/#!topic/deap-users/uU382eztuts
import random
@DMTSource
DMTSource / deap_complex_individual_mlp_example.py
Created October 29, 2020 15:10
Deap example of working with multi section individual, in this case a MLP neural network configuration for sklearn.
# Example of creating an individual with multiple 'parts'
# Derek M Tishler, Oct 2020
'''
Evolve a complex structure/individual, such as encoded hyperparamters of a mlp classifier
individual_example = [encoded_solver__int, learning_rate__float, hidden_units__list]
example of a 10 layer network using adam solver with learning rate ~0.007:
[0, 0.006592, [13, 89, 21, 100, 96, 100, 16, 67, 45, 88]]
'''