Skip to content

Instantly share code, notes, and snippets.

View cvanweelden's full-sized avatar

Carsten van Weelden cvanweelden

View GitHub Profile
@cvanweelden
cvanweelden / code Makefile
Created March 6, 2012 14:07
Files needed to get cpmc_release1 working on a 64-bit Intel Mac with Matlab R2011a.
CC = gcc #gcc-4.2
MATLABDIR=/Applications/MATLAB_R2011a.app
INCLUDES=-I$(MATLABDIR)/extern/include
LDIRS= -L$(MATLABDIR)/bin/maci64
EXE_TARGETS = segm_overlap_mex.mexa64 segm_intersection_mex.mexa64
all: $(EXE_TARGETS)
overlap.o: overlap.c
$(CC) -D__MAIN__ -O3 -fPIC -c $(INCLUDES) -fopenmp -o overlap.o overlap.c
inversions :: (Ord a) => [a] -> Int
inversions list = let (n,_) = inversions' list in n
inversions' :: (Ord a) => [a] -> (Int,[a])
inversions' [] = (0, [])
inversions' [a] = (0, [a])
inversions' list =
let half = (length list) `div` 2
(na, a) = inversions' (take half list)
(nb, b) = inversions' (drop half list)
@cvanweelden
cvanweelden / gcc -v
Created November 13, 2012 10:37
qrupdate did not build on OS X 10.6.8-i386
Using built-in specs.
Target: i686-apple-darwin10
Configured with: /var/tmp/gcc/gcc-5666.3~6/src/configure --disable-checking --enable-werror --prefix=/usr --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin10 --program-prefix=i686-apple-darwin10- --host=x86_64-apple-darwin10 --target=i686-apple-darwin10 --with-gxx-include-dir=/include/c++/4.2.1
Thread model: posix
gcc version 4.2.1 (Apple Inc. build 5666) (dot 3)
==> Downloading http://ftpmirror.gnu.org/octave/octave-3.6.3.tar.bz2
Already downloaded: /Users/carsten/Library/Caches/Homebrew/octave-3.6.3.tar.bz2
/usr/bin/tar xf /Users/carsten/Library/Caches/Homebrew/octave-3.6.3.tar.bz2
==> Using Homebrew-provided fortran compiler.
This may be changed by setting the FC environment variable.
==> ./configure --disable-dependency-tracking --prefix=/usr/local/Cellar/octave/3.6.3 --with-blas=-ldotwrp -Wl,-framework -Wl,Accelerate --with-umfpack=-lumfpack -lsuitesparseconfig
./configure --disable-dependency-tracking --prefix=/usr/local/Cellar/octave/3.6.3 --with-blas=-ldotwrp -Wl,-framework -Wl,Accelerate --with-umfpack=-lumfpack -lsuitesparseconfig
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
@cvanweelden
cvanweelden / sampling.py
Last active December 13, 2015 19:09
Minimization problem for sampling histograms
import cvxpy
import numpy as np
if __name__ == "__main__":
#The histogram data, 250 histograms with 3 bins
D = cvxpy.parameter(250,3,name='D')
D.value = cvxpy.matrix(np.random.randint(0,100,(250,3)))
#The weights, one for each histogram
@cvanweelden
cvanweelden / weighted_sample.py
Created February 17, 2013 12:24
A python method for weighted sampling without replacement based on roulette selection.
def weighted_sample(weights, sample_size):
"""
Returns a weighted sample without replacement. Note: weights.dtype should be float for speed, see: http://sociograph.blogspot.nl/2011/12/gotcha-with-numpys-searchsorted.html
"""
totals = np.cumsum(weights)
sample = []
for i in xrange(sample_size):
rnd = random.random() * totals[-1]
idx = np.searchsorted(totals,rnd,'right')
sample.append(idx)