pinnx.utils module#

Internal utilities.

This module provides utility functions for array operations, data conversion, visualization, sampling, and other helper functions used throughout PINNx.

Conversion Helpers#

Functions for converting between dictionary and array representations.

array_to_dict

Convert args to a dictionary.

dict_to_array

Convert a dictionary to an array.

Array Operations#

Utilities for tensor and array manipulation.

is_tensor

istensorlist

convert_to_array

Convert a list of numpy arrays or tensors to a numpy array or a tensor.

hstack

zero_padding

Training Utilities#

Functions for training, visualization, and result management.

apply: Apply a function element-wise.

standardize: Standardize data to zero mean and unit variance.

saveplot: Save and plot training results.

plot_loss_history: Plot loss history over iterations.

save_loss_history: Save loss history to file.

plot_best_state: Plot best model state.

save_best_state: Save best model state.

dat_to_csv: Convert .dat files to .csv format.

isclose: Check if values are close within tolerance.

smart_numpy: Convert to NumPy array intelligently.

apply

Launch a new process to call the function.

standardize

Standardize features by removing the mean and scaling to unit variance.

saveplot

Save/plot the loss history and best trained result.

plot_loss_history

Plot the training and testing loss history.

save_loss_history

Save the training and testing loss history to a file.

plot_best_state

Plot the best result of the smallest training loss.

save_best_state

Save the best result of the smallest training loss to a file.

dat_to_csv

Converts a dat file to CSV format and saves it.

isclose

A modified version of np.isclose for DeepXDE.

smart_numpy

Internal Helpers#

Internal utility functions for PINNx operations.

timing

Decorator for measuring the execution time of methods.

merge_dict

subdict

Get a sub-dictionary from a dictionary.

check_not_none

run_if_all_none

run_if_any_none

vectorize

numpy.vectorize wrapper that works with instance methods.

return_tensor

Convert the output to a Tensor.

to_numpy

Create numpy ndarrays that shares the same underlying storage, if possible.

make_dict

Convert two lists or two variables into a dictionary.

save_animation

list_to_str

Loss Functions#

Loss functions for training neural networks.

Sampling Helpers#

Batch sampling utilities.

BatchSampler

Samples a mini-batch of indices.

Sampling Strategies#

Point sampling strategies for training data generation.

sample: Generic sampling function.

pseudorandom: Pseudorandom sampling.

quasirandom: Quasi-random (low-discrepancy) sampling.

InitialPointGenerator: Generates initial training points.

check_random_state: Validates random state.

check_dimension: Validates dimension parameter.

sample

Generate pseudorandom or quasirandom samples in [0, 1]^dimension.

pseudorandom

Pseudo random.

quasirandom

InitialPointGenerator

check_random_state

check_dimension

Turn a provided dimension description into a dimension object.

Transformers#

Data transformation and preprocessing utilities.

Transformer: Base transformer class.

Identity: Identity transformation.

StringEncoder: Encode strings to numerical values.

LogN: Logarithmic transformation.

CategoricalEncoder: Encode categorical variables.

LabelEncoder: Encode labels.

Normalize: Normalize data.

Pipeline: Chain multiple transformers.

Transformer

Base class for all 1-D transformers.

Identity

Identity transform.

StringEncoder

StringEncoder transform.

LogN

Base N logarithm transform.

CategoricalEncoder

OneHotEncoder that can handle categorical variables.

LabelEncoder

LabelEncoder that can handle categorical variables.

Normalize

Scales each dimension into the interval [0, 1].

Pipeline

A lightweight pipeline to chain transformers.