Hello,
yes this is true. According to the PyTorch documentation:
torch.rand returns a tensor filled with random numbers from a uniform distribution on the interval [0,1)
https://pytorch.org/docs/stable/torch.html#torch.rand 50
I would appreciate if you can explain the following. I am trying to figure out how the authors of the papers generate normal and uniform distribution:
“Gaussian Noise. The synthetic Gaussian noise dataset consists of 10,000 random 2D Gaussian
noise images, where each RGB value of every pixel is sampled from an i.i.d Gaussian distribution
with mean 0.5 and unit variance. We further clip each pixel value into the range [0, 1].
Uniform Noise. The synthetic uniform noise dataset consists of 10,000 images where each RGB
value of every pixel is independently and identically sampled from a uniform distribution on [0, 1].”

  
      
      GitHub
  
  
    

facebookresearch/odin 7

A simple and effective method for detecting out-of-distribution images in neural networks. - facebookresearch/odin


  
  
    
    
  
  


In the code they seemed to use this for generating Gaussian dataset:
        images = torch.randn(1, 3, 32, 32) + 0.5
        images = torch.clamp(images, 0, 1)

and this for generating Uniform dataset:
       images = torch.rand(1, 3, 32, 32)

According to your explanation the generation of the Uniform dataset is being correct.
What I would like to know is how they used the rand for the Gaussian dataset, although this discussion aligns with what they did:

  
      stackoverflow.com
  
  
      
    
  

  How to create a normal distribution in pytorch 7



  python, statistics, pytorch, linear-algebra



  asked by
  
  
    dq.shen
  
  on 12:46PM - 02 Jul 18 UTC


  
  
    
    
  
  


A simple option is to use the  randn  function from the base module. It creates a random sample from the standard Gaussian distribution. To change the mean and the standard deviation you just use addition and multiplication. Below I create sample of size 5 from your requested distribution.
import torch
torch.randn(5) * 0.5 + 4 # tensor([4.1029, 4.5351, 2.8797, 3.1883, 4.3868])

I am still little confused about how they could use “rand” function for generating Gaussian images?
Thank you