TITLE: How to smoothly approximate a sign function
QUESTION [9 upvotes]: 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.

REPLY [4 votes]: 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.