Skip to content

Instantly share code, notes, and snippets.

@duckworthd
duckworthd / gist:1520395
Created December 26, 2011 02:08
erf() and erfi()
private val a = 0.147 // constant for calculating erf/erfi
/**
* An approximation to the error function
*/
def erf(x: Double) = {
val x2 = x*x
val inner = exp(-1*x2*(4/pi + a*x2) /
(1.0 + a*x2))
signum(x)*sqrt(1.0 - inner)
}
@duckworthd
duckworthd / instant_debug.py
Created April 24, 2012 20:34
Instant Debug
'''
A module that allows one to press CTRL+\ at any time to pause program execution.
The stack may be examined with `u` and `d`, and the process can be continued with
`c`. For example,
import instant_debug
import time
for i in xrange(10000):
print i
@duckworthd
duckworthd / gist:2692699
Created May 14, 2012 08:27
Reproducing KNN warnings
from pprint import pprint
from sklearn.datasets import load_digits
from sklearn.neighbors import KNeighborsClassifier
from sklearn.cross_validation import KFold
# load data
digits = load_digits()
X = digits.data.astype('uint8')
Y = digits.target
Startup
=======
run pig locally:
$ magicpig -x local script.pig # doesn't work
expand pig macros:
$ magicpig -dryrun script.pig
Commands
========
@duckworthd
duckworthd / rfb_nn.py
Last active December 21, 2015 22:19
What does the output of an a Neural Network with soft-max and RBF kernels look like?
import numpy as np
from scipy.stats import norm
import pylab as pl
def rbf(x, C, w):
y = [norm.pdf(np.linalg.norm(x - C[i]) ** 2.0, 0, 1) for i in range(C.shape[0])]
y = np.exp(y) / np.sum(np.exp(y))
return w.dot(y)
@duckworthd
duckworthd / cross_validation.py
Created September 16, 2013 17:46
Drop-in replacement for `sklearn.cross_validation.KFold` for sequential data.
'''
Cross validation selectors
@author: duckworthd
'''
import numpy as np
class SequentialFolds(object):
'''
@duckworthd
duckworthd / OSXScreen.md
Last active December 24, 2015 05:19 — forked from bigeasy/OSXScreen.md

Installing GNU Screen on OS X in Homebrew

Sadly, I found that the screen that comes with OS X does not support 256 colors. Starting with this article GNU/Screen with 256 colours in Mac OS X, I built GNU Screen as follows.

git clone git clone git://git.savannah.gnu.org/screen.git
cd screen/src
mkdir -p /opt/etc
mv etc/etcscreenrc /opt/etc/screenrc
./autogen.sh
<html>
<head>
<!-- CSS goes here -->
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<!-- page content goes here -->
<h1>Hello, World</h1>