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 / animation.py
Created September 24, 2014 14:03
Animating a dynamic random normal multivariate sampling with matplotlib example.
import math
import numpy
from scipy.stats import chi2
from matplotlib import pyplot as plt
from matplotlib import animation
from matplotlib.patches import Ellipse
def cov_patch(centroid, cov, perc, alpha=0.5, color='b'):
import operator
import math
import random
import ctypes
from functools import reduce
import numpy
from deap import algorithms
from deap import base
import array
import random
from deap import algorithms
from deap import base
from deap import creator
from deap import tools
import networkx as nx
import math
import drawG
import networkx
from metric import measure_A, measure_B, measure_C, measure_D
def evaluate(individual):
matrix = numpy.zeros((n,n))
index = 0
for i in range(n-1):
for j in range(i+1, n):
matrix[i,j] = matrix[j,i] = individual[index]
index += 1
@cmd-ntrf
cmd-ntrf / thickness.py
Created November 21, 2013 14:54
[deap-users] Set up a simulation fit
import random
import numpy
from deap import base
from deap import creator
from deap import tools
creator.create("Fitness", base.Fitness, weights=(1.0,))
creator.create("Individual", numpy.ndarray, fitness=creator.Fitness)
@cmd-ntrf
cmd-ntrf / datalogger.py
Last active December 17, 2015 00:59
DEAP - Proposal for a replacement to the Statistics and EvolutionLogger objects. The Database object combine both object functionalities. It requires numpy for statistics computation.
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
@cmd-ntrf
cmd-ntrf / deap_reg_12args.py
Last active December 14, 2015 07:09
Example of a evaluation function for a trivial symbolic regression problems with 12 inputs using DEAP.
import operator
import numpy
from math import sqrt
from deap import gp
# Our dataset is 100 random arrays of 0s and 1s
# and the function we are trying to find is simply
@cmd-ntrf
cmd-ntrf / datalogger.py
Last active December 14, 2015 06:19
Prototype for a DataLogger object based on pandas DataFrame for the DEAP framework. This object would take care of statistics computation and bookeeping along the evolution.
from collections import defaultdict
from pandas import DataFrame, concat
from sys import stdout
from numpy import random
from matplotlib import pyplot as plt
class DataLogger(object):
def __init__(self, key=None):
self.key = key
@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)))
@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