3
$\begingroup$

I'm trying to come up with a function $f(x, n, m)$ which mainly focuses on the range $0 ≤ x ≤ 1$ and $m ≤ y ≤ 1$, where $m$ is the $y$-intercept at both $0$ and $1$, and $n$ is the sole maximum of $x$. It must always be the case that $f(n) = 1$, and $f(0) = f(1) = m$. When $x < 0$ and $x > 1$, the curve must approach, but never reach, $0$.

I've sketched an example:

Two curves which match the above-described behavior

I think this involves $ln$, but I can't quite grok it. Can anyone help me design such a function $f(x, n, m)$?


I can imagine an approximation using Bézier curves, so I made that. I hope this helps.

$\endgroup$
4
  • $\begingroup$ Do you mean $n$ is the sole maximum? $\endgroup$
    – jgon
    Commented Mar 20, 2018 at 0:18
  • $\begingroup$ @jgon yes, thank you $\endgroup$
    – Ky -
    Commented Mar 20, 2018 at 0:23
  • $\begingroup$ Also do you mean actually a bell curve? or just bell curve like, within those parameters? $\endgroup$
    – jgon
    Commented Mar 20, 2018 at 0:24
  • $\begingroup$ @jgon Bell-curve-like. My first draft had the term "humpback curve" and I thought this was better than that :P $\endgroup$
    – Ky -
    Commented Mar 20, 2018 at 0:34

2 Answers 2

3
$\begingroup$

We can build a function that does what you want by "changing coordinates" on the domain and range.

A Strategy Based on Changing Coordinates

Let's take an unnormalized gaussian $g(x) = e^{-x^2}$. This has $g(0) = 1$ and it tends to 0 as $x$ goes to $\pm\infty$. Also at $x = \pm1$ its value is $e^{-1} = 1/e$.

Let's construct a function $h_n(x)$ which is monotonic and takes your special desired inputs $0, n, 1$ to $-1, 0, 1$, respectively.

And let's construct another function $k_m(x)$ which is monotonic and takes the outputs $0, 1/e, 1$ to $0, m, 1$, respectively.

Then $$f(x, n, m) = k_m( g( h_n(x)))$$ will do what you want.


Functions $h$ and $k$

There are many ways to build appropriate functions $h$ and $k$. One nice form for functions which can be made to take any 3 inputs on the line to any 3 outputs are the functions of the form $$\frac{ax + b}{cx + d}$$

