Model Library (pypielm.models)

Model library: all PIELM variants, PINN baselines, and the model registry.

Public surface:

from pypielm.models import (
    CorePIELM, VanillaPIELM, BayesianPIELM, GFFPIELM,
    DPIELM, LocELM, DDELMCoarse,
    CurriculumPIELM,
    NullSpacePIELM, EigPIELM, LSEELM, StefanPIELM,
    NormalEquationELM, ParameterRetentionELM, PiecewiseELM, DELM,
    FPIELM, SGEPIELM, RINN, RaNNPIELM, XPIELM,
    PIELMRVDS, TSPIELM, KAPIELM, SoftPartitionKAPIELM,
    VanillaPINN, AdaptivePINN, FourierPINN, MuonPINN,
    ResidualAdaptivePINN,
    get_model, MODEL_REGISTRY,
)
class pypielm.models.VanillaPIELM(hidden_dim=200, ridge_lambda=1e-08, activation='tanh', seed=42, device='cpu', dtype=torch.float64)[source]

ELM regression with random features and ridge solve — no physics.

Parameters:
  • hidden_dim (int) – Number of random neurons.

  • ridge_lambda (float) – Ridge regularisation lambda.

  • activation (str) – Activation function name.

  • seed (int) – Random seed for hidden-layer weights.

  • device (str | device) – PyTorch device.

  • dtype (dtype) – Floating-point dtype.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, **kwargs)[source]

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs – List of boundary condition objects (DirichletBC, etc.).

  • ics – List of initial condition objects.

  • collocation_sampler – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

predict(X)[source]

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

score(X, y, metric='relative_l2')[source]

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

get_feature_matrix(X)[source]

Return the hidden-layer activation matrix Φ(X).

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d).

Return type:

Tensor

Returns:

Feature matrix H of shape (N, hidden_dim).

forward(X)[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Return type:

Tensor

class pypielm.models.CorePIELM(hidden_dim=200, ridge_lambda=1e-08, activation='tanh', w_pde=1.0, w_bc=1.0, w_ic=1.0, solver='ridge', seed=42, device='cpu', dtype=torch.float64)[source]

Physics-Informed ELM: random features + physics-augmented linear system.

Assembles an augmented weighted least-squares system from PDE collocation blocks, boundary/initial condition blocks, and optionally observed data, then solves analytically via ridge regression or RRQR.

The pde_operator argument is a callable with signature:

pde_operator(feature_map, X_colloc) -> WeightedLinearSystem

where WeightedLinearSystem.H is the PDE operator applied to the feature matrix (e.g. the Laplacian feature matrix) and WeightedLinearSystem.y is the RHS of the PDE evaluated at the collocation points.

Parameters:
  • hidden_dim (int) – Number of random neurons.

  • ridge_lambda (float) – Regularisation strength.

  • activation (str) – Activation function.

  • w_pde (float) – Weight on PDE residual rows.

  • w_bc (float) – Weight on boundary condition rows.

  • w_ic (float) – Weight on initial condition rows.

  • solver (str) – 'ridge' or 'rrqr'.

  • seed (int) – Random seed.

  • device (str | device) – PyTorch device.

  • dtype (dtype) – Floating-point dtype.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)[source]

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator (Any | None) – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs (list[Any] | None) – List of boundary condition objects (DirichletBC, etc.).

  • ics (list[Any] | None) – List of initial condition objects.

  • collocation_sampler (Any | None) – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

predict(X)[source]

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

score(X, y, metric='relative_l2')[source]

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

get_feature_matrix(X)[source]

Return the hidden-layer activation matrix Φ(X).

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d).

Return type:

Tensor

Returns:

Feature matrix H of shape (N, hidden_dim).

forward(X)[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Return type:

Tensor

class pypielm.models.BayesianPIELM(hidden_dim=200, activation='tanh', prior_precision=0.0001, w_pde=1.0, w_bc=1.0, w_ic=1.0, w_data=1.0, seed=42, device='cpu', dtype=torch.float64)[source]

Physics-Informed ELM with Bayesian output-weight estimation.

Instead of a single ridge solve, this model computes the full posterior distribution over output weights β via sequential Bayesian updates:

\[p(\boldsymbol{\beta} \mid \text{data}, \text{PDE}) = \mathcal{N}(\boldsymbol{\mu}_{\text{post}}, \boldsymbol{\Lambda}_{\text{post}}^{-1})\]

Prediction is the posterior mean; uncertainty is propagated through the output layer giving pointwise confidence intervals on the PDE solution.

Parameters:
  • hidden_dim (int) – Number of random neurons.

  • activation (str) – Activation function name.

  • prior_precision (float) – Precision α of the isotropic Gaussian prior on β.

  • w_pde (float) – Observation precision for PDE collocation blocks.

  • w_bc (float) – Observation precision for boundary condition blocks.

  • w_ic (float) – Observation precision for initial condition blocks.

  • w_data (float) – Observation precision for data-fit block.

  • seed (int) – Random seed.

  • device (str | device) – PyTorch device.

  • dtype (dtype) – Floating-point dtype.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)[source]

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator (Any | None) – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs (list[Any] | None) – List of boundary condition objects (DirichletBC, etc.).

  • ics (list[Any] | None) – List of initial condition objects.

  • collocation_sampler (Any | None) – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

predict(X)[source]

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

predict_with_uncertainty(X)[source]

Return (posterior mean, posterior std) at input points X.

Parameters:

X (ndarray | Tensor) – Input coordinates, shape (N, d).

Return type:

tuple[Tensor, Tensor]

Returns:

Tuple (mean, std) each of shape (N, out_dim).

score(X, y, metric='relative_l2')[source]

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

get_feature_matrix(X)[source]

Return the hidden-layer activation matrix Φ(X).

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d).

Return type:

Tensor

Returns:

Feature matrix H of shape (N, hidden_dim).

class pypielm.models.GFFPIELM(hidden_dim=200, freq_init='log_uniform', freq_min=1.0, freq_max=100.0, ridge_lambda=1e-08, w_pde=1.0, w_bc=1.0, w_ic=1.0, solver='ridge', seed=42, device='cpu', dtype=torch.float64)[source]

Generalised Fourier Feature PIELM (GFF-PIELM).

Port of GFF-PIELM/gff_pielm.py to PyTorch with GPU support.

Each hidden neuron computes:

\[\phi_j(\mathbf{x}) = \sqrt{2} \cos\!\left( \omega_j \, \mathbf{w}_j^\top \mathbf{x} + b_j \right)\]

The analytic second derivative w.r.t. each input dimension is used directly (no autograd overhead).

Parameters:
  • hidden_dim (int) – Number of Fourier neurons.

  • freq_init (Literal['uniform', 'log_uniform', 'auto']) – Frequency initialisation strategy ('log_uniform', 'uniform').

  • freq_min (float) – Minimum frequency value.

  • freq_max (float) – Maximum frequency value.

  • ridge_lambda (float) – Output-weight regularisation.

  • w_pde (float) – Weight for PDE residual block.

  • w_bc (float) – Weight for BC block.

  • w_ic (float) – Weight for IC block.

  • solver (str) – 'ridge' or 'rrqr'.

  • seed (int) – Random seed.

  • device (str | device) – Target device.

  • dtype (dtype) – Floating-point dtype.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)[source]

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator (Any | None) – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs (list[Any] | None) – List of boundary condition objects (DirichletBC, etc.).

  • ics (list[Any] | None) – List of initial condition objects.

  • collocation_sampler (Any | None) – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

predict(X)[source]

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

score(X, y, metric='relative_l2')[source]

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

get_feature_matrix(X)[source]

Return the hidden-layer activation matrix Φ(X).

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d).

Return type:

Tensor

Returns:

Feature matrix H of shape (N, hidden_dim).

class pypielm.models.DPIELM(n_subdomains=4, overlap=0.1, hidden_dim=128, ridge_lambda=1e-08, activation='tanh', seed=42, device='cpu', dtype=torch.float64)[source]

Distributed PIELM with fixed uniform domain decomposition.

The spatial domain is partitioned into n_subdomains regions along the first spatial axis. Each subdomain trains an independent ELM. Predictions are assembled by assigning each query point to its containing subdomain.

Parameters:
  • n_subdomains (int) – Number of subdomains.

  • overlap (float) – Fractional overlap between adjacent subdomains (0 = none).

  • hidden_dim (int) – Hidden neurons per subdomain.

  • ridge_lambda (float) – Regularisation per subdomain.

  • activation (str) – Activation function.

  • seed (int) – Random seed.

  • device (str | device) – Target device.

  • dtype (dtype) – Floating-point dtype.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

class pypielm.models.LocELM(n_subdomains=6, overlap=0.25, hidden_dim=160, ridge_lambda=1e-08, activation='tanh', seed=42, device='cpu', dtype=torch.float64)[source]

Localised ELM (LocELM): independent local feature maps per subdomain.

Similar to DPIELM but each subdomain has its own independently initialised random feature map (different seed per subdomain).

Parameters:
  • n_subdomains (int) – Number of subdomains.

  • overlap (float) – Fractional overlap between adjacent subdomains.

  • hidden_dim (int) – Hidden neurons per subdomain.

  • ridge_lambda (float) – Regularisation per subdomain.

  • activation (str) – Activation function.

  • seed (int) – Base random seed; each subdomain gets seed + sub_id.

  • device (str | device) – Target device.

  • dtype (dtype) – Floating-point dtype.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

class pypielm.models.DDELMCoarse(n_subdomains=6, overlap=0.15, hidden_dim=128, coarse_hidden_dim=64, coarse_alpha=0.2, ridge_lambda=1e-08, activation='tanh', seed=42, device='cpu', dtype=torch.float64)[source]

Domain-Decomposition ELM with a coarse global correction layer.

Combines a local domain-decomposition solve (like DPIELM) with a single global ELM trained on the full dataset, blending the two predictions:

\[\hat{u}(x) = (1 - \alpha_{\text{coarse}})\, \hat{u}_{\text{local}}(x) + \alpha_{\text{coarse}}\, \hat{u}_{\text{coarse}}(x)\]
Parameters:
  • n_subdomains (int) – Number of local subdomains.

  • overlap (float) – Subdomain overlap fraction.

  • hidden_dim (int) – Hidden neurons per subdomain.

  • coarse_hidden_dim (int) – Hidden neurons in the global correction ELM.

  • coarse_alpha (float) – Blending weight for the coarse model (default 0.2).

  • ridge_lambda (float) – Regularisation.

  • activation (str) – Activation function.

  • seed (int) – Random seed.

  • device (str | device) – Target device.

  • dtype (dtype) – Floating-point dtype.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, **kwargs)[source]

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs – List of boundary condition objects (DirichletBC, etc.).

  • ics – List of initial condition objects.

  • collocation_sampler – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

predict(X)[source]

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

class pypielm.models.CurriculumPIELM(hidden_dim=200, ridge_lambda=1e-08, activation='tanh', n_stages=5, n_collocation=1000, n_candidates=5000, refine_ratio=0.5, seed=42, device='cpu', dtype=torch.float64)[source]

Physics-Informed ELM with curriculum (residual-adaptive) collocation.

Training proceeds in n_stages rounds. In each round:

  1. Solve for β on the current collocation set (ridge solve).

  2. Evaluate PDE residual |H_pde @ β f| at a dense candidate set.

  3. Replace refine_ratio fraction of collocation points with points sampled from the high-residual tail of the candidate distribution.

  4. Repeat until n_stages is reached.

Parameters:
  • hidden_dim (int) – Number of random neurons.

  • ridge_lambda (float) – Regularisation strength.

  • activation (str) – Activation name.

  • n_stages (int) – Number of curriculum refinement rounds.

  • n_collocation (int) – Number of collocation points per stage.

  • n_candidates (int) – Number of dense candidate points used for residual evaluation.

  • refine_ratio (float) – Fraction of collocation points replaced each stage.

  • seed (int) – Random seed.

  • device (str | device) – Target device.

  • dtype (dtype) – Floating-point dtype.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)[source]

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator (Any | None) – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs (list[Any] | None) – List of boundary condition objects (DirichletBC, etc.).

  • ics (list[Any] | None) – List of initial condition objects.

  • collocation_sampler (Any | None) – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

predict(X)[source]

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

score(X, y, metric='relative_l2')[source]

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

get_feature_matrix(X)[source]

Return the hidden-layer activation matrix Φ(X).

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d).

Return type:

Tensor

Returns:

Feature matrix H of shape (N, hidden_dim).

class pypielm.models.NullSpacePIELM(hidden_dim=200, ridge_lambda=1e-08, activation='tanh', null_tol=1e-10, w_pde=1.0, seed=42, device='cpu', dtype=torch.float64)[source]

Hard BC enforcement via null-space projection.

  1. Assembles the BC constraint matrix C = H_bc (shape (N_bc, H)).

  2. Computes the null space Z of C via truncated SVD.

  3. Projects the physics/data linear system onto Z: (H_full @ Z) @ α = y_full.

  4. Solves for α, then recovers β = Z @ α.

This guarantees H_bc @ β = 0 exactly (up to numerical rank tolerance), meaning the approximation satisfies the BCs by construction.

Parameters:
  • hidden_dim (int) – Number of random neurons.

  • ridge_lambda (float) – Regularisation strength.

  • activation (str) – Activation function.

  • null_tol (float) – SVD tolerance for null-space truncation.

  • w_pde (float) – Weight on PDE block.

  • seed (int) – Random seed.

  • device (str | device) – Target device.

  • dtype (dtype) – Floating-point dtype.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)[source]

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator (Any | None) – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs (list[Any] | None) – List of boundary condition objects (DirichletBC, etc.).

  • ics (list[Any] | None) – List of initial condition objects.

  • collocation_sampler (Any | None) – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

predict(X)[source]

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

score(X, y, metric='relative_l2')[source]

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

get_feature_matrix(X)[source]

Return the hidden-layer activation matrix Φ(X).

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d).

Return type:

Tensor

Returns:

Feature matrix H of shape (N, hidden_dim).

class pypielm.models.EigPIELM(hidden_dim=200, ridge_lambda=1e-08, activation='tanh', eig_threshold=1e-08, seed=42, device='cpu', dtype=torch.float64)[source]

Eigenvector-based PIELM for hard BC enforcement.

Uses the eigen-decomposition of CᵀC (C = BC feature matrix) to partition the weight space into BC-satisfying and unconstrained subspaces.

Parameters:
  • hidden_dim (int) – Number of random neurons.

  • ridge_lambda (float) – Regularisation.

  • activation (str) – Activation function.

  • eig_threshold (float) – Eigenvalue threshold below which eigenvectors are treated as BC-satisfying.

  • seed (int) – Random seed.

  • device (str | device) – Target device.

  • dtype (dtype) – Floating-point dtype.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)[source]

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator (Any | None) – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs (list[Any] | None) – List of boundary condition objects (DirichletBC, etc.).

  • ics (list[Any] | None) – List of initial condition objects.

  • collocation_sampler (Any | None) – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

predict(X)[source]

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

score(X, y, metric='relative_l2')[source]

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

get_feature_matrix(X)[source]

Return the hidden-layer activation matrix Φ(X).

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d).

Return type:

Tensor

Returns:

Feature matrix H of shape (N, hidden_dim).

class pypielm.models.LSEELM(hidden_dim=200, ridge_lambda=1e-08, activation='tanh', w_pde=1.0, seed=42, device='cpu', dtype=torch.float64)[source]

Least-squares ELM with explicit equality constraints (Lagrange / KKT).

Solves the constrained optimisation:

\[\min_\beta \frac{1}{2}\|H\beta - y\|^2 + \frac{\lambda}{2}\|\beta\|^2 \quad \text{subject to} \quad C\beta = g\]

via the KKT system:

\[\begin{split}\begin{pmatrix} H^\top H + \lambda I & C^\top \\ C & 0 \end{pmatrix} \begin{pmatrix} \beta \\ \mu \end{pmatrix} = \begin{pmatrix} H^\top y \\ g \end{pmatrix}\end{split}\]
Parameters:
  • hidden_dim (int) – Number of random neurons.

  • ridge_lambda (float) – Regularisation for the unconstrained part.

  • activation (str) – Activation function.

  • w_pde (float) – PDE block weight.

  • seed (int) – Random seed.

  • device (str | device) – Target device.

  • dtype (dtype) – Floating-point dtype.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)[source]

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator (Any | None) – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs (list[Any] | None) – List of boundary condition objects (DirichletBC, etc.).

  • ics (list[Any] | None) – List of initial condition objects.

  • collocation_sampler (Any | None) – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

predict(X)[source]

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

score(X, y, metric='relative_l2')[source]

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

get_feature_matrix(X)[source]

Return the hidden-layer activation matrix Φ(X).

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d).

Return type:

Tensor

Returns:

Feature matrix H of shape (N, hidden_dim).

class pypielm.models.StefanPIELM(hidden_dim=200, ridge_lambda=1e-08, activation='tanh', n_iter=10, stefan_lr=0.1, seed=42, device='cpu', dtype=torch.float64)[source]

PIELM for Stefan-type free-boundary problems.

Iteratively tracks a 1-D interface s(t) between two phases. At each iteration:

  1. Fix interface location s.

  2. Fit a CorePIELM-like model on each phase subdomain.

  3. Update s to enforce the Stefan condition [u]_s = 0.

  4. Repeat until s converges.

This is a simplified single-front, 1-D implementation.

Parameters:
  • hidden_dim (int) – Neurons per subdomain.

  • ridge_lambda (float) – Regularisation.

  • activation (str) – Activation.

  • n_iter (int) – Interface update iterations.

  • stefan_lr (float) – Learning rate for interface position update.

  • seed (int) – Random seed.

  • device (str | device) – Target device.

  • dtype (dtype) – Floating-point dtype.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)[source]

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator (Any | None) – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs (list[Any] | None) – List of boundary condition objects (DirichletBC, etc.).

  • ics (list[Any] | None) – List of initial condition objects.

  • collocation_sampler (Any | None) – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

predict(X)[source]

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

score(X, y, metric='relative_l2')[source]

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

