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 | |
from scipy import linalg, optimize | |
MAX_ITER = 100 | |
def group_lasso(X, y, alpha, groups, max_iter=MAX_ITER, rtol=1e-6, | |
verbose=False): | |
""" | |
Linear least-squares with l2/l1 regularization solver. |
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
""" | |
Low rank approximation for the lena image | |
""" | |
import numpy as np | |
import scipy as sp | |
from scipy import linalg | |
import pylab as pl | |
X = sp.lena().astype(np.float) | |
pl.gray() |
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 _solve(A, b, solver, tol): | |
# helper method for ridge_regression, A is symmetric positive | |
if solver == 'auto': | |
if hasattr(A, 'todense'): | |
solver = 'sparse_cg' | |
else: | |
solver = 'dense_cholesky' | |
if solver == 'sparse_cg': |
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
""" | |
usage : simple_client.py torrent_file | |
""" | |
#!/usr/bin/env python | |
# Copyright Arvid Norberg 2008. Use, modification and distribution is | |
# subject to the Boost Software License, Version 1.0. (See accompanying | |
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
# with modifications by Fabian Pedregosa <fabian@fseoane.net> | |
# October 2011 |
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
""" | |
Plot memory usage of a numeric computation using numpy and scipy | |
""" | |
"""Get process information""" | |
import time, sys, os | |
import linecache | |
if sys.platform.startswith('linux'): |
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
cimport numpy as np | |
import numpy as np | |
np.import_array() | |
def chkfinite_double(np.ndarray X): | |
cdef int i, length | |
cdef np.PyArrayObject val | |
cdef np.flatiter iter |
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
""" | |
Ridge coefficients as a function of the regularization parameter | |
---------------------------------------------------------------- | |
And highlight in dashed lines the optimal value by cross-validation. | |
Author: Fabian Pedregosa -- <fabian@fseoane.net> | |
""" | |
print __doc__ |
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 | |
from scipy import linalg | |
def ridge(A, b, alphas): | |
"""Return coefficients for regularized least squares | |
||A x - b|| + alpha ||x|| | |
""" | |
U, s, V = linalg.svd(X, full_matrices=False) | |
d = np.dot(U.T, y) / (s + alphas[:, np.newaxis] / s) | |
return np.dot(d, V) |
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 | |
from scipy import linalg | |
def cgs(A): | |
"""Classical Gram-Schmidt (CGS) algorithm""" | |
m, n = A.shape | |
R = np.zeros((n, n)) | |
Q = np.empty((m, n)) | |
R[0, 0] = linalg.norm(A[:, 0]) | |
Q[:, 0] = A[:, 0] / R[0, 0] |
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
""" | |
Hilbert matrix using numpy. Contains: | |
- hilb(n, m) : returns the Hilbert matrix of size (n, m) | |
- invhilb(n) : returns the inverse of the Hilbert matrix of size (n, n) | |
""" | |
import numpy as np | |
from math import factorial |