7
$\begingroup$

I need a function that has the shape shown below. I don't care what the function does for $x < 0$ or $x > 1$.

enter image description here

I've experimented with a lot of different functions, configured first and second derivatives, and came up with this little monster. But I suspect there's something simpler.

$$\frac{1 + \sin \left[\frac{\pi}{2}(544x + 81)^{1/4}\right]}{2}$$

The origin of this problem is that I'm trying to turn a difference metric between a pattern and a model into a sort of "probability" that the model and the pattern are a bad match. So it should be zero for the model that best matches the pattern, and low for very similar patterns, but rising quickly for patterns that are less similar.

But as I look at it, it reminds me of a gravity well.

$\endgroup$
14
  • $\begingroup$ Simple in what sense? Fast to calculate with computers? Short expression to write with symbols? $\endgroup$ Apr 29, 2016 at 11:25
  • $\begingroup$ Does en.wikipedia.org/wiki/Smoothstep qualify? $\endgroup$
    – lhf
    Apr 29, 2016 at 11:26
  • 2
    $\begingroup$ Simpler in the sense that it's a short expression to write with symbols. $\endgroup$
    – mhwombat
    Apr 29, 2016 at 11:33
  • $\begingroup$ Any more information do you have? $\endgroup$ Apr 29, 2016 at 11:35
  • $\begingroup$ I tried smoothstep, both third and 5th order, but I couldn't get it to rise quickly near the origin. $\endgroup$
    – mhwombat
    Apr 29, 2016 at 11:36

6 Answers 6

5
$\begingroup$

If you need it to be smooth to a silly extent you can use the integral (or some approximation) of a bump function:

$$f(x) = \cases{\exp\left[-\frac{1}{1-x^2}\right] \hspace{1cm} x \in [-1,1]\\0 \hspace{3.cm} |x|>1}$$

This function is differentiable infinitely many times, and of course so will also it's integral be. But we will of course need to rescale it to fit the range for $x$: $[-1,1] \to [0,1]$ of course.

EDIT To answer to Bernards comment we may also need to renormalize it which we can do by dividing with $\int_{-\infty}^{\infty} f(x)dx$, that will ensure we get maximum of 1 (at $x=1$). Dividing by a constant won't change any of the other properties.

$\endgroup$
2
  • $\begingroup$ But it won't be equal to $1$ at $x=1$! $\endgroup$
    – Bernard
    Apr 29, 2016 at 12:21
  • 2
    $\begingroup$ @Bernard: you may rewrite it as $\;\displaystyle\exp\left[1-\frac 1{1-(1-x)^2}\right]\;$ and change the power of $(1-x)$ if you want. Another simple solution is $\;\displaystyle\int x(1-x)^3 dx$. $\endgroup$ Apr 29, 2016 at 12:31
5
$\begingroup$

I suggest the following family of functions: $$f_a(x)=1-\sin\left(\frac{\pi}{2}(1-x)^2e^{-ax^2}\right).$$ Where you can choose $a$ as you like to satisfy your requirement. In the next image you see the cases $ a=1,10$.

enter image description here

$\endgroup$
1
  • 1
    $\begingroup$ That's definitely an improvement over what I had, because the $a$ parameter can control the steepness of the curve. $\endgroup$
    – mhwombat
    Apr 29, 2016 at 16:50
5
$\begingroup$

Since you mentioned 'probability' have you considered a Weibull CDF? Weibull CDF with shape = 2.5 and scale = 0.4

$$ y = 1 - {e^{-(x/0.4)}}^{2.5} $$

$\endgroup$
4
$\begingroup$

Depending on your definition of "simple", you might want to consider a polynomial over a polynomial. These can be set up so that the difference in growth of the polynomial effectively "cancel" other terms, allowing you to set up regions in the curve of differing behavior.

Such equations are highly flexible and usually not too difficult to deal with, especially for further mathematical manipulation. They can also be fit to data fairly easily.

Here is an example I randomly came up with:

$$\frac{x+50x^{2.5}}{1+50x^{2.5}}$$

enter image description here

$\endgroup$
2
$\begingroup$

As requested, I have made my comment into an answer.

The function $f(x)=x^{1/x}$ could be used for your purposes, although as you pointed out, it isn't asymptotic at $y=1$. I haven't really worked out any variations of this function that could better suit your needs, but you claim that this would work too. If I do find a better variation, I shall edit this answer.A Graph of the function Here is a graph of the function for reference.

EDIT: I forgot to mention, as pointed out by OP, that one could change the function to $f(x)=x^{1/x^b}$ where $b$ is a parameter that controls steepness.

$\endgroup$
1
$\begingroup$

The reciprocals "integer roots" are very simple and achieve at least a bit of the same look although extremely quick raise at close to 0 $$r_n(x) = x^{1/n}$$

We can also take a look at the log-towers which are recursively defined

$$L_{n+1}(x) = \cases{\log\left[1+(e-1)x\right] \hspace{2cm} n = 0\\\\\log\left[1+(e-1)L_{n}(x)\right]\hspace{1.24cm}n>0}$$

We plot side by side for a few $n$ in these families, left: reciprocals, right logtowers:

$\endgroup$

You must log in to answer this question.

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