This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class countCalls(object): | |
"""Decorator that keeps track of the number of times a function is called. | |
:: | |
>>> @countCalls | |
... def foo(): | |
... return "spam" | |
... | |
>>> for _ in range(10) | |
... foo() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
from deap import algorithms, base, creator, tools | |
import sortingnetwork as sn | |
INIT_SIZE, INPUTS, MAXGEN = 40, 12, 250 | |
H_CXPB, H_MUTPB = 0.5, 0.3 | |
P_CXPB, PMUT_PB = 0.5, 0.3 | |
def evalNetwork(host, parasite, dimension): | |
network = sn.SortingNetwork(dimension, host) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from scoop.futures import map | |
def root(): | |
for _ in range(100): | |
r = list(map(node, [range(1000)] * 100)) | |
def node(data): | |
for _ in range(5): | |
r1 = sum(map(leaf, [range(1000)] * 10)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try: | |
import numpy | |
except ImportError: | |
import platform | |
if platform.python_implementation() == "PyPy": | |
import numpypy as numpy | |
else: | |
raise ImportError("DEAP requires Numpy.") | |
from collections import OrderedDict |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ghalton | |
import random | |
import json | |
from deap import base | |
from deap import creator | |
from deap import tools | |
creator.create("FitnessMax", base.Fitness, weights=(1.0,)) | |
creator.create("Individual", list, fitness=creator.FitnessMax) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from operator import attrgetter | |
logbook = tools.Logbook() | |
logbook.header = ['gen', 'nevals'] + (stats.fields if stats else []) | |
for gen in xrange(ngen): | |
# Generate a new population | |
population = toolbox.generate() | |
# Evaluate the individuals | |
fitnesses = toolbox.map(toolbox.evaluate, population) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(!function.isFeasible(m_pop[mu()+i].searchPoint())){ | |
RealVector t(m_pop[mu()+i].searchPoint()); | |
function.closestFeasible( t ); | |
double dist = norm_sqr( t - m_pop[mu()+i].searchPoint() ); | |
std::cout << dist << std::endl; | |
m_invalidCount++; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
try: | |
tree = subprocess.check_output(["git", "rev-parse", "HEAD"]).strip() | |
except OSError: | |
import warnings | |
warnings.warn("Cannot link examples because we cannot retrieve the git version", Warning) | |
else: | |
extlinks = {'example': ('https://github.com/DEAP/deap/blob/{tree}/examples/%s.py'.format(tree=tree), "examples/")} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ClosestValidMultiPenality(object): | |
def __init__(self, feasibility, feasible, alpha, distance=None): | |
self.fbty_fct = feasibility | |
self.fbl_fct = feasible | |
self.alpha = alpha | |
self.dist_fct = distance | |
def __call__(self, func): | |
@wraps(func) | |
def wrapper(individual, *args, **kwargs): |
OlderNewer