Take this sample graph illustration:


As $X$ approaches negative infinity the output approaches $-5$

As $X$ approaches positive infinity the output approaches $5$

From what I recall this would be leveraging $\log, \ln$ or $e$ but I'm failing to remember the specific principles involved to come up with this function.

Other things that would be nice for this function is that it accelerates very quickly from the origin and tapers off which I tried to illustrate.

Bring this back to the real world and not just conceptual, realistic values of $X$ will primarily exist between $-10,10$ and much less frequently $-20,20$ and $-50,50$. My goal is to produce scoring algorithm with constrained limits on the output of the score.

The simpler the function, the better.

This function seems to be very close to what I'm looking for:


The graph it produces is:


At $F(5)$ and $F(-5)$ the graph is approximately 4 and -4.

How can I stretch out this function that $F(10)$ and $F(-10)$ are roughly 4 and -4 instead?

Able to answer this question myself, replace $X$ with $0.5X$

  • $\begingroup$ You guys really rock, it's going to be hard to pick an answer from all these great responses! $\endgroup$ – Chris Marisic May 5 '17 at 1:34

You have many alternatives. Have a look at this picture:

enter image description here

You can choose any one of these functions and just multiply it by the max value you want to obtain (you wrote about $5$). If you replace $x$ with $kx$ you are able to tune how steep the curve is in the middle. You can find this functions and even a few other examples on Wikipedia's entry about sigmoid functions.

FOLLOW UP: you can tune the purple function to get what you need in two different ways: $y=5\frac{x/2}{1+|x/2|}$ and $y=5\frac{x}{5/2+|x|}$.

  • $\begingroup$ Added a follow up question about your purple function $\endgroup$ – Chris Marisic May 5 '17 at 4:52
  • 1
    $\begingroup$ And here you are! @Chris $\endgroup$ – lesath82 May 5 '17 at 6:14

It looks like you want a sigmoid function. $$y = 5\left(\frac{2}{1 + e^{-kx}} - 1\right)$$ Increasing k will give a faster change through the origin. This one will go between $-5$ and $5$, replace the $5$ out front for a different range.


The simplest is $$f(x)=\frac{10}{1+e^{-x}}-5$$

It is a simple logistic function subtracted by 0.5 multiplied by $10$.

  • $\begingroup$ When is that ever negative? $\endgroup$ – Zain Patel May 4 '17 at 23:29
  • $\begingroup$ @ZainPatel I fixed it, thanks for pointing it out. $\endgroup$ – KKZiomek May 4 '17 at 23:32
  • $\begingroup$ I downvoted. It's still wrong. $\endgroup$ – Zain Patel May 4 '17 at 23:34
  • $\begingroup$ Now it's correct, I had a brainfart. @ZainPatel $\endgroup$ – KKZiomek May 4 '17 at 23:35

What about this :$$f(x)=\frac{10}{\pi} \tan^{-1}x$$


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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