lnNoam
lnNoam

Reputation: 1055

Compute a metric that punishes on the basis of type and distance

Suppose I have a single important point on a 2D graph called "Alpha A". All other points on the surface are of two types: "Beta A" and "Beta B".

I'd like to compute a metric of 'Alpha A' relative to the beta points with these properties:

  1. Punish greater distances from 'Alpha A' regardless of type, e.g., with (1/distance)
  2. if type == 'Beta A', give stronger weighting than if type == 'Beta
    B', e.g., make 'Beta B' negative.

Sample data frame:

color     distance
match        10
match        33
no_match     88
match       1000

Here is a very naive solution to my problem in pseudo code:

metric = 0

for (point in df){
     if (color == match){
         weight = 1*(1/distance)
     } else { 
         weight = -1*(1/distance)
     }
     metric  = metric + weight
 }

I don't doubt this problem is common and that there are myriad techniques to solve it. However, as I don't know the correct terminology to search with, finding information has not been very successful...

To be clear, I am not trying to predict the location of 'Alpha A'. I am simply trying to compute a metric that is informative about its environment.


DF

df = data.frame(color = c('match', 'match', 'no_match', 'match'), distance = c(10, 33, 1, 0))

Upvotes: 0

Views: 62

Answers (2)

DAV
DAV

Reputation: 756

It's not clear what you are asking for.

If it's how to find more literature concerning this is a Nearest Neighbor problem or, perhaps more correctly, a Nearest Set problem.

You haven't explained how you use this metric. It will be most positive if the nearest neighbors are of color==match; most negative if they are of opposite color; and zero if equidistant from both.

Is this what you want?

If so, this is correct. The only question would be if it falls off rapidly enough so that its magnitude is less than some value unless "pretty close" to some set, say by using 1/(1-distance^2).

Edit: Actually, 1/(1+distance) might be better or you may find yourself dividing by zero.

Upvotes: 1

Vikram Venkat
Vikram Venkat

Reputation: 671

Use this

df$weight <- NULL
df$weight = 1*(1 - 1/df$distance)
df$weight[df$color!="match"] = -1*df$weight[df$color!="match"]

Upvotes: 1

Related Questions