uniform distribution
가끔 파라미터를 uniform distribution으로 초기화하는 경우가 있다. 어떤 원리로 그게 uniform 해지는지 문서를 살펴보았으나
https://pytorch.org/docs/stable/distributions.html#uniform
Probability distributions - torch.distributions — PyTorch 2.1 documentation
Probability distributions - torch.distributions The distributions package contains parameterizable probability distributions and sampling functions. This allows the construction of stochastic computation graphs and stochastic gradient estimators for optimi
pytorch.org
그냥 사용법만 써져 있었다.
stackoverflow에서 검색해보니
How to get a uniform distribution in a range [r1,r2] in PyTorch?
I want to get a 2-D torch.Tensor with size [a,b] filled with values from a uniform distribution (in range [r1,r2]) in PyTorch.
stackoverflow.com
이 같은 글이 있었고 계산식이 2개로 나뉘어 있었지만 pytorch 문서에서 Uniform 클래스의 설명을 보았을 때 추측해보면 주석에 써놓은 계산으로 uniform distribution을 구현한 것으로 예상된다.
# (r2 - r1) * torch.rand(a, b) + r1
# torch.FloatTensor(a, b).uniform_(r1, r2)
torch.FloatTensor(2, 6).uniform_(3, 5)
tensor([[3.8057, 3.8924, 4.9072, 4.6287, 4.5982, 3.0626],
[4.7080, 3.2708, 4.1505, 4.0639, 4.5821, 4.7681]])