First pass of the density probability algorithm

It kinda works. Better to commit than to leave this around. Feel free to
check it out and figure out the bugs.