Skip to content

Instantly share code, notes, and snippets.

View kylebgorman's full-sized avatar

Kyle Gorman kylebgorman

View GitHub Profile
@kylebgorman
kylebgorman / tolerance.c
Last active November 27, 2023 19:22
Just for fun: a C-based calculator for Yang's (2005; "On Productivity", Language Variation Yearbook) Tolerance function
/*
* Tolerance Principle calculator, based on:
*
* C. Yang (2005). On productivity. Language Variation Yearbook 5:333-370.
*
* Definition:
*
* The number of data points consistent with a rule R is given by N, and the
* number of exceptions to it by m. By Tolerance, R is productive iff:
*
@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 / 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:
@kylebgorman
kylebgorman / .vimrc
Last active October 23, 2023 21:57
my .vimrc (pretty basic)
syn on
set hlsearch
set ruler
" tab stuff
set expandtab
set tabstop=4
" scrolling
set scrolloff=5
" backspace over everythign
set backspace=indent,eol,start
@kylebgorman
kylebgorman / autoloess.R
Last active November 28, 2022 16:06
autoloess.R: set the "span" (smoothing) hyperparameter for a LOESS curve so as to minimize AIC_c (includes a cute demonstration)
# autoloess.R: compute loess metaparameters automatically
# Kyle Gorman <gormanky@ohsu.edu>
aicc.loess <- function(fit) {
# compute AIC_C for a LOESS fit, from:
#
# Hurvich, C.M., Simonoff, J.S., and Tsai, C. L. 1998. Smoothing
# parameter selection in nonparametric regression using an improved
# Akaike Information Criterion. Journal of the Royal Statistical
# Society B 60: 271–293.
@kylebgorman
kylebgorman / wagnerfischerpp.py
Last active March 3, 2023 17:27
Wagner-Fischer Levenshtein distance, now with a means to generate all possible optimal alignments.
# Copyright (c) 2013-2022 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:
#
@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 / 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 / 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 / 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):