ganhacks icon indicating copy to clipboard operation
ganhacks copied to clipboard

Sampling from a sphere instead of a cube

Open mgarbade opened this issue 8 years ago • 3 comments

Especially the trick number 3 (sampling z from a sphere) sounds interesting to me, but I'm unsure how it should be implemented.
Is it just that I need to normalize my z vector to have unit length such that it lies on the surface of a hyper sphere?
If not is there some special function to sample points from inside a hypersphere in python?
Is there a repository where these ganhacks are already implemented (for dcgan)?

mgarbade avatar Nov 29 '17 08:11 mgarbade

you can find slerp code in this comment https://github.com/soumith/dcgan.torch/issues/14#issuecomment-199171316

soumith avatar Nov 29 '17 15:11 soumith

As far as I understand this the slerp code is only for interpolating between two points on a hypersphere. Isn't it also necessary to replace the z vector that is used as input to the generator during dcgan training?
Right now I generate z like this:

batch_z = np.random.uniform(-1, 1, [batch_size, z_dim]).astype(np.float32)

mgarbade avatar Nov 29 '17 15:11 mgarbade

You should also sample from a normal distribution. Just use np.random.normal

alexrakowski avatar Jan 08 '18 13:01 alexrakowski