Initialize network weights `W` using the Glorot normal initialization strategy. Notes ----- The Glorot normal initializaiton initializes weights with draws from TruncatedNormal(0, b) where the variance `b` is .. math:: b = \\frac{2 \\text{gain}^2}{\\text{fan_in} +
(weight_shape, gain=1.0)
| 960 | |
| 961 | |
| 962 | def glorot_normal(weight_shape, gain=1.0): |
| 963 | """ |
| 964 | Initialize network weights `W` using the Glorot normal initialization strategy. |
| 965 | |
| 966 | Notes |
| 967 | ----- |
| 968 | The Glorot normal initializaiton initializes weights with draws from |
| 969 | TruncatedNormal(0, b) where the variance `b` is |
| 970 | |
| 971 | .. math:: |
| 972 | |
| 973 | b = \\frac{2 \\text{gain}^2}{\\text{fan_in} + \\text{fan_out}} |
| 974 | |
| 975 | The motivation for Glorot normal initialization is to choose weights to |
| 976 | ensure that the variance of the layer outputs are approximately equal to |
| 977 | the variance of its inputs. |
| 978 | |
| 979 | This initialization strategy was primarily developed for deep networks with |
| 980 | :class:`~numpy_ml.neural_nets.activations.Tanh` and |
| 981 | :class:`~numpy_ml.neural_nets.activations.Sigmoid` nonlinearities. |
| 982 | |
| 983 | Parameters |
| 984 | ---------- |
| 985 | weight_shape : tuple |
| 986 | The dimensions of the weight matrix/volume. |
| 987 | |
| 988 | Returns |
| 989 | ------- |
| 990 | W : :py:class:`ndarray <numpy.ndarray>` of shape `weight_shape` |
| 991 | The initialized weights. |
| 992 | """ |
| 993 | fan_in, fan_out = calc_fan(weight_shape) |
| 994 | std = gain * np.sqrt(2 / (fan_in + fan_out)) |
| 995 | return truncated_normal(0, std, weight_shape) |
| 996 | |
| 997 | |
| 998 | def truncated_normal(mean, std, out_shape): |
nothing calls this directly
no test coverage detected