Como avaliar a semelhança de dois histogramas?

33

Dados dois histogramas, como avaliamos se são semelhantes ou não?

É suficiente simplesmente olhar para os dois histogramas? O mapeamento simples de um para um tem o problema de que, se um histograma for ligeiramente diferente e ligeiramente alterado, não obteremos o resultado desejado.

Alguma sugestão?

Mew 3.4
fonte
2
O que significa "similar"? O teste do qui-quadrado e o teste KS, por exemplo, testam se dois histogramas são quase idênticos. Mas "semelhante" pode significar "ter a mesma forma", ignorando quaisquer diferenças de localização e / ou escala. Você poderia esclarecer sua intenção?
whuber

Respostas:

8

Um artigo recente que pode valer a pena ser lido é:

Cao, Y. Petzold, L. Limitações de precisão e medição de erros na simulação estocástica de sistemas de reação química, 2006.

Embora o foco deste artigo esteja na comparação de algoritmos de simulação estocástica, essencialmente a idéia principal é como comparar dois histogramas.

Você pode acessar o pdf na página do autor.

csgillespie
fonte
Oi, é um bom papel, obrigado por dar link em pdf .. Certamente vou passar por este artigo .. #
Mew 3.4
12
Em vez de fornecer uma referência, seria bom se você resumisse os principais pontos do artigo. Os links morrem; portanto, no futuro, sua resposta poderá se tornar inútil para os não assinantes deste periódico (e a grande maioria da população humana são os não assinantes).
Tim
27

Existem várias medidas de distância entre dois histogramas. Você pode ler uma boa categorização dessas medidas em:

K. Meshgi e S. Ishii, "Expandindo o histograma de cores com grade para melhorar a precisão do rastreamento", em Proc. de MVA'15, Tóquio, Japão, maio de 2015.

As funções de distância mais populares estão listadas aqui para sua conveniência:

  • eu0 0 Distância L 0 ou Hellinger

Deu0 0=Euh1(Eu)h2(Eu)

  • eu1Distância L 1 , Manhattan ou City Block

Deu1=Eu|h1(Eu)-h2(Eu)|

  • eu=2 ou distância euclidiana

DL2=i(h1(i)h2(i))2

  • Distância L ou Chybyshev

Deu=mumaxEu|h1(Eu)-h2(Eu)|

  • L p ou distância fracionária (parte da família de distância Minkowski)p

Deup=(Eu|h1(Eu)-h2(Eu)|p)1/p e0 0<p<1

  • Interseção do histograma

