Variance measures how much a single random variable (like position $p$) deviates from its own mean ($\mu_p$). It is the average of the squared distances from the mean:
$$Var(X) = \sigma_X^2 = \mathbb E\left[\left(X - \mathbb E\left[ X\right]\right)^2 \right]$$
The covariance between two random variables $X$ and $Y$ defines how they change together. It is the expected value of the product of their deviations:$$Cov(X,Y) = \sigma_{XY} = \mathbb E\left[\left(X - \mathbb E\left[ X\right]\right) \left(Y - \mathbb E\left[ Y\right]\right) \right]$$
What does the number tell us?
The sign of the covariance tells us the "direction" of the relationship:
Why this is the important of the Kalman Filter
In the Kalman Filter, we don't just want to know "Where is the car?" and "How fast is it?" independently. We want to know how an error in one propagates into the other.
If we have a set of $m$ measurements, we calculate the empirical covariance using the following formula:
$$cov(x,y) = \frac{\sum_{i=1}^{m} (x^{(i)} - \bar x)(y^{(i)} - \bar y )}{m-1}$$
Where:
from ipynb.fs.defs.plot_multivariate_Gaussian_distribution import plot_cov_matricies, plot_all_mvd
plot_cov_matricies()
Explanation:
While covariance tells us the direction of the relationship, its raw value is hard to interpret because it depends on the units of the variables.
To solve this, we use the Pearson Correlation Coefficient ($\rho$), which normalizes the covariance into a range from -1 to +1.
The formula is:
$$\rho_{xy} = \frac {cov(x, y)}{\sigma_x \sigma_y}$$
Where $\sigma_x$ and $\sigma_y$ are the standard deviations (the square roots of the variances).
Why this matters for the Kalman Filter:
In our 1D point mass ($p, v$), the correlation coefficient tells us how "flat" our uncertainty ellipse is:
When dealing with a multi-dimensional random variable, we use a covariance matrix to describe the relationships between the different dimensions (or components) of the variable.
Let's assume that such a vector $\mathbf x$ has three elements, i.e., $n=3$:
$$ \mathbf{x} = \begin{pmatrix} x_1 \\ x_2 \\ x_3 \end{pmatrix} $$ Then, the covariance matrix $\mathbf{C}$ is an $n \times n$ matrix (in this case, a $3 \times 3$ matrix):
$$ \mathbf{C} = \begin{pmatrix} cov(x_1,x_1) & cov(x_1,x_2) & cov(x_1,x_3) \\ cov(x_2,x_1) & cov(x_2,x_2) & cov(x_2,x_3) \\ cov(x_3,x_1) & cov(x_3,x_2) & cov(x_3,x_3) \end{pmatrix} $$
Key Properties:
The Multivariate Normal Distribution (MVD) is the generalization of the 1-dimensional bell curve to $n$ dimensions. For a state vector $\mathbf{x}$ of size $n$, the probability density function (PDF) is defined as:
$$f(\mathbf{x}) = \frac{1}{\sqrt{(2\pi)^n |\mathbf{C}|}} \exp\left(-\frac{1}{2}(\mathbf{x} - \hat{\mathbf{x}})^T \mathbf{C}^{-1} (\mathbf{x} - \hat{\mathbf{x}})\right)$$
Where:
In our 1D point mass model, the state vector is $\mathbf{x} = \begin{bmatrix} p \\ v \end{bmatrix}$. The distribution lives in a 2D plane where the "height" of the mountain at any $(p, v)$ coordinate tells us how likely that specific combination of position and velocity is.
For this case, the covariance matrix is:$$\mathbf{C} = \begin{bmatrix} \sigma_p^2 & \sigma_{pv} \\ \sigma_{vp} & \sigma_v^2 \end{bmatrix}$$
Meaning: $$\mathbf{C} = \begin{pmatrix} \text{Uncertainty in Position} & \text{Correlation between } p \text{ and } v \\ \text{Correlation between } v \text{ and } p & \text{Uncertainty in Velocity} \end{pmatrix}$$
with $\text{Correlation between } p \text{ and } v = \text{Correlation between } v \text{ and } p $
plot_all_mvd()
Explaination: