deepxde.utils¶
deepxde.utils.external module¶
External utilities.
-
class
deepxde.utils.external.
PointSet
(points)[source]¶ Bases:
object
A set of points.
Parameters: points – A NumPy array of shape (N, dx). A list of dx-dim points. -
inside
(x)[source]¶ Returns
True
if x is in this set of points, otherwise, returnsFalse
.Parameters: x – A NumPy array. A single point, or a list of points. Returns: - If x is a single point, returns
True
orFalse
. If x is a list of - points, returns a list of
True
orFalse
.
- If x is a single point, returns
-
values_to_func
(values, default_value=0)[source]¶ Convert the pairs of points and values to a callable function.
Parameters: - values – A NumPy array of shape (N, dy). values[i] is the dy-dim function value of the i-th point in this point set.
- default_value (float) – The function value of the points not in this point set.
Returns: - A callable function. The input of this function should be a NumPy array of
shape (?, dx).
-
-
deepxde.utils.external.
apply
(func, args=None, kwds=None)[source]¶ Launch a new process to call the function.
This can be used to clear Tensorflow GPU memory after model execution: https://stackoverflow.com/questions/39758094/clearing-tensorflow-gpu-memory-after-model-execution
-
deepxde.utils.external.
dat_to_csv
(dat_file_path, csv_file_path, columns)[source]¶ Converts a dat file to CSV format and saves it.
Parameters: - dat_file_path (string) – Path of the dat file.
- csv_file_path (string) – Desired path of the CSV file.
- columns (list) – Column names to be added in the CSV file.
-
deepxde.utils.external.
isclose
(a, b)[source]¶ A modified version of np.isclose for DeepXDE.
This function changes the value of atol due to the dtype of a and b. If the dtype is float16, atol is 1e-4. If it is float32, atol is 1e-6. Otherwise (for float64), the default is 1e-8. If you want to manually set atol for some reason, use np.isclose instead.
Parameters: b (a,) – Input arrays to compare.
-
deepxde.utils.external.
plot_best_state
(train_state)[source]¶ Plot the best result of the smallest training loss.
This function only works for 1D and 2D problems. For other problems and to better customize the figure, use
save_best_state()
.Note
You need to call
plt.show()
to show the figure.Parameters: train_state – TrainState
instance. The second variable returned fromModel.train()
.
-
deepxde.utils.external.
plot_loss_history
(loss_history, fname=None)[source]¶ Plot the training and testing loss history.
Note
You need to call
plt.show()
to show the figure.Parameters: - loss_history –
LossHistory
instance. The first variable returned fromModel.train()
. - fname (string) – If fname is a string (e.g., ‘loss_history.png’), then save the figure to the file of the file name fname.
- loss_history –
-
deepxde.utils.external.
save_best_state
(train_state, fname_train, fname_test)[source]¶ Save the best result of the smallest training loss to a file.
-
deepxde.utils.external.
save_loss_history
(loss_history, fname)[source]¶ Save the training and testing loss history to a file.
-
deepxde.utils.external.
saveplot
(loss_history, train_state, issave=True, isplot=True, loss_fname='loss.dat', train_fname='train.dat', test_fname='test.dat', output_dir=None)[source]¶ Save/plot the loss history and best trained result.
This function is used to quickly check your results. To better investigate your result, use
save_loss_history()
andsave_best_state()
.Parameters: - loss_history –
LossHistory
instance. The first variable returned fromModel.train()
. - train_state –
TrainState
instance. The second variable returned fromModel.train()
. - issave (bool) – Set
True
(default) to save the loss, training points, and testing points. - isplot (bool) – Set
True
(default) to plot loss, metric, and the predicted solution. - loss_fname (string) – Name of the file to save the loss in.
- train_fname (string) – Name of the file to save the training points in.
- test_fname (string) – Name of the file to save the testing points in.
- output_dir (string) – If
None
, use the current working directory.
- loss_history –
-
deepxde.utils.external.
standardize
(X_train, X_test)[source]¶ Standardize features by removing the mean and scaling to unit variance.
The mean and std are computed from the training data X_train using sklearn.preprocessing.StandardScaler, and then applied to the testing data X_test.
Parameters: - X_train – A NumPy array of shape (n_samples, n_features). The data used to compute the mean and standard deviation used for later scaling along the features axis.
- X_test – A NumPy array.
Returns: Instance of
sklearn.preprocessing.StandardScaler
. X_train: Transformed training data. X_test: Transformed testing data.Return type: scaler