PINN Auxiliary Losses¶
PINN-specific loss callables for physics-informed training.
PhysicsLoss ¶
PhysicsLoss(physics_loss_func: Callable, weight: float = 1.0, loss_weights: dict | None = None, n_inputs: int | None = None, n_skip: int = 0)
Physics-informed loss term for PINN training.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
physics_loss_func
|
Callable
|
function(u, y_pred, y_ref) returning dict of losses or single loss tensor |
required |
weight
|
float
|
global scaling factor for physics loss contribution |
1.0
|
loss_weights
|
dict | None
|
per-component weights like {'physics': 1.0, 'derivative': 0.1} |
None
|
n_inputs
|
int | None
|
number of input channels (if using concatenated inputs like FranSysLearner) |
None
|
n_skip
|
int
|
number of initial timesteps to skip before computing physics loss |
0
|
Source code in tsfast/pinn/aux_losses.py
__call__ ¶
Compute physics-informed loss on training data.
Source code in tsfast/pinn/aux_losses.py
CollocationLoss ¶
CollocationLoss(generate_pinn_input: Callable, physics_loss_func: Callable, weight: float = 1.0, loss_weights: dict | None = None, num_workers: int = 0, init_mode: str = 'none', output_ranges: list | None = None, hidden_std: float = 0.1, n_skip: int = 0)
Collocation-point physics loss for PINN training.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
generate_pinn_input
|
Callable
|
function(batch_size, seq_len, device) returning tensor of collocation points |
required |
physics_loss_func
|
Callable
|
function(u, y_pred, y_ref) returning dict of losses or single loss tensor |
required |
weight
|
float
|
global scaling factor for physics loss contribution |
1.0
|
loss_weights
|
dict | None
|
per-component weights like {'physics': 1.0, 'derivative': 0.1} |
None
|
num_workers
|
int
|
number of parallel workers for collocation point generation |
0
|
init_mode
|
str
|
initialization mode: 'none', 'state_encoder', or 'random_hidden' |
'none'
|
output_ranges
|
list | None
|
list of (min, max) tuples for random state generation |
None
|
hidden_std
|
float
|
std for random hidden state initialization |
0.1
|
n_skip
|
int
|
number of initial timesteps to skip before computing physics loss |
0
|
Source code in tsfast/pinn/aux_losses.py
setup ¶
teardown ¶
Clean up the collocation DataLoader iterator.
Source code in tsfast/pinn/aux_losses.py
__call__ ¶
Compute physics-informed loss on collocation points.
Source code in tsfast/pinn/aux_losses.py
ConsistencyLoss ¶
Consistency loss between sequence and state encoders.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weight
|
float
|
weight for consistency loss |
1.0
|
match_at_timestep
|
int | None
|
timestep to match hidden states (default: model.init_sz) |
None
|
Source code in tsfast/pinn/aux_losses.py
setup ¶
Register forward hook on rnn_diagnosis if model supports it.
Source code in tsfast/pinn/aux_losses.py
teardown ¶
__call__ ¶
Compute consistency loss between SequenceEncoder and StateEncoder.
Source code in tsfast/pinn/aux_losses.py
TransitionSmoothnessLoss ¶
Penalizes discontinuities in predictions around the init_sz boundary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
init_sz
|
int
|
init window size (transition at this index) |
required |
weight
|
float
|
loss weight |
1.0
|
window
|
int
|
timesteps around boundary to penalize |
3
|
dt
|
float
|
time step for derivative computation |
0.01
|
Source code in tsfast/pinn/aux_losses.py
__call__ ¶
Compute curvature penalty around the transition boundary.