Skip to content

Instantly share code, notes, and snippets.

Avatar

Mathieu Blondel mblondel

View GitHub Profile
@mblondel
mblondel / gaussian_process.py
Created Aug 14, 2013
Gaussian Process Regression
View gaussian_process.py
"""Gaussian processes"""
# Author: Mathieu Blondel <mathieu@mblondel.org>
# License: BSD 3 clause
import numpy as np
from scipy.linalg import cholesky, solve_triangular
from sklearn.base import BaseEstimator, RegressorMixin
from sklearn.metrics.pairwise import pairwise_kernels
@mblondel
mblondel / logsum.py
Created Apr 13, 2010
Logarithm of a sum without underflow
View logsum.py
import numpy as np
def _logsum(logx, logy):
"""
Return log(x+y), avoiding arithmetic underflow/overflow.
logx: log(x)
logy: log(y)
Rationale:
View out_of_scope.py
def test():
print(i)
i = 1
test()
@mblondel
mblondel / einsum.py
Created May 22, 2015
Einstein sum notation
View einsum.py
import numpy as np
rng = np.random.RandomState(0)
print "Trace"
A = rng.rand(3, 3)
print np.trace(A)
print np.einsum("ii", A)
print
@mblondel
mblondel / ot_dual_lp.py
Created Sep 3, 2017
Optimal transport dual LP
View ot_dual_lp.py
# Author: Mathieu Blondel
# License: BSD 3 clause
import numpy as np
from scipy.optimize import linprog
def dual_lp(a, b, C, verbose=0):
"""Solves the dual optimal transport problem:
@mblondel
mblondel / imputer.py
Last active May 13, 2017
Missing-value imputation
View imputer.py
# (C) Mathieu Blondel
# License: BSD 3 clause
import numpy as np
from numpy import ma
import scipy.sparse as sp
def _get_mask(X, missing_values, sparse=False):
if sparse:
@mblondel
mblondel / curve_averaging.py
Last active May 13, 2017
Variable-length curve averaging
View curve_averaging.py
"""Variable-length curve averaging"""
# Author: Mathieu Blondel <mathieu@mblondel.org>
# License: BSD 3 clause
import numpy as np
from scipy.interpolate import interp1d
def curves_mean_std(X, Y, kind="linear"):
View mcmc_exercices.py
"""
Exercises for the Markov Chain Monte-Carlo (MCMC) course available at
http://users.aims.ac.za/~ioana/
"""
import numpy as np
import numpy.linalg as la
import pylab
from scipy import stats
@mblondel
mblondel / xref.txt
Created May 10, 2013
Cross-referencing in LaTeX.
View xref.txt
paper.tex: main manuscript
supp.tex: supplementary material
Cross-referencing
-----------------
We want to cross-reference equations in paper.tex from supp.tex.
@mblondel
mblondel / lbfgs_nnls.py
Last active Dec 10, 2015
NNLS via LBFGS
View lbfgs_nnls.py
# (C) Mathieu Blondel 2012
# License: BSD 3 clause
import numpy as np
from scipy.optimize import fmin_l_bfgs_b
from sklearn.base import BaseEstimator, RegressorMixin
from sklearn.utils.extmath import safe_sparse_dot