P2INN
popinn.P2INN
¤
Parametrized Physics-Informed Neural Network.
Consists of 3 MLPs: a coordinate encoder, parameter encoder, and manifold network. The outputs of the two encoders are stacked together and then passed into the manifold network, which returns the scalar model output.
The parameters can be scalar PDE parameters, e.g. the scalar parameters \(\beta\), \(\nu\), and \(\rho\) in this PDE:
Example usage:
import jax.numpy as jnp
import popinn
beta = jnp.array(1.)
nu = jnp.array(2.)
rho = jnp.array(3.)
x = jnp.array(1.)
t = jnp.array(1.)
# initialize
model = popinn.P2INN(num_params = 3, num_coords = 2)
# evaluate
u = model(x, t, (beta, nu, rho))
See Cho et al. (2024) for more details about P\(^2\)INNs.
Source code in src/popinn/models.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 | |
__init__(key, num_params=1, num_coords=2, param_hidden_dim=150, param_depth=4, coord_hidden_dim=64, coord_depth=3, manifold_inner_dim=64, manifold_depth=5, param_activation=jnp.tanh, coord_activation=jax.nn.silu, manifold_inner_activation=jnp.tanh, manifold_final_activation=jax.nn.softplus, param_kwargs={}, coord_kwargs={}, manifold_kwargs={})
¤
Initialize the three sub-networks: coordinate encoder, parameter encoder, and manifold network,
each as an equinox.nn.MLP.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
jax.random.PRNGKey
|
PRNG key; split three ways for the encoders and manifold. |
required |
num_params
|
int
|
Number of scalar PDE parameters; defines the input dimension of the parameter encoder. |
1
|
num_coords
|
int
|
number of coordinate inputs (coord-encoder input size). |
2
|
param_hidden_dim
|
int
|
width and output size of the parameter encoder. |
150
|
param_depth
|
int
|
number of hidden layers in the parameter encoder. |
4
|
coord_hidden_dim
|
int
|
width and output size of the coordinate encoder. |
64
|
coord_depth
|
int
|
number of hidden layers in the coordinate encoder. |
3
|
manifold_inner_dim
|
int
|
width of the manifold network's hidden layers. |
64
|
manifold_depth
|
int
|
number of hidden layers in the manifold network. |
5
|
param_activation
|
collections.abc.Callable
|
activation for the parameter encoder (used inner and final). |
jax.numpy.tanh
|
coord_activation
|
collections.abc.Callable
|
activation for the coordinate encoder (used inner and final). |
jax.nn.silu
|
manifold_inner_activation
|
collections.abc.Callable
|
activation between the manifold network's hidden layers. |
jax.numpy.tanh
|
manifold_final_activation
|
collections.abc.Callable
|
activation on the manifold output. The default softplus keeps the solution positive; override for sign-changing solutions. |
jax.nn.softplus
|
param_kwargs
|
dict
|
extra kwargs forwarded to the parameter encoder MLP. |
{}
|
coord_kwargs
|
dict
|
extra kwargs forwarded to the coordinate encoder MLP. |
{}
|
manifold_kwargs
|
dict
|
extra kwargs forwarded to the manifold MLP. |
{}
|
Source code in src/popinn/models.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 | |
__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. |