How can we transform a non uniform sampling method to a uniform one?
- Given a function
$f: x \mapsto y$ - find
$g: x \mapsto x'$ - where
$D_g=I_g=D_f$ - such that
$g(D)=D$ - and
$J_{f}(x')J_{g}(x)|D|=|I|$ - where functional
$J_{f}(x) := \sqrt{\bigg |\det \bigg ( \frac{\partial f}{\partial x}^T \frac{\partial f}{\partial x} \bigg ) \bigg|}$
When sampling points from some sort of geometrical object, I often want to do so uniformly, e.g. "Pick a random point from a sphere.". For a sphere, this is not that hard to do with, for example, rejection sampling. However, I was playing around with the spiral dataset (typically use in ML), where my ad-hoc approach of sampling the points, gave a large bias for the points close to the center. Rejection sampling in this sceneario is impossible (1D manifold embedded in 2D and all...), and hence we need another solution. Basically what we want is, given a function and a domain, how can we alter the function, such that the resulting image is uniformly dense when sampling uniformly from the domain. The approach we will take in this repo, is to find a new function which maps from the domain to itself in such a way that the final image has a uniform density (see header image).
Some examples
This is a classical example. We want to sample points from a disc of radius
Given the radius, there should be no bias for any particular angle, and we will hence set
Adding the constraint that
And our final function:
Implementing this on an actual sampler gives the following results where the above image shows the final sampling, and the lower the intermediate step after just the
The spiral example is the actual problem I wanted to solve. Here we have an ad-hoc function
Giving us the equation:
Here
Again implementing this on a real sampler, this time with a couple numerical approximations of the
Points in a trianlge can be naivly generated by
We cab then plotting the result in a similar fashion as the header of this project:
Let
As stated above, this must be true for all
Before we dive into that question, let's talk about the area/volume of a simpler object: the parallelotope. This is the object you get by looking at the span of a set of vectors and has the nice property that the signed volume is equal to the determinant of these vectors. However, if your parallelotope is of dimension
If we now look at a general case, like the image below, where we have a vector from
Note that
We can do a similiar thing for the transformed version of the vector and get
Carying out a similir argument for the image's parallelotope we get:
Now, let's get back to our problem. From the above explination, we can see that our domain area elemtn
Substituting the expanded differential forms into our previous equation gives the final equation:







