Skip to content

Commit

Permalink
Backend paddle: Add the type conversion of dde.data.MfDataSet to supp…
Browse files Browse the repository at this point in the history
…ort examples (#1897)
  • Loading branch information
lijialin03 authored Jan 6, 2025
1 parent 36e3233 commit 2de79c9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
26 changes: 15 additions & 11 deletions deepxde/data/mf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import numpy as np

from .data import Data
from ..backend import tf
from .. import backend as bkd
from .. import config
from ..utils import run_if_any_none, standardize


Expand Down Expand Up @@ -83,20 +84,20 @@ def __init__(
standardize=False,
):
if X_lo_train is not None:
self.X_lo_train = X_lo_train
self.X_hi_train = X_hi_train
self.y_lo_train = y_lo_train
self.y_hi_train = y_hi_train
self.X_hi_test = X_hi_test
self.y_hi_test = y_hi_test
self.X_lo_train = X_lo_train.astype(config.real(np))
self.X_hi_train = X_hi_train.astype(config.real(np))
self.y_lo_train = y_lo_train.astype(config.real(np))
self.y_hi_train = y_hi_train.astype(config.real(np))
self.X_hi_test = X_hi_test.astype(config.real(np))
self.y_hi_test = y_hi_test.astype(config.real(np))
elif fname_lo_train is not None:
data = np.loadtxt(fname_lo_train)
data = np.loadtxt(fname_lo_train).astype(config.real(np))
self.X_lo_train = data[:, col_x]
self.y_lo_train = data[:, col_y]
data = np.loadtxt(fname_hi_train)
data = np.loadtxt(fname_hi_train).astype(config.real(np))
self.X_hi_train = data[:, col_x]
self.y_hi_train = data[:, col_y]
data = np.loadtxt(fname_hi_test)
data = np.loadtxt(fname_hi_test).astype(config.real(np))
self.X_hi_test = data[:, col_x]
self.y_hi_test = data[:, col_y]
else:
Expand All @@ -116,7 +117,10 @@ def losses_train(self, targets, outputs, loss_fn, inputs, model, aux=None):
return [loss_lo, loss_hi]

def losses_test(self, targets, outputs, loss_fn, inputs, model, aux=None):
return [0, loss_fn(targets[1], outputs[1])]
return [
bkd.as_tensor(0, dtype=config.real(bkd.lib)),
loss_fn(targets[1], outputs[1]),
]

@run_if_any_none("X_train", "y_train")
def train_next_batch(self, batch_size=None):
Expand Down
2 changes: 1 addition & 1 deletion examples/function/func_uncertainty.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Backend supported: tensorflow.compat.v1, tensorflow"""
"""Backend supported: tensorflow.compat.v1, tensorflow, paddle"""
import deepxde as dde
import numpy as np

Expand Down
2 changes: 1 addition & 1 deletion examples/function/mf_dataset.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Backend supported: tensorflow.compat.v1"""
"""Backend supported: tensorflow.compat.v1, paddle"""
import deepxde as dde


Expand Down
2 changes: 1 addition & 1 deletion examples/function/mf_func.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Backend supported: tensorflow.compat.v1"""
"""Backend supported: tensorflow.compat.v1, paddle"""
import deepxde as dde
import numpy as np

Expand Down

0 comments on commit 2de79c9

Please sign in to comment.