This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Authors: Mathieu Blondel, Vlad Niculae | |
# License: BSD 3 clause | |
import numpy as np | |
def _gen_pairs(gen, max_iter, max_inner, random_state, verbose): | |
rng = np.random.RandomState(random_state) | |
# if tuple, interpret as randn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
(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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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|| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# (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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def _logsum(logx, logy): | |
""" | |
Return log(x+y), avoiding arithmetic underflow/overflow. | |
logx: log(x) | |
logy: log(y) | |
Rationale: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def test(): | |
print(i) | |
i = 1 | |
test() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |