Glorot, Bordes and Bengio (2011) report that rectifier networks are truly sparse: a large fraction of their hidden activations are exactly zero, not just small. Smooth units such as softplus and tanh almost never output an exact zero. Run a batch through a stack of hidden layers and measure this sparsity.
Implement exact_sparsity(X, weights, biases, activation).
X: input batch, shape (N, n_0), one example per row.weights[l]: shape (n_{l+1}, n_l) and biases[l]: shape (n_{l+1},), for hidden layers ().activation: "rectifier", "softplus" or "tanh".Each hidden layer computes, for each example (row) of the previous layer,
with for the rectifier, for softplus and for tanh. The first layer receives the rows of X.
Output: a dict with
"per_layer": for each hidden layer, the fraction of its outputs that are exactly 0.0."average": the mean of the "per_layer" fractions (each layer counts equally, whatever its width)."active": for each hidden layer, a list of ints: how many units of that layer are non-zero on each example.== 0.0, not with a tolerance: the point is to count true zeros.