sindae.algorithms.inference
Embed a trained MLP back into a new (or the same) DAE problem and solve for the trajectory
consistent with the learned dynamics. The network is enforced as a hard GBM output
constraint by default (slack_coef=0, a square system solved by POUNCE), or relaxed via
an slack (slack_coef > 0) when the trained network does not fit the inference
problem’s dynamics exactly.
make_inference_modelbuilds the inference NLP.solve_inferencebuilds and solves it.
Because the mechanistic equations remain hard constraints, predictions stay physically consistent even at initial conditions never seen during training.
Usage¶
import numpy as np
from sindae import extract_instance_data
from sindae.algorithms.inference import solve_inference
# New initial conditions — the discretization may also differ from training.
val_problem = MyProblem(
ics=np.array([[5.0, 0.3]]),
input_dim=2, z_dim=1, t_span=(0, 80), nfe=20, ncp=2,
)
inference_m = solve_inference(
val_problem, mlp,
data=trained_data, # normalization stats from training
slack_coef=1e-5, # small l1 relaxation; use 0.0 for a hard constraint
)
prediction = extract_instance_data(val_problem, inference_m)API reference¶
make_inference_model¶
make_inference_model(
problem: ProblemDefinition,
mlp: SimpleMLP,
traj_indices: List[int],
data: InstanceData,
slack_coef: float = 0.0,
) -> pyo.ConcreteModelBuild an inference NLP: DAE + trained NN embedded as a GBM constraint.
Parameters
problem(ProblemDefinition) — Inference problem — may have different ICs / dynamics from training. Must implement build_trajectory / discretize / get_input_vars / get_output_vars.mlp(SimpleMLP)traj_indices(List[int])data(InstanceData) — Provides input_mean/std and output_mean/std from training.slack_coef(float, default0.0) — When 0 (default) the NN equality is a hard GBM output constraint (square system, no objective). When > 0 the constraint is relaxed with ℓ₁ slack variables and the objective isslack_coef * mean(sp + sn). The model is then over-determined with a least-infeasibility flavour.
Returns
m(pyo.ConcreteModel) — Extra attribute:m._traj_t_sorted: List[List[float]]
solve_inference¶
solve_inference(
problem: ProblemDefinition,
mlp: SimpleMLP,
data: InstanceData,
traj_indices: Optional[List[int]] = None,
slack_coef: float = 0.0,
solver_options: Optional[dict] = None,
nlp_solver: str = 'pounce',
tee: bool = False,
timer: Optional[HierarchicalTimer] = None,
) -> pyo.ConcreteModelBuild and solve the inference NLP, returning the solved model.
Parameters
problem(ProblemDefinition)mlp(SimpleMLP)data(InstanceData)traj_indices(Optional[List[int]], defaultNone)slack_coef(float, default0.0)solver_options(Optional[dict], defaultNone) — Passed to the selected NLP backend.nlp_solver(str, default'pounce') — select alternative grey-box-capable backends)tee(bool, defaultFalse)timer(Optional[HierarchicalTimer], defaultNone)
Returns
m(pyo.ConcreteModel(solved))