Skip to content

Instantly share code, notes, and snippets.

@DMTSource
DMTSource / deap_node_plot.py
Last active June 1, 2021 15:44
Deap Pretty Node Plot Example Code Example (Need to bring your own deap Individuals in)
# Derek M. Tishler
# nx plot example deap individual
# For post: https://groups.google.com/g/deap-users/c/nZFZpm5OPZA
import matplotlib.pyplot as plt
import networkx as nx
from networkx.drawing.nx_agraph import graphviz_layout
## May need is resuming session
#from deap import creator
@DMTSource
DMTSource / baikal_readme_long_gridsearchcv_example.py
Last active March 24, 2021 21:33
Modified version of the readme_long_example from baikal. Attempting to make it work for multiple inputs: https://github.com/alegonz/baikal/issues/50
import sklearn.decomposition
import sklearn.ensemble
import sklearn.linear_model
import sklearn.preprocessing
import sklearn.svm
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
from baikal import Input, Model, make_step
from baikal.plot import plot_model
@DMTSource
DMTSource / deap_heuristic_random_hybrid_init.py
Created January 16, 2021 21:11
Deap python example showing how population lists can be combined for use with hybrid initialization methods such as heuristic + random.
import array
import random
import numpy
from deap import algorithms
from deap import base
from deap import creator
from deap import tools
@DMTSource
DMTSource / normalized_individual_deap_example.py
Created December 12, 2020 02:16
Example of a Deap GA problem, working with normalized individuals only
# Based on https://raw.githubusercontent.com/DEAP/deap/master/examples/ga/onemax_mp.py
# Using onemax(ignore the problem sorta) to show how to work with only normalized individuals
# Can Uses numpy individuals but no multiproc: https://deap.readthedocs.io/en/master/examples/ga_onemax_numpy.html
# Derek M Tishler, Dec 2020
import multiprocessing
import random
import sys
@DMTSource
DMTSource / hypervol_man_dim_test.py
Last active November 26, 2020 05:11
Deap Hypervolume comparison for varying population size and number of objectives, testing for use with high dimensional NSGA III with many objectives (over 8).) Discussion here: https://groups.google.com/g/deap-users/c/XLfLa3at6pw
# Derek Tishler
# Deap Hypervolume comparison for varying population size and number of objectives,
# testing for use with high dimensional NSGA III with many objectives (over 8).)
# Discussion here, also required fitness_values.txt with 212x14 array of fitness values per ind in pop:
# https://groups.google.com/g/deap-users/c/XLfLa3at6pw
import numpy as np
@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]]
'''
@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
# 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 / 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
@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