Skip to content

Instantly share code, notes, and snippets.

@leonidk
Created April 14, 2023 19:14
Show Gist options
  • Save leonidk/4c3d7ea5cb7aa9750c396874725c2be9 to your computer and use it in GitHub Desktop.
Save leonidk/4c3d7ea5cb7aa9750c396874725c2be9 to your computer and use it in GitHub Desktop.
Low Discrepency sequences in arbitrary dimensions
import numpy as np
class QuasiRandom():
def __init__(self,dim=1,seed=None):
self.dim = dim
self.x = np.random.rand(dim) if seed is None else seed
root_sys = [1] +[0 for i in range(dim-1)] + [-1,-1]
self.const = sorted(np.roots(root_sys))[-1].real
self.phi = np.array([1/(self.const)**(i+1) for i in range(dim)])
def generate(self,n_points=1):
res = np.zeros((n_points,self.dim))
for i in range(n_points):
res[i] = self.x = (self.x+self.phi)
return np.squeeze(res%1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment