# Confidence value for face recognition

In the context of face recognition I have the following histogram:

blue bins count the comparison distances for "self matches" (comparing two images of the same person). Orange bins count the distances for cross matches (different persons).

The distance is the value returned by the neural networks as the result of a comparison between two faces, how much two "faces vectors" (embeddings) differ.

I'm looking for a function that, given a distance, can tell how likely it is for two pictures to be from the same person.

This function should be look like this red line (with a different y-scale):

So with distance 0.5 it is extremely likely, with distance 1.4 it is close to a 50% chance.

Is there such a function? How is it called?

It is similar to this question but also very different. In my case a very small z-value (distance) still means high confidence even if it is many standard deviations away from the mean. The same is true for a value like 1.0.

This question is very similar too but I'd like to extract the distance to probability mapping function from actual measurements, on a reference dataset, and not from the distance by itself. So this should not depend on the loss or distance definition but on the data distribution alone.

EDIT: I think I could compute the AUC at different thresholds like shown here. But this will give me a single bell centered in the middle of the two peaks, quite different from what I'm looking for.

• what is the red line? – Leevo Jan 17 at 18:38
• @Leevo The red line is the intuitive shape of the function I have in mind – lorenzo Jan 17 at 23:21

If I had to calculate such a function, I would:

Calculate the probability (not Z-score) for $$x$$ in a two-tailed test (https://en.wikipedia.org/wiki/One-_and_two-tailed_tests) for the probability that $$x$$ belongs to the distribution for both distributions. Then you have $$p_s(x)$$ and $$p_c(x)$$ for self-match/cross-match. Don't use probability $$0.1\%$$ to reject, but to compare.

Then calculate $$\frac{p_s(x)}{p_s(x) + p_c(x)}$$

Which tends to $$1$$ if $$p_s(x)$$ is the larger term, is $$0.5$$ if they are the same, and tends to $$0$$ if $$p_c(x)$$ is the larger term.

At the far tails, $$p_s(x)$$ and $$p_c(x)$$ both tend to zero, but the order of magnitude will select the good probability.

• I'm missing the reference to "probability 0.1%" (p-value?). The Ps for 0.1 and for 0.9 should be different even if both are at the same distance from the mean, I'm not sure this if is accounted for. Also, considering that Pc is practically zero up to 1.2 this formula gives 1 for the whole [0, 1.2] range: intuitively is not ideal (even if it might be correct) as I would expect it to decrease lightly while the distance increases. – lorenzo Jan 18 at 10:04
• The probability that 1.4 belongs to either one of the distributions is very small, I just picked $0.1\%$. Typically you'd reject that the point belongs to the distribution, but given that you need to select a distribution, you still use it in your formula. Your intuition applies to distributions that have significant overlap. These don't and you can expect a steep descent and a clear decision boundary. – Pieter21 Jan 18 at 10:29
• This works, but what bothers me is that the idea of distance is completely lost. This would be identical if the bells represent the sizes of dogs of two different breeds. Here 0.1 and 0.9 means very different things even if 0.1/0.1 and 0.9/0.9 gives the same result. Assuming that the strict probability is correct in this way, then maybe I'm looking for a different kind of confidence metric specific for distance based comparisons. – lorenzo Jan 19 at 12:18