Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View fmder's full-sized avatar

François-Michel De Rainville fmder

  • Québec, Canada
View GitHub Profile
from collections.abc import Sequence
from copy import deepcopy
from functools import wraps
from typing import Callable
import numpy
MAXIMIZE = 1.0
MINIMIZE = -1.0
@fmder
fmder / pymoo_nsga3.py
Last active May 31, 2019 09:43
DTLZ1 pymoo
from math import factorial
from pymoo.optimize import minimize
from pymoo.util import plotting
from pymoo.util.reference_direction import UniformReferenceDirectionFactory
from pymop.factory import get_problem
from pymoo.algorithms.nsga3 import nsga3
import matplotlib.pyplot as plt
import numpy
import itertools
import numpy
from deap import cma
class CovarianceConditionError(Exception):
pass
class StrategyMixedInteger(cma.Strategy):
@fmder
fmder / kursawe_test.py
Created May 22, 2016 01:34
ParetoFront test
# 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
@fmder
fmder / inflate.py
Created January 26, 2016 20:52
Inflate a flattened dictionary
def inflate(d, sep="_"):
items = dict()
for k, v in d.items():
keys = k.split(sep)
sub_items = items
for ki in keys[:-1]:
try:
sub_items = sub_items[ki]
except KeyError:
End of evolution after 80 generations
MU = 10, LAMBDA = 100
Population of the generation number 79 :
(array('d', [0.3384816385414553, 0.2913862946297661, 0.6391631079035605, 99.78019922362375, 0.9999999999999991]), (100.78019922362375, 102.04923026469854))
(array('d', [0.12725983751030595, 0.06852642494740502, 0.2944790143036873, -80.78193202686674, 0.9999999999999988]), (-79.78193202686674, -79.29166675010535))
(array('d', [0.32497537960481293, 0.30232682417375684, 0.6611237261340428, 34.76077835597124, 0.999999999999999]), (35.76077835597124, 37.04920428588385))
(array('d', [0.12518823446474206, 0.05982068209343572, 0.2846256754372451, -24.98563318764257, 0.9999999999999986]), (-23.98563318764257, -23.515998595647147))
(array('d', [0.16447172340744912, -0.37862460917923624, 0.2425460722676009, -0.8978315694776402, 0.9999999999999983]), (0.10216843052235813, 0.13056161701817193))
(array('d', [0.17269510499090013, -0.3647635822434079, 0.27057986499062364, 8.828981876870646, 0.9999999999999986]), (9.828981876
@fmder
fmder / shuffled_iterator.py
Last active September 18, 2015 15:37
Shuffled iterator with lookahead
def shuffled_iterator(iterator, look_ahead=5000, skip=0, seed=None):
"""Return an iterator on the shuffled (part) of the provided *iterator*.
This iterator consumes the provided iterator to turn it into a shuffled
version. The cunsumption can be limited by the *lookahead* argument that
limits the view of the operator. The *skip* argument flushes the first n
items of the provided *iterator* and the *seed* allow for repetability.
"""
rng = numpy.random.RandomState(seed)
batch = list(itertools.islice(iterator, skip, skip+look_ahead))
@fmder
fmder / loss_infty.py
Last active September 10, 2015 14:27
from lasagne.layers import *
from lasagne.nonlinearities import sigmoid
import lasagne
import numpy
import theano
import theano.tensor as T
def build_network(input_shape, input_var, num_units):
nnet = dict()
nnet["input"] = InputLayer(input_shape, input_var, name="input")
import lasagne
import numpy
import theano
import theano.tensor as T
def get_data():
return numpy.random.randn(200, 32, 32), numpy.random.randint(2, size=(200, 1))
def build_ae(input_shape, input_var):
@fmder
fmder / elastic_transform.py
Last active August 22, 2021 14:54
Elastic transformation of an image in Python
import numpy
from scipy.ndimage.interpolation import map_coordinates
from scipy.ndimage.filters import gaussian_filter
def elastic_transform(image, alpha, sigma, random_state=None):
"""Elastic deformation of images as described in [Simard2003]_.
.. [Simard2003] Simard, Steinkraus and Platt, "Best Practices for
Convolutional Neural Networks applied to Visual Document Analysis", in