Implement He weight initialization for neural networks. This initialization is designed for layers using ReLU activations and accounts for the fact that ReLU zeros out half of the neurons.
import numpy as np
def he_normal(fan_in: int, fan_out: int) -> np.ndarray:
std = np.sqrt(2.0 / fan_in)
return np.random.normal(0, std, size=(fan_in, fan_out))
def he_uniform(fan_in: int, fan_out: int) -> np.ndarray:
limit = np.sqrt(6.0 / fan_in)
return np.random.uniform(-limit, limit, size=(fan_in, fan_out))