Skip to content

Instantly share code, notes, and snippets.

View cmd-ntrf's full-sized avatar

Félix-Antoine Fortin cmd-ntrf

View GitHub Profile
@cmd-ntrf
cmd-ntrf / gist:1988770
Created March 6, 2012 20:25
varOr + numpy multinomial
def varOr(toolbox, population, lambda_, cxpb, mutpb):
assert (cxpb + mutpb) <= 1.0, ("The sum of the crossover and mutation "
"probabilities must be smaller or equal to 1.0.")
ncx, nmut, nrep = numpy.random.multinomial(lambda_, (cxpb, mutpb, 1-cxpb-mutpb))
offcx = map(toolbox.clone, tools.selRandom(population, 2*ncx))
offmut = map(toolbox.clone, tools.selRandom(population, nmut))
offrep = map(toolbox.clone, tools.selRandom(population, nrep))
for ind1, ind2 in offcx:
@cmd-ntrf
cmd-ntrf / gist:1989214
Created March 6, 2012 22:01
algorithm eaGenerateUpdate
def eaGenerateUpdate(toolbox, ngen, halloffame=None, stats=None, verbose=True):
"""The CMA-ES algorithm as described in Hansen, N. (2006). *The CMA
Evolution Strategy: A Comparing Rewiew.*
:param toolbox: A :class:`~deap.base.Toolbox` that contains the evolution
operators.
:param ngen: The number of generation.
:param stats: A :class:`~deap.tools.Statistics` object that is updated
inplace, optional.
:param halloffame: A :class:`~deap.tools.HallOfFame` object that will
@cmd-ntrf
cmd-ntrf / gist:1989231
Created March 6, 2012 22:02
CMA Strategy inheriting from base.Toolbox
class Strategy(base.Toolbox):
"""
A strategy that will keep track of the basic parameters of the CMA-ES
algorithm.
:param centroid: An iterable object that indicates where to start the
evolution.
:param sigma: The list of initial standard deviations of the distribution,
it shall be the same length than the centroid.
:param parameter: One or more parameter to pass to the strategy as
@cmd-ntrf
cmd-ntrf / gist:1989254
Created March 6, 2012 22:03
CMA-ES generate update example
import numpy
from deap import algorithms
from deap import base
from deap import benchmarks
from deap import cma
from deap import creator
from deap import tools
# Problem size
@cmd-ntrf
cmd-ntrf / deap_ga_onemax_multidemic_distributed.py
Created March 25, 2012 18:30 — forked from anonymous/deap_ga_onemax_multidemic_distributed.py
A simple example of multidemes distribution using DEAP
# 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
@cmd-ntrf
cmd-ntrf / mutation_success_rate.py
Created May 31, 2012 15:43
GA OneMax with only mutation and a computation of the mutation success rate.
# 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
@cmd-ntrf
cmd-ntrf / gp2.py
Created June 8, 2012 22:34
New experimental way to handle trees in deap
import gp
import random
__type__ = None
class PrimitiveTree(list):
def __init__(self, content):
self[:] = content
@property
@cmd-ntrf
cmd-ntrf / gp_adf_spambase.py
Created November 28, 2012 01:25
DEAP GP Spambase example + ADF.
# 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
@cmd-ntrf
cmd-ntrf / onemax_mutadapt.py
Created December 15, 2012 22:05
Mutation rate adaptation and loggin of hall-of-fame best with onemax problem.
# 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
@cmd-ntrf
cmd-ntrf / cython_instance_scoop.py
Last active December 14, 2015 01:38
Example of the distribution of an instance method from a Cython class object with SCOOP. It uses the Benchmark class defined by pycec2013 available here : https://bitbucket.org/CmdNtrf/niching-benchmark-cec2013
import array
import pycec2013
from scoop import futures
if __name__ == "__main__":
bench = pycec2013.Benchmark(1)
pop = [array.array('d', [1.0]), array.array('d', [2.0]), array.array('d', [3.0])]
print(list(futures.map(bench.evaluate, pop)))
# print(list(map(bench.evaluate, pop)))