# Distance or Similarity metric for 2D frequency data maps

I want to compare the distance/similarity of 2D flood frequency data maps. The maps are square with YxY grid size and in each cell of the map is stored its flood frequency. For example in a 5x5 grid we may have this two flood frequency maps of the same area for the past 10 years, where we observe how many times the corresponding cell/place flooded:

0 0 0 0 0       0 0 0 0 0
0 1 2 1 0       0 2 3 1 0
0 4 6 2 0       9 9 8 7 6
0 1 2 1 0       0 2 3 1 0
0 4 6 2 0       9 9 8 7 6

I can easily transform these maps into a probability map that will add up to one. So the question now is what is the most meaningful way of comparing these kind of maps with each other to find their (dis)similarity. A distance metric taken from information theory field like JSD or L1 (and many others) or a similarity metric taken from the image processing field like the area under ROC (and many others)?

• I don't quite get what you mean by "maps", but if what you realy want is to compare visually several frequency (or other contingency) tables, here is two choices among a few: (1) multiple (3-way) correspondence analysis; (2) individual-scaling model of multidimensional unfolding. Both are quite advanced statistical techniques, so you might prefer easier ways, such as mosaic, paneled, etc. charts showing frequencies. – ttnphns Oct 18 '13 at 11:03
• By "maps" I mean 2D data that have geographic interpretation. I'm not a statistician but I think that what you're proposing will help to find some patterns inside these maps and not help me to compare one with another to find their (dis)similarity. Maybe I was not clear enough in my post so I'll update it with some more info. – bognick Oct 19 '13 at 15:37

Let's define a kernel that is sensitive to translation, rotation and scaling of the input grid.

$f(x,y) ={(2\mu_x\mu_y + c_1)(2\sigma_{xy}+c_2)\over{(\mu_x^2+\mu_y^2+c_1)(\sigma_x^2+\sigma_y^2+c_2)}}$

Where $c_1$ and $c_2$ are some small constant times the range of the data.

The guts of this function is the covariance between data, $\sigma_{xy}$. The more absolutely similar our values are, the higher this function goes.

It's a valid mercer kernel, which means it's a good distance function for many purposes.

Plotting your data below, we see some vaguely similar pattern over the grid $(1,2)$ to $(2,4)$.

With data indexed in a grid pattern, we aren't interested in small translations of the inputs. One such way to overcome these translations is to average over the many small shifts in the grid. This calculation wrt to above distance function is known as Structural Similarity Index.

For observation $A$ here's 9 3x3 square shifts in the grid.

We do the same for $B$, then compute the SSIM. One way to look at the impact of different parts of the grid is to look at the local gradient of SSIM wrt inputs.

Shown below is the gradient of SSIM computed over windows and not.

$SSIM(3) = 0.46375$

$SSIM = 0.30504$

If you want to discard the information about scaling, we can $x\over{\sum_i x_i}$, yielding the following gradient.

$SSIM_{normed}(3) = 0.72070$

$SSIM_{normed} = 0.74618$

The calculations were done with Skimage.measure.structural_similarity