Skip to content

Instantly share code, notes, and snippets.

View npinto's full-sized avatar

Nicolas Pinto npinto

View GitHub Profile
@npinto
npinto / openmpsum.py
Created July 31, 2012 19:03
openmp with scipy weave inline
import numpy as np
from scipy import weave
def openmpSum(in_array):
"""
Performs fast sum of an array using openmm
"""
a = np.asarray(in_array)
b = np.array([1.])
N = int(np.prod(a.shape))
@npinto
npinto / AdjustedRandError.java
Created July 25, 2012 21:19
Fiji's Segmentation Metrics
package trainableSegmentation.metrics;
/**
*
* License: GPL
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License 2
* as published by the Free Software Foundation.
*
@npinto
npinto / connectomics_swirls.py
Created July 21, 2012 08:58
Connectomics swirls
import numpy as np
from scipy import misc
from skimage.transform import swirl
import connectomics_data as cd
def random_swirls(X, Y, n_swirls=1, order=0, rseed=None):
@npinto
npinto / connectomics_noise.py
Created July 21, 2012 08:05
Connectomics EM Noise Simulation
from scipy import ndimage
from scipy import misc
import numpy as np
import connectomics_data as cd
def get_mask(shape, p=0.999, sigma=10, th=0.2):
r = np.random.binomial(1, p, size=shape).astype('f')
r2 = ndimage.gaussian_filter(r, sigma)
@npinto
npinto / gd.py
Created July 21, 2012 05:41
steepest descent w/ line search (brent)
import numpy as np
from scipy.optimize import brent
def steepest_descent(func, X0, grad, maxiter= 100, verbose = False,
project=None, alpha_0=1.0, gtol = 1e-5, **args):
def func_one(X,dir_):
def inner(alpha):
if project is None:
return func(X + alpha*dir_)
@npinto
npinto / img2_00_X.png
Created July 20, 2012 23:21
Infinite Connectomics Data
img2_00_X.png
@npinto
npinto / perl-5.12.3.ebuild
Created July 3, 2012 06:18
Ubuntu 11+ compatible perl gentoo prefix ebuild
# Copyright 1999-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/dev-lang/perl/perl-5.12.3.ebuild,v 1.1 2011/01/22 09:41:54 tove Exp $
EAPI=3
inherit eutils alternatives flag-o-matic toolchain-funcs multilib
PATCH_VER=1
@npinto
npinto / deform.py
Created July 2, 2012 20:16
"Water" Image Deformation
import numpy as np
from scipy import ndimage
#from pylab import quiver
from scipy import misc
l = misc.lena()
yy, xx = np.indices(l.shape)
@npinto
npinto / rv_grad.py
Created June 28, 2012 21:20
Gradients of Rolling View
import numpy as np
from skimage.util.shape import view_as_windows, view_as_blocks
from sthor.util import filter_pad2d
def f_g(x):
xr = view_as_windows(x, (2, 2)).copy()
#print xr
loss = 0.5 * (xr**2.).sum()
@npinto
npinto / mcc_bug.py
Created May 18, 2012 13:03
MCC Bug ?
import numpy as np
def test_mcc_bug():
np.random.seed(42)
# 64 classes with different "scale variation"
# 100 samples per class, 1000 dimensions
C = np.random.randn(100, 64, 1000) + np.arange(64)[np.newaxis, :, np.newaxis]
# single test point with 1000 dimensions
x = np.random.randn(1000)