Last active
December 3, 2019 13:36
-
-
Save ncruces/b4ee29d37d2ea88a8775acb56a7a6975 to your computer and use it in GitHub Desktop.
2D Hammersley low-discrepancy sequence
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function hammersley(n, bias) { | |
if (isNaN(bias)) bias = (1-n)/(n+n); | |
function phi2(n) { | |
let r = 0; | |
let b = n.toString(2); | |
for (let i = 0; i < b.length; ++i) { | |
if (Number(b[i])) r += 1/(1 << b.length-i); | |
} | |
return r; | |
} | |
let r = []; | |
for (let i = 0; i < n; i++) { | |
r.push([i/n+bias, phi2(i)+bias]); | |
} | |
return r; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment