3

The problem:

I'm looking for a particular function $f(x, y)$—this isn't "homework" in the sense that I have no idea if such a function exists. It has a continuous domain $-1 \lt x \lt 1$ and $-1 \lt y \lt 1$, and a continuous range $-1 \le f(x, y) \le 1$ (EDIT: I have no idea how to word these requirements. See comments.) Additionally:

$f(n, -n) = 0$

$f(n, 0) = f(0, n) = n$

$f(n, 1) = f(1, n) = 1$

$f(n, -1) = f(-1, n) = -1$

I did work out the following cubic function $g$ which comes close:

$g(x, y) = (-\frac{x^2}{1-x^2})y^3 - xy^2 + (\frac{1 - 2x^2}{1-x^2})y + x$

$g(n, -n) = 0$

$g(n, 0) = g(0, n) = n$

$g(n, 1) = 1$

$g(n, -1) = -1$

However:

$g(\lim \limits_{x \to 1}, |n|) = \infty$

What I'm trying to achieve:

In my code, $x$ and $y$ are two "match" percentages between elements $a$ and $b$ (for $x =$ +100%, $a$ and $b$ are perfect matches; for $x =$ 0%, $a$ and $b$ have no relation; for $x =$ -100%, $a$ and $b$ are exact opposites). I'm trying to (elegantly) combine these two match values such that $x$ & $y$ with the same sign pull each other toward |100%| and $x$ & $y$ with opposite signs pull each other toward 0% (cancel each other out).

If I can't find an elegant mathematic solution, I'll just use linear interpolation in the three ranges $(sign(x), 0), (0, -x), (-x, -sign(x))$.

EDIT: Also worth noting that function $g$ doesn't work well for this purpose for $|x| > \frac23$ or $|y| > \frac23$, since the cubic function grows a peak & valley beyond that threshold.

  • As long as your requirements aren't contradicting each other or the definition of a function (and your's doesn't) a function will exist. In your case a lot of functions exist, you might want to add some requirements, like should it be continuous? – Henrik supports the community May 23 '16 at 15:58
  • Your "however" doesn't make any sense. You have a limit of nothing? – Henrik supports the community May 23 '16 at 16:05
  • f(-1,1) would have to be equal to -1 and to 1. Such a function is impossible..... Oh, I guess not. – fleablood May 23 '16 at 16:06
  • @fleablood: I thought so to for a moment, but the requirements are only for $-1<n<1$, so the function just isn't continuous at $(-1,1)$ (or at $(1,-1)$). - And that means that my suggested requirement above is not valid. – Henrik supports the community May 23 '16 at 16:08
  • @yeah, I realize that now. So anyway... many functions. f(x,y) = i)ii) iii) iv) if conditions met. f(x) = $\sqrt{\pi}*x + e^y$ otherwise will do. – fleablood May 23 '16 at 16:11
  • @Henrik I suppose my requirement is a continuous domain within -1 and 1 and a continuous range within -1 and 1 (see edit). Does that make sense? –  May 23 '16 at 16:14
  • In your explanation you say that x and y are percent matches between a and b but you only describe x. What is the use of y and how are there two percent matches? What is the input of your function? a and b? or x and y? – fleablood May 23 '16 at 16:19
  • It makes sense, but it doesn't help. @fleablood's function takes on values outside $[-1,1]$, but if you divide it by $5$ (where it doesn't have to take a value to meet your criteria) you have an example. – Henrik supports the community May 23 '16 at 16:21
  • @fleablood I'm sorry, this is a mess of a question right now. Can you vote for closure? –  May 23 '16 at 16:21
  • I have voted to close this. – Henrik supports the community May 23 '16 at 16:22
  • Ignore Henrik and my comments. We're mathematicians and sticklers for precise definition. You have a question and want an answer. Describe what you want. The conditions aren't so important in asking the question. – fleablood May 23 '16 at 16:24
  • I don't think you want f(1,n) = 1 and f(-1,n) = -1. I think you want f(1,n) =1 if n >0, f(-1,n) = -1 if n < 0. – fleablood May 23 '16 at 16:26
  • In my opinion, it might be helpful if the 'what I want to achieve part' was placed before the 'constraints' part and if the former was elaborated a little. – shardulc May 23 '16 at 16:29
  • @shardulc I agree. I got thrown by the specific math theorectical nature of the question which is irrelevent. Heres: a broad solution f(x,y) = 0 if x <= 0 and y >= 0; f(x,y) = 0 if x >= 0 and y <= 0; f(x,y) = 1 if x>0 y>0 and f(x,y) = -1 if x < 0 y < 0. One can make something a little more continuous if I knew what the OP wanted for f(n,m) 0<n<m<1. I'm not sure what "drawing" to 100 if both same sign means in his/her mind. – fleablood May 23 '16 at 16:37

1 Answers1

1

What about $$f(x, y) = \begin{cases} x + y & -1 \leq x + y \leq 1 \\ 1 & x + y > 1 \\ -1 & -1 > x + y \end{cases}$$

OK, so it's a piecewise function, but it does what (I think) you intended. Bear in mind that I guessed most of it based on the fact that $x$ and $y$ represent percentages and you are probably trying to combine two aspects of similarity into a single number.

For $-1 \leq n \leq 1$, $$ f(n, 0) = f(0, n) = n $$ For $n \geq 0$: $$ f(n, 1) = f(1, n) = 1 $$ (If there's one 100% correlation and the other one is negative, then that isn't a 100% result, is it?) For $n \leq 0$: $$ f(n, -1) = f(-1, n) $$ (A similar observation as above applies.)

Do tell me whether this works.

shardulc
  • 4,562