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 / 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 / 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 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 / 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)
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
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 operator
import math
import random
import ctypes
from functools import reduce
import numpy
from deap import algorithms
from deap import base
@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'):
@cmd-ntrf
cmd-ntrf / gsl.pyx
Created October 9, 2014 20:18
GSL wrapper to sample Sobol QRNG
from cpython.mem cimport PyMem_Malloc, PyMem_Free
# Declare the few types and functions we need
cdef extern from "gsl/gsl_qrng.h":
ctypedef struct gsl_qrng
ctypedef struct gsl_qrng_type
gsl_qrng_type* gsl_qrng_sobol
gsl_qrng* gsl_qrng_alloc(gsl_qrng_type* T, unsigned int d)
void gsl_qrng_free(gsl_qrng* q)
@cmd-ntrf
cmd-ntrf / merging_logbooks.py
Last active August 29, 2015 14:07
DEAP example of logbook merging
import numpy
from deap import tools
logbook1 = tools.Logbook()
logbook2 = tools.Logbook()
logbook3 = tools.Logbook()
# Filling the logbooks [...]