Skip to content

Instantly share code, notes, and snippets.

View GaelVaroquaux's full-sized avatar

Gael Varoquaux GaelVaroquaux

View GitHub Profile
@GaelVaroquaux
GaelVaroquaux / spectral_clustering.py
Created September 25, 2011 18:33
With a random shapeless affinity matrix, spectral clustering does not work: the spectrum of the laplacian is flat.
#!/usr/bin/env python
# gvaroquaux (adapted from tdh.net gmail com)
# 31.August.2011
# try clustering module in scikits.learn
import numpy as np
from scipy import linalg
from sklearn.metrics.pairwise import euclidean_distances
from sklearn.cluster import SpectralClustering
@GaelVaroquaux
GaelVaroquaux / compute_bins.py
Created June 6, 2011 10:46
Computing bins to have a somewhat equal partitioning of the data
import numpy as np
def _compute_bins(x, n_bins=10):
""" Find optimal bins from a univariate distribution
Parameters
===========
x: 1D array-like
Samples
n_bins: integer
@GaelVaroquaux
GaelVaroquaux / concat_img.py
Created March 10, 2011 16:23
Preprocess some resting state fMRI data with NiPype
"""A helper node to concatenate images in nipype"""
import os
from nipype.interfaces.base import TraitedSpec, File, CommandLineInputSpec, CommandLine
from nipype.utils.misc import isdefined
class ConcatImgInputSpec(CommandLineInputSpec):
in_file1 = File(exists=True, argstr="-append %s",
position=1, mandatory=True)
@GaelVaroquaux
GaelVaroquaux / SparsePCA.py
Created January 28, 2011 10:12
A sparse PCA implementation based on the LARS algorithm
import time
import sys
import numpy as np
from numpy.lib.stride_tricks import as_strided
from math import sqrt
from scipy import linalg
from scikits.learn.linear_model import Lasso, lars_path
from joblib import Parallel, delayed