Skip to content

Instantly share code, notes, and snippets.

View mehdidc's full-sized avatar

Mehdi Cherti mehdidc

View GitHub Profile
@mehdidc
mehdidc / README.md
Created March 20, 2016 17:33 — forked from EderSantana/CATCH_Keras_RL.md
Keras plays catch - a single file Reinforcement Learning example
import numpy as np
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
from pyearth import Earth
import time
from itertools import product
np.random.seed(2)
import numpy as np
import os
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
from pyearth import Earth
import time
np.random.seed(2)
@mehdidc
mehdidc / elastic_transform.py
Created May 15, 2016 09:46 — forked from fmder/elastic_transform.py
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
import numpy as np
import time
from joblib import Memory
import pandas as pd
from bokeh.charts import show, Bar
from bokeh.io import output_file, vplot
@mehdidc
mehdidc / min-char-rnn.py
Created May 28, 2016 16:33 — forked from karpathy/min-char-rnn.py
Minimal character-level language model with a Vanilla Recurrent Neural Network, in Python/numpy
"""
Minimal character-level Vanilla RNN model. Written by Andrej Karpathy (@karpathy)
BSD License
"""
import numpy as np
# data I/O
data = open('input.txt', 'r').read() # should be simple plain text file
chars = list(set(data))
data_size, vocab_size = len(data), len(chars)
from sklearn.ensemble import RandomForestRegressor
from sklearn.base import clone
import numpy as np
class GAM(object):
"""
Simple generalized additive model which fits each feature w.r.t
the output independently using a model specified by
base_estimator. the final predictions can be done by regressing linearly
the predictions of the model of each features by using a pipeline.
from tempfile import mkdtemp
import shutil
import os
import sys
import subprocess
from skimage.io import imsave
cmd_tpl = 'ffmpeg -y -framerate {framerate} -i {pattern} -c:v libx264 -r {rate} -pix_fmt yuv420p {out}'
# Code adapted from https://github.com/kylemcdonald/Parametric-t-SNE
import numpy as np
import theano.tensor as T
def Hbeta(D, beta):
P = np.exp(-D * beta)
sumP = np.sum(P)
H = np.log(sumP) + beta * np.sum(np.multiply(D, P)) / sumP
P = P / sumP
return H, P
@mehdidc
mehdidc / ranking.py
Created June 27, 2016 01:48 — forked from agramfort/ranking.py
Pairwise ranking using scikit-learn LinearSVC
"""
Implementation of pairwise ranking using scikit-learn LinearSVC
Reference: "Large Margin Rank Boundaries for Ordinal Regression", R. Herbrich,
T. Graepel, K. Obermayer.
Authors: Fabian Pedregosa <fabian@fseoane.net>
Alexandre Gramfort <alexandre.gramfort@inria.fr>
"""