Skip to content

Instantly share code, notes, and snippets.

View kylebgorman's full-sized avatar

Kyle Gorman kylebgorman

View GitHub Profile
@ctw
ctw / wagnerfischerpp.py
Last active February 8, 2016 17:44 — forked from kylebgorman/wagnerfischerpp.py
Wagner-Fischer Levenshtein distance, now with a means to generate all possible optimal alignments.
#!/usr/bin/env python
#
# Copyright (c) 2013-2014 Kyle Gorman
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
@kylebgorman
kylebgorman / casefold.py
Created July 10, 2019 12:15
Applies Unicode case folding to input data
#!/usr/bin/env python
import fileinput
import nltk
if __name__ == "__main__":
for line in fileinput.input():
print(line.rstrip().casefold())
@kylebgorman
kylebgorman / fix.sh
Created May 6, 2019 18:14
Update shared library caches
# On Linux:
sudo ldconfig
# On Mac OS X:
sudo update_dyld_shared_cache
@kylebgorman
kylebgorman / torch_cuda.py
Last active October 8, 2019 15:58
Checks that PyTorch can reach CUDA
#!/usr/bin/env python
"""Checks that PyTorch can reach CUDA."""
import sys
import torch
if __name__ == "__main__":
if not torch.cuda.is_available():
@kylebgorman
kylebgorman / ratio.pyx
Last active October 8, 2019 15:58
Log-likelihood ratio test in Cython, using scipy for distribution functions.
"""Functions for computing log-likelihood ratio statistics."""
from libc.math cimport log
from scipy.stats import binom
from scipy.stats import chi2
cpdef double LLR(int c_a, int c_b, int c_ab, int n):
@kylebgorman
kylebgorman / wcm.py
Created November 4, 2015 02:49
Stole-Gammon word complexity measure (WCM)
#!/usr/bin/env python
#
# Copyright (c) 2014 Kyle Gorman
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
@kylebgorman
kylebgorman / bktree.py
Created November 4, 2015 02:48
Burkhard-Keller trees
# Copyright (c) 2014-2015 Kyle Gorman <gormanky@ohsu.edu>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
@kylebgorman
kylebgorman / martini.c
Created June 10, 2012 23:08
Recursive martini class
// A cool way to draw a martini glass; this was on the final of CS 115 at U of I
#include <stdio.h>
void drawcup(int N, int offset) {
// base case
if (offset > N)
return;
@kylebgorman
kylebgorman / mcnemar.py
Last active February 11, 2020 18:46
Compute McNemar's test (two two-sided variants) in Python
import scipy.stats
def mcnemar_p(n1: int, n2: int) -> float:
"""Computes McNemar's test.
Args:
n1: the number of "wins" for the first condition.
n2: the number of "wins" for the second condition.
@kylebgorman
kylebgorman / em2gaus.py
Created June 26, 2012 00:02
EM for a mixture of 2 univariate Gaussians
#!/usr/bin/env python
#
# Copyright (c) 2012 Kyle Gorman
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions: