Is there a bell-curve-like function where n and m control the curve shape between 0 and 1?

366 Views Asked by At

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.

2

There are 2 best solutions below

13
On

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}} $.

3
On

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)}$$