Minor tidbit on what mean absolute deviation is.


This is a trivial tidbit that is useful to have as a quick glance.

The mean absolute deviation which is essentially just

t = torch.tensor([1, 2,3, 5, 68 ]).float(); 
m = t.mean(); 
(t-m).abs().mean()

is less susceptible to outliers than standard deviation.

%load_ext autoreload
%autoreload 2
%matplotlib inline
%reload_ext autoreload
from torch import tensor
t = torch.tensor([1, 2,3, 5, 68 ]).float(); t
tensor([ 1.,  2.,  3.,  5., 68.])
m = t.mean(); m
tensor(15.8000)

Variance and Standard deviation


Variance

\[\frac{\sum(x − x_{mean})^2}{(n)}\]


Standard deviation

\[σ =\sqrt\frac{\sum(x −x_{mean})^2}{n}\]
variance = (t-m).pow(2).mean()
mean_absolute_deviation = (t-m).abs().mean()
standard_deviation = (t-m).pow(2).mean().sqrt()
variance, mean_absolute_deviation, standard_deviation
(tensor(682.9600), tensor(20.8800), tensor(26.1335))

Variance in a different form

(t-m).pow(2).mean() == (t*t).mean() - (m*m)
variance2 = (t*t).mean() - (m*m)
torch.allclose(variance, variance2)
True