PDE#
- class pinnx.problem.PDE(geometry, pde, constraints, approximator=None, solution=None, loss_fn='MSE', num_domain=0, num_boundary=0, num_test=None, train_distribution='Hammersley', anchors=None, exclusions=None, loss_weights=None)[source]#
ODE or time-independent PDE solver.
- Parameters:
geometry (
DictPointGeometry) – Instance ofGeometry.constraints (
Union[ICBC,Sequence[ICBC]]) – A boundary condition or a list of boundary conditions. Use[]if no boundary condition.approximator (
Optional[Module]) – A neural network trainer for approximating the solution.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 (
str) – 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 (
Union[Array,ndarray,bool,number,bool,int,float,complex,Quantity,None]) – 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 (
Callable[[PyTree],PyTree]) – The reference solution.num_test (
int) – 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. IfNone, then the training points will be used for testing.
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
Trainer.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
Trainer.predict()to predict the solution on these points and compute the metric:x = geometry.uniform_points(num, boundary=True) y_true = ... y_pred = trainer.predict(x) error= pinnx.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
trainer.compile().
- 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.
- 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.
- add_anchors(anchors)[source]#
Add new points for training PDE losses.
The BC points will not be updated.
- bc_points()[source]#
Generate boundary condition points.
- Returns:
The boundary condition points.
- Return type:
np.ndarray
- replace_with_anchors(anchors)[source]#
Replace the current PDE training points with anchors.
The BC points will not be changed.