PINN
popinn.PINN
¤
Physics-Informed Neural Network.
A single MLP mapping coordinates to a scalar, with no auxiliary inputs.
See Raissi et al. (2019) for more details on PINNs.
Source code in src/popinn/models.py
__init__(key, num_coords=2, hidden_dim=64, depth=4, inner_activation=jnp.tanh, final_activation=jax.nn.softplus, mlp_kwargs={})
¤
Initialize the PINN as a multi-layer perceptron using equinox.nn.MLP.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
jax.random.PRNGKey
|
PRNG key for MLP initialization. |
required |
num_coords
|
int
|
Number of coordinate inputs (e.g. 2 for x & t). |
2
|
hidden_dim
|
int
|
Width of each hidden layer. |
64
|
depth
|
int
|
Number of hidden layers. |
4
|
inner_activation
|
collections.abc.Callable
|
Activation between hidden layers. |
jax.numpy.tanh
|
final_activation
|
collections.abc.Callable
|
Activation on the output. |
jax.nn.softplus
|
mlp_kwargs
|
dict
|
Extra keyword arguments forwarded to
|
{}
|
Source code in src/popinn/models.py
__call__(*args)
¤
Evaluate the model at one point.
Coordinates are passed as individual scalars; auxiliary inputs are passed as a single trailing tuple:
model(x, t, (a, b)) # x & t are the coordinates; a & b are the auxiliary inputs.
For models with no auxiliary inputs, e.g. popinn.PINN, the auxiliary tuple
can be empty, or omitted completely:
model(x, t, ()) # explicit empty aux -- equivalent to:
model(x, t) # no aux
Note the auxiliary inputs must be a tuple specifically, not a list or array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
The coordinate scalars, optionally followed by the aux tuple. |
()
|
Returns:
| Type | Description |
|---|---|
jaxtyping.Float[jax.Array, '']
|
The model output as a scalar JAX array. |
Source code in src/popinn/models.py
D(*argnums)
¤
Build the derivative of the model with respect to one or more coordinates.
Returns a function with the same call signature as the model whose output is the requested derivative.
Derivative syntax
Each entry of argnums indexes a coordinate argument (0 -> first coordinate, 1 -> second, ...);
chaining differentiates repeatedly. For example, for a model with two coordinates x & t,
derivatives are taken & evaluated like:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*argnums
|
int
|
Coordinate indices to differentiate with respect to, applied left to right. |
()
|
Returns:
| Type | Description |
|---|---|
collections.abc.Callable
|
A function with the same signature as the model that returns the requested scalar derivative. |