11
$\begingroup$

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

$\endgroup$
14
  • 5
    $\begingroup$ Of course, one can improve the approximation by taking $\tanh \lambda x$ for some $\lambda \gg 0$. $\endgroup$ Commented May 3, 2015 at 14:36
  • 3
    $\begingroup$ what sort of benefits are you looking for? $\endgroup$ Commented May 3, 2015 at 14:37
  • 4
    $\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$ Commented 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$ Commented 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$ Commented May 3, 2015 at 14:54

3 Answers 3

7
$\begingroup$

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.

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

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

$\endgroup$
5
  • $\begingroup$ Any sigmoid function has the problem that the OP mentioned in his edit. $\endgroup$ Commented May 3, 2015 at 15:15
  • $\begingroup$ So just multiply with 2 and then subtract 1. $\endgroup$ Commented May 3, 2015 at 15:17
  • $\begingroup$ Why remove the comment afterwards? Destroys the communication. $\endgroup$ Commented 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$ Commented 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$ Commented May 3, 2015 at 15:23
0
$\begingroup$

If you want something that is perfectly flat but also smooth you should try some smooth transition function like the following example for $n\geq \sqrt{3}$: $$f(x,n) = \begin{cases} -1,\quad x\leq -1;\\ \tanh\left(\frac{nx}{1-x^2} \right),\quad -1<x<1;\\ 1,\quad x\geq 1\end{cases}$$

where you could made it as close as you want to the $\text{sgn}(x)$ function by increasing the value of $n \to \infty$. You could see this function in Desmos.

increasing the value of n

$\endgroup$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.