Skip to content

Instantly share code, notes, and snippets.

View longouyang's full-sized avatar

Long Ouyang longouyang

View GitHub Profile
@longouyang
longouyang / log-add.py
Created August 28, 2012 22:36
Adding log probabilities
from math import log, exp
"""
sources:
http://windowoffice.tumblr.com/post/33548509/logsum-underflow-trick-re-discovery
https://facwiki.cs.byu.edu/nlp/index.php/Log_Domain_Computations
"""
def log_add(x,y):
logx = log(x)
logy = log(y)
@longouyang
longouyang / gist:3180917
Created July 26, 2012 08:14
PCFG unfold in Mathematica
TerminalQ[x_] := MemberQ[{a, b, c, d}, x];
Rules = {S -> {{{X, Y}, 1}, {{X, X, Y}, 5}},
X -> {{{a}, 1/2}, {{b}, 1/2}}, Y -> {{{c}, 1/3}, {{d}, 2/3}}};
PCFGUnfold[sym_, Rules_, TerminalQ_] :=
If[TerminalQ[sym],
{{{sym}, 1}},
Block[{lookup, rules, probabilities},
(*for some reason,I can't specify the last two in the {} above*)
@longouyang
longouyang / quine.rb
Created April 10, 2011 03:29
A small quine in Ruby
def p(x) puts x + 'p ' + 34.chr + x + 34.chr end; p "def p(x) puts x + 'p ' + 34.chr + x + 34.chr end; "
@longouyang
longouyang / turk.js
Created February 26, 2011 19:30
Small helper file for doing external HITs on Mechanical Turk
/*
-----------------------------------------------------------------
-----------------------------------------------------------------
NOTE: this file has been superseded by mmturkey:
https://github.com/longouyang/mmturkey
-----------------------------------------------------------------
-----------------------------------------------------------------
*/
var turk = {};
Hello World!
<html>
<head>
<script type="text/javascript">
var pID;
var i = 0;
var startTime, endTime;
function start_test() {
i = 0;