How to generate random uniform points on (hyper) ellipsoid?
Note: Rejection methods are very inefficient specially in higher dimension. Check the ratio of volumes (box VS its inscripted ellipsoid) as the dimension grows.
Note 2: Here's an elegant way of generating uniform distribution on a sphere, using a Gaussian vector. I guess I need do modify the norm to obtain a uniform distribution on an ellipsoid.
import numpy as np
import matplotlib.pylab as plt
fig = plt.figure(figsize=(7, 7))
ax = fig.add_subplot(projection='3d')
dim = 3
x = np.random.normal(0,1,(1100,dim))
z = np.linalg.norm(x, axis=1)
z = z.reshape(-1,1).repeat(x.shape[1], axis=1)
y = x/z * 1 * np.sqrt(dim)
ax.scatter(y[:,0], y[:,1], y[:,2]);
Update : The results with Cholesky factor decomposition.
dim = 2 # test in 2D
r=1
A = np.array([[1/10**2, 0],
[0, 1/4**2]])
L = np.linalg.cholesky(A).T
x = np.random.normal(0,1,(200,dim))
z = np.linalg.norm(x, axis=1) dimension
z = z.reshape(-1,1).repeat(x.shape[1], axis=1)
y = x/z * r #uniform points on a sphere
y_new = np.linalg.inv(L) @ y.T # expected transformation
plt.figure(figsize=(5,5))
plt.plot(y[:,0],y[:,1], linestyle="", marker='o', markersize=2)
plt.plot(y_new.T[:,0],y_new.T[:,1], linestyle="", marker='o', markersize=5)
plt.gca().set_aspect(1)
plt.grid()



UPDATEsections. Feel free to refine the whole question and if comments are orphaned, so be it. Also, please post code in ASCII form using the{}instead of taking a screenshot of the code snippet. If someone would like to replicate your experiment, why should that someone write the whole code snippet again? – Rodrigo de Azevedo Nov 16 '22 at 14:19