MCPcopy Create free account
hub / github.com/ddbourgin/numpy-ml / glorot_uniform

Function glorot_uniform

numpy_ml/neural_nets/utils/utils.py:926–959  ·  view source on GitHub ↗

Initialize network weights `W` using the Glorot uniform initialization strategy. Notes ----- The Glorot uniform initialization strategy initializes weights using draws from ``Uniform(-b, b)`` where: .. math:: b = \\text{gain} \sqrt{\\frac{6}{\\text{fan_in} + \

(weight_shape, gain=1.0)

Source from the content-addressed store, hash-verified

924
925
926def glorot_uniform(weight_shape, gain=1.0):
927 """
928 Initialize network weights `W` using the Glorot uniform initialization
929 strategy.
930
931 Notes
932 -----
933 The Glorot uniform initialization strategy initializes weights using draws
934 from ``Uniform(-b, b)`` where:
935
936 .. math::
937
938 b = \\text{gain} \sqrt{\\frac{6}{\\text{fan_in} + \\text{fan_out}}}
939
940 The motivation for Glorot uniform initialization is to choose weights to
941 ensure that the variance of the layer outputs are approximately equal to
942 the variance of its inputs.
943
944 This initialization strategy was primarily developed for deep networks with
945 tanh and logistic sigmoid nonlinearities.
946
947 Parameters
948 ----------
949 weight_shape : tuple
950 The dimensions of the weight matrix/volume.
951
952 Returns
953 -------
954 W : :py:class:`ndarray <numpy.ndarray>` of shape `weight_shape`
955 The initialized weights.
956 """
957 fan_in, fan_out = calc_fan(weight_shape)
958 b = gain * np.sqrt(6 / (fan_in + fan_out))
959 return np.random.uniform(-b, b, size=weight_shape)
960
961
962def glorot_normal(weight_shape, gain=1.0):

Callers

nothing calls this directly

Calls 1

calc_fanFunction · 0.85

Tested by

no test coverage detected