get_feature_matrix(X)[source]

Return the hidden-layer activation matrix Φ(X).

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d).

Return type:

Tensor

Returns:

Feature matrix H of shape (N, hidden_dim).

class pypielm.models.NormalEquationELM(**kwargs)

NormalEquationELM: thin wrapper over CorePIELM.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator (Any | None) – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs (list[Any] | None) – List of boundary condition objects (DirichletBC, etc.).

  • ics (list[Any] | None) – List of initial condition objects.

  • collocation_sampler (Any | None) – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

get_feature_matrix(X)

Return the hidden-layer activation matrix Φ(X).

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d).

Return type:

Tensor

Returns:

Feature matrix H of shape (N, hidden_dim).

predict(X)

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

score(X, y, metric='relative_l2')

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

class pypielm.models.ParameterRetentionELM(**kwargs)

ParameterRetentionELM: thin wrapper over CorePIELM.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator (Any | None) – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs (list[Any] | None) – List of boundary condition objects (DirichletBC, etc.).

  • ics (list[Any] | None) – List of initial condition objects.

  • collocation_sampler (Any | None) – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

get_feature_matrix(X)

Return the hidden-layer activation matrix Φ(X).

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d).

Return type:

Tensor

Returns:

Feature matrix H of shape (N, hidden_dim).

predict(X)

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

score(X, y, metric='relative_l2')

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

class pypielm.models.PiecewiseELM(**kwargs)

PiecewiseELM: thin wrapper over CorePIELM.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator (Any | None) – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs (list[Any] | None) – List of boundary condition objects (DirichletBC, etc.).

  • ics (list[Any] | None) – List of initial condition objects.

  • collocation_sampler (Any | None) – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

get_feature_matrix(X)

Return the hidden-layer activation matrix Φ(X).

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d).

Return type:

Tensor

Returns:

Feature matrix H of shape (N, hidden_dim).

predict(X)

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

score(X, y, metric='relative_l2')

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

class pypielm.models.DELM(**kwargs)

DELM: thin wrapper over CorePIELM.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator (Any | None) – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs (list[Any] | None) – List of boundary condition objects (DirichletBC, etc.).

  • ics (list[Any] | None) – List of initial condition objects.

  • collocation_sampler (Any | None) – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

get_feature_matrix(X)

Return the hidden-layer activation matrix Φ(X).

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d).

Return type:

Tensor

Returns:

Feature matrix H of shape (N, hidden_dim).

predict(X)

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

score(X, y, metric='relative_l2')

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

class pypielm.models.FPIELM(**kwargs)

FPIELM: thin wrapper over CorePIELM.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator (Any | None) – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs (list[Any] | None) – List of boundary condition objects (DirichletBC, etc.).

  • ics (list[Any] | None) – List of initial condition objects.

  • collocation_sampler (Any | None) – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

get_feature_matrix(X)

Return the hidden-layer activation matrix Φ(X).

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d).

Return type:

Tensor

Returns:

Feature matrix H of shape (N, hidden_dim).

predict(X)

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

score(X, y, metric='relative_l2')

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

class pypielm.models.SGEPIELM(**kwargs)

SGEPIELM: thin wrapper over CorePIELM.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator (Any | None) – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs (list[Any] | None) – List of boundary condition objects (DirichletBC, etc.).

  • ics (list[Any] | None) – List of initial condition objects.

  • collocation_sampler (Any | None) – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

get_feature_matrix(X)

Return the hidden-layer activation matrix Φ(X).

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d).

Return type:

Tensor

Returns:

Feature matrix H of shape (N, hidden_dim).

predict(X)

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

score(X, y, metric='relative_l2')

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

class pypielm.models.RINN(**kwargs)

RINN: thin wrapper over CorePIELM.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator (Any | None) – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs (list[Any] | None) – List of boundary condition objects (DirichletBC, etc.).

  • ics (list[Any] | None) – List of initial condition objects.

  • collocation_sampler (Any | None) – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

get_feature_matrix(X)

Return the hidden-layer activation matrix Φ(X).

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d).

Return type:

Tensor

Returns:

Feature matrix H of shape (N, hidden_dim).

predict(X)

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

score(X, y, metric='relative_l2')

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

class pypielm.models.RaNNPIELM(**kwargs)

RaNNPIELM: thin wrapper over CorePIELM.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator (Any | None) – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs (list[Any] | None) – List of boundary condition objects (DirichletBC, etc.).

  • ics (list[Any] | None) – List of initial condition objects.

  • collocation_sampler (Any | None) – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

get_feature_matrix(X)

Return the hidden-layer activation matrix Φ(X).

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d).

Return type:

Tensor

Returns:

Feature matrix H of shape (N, hidden_dim).

predict(X)

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

score(X, y, metric='relative_l2')

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

class pypielm.models.XPIELM(**kwargs)

XPIELM: thin wrapper over CorePIELM.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator (Any | None) – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs (list[Any] | None) – List of boundary condition objects (DirichletBC, etc.).

  • ics (list[Any] | None) – List of initial condition objects.

  • collocation_sampler (Any | None) – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

get_feature_matrix(X)

Return the hidden-layer activation matrix Φ(X).

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d).

Return type:

Tensor

Returns:

Feature matrix H of shape (N, hidden_dim).

predict(X)

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

score(X, y, metric='relative_l2')

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

class pypielm.models.PIELMRVDS(**kwargs)

PIELMRVDS: thin wrapper over CorePIELM.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator (Any | None) – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs (list[Any] | None) – List of boundary condition objects (DirichletBC, etc.).

  • ics (list[Any] | None) – List of initial condition objects.

  • collocation_sampler (Any | None) – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

get_feature_matrix(X)

Return the hidden-layer activation matrix Φ(X).

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d).

Return type:

Tensor

Returns:

Feature matrix H of shape (N, hidden_dim).

predict(X)

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

score(X, y, metric='relative_l2')

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

class pypielm.models.TSPIELM(**kwargs)

TSPIELM: thin wrapper over CorePIELM.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator (Any | None) – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs (list[Any] | None) – List of boundary condition objects (DirichletBC, etc.).

  • ics (list[Any] | None) – List of initial condition objects.

  • collocation_sampler (Any | None) – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

get_feature_matrix(X)

Return the hidden-layer activation matrix Φ(X).

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d).

Return type:

Tensor

Returns:

Feature matrix H of shape (N, hidden_dim).

predict(X)

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

score(X, y, metric='relative_l2')

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

class pypielm.models.KAPIELM(**kwargs)

KAPIELM: thin wrapper over CorePIELM.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator (Any | None) – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs (list[Any] | None) – List of boundary condition objects (DirichletBC, etc.).

  • ics (list[Any] | None) – List of initial condition objects.

  • collocation_sampler (Any | None) – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

get_feature_matrix(X)

Return the hidden-layer activation matrix Φ(X).

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d).

Return type:

Tensor

Returns:

Feature matrix H of shape (N, hidden_dim).

predict(X)

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

score(X, y, metric='relative_l2')

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

class pypielm.models.SoftPartitionKAPIELM(**kwargs)

SoftPartitionKAPIELM: thin wrapper over CorePIELM.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator (Any | None) – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs (list[Any] | None) – List of boundary condition objects (DirichletBC, etc.).

  • ics (list[Any] | None) – List of initial condition objects.

  • collocation_sampler (Any | None) – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

get_feature_matrix(X)

Return the hidden-layer activation matrix Φ(X).

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d).

Return type:

Tensor

Returns:

Feature matrix H of shape (N, hidden_dim).

predict(X)

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

score(X, y, metric='relative_l2')

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

class pypielm.models.VanillaPINN(layer_dims=None, activation='tanh', optimizer='adam', lr=0.001, max_epochs=10000, w_pde=1.0, w_bc=1.0, w_ic=1.0, seed=42, device='cpu', dtype=torch.float64)[source]

Standard Physics-Informed Neural Network (MLP backbone).

Trains via Adam (default) or L-BFGS by minimising a weighted sum of:

\[\mathcal{L} = w_{\text{pde}}\,\mathcal{L}_{\text{pde}} + w_{\text{bc}}\,\mathcal{L}_{\text{bc}} + w_{\text{ic}}\,\mathcal{L}_{\text{ic}} + \mathcal{L}_{\text{data}}\]
Parameters:
  • layer_dims (list[int] | None) – Width of each hidden layer, e.g. [50, 50, 50].

  • activation (str) – Hidden activation ('tanh', 'sin', 'relu', 'softplus').

  • optimizer (str) – 'adam' or 'lbfgs'.

  • lr (float) – Learning rate for Adam (L-BFGS ignores this; uses line search).

  • max_epochs (int) – Maximum number of training epochs / outer L-BFGS iterations.

  • w_pde (float) – Weight on PDE residual loss term.

  • w_bc (float) – Weight on BC loss term.

  • w_ic (float) – Weight on IC loss term.

  • seed (int) – Random seed for weight initialisation.

  • device (str | device) – Target device ('cpu', 'cuda', 'mps').

  • dtype (dtype) – Floating-point dtype (torch.float64 default).

Example:

