Created
October 28, 2024 06:45
-
-
Save jgs03177/0194f2fb6cdc0f66bb0c2979b83a63d6 to your computer and use it in GitHub Desktop.
uniform sample from d-ball
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
def uniformsample_dball(npoint, nd=2): | |
# https://extremelearning.com.au/how-to-generate-uniformly-random-points-on-n-spheres-and-n-balls/ | |
# # method 20 | |
eps = 1e-12 | |
u = np.random.normal(0,1, (npoint,nd)) | |
norm = np.sum(u ** 2, axis=1) ** 0.5 | |
r = np.random.random(npoint)**(1.0/nd) | |
x = (r / (norm+eps)).reshape((-1,1)) * u | |
return x | |
def uniformsample_dball2(npoint, nd=2): | |
# https://extremelearning.com.au/how-to-generate-uniformly-random-points-on-n-spheres-and-n-balls/ | |
# # method 22 | |
u = np.random.normal(0,1, (npoint,nd+2)) | |
norm = np.sum(u ** 2, axis=1) ** 0.5 | |
x = (u/norm.reshape((-1,1)))[:,:nd] | |
return x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment