frontx.neural
frontx.neural
Physics-Informed Neural Network (PINN) utilities for Frontx.
This module provides the public API to train a PINN and to evaluate the learned
solution. The internal training network is implementation detail; consumers
should use the :class:Solution class (immutable wrapper around the trained
network) and the :func:fit routine to obtain it.
The PINN models a scalar mapping o -> theta(o) constrained by data and a
physics residual defined via a diffusivity-like callable D.
Solution
Bases: AbstractSolution
Trained PINN solution wrapper.
This class exposes a callable solution theta(o) together with its
configuration. The underlying neural network and training logic are
internal; users typically obtain an instance via :func:fit.
The solution maps an observable/coordinate o to a scalar response
constrained to lie between i and b after a normalized transform.
The scaling parameter oi provides a characteristic range for o and
is used to normalize inputs during training and inference.
Attributes:
| Name | Type | Description |
|---|---|---|
oi |
float
|
Characteristic scale used to normalize inputs |
Source code in frontx/neural.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
oi: float = oi
instance-attribute
D: Callable[[float | jax.Array | np.ndarray[Any, Any]], float | jax.Array | np.ndarray[Any, Any]]
property
Return the diffusivity-like callable used in the physics term.
Returns:
| Type | Description |
|---|---|
Callable[[float | Array | ndarray[Any, Any]], float | Array | ndarray[Any, Any]]
|
A callable that accepts a scalar/array and returns a scalar/array |
Callable[[float | Array | ndarray[Any, Any]], float | Array | ndarray[Any, Any]]
|
with the same broadcastable shape. It is the same function that was |
Callable[[float | Array | ndarray[Any, Any]], float | Array | ndarray[Any, Any]]
|
passed to :func: |
__init__(net: _PINN, *, i: float, b: float, oi: float) -> None
Initialize a :class:Solution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
net
|
_PINN
|
Trained internal PINN network (implementation detail). |
required |
i
|
float
|
Lower bound (baseline) of the response range. |
required |
b
|
float
|
Upper bound (saturation) of the response range. |
required |
oi
|
float
|
Characteristic input scale used for normalization. |
required |
Source code in frontx/neural.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
__call__(o: float | jax.Array | np.ndarray[Any, Any]) -> float | jax.Array | np.ndarray[Any, Any]
Evaluate the trained solution at input o.
The input is clipped to [0, oi] (after normalization) and the
network prediction is rescaled back to the original range [i, b].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
o
|
float | Array | ndarray[Any, Any]
|
Input coordinate(s) at which to evaluate the solution. |
required |
Returns:
| Type | Description |
|---|---|
float | Array | ndarray[Any, Any]
|
The predicted response with the same shape broadcasting as |
Source code in frontx/neural.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
fit(D: Callable[[float | jax.Array | np.ndarray[Any, Any]], float | jax.Array | np.ndarray[Any, Any]], o: jax.Array | np.ndarray[Any, Any], theta: jax.Array | np.ndarray[Any, Any], /, sigma: float | jax.Array | np.ndarray[Any, Any] | None = None, *, i: float, b: float, oi: float | None = None, max_steps: int = 300000) -> Solution
Train a PINN against data and physics, returning a callable solution.
This routine fits a physics-informed neural network using paired data
(o, theta) and a physics residual weighted by an annealed coefficient.
Inputs are normalized by oi and outputs are scaled to [i, b].
Training stops early when the physics loss target is reached or when
max_steps is exceeded.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
D
|
Callable[[float | Array | ndarray[Any, Any]], float | Array | ndarray[Any, Any]]
|
Diffusivity-like callable used in the physics residual. |
required |
o
|
Array | ndarray[Any, Any]
|
Input coordinates (1D array-like). Typically monotonically increasing. |
required |
theta
|
Array | ndarray[Any, Any]
|
Target responses aligned with |
required |
sigma
|
float | Array | ndarray[Any, Any] | None
|
Optional observational noise (scalar or array-like) to weight the
data loss. If |
None
|
i
|
float
|
Lower bound (baseline) of the response range. |
required |
b
|
float
|
Upper bound (saturation) of the response range. |
required |
oi
|
float | None
|
Optional input scale. If |
None
|
max_steps
|
int
|
Maximum number of optimization steps. |
300000
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
Solution
|
class: |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the physics loss fails to converge to the target
threshold before |
AssertionError
|
If internal normalization parameters are missing. |
Source code in frontx/neural.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 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 | |