# Math notes

From raju

### dummy

This applies when profiling code. If you have a hotspot that takes 99% of the time and optimize it until your whole program is twice as fast, now that hotspot takes 98% of the time.

#### likelihood function

The definition of the likelihood function for continuous case:

$\mathcal{L}(\theta | x) = p_{\theta}(x)$

The left term means “the likelihood of the parameters $\theta$, given data $x$”.

Here the notation $\mathcal{L}(\cdot | \cdot)$ does not mean the same as the conditional notation. Another representation of the likelihood that is often used is $\mathcal{L}(x; \theta)$, which is better in the sense that it makes it clear that it’s not a conditional, however, it makes it look like the likelihood is a function of the data and not of the parameters.

#### averages

average of squares > square of averages

ex:- for [3,4]
average of squares = (3**2 + 4**2) / 2 = 12.5
square of averages = ((3 + 4)/2)**2 = 3.5**2 = 12.25

#### simplifications I came across

$\frac{x}{(1-\alpha x)(1-\beta x)} = \frac{1}{\alpha-\beta}\left[ \frac{1}{1-\alpha x} - \frac{1}{1-\beta x}\right]$

### mental math

#### convert from miles to km

Double four times and divide by ten as soon as possible (i.e. the first time you see a zero on the end, drop it). This amounts to multiplying it by 1.6. Actual formula is 1 mi = 1.60934 km.

Ex:- 30 mph -> 3 (drop the zero) -> 6 -> 12 -> 24 -> 48 kmph.

No need to count how many times you are doubling. Look for something between 1x and 2x of the original number.

Ex:- 135 mph -> 270 -> 27 -> 54 -> 108 (keep going, less than 135) -> 216 kmph (stop here, less than 2* 135 = 270)

#### pounds to kilos

Divide by 2, less 10%. This amounts to multiplying it by 0.45. Actual formula is 1 lb = 0.453592 kg

Ex:- 160 lbs = 80 - 8 = 72 kg

#### kilos to pounds

Multiple by 2, add 10%. This amounts to multiplying it by 2.2. Actual formula is 1 kg = 2.20462 lbs