Added sampling_density to stats (replaces #1572)

This is a rebased and touched up version to fix #1572.