D=1i(min(h1(i),h2(i))min(|h1(i)|,|h2(i)|)

  • Distância Cosine

DCO=1ih1(i)h2(i)

  • Distância Canberra

DCB=i|h1(i)h2(i)|min(|h1(i)|,|h2(i)|)

  • Pearson's Correlation Coefficient

DCR=i(h1(i)1n)(h2(i)1n)i(h1(i)1n)2i(h2(i)1n)2

  • Kolmogorov-Smirnov Divergance

DKS=maxi|h1(i)h2(i)|

  • Match Distance

DMA=i|h1(i)h2(i)|

  • Cramer-von Mises Distance

DCM=i(h1(i)h2(i))2

  • χ2 Statistics

Dχ2=i(h1(i)h2(i))2h1(i)+h2(i)

  • Bhattacharyya Distance

DBH=1ih1(i)h2(i) & hellinger

  • Squared Chord

DSC=i(h1(i)h2(i))2

  • Kullback-Liebler Divergance

DKL=ih1(i)logh1(i)m(i)

  • Jefferey Divergence

DJD=i(h1(i)logh1(i)m(i)+h2(i)logh2(i)m(i))

  • Earth Mover's Distance (this is the first member of Transportation distances that embed binning information A into the distance, for more information please refer to the abovementioned paper or Wikipedia entry.

DEM=minfiji,jfijAijsumi,jfij jfijh1(i),jfijh2(j),i,jfij=min(ih1(i)jh2(j)) and fij represents the flow from i to j

  • Quadratic Distance

DQU=i,jAij(h1(i)h2(j))2

  • Quadratic-Chi Distance

DQC=i,jAij(h1(i)h2(i)(cAci(h1(c)+h2(c)))m)(h1(j)h2(j)(cAcj(h1(c)+h2(c)))m) and 000

A Matlab implementation of some of these distances is available from my GitHub repository: https://github.com/meshgi/Histogram_of_Color_Advancements/tree/master/distance Also you can search guys like Yossi Rubner, Ofir Pele, Marco Cuturi and Haibin Ling for more state-of-the-art distances.

Update: Alternative explaination for the distances appears here and there in the literature, so I list them here for sake of completeness.

  • Canberra distance (another version)

DCB=i|h1(i)h2(i)||h1(i)|+|h2(i)|

  • Bray-Curtis Dissimilarity, Sorensen Distance (since the sum of histograms are equal to one, it equals to DL0)

DBC=12ih1(i)=h2(i)ih1(i)+ih2(i)

  • Jaccard Distance (i.e. intersection over union, another version)

DIOU=1imin(h1(i),h2(i))imax(h1(i),h2(i))

Kourosh Meshgi
fonte
Welcome to our site! Thank you for this contribution.
whuber
Here is the paper link: mva-org.jp/Proceedings/2015USB/papers/14-15.pdf
neves
Thanks, a list is wonderful, while it doesn't allow to create a comparison operator for histogram, e.g. to say that hist1 < hist2
Olha Pavliuk
22

The standard answer to this question is the chi-squared test. The KS test is for unbinned data, not binned data. (If you have the unbinned data, then by all means use a KS-style test, but if you only have the histogram, the KS test is not appropriate.)

David Wright
fonte
You are correct that the KS test is not appropriate for histograms when it is understood as a hypothesis test about the distribution of the underlying data, but I see no reason why the KS statistic wouldn't work well as a measure of sameness of any two histograms.
whuber
An explanation of why the Kolmogorov-Smirnov test is not appropriate with binned data would be useful.
naught101
This may not be as useful in image processing as in statistical fit assessment. Often in image processing, a histogram of data is used as a descriptor for a region of an image, and the goal is for a distance between histograms to reflect the distance between image patches. Little, or possibly nothing at all, may be known about the general population statistics of the underlying image data used to get the histogram. For example, the underlying population statistics when using histograms of oriented gradients would differ considerably based on the actual content of the images.
ely
1
naught101's question was answered by Stochtastic: stats.stackexchange.com/a/108523/37373
Lapis
10

You're looking for the Kolmogorov-Smirnov test. Don't forget to divide the bar heights by the sum of all observations of each histogram.

Note that the KS-test is also reporting a difference if e.g. the means of the distributions are shifted relative to one another. If translation of the histogram along the x-axis is not meaningful in your application, you may want to subtract the mean from each histogram first.

Jonas
fonte
1
Subtracting the mean changes the null distribution of the KS statistic. @David Wright raises a valid objection to the application of the KS test to histograms anyway.
whuber
7

As David's answer points out, the chi-squared test is necessary for binned data as the KS test assumes continuous distributions. Regarding why the KS test is inappropriate (naught101's comment), there has been some discussion of the issue in the applied statistics literature that is worth raising here.

An amusing exchange began with the claim (García-Berthou and Alcaraz, 2004) that one third of Nature papers contain statistical errors. However, a subsequent paper (Jeng, 2006, "Error in statistical tests of error in statistical tests" -- perhaps my all-time favorite paper title) showed that Garcia-Berthou and Alcaraz (2005) used KS tests on discrete data, leading to their reporting inaccurate p-values in their meta-study. The Jeng (2006) paper provides a nice discussion of the issue, even showing that one can modify the KS test to work for discrete data. In this specific case, the distinction boils down to the difference between a uniform distribution of the trailing digit on [0,9],

P(x)=19, (0x9)
(in the incorrect KS test) and a comb distribution of delta functions,
P(x)=110j=09δ(xj)
(in the correct, modified form). As a result of the original error, Garcia-Berthou and Alcaraz (2004) incorrectly rejected the null, while the chi-squared and modified KS test do not. In any case, the chi-squared test is the standard choice in this scenario, even if KS can be modified to work here.
Stochtastic
fonte
-1

You can compute the cross-correlation (convolution) between both histograms. That will take into account slight traslations.

Juan Manuel Tonello
fonte
1
This is being automatically flagged as low quality, probably because it is so short. At present it is more of a comment than an answer by our standards. Can you expand on it? We can also turn it into a comment.
gung - Reinstate Monica
Since histograms are fairly unstable representations of data, and also because they do not represent probabilities using height alone (they use area), one might reasonably question the applicability, generality, or usefulness of this approach unless more specific guidance is provided.
whuber