• #### Nearness of two number/

From Mel Smith@21:1/5 to All on Wed Aug 4 07:36:06 2021
Hi All:
I'm working on a little Harbour program where my algorithm has to decide on the nearness of n sets of numbers. There are two integers in each set. I retain a measurement of of each set :

Here is the algo I am using to compute and save the 'nearness' of each set:

nVal := ABS(log(a)-log(b))

where a and b are the two numbers in each set. (Typical values of a and b will range up in the trillions.)
I will save/compare this nVal with many thousands of other nVals and decide with nVal is the smallest value, and so which set is 'nearest'.

I don't expect a and b to ever be identical, but, if they are, I would be delighted. But, first, I wish to find the nearest.

Question: Is there a better algo that you know off than the one I show above. ??
-Mel

--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)
• From dlzc@21:1/5 to meds...@gmail.com on Wed Aug 4 08:10:49 2021
Dear Mel Smith:

On Wednesday, August 4, 2021 at 7:36:07 AM UTC-7, meds...@gmail.com wrote:
...
I'm working on a little Harbour program where my algorithm has to
decide on the nearness of n sets of numbers. There are two integers
in each set. I retain a measurement of of each set :

Here is the algo I am using to compute and save the 'nearness' of each set:

nVal := ABS(log(a)-log(b))

Why not just ABS(a-b)? Is {1,2} further apart than {10001,10002}? (0-0.30) vs. (4.00004-4.00009)

Plus log() involves lots of calculations... might be better off with ABS(a/b) or ABS( (a-b)/(a+b) ) if you really want "nearness" to be scaled by "average size". And if you want to stick with logs, just use ln(), slightly faster.

where a and b are the two numbers in each set. (Typical values of a
and b will range up in the trillions.) I will save/compare this nVal with many thousands of other nVals and decide with nVal is the smallest
value, and so which set is 'nearest'.

I don't expect a and b to ever be identical, but, if they are, I would be delighted. But, first, I wish to find the nearest.

Question: Is there a better algo that you know off than the one I show
above. ??

Form the "nearness" as you load the array, and have that be one of the terms in the array. Then sort.

David A. Smith

--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)
• From Mel Smith@21:1/5 to All on Wed Aug 4 08:23:18 2021
Hi David:
Thanks for your alternate solutions. I will test and consider them.
I've been looking at 'nearness' for a couple of days now, and there seem to be several different thoughts/ways to measure.
-Mel

--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)
• From Ella Stern@21:1/5 to meds...@gmail.com on Thu Aug 5 01:11:16 2021
On Wednesday, August 4, 2021 at 6:23:19 PM UTC+3, meds...@gmail.com wrote:
Hi David:
Thanks for your alternate solutions. I will test and consider them.
I've been looking at 'nearness' for a couple of days now, and there seem to be several different thoughts/ways to measure.
-Mel

In case the (x, y) sets are points in 2D, there is possible to calculate their distances to aka center of mass point, for example the (median_of_my_x_values, median_of_my_y_values) ...it depends on the distribution of your points (medium might work
better than median, or just half of the difference between minimum and maximum etc.).

--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)