How can I measure "volatility" of a two dimensional matrix?

86 Views Asked by At

With possible null values as well. What would be the best way to measure volatility of something like this? Imagine this is some height to geographical locations, so not only difference in values but proximity should be considered in some respect as well to measure volatility.

1, 5, 5, 7, 9
2, 2, 1, NULL, 2
6, 2, 1, 6, 6
1, 1, 2, 10, 25

My goal is to simply have some consistent method of measuring 'volatility' when given two dimensional matrices such as this. Open to any ideas on how that could be derived. Math isn't my strong suit, would love suggestions or even just a direction in which to do further research.

These aren't exact in any sense, but just to give a sense of what I'm hoping to achieve. It should look at the difference in two points to get a value, then adjust the value by the proximity of the two points (nearby matters more), and all of it combines to a singular volatility metric.

1,1,1,1
1,1,1,1
1,1,1,1
1,1,1,1

Could have a volatility score of 0

1,1,1,1
1,2,1,1
1,1,1,1
1,1,1,1

Could have a volatility score of .1

1,1,1,1
1,20,1,1
1,1,1,1
1,1,1,1

Could have a volatility score of 1

5,1,1,1
1,5,1,8
1,1,1,1
7,1,9,1

Could have a volatility score of 3

2

There are 2 best solutions below

0
On

OK. So you've just invented the "Laplacian" (https://en.wikipedia.org/wiki/Laplacian_matrix) more or less. The Laplacian of a matrix $M$ gives you the per-location "volatility" (i.e., for a $10 \times 10$ input matrix, $M$, you get a $10 \times 10$ output matrix $Q$ where entry $(i,j)$ in the output tells you the volatility associated with entry $(i,j)$ in the input.

If you want a notion of "total volatility", it's tempting to just sum up the entries of $Q$, but since these entries can be either negative or positive, that's a bad idea. Far better in general is to sum up the squares of the entries of $Q$, which will give you a nonnegative number, $u$. You can then take the square-root of $u$, and this would be called the "root mean square laplacian" and probably correspond to your notion of volatility.

Lots of programming languages (especially ones like Matlab) have a built-in Laplacian computation. But the formula at position $(i,j)$ is pretty simple: you take $$ Q(i, j) = \frac{M(i-1, j) + M(i+1, j) + M(i, j-1) + M(i, j+1)}{4} - M(i, j). $$ There's a problem with this "at the edges" (where going one step to the left of $(i, j)$ might take you off the edge of the matrix). One solution/hack is to say that $Q(i, j)$ is defined to be the difference between the average of the neighbors of $M(i, j)$ and $M(i,j)$ itself, where the "average" for most points is an average of four neighbors, but at edges you have just three, and at corners just two.

0
On

Perhaps you would like to compute the "total variation" of a given 2D array. (Total variation is often useful in image processing, where our 2D array represents an image.) If $x$ is an $m \times n$ matrix, the total variation of $x$ is $$\sum_{\substack{1 \leq i < m \\ 1 \leq j < n }} | x_{i+1,j} - x_{ij }| + | x_{i,j+1} - x_{ij}|. $$