from pypielm.models import VanillaPINN
model = VanillaPINN(layer_dims=[64, 64], max_epochs=5000)
model.fit(dataset, pde_operator=laplacian_op)
u_pred = model.predict(X_test)

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)[source]

Train the PINN on dataset.

Parameters:
  • dataset (PIELMDataset) – PIELMDataset with collocation, boundary, and optionally observation points.

  • pde_operator (Any | None) – Callable (fm, X_colloc) WeightedLinearSystem used to evaluate PDE residuals. When provided, the loss includes a PDE term.

  • bcs (list[Any] | None) – Explicit boundary condition objects (optional; falls back to dataset.X_bc / y_bc).

  • ics (list[Any] | None) – Explicit initial condition objects (optional).

  • collocation_sampler (Any | None) – Not used by gradient-based PINN (reserved for future adaptive variants).

Return type:

VanillaPINN

Returns:

self

predict(X)[source]

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

score(X, y, metric='relative_l2')[source]

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

get_feature_matrix(X)[source]

Return the last hidden-layer activations as the feature matrix.

Return type:

Tensor

class pypielm.models.AdaptivePINN(*, n_colloc=500, n_candidates=2000, update_every=100, domain_lb=None, domain_ub=None, resample_ratio=0.5, **kwargs)[source]

PINN with residual-based importance weighting on collocation points.

After every update_every Adam steps, collocation points are re-sampled from n_candidates candidates by drawing n_colloc points with probability proportional to the squared PDE residual (Anagnostopoulos et al., 2024; Lu et al., 2021 RAR).

Parameters:
  • n_colloc (int) – Number of collocation points to keep each iteration.

  • n_candidates (int) – Candidate pool for residual evaluation.

  • update_every (int) – Resampling interval (epochs).

  • domain_lb (list[float] | None) – Lower bound of the sampling domain (tensor or list).

  • domain_ub (list[float] | None) – Upper bound of the sampling domain (tensor or list).

  • resample_ratio (float) – Fraction of points replaced at each update.

  • **kwargs (Any) – Forwarded to VanillaPINN.

Example:

model = AdaptivePINN(
    n_colloc=500, domain_lb=[0.0], domain_ub=[1.0],
    update_every=100, layer_dims=[64, 64],
)
model.fit(dataset, pde_operator=laplacian_op)

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)[source]

Train with periodic adaptive collocation resampling.

Return type:

AdaptivePINN

class pypielm.models.FourierPINN(*, sigma=10.0, n_fourier=64, **kwargs)[source]

PINN with Fourier input encoding (Tancik et al., 2020).

Replaces the raw coordinate input with a random Fourier feature encoding:

\[\gamma(\mathbf{x}) = [\cos(2\pi\mathbf{B}\mathbf{x}), \sin(2\pi\mathbf{B}\mathbf{x})]\]

where each entry of B is drawn from \(\mathcal{N}(0, \sigma^2)\). This lifts the input into a \(2m\)-dimensional space and mitigates spectral bias.

Parameters:
  • sigma (float) – Standard deviation of the Gaussian frequency matrix.

  • n_fourier (int) – Number of Fourier features m (output dim = 2m).

  • **kwargs (Any) – Forwarded to VanillaPINN.

Example:

model = FourierPINN(sigma=10.0, n_fourier=64, layer_dims=[64, 64])
model.fit(dataset, pde_operator=laplacian_op)

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)[source]

Train FourierPINN — encodes inputs before building the MLP.

Return type:

FourierPINN

class pypielm.models.MuonPINN(*, momentum=0.95, ns_steps=5, **kwargs)[source]

PINN trained with the Muon (orthogonal momentum) optimizer.

Muon orthogonalises parameter updates via Newton-Schulz iteration, which improves conditioning and reduces loss of rank in weight matrices.

Parameters:
  • momentum (float) – Nesterov momentum coefficient (default 0.95).

  • ns_steps (int) – Number of Newton-Schulz iterations (default 5).

  • **kwargs (Any) – Forwarded to VanillaPINN.

Example:

model = MuonPINN(layer_dims=[64, 64], momentum=0.95, max_epochs=5000)
model.fit(dataset, pde_operator=laplacian_op)

Initialize internal Module state, shared by both nn.Module and ScriptModule.

class pypielm.models.ResidualAdaptivePINN(width=64, n_blocks=3, activation='tanh', optimizer='adam', lr=0.001, max_epochs=10000, w_pde=1.0, w_bc=1.0, w_ic=1.0, n_new=20, update_every=100, max_colloc=2000, n_candidates=5000, domain_lb=None, domain_ub=None, seed=42, device='cpu', dtype=torch.float64)[source]

ResNet-backbone PINN with adaptive collocation sampling.

Combines:

  • A residual network (skip connections) backbone for improved gradient flow in deep networks.

  • Residual-adaptive collocation (RAR; Lu et al., 2021): every update_every epochs, n_new fresh points are added in high-residual regions, capped at max_colloc total collocation points.

Parameters:
  • width (int) – Hidden-layer width for all residual blocks.

  • n_blocks (int) – Number of residual blocks.

  • activation (str) – Activation function name.

  • optimizer (str) – 'adam' or 'lbfgs'.

  • lr (float) – Learning rate.

  • max_epochs (int) – Maximum training epochs.

  • w_pde (float) – PDE loss weight.

  • w_bc (float) – BC loss weight.

  • w_ic (float) – IC loss weight.

  • n_new (int) – Points added per RAR update.

  • update_every (int) – RAR update interval (epochs).

  • max_colloc (int) – Maximum collocation pool size.

  • n_candidates (int) – Candidate pool for RAR evaluation.

  • domain_lb (list[float] | None) – Lower bound of sampling domain.

  • domain_ub (list[float] | None) – Upper bound of sampling domain.

  • seed (int) – Random seed.

  • device (str | device) – Target device.

  • dtype (dtype) – Floating-point dtype.

Example:

model = ResidualAdaptivePINN(
    width=64, n_blocks=3, max_epochs=5000,
    domain_lb=[0.0], domain_ub=[1.0],
)
model.fit(dataset, pde_operator=laplacian_op)

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)[source]

Train with ResNet backbone and RAR collocation refinement.

Return type:

ResidualAdaptivePINN

pypielm.models.get_model(name, **kwargs)[source]

Instantiate a registered model by name.

Parameters:
  • name (str) – Model name as registered via register(). Case-insensitive.

  • **kwargs (Any) – Constructor arguments forwarded to the model class.

Return type:

BasePIELM

Returns:

Instantiated model object.

Raises:

KeyError – If name is not in the registry.

Example:

model = get_model("core_pielm", hidden_dim=300, ridge_lambda=1e-8)
pypielm.models.register(name)[source]

Class decorator that registers a PIELM/PINN model under name.

Parameters:

name (str) – The string key used in YAML configs and the CLI.

Return type:

Callable[[type], type]

Returns:

The unmodified class (decorator is side-effect only).

Example:

@register("vanilla_pielm")
class VanillaPIELM(BasePIELM):
    ...

Registry

Model registry: maps string names to PIELM/PINN model classes.

The registry is populated automatically via the register() decorator. All model classes in this package self-register at import time, so YAML configs and CLI commands can reference models by name without hardcoded imports.

pypielm.models.registry.register(name)[source]

Class decorator that registers a PIELM/PINN model under name.

Parameters:

name (str) – The string key used in YAML configs and the CLI.

Return type:

Callable[[type], type]

Returns:

The unmodified class (decorator is side-effect only).

Example:

@register("vanilla_pielm")
class VanillaPIELM(BasePIELM):
    ...
pypielm.models.registry.get_model(name, **kwargs)[source]

Instantiate a registered model by name.

Parameters:
  • name (str) – Model name as registered via register(). Case-insensitive.

  • **kwargs (Any) – Constructor arguments forwarded to the model class.

Return type:

BasePIELM

Returns:

Instantiated model object.

Raises:

KeyError – If name is not in the registry.

Example:

model = get_model("core_pielm", hidden_dim=300, ridge_lambda=1e-8)

VanillaPIELM / CorePIELM

Vanilla and Core PIELM models.

  • VanillaPIELM — ELM with random features and ridge regression. No physics information; pure data-driven regression. Useful as a performance lower-bound.

  • CorePIELM — the standard Physics-Informed ELM formulation. Assembles collocation blocks for PDE interior, boundary, and initial conditions into one augmented linear system and solves with ridge or RRQR.

class pypielm.models.vanilla.VanillaPIELM(hidden_dim=200, ridge_lambda=1e-08, activation='tanh', seed=42, device='cpu', dtype=torch.float64)[source]

Bases: BasePIELM

ELM regression with random features and ridge solve — no physics.

Parameters:
  • hidden_dim (int) – Number of random neurons.

  • ridge_lambda (float) – Ridge regularisation lambda.

  • activation (str) – Activation function name.

  • seed (int) – Random seed for hidden-layer weights.

  • device (str | device) – PyTorch device.

  • dtype (dtype) – Floating-point dtype.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, **kwargs)[source]

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs – List of boundary condition objects (DirichletBC, etc.).

  • ics – List of initial condition objects.

  • collocation_sampler – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

