Nearness of two number/

41 views
Skip to first unread message

Mel Smith

unread,
Aug 4, 2021, 10:36:07 AMAug 4
to
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

dlzc

unread,
Aug 4, 2021, 11:10:50 AMAug 4
to
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

Mel Smith

unread,
Aug 4, 2021, 11:23:19 AMAug 4
to
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

Ella Stern

unread,
Aug 5, 2021, 4:11:18 AMAug 5
to
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.).
Reply all
Reply to author
Forward
0 new messages