algebratheory

why

For 2 n-dimensional unit vectors and

  • The of the angle between them is
  • By the Central Limit Theorem, approximates a normal distribution with mean zero as
  • So as , the is more likely to be around the mean which is 0, which means the 2 vectors are more likely to be orthogonal

notes

  • The vector must be sample from normal distribution, not uniform distribution. So one should use np.rand.normal and torch.normal instead of np.rand.random and torch.random

    generate random unit vectors

    geometrystatistics

    How

    • Draw from a standard distribution for each dimension.
    • Do not draw from a uniform distribution.

    Implementation

    import numpy as np
    import torch
     
    # numpy
    v = np.random.normal(0, 1, size)
     
    # torch
    v = torch.normal(torch.tensor([0.0] * size), torch.tensor([1.0] * size))

    Why that works

    • Considering a 2D space, the probability of a point being at is
    • The PDF for the standard distribution is , which is roughly in the form of
    • Thus is in the form of , which is a function of the distance to the origin
    • So the resulting distribution is radially symmetric around the origin

    An intuitive explanation of why uniform sampling don’t work

    • Considering a 2D space, uniformly sampling from both dimension results in a square population
    • Whereas a random distribution in 2D space should be a circle
    • This is called the corner effect
    Link to original