Created
February 2, 2023 13:46
-
-
Save j-c-cook/50140055ff4290675a5294652af1c1d4 to your computer and use it in GitHub Desktop.
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
import matplotlib.pyplot as plt | |
""" | |
The Halton sequence is a generalization of the one-dimensional Van der Corput | |
sequence. | |
https://en.wikipedia.org/wiki/Halton_sequence | |
https://en.wikipedia.org/wiki/Van_der_Corput_sequence | |
""" | |
def van_der_corput(n, base=2): | |
q = 0 | |
bk = 1. / base | |
while n > 0: | |
q += (n % base) * bk | |
n //= base | |
bk /= base | |
return q | |
def main(): | |
s1 = [van_der_corput(i, base=2) for i in range(1, 257)] | |
s2 = [van_der_corput(i, base=3) for i in range(1, 257)] | |
fig = plt.figure() | |
ax = fig.add_subplot() | |
ax.scatter(s1, s2) | |
ax.set_xlabel('x') | |
ax.set_ylabel('y') | |
fig.tight_layout() | |
fig.show() | |
plt.close(fig) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment