# Back-of-the-envelope machine learning (specifically neural networks) calculations

There is a popular story regarding the back-of-the-envelope calculation performed by a British physicist named G. I. Taylor. He used dimensional analysis to estimate the power released by the explosion of a nuclear bomb, simply by analyzing a picture that was released in a magazine at the time.

I believe many of you know some nice back-of-the-envelope calculations performed in machine learning (more specifically neural networks). Can you please share them?

• Whasup with the pronoun change from singular first person to plural first person? – FreezePhoenix Apr 17 '18 at 15:09
• Yeah, not sure why I did that. – Charles Apr 17 '18 at 15:36

I have one to share. This is no formula, but a general thing I have noticed.

The number of neurons + neurons should be proportionate, in some way, to the complexity of the classification.

Although this is fairly basic and widely known, it has helped me in many times to consider one thing: how many at a minimum does it need?

• Are you sure you understood his question? – DuttaA Apr 17 '18 at 15:17
• @DuttaA now that you mention it, no. – FreezePhoenix Apr 17 '18 at 15:20
• He is asking something like approximations by NN apparently without very useful information..like the speed of a car from a photo or the pitch of an animal/instrument from its pic..something like that I guess..though im not sure – DuttaA Apr 17 '18 at 15:23
• @DuttaA I thought he was talking about semi-useful information about NN, AKA "tidbits". – FreezePhoenix Apr 17 '18 at 15:24
• It looks like my question may be a bit vague. I’ll try to add more constraints this afternoon if I have time. – Charles Apr 17 '18 at 15:41

I think a nice back-of-the envelope calculation is the intuition for exploding/vanishing gradients in RNNs:

Simplifications: diagonalisable weights, no non-linearities, 1 layer: $$h_t = W\cdot h_{t-1} + U\cdot x_t$$

Let $$L_t$$ be the loss at timestep $$t$$ with the total loss $$L = \sum_t L_t$$

$$\frac{\partial L_t}{\partial W} \sim= \sum_{k=1}^{t}\frac{\partial h_t}{\partial h_k}\times\alpha_{t, k}$$

Let's not care about terms regrouped in $$\alpha_{t, k}$$:

$$\frac{\partial h_t}{\partial h_k} = \prod_{k

So you can easily see that if the eigen values of $$W$$ (in the diagonal matrix $$D$$) are larger than $$1$$, the gradient will explode with time, and if they are smaller than $$1$$, it will vanish.

More detailed derivations in On the difficulty of training recurrent neural networks