Skip to content

Commit dbcc23f

Browse files
committed
Support layer-wise locally adaptive activation function
1 parent fd34acf commit dbcc23f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

deepxde/maps/activations.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,37 @@
22
from __future__ import division
33
from __future__ import print_function
44

5+
from .. import config
56
from ..backend import tf
67

78

89
def linear(x):
910
return x
1011

1112

13+
def layer_wise_locally_adaptive(activation, n=1):
14+
"""Layer-wise locally adaptive activation functions (L-LAAF).
15+
Jagtap et al., arXiv preprint arXiv:1909.12228, 2019.
16+
17+
Examples:
18+
To define a L-LAAF ReLU with the scaling factor ``n = 10``
19+
```python
20+
n = 10
21+
activation = f"LAAF-{n} relu" # "LAAF-10 relu"
22+
```
23+
"""
24+
a = tf.Variable(1 / n, dtype=config.real(tf))
25+
return lambda x: activation(n * a * x)
26+
27+
1228
def get(identifier):
1329
if identifier is None:
1430
return linear
1531
if isinstance(identifier, str):
32+
if identifier.startswith("LAAF"):
33+
identifier = identifier.split()
34+
n = float(identifier[0].split("-")[1])
35+
return layer_wise_locally_adaptive(get(identifier[1]), n=n)
1636
return {
1737
"elu": tf.nn.elu,
1838
"relu": tf.nn.relu,

0 commit comments

Comments
 (0)