pinnicle.utils
pinnicle.utils.backends_specified module
- pinnicle.utils.backends_specified.jacobian(output_var, input_var, i, j, val=0)
Compute jacobian using deepxde
- pinnicle.utils.backends_specified.jacobian_jax(output_var, input_var, i, j, val=0)[source]
Compute jacobian using deepxde This is a hack for now to take the first entry from the tuple returned by jax
- pinnicle.utils.backends_specified.jacobian_tf(output_var, input_var, i, j, val=0)[source]
Compute jacobian using deepxde
- pinnicle.utils.backends_specified.matmul(A, B)
- pinnicle.utils.backends_specified.slice_column(variable, i)
slice the column i:i+1 of variable, tensorflow version
- pinnicle.utils.backends_specified.slice_column_jax(variable, i)[source]
slice the column i:i+1 of variable, jax version currently jax output returns tuple (variable, function)
pinnicle.utils.data_misfit module
- pinnicle.utils.data_misfit.get(identifier)[source]
Retrieves a loss function.
- Parameters:
identifier – A loss identifier. String name of a loss function, or a loss function.
- Returns:
A loss function.
- pinnicle.utils.data_misfit.mean_absolute_percentage_error(y_true, y_pred)[source]
Calculates the Mean Absolute Percentage Error (MAPE).
- pinnicle.utils.data_misfit.mean_squared_log_error_jax(y_true, y_pred)[source]
use jax/numpy function to compute mean squared log error
- pinnicle.utils.data_misfit.mean_squared_log_error_paddle(y_true, y_pred)[source]
use log function to compute mean squared log error
- pinnicle.utils.data_misfit.mean_squared_log_error_pytorch(y_true, y_pred)[source]
use log function to compute mean squared log error
- pinnicle.utils.data_misfit.mean_squared_log_error_tf(y_true, y_pred)[source]
use tensorflow function to compute mean squared log error
- pinnicle.utils.data_misfit.surface_log_vel_misfit_jax(v_true, v_pred)[source]
Compute SurfaceLogVelMisfit: This function is for jax
- pinnicle.utils.data_misfit.surface_log_vel_misfit_paddle(v_true, v_pred)[source]
Compute SurfaceLogVelMisfit: This function is for paddle backend
pinnicle.utils.helper module
- pinnicle.utils.helper.coord_window_indices(coord, lo, hi, pad=0)[source]
Return slice indices for coord values between lo and hi. Works for both ascending and descending coordinate arrays.
- pinnicle.utils.helper.createsubdomain(xmin, ymin, xid, yid, dx=50000, dy=50000, margin=0)[source]
Create a rectangle subdomain within the large domain defined by the bottom-left corner and x, y indices
- Parameters:
xmin (float) – x coordinate of bottom-left corner of the large domain
ymin (float) – y coordinate of bottom-left corner of the large domain
xid (int) – x index of the subdomain (starting from 0)
yid (int) – y index of the subdomain (starting from 0)
dx (float, optional) – width of the subdomain. Defaults to 50000.
dy (float, optional) – height of the subdomain. Defaults to 50000.
margin (float, optional) – between 0 and 1, percentage of the margin extended beyond the given subdomain size
- Returns:
(x0, x1, y0, y1) coordinates of the subdomain, this need to be consistent with domain.shapebox
- Return type:
- pinnicle.utils.helper.down_sample(points, data_size)[source]
downsample points to be a size of data_size, the strategy is to call down_sample_core with at least double resolution required, then randomly choose
- Parameters:
points (np array)
data_size (Integer) – number of data points needed
- Returns:
indices of the downsample
- Return type:
ind
- pinnicle.utils.helper.down_sample_core(points, resolution=100)[source]
downsample the given scatter points using KDtree with the nearest neighbors on a Cartisian grid
- Parameters:
points (np array)
resolution (Integer) – resolution of the downsample grid
- Returns:
indices of the downsample
- Return type:
ind
- pinnicle.utils.helper.feathered_rect_weights(x, y, rect, width)[source]
Compute 2D weights for points (x, y) relative to an axis-aligned rectangle. Inside the rectangle: weight = 1 Outside, within width: weight = 1 - d / width (linear falloff) Outside, beyond width: weight = 0
- Parameters:
- Returns:
Weights in [0, 1] with shape broadcast from x and y.
- Return type:
(ndarray)
- pinnicle.utils.helper.load_dict_from_json(path, filename)[source]
Load a dict data from a .json file
pinnicle.utils.history module
pinnicle.utils.plotting module
- pinnicle.utils.plotting.diffplot(pinn, feature, feat_title=None, mdata='ISSM', sim='mae', figsize=(15, 4), cmap='jet', scale=1, clim=None, cbar_bins=10, elements=None)[source]
- pinnicle.utils.plotting.plot_data(X, Y, im_data, axs=None, vranges={}, **kwargs)[source]
plot all the data in im_data
- Parameters:
X (np.array) – x-coordinates of the 2D plot
Y (np.array) – y-coordinates of the 2D plot
im_data (dict) – Dict of data for the 2D plot, each element has the same size as X and Y
axs (array of AxesSubplot) – axes to plot each data, if not given, then generate a subplot according to the size of data_names
vranges (dict) – range of the data
- Returns:
axes of the subplots
- Return type:
axs (array of AxesSubplot)
- pinnicle.utils.plotting.plot_dict_data(X_dict, data_dict, axs=None, vranges={}, resolution=200, **kwargs)[source]
plot the data in data_dict, with coordinates in X_dict
- Parameters:
X_dict (dict) – Dict of the coordinates, with keys ‘x’, ‘y’
data_dict (dict) – Dict of data
axs (array of AxesSubplot) – axes to plot each data, if not given, then generate a subplot according to the size of data_names
vranges (dict) – range of the data
resolution (int) – number of pixels in horizontal and vertical direction
- Returns:
x-coordinates of the 2D plot Y (np.array): y-coordinates of the 2D plot im_data (dict): Dict of data for the 2D plot, each element has the same size as X and Y axs (array of AxesSubplot): axes of the subplots
- Return type:
X (np.array)
- pinnicle.utils.plotting.plot_nn(pinn, data_names=None, X_mask=None, axs=None, vranges={}, resolution=200, **kwargs)[source]
plot the prediction of the nerual network in pinn, according to the data_names
- Parameters:
pinn (class PINN) – The PINN model
data_names (list) – List of data names
X_mask (np.array) – xy-coordinates of the ice mask
axs (array of AxesSubplot) – axes to plot each data, if not given, then generate a subplot according to the size of data_names
vranges (dict) – range of the data
resolution (int) – number of pixels in horizontal and vertical direction
- Returns:
x-coordinates of the 2D plot Y (np.array): y-coordinates of the 2D plot im_data (dict): Dict of data for the 2D plot, each element has the same size as X and Y axs (array of AxesSubplot): axes of the subplots
- Return type:
X (np.array)
- pinnicle.utils.plotting.plot_solutions(pinn, path='', filename='2Dsolution.png', X_ref=None, sol_ref=None, cols=None, resolution=200, absvariable=[], default_time=None, **kwargs)[source]
plot model predictions
- Parameters:
path (Path, str) – Path to save the figures
filename (str) – name to save the figures, if set to None, then the figure will not be saved
X_ref (dict) – Coordinates of the reference solutions, if None, then just plot the predicted solutions
u_ref (dict) – Reference solutions, if None, then just plot the predicted solutions
cols (int) – Number of columns of subplot
resolution (int) – Number of grid points per row/column for plotting
absvariable (list) – Names of variables in the predictions that will need to take abs() before comparison
- pinnicle.utils.plotting.plot_tracks(pinn, feature, filepath=None, x_name_map='x', y_name_map='y', feat_name_map=None, gdata=None, mdata='ISSM', elements=None, scale=1, cmap='jet', figsize=(10, 8), clim=None, cbar_bins=10)[source]
plotting (sparse) ground truth data on top of prediction
- pinnicle.utils.plotting.resplot(pinn, mdata='ISSM', figsize=None, cmap='RdBu', cbar_bins=10, cbar_limits=[-5000.0, 5000.0], elements=None)[source]
plotting the pde residuals