Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to find a mathematical function that would provide certain weighting to the values of my algorithm. Namely, having two values, x,y, I would like to provide a function that would favour big differences between x and y. Ideally, it would return 1, if x = -inf and y = +inf (or vice versa) and 0, if they are equal. On top of that, I would like it to be non-linear in growth.

I hope the above makes sense. Thank you very much in advance for your comments and answers.

share|cite|improve this question
up vote 3 down vote accepted

You can define a lot of such functions, the most simple choice being $1-\mathrm e^{-|x-y|}$ which admits all the requirements you've requested. We can also make it even more nonlinear: $$ 1 - \mathrm e^{-|x^3-y^5|} $$ not to depend explicitly on $|x-y|$ if you would like to avoid that.

You can also consider $1-\mathrm e^{-|x-y|^p}$ for $p>0$. If you would like to weight more huge differences in $x,y$ then choose $p>1$, otherwise choose $p<1$. If you know that the maximum difference is $D$ then you can simply use $$ \left(\frac{|x-y|}{D}\right)^p $$ where the choice of $p$ follows the same reasons.

share|cite|improve this answer
Thank you very much Ilya. I further noticied that the basic function quite quickly reaches "high" weight values. if x and y differ by only 1, the value would still be at around 0.6. My values would most likely differ by 10-20, or even more, so I would like to be able to see big difference between 20 and 200, if that is the case. Should I simply divide the difference by 100 or other constant of mine or is there a better way to achieve what I described? thanks – Bober02 May 30 '12 at 12:33
Another update: if I know, taht maximum difference is D, how can I make this equal to 1, using the above function, and rescale all the other, smaller values respectively? – Bober02 May 30 '12 at 12:38
@Bober02: updated – Ilya May 30 '12 at 12:49

Any strictly monotonic function $f$, such that $\lim \limits_{x \rightarrow +\infty} f(x) \neq \infty$ could be used after a bit of linear transformations. Aside from what Ilya suggests, other natural choices could be $$1 - \frac{1}{1+|x-y|}$$ or $$\frac{2\arctan |x-y|}{\pi}$$ There is a lot of freedom here, if you know exactly what you want.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.