6
$\begingroup$

I would like to find a similarity function $f$ between two values (each value is continuous and is bounded by $[0,1]$) that would have the following properties:

$$ f(1, 1) = 0.5 $$

$$ f(0.5, 0.5) =0.25 $$

$$ f(1, 0) = 1 $$

$$ f(0, 1) = 1 $$

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

Is there such a function in math? If not how could I design it?

$\endgroup$
3
  • $\begingroup$ I took the liberty of editing your question. Please take a look and roll back if I misunderstood. $\endgroup$ Commented Jun 8, 2016 at 9:49
  • 2
    $\begingroup$ If you want a similarity function, do you require that $f(a,b)=f(b,a)$ and that $f\geq 0$? Possibly also that $f(a,b)>0$ if $a\neq b$? $\endgroup$ Commented Jun 8, 2016 at 9:50
  • $\begingroup$ I don't strickly require metric properties you mentioned. But this would be desirable to have them. $\endgroup$
    – fractile
    Commented Jun 8, 2016 at 9:52

1 Answer 1

8
$\begingroup$

The function

$$ f\colon [0,1]\times[0,1]\to[0,1], \quad(x,y)\mapsto \frac{1}{4}x+\frac{1}{4}y+\frac{3}{4}(x-y)^2 $$

does what you want. Plus, it's positive, symmetric and definite ($x\neq y$ implies that $f(x,y)>0$).

Neither it nor its root is linearly homogeneous like a norm-derived distance function, though ($f(\lambda x, \lambda y)\neq\lambda f(x,y)$) - but that does not seem to possible anyway given your requirements.

perspective plot

I found it by estimating a linear model based on your input data, with covariates $x$, $y$ and $(x-y)^2$:

foo <- data.frame(a=c(1,.5,1,0,0),b=c(1,.5,0,1,0),y=c(.5,.25,1,1,0))
model <- lm(y~a*b+I((a-b)^2),foo)

xx <- yy <- seq(0,1,.01)
persp(x=xx,y=yy,z=outer(xx,yy,function(xx,yy)xx/4+yy/4+0.75*(xx-yy)^2))
$\endgroup$
4
  • $\begingroup$ I guess now I can also try to specify more data points and make the function more precise, right? $\endgroup$
    – fractile
    Commented Jun 8, 2016 at 10:05
  • $\begingroup$ Yes indeed. Then it likely won't fit so nicely at the boundaries any more, though. $\endgroup$ Commented Jun 8, 2016 at 10:12
  • $\begingroup$ Very clever solution. How did you hit upon the specific covariates you used, symmetry? $\endgroup$ Commented Jun 8, 2016 at 16:32
  • 1
    $\begingroup$ @MatthewDrury: yes. As a matter of fact, after thinking about it, I'd rather use $(x+y)^2$ (instead of $x$ and $y$) and $(x-y)^2$, to enforce symmetry even with different input data. I don't like (dis)similarities that are not symmetric. $\endgroup$ Commented Jun 8, 2016 at 18:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.