# Cosine similarity vs quadratic objective function

The aim is to calculate the similarity between two foods given the nutritional content of each. After some reading, it seems the most popular measure for this sort of problem is the cosine similarity measure.

My initial approach however was to use a quadratic function as an objective function. For $$n$$ categories $$c = [Protein, Carbs]$$ and positive vectors $$x = [200, 100]$$ and $$y = [500, 50]$$, where $$x_0$$ is the amount of protein in food $$x$$, we define the similarity function as:

$$\begin{equation} similarity = \frac{\sum_{i=0}^n \frac{-abs(x_i - y_i)^2}{max(x_i,y_i)^2} + 1}{n} \end{equation}$$

For example, for $$c = 0$$ (Protein), the absolute difference between the two foods is $$500 - 200 = 300$$ and the max is $$500$$. I feed this number into the quadratic function $$y = \frac{-x^2}{500^2} + 1$$, in essence calculating $$\frac{-300^2}{500^2} + 1$$. I repeat for the second category Carbs and average the two results to get the similarity measure as per the $$similarity$$ function above.

The objective function for the example above would look like the below: If the difference is 0, we get a value of 1. If the difference is the maximum 500, we get a value of 0. More importantly, the convex nature of the quadratic function means the bigger the difference, the larger its effect on the similarity measure.

My question is, what is the problem with this approach, and why would you prefer to use cosine similarity?