Skip to content

Instantly share code, notes, and snippets.

Avatar

Mathieu Blondel mblondel

View GitHub Profile
@mblondel
mblondel / second_order_ode.py
Created Jul 23, 2010
Solve second order differential equation using the Euler and the Runge-Kutta methods
View second_order_ode.py
#!/usr/bin/env python
"""
Find the solution for the second order differential equation
u'' = -u
with u(0) = 10 and u'(0) = -5
using the Euler and the Runge-Kutta methods.
@mblondel
mblondel / kmeans.py
Last active May 7, 2020
Fuzzy K-means and K-medians
View kmeans.py
# Copyright Mathieu Blondel December 2011
# License: BSD 3 clause
import numpy as np
import pylab as pl
from sklearn.base import BaseEstimator
from sklearn.utils import check_random_state
from sklearn.cluster import MiniBatchKMeans
from sklearn.cluster import KMeans as KMeansGood
@mblondel
mblondel / sparse_multiclass_numba.py
Last active Jan 27, 2020
Sparse Multiclass Classification in Numba!
View sparse_multiclass_numba.py
"""
(C) August 2013, Mathieu Blondel
# License: BSD 3 clause
This is a Numba-based reimplementation of the block coordinate descent solver
(without line search) described in the paper:
Block Coordinate Descent Algorithms for Large-scale Sparse Multiclass
Classification. Mathieu Blondel, Kazuhiro Seki, and Kuniaki Uehara.
Machine Learning, May 2013.
@mblondel
mblondel / projection_simplex_isotonic.py
Created Nov 2, 2019
Projection onto the probability simplex using isotonic regression.
View projection_simplex_isotonic.py
# Author: Mathieu Blondel
# License: BSD 3 clause
import numpy as np
from sklearn.isotonic import isotonic_regression
def projection_simplex(x, z=1):
"""
Compute argmin_{p : p >= 0 and \sum_i p_i = z} ||p - x||
@mblondel
mblondel / projection_simplex_vectorized.py
Last active Nov 2, 2019
Vectorized projection onto the simplex
View projection_simplex_vectorized.py
# Author: Mathieu Blondel
# License: BSD 3 clause
import numpy as np
def projection_simplex(V, z=1, axis=None):
"""
Projection of x onto the simplex, scaled by z:
P(x; z) = argmin_{y >= 0, sum(y) = z} ||y - x||^2
@mblondel
mblondel / seminb.py
Created Oct 28, 2015
Semi-supervised Naive Bayes
View seminb.py
# -*- coding: utf-8 -*-
# Copyright (C) 2010 Mathieu Blondel
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
@mblondel
mblondel / nmf_cd.py
Last active Jun 12, 2019
NMF by coordinate descent
View nmf_cd.py
"""
NMF by coordinate descent, designed for sparse data (without missing values)
"""
# Author: Mathieu Blondel <mathieu@mblondel.org>
# License: BSD 3 clause
import numpy as np
import scipy.sparse as sp
import numba
@mblondel
mblondel / matrix_sketch.py
Last active Feb 13, 2019
Frequent directions algorithm for matrix sketching.
View matrix_sketch.py
# (C) Mathieu Blondel, November 2013
# License: BSD 3 clause
import numpy as np
from scipy.linalg import svd
def frequent_directions(A, ell, verbose=False):
"""
Return the sketch of matrix A.
@mblondel
mblondel / fista.py
Created Nov 6, 2016
Efficient implementation of FISTA
View fista.py
"""
Efficient implementation of FISTA.
"""
# Author: Mathieu Blondel
# License: BSD 3 clause
import numpy as np
@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
You can’t perform that action at this time.