# Distance function

1. Sep 28, 2009

### JasonBourne

Hello everyone,

I need to figure out a penalty function that computes the penalty w.r.t distance of a point from two boundaries. The function produces a high penalty value if the point is closer to any of the two boundary and the penalty value decreases as the distance from boundaries increases. Two boundary can be viewed as distance from two axis.

Formulation:
Let x be the distance from Y axis and y be the distance from X axis, I need a penalty function

P = f(x,y) having above property

Jason

2. Sep 29, 2009

### Fredrik

Staff Emeritus
Are you talking about a point inside a square that should be as far as possible away from the edges to get the minimum penalty? In that case, you could put the origin of your coordinate system at the center, and use a scale on the x and y axis so that the corners are at (1,1), (1,-1), (-1,-1) and (-1,1). Then you can can set P=M(|x|+|y|)/2, where M is the maximum penalty. Or how about P=M(x2+y2)/2 ? This defines a penalty that's proportional to the distance from the center (so any two points on the same circle around the center gets the same penalty). If you want an option that's intermediate between these two, consider P=M(|x|s+|y|s)/2, where you choose an s from the interval (0,1), e.g. s=1/2, which gives you $$P=M(\sqrt{|x|}+\sqrt{|y|})$$

3. Sep 29, 2009

### JasonBourne

Thank Fredrik for your response, but a major issue about the problem which I think I didnt made that clear is that the point is bounded from 2 sides only. Other 2 sides are not bounded. Think of the point in any of the quadrant of a coordinate system where it is bounded by X and Y axis from two sides while other two sides are not bounded.

The function needs to max out after certain distance from the centre.

- Also smaller the distance from any of the boundary, larger the penalty value (i.e min of the two distances should have more effect on the penalty function). However I am more concerned about the above characteristics of the penalty function.

4. Sep 29, 2009

### Fredrik

Staff Emeritus
There are two things you need to think about. The first is the shape of the curves on which every point is assigned the same penalty. The second is what penalty to assign to each of those curves. For the first problem, I suggest the curves y=k/x, where k is a constant. This restricts your penalty function to the form P(x,y)=f(xy). For the second problem, I need more information before I can suggest anything.

You should tell me something about what penalties you want to assign to points on the line y=x. Let r be the distance from the origin. Do you want a linear decrease from a maximum penalty to zero, or do you want the penalty to grow rapidly as r approaces zero? Do you want the penalty to be 0 above a certain value of r, or to decrease rapidly as r goes to infinity?

5. Sep 29, 2009

### JasonBourne

Hello Fredrik,

Penalty on the curve closest to two boundaries will be higher and the penalty decreases rapidly as the curves move part from the two boundaries.

I want the penalty in the range [0-1]. Penalty value increases rapidly(exponentially) as the distance of the point from any of the two boundaries decreases and have value 1 for point on the boundary or on the origin. I want the penalty to decrease rapidly as r goes to infinity. it shouldnt be zero cause there is no such r value. As far as the penalty on the line y=x is concerned it will be directly proportional to r.

6. Sep 30, 2009

### Fredrik

Staff Emeritus
Unfortunately these two contradict each other. ("Directly proportional to" would be P(r)=kr). Maybe you meant something like P(r)=1-r/d for r≤d and P(r)=0 for r>d, but it still contradicts the other thing you said.

I also realized that I made a mistake in my previous post. To have the penalty constant along curves of the form y=kx would make the penalty very small for some points that are very close to one of the axes (and far from the other). That's not what you want.

This makes it much more difficult to find a suitable function. P(r)=e-r does the job on the line y=x, but I can't think of a continuous function that's =1 everywhere on both axes and goes to zero when r goes to infinity. Is it necessary to have the penalty =1 at the origin? If it's OK to have the penalty =2 there, and close to 1 at points on either the x or the y axis that's far from the origin, then P(x,y)=e-x+e-y would work. You can adjust how rapidly the function increases and decreases by puting another exponent on the variables: P(x,y)=e-xa+e-ya

Last edited: Sep 30, 2009
7. Sep 30, 2009

### Ben Niehoff

$$p(x,y) = e^{-xy}$$

? This is equal to 1 on either the x or y axis, and rapidly decreases to 0 as you get further away.

8. Sep 30, 2009

### Fredrik

Staff Emeritus
I tried to explain the problem with functions of that type in my previous post, but I made a mistake while typing. This is what I wrote:
It should of course have been "constant along curves of the form y=k/x". This includes the choice P(x,y)=exp(-xy).

For example, if x=50 and y=1/10, the penalty is only 0.0025. I'm not sure if that's good or bad. JasonBourne, I suggest you try inserting a few values into this function to see if you get penalty scores you think are reasonable. You can also put a constant in the exponent, P(x,y)=exp(-kxy). This is equivalent to changing the units on the x and y axes.