Skip to content

Instantly share code, notes, and snippets.

View perimosocordiae's full-sized avatar

CJ Carey perimosocordiae

View GitHub Profile
@perimosocordiae
perimosocordiae / forth.rb
Created February 10, 2010 18:58
A pure Ruby interpreter for Forth
#!/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
@perimosocordiae
perimosocordiae / stereogram.py
Created February 16, 2010 00:38
Stereogram generator
#!/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
#!/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
@perimosocordiae
perimosocordiae / eigenface.py
Created March 23, 2010 06:55
PCA-based face recognition
#!/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
@perimosocordiae
perimosocordiae / fit_curve.py
Created May 21, 2012 16:06
User-friendly interface to scipy's curve_fit function
#!/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 / spanning_tree.py
Created August 4, 2014 18:22
MST graph construction
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 / als.py
Created September 25, 2015 18:03
Asymmetric Least Squares
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.
@perimosocordiae
perimosocordiae / .block
Last active December 16, 2016 20:00
Sonified Line Chart
license: gpl-3.0