ARGODEV-157: Calculate covariance matrix
Jira Issue
ARGODEV-157 (https://jira.ceh.ac.uk/browse/ARGODEV-157)
Python Implementation
Same as matlab implimentation, except variable names are now more descriptive, and the function will catch an exception if used incorrectly.
Testing
For this function I have written 6 unit tests:
- Test that the return value is an array
- Test that the function throws an error for bad inputs for arrays
- Test that we get a covariance matrix full of 1's if the input values are all indentical
- Test that we get a covariance matrix full of 0's if the inputs are all massively different to each other
- Test that entering points1 of size 4n and points2 of 4m returns a covariance matrix of size m*n
- Test that, if given specific values, we recieve the expected answer
Old Matlab Implementation
Uses the Squared Exponential (SE) covariance matrix:
SE(x1, x2) = exp{((x1 - x2) / l) ^ 2}
where x1 and x2 are two different data points of [latitude, longitude, date], and l is the characteristic length scale for each of these data points. This is to find out how similar two points are, and therefore how much influence they have over each other. An answer near 0 implies the points are incredibly different, whereas an answer near to 1 implies they are incredibly similar. As an example, if
- x1 = [-57.996, 53.195, 1974.0875]
- x2 = [-56.4902, 63.1170, 1987.0367]
- l = [4, 8, 20]
then
SE(x1, x2) = exp{((-57.996 - -56.4902) / 4) ^ 2
+ ((53.195 - 63.1170) / 8) ^ 2
+ ((1974.0875 - 1987.0367) / 20) ^ 2}
= 0.122562
This implies that the points aren't totally disimilar, but don't have much influence over each other. This is most likely because the difference in longitude is larger than the characteristic length scale in that direction.