Source code for https://arxiv.org/abs/1405.7698