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 km_segmentation(image, n_segments=100, ratio=50, max_iter=100): | |
# initialize on grid: | |
height, width = image.shape[:2] | |
# approximate grid size for desired n_segments | |
step = np.sqrt(height * width / n_segments) | |
grid_y, grid_x = np.mgrid[:height, :width] | |
means_y = grid_y[::step, ::step] |
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 check_grad(f, fprime, x0): | |
eps = 1e-5 | |
approx = np.zeros(len(x0)) | |
for i in xrange(len(x0)): | |
x0_ = x0.copy() | |
x0_[i] += eps | |
approx[i] = (f(x0_) - f(x0)) / eps | |
return np.linalg.norm(approx.ravel() - fprime(x0).ravel()) | |
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
########################################################################## | |
# Maximum Response filterbank from | |
# http://www.robots.ox.ac.uk/~vgg/research/texclass/filters.html | |
# based on several edge and bar filters. | |
# Adapted to Python by Andreas Mueller [email protected] | |
# Share and enjoy | |
# | |
import numpy as np | |
import matplotlib.pyplot as plt |
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 make_node(p, name=1): | |
if p == 0: | |
return [name] | |
return [name, make_node(p - 1, 10 * name + 0), | |
make_node(p - 1, 10 * name + 1)] | |
def depth_first(p): | |
print(p[0]) | |
if len(p) == 3: |
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
====================================================================== | |
FAIL: test_texture.TestLBP.test_default | |
---------------------------------------------------------------------- | |
Traceback (most recent call last): | |
File "/usr/local/lib/python2.7/dist-packages/nose/case.py", line 197, in runTest | |
self.test(*self.arg) | |
File "/home/andy/checkout/scikits.image/skimage/feature/tests/test_texture.py", line 163, in test_default | |
np.testing.assert_array_equal(lbp, ref) | |
File "/usr/lib/python2.7/dist-packages/numpy/testing/utils.py", line 707, in assert_array_equal | |
verbose=verbose, header='Arrays are not equal') |
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 sparse | |
from sklearn import svm | |
from nose.tools import assert_raises | |
X = np.array([[-2, -1], [-1, -1], [-1, -2], [1, 1], [1, 2], [2, 1]]) | |
X_sp = sparse.lil_matrix(X) | |
Y = [1, 1, 1, 2, 2, 2] | |
sp = svm.sparse.SVC(C=1, kernel=lambda x, y: x * y.T, probability=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
import numpy as np | |
from sklearn.feature_selection import chi2 | |
data = np.load("values.npy") | |
labels = np.load("labels.npy") | |
print(chi2(data, labels)) |
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
blub |
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) 2012 Andreas Mueller [email protected] | |
# License: BSD 2-Clause | |
# | |
# See my blog for details: http://peekaboo-vision.blogspot.com | |
import numpy as np | |
import matplotlib.pyplot as plt | |
from matplotlib.animation import FuncAnimation |
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
from sklearn.utils.testing import all_estimators | |
import numpy as np | |
all_objects = [] | |
for C in all_estimators(): | |
try: | |
all_objects.append(C[1]()) | |
except: | |
pass | |
params = [c.get_params().keys() for c in all_objects] |