Skip to content

Commit

Permalink
update code2
Browse files Browse the repository at this point in the history
  • Loading branch information
lijialin03 committed Dec 3, 2024
1 parent 3eefdf0 commit 700d788
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
8 changes: 4 additions & 4 deletions deepxde/backend/paddle/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
12 changes: 6 additions & 6 deletions deepxde/backend/tensorflow_compat_v1/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
3 changes: 2 additions & 1 deletion deepxde/nn/regularizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

0 comments on commit 700d788

Please sign in to comment.