predict(X)[source]

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

score(X, y, metric='relative_l2')[source]

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

get_feature_matrix(X)[source]

Return the hidden-layer activation matrix Φ(X).

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d).

Return type:

Tensor

Returns:

Feature matrix H of shape (N, hidden_dim).

forward(X)[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Return type:

Tensor

class pypielm.models.vanilla.CorePIELM(hidden_dim=200, ridge_lambda=1e-08, activation='tanh', w_pde=1.0, w_bc=1.0, w_ic=1.0, solver='ridge', seed=42, device='cpu', dtype=torch.float64)[source]

Bases: BasePIELM

Physics-Informed ELM: random features + physics-augmented linear system.

Assembles an augmented weighted least-squares system from PDE collocation blocks, boundary/initial condition blocks, and optionally observed data, then solves analytically via ridge regression or RRQR.

The pde_operator argument is a callable with signature:

pde_operator(feature_map, X_colloc) -> WeightedLinearSystem

where WeightedLinearSystem.H is the PDE operator applied to the feature matrix (e.g. the Laplacian feature matrix) and WeightedLinearSystem.y is the RHS of the PDE evaluated at the collocation points.

Parameters:
  • hidden_dim (int) – Number of random neurons.

  • ridge_lambda (float) – Regularisation strength.

  • activation (str) – Activation function.

  • w_pde (float) – Weight on PDE residual rows.

  • w_bc (float) – Weight on boundary condition rows.

  • w_ic (float) – Weight on initial condition rows.

  • solver (str) – 'ridge' or 'rrqr'.

  • seed (int) – Random seed.

  • device (str | device) – PyTorch device.

  • dtype (dtype) – Floating-point dtype.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)[source]

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator (Any | None) – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs (list[Any] | None) – List of boundary condition objects (DirichletBC, etc.).

  • ics (list[Any] | None) – List of initial condition objects.

  • collocation_sampler (Any | None) – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

predict(X)[source]

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

score(X, y, metric='relative_l2')[source]

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

get_feature_matrix(X)[source]

Return the hidden-layer activation matrix Φ(X).

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d).

Return type:

Tensor

Returns:

Feature matrix H of shape (N, hidden_dim).

forward(X)[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Return type:

Tensor

BayesianPIELM

Bayesian PIELM model.

Port of BPIELM/bpielm.py to a PyTorch-native, GPU-aware implementation. Uses sequential Bayesian linear regression over weighted observation blocks (PDE interior, BCs, ICs, data) rather than a single ridge solve, providing posterior uncertainty estimates for the output weights.

class pypielm.models.bayesian.BayesianPIELM(hidden_dim=200, activation='tanh', prior_precision=0.0001, w_pde=1.0, w_bc=1.0, w_ic=1.0, w_data=1.0, seed=42, device='cpu', dtype=torch.float64)[source]

Bases: BasePIELM

Physics-Informed ELM with Bayesian output-weight estimation.

Instead of a single ridge solve, this model computes the full posterior distribution over output weights β via sequential Bayesian updates:

\[p(\boldsymbol{\beta} \mid \text{data}, \text{PDE}) = \mathcal{N}(\boldsymbol{\mu}_{\text{post}}, \boldsymbol{\Lambda}_{\text{post}}^{-1})\]

Prediction is the posterior mean; uncertainty is propagated through the output layer giving pointwise confidence intervals on the PDE solution.

Parameters:
  • hidden_dim (int) – Number of random neurons.

  • activation (str) – Activation function name.

  • prior_precision (float) – Precision α of the isotropic Gaussian prior on β.

  • w_pde (float) – Observation precision for PDE collocation blocks.

  • w_bc (float) – Observation precision for boundary condition blocks.

  • w_ic (float) – Observation precision for initial condition blocks.

  • w_data (float) – Observation precision for data-fit block.

  • seed (int) – Random seed.

  • device (str | device) – PyTorch device.

  • dtype (dtype) – Floating-point dtype.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)[source]

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator (Any | None) – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs (list[Any] | None) – List of boundary condition objects (DirichletBC, etc.).

  • ics (list[Any] | None) – List of initial condition objects.

  • collocation_sampler (Any | None) – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

predict(X)[source]

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

predict_with_uncertainty(X)[source]

Return (posterior mean, posterior std) at input points X.

Parameters:

X (ndarray | Tensor) – Input coordinates, shape (N, d).

Return type:

tuple[Tensor, Tensor]

Returns:

Tuple (mean, std) each of shape (N, out_dim).

score(X, y, metric='relative_l2')[source]

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

get_feature_matrix(X)[source]

Return the hidden-layer activation matrix Φ(X).

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d).

Return type:

Tensor

Returns:

Feature matrix H of shape (N, hidden_dim).

GFF-PIELM (Fourier)

GFF-PIELM: Generalised Fourier Feature Physics-Informed ELM.

Uses FourierFeatureMap instead of a standard random feature map. The multi-scale frequency set enables accurate approximation of high-frequency PDE solutions that standard random-activation ELMs fail to capture.

class pypielm.models.fourier.GFFPIELM(hidden_dim=200, freq_init='log_uniform', freq_min=1.0, freq_max=100.0, ridge_lambda=1e-08, w_pde=1.0, w_bc=1.0, w_ic=1.0, solver='ridge', seed=42, device='cpu', dtype=torch.float64)[source]

Bases: BasePIELM

Generalised Fourier Feature PIELM (GFF-PIELM).

Port of GFF-PIELM/gff_pielm.py to PyTorch with GPU support.

Each hidden neuron computes:

\[\phi_j(\mathbf{x}) = \sqrt{2} \cos\!\left( \omega_j \, \mathbf{w}_j^\top \mathbf{x} + b_j \right)\]

The analytic second derivative w.r.t. each input dimension is used directly (no autograd overhead).

Parameters:
  • hidden_dim (int) – Number of Fourier neurons.

  • freq_init (Literal['uniform', 'log_uniform', 'auto']) – Frequency initialisation strategy ('log_uniform', 'uniform').

  • freq_min (float) – Minimum frequency value.

  • freq_max (float) – Maximum frequency value.

  • ridge_lambda (float) – Output-weight regularisation.

  • w_pde (float) – Weight for PDE residual block.

  • w_bc (float) – Weight for BC block.

  • w_ic (float) – Weight for IC block.

  • solver (str) – 'ridge' or 'rrqr'.

  • seed (int) – Random seed.

  • device (str | device) – Target device.

  • dtype (dtype) – Floating-point dtype.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)[source]

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator (Any | None) – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs (list[Any] | None) – List of boundary condition objects (DirichletBC, etc.).

  • ics (list[Any] | None) – List of initial condition objects.

  • collocation_sampler (Any | None) – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

predict(X)[source]

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

score(X, y, metric='relative_l2')[source]

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

get_feature_matrix(X)[source]

Return the hidden-layer activation matrix Φ(X).

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d).

Return type:

Tensor

Returns:

Feature matrix H of shape (N, hidden_dim).

Domain Decomposition

Domain-decomposition PIELM variants.

  • DPIELM — Distributed PIELM: fixed uniform decomposition.

  • LocELM — Localised ELM: each subdomain has its own feature map.

  • DDELMCoarse — DD-ELM with a coarse global correction layer.

class pypielm.models.domain.DPIELM(n_subdomains=4, overlap=0.1, hidden_dim=128, ridge_lambda=1e-08, activation='tanh', seed=42, device='cpu', dtype=torch.float64)[source]

Bases: _DomainDecompositionBase

Distributed PIELM with fixed uniform domain decomposition.

The spatial domain is partitioned into n_subdomains regions along the first spatial axis. Each subdomain trains an independent ELM. Predictions are assembled by assigning each query point to its containing subdomain.

Parameters:
  • n_subdomains (int) – Number of subdomains.

  • overlap (float) – Fractional overlap between adjacent subdomains (0 = none).

  • hidden_dim (int) – Hidden neurons per subdomain.

  • ridge_lambda (float) – Regularisation per subdomain.

  • activation (str) – Activation function.

  • seed (int) – Random seed.

  • device (str | device) – Target device.

  • dtype (dtype) – Floating-point dtype.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

class pypielm.models.domain.LocELM(n_subdomains=6, overlap=0.25, hidden_dim=160, ridge_lambda=1e-08, activation='tanh', seed=42, device='cpu', dtype=torch.float64)[source]

Bases: _DomainDecompositionBase

Localised ELM (LocELM): independent local feature maps per subdomain.

Similar to DPIELM but each subdomain has its own independently initialised random feature map (different seed per subdomain).

Parameters:
  • n_subdomains (int) – Number of subdomains.

  • overlap (float) – Fractional overlap between adjacent subdomains.

  • hidden_dim (int) – Hidden neurons per subdomain.

  • ridge_lambda (float) – Regularisation per subdomain.

  • activation (str) – Activation function.

  • seed (int) – Base random seed; each subdomain gets seed + sub_id.

  • device (str | device) – Target device.

  • dtype (dtype) – Floating-point dtype.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

class pypielm.models.domain.DDELMCoarse(n_subdomains=6, overlap=0.15, hidden_dim=128, coarse_hidden_dim=64, coarse_alpha=0.2, ridge_lambda=1e-08, activation='tanh', seed=42, device='cpu', dtype=torch.float64)[source]

Bases: _DomainDecompositionBase

Domain-Decomposition ELM with a coarse global correction layer.

Combines a local domain-decomposition solve (like DPIELM) with a single global ELM trained on the full dataset, blending the two predictions:

\[\hat{u}(x) = (1 - \alpha_{\text{coarse}})\, \hat{u}_{\text{local}}(x) + \alpha_{\text{coarse}}\, \hat{u}_{\text{coarse}}(x)\]
Parameters:
  • n_subdomains (int) – Number of local subdomains.

  • overlap (float) – Subdomain overlap fraction.

  • hidden_dim (int) – Hidden neurons per subdomain.

  • coarse_hidden_dim (int) – Hidden neurons in the global correction ELM.

  • coarse_alpha (float) – Blending weight for the coarse model (default 0.2).

  • ridge_lambda (float) – Regularisation.

  • activation (str) – Activation function.

  • seed (int) – Random seed.

  • device (str | device) – Target device.

  • dtype (dtype) – Floating-point dtype.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, **kwargs)[source]

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs – List of boundary condition objects (DirichletBC, etc.).

  • ics – List of initial condition objects.

  • collocation_sampler – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

predict(X)[source]

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

CurriculumPIELM

Curriculum PIELM: residual-adaptive collocation resampling.

CurriculumPIELM iteratively refines the set of collocation points by concentrating new samples in high-residual regions, progressively improving accuracy for solutions with localised features (shocks, steep gradients).

class pypielm.models.curriculum.CurriculumPIELM(hidden_dim=200, ridge_lambda=1e-08, activation='tanh', n_stages=5, n_collocation=1000, n_candidates=5000, refine_ratio=0.5, seed=42, device='cpu', dtype=torch.float64)[source]

Bases: BasePIELM

Physics-Informed ELM with curriculum (residual-adaptive) collocation.

Training proceeds in n_stages rounds. In each round:

  1. Solve for β on the current collocation set (ridge solve).

  2. Evaluate PDE residual |H_pde @ β f| at a dense candidate set.

  3. Replace refine_ratio fraction of collocation points with points sampled from the high-residual tail of the candidate distribution.

  4. Repeat until n_stages is reached.

Parameters:
  • hidden_dim (int) – Number of random neurons.

  • ridge_lambda (float) – Regularisation strength.

  • activation (str) – Activation name.

  • n_stages (int) – Number of curriculum refinement rounds.

  • n_collocation (int) – Number of collocation points per stage.

  • n_candidates (int) – Number of dense candidate points used for residual evaluation.

  • refine_ratio (float) – Fraction of collocation points replaced each stage.

  • seed (int) – Random seed.

  • device (str | device) – Target device.

  • dtype (dtype) – Floating-point dtype.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)[source]

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator (Any | None) – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs (list[Any] | None) – List of boundary condition objects (DirichletBC, etc.).

  • ics (list[Any] | None) – List of initial condition objects.

  • collocation_sampler (Any | None) – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

predict(X)[source]

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

score(X, y, metric='relative_l2')[source]

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

get_feature_matrix(X)[source]

Return the hidden-layer activation matrix Φ(X).

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d).

Return type:

Tensor

Returns:

Feature matrix H of shape (N, hidden_dim).

Constrained Variants

Constraint-enforcing PIELM variants and additional model library.

Implemented variants:

  • NullSpacePIELM — null-space BC projection.

  • EigPIELM — eigendecomposition-based BC enforcement.

  • LSEELM — least-squares ELM with equality constraints.

  • StefanPIELM — free-boundary (Stefan) iterative interface tracking.

Additional variants (functional wrappers over CorePIELM / VanillaPIELM): NormalEquationELM, ParameterRetentionELM, PiecewiseELM, DELM, FPIELM, SGEPIELM, RINN, RaNNPIELM, XPIELM, PIELMRVDS, TSPIELM, KAPIELM, SoftPartitionKAPIELM.

class pypielm.models.constrained.NullSpacePIELM(hidden_dim=200, ridge_lambda=1e-08, activation='tanh', null_tol=1e-10, w_pde=1.0, seed=42, device='cpu', dtype=torch.float64)[source]

Bases: BasePIELM

Hard BC enforcement via null-space projection.

  1. Assembles the BC constraint matrix C = H_bc (shape (N_bc, H)).

  2. Computes the null space Z of C via truncated SVD.

  3. Projects the physics/data linear system onto Z: (H_full @ Z) @ α = y_full.

  4. Solves for α, then recovers β = Z @ α.

This guarantees H_bc @ β = 0 exactly (up to numerical rank tolerance), meaning the approximation satisfies the BCs by construction.

Parameters:
  • hidden_dim (int) – Number of random neurons.

  • ridge_lambda (float) – Regularisation strength.

  • activation (str) – Activation function.

  • null_tol (float) – SVD tolerance for null-space truncation.

  • w_pde (float) – Weight on PDE block.

  • seed (int) – Random seed.

  • device (str | device) – Target device.

  • dtype (dtype) – Floating-point dtype.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)[source]

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator (Any | None) – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs (list[Any] | None) – List of boundary condition objects (DirichletBC, etc.).

  • ics (list[Any] | None) – List of initial condition objects.

  • collocation_sampler (Any | None) – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

predict(X)[source]

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

score(X, y, metric='relative_l2')[source]

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

get_feature_matrix(X)[source]

Return the hidden-layer activation matrix Φ(X).

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d).

Return type:

Tensor

Returns:

Feature matrix H of shape (N, hidden_dim).

class pypielm.models.constrained.EigPIELM(hidden_dim=200, ridge_lambda=1e-08, activation='tanh', eig_threshold=1e-08, seed=42, device='cpu', dtype=torch.float64)[source]

Bases: BasePIELM

Eigenvector-based PIELM for hard BC enforcement.

Uses the eigen-decomposition of CᵀC (C = BC feature matrix) to partition the weight space into BC-satisfying and unconstrained subspaces.

Parameters:
  • hidden_dim (int) – Number of random neurons.

  • ridge_lambda (float) – Regularisation.

  • activation (str) – Activation function.

  • eig_threshold (float) – Eigenvalue threshold below which eigenvectors are treated as BC-satisfying.

  • seed (int) – Random seed.

  • device (str | device) – Target device.

  • dtype (dtype) – Floating-point dtype.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)[source]

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator (Any | None) – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs (list[Any] | None) – List of boundary condition objects (DirichletBC, etc.).

  • ics (list[Any] | None) – List of initial condition objects.

  • collocation_sampler (Any | None) – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

predict(X)[source]

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

score(X, y, metric='relative_l2')[source]

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

get_feature_matrix(X)[source]

Return the hidden-layer activation matrix Φ(X).

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d).

Return type:

Tensor

Returns:

Feature matrix H of shape (N, hidden_dim).

class pypielm.models.constrained.LSEELM(hidden_dim=200, ridge_lambda=1e-08, activation='tanh', w_pde=1.0, seed=42, device='cpu', dtype=torch.float64)[source]

Bases: BasePIELM

Least-squares ELM with explicit equality constraints (Lagrange / KKT).

Solves the constrained optimisation:

\[\min_\beta \frac{1}{2}\|H\beta - y\|^2 + \frac{\lambda}{2}\|\beta\|^2 \quad \text{subject to} \quad C\beta = g\]

via the KKT system:

\[\begin{split}\begin{pmatrix} H^\top H + \lambda I & C^\top \\ C & 0 \end{pmatrix} \begin{pmatrix} \beta \\ \mu \end{pmatrix} = \begin{pmatrix} H^\top y \\ g \end{pmatrix}\end{split}\]
Parameters:
  • hidden_dim (int) – Number of random neurons.

  • ridge_lambda (float) – Regularisation for the unconstrained part.

  • activation (str) – Activation function.

  • w_pde (float) – PDE block weight.

  • seed (int) – Random seed.

  • device (str | device) – Target device.

  • dtype (dtype) – Floating-point dtype.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)[source]

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator (Any | None) – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs (list[Any] | None) – List of boundary condition objects (DirichletBC, etc.).

  • ics (list[Any] | None) – List of initial condition objects.

  • collocation_sampler (Any | None) – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

predict(X)[source]

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

score(X, y, metric='relative_l2')[source]

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

get_feature_matrix(X)[source]

Return the hidden-layer activation matrix Φ(X).

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d).

Return type:

Tensor

Returns:

Feature matrix H of shape (N, hidden_dim).

class pypielm.models.constrained.StefanPIELM(hidden_dim=200, ridge_lambda=1e-08, activation='tanh', n_iter=10, stefan_lr=0.1, seed=42, device='cpu', dtype=torch.float64)[source]

Bases: BasePIELM

PIELM for Stefan-type free-boundary problems.

Iteratively tracks a 1-D interface s(t) between two phases. At each iteration:

  1. Fix interface location s.

  2. Fit a CorePIELM-like model on each phase subdomain.

  3. Update s to enforce the Stefan condition [u]_s = 0.

  4. Repeat until s converges.

