Need your thoughts on a faster approximation for the signum function I came up with.

383 Views Asked by At

I recently was kind of fascinated with the whole signum function out of the blue, and was generally really curious of the already existing approximations of it. I really don't want to lag this down and before I show you mine, here are the pre-existing ones;

$$\bbox[5px,border:2px solid blue] {sgn(x)\approx\frac{x}{\sqrt{x^2+k_2^2}},\;\;\;\;\; for\;k_2 \to 0}\tag{Eq. 1}\label{1}$$ $$sgn(x)\approx tanh(kx), \;\;\;\;\; for\; k >> 1\tag{Eq. 2}\label{2}$$

These are the basic ones, and can be found at the wikipedia page for signum function. I've also looked for other sources for other approximations to this and here is what I've found;

$$sgn(x)\approx\frac{x\left(1+k\left|x\right|\right)}{1+\left|x\right|\left(1+k\left|x\right|\right)},\;\;\;\;\; x ∈ R, k ≥ 0\tag{Eq. 3}\label{3}$$ $$\bbox[5px,border:2px solid black] {sgn(x)\approx\frac{e^{kx}-e^{-kx}}{e^{kx}+e^{-kx}},\;\;\;\;\; x ∈ R, k ≥ 1}\tag{Eq. 4}\label{4}$$

These two has been taken from this research paper. Where Eq. 3 is called Parametric Algebraic Activation (PAA) function and Eq. 4 is called Parametric Hyperbolic Tangent Activation (PHTA) function. And the last one which I found is really good, is;

$$\bbox[5px,border:2px solid darkviolet] {sgn(x)\approx\operatorname{erf}\left(\frac{\sqrt{\pi}}{k_2}x\right),\;\;\;\;\;k_2 \to 0}\tag{Eq. 5}\label{5}$$

Unfortunately, I'm still finding the source paper for this. I'll put it soon enough (If anyone knows it, please edit it in, thank you). Here $erf$ is called the error function (also called the Gauss error function).This has been the best approximation that I could find. Now as that is over, here is my approximation; $$\bbox[5px,border:2px solid darkorange] {sgn(x)=\frac{kx}{|kx|!}||kx|-1|!, \;\;\;\;\; k≥1}\tag{Eq. 6}\label{6}$$

Now Eq. 6 is somewhat a really good approximation on its own, but Eq. 05 still beats it to a little degree. So I wanted to make another much more good expression, So I came up with this; $$\bbox[5px,border:2px solid red] {sgn(x)=\frac{k\left(x+\frac{x}{\left|kx\right|!}\right)\left(\left|\left|k\left(x+\frac{x}{\left|kx\right|!}\right)\right|-1\right|\right)!}{\left|k\left(x+\frac{x}{\left|kx\right|!}\right)\right|!}, \;\;\;\;\; k≥1}\tag{Eq. 7}\label{7}$$ Now this equation is just an extended form of Eq. 6 and is much more good.

And when I say it is good, I meant that even for fewer values of $k$, the graph of this approximation will tend to look like this;

enter image description here.

Btw, if you're thinking why are factorials doing in Eq 6 & 7, when it is only for integers, this uses the Gamma function (Γ) which extends the factorial function for all positive numbers as compared to the usual positive integers. Now there is one big motive to why I came up with Eq. 6; some may notice it, but as this is getting long as it is, I'm not going to explain.

And also the reason why I color-coded some of these approximations is that, I want to show them in a graphing calculator as follows. https://www.desmos.com/calculator/lsb0sonxxq. I've selected some of the best approximations and my 2 approximations for comparison. And all the colored lines are as per the respective color-coded approximation that I did in this post. Here is an image of it.

enter image description here

For the grph-image above, I put $k=4$ for Eq $\color{black}{4}$, $\color{orange}{6}$, $\color{red}{7}$ and $k_2=4^{-1}$ for Eq $\color{blue}{1}$, $\color{darkviolet}{5}$

FURTHERMORE; I know that this isn't much of a question that are usually asked in here, I just wanted to know whether my methods are correct or not as I was not able to get any help elsewhere. I'm really new to complex contents of math myself. So if I did any mistake or some of these are just too obvious or things I do ignorantly, please forgive them. Any opinion, criticism, comment is really appreciated.

So what do you guys think of this? I've never seen factorial function used in any approximations. And I think my approximation is kind of a Hard-sigmoid/Saturation type of function while the others are regular Sigmoids.