Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sample points in a circle are not uniformly distributed. #7

Closed
kwonoh opened this issue Sep 28, 2018 · 1 comment
Closed

Sample points in a circle are not uniformly distributed. #7

kwonoh opened this issue Sep 28, 2018 · 1 comment

Comments

@kwonoh
Copy link

kwonoh commented Sep 28, 2018

Hi,

Thank you for sharing the code.

In the original implementation, I found that the function generateZ in MNIST_SlicedWassersteinAutoEncoder_Circle.ipynb does not generate sample points in a circle uniformly.
The generated sample points are more dense at the center of a circle. This can affect the resulting latent space.

I made an issue in the original implementation repository.

For this PyTorch implementation, It can be easily fixed by applying sqrt on random radius samples from a uniform distribution in rand_cirlce2d.

def rand_cirlce2d(batch_size):
    """ This function generates 2D samples from a filled-circle distribution in a 2-dimensional space.
        Args:
            batch_size (int): number of batch samples
        Return:
            torch.Tensor: tensor of size (batch_size, 2)
    """
    # r = np.random.uniform(size=(batch_size)) # before
    r = np.sqrt(np.random.uniform(size=(batch_size))) # after
    theta = 2 * np.pi * np.random.uniform(size=(batch_size))
    x = r * np.cos(theta)
    y = r * np.sin(theta)
    z = np.array([x, y]).T
    return torch.from_numpy(z).type(torch.FloatTensor)

Here is an related article: Generate a random point within a circle (uniformly)

Best,
Oh-Hyun

@eifuentes
Copy link
Owner

thanks @kwonoh , the stack overflow link was very informative. i'll re-run the experiment with your suggested changes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants