Loading...
Apply Xavier (Glorot) uniform initialization to a linear layer and verify its properties.
Xavier initialization sets weights from a uniform distribution U(-a, a) where a = gain * sqrt(6 / (fan_in + fan_out)). It's designed for layers with Sigmoid/Tanh activations.
The starter code creates an nn.Linear(6, 4) layer. Apply Xavier uniform initialization to the layer's weights.
The rest (computing statistics) is pre-filled.
Returns a dictionary with "weight_shape", "weight_mean", "weight_std", "weight_min", and "weight_max".
None
{'weight_shape': [4, 6], 'weight_mean': 0.0727, 'weight_std': 0.4648, 'weight_min': -0.6817, 'weight_max': 0.7337}xavier_uniform_test() starts by seeding the random number generator with torch.manual_seed(42) to ensure reproducibility.nn.Linear(6, 4), which has a weight matrix of shape (4,6), where 4 is the number of outputs (fan_out) and 6 is the number of inputs (fan_in).nn.init.xavier_uniform_ function is applied to the linear layer with default gain, which initializes the weights from a uniform distribution U(−a,a) where a=6+46=106=53.