I have a function that defined as following

$$f(x) = \begin{cases} 1, & \text{if $x > 0$ } \\ 0, & \text{if $x=0$ } \\ -1, & \text{if $x<0$ } \end{cases}$$ In practice, the $f(x)$ is approximated by a smooth $\tanh(kx)$ or Heaviside function as bellow figure. Could you have other way to represent the $f(x)$ function? What are the benefits of your way?

Update: $\tanh(kx)$ function $k$ controls the smoothness of the sign function. As $k \to \infty$, the function defined in $f(x)=\tanh(kx)$ converges to standard sign function. Similarly, the derivative of $\tanh(x)$ also converges to Dirac delta function as $k \to \infty$. If $k$ is too small, the evolution equation for $x$ acts locally only on a few values around $\{x=0\}$. Hence, the $\tanh(kx)$ function is sensitive with parameter $k$. The parameter $k$ must be chosen carefully.

Hence, My purposed want to reduce/ignore the affect of k, but remains the above smoothly approximation.

enter image description here

  • 5
    $\begingroup$ Of course, one can improve the approximation by taking $\tanh \lambda x$ for some $\lambda \gg 0$. $\endgroup$ May 3, 2015 at 14:36
  • 3
    $\begingroup$ what sort of benefits are you looking for? $\endgroup$
    – Andrea
    May 3, 2015 at 14:37
  • 3
    $\begingroup$ It would help if you explain why you want something other than the $\tanh$ function. What is it about $\tanh$ that doesn't work for your purposes? Otherwise, people may waste a lot of time coming up with other functions that also won't work for you. $\endgroup$ May 3, 2015 at 14:44
  • 2
    $\begingroup$ Check out the function $f(x) = e^{-1/x^2} x>0; =0 $ for $ x<0$. It is infinitely differentiable at 0 and you can use it to glue together stuff. $\endgroup$
    – Asvin
    May 3, 2015 at 14:44
  • 2
    $\begingroup$ Another suggestion; for $x\geq 0$ we have $f(x) = 1-e^{-\lambda x}$ and for $x<0$, $f(x)=e^{\lambda x}-1$. With some $\lambda \gg 0$. $\endgroup$
    – Rammus
    May 3, 2015 at 14:54

2 Answers 2


You could try $\frac 2 \pi \arctan \lambda x$ for various $\lambda >0$. If you do not tell us what exactly you are looking for, we shall not be able to help.

  • $\begingroup$ Yes. I update my question. Let see my analyze and my goal $\endgroup$
    – John
    May 3, 2015 at 15:04

What you are describing is usually called "sigmoid" functions in the machine learning community, of which some can be found here: http://en.wikipedia.org/wiki/Sigmoid_function

Another way to do it is to perform local integration on the sign function:

$$a_1(x_0) = \frac{1}{2\delta_x}\int_{x_0-\delta_x}^{x_0+\delta_x} s(x)dx$$

And you could do this over and over, recursively:

$$a_n(x_0) = \frac{1}{2\delta_x}\int_{x_0-\delta_x}^{x_0+\delta_x} a_{n-1}(x)dx$$

You would gain one degree of differentiability every time you do so.

enter image description here

  • $\begingroup$ Any sigmoid function has the problem that the OP mentioned in his edit. $\endgroup$
    – Alex M.
    May 3, 2015 at 15:15
  • $\begingroup$ So just multiply with 2 and then subtract 1. $\endgroup$ May 3, 2015 at 15:17
  • $\begingroup$ Why remove the comment afterwards? Destroys the communication. $\endgroup$ May 3, 2015 at 15:18
  • $\begingroup$ Multiplying by 2 and subtracting one gives you $\tanh(\frac{x}{2})$ and OP seems to be against use of tanh. Apologies. $\endgroup$ May 3, 2015 at 15:22
  • $\begingroup$ Not for all sigmoid functions. There is a long list at the end of the wikipedia page. $\endgroup$ May 3, 2015 at 15:23

You must log in to answer this question.

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