# In search of a proper similarity function

I'm trying to find the most similar sample between a candidate and a bag of samples.

Consider you have a knowledge corpus as follows:

corpus = data.frame(region = factor(), time = numeric(), observation = numeric())
corpus = rbind(corpus, data.frame(region = 'america', time = 1:20, observation = rnorm(20)))
corpus = rbind(corpus, data.frame(region = 'asia', time = 1:20, observation = rnorm(20)))
corpus = rbind(corpus, data.frame(region = 'europe', time = 1:20, observation = rnorm(20)))


Now I have a new sample and I want to choose from my knowledge base, which of the records is the most similar to my new sample.

I used different metrics with not so much improvements between them:

• Euclidian
• Cosine
• Correlations

But what I really want to see is that the matching is done based on the shape of the curve not in vectorial distance but I have no clues about similarity functions that would metric this type of space.

*Edit: I want to match my new sample with the "closest" element in my knowledge base. But what I want is to have a match using the shape of the curve to compare the samples. If it has positive or negative derivatives in the same intervals, same amount of local maximums, that sort of things.

I tried different approaches and compared the quality of them with a random assign using a KolmogorovSmirnov test.

Fact is that my random assign is not showing to be worse than my super califragilistic detection method .

Any clues? Thoughts?

• matching is done based on the shape of the curve not in vectorial distance I could not quite understand this. Could there be missing some words? – ttnphns Sep 13 '14 at 20:35
• Euclidean distance compares profiles as they are, their gross difference. Cosine compares shapes of the profiles - with "sea level" of these "landscapes" being kept at original zero. Correlation is like cosine, only it sets the "sea level" at the average height of a profile. – ttnphns Sep 13 '14 at 20:42
• @ttnphns I edit the question to clarify what I want regarding to the matching on the shape of the curve. – Daniel Sep 13 '14 at 21:31