r"""Fills tensor with random values sampled from :math:`\mathcal{U}(-a, a)` where .. math:: a = \text{gain} \times \sqrt{\frac{6}{\text{fan_in} + \text{fan_out}}} Also known as Glorot initialization. Detailed information can be retrieved from `Understanding the difficulty
(tensor: Tensor, gain: float = 1.0)
| 175 | |
| 176 | |
| 177 | def xavier_uniform_(tensor: Tensor, gain: float = 1.0) -> None: |
| 178 | r"""Fills tensor with random values sampled from :math:`\mathcal{U}(-a, a)` |
| 179 | where |
| 180 | |
| 181 | .. math:: |
| 182 | |
| 183 | a = \text{gain} \times \sqrt{\frac{6}{\text{fan_in} + \text{fan_out}}} |
| 184 | |
| 185 | Also known as Glorot initialization. Detailed information can be retrieved from |
| 186 | `Understanding the difficulty of training deep feedforward neural networks` - |
| 187 | Glorot, X. & Bengio, Y. (2010). |
| 188 | |
| 189 | Args: |
| 190 | tensor: tensor to be initialized. |
| 191 | gain: scaling factor for :math:`a`. |
| 192 | """ |
| 193 | fan_in, fan_out = calculate_fan_in_and_fan_out(tensor) |
| 194 | std = gain * math.sqrt(2.0 / float(fan_in + fan_out)) |
| 195 | a = math.sqrt(3.0) * std |
| 196 | uniform_(tensor, -a, a) |
| 197 | |
| 198 | |
| 199 | def xavier_normal_(tensor: Tensor, gain: float = 1.0) -> None: |
no test coverage detected