Skip to content

Instantly share code, notes, and snippets.

@davidandrzej
davidandrzej / py3simplex.py
Created April 24, 2011 20:11
3-simplex triangular scatter plot
"""
Visualize points on the 3-simplex (eg, the parameters of a
3-dimensional multinomial distributions) as a scatter plot
contained within a 2D triangle.
David Andrzejewski ([email protected])
"""
import numpy as NP
import matplotlib.pyplot as P
import matplotlib.ticker as MT
@davidandrzej
davidandrzej / scaledimage.py
Created April 25, 2011 02:17
Simple matrix intensity plot, similar to MATLAB imagesc()
"""
Simple matrix intensity plot, similar to MATLAB imagesc()
David Andrzejewski ([email protected])
"""
import numpy as NP
import matplotlib.pyplot as P
import matplotlib.ticker as MT
import matplotlib.cm as CM
@davidandrzej
davidandrzej / blockviz.py
Created May 3, 2011 17:56
Visualize matrix blockstructure with spectral clustering
"""
Visualization of matrix block structure
(eg, pairwise similarity or co-occurrence)
Requires scaledimage.py for intensity plots
David Andrzejewski
"""
import numpy as NP
import matplotlib.pyplot as P
@davidandrzej
davidandrzej / bv-example.py
Created May 3, 2011 17:57
Example usage of blockviz.py
"""
Example blockviz usage with synthetic generated data
Requires scaledimage.py and blockviz.py
David Andrzejewski
"""
import numpy as NP
import numpy.random as NPR
@davidandrzej
davidandrzej / linearscatter.py
Created May 3, 2011 18:32
Augment 2D scatter plot with linear regression
"""
Augment scatter plot with linear regression fit
David Andrzejewski
"""
import numpy as NP
import numpy.random as NPR
import matplotlib.pyplot as P
import matplotlib.lines as L
from scikits.learn.linear_model import LinearRegression
@davidandrzej
davidandrzej / discretefeature.clj
Created May 13, 2011 07:30
Create 1-of-N binary encoder from a discrete feature
;; Assumes examples are Clojure maps,
;; for example from clojure.contrib.sql
;;
;; {:eyecolor "brown" :heightmeters 1.7 ...}
;; {:eyecolor "blue" :heightmeters 1.5 ...}
;;
;; (def eye-encoder (discrete-feature-encoder :eyecolor myexamples))
;;
(defn discrete-feature
"Create binary 1-of-N encoding of a discrete feature"
@davidandrzej
davidandrzej / mws.clj
Created May 14, 2011 23:09
Max-WalkSAT (MWS) weighted satisfiability solver
; MaxWalkSAT weighted satisfiability solver
;
; A General Stochastic Approach to Solving Problems with Hard and Soft
; Constraints Henry Kautz, Bart Selman, and Yueyen Jiang. In The
; Satisfiability Problem: Theory and Applications, Dingzhu Gu, Jun Du,
; and Panos Pardalos (Eds.), DIMACS Series in Discrete Mathematics and
; Theoretical Computer Science, vol. 35, American Mathematical Society,
; 1997, pages 573-586.
;
;
@davidandrzej
davidandrzej / knn.clj
Created May 14, 2011 23:10
k-Nearest Neighbors (kNN) supervised classifier
; Standard k nearest neighbors classifier
; Does not handle
; > 2 classes
; even values of k
; any bad input, really
;
; David Andrzejewski ([email protected])
;
; Command-line arguments
; 0 training data filename
@davidandrzej
davidandrzej / loc.clj
Created May 14, 2011 23:14
Count project lines of code
; Calculate lines of code contained in a given directory
; -ignores empty lines
; -ignores comment-only lines
; -does *not* ignore block comments
;
; David Andrzejewski ([email protected])
;
; Command-line arguments
; 0 Code root directory
;
@davidandrzej
davidandrzej / printfig.py
Created June 16, 2011 14:47
Print-friendly plot with Matplotlib
"""
Handful of tricks for making a print-friendly plot
David Andrzejewski
"""
import matplotlib as MPL
import matplotlib.pyplot as P
# Have plots be the exact same size
MPL.rc('figure', figsize=(14, 11)) # figure size in inches