Poisson Disk Sampling

I’ve borrowed (stolen) code from this iPython Notebook hosted on GitHub from the PyData NYC 2014 conference. I didn’t like the local call in the original code, so I made it object oriented. (Full disclosure: I’d never seen the local keyword before, so I stuck with the devil I knew.) I also wanted syntax reminiscent of scipy.stats, so I added a .rvs() method from extracting a sample from the Poisson disk object.

Continue reading Poisson Disk Sampling

Generating Sub-random Numbers

Sub-random numbers sort of look random, but they aren’t and they usually provide better coverage over an interval which is sometimes more important than having truly random data. For example, you wouldn’t use sub-random numbers for encryption, but they’d be great for performing Monte Carlo calculations. You can read more about them on the Wikipedia page for low discrepancy sequences.

Continue reading Generating Sub-random Numbers

Modeling Elevator Usage Pt. I

I was reading a book on modeling and the first problem in the first chapter asked the reader to model the use of an elevator during the morning rush at an office. There was the implicit assumption that employees would only be going up, and that there wouldn’t be any intra-level travel. I though this problem was interesting, so I thought I’d start to model this with Python. (I turned out that it was a rabbit hole.) I think that this is interesting for two reasons, you can model the wait-time for a very common situation, this can be abstracted to a more general constrained resource problem. This is my first whack:

Continue reading Modeling Elevator Usage Pt. I

Making and Changing into a Directory

This function, added to your shell profile, will allow you to create directories and cd into them in one fell swoop, without you having to type mkdir, and then cd ALL DAY. After looking around online, I like the name mkcd for this utility, because md makes me think of markdown.

For some reason, I couldn’t get this to work as a one-liner in my .zshrc file, but the listing below worked fine.

function mkcd () {
  mkdir -p $1
  cd $1
}

Note that the -p flag allows you to create a directory several directories deep at one go, without having to descend into them one at a time.

Visualizing Networks with Graphviz

In this post I’ll look at building graphs in Python using the graphviz module. This assumes that you’ve installed graphviz itself, which is easy enough on a Mac using homebrew. (Simply run: brew install graphviz.) I had two requirements for my graphs: I needed them to be directed, and I wanted to use the edge thickness to illustrate the strength of a connection. The first part was dead simple, but the second part required a little hunting.

Continue reading Visualizing Networks with Graphviz