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 numpy.lib.stride_tricks import as_strided | |
import numbers | |
def make_patches(arr, patch_shape=2, extraction_step=1): | |
arr_ndim = arr.ndim | |
if isinstance(patch_shape, numbers.Number): | |
patch_shape = tuple([patch_shape] * arr_ndim) |
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 sklearn.linear_model import Ridge, SGDRegressor | |
rng = np.random.RandomState(42) | |
n_samples, n_features = 2000, 50 | |
X = rng.randn(n_samples, n_features) | |
w = rng.randn(n_features) |
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 | |
# X.dot(X.T) + alpha * eye = U.dot(S ** 2 + alpha).dot(U.T) | |
# X.T.dot(inv(X.dot(X.T) + alpha * eye)) = V.dot(S / (S **2 + alpha).dot(U.T)) | |
def _linear_kernel_ridge_path_svd( | |
U_train, S_train, VT_train, Y_train, alphas, X_test=None): | |
UTY = U_train.T.dot(Y_train) |
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
--------------------------------------------------------------------------- | |
SystemError Traceback (most recent call last) | |
/home/parietal/eickenbe/software/python_pkg/anaconda/lib/python2.7/site-packages | |
/IPython/utils/py3compat.pyc in execfile(fname, *where) | |
202 else: | |
203 filename = fname | |
--> 204 __builtin__.execfile(filename, *where) | |
/home/parietal/eickenbe/code/ofv/ofb.py in <module>() | |
369 dump_theano_r_layer(l) |
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
# Coordinate descent algorithm for Lasso in pure python | |
# Goal: evaluate speed up potential when using dynamic screening | |
# rules every few coordinate sweeps, on all types of design | |
# See Bonnefoy et al., 2014, https://hal.inria.fr/hal-00880787v4 | |
# Author: Michael Eickenberg, michael.eickenberg@nsup.org | |
import numpy as np | |
def screen_dictionary(X, residual, y, alpha, | |
current_support=None, | |
current_radius=None, |
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(42) | |
n_samples, n_features = 100, 50 | |
X = rng.randn(n_samples, n_features) | |
V1, S1, VT1 = np.linalg.svd(X.T.dot(X), full_matrices=True) | |
U2, S2, VT2 = np.linalg.svd(X, full_matrices=True) |
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
# Implements functionality corresponding to numpy.mgrid / numpy.ogrid for symbolic theano variables | |
# Author: Michael Eickenberg, michael.eickenberg@nsup.org | |
import theano | |
import theano.tensor as T | |
class _nd_grid(object): | |
"""Implements the mgrid and ogrid functionality for theano tensor | |
variables. |
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
# Maxpooling with arbitrary pooling strides and pooling shapes | |
# Based on theano.tensor.signal.downsample.max_pool_2d. This | |
# operation is repeated the minimum necessary times to account for | |
# all stride steps. | |
#Author: Michael Eickenberg, michael.eickenberg@nsup.org | |
import theano | |
import numpy as np |
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 theano | |
import theano.tensor as T | |
import numpy as np | |
# 0 and some arbitrarily small positive and negative numbers | |
test_vector = np.array( | |
[0., 1., -1., .1, -.1, 10., -10., 1e-8, -1e-8, | |
1e-10, -1e-10, 1e-16, -1e-16]).astype(np.float32) |
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 Michael Eickenberg <michael.eickenberg@nsup.org>, Fabian Pedregosa | |
# Coded in 2012, another era, pure python, no guarantees for 1000% correctness or speed | |
# requires loess.py | |
import numpy as np | |
from loess import lowess | |
VERBOSE = 100 |
OlderNewer