2
$\begingroup$

I have two numbers x & y for N different readings and wish to find how close they are from each other and would like to rank the reading in order of they equalness.

If I were to have the following set of data

Reading____x__________y
1__________1__________0
2__________0__________1
3__________1__________1
4__________1000_______1000
5__________990________1000
6__________1000_______990
7__________10_________9
8__________9__________10
9__________5__________10
10_________10_________6

I would expect something like this after sorting by equalness

Reading____x__________y
4__________1000_______1000
3__________1__________1
5__________990________1000
6__________1000_______990
8__________9__________10
7__________10_________9
10_________10_________6
9__________5__________10
1__________1__________0
2__________0__________1

I wish to use the exact values in combination with the magnitude of the values for comparison, such that

  • 990 is more equal to 1000 than what 9 is to 10
  • 1000 is more equal to 1000 than 1 is equal to 1

For simplicity, I wish to only consider whole numbers.

What would be an f(x,y) that I could use to sort the values?

I am trying to use this function to find out users that have almost equal scores on Questions and Answers on Stack Overflow

$\endgroup$
4
  • $\begingroup$ Do you want some kind of scaling behaviour? For example, how should $f(2x,2y)$ and $f(x,y)$ be related? $\endgroup$ Sep 28, 2014 at 14:07
  • $\begingroup$ Let's say f(2x,2y) precedes f(x,y) from a sorting point of view $\endgroup$ Sep 28, 2014 at 14:11
  • $\begingroup$ What if you take the lexicographic order where you first look at $\log x-\log y$ and then at $x$ in case of equality? (I'm assuming $x,y>0$.) If this is not the kind of thing you want, can you say how it should be improved? $\endgroup$ Sep 28, 2014 at 14:21
  • $\begingroup$ @JoonasIlmavirta Sweet! Looks like that can work for me after taking the absolute value, I can't think of any scenario this does not handle so far. I will run it over my actual data and check $\endgroup$ Sep 28, 2014 at 14:30

1 Answer 1

2
$\begingroup$

You could use the function $g(x,y)=|\log x-\log y|$ for $x,y>0$. This function measures relative difference in such a way that $g(x,y)=g(y,x)=g(ax,ay)$ for all $a>0$. Now if you want the the pair $(10,10)$ to be "more same" than $(1,1)$, you could order pairs $(x,y)$ and $(a,b)$ by "equalness" by first comparing $g(x,y)$ with $g(a,b)$ and in case of equality comparing $x$ with $a$.

If you want all of this in one function, you could take $f(x,y)=g(x,y)-c\log(x+y)$ for $c$ small enough. There are of course many ways to achieve your goal since it's not very specific. If you think that my approach should be modified in some direction and you don't know how, let me know.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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