Skip to content
This repository was archived by the owner on May 6, 2025. It is now read-only.

Commit de2a61d

Browse files
SiuMathromanngg
authored andcommitted
Adding a sigmoid like function to mimic the real sigmoid function, which will be useful for network that outputs a probability distribution or RNN. The choice of the values of a, b and c is justified in the colab below:
https://colab.corp.google.com/drive/1C9IrZzp3tAL96FQAL67upa33NtVTneWL?usp=sharing PiperOrigin-RevId: 327654635
1 parent ae66cb8 commit de2a61d

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

neural_tangents/stax.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1349,13 +1349,26 @@ def Identity() -> InternalLayer:
13491349
return init_fn, apply_fn, kernel_fn
13501350

13511351

1352+
def Sigmoid_like():
1353+
"""A sigmoid like function `f(x) = .5 * erf(x / 2.4020563531719796) + .5`.
1354+
1355+
The constant `2.4020563531719796` is chosen so that the squared loss between
1356+
this function the ground true sigmoid is minimized in the interval [-5, 5];
1357+
see https://gist.github.com/SiuMath/679e8bb4bce13d5f2383a27eca649575.
1358+
1359+
Returns:
1360+
`(init_fn, apply_fn, kernel_fn)`.
1361+
"""
1362+
return Erf(a=0.5, b=1/2.4020563531719796, c=0.5)
1363+
1364+
13521365
@layer
13531366
@_supports_masking(remask_kernel=True)
13541367
def Erf(a: float = 1.,
13551368
b: float = 1.,
13561369
c: float = 0.,
13571370
do_backprop: bool = False) -> InternalLayer:
1358-
"""Affine transform of `Erf` nonlinearity, i.e. `a Erf(b * x) + c`.
1371+
"""Affine transform of `Erf` nonlinearity, i.e. `a * Erf(b * x) + c`.
13591372
13601373
Args:
13611374
a: output scale.

0 commit comments

Comments
 (0)