MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / xavier_uniform_

Function xavier_uniform_

imperative/python/megengine/module/init.py:177–196  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

175
176
177def 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
199def xavier_normal_(tensor: Tensor, gain: float = 1.0) -> None:

Callers 1

reset_parametersMethod · 0.85

Calls 3

uniform_Function · 0.85
sqrtMethod · 0.45

Tested by

no test coverage detected