Skip to content

Instantly share code, notes, and snippets.

@perimosocordiae
perimosocordiae / .block
Last active Dec 16, 2016
Sonified Line Chart
View .block
license: gpl-3.0
@perimosocordiae
perimosocordiae / als.py
Created Sep 25, 2015
Asymmetric Least Squares
View als.py
import numpy as np
from scipy.linalg import solveh_banded
def als_baseline(intensities, asymmetry_param=0.05, smoothness_param=1e6,
max_iters=10, conv_thresh=1e-5, verbose=False):
'''Computes the asymmetric least squares baseline.
* http://www.science.uva.nl/~hboelens/publications/draftpub/Eilers_2005.pdf
smoothness_param: Relative importance of smoothness of the predicted response.
View spanning_tree.py
import numpy as np
from scipy.sparse.csgraph import minimum_spanning_tree
from sklearn.metrics import pairwise_distances
def perturbed_mst(X, num_perturbations=20, jitter=None):
'''Builds a graph as the union of several MSTs on perturbed data.
Reference: http://ecovision.mit.edu/~sloop/shao.pdf, page 8
jitter refers to the scale of the gaussian noise added for each perturbation.
When jitter is None, it defaults to the 5th percentile interpoint distance.'''
@perimosocordiae
perimosocordiae / fit_curve.py
Created May 21, 2012
User-friendly interface to scipy's curve_fit function
View fit_curve.py
#!/usr/bin/env python
from scipy.optimize import curve_fit
import re
from math import *
from numpy import *
from sys import stdin
from optparse import OptionParser
op = OptionParser(usage='%prog [options] <function_of_x> [input_file]')
@perimosocordiae
perimosocordiae / eigenface.py
Created Mar 23, 2010
PCA-based face recognition
View eigenface.py
#!/usr/bin/env python
from sys import argv, exit
from glob import glob
from matplotlib.pyplot import show, imshow, subplot, gray
from matplotlib.image import imread
from numpy import zeros,dot,sum,arange,savez,load,flipud,array
from scipy.linalg import eig
ATT = False
CLIP = False
View moving-stereogram.py
#!/usr/bin/env python
import stereogram as s
import numpy as np
from sys import argv,exit
from os import system
from os.path import splitext
from PIL import Image,ImageSequence
# axis: 0 is up/down, 1 is left/right
View stereogram.py
#!/usr/bin/env python
from PIL import Image
import numpy as np
from sys import argv,exit
from random import randint
from time import time
from math import ceil
try:
from weave import inline,converters
@perimosocordiae
perimosocordiae / forth.rb
Created Feb 10, 2010
A pure Ruby interpreter for Forth
View forth.rb
#!/usr/bin/env ruby
# the stack
$stack = []
def pop() $stack.pop || ufe end
def push(f) $stack<<f end
# poor man's Exception class
def ufe() raise("Stack underflow") end
# lambda constructor helpers