diff --git a/deepxde/backend/paddle/tensor.py b/deepxde/backend/paddle/tensor.py index 1f59fb5e4..713ac9f58 100644 --- a/deepxde/backend/paddle/tensor.py +++ b/deepxde/backend/paddle/tensor.py @@ -231,9 +231,9 @@ def sparse_dense_matmul(x, y): return paddle.sparse.matmul(x, y) -def l1_regularization(x): - return paddle.regularizer.L1Decay(coeff=x) +def l1_regularization(l1): + return paddle.regularizer.L1Decay(coeff=l1) -def l2_regularization(x): - return paddle.regularizer.L2Decay(coeff=x) +def l2_regularization(l2): + return paddle.regularizer.L2Decay(coeff=l2) diff --git a/deepxde/backend/tensorflow_compat_v1/tensor.py b/deepxde/backend/tensorflow_compat_v1/tensor.py index cc928bdc5..52270260b 100644 --- a/deepxde/backend/tensorflow_compat_v1/tensor.py +++ b/deepxde/backend/tensorflow_compat_v1/tensor.py @@ -247,13 +247,13 @@ def sparse_dense_matmul(x, y): return tf.sparse.sparse_dense_matmul(x, y) -def l1_regularization(x): - return tf.keras.regularizers.L1(l1=x) +def l1_regularization(l1): + return tf.keras.regularizers.L1(l1=l1) -def l2_regularization(x): - return tf.keras.regularizers.L2(l2=x) +def l2_regularization(l2): + return tf.keras.regularizers.L2(l2=l2) -def l1_l2_regularization(x, y): - return tf.keras.regularizers.L1L2(l1=x, l2=y) +def l1_l2_regularization(l1, l2): + return tf.keras.regularizers.L1L2(l1=l1, l2=l2) diff --git a/deepxde/nn/regularizers.py b/deepxde/nn/regularizers.py index 5cc8686e1..0e63d2bfc 100644 --- a/deepxde/nn/regularizers.py +++ b/deepxde/nn/regularizers.py @@ -29,5 +29,6 @@ def get(identifier): if name in ("l1l2", "l1+l2"): # TODO: only supported by 'tensorflow.compat.v1' now. if len(factor) < 2: - return bkd.l1_l2_regularization(factor[0], factor[1]) + raise ValueError("L1L2 regularizer requires both L1/L2 penalties.") + return bkd.l1_l2_regularization(factor[0], factor[1]) raise ValueError(f"Unknown regularizer name: {name}")