Skip to main content
Question

How to find which number closet to other number ?

  • August 30, 2023
  • 4 replies
  • 57 views

spiderman
Contributor
Forum|alt.badge.img+7

Hello

how to find which value closet to another value ?

i have 4 id

id -value

1 - 15

2 - 40

3 - 70

4 10

how could I find which value of id closet to another value of another id more than others .

As example , my target to know that

id 1 and id 4 are close to each other

and id 2 and id 3 ,close to each other

fme 2021

4 replies

DanAtSafe
Safer
Forum|alt.badge.img+19
  • Safer
  • 345 replies
  • August 30, 2023

Hi @spiderman​ I'd make the values into a number line with a VertexCreator, then use a NeighborFinder to find the point closest to itself. From your sample data you'll see that Id 1 is the closest point to both Id's 2 and 4.

 

If you want to make pairs of closest points so that for the entire set of points the sum of the distances between paired points is minimized - then that would be very difficult to solve.

 

closest_point


spiderman
Contributor
Forum|alt.badge.img+7
  • Author
  • Contributor
  • 64 replies
  • August 31, 2023

Hi @spiderman​ I'd make the values into a number line with a VertexCreator, then use a NeighborFinder to find the point closest to itself. From your sample data you'll see that Id 1 is the closest point to both Id's 2 and 4.

 

If you want to make pairs of closest points so that for the entire set of points the sum of the distances between paired points is minimized - then that would be very difficult to solve.

 

closest_point

Thanks for ur reply.

but is there any mathematical calculation to calculate the difference between values

to say 15-10 = 5 so id 1,4 are close

but I think ,I have to calculate the difference between all id .

i believe ,by using neighbor finder will not be possible to get the solution that I want .


DanAtSafe
Safer
Forum|alt.badge.img+19
  • Safer
  • 345 replies
  • September 1, 2023

Thanks for ur reply.

but is there any mathematical calculation to calculate the difference between values

to say 15-10 = 5 so id 1,4 are close

but I think ,I have to calculate the difference between all id .

i believe ,by using neighbor finder will not be possible to get the solution that I want .

I'm not sure of what you want exactly. Here's another method using lists. The trick is to get the values of all other features onto the current feature. The workspace does that with an Aggregator, Deaggregator, and ListExploder. But first it copies the current features attributes to traits. The Tester currently causes the output to have just one record (with the distance value) for every combination of input features. Change the ">" to "!=" to get duplicates, but reversed, e.g. distance from id 1 to id 4, and the distance from id 4 to id 1.


nielsgerrits
VIP
Forum|alt.badge.img+60
  • 2938 replies
  • September 1, 2023

How about sorting on Value and group record 1&2, 3&4, 5&6 using an AttributeCreator and Adjacent Feature Attributes?