(These are called rational functions of degree 1 or alternatively Möbius transformations if you want to look them up; here they're just a useful tool for moving and stretching the real line.)

I'll give details below, but here are functions that have the behavior described above:

$$h_n(x) = \frac{x-n}{(1-2n)x + n}$$ this takes $0$ to $-1$ and $n$ to $0$ and $1$ to $1$.

$$k_m(x) = \frac{(1-e)m x}{(1-em) x + (m-1)}$$ this takes $0$ to $0$ and $1$ to $(1-e)m/((1-em)+(m-1)) = 1$ and $1/e$ to $(1/e-1)m/(1/e-m + m-1) = (1/e-1)m/(1/e-1) = m$


Putting it together

This gives

$ \begin{eqnarray*} f(x,n,m) &=& k_m(g(h_n(x))) \\ &=& k_m(g(\frac{x-n}{(1-2n)x + n})) \\ &=& k_m(e^{- (\frac{x-n}{(1-2n)x + n})^2}) \\ &=& \frac{(1-e)m e^{- (\frac{x-n}{(1-2n)x + n})^2}}{(1-em) e^{- (\frac{x-n}{(1-2n)x + n})^2} + (m-1)} \end{eqnarray*}$

This way of doing things gives a conceptually simple answer, in that we've just moved and stretched the gaussian to meet your requirements. But we do get a fairly messy formula.


Details on solving for $h$ and $k$

We can solve for $h_n$ and $k_m$ of the form $\frac{ax+b}{cx+d}$ by plugging in the 3 equations we want them to solve and solving for the coefficients $a$, $b$, $c$, and $d$.

For $h_n$ we want $h_n(0) = -1$ so $b/d = -1$ so $d = -b$. And we want $h_n(1) = 1$ so $a + b = c + d$. And we want $h_n(n) = 0$ so $an + b = 0$ so $b = -an$.

Putting this together we get $d = -b = an$ so $a+b = c+d$ becomes $a - an = c + an$. So $c = a - 2an$. We can choose $a=1$ freely and we get $$h_n(x) = \frac{x - n}{(1-2n) x + n}$$

For $k_m$ we want $k_m(0) = 0$ so $b = 0$. And we want $k_m(1) = 1$ so $a = c + d$ (omitting $b$ which is $0$). And $k_m(1/e) = m$ so $a/e = m(c/e+d)$.

Putting this together we get $(c+d)/e = m(c/e + d)$. Let's choose $c = e$ for simplicity (we have a free parameter). So we have $1 + d/e = m + md$ so $d (1/e - m) = m - 1$ so $d = \frac{m-1}{1/e-m}$. Then $a = c+d = e + \frac{m-1}{1/e-m} = \frac{m-em}{1/e-m}$. So we get $$k_m(x) = \frac{\frac{(1-e)m}{1/e-m} x}{e x + \frac{m-1}{1/e-m}} = \frac{(1-e)m x}{(1-em) x + (m-1)}$$

$\endgroup$
3
  • 2
    $\begingroup$ I've programmed this in and it's beautiful! It's so close, but it fails on the edge cases... when $m = 0$, $x = 0$, or $x = 1$, it's a straight line. Also, when $m > 0.5$, it loses its bell-curve shape. Here's a demo, with your solution as red dots and my approximation as a grey curve. I've written my translation of your function in code below it, in case you can find any errors I made during translation. $\endgroup$
    – Ky -
    Commented Mar 22, 2018 at 3:58
  • $\begingroup$ Cool demo! The edge cases are interesting; for example what you want at $m=0$ would presumably be to have the function be constant at $0$ outside $(0,1)$. It’s not so bad to get that, but such a function couldn’t be analytic so we’d want a piecewise definition. On the other hand, making it so we don’t lose the inflection points above $m > 0.5$ should be doable with slightly different functions. $\endgroup$
    – aes
    Commented Mar 27, 2018 at 16:25
  • $\begingroup$ the grey curve in the demo should look similar to the red dots in all cases $\endgroup$
    – Ky -
    Commented Mar 27, 2018 at 16:45
1
$\begingroup$

A standard one, which I think is called the Beta distribution, is $f(x) =x^m(1-x)^n$.

Since $f'(x) =-x^mn(1-x)^{n-1}+mx^{m-1}(1-x)^n =x^{m-1}(1-x)^{n-1}(-nx+m(1-x)) $, $f'(x) = 0$ when $nx = m(1-x)$ or $x =\dfrac{m}{m+n} $.

At this $x$, $f(\dfrac{m}{m+n}) =(\dfrac{m}{m+n})^m(\dfrac{n}{m+n})^n =\dfrac{m^mn^n}{(m+n)^{m+n}} $.

$\endgroup$
13
  • $\begingroup$ in your final function, I don't see where $x$ would factor in on the right-hand side $\endgroup$
    – Ky -
    Commented Mar 20, 2018 at 0:37
  • $\begingroup$ We have $x=m/(m+n)$. $\endgroup$ Commented Mar 20, 2018 at 0:39
  • $\begingroup$ So by choosing $m$ and $n$ appropriately, the peak can be anywhere in $[0, 1]$. $\endgroup$ Commented Mar 20, 2018 at 0:40
  • $\begingroup$ That seems to be a constant number, not a curve: Wolfram Alpha $\endgroup$
    – Ky -
    Commented Mar 20, 2018 at 0:43
  • $\begingroup$ I don't think this answers my question. The very first function doesn't address the bell-curve-like requirement, is nonsense when $x < 0$ and $x > 1$, doesn't reach $1$ at its peak unless $x = 0$ or $x = 1$, and its peak's position is inverted from $n$'s value. Absolutely not what I want. The last function is just a straight line so won't work. I just want an $f(x, n, m) = something$ which looks like my sketch... $\endgroup$
    – Ky -
    Commented Mar 20, 2018 at 2:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .