deepxde.data
deepxde.data.constraint module
deepxde.data.data module
- class deepxde.data.data.Data[source]
Bases:
ABCData base class.
- losses(targets, outputs, loss_fn, inputs, model, aux=None)[source]
Return a list of losses, i.e., constraints.
- losses_test(targets, outputs, loss_fn, inputs, model, aux=None)[source]
Return a list of losses for test dataset, i.e., constraints.
- class deepxde.data.data.Tuple(train_x, train_y, test_x, test_y)[source]
Bases:
DataDataset with each data point as a tuple.
Each data tuple is split into two parts: input tuple (x) and output tuple (y).
deepxde.data.dataset module
- class deepxde.data.dataset.DataSet(X_train=None, y_train=None, X_test=None, y_test=None, fname_train=None, fname_test=None, col_x=None, col_y=None, standardize=False)[source]
Bases:
DataFitting Data set.
- Parameters:
col_x – List of integers.
col_y – List of integers.
deepxde.data.fpde module
- class deepxde.data.fpde.FPDE(geometry, fpde, alpha, bcs, resolution, meshtype='dynamic', num_domain=0, num_boundary=0, train_distribution='Hammersley', anchors=None, solution=None, num_test=None)[source]
Bases:
PDEFractional PDE solver.
The \(D\)-dimensional fractional Laplacian of order \(\alpha/2\) (\(1 < \alpha < 2\)) is defined as
\[(-\Delta)^{\alpha/2} u(x) = C(\alpha, D) \int_{\|\theta\|=1} D_{\theta}^\alpha u(x) \, d\theta,\]where\(C(\alpha, D) = \frac{\Gamma((1-\alpha)/2) \Gamma((D+\alpha)/2)}{2 \pi^{(D+1)/2}}\)
\(D_{\theta}^\alpha\) is the Riemann-Liouville directional fractional derivative.
\(\theta\) is the differentiation direction vector.
The solution \(u(x)\) is assumed to be identically zero in the boundary and exterior of the domain. When \(D = 1\), the constant simplifies to
\[C(\alpha, D) = \frac{1}{2 \cos(\alpha \pi / 2)}.\]Note
This solver does not consider \(C(\alpha, D)\) in the fractional Laplacian, and only discretizes \(\int_{\|\theta\|=1} D_{\theta}^\alpha u(x) \, d\theta\). The derivative \(D_{\theta}^\alpha\) is approximated by the Grünwald–Letnikov formula.
- losses_test(targets, outputs, loss_fn, inputs, model, aux=None)[source]
Return a list of losses for test dataset, i.e., constraints.
- class deepxde.data.fpde.Scheme(meshtype, resolution)[source]
Bases:
objectFractional Laplacian discretization.
Discretize fractional Laplacian using quadrature rule for the integral with respect to the directions and Grunwald-Letnikov (GL) formula for the Riemann-Liouville directional fractional derivative.
- Parameters:
meshtype (string) – “static” or “dynamic”.
resolution – A list of integer. The first number is the number of quadrature points in the first direction, …, and the last number is the GL parameter.
References
- class deepxde.data.fpde.TimeFPDE(geometryxtime, fpde, alpha, ic_bcs, resolution, meshtype='dynamic', num_domain=0, num_boundary=0, num_initial=0, train_distribution='Hammersley', anchors=None, solution=None, num_test=None)[source]
Bases:
FPDETime-dependent fractional PDE solver.
The \(D\)-dimensional fractional Laplacian of order \(\alpha/2\) (\(1 < \alpha < 2\)) is defined as
\[(-\Delta)^{\alpha/2} u(x) = C(\alpha, D) \int_{\|\theta\|=1} D_{\theta}^\alpha u(x) \, d\theta,\]where\(C(\alpha, D) = \frac{\Gamma((1-\alpha)/2) \Gamma((D+\alpha)/2)}{2 \pi^{(D+1)/2}}\)
\(D_{\theta}^\alpha\) is the Riemann-Liouville directional fractional derivative.
\(\theta\) is the differentiation direction vector.
The solution \(u(x)\) is assumed to be identically zero in the boundary and
exterior of the domain.
When \(D = 1\), the constant simplifies to
\[C(\alpha, D) = \frac{1}{2 \cos(\alpha \pi / 2)}.\]Note
This solver does not consider \(C(\alpha, D)\) in the fractional Laplacian calculation. It only discretizes the integral \(\int_{\|\theta\|=1} D_{\theta}^\alpha u(x) \, d\theta\), where \(D_{\theta}^\alpha\) is approximated by the Grünwald-Letnikov formula.
deepxde.data.func_constraint module
deepxde.data.function module
- class deepxde.data.function.Function(geometry, function, num_train, num_test, train_distribution='uniform', online=False)[source]
Bases:
DataApproximate a function via a network.
- Parameters:
geometry – The domain of the function. Instance of
Geometry.function – The function to be approximated. A callable function takes a NumPy array as the input and returns the a NumPy array of corresponding function values.
num_train (int) – The number of training points sampled inside the domain.
num_test (int)
train_distribution (string) – The distribution to sample training points. One of the following: “uniform” (equispaced grid), “pseudo” (pseudorandom), “LHS” (Latin hypercube sampling), “Halton” (Halton sequence), “Hammersley” (Hammersley sequence), or “Sobol” (Sobol sequence).
online (bool) – If
True, resample the pseudorandom training points every training step, otherwise, use the same training points.
deepxde.data.function_spaces module
- class deepxde.data.function_spaces.Chebyshev(N=100, M=1)[source]
Bases:
FunctionSpaceChebyshev polynomial.
p(x) = sum_{i=0}^{N-1} a_i T_i(x), where T_i is Chebyshev polynomial of the first kind. Note: The domain of x is scaled from [-1, 1] to [0, 1].
- Parameters:
N (int)
M (float) – M > 0. The coefficients a_i are randomly sampled from [-M, M].
- eval_batch(features, xs)[source]
Evaluate a list of functions at a list of points.
- Parameters:
features – A NumPy array of shape (n_functions, n_features). A list of the feature vectors of the functions to be evaluated.
xs – A NumPy array of shape (n_points, dim). A list of points to be evaluated.
- Returns:
A NumPy array of shape (n_functions, n_points). The values of different functions at different points.
- class deepxde.data.function_spaces.FunctionSpace[source]
Bases:
ABCFunction space base class.
Example
space = dde.data.GRF() feats = space.random(10) xs = np.linspace(0, 1, num=100)[:, None] y = space.eval_batch(feats, xs)
- abstractmethod eval_batch(features, xs)[source]
Evaluate a list of functions at a list of points.
- Parameters:
features – A NumPy array of shape (n_functions, n_features). A list of the feature vectors of the functions to be evaluated.
xs – A NumPy array of shape (n_points, dim). A list of points to be evaluated.
- Returns:
A NumPy array of shape (n_functions, n_points). The values of different functions at different points.
- class deepxde.data.function_spaces.GRF(T=1, kernel='RBF', length_scale=1, N=1000, interp='cubic')[source]
Bases:
FunctionSpaceGaussian random field (Gaussian process) in 1D.
The random sampling algorithm is based on Cholesky decomposition of the covariance matrix.
- Parameters:
T (float) – T > 0. The domain is [0, T].
kernel (str) – Name of the kernel function. “RBF” (radial-basis function kernel, squared-exponential kernel, Gaussian kernel), “AE” (absolute exponential kernel), or “ExpSineSquared” (Exp-Sine-Squared kernel, periodic kernel).
length_scale (float) – The length scale of the kernel.
N (int) – The size of the covariance matrix.
interp (str) – The interpolation to interpolate the random function. “linear”, “quadratic”, or “cubic”.
- eval_batch(features, xs)[source]
Evaluate a list of functions at a list of points.
- Parameters:
features – A NumPy array of shape (n_functions, n_features). A list of the feature vectors of the functions to be evaluated.
xs – A NumPy array of shape (n_points, dim). A list of points to be evaluated.
- Returns:
A NumPy array of shape (n_functions, n_points). The values of different functions at different points.
- class deepxde.data.function_spaces.GRF2D(kernel='RBF', length_scale=1, N=100, interp='splinef2d')[source]
Bases:
FunctionSpaceGaussian random field in [0, 1]x[0, 1].
The random sampling algorithm is based on Cholesky decomposition of the covariance matrix.
- Parameters:
kernel (str) – The kernel function. “RBF” (radial-basis function) or “AE” (absolute exponential).
length_scale (float) – The length scale of the kernel.
N (int) – The size of the covariance matrix.
interp (str) – The interpolation to interpolate the random function. “linear” or “splinef2d”.
Example
space = dde.data.GRF2D(length_scale=0.1) features = space.random(3) x = np.linspace(0, 1, num=500) y = np.linspace(0, 1, num=500) xv, yv = np.meshgrid(x, y) sensors = np.vstack((np.ravel(xv), np.ravel(yv))).T u = space.eval_batch(features, sensors) for ui in u: plt.figure() plt.imshow(np.reshape(ui, (len(y), len(x)))) plt.colorbar() plt.show()
- eval_batch(features, xs)[source]
Evaluate a list of functions at a list of points.
- Parameters:
features – A NumPy array of shape (n_functions, n_features). A list of the feature vectors of the functions to be evaluated.
xs – A NumPy array of shape (n_points, dim). A list of points to be evaluated.
- Returns:
A NumPy array of shape (n_functions, n_points). The values of different functions at different points.
- class deepxde.data.function_spaces.GRF_KL(T=1, kernel='RBF', length_scale=1, num_eig=10, N=100, interp='cubic')[source]
Bases:
FunctionSpaceGaussian random field (Gaussian process) in 1D.
The random sampling algorithm is based on truncated Karhunen-Loeve (KL) expansion.
- Parameters:
T (float) – T > 0. The domain is [0, T].
kernel (str) – The kernel function. “RBF” (radial-basis function) or “AE” (absolute exponential).
length_scale (float) – The length scale of the kernel.
num_eig (int) – The number of eigenfunctions in KL expansion to be kept.
N (int) – Each eigenfunction is discretized at N points in [0, T].
interp (str) – The interpolation to interpolate the random function. “linear”, “quadratic”, or “cubic”.
- eval_batch(features, xs)[source]
Evaluate a list of functions at a list of points.
- Parameters:
features – A NumPy array of shape (n_functions, n_features). A list of the feature vectors of the functions to be evaluated.
xs – A NumPy array of shape (n_points, dim). A list of points to be evaluated.
- Returns:
A NumPy array of shape (n_functions, n_points). The values of different functions at different points.
- class deepxde.data.function_spaces.PowerSeries(N=100, M=1)[source]
Bases:
FunctionSpacePower series.
p(x) = sum_{i=0}^{N-1} a_i x^i
- Parameters:
N (int)
M (float) – M > 0. The coefficients a_i are randomly sampled from [-M, M].
- eval_batch(features, xs)[source]
Evaluate a list of functions at a list of points.
- Parameters:
features – A NumPy array of shape (n_functions, n_features). A list of the feature vectors of the functions to be evaluated.
xs – A NumPy array of shape (n_points, dim). A list of points to be evaluated.
- Returns:
A NumPy array of shape (n_functions, n_points). The values of different functions at different points.
deepxde.data.helper module
deepxde.data.ide module
- class deepxde.data.ide.IDE(geometry, ide, bcs, quad_deg, kernel=None, num_domain=0, num_boundary=0, train_distribution='Hammersley', anchors=None, solution=None, num_test=None)[source]
Bases:
PDEIDE solver.
The current version only supports 1D problems with the integral int_0^x K(x, t) y(t) dt.
- Parameters:
kernel – (x, t) –> R.
- losses_test(targets, outputs, loss_fn, inputs, model, aux=None)[source]
Return a list of losses for test dataset, i.e., constraints.
deepxde.data.mf module
- class deepxde.data.mf.MfDataSet(X_lo_train=None, X_hi_train=None, y_lo_train=None, y_hi_train=None, X_hi_test=None, y_hi_test=None, fname_lo_train=None, fname_hi_train=None, fname_hi_test=None, col_x=None, col_y=None, standardize=False)[source]
Bases:
DataMultifidelity function approximation from data set.
- Parameters:
col_x – List of integers.
col_y – List of integers.
- losses_test(targets, outputs, loss_fn, inputs, model, aux=None)[source]
Return a list of losses for test dataset, i.e., constraints.
deepxde.data.pde module
- class deepxde.data.pde.PDE(geometry, pde, bcs, num_domain=0, num_boundary=0, train_distribution='Hammersley', anchors=None, exclusions=None, solution=None, num_test=None, auxiliary_var_function=None)[source]
Bases:
DataODE or time-independent PDE solver.
- Parameters:
geometry – Instance of
Geometry.pde – A global PDE or a list of PDEs.
Noneif no global PDE.bcs – A boundary condition or a list of boundary conditions. Use
[]if no boundary condition.num_domain (int) – The number of training points sampled inside the domain.
num_boundary (int) – The number of training points sampled on the boundary.
train_distribution (string) – The distribution to sample training points. One of the following: “uniform” (equispaced grid), “pseudo” (pseudorandom), “LHS” (Latin hypercube sampling), “Halton” (Halton sequence), “Hammersley” (Hammersley sequence), or “Sobol” (Sobol sequence).
anchors – A Numpy array of training points, in addition to the num_domain and num_boundary sampled points.
exclusions – A Numpy array of points to be excluded for training.
solution – The reference solution.
num_test – The number of points sampled inside the domain for testing PDE loss. The testing points for BCs/ICs are the same set of points used for training. If
None, then the training points will be used for testing.auxiliary_var_function – A function that inputs train_x or test_x and outputs auxiliary variables.
Warning
The testing points include points inside the domain and points on the boundary, and they may not have the same density, and thus the entire testing points may not be uniformly distributed. As a result, if you have a reference solution (solution) and would like to compute a metric such as
Model.compile(metrics=["l2 relative error"])
then the metric may not be very accurate. To better compute a metric, you can sample the points manually, and then use
Model.predict()to predict the solution on thess points and compute the metric:x = geom.uniform_points(num, boundary=True) y_true = ... y_pred = model.predict(x) error= dde.metrics.l2_relative_error(y_true, y_pred)
- train_x_all
A Numpy array of points for PDE training. train_x_all is unordered, and does not have duplication. If there is PDE, then train_x_all is used as the training points of PDE.
- train_x_bc
A Numpy array of the training points for BCs. train_x_bc is constructed from train_x_all at the first step of training, by default it won’t be updated when train_x_all changes. To update train_x_bc, set it to None and call bc_points, and then update the loss function by
model.compile().
- num_bcs
num_bcs[i] is the number of points for bcs[i].
- Type:
list
- train_x
A Numpy array of the points fed into the network for training. train_x is ordered from BC points (train_x_bc) to PDE points (train_x_all), and may have duplicate points.
- train_aux_vars
Auxiliary variables that associate with train_x.
- test_x
A Numpy array of the points fed into the network for testing, ordered from BCs to PDE. The BC points are exactly the same points in train_x_bc.
- test_aux_vars
Auxiliary variables that associate with test_x.
- add_anchors(anchors)[source]
Add new points for training PDE losses.
The BC points will not be updated.
- losses(targets, outputs, loss_fn, inputs, model, aux=None)[source]
Return a list of losses, i.e., constraints.
- replace_with_anchors(anchors)[source]
Replace the current PDE training points with anchors.
The BC points will not be changed.
- class deepxde.data.pde.TimePDE(geometryxtime, pde, ic_bcs, num_domain=0, num_boundary=0, num_initial=0, train_distribution='Hammersley', anchors=None, exclusions=None, solution=None, num_test=None, auxiliary_var_function=None)[source]
Bases:
PDETime-dependent PDE solver.
- Parameters:
num_initial (int) – The number of training points sampled on the initial location.
deepxde.data.pde_operator module
- class deepxde.data.pde_operator.PDEOperator(pde, function_space, evaluation_points, num_function, function_variables=None, num_test=None)[source]
Bases:
DataPDE solution operator.
- Parameters:
pde – Instance of
dde.data.PDEordde.data.TimePDE.function_space – Instance of
dde.data.FunctionSpace.evaluation_points – A NumPy array of shape (n_points, dim). Discretize the input function sampled from function_space using pointwise evaluations at a set of points as the input of the branch net.
num_function (int) – The number of functions for training.
function_variables –
Noneor a list of integers. The functions in the function_space may not have the same domain as the PDE. For example, the PDE is defined on a spatio-temporal domain (x, t), but the function is IC, which is only a function of x. In this case, we need to specify the variables of the function by function_variables=[0], where 0 indicates the first variable x. IfNone, then we assume the domains of the function and the PDE are the same.num_test – The number of functions for testing PDE loss. The testing functions for BCs/ICs are the same functions used for training. If
None, then the training functions will be used for testing.
- train_bc
A triple of three Numpy arrays (v, x, vx) fed into PIDeepONet for training BCs/ICs.
- num_bcs
num_bcs[i] is the number of points for bcs[i].
- Type:
list
- train_x
A tuple of two Numpy arrays (v, x) fed into PIDeepONet for training. v is the function input to the branch net; x is the point input to the trunk net. train_x is ordered from BCs/ICs (train_bc) to PDEs.
- train_aux_vars
v(x), i.e., the value of v evaluated at x.
- losses(targets, outputs, loss_fn, inputs, model, aux=None)[source]
Return a list of losses, i.e., constraints.
- class deepxde.data.pde_operator.PDEOperatorCartesianProd(pde, function_space, evaluation_points, num_function, function_variables=None, num_test=None, batch_size=None)[source]
Bases:
DataPDE solution operator with data in the format of Cartesian product.
- Parameters:
pde – Instance of
dde.data.PDEordde.data.TimePDE.function_space – Instance of
dde.data.FunctionSpace.evaluation_points – A NumPy array of shape (n_points, dim). Discretize the input function sampled from function_space using pointwise evaluations at a set of points as the input of the branch net.
num_function (int) – The number of functions for training.
function_variables –
Noneor a list of integers. The functions in the function_space may not have the same domain as the PDE. For example, the PDE is defined on a spatio-temporal domain (x, t), but the function is IC, which is only a function of x. In this case, we need to specify the variables of the function by function_variables=[0], where 0 indicates the first variable x. IfNone, then we assume the domains of the function and the PDE are the same.num_test – The number of functions for testing PDE loss. The testing functions for BCs/ICs are the same functions used for training. If
None, then the training functions will be used for testing.batch_size – Integer or
None.
- train_x
A tuple of two Numpy arrays (v, x) fed into PIDeepONet for training. v is the function input to the branch net and has the shape (N1, dim1); x is the point input to the trunk net and has the shape (N2, dim2).
- train_aux_vars
v(x), i.e., the value of v evaluated at x, has the shape (N1, N2).
- losses_test(targets, outputs, loss_fn, inputs, model, aux=None)[source]
Return a list of losses for test dataset, i.e., constraints.
deepxde.data.quadruple module
- class deepxde.data.quadruple.Quadruple(X_train, y_train, X_test, y_test)[source]
Bases:
DataDataset with each data point as a quadruple.
The couple of the first three elements are the input, and the fourth element is the output. This dataset can be used with the network
MIONetfor operator learning.- Parameters:
X_train – A tuple of three NumPy arrays.
y_train – A NumPy array.
- class deepxde.data.quadruple.QuadrupleCartesianProd(X_train, y_train, X_test, y_test)[source]
Bases:
DataCartesian Product input data format for MIONet architecture.
This dataset can be used with the network
MIONetCartesianProdfor operator learning.- Parameters:
X_train – A tuple of three NumPy arrays. The first element has the shape (N1, dim1), the second element has the shape (N1, dim2), and the third element has the shape (N2, dim3).
y_train – A NumPy array of shape (N1, N2).
deepxde.data.sampler module
- class deepxde.data.sampler.BatchSampler(num_samples, shuffle=True)[source]
Bases:
objectSamples a mini-batch of indices.
The indices are repeated indefinitely. Has the same effect as:
indices = tf.data.Dataset.range(num_samples) indices = indices.repeat().shuffle(num_samples).batch(batch_size) iterator = iter(indices) batch_indices = iterator.get_next()
However,
tf.data.Dataset.__iter__()is only supported inside oftf.functionor when eager execution is enabled.tf.data.Dataset.make_one_shot_iterator()supports graph mode, but is too slow.This class is not implemented as a Python Iterator, so that it can support dynamic batch size.
- Parameters:
num_samples (int) – The number of samples.
shuffle (bool) – Set to
Trueto have the indices reshuffled at every epoch.
- property epochs_completed
deepxde.data.triple module
- class deepxde.data.triple.Triple(X_train, y_train, X_test, y_test)[source]
Bases:
DataDataset with each data point as a triple.
The couple of the first two elements are the input, and the third element is the output. This dataset can be used with the network
DeepONetfor operator learning.- Parameters:
X_train – A tuple of two NumPy arrays.
y_train – A NumPy array.
References
- class deepxde.data.triple.TripleCartesianProd(X_train, y_train, X_test, y_test)[source]
Bases:
DataDataset with each data point as a triple. The ordered pair of the first two elements are created from a Cartesian product of the first two lists. If we compute the Cartesian product of the first two arrays, then we have a
Tripledataset.This dataset can be used with the network
DeepONetCartesianProdfor operator learning.- Parameters:
X_train – A tuple of two NumPy arrays. The first element has the shape (N1, dim1), and the second element has the shape (N2, dim2).
y_train – A NumPy array of shape (N1, N2).