Skip to content

Instantly share code, notes, and snippets.

View hamilton's full-sized avatar

Hamilton Ulmer hamilton

View GitHub Profile
import sys
class Rhuthmos(object):
def __init__(self):
"""
wts = word to structure. A hash.
stw = structure to word. A tree.
"""
self.wts = {}
self.stw = {}
import sys
class Rhuthmos(object):
def __init__(self):
"""
wts = word to structure. A hash.
stw = structure to word. A tree.
"""
self.wts = {}
self.stw = {}
# stochastically generated poem from Darwin's _On the Origin of Species_.
He often begins his selection,
Done nothing, and all the species of shells in the same genus have been checked.
Mainly distinctive of each species, has been victorious in a reversed direction.
But I believe the above effect.
Competition by having inhabited a protected station,
Its contingencies of extinction will tend to intersect.
Connect and except secondly by a rotation.
@hamilton
hamilton / rhymeless_demo.py
Created January 14, 2010 18:12
A short demo on how to use Rhymeless.
>>> from rhymeless import Rhymeless
>>> poem_generator = Rhymeless()
>>> book = open("books/on_the_origin_of_species.txt", "r")
>>> lines = []
>>> for line in book:
... lines.append(line)
...
>>> book = "".join(lines)
>>>
>>> # the book variable is just a huge string. I could also train
import numpy as np
import som
from grid import hexagonal_grid # comes with som repository
from distance import euclidean # also comes with the som repository
##### Create a funky, curved data set in 3 dimensions. #####
data = np.transpose(np.matrix([
np.random.normal(0,1,20000),
np.random.normal(0,1,20000),
np.random.normal(0,1,20000)
import lsh
lsh_machine = lsh.LSH(assignment_name="example")
# data is a dictionary of the form:
#{user_id: set([item_id1, item_id2, ...]), ...}
# Depending on the input size, training can take a while.
# But it will use all your cores to do so, and will
# automatically cache the data for assignment_name. This
@hamilton
hamilton / electronic_music.py
Created September 22, 2011 06:31
Downloads every track from "History of Electronic / Electroacoustic Music, 1937-2000"
import urllib2
import os
import re
from sgmllib import SGMLParser
print '-' * 80
print ' History of Electronic / Electroacoustic Music, 1937-2000 '
print '-' * 80
print
@hamilton
hamilton / formula.py
Created October 28, 2011 22:00
Implementing formula notation in python
# Here's a small experiment in hacking together a formula notation for
# Python, in the style of R. This is without reference to any matrices, but
# it's pretty straightforward to see how one might plug such a system into a
# matrix library.
# I bet this could easily extend to other R formula features.
class Predictor(object):
def __init__(self,label):
self.label = label
@hamilton
hamilton / css
Last active September 21, 2017 01:36
by-neighborhood
date,nbrhd,count
1997-01-01,Inner Richmond,121
1997-01-01,Japantown,7
1997-01-01,Glen Park,16
1997-01-01,Western Addition,45
1997-01-01,Outer Richmond,144
1997-01-01,Tenderloin,56
1997-01-01,Financial District/South Beach,6
1997-01-01,Excelsior,56
1997-01-01,Presidio Heights,36
@hamilton
hamilton / dataset.js
Last active October 11, 2017 05:32
a small dplyr-type clone in javascript
/*
Cloning dplyr in Javascript, sort of
====================================
Works on arrays of objects.
usage:
var transformation = DS.data(arrayOfObjects)
.standardize()