Search code examples
pythonnumpymultidimensional-arrayrandomhypercube

uniform sampling from a ellipsoidal confidence region


I have a 4-dimensional ellipsoid from which I want to draw samples uniformly. I thought of an approach using a hyper cube around the ellipsoid. We can draw a sample from it and check if it is in the ellipsoid. But the volume ratio of hypercube and ellipsoid in 4 dimensions is 0.3. That means I have only 30 percent success rate. As my algorithm has speed issues I don't want to use this approach. I have also been looking at Inverse transform sampling. Can you give me an insight on how to do this with a 4-dimensional ellipsoid ?


Solution

  • You can transform your hyper ellipsoid to a sphere.

    So the given algorithm is valid for the sphere but can easily transformed to your ellipsoid.

    1. Draw from a gaussian distribution N(0,1) for all coordinates x1, to x4. x=[x1,x2,x3,x4].
    2. Normalize the vector x. ==> You have obtained uniformly distributed vectors on the surface.
    3. Now, draw a radius u from [0,1] for the inner point from unit sphere
    4. p=u**(1/4)*x is the uniformly distributed vector within the 4 dimensional unit sphere.