# variance of weights in a loss function

I would like to use variance of weights from a NN layer in my loss function. I mean:

$$L=\frac{1}{2}\sum(y-\hat{y})^2 - \alpha var(W)$$

And the question:

Is it possible to have a gradient from weights variance? Does it make any sense?

$\frac{1}{N}\sum&space;(W_i-\mu&space;)^2$