Skip to content

Instantly share code, notes, and snippets.

View timm's full-sized avatar

Tim Menzies timm

View GitHub Profile
@timm
timm / a12.py
Created May 22, 2013 20:07
Python version of non-parametric hypothesis testing using Vargha and Delaney's A12 statistic.
class Rx:
"has the nums of a treatment, its name and rank"
def __init__(i,lst):
i.rx, i.lst = lst[0], lst[1:]
i.mean = sum(i.lst)/len(i.lst)
i.rank = 0
def __repr__(i):
return 'rank #%s %s at %s'%(i.rank,i.rx,i.mean)
def a12s(lst,rev=True,enough=0.66):
@timm
timm / chunk.py
Last active March 30, 2023 21:44
CHUNK: fast clustering in Python. CHUNK is a near-linear time spectral learner that ignores irrelevant variables by combining raw data into an approximation to the data’s eigenvectors (which it finds via a linear-time heuristic). CHUNK generates clusters by recursively dividing the data on those eigenvector approximations.
"""
---
title: chunk.py
author: Tim Menzies, [email protected]
---
(Can be view as
[html](http://menzies.us/cs472/?niching) or [raw
Python](http://unbox.org/open/trunk/472/14/spring/src/where.py).)
@timm
timm / cliffsDelta.py
Last active March 16, 2018 14:31
Fast method for computing Cliffs Delta
from __future__ import division
def cliffsDelta(lst1,lst2,
dull = [0.147, # small
0.33, # medium
0.474 # large
][0] ):
"Returns true if there are more than 'dull' differences"
m, n = len(lst1), len(lst2)
lst2 = sorted(lst2)
@timm
timm / gitable.py
Last active April 11, 2017 21:24
Extracting info from github
page 1
page 2
page 3
page 4
page 5
page 6
page 7
page 8
page 9
page 10
@timm
timm / unittest.py
Last active August 29, 2015 14:18
Simple python unit test engine. Inspired by Kent Beck's video https://www.youtube.com/watch?v=nIonZ6-4nuU.
"""
ok : a simple python unit test engine
Copyright (c) Tim Menzies, 2015, WTFPL http://www.wtfpl.net/
Inspired by Kent Beck's video
https://www.youtube.com/watch?v=nIonZ6-4nuU.
For example usage, see the _ok function (at end).
For help, see [email protected].
"""
@timm
timm / sigs
Last active May 15, 2018 14:43
Random sig generator (prints 2 quotes: always quote#1, then any other picked at random). Usage: bash sig
#!/bin/bash
uniques() {
gawk --source 'BEGIN { RS=""
split("",seen,"") }
{ copy = tolower($0)
gsub(/(--|::).*\n/,"",copy)
gsub(/[^a-z0-9]/,"",copy)
if ( ! (copy in seen) )
print("\n" $0)
@timm
timm / mock.sh
Last active October 3, 2015 15:21
mock: death to recursive make
mock ()
{
root=$(git rev-parse --show-toplevel);
if [ -d "$root" ]; then
( cd $root;
make $* );
else
echo "mock: nothing to do";
fi
}
@timm
timm / abcd.py
Last active October 18, 2021 18:27
class Abcd:
def __init__(i,db="all",rx="all"):
i.db = db; i.rx=rx;
i.yes = i.no = 0
i.known = {}; i.a= {}; i.b= {}; i.c= {}; i.d= {}
def __call__(i,actual=None,predicted=None):
return i.keep(actual,predicted)
def tell(i,actual,predict):
"""
#<<
###################################################
CHUNK: near-linear time recursive clustering.
Copyright (c) 2014, Tim Menzies, [email protected]
All rights reserved.
For details on this code, see chapter 12 of
@timm
timm / knightstour.py
Last active September 7, 2018 18:16
Knights tour with Warnsdorf's rule (written in Python, 60 lines, shows examples of list comprehensions and generators)
#!/usr/bin/python
# Knights tour with Warnsdorf's rule
# copyright (c) 2016 Tim Menzies [email protected], MIT (2 clause)
# usage python knightstour.py [BOARDSIZE] [seed] [x0] [y0]
# suggested usage:
# for((i=1;i<30;i++)); do python knightstour.py 30 $RANDOM; done
# On failure, it retries up to 20 times, picking new x0,y0 each tie.
# Usually gets it right first time, very rarely needs than 5 retries.
# Works fine up to boards of size 50. Starts to crawl a bit at size 100