This is a simplified single-front, 1-D implementation.

Parameters:
  • hidden_dim (int) – Neurons per subdomain.

  • ridge_lambda (float) – Regularisation.

  • activation (str) – Activation.

  • n_iter (int) – Interface update iterations.

  • stefan_lr (float) – Learning rate for interface position update.

  • seed (int) – Random seed.

  • device (str | device) – Target device.

  • dtype (dtype) – Floating-point dtype.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)[source]

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator (Any | None) – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs (list[Any] | None) – List of boundary condition objects (DirichletBC, etc.).

  • ics (list[Any] | None) – List of initial condition objects.

  • collocation_sampler (Any | None) – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

predict(X)[source]

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

score(X, y, metric='relative_l2')[source]

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

get_feature_matrix(X)[source]

Return the hidden-layer activation matrix Φ(X).

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d).

Return type:

Tensor

Returns:

Feature matrix H of shape (N, hidden_dim).

class pypielm.models.constrained.NormalEquationELM(**kwargs)

Bases: BasePIELM

NormalEquationELM: thin wrapper over CorePIELM.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator (Any | None) – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs (list[Any] | None) – List of boundary condition objects (DirichletBC, etc.).

  • ics (list[Any] | None) – List of initial condition objects.

  • collocation_sampler (Any | None) – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

get_feature_matrix(X)

Return the hidden-layer activation matrix Φ(X).

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d).

Return type:

Tensor

Returns:

Feature matrix H of shape (N, hidden_dim).

predict(X)

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

score(X, y, metric='relative_l2')

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

class pypielm.models.constrained.ParameterRetentionELM(**kwargs)

Bases: BasePIELM

ParameterRetentionELM: thin wrapper over CorePIELM.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator (Any | None) – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs (list[Any] | None) – List of boundary condition objects (DirichletBC, etc.).

  • ics (list[Any] | None) – List of initial condition objects.

  • collocation_sampler (Any | None) – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

get_feature_matrix(X)

Return the hidden-layer activation matrix Φ(X).

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d).

Return type:

Tensor

Returns:

Feature matrix H of shape (N, hidden_dim).

predict(X)

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

score(X, y, metric='relative_l2')

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

class pypielm.models.constrained.PiecewiseELM(**kwargs)

Bases: BasePIELM

PiecewiseELM: thin wrapper over CorePIELM.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator (Any | None) – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs (list[Any] | None) – List of boundary condition objects (DirichletBC, etc.).

  • ics (list[Any] | None) – List of initial condition objects.

  • collocation_sampler (Any | None) – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

get_feature_matrix(X)

Return the hidden-layer activation matrix Φ(X).

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d).

Return type:

Tensor

Returns:

Feature matrix H of shape (N, hidden_dim).

predict(X)

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

score(X, y, metric='relative_l2')

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

class pypielm.models.constrained.DELM(**kwargs)

Bases: BasePIELM

DELM: thin wrapper over CorePIELM.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator (Any | None) – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs (list[Any] | None) – List of boundary condition objects (DirichletBC, etc.).

  • ics (list[Any] | None) – List of initial condition objects.

  • collocation_sampler (Any | None) – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

get_feature_matrix(X)

Return the hidden-layer activation matrix Φ(X).

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d).

Return type:

Tensor

Returns:

Feature matrix H of shape (N, hidden_dim).

predict(X)

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

score(X, y, metric='relative_l2')

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

class pypielm.models.constrained.FPIELM(**kwargs)

Bases: BasePIELM

FPIELM: thin wrapper over CorePIELM.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator (Any | None) – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs (list[Any] | None) – List of boundary condition objects (DirichletBC, etc.).

  • ics (list[Any] | None) – List of initial condition objects.

  • collocation_sampler (Any | None) – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

get_feature_matrix(X)

Return the hidden-layer activation matrix Φ(X).

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d).

Return type:

Tensor

Returns:

Feature matrix H of shape (N, hidden_dim).

predict(X)

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

score(X, y, metric='relative_l2')

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

class pypielm.models.constrained.SGEPIELM(**kwargs)

Bases: BasePIELM

SGEPIELM: thin wrapper over CorePIELM.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator (Any | None) – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs (list[Any] | None) – List of boundary condition objects (DirichletBC, etc.).

  • ics (list[Any] | None) – List of initial condition objects.

  • collocation_sampler (Any | None) – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

get_feature_matrix(X)

Return the hidden-layer activation matrix Φ(X).

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d).

Return type:

Tensor

Returns:

Feature matrix H of shape (N, hidden_dim).

predict(X)

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

score(X, y, metric='relative_l2')

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

class pypielm.models.constrained.RINN(**kwargs)

Bases: BasePIELM

RINN: thin wrapper over CorePIELM.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator (Any | None) – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs (list[Any] | None) – List of boundary condition objects (DirichletBC, etc.).

  • ics (list[Any] | None) – List of initial condition objects.

  • collocation_sampler (Any | None) – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

get_feature_matrix(X)

Return the hidden-layer activation matrix Φ(X).

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d).

Return type:

Tensor

Returns:

Feature matrix H of shape (N, hidden_dim).

predict(X)

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

score(X, y, metric='relative_l2')

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

class pypielm.models.constrained.RaNNPIELM(**kwargs)

Bases: BasePIELM

RaNNPIELM: thin wrapper over CorePIELM.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator (Any | None) – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs (list[Any] | None) – List of boundary condition objects (DirichletBC, etc.).

  • ics (list[Any] | None) – List of initial condition objects.

  • collocation_sampler (Any | None) – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

get_feature_matrix(X)

Return the hidden-layer activation matrix Φ(X).

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d).

Return type:

Tensor

Returns:

Feature matrix H of shape (N, hidden_dim).

predict(X)

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

score(X, y, metric='relative_l2')

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

class pypielm.models.constrained.XPIELM(**kwargs)

Bases: BasePIELM

XPIELM: thin wrapper over CorePIELM.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator (Any | None) – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs (list[Any] | None) – List of boundary condition objects (DirichletBC, etc.).

  • ics (list[Any] | None) – List of initial condition objects.

  • collocation_sampler (Any | None) – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

get_feature_matrix(X)

Return the hidden-layer activation matrix Φ(X).

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d).

Return type:

Tensor

Returns:

Feature matrix H of shape (N, hidden_dim).

predict(X)

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

score(X, y, metric='relative_l2')

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

class pypielm.models.constrained.PIELMRVDS(**kwargs)

Bases: BasePIELM

PIELMRVDS: thin wrapper over CorePIELM.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator (Any | None) – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs (list[Any] | None) – List of boundary condition objects (DirichletBC, etc.).

  • ics (list[Any] | None) – List of initial condition objects.

  • collocation_sampler (Any | None) – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

get_feature_matrix(X)

Return the hidden-layer activation matrix Φ(X).

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d).

Return type:

Tensor

Returns:

Feature matrix H of shape (N, hidden_dim).

predict(X)

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

score(X, y, metric='relative_l2')

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

class pypielm.models.constrained.TSPIELM(**kwargs)

Bases: BasePIELM

TSPIELM: thin wrapper over CorePIELM.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator (Any | None) – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs (list[Any] | None) – List of boundary condition objects (DirichletBC, etc.).

  • ics (list[Any] | None) – List of initial condition objects.

  • collocation_sampler (Any | None) – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

get_feature_matrix(X)

Return the hidden-layer activation matrix Φ(X).

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d).

Return type:

Tensor

Returns:

Feature matrix H of shape (N, hidden_dim).

predict(X)

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

score(X, y, metric='relative_l2')

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

class pypielm.models.constrained.KAPIELM(**kwargs)

Bases: BasePIELM

KAPIELM: thin wrapper over CorePIELM.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator (Any | None) – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs (list[Any] | None) – List of boundary condition objects (DirichletBC, etc.).

  • ics (list[Any] | None) – List of initial condition objects.

  • collocation_sampler (Any | None) – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

get_feature_matrix(X)

Return the hidden-layer activation matrix Φ(X).

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d).

Return type:

Tensor

Returns:

Feature matrix H of shape (N, hidden_dim).

predict(X)

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

score(X, y, metric='relative_l2')

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

class pypielm.models.constrained.SoftPartitionKAPIELM(**kwargs)

Bases: BasePIELM

SoftPartitionKAPIELM: thin wrapper over CorePIELM.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)

Solve for output weights analytically.

Parameters:
  • dataset (PIELMDataset) – A PIELMDataset containing X_train, y_train, and (optionally) validation splits.

  • pde_operator (Any | None) – Optional differential operator applied at collocation points to build the physics residual block in the linear system. If None, the model falls back to pure data regression.

  • bcs (list[Any] | None) – List of boundary condition objects (DirichletBC, etc.).

  • ics (list[Any] | None) – List of initial condition objects.

  • collocation_sampler (Any | None) – Overrides the default collocation sampler used to generate interior PDE points.

Returns:

model.fit(ds, pde_operator=op).predict(X_test).

Return type:

self — enables fluent chaining

get_feature_matrix(X)

Return the hidden-layer activation matrix Φ(X).

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d).

Return type:

Tensor

Returns:

