TITLE: Formally describe a similarity function
QUESTION [0 upvotes]: I have a function that takes two real world objects as input and returns a real value between 0 and 1 as the similarity of the two objects. How to formally describe this function in mathematical language? I am looking for something like $f: \mathbb{R} \rightarrow \mathbb{R}$

REPLY [2 votes]: Encode the two objects into feature vectors of length $n$, call them $x$ and $y$.
Suppose you have two vectors, $x, y$ where they are componentwise nonnegative.
One possible approach to use Jaccard similarity coefficient.
$$J(x,y)=\frac{\sum_{i=1}^n \min(x_i, y_i)}{\sum_{i=1}^n \max{x_i, y_i}}$$
For the case of binary vectors.
Let $M_{11}$ represents the total number of attributes where $x$ and $y$ both have a value of $1$.
Let $M_{01}$ represents the total number of attributes where the attribute of $x$ is $0$ and the attribute of $y$ is $1$.
Let $M_{10}$ represents the total number of attributes where the attribute of $x$ is $1$ and the attribute of $y$ is $0$.
$$J(x,y)=\frac{M_{11}}{M_{10}+M_{01}+M_{11}}$$
You can read more about Jaccard similarity here
{"set_name": "stack_exchange", "score": 0, "question_id": 2277203}