Feature matrix H of shape (N, hidden_dim).

predict(X)

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

score(X, y, metric='relative_l2')

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

PINN Baselines

Gradient-based PINN variants (baselines for PIELM comparison).

All variants expose the same fit / predict / score API as the PIELM models and inherit from BasePIELM for interface consistency.

class pypielm.models.pinn.VanillaPINN(layer_dims=None, activation='tanh', optimizer='adam', lr=0.001, max_epochs=10000, w_pde=1.0, w_bc=1.0, w_ic=1.0, seed=42, device='cpu', dtype=torch.float64)[source]

Bases: _GradPINNBase

Standard Physics-Informed Neural Network (MLP backbone).

Trains via Adam (default) or L-BFGS by minimising a weighted sum of:

\[\mathcal{L} = w_{\text{pde}}\,\mathcal{L}_{\text{pde}} + w_{\text{bc}}\,\mathcal{L}_{\text{bc}} + w_{\text{ic}}\,\mathcal{L}_{\text{ic}} + \mathcal{L}_{\text{data}}\]
Parameters:
  • layer_dims (list[int] | None) – Width of each hidden layer, e.g. [50, 50, 50].

  • activation (str) – Hidden activation ('tanh', 'sin', 'relu', 'softplus').

  • optimizer (str) – 'adam' or 'lbfgs'.

  • lr (float) – Learning rate for Adam (L-BFGS ignores this; uses line search).

  • max_epochs (int) – Maximum number of training epochs / outer L-BFGS iterations.

  • w_pde (float) – Weight on PDE residual loss term.

  • w_bc (float) – Weight on BC loss term.

  • w_ic (float) – Weight on IC loss term.

  • seed (int) – Random seed for weight initialisation.

  • device (str | device) – Target device ('cpu', 'cuda', 'mps').

  • dtype (dtype) – Floating-point dtype (torch.float64 default).

Example:

from pypielm.models import VanillaPINN
model = VanillaPINN(layer_dims=[64, 64], max_epochs=5000)
model.fit(dataset, pde_operator=laplacian_op)
u_pred = model.predict(X_test)

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)[source]

Train the PINN on dataset.

Parameters:
  • dataset (PIELMDataset) – PIELMDataset with collocation, boundary, and optionally observation points.

  • pde_operator (Any | None) – Callable (fm, X_colloc) WeightedLinearSystem used to evaluate PDE residuals. When provided, the loss includes a PDE term.

  • bcs (list[Any] | None) – Explicit boundary condition objects (optional; falls back to dataset.X_bc / y_bc).

  • ics (list[Any] | None) – Explicit initial condition objects (optional).

  • collocation_sampler (Any | None) – Not used by gradient-based PINN (reserved for future adaptive variants).

Return type:

VanillaPINN

Returns:

self

predict(X)[source]

Evaluate the surrogate solution at input coordinates X.

Parameters:

X (ndarray | Tensor) – Input coordinates of shape (N, d). Accepts both torch.Tensor and numpy.ndarray; the result is always a torch.Tensor.

Return type:

Tensor

Returns:

Predicted values of shape (N, 1) or (N, out_dim).

score(X, y, metric='relative_l2')[source]

Compute a scalar accuracy metric on a held-out set.

Parameters:
  • X (ndarray | Tensor) – Input coordinates of shape (N, d).

  • y (ndarray | Tensor) – Reference values of shape (N,) or (N, out_dim).

  • metric (str) – One of 'relative_l2', 'rmse', 'mae', 'r2', 'max_error'.

Return type:

float

Returns:

Scalar metric value. For error metrics (relative_l2, rmse, mae, max_error) lower is better; for R² higher is better.

get_feature_matrix(X)[source]

Return the last hidden-layer activations as the feature matrix.

Return type:

Tensor

class pypielm.models.pinn.AdaptivePINN(*, n_colloc=500, n_candidates=2000, update_every=100, domain_lb=None, domain_ub=None, resample_ratio=0.5, **kwargs)[source]

Bases: VanillaPINN

PINN with residual-based importance weighting on collocation points.

After every update_every Adam steps, collocation points are re-sampled from n_candidates candidates by drawing n_colloc points with probability proportional to the squared PDE residual (Anagnostopoulos et al., 2024; Lu et al., 2021 RAR).

Parameters:
  • n_colloc (int) – Number of collocation points to keep each iteration.

  • n_candidates (int) – Candidate pool for residual evaluation.

  • update_every (int) – Resampling interval (epochs).

  • domain_lb (list[float] | None) – Lower bound of the sampling domain (tensor or list).

  • domain_ub (list[float] | None) – Upper bound of the sampling domain (tensor or list).

  • resample_ratio (float) – Fraction of points replaced at each update.

  • **kwargs (Any) – Forwarded to VanillaPINN.

Example:

model = AdaptivePINN(
    n_colloc=500, domain_lb=[0.0], domain_ub=[1.0],
    update_every=100, layer_dims=[64, 64],
)
model.fit(dataset, pde_operator=laplacian_op)

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)[source]

Train with periodic adaptive collocation resampling.

Return type:

AdaptivePINN

class pypielm.models.pinn.FourierPINN(*, sigma=10.0, n_fourier=64, **kwargs)[source]

Bases: VanillaPINN

PINN with Fourier input encoding (Tancik et al., 2020).

Replaces the raw coordinate input with a random Fourier feature encoding:

\[\gamma(\mathbf{x}) = [\cos(2\pi\mathbf{B}\mathbf{x}), \sin(2\pi\mathbf{B}\mathbf{x})]\]

where each entry of B is drawn from \(\mathcal{N}(0, \sigma^2)\). This lifts the input into a \(2m\)-dimensional space and mitigates spectral bias.

Parameters:
  • sigma (float) – Standard deviation of the Gaussian frequency matrix.

  • n_fourier (int) – Number of Fourier features m (output dim = 2m).

  • **kwargs (Any) – Forwarded to VanillaPINN.

Example:

model = FourierPINN(sigma=10.0, n_fourier=64, layer_dims=[64, 64])
model.fit(dataset, pde_operator=laplacian_op)

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)[source]

Train FourierPINN — encodes inputs before building the MLP.

Return type:

FourierPINN

class pypielm.models.pinn.MuonPINN(*, momentum=0.95, ns_steps=5, **kwargs)[source]

Bases: VanillaPINN

PINN trained with the Muon (orthogonal momentum) optimizer.

Muon orthogonalises parameter updates via Newton-Schulz iteration, which improves conditioning and reduces loss of rank in weight matrices.

Parameters:
  • momentum (float) – Nesterov momentum coefficient (default 0.95).

  • ns_steps (int) – Number of Newton-Schulz iterations (default 5).

  • **kwargs (Any) – Forwarded to VanillaPINN.

Example:

model = MuonPINN(layer_dims=[64, 64], momentum=0.95, max_epochs=5000)
model.fit(dataset, pde_operator=laplacian_op)

Initialize internal Module state, shared by both nn.Module and ScriptModule.

class pypielm.models.pinn.ResidualAdaptivePINN(width=64, n_blocks=3, activation='tanh', optimizer='adam', lr=0.001, max_epochs=10000, w_pde=1.0, w_bc=1.0, w_ic=1.0, n_new=20, update_every=100, max_colloc=2000, n_candidates=5000, domain_lb=None, domain_ub=None, seed=42, device='cpu', dtype=torch.float64)[source]

Bases: _GradPINNBase

ResNet-backbone PINN with adaptive collocation sampling.

Combines:

  • A residual network (skip connections) backbone for improved gradient flow in deep networks.

  • Residual-adaptive collocation (RAR; Lu et al., 2021): every update_every epochs, n_new fresh points are added in high-residual regions, capped at max_colloc total collocation points.

Parameters:
  • width (int) – Hidden-layer width for all residual blocks.

  • n_blocks (int) – Number of residual blocks.

  • activation (str) – Activation function name.

  • optimizer (str) – 'adam' or 'lbfgs'.

  • lr (float) – Learning rate.

  • max_epochs (int) – Maximum training epochs.

  • w_pde (float) – PDE loss weight.

  • w_bc (float) – BC loss weight.

  • w_ic (float) – IC loss weight.

  • n_new (int) – Points added per RAR update.

  • update_every (int) – RAR update interval (epochs).

  • max_colloc (int) – Maximum collocation pool size.

  • n_candidates (int) – Candidate pool for RAR evaluation.

  • domain_lb (list[float] | None) – Lower bound of sampling domain.

  • domain_ub (list[float] | None) – Upper bound of sampling domain.

  • seed (int) – Random seed.

  • device (str | device) – Target device.

  • dtype (dtype) – Floating-point dtype.

Example:

model = ResidualAdaptivePINN(
    width=64, n_blocks=3, max_epochs=5000,
    domain_lb=[0.0], domain_ub=[1.0],
)
model.fit(dataset, pde_operator=laplacian_op)

Initialize internal Module state, shared by both nn.Module and ScriptModule.

fit(dataset, *, pde_operator=None, bcs=None, ics=None, collocation_sampler=None)[source]

Train with ResNet backbone and RAR collocation refinement.

Return type:

ResidualAdaptivePINN