Skip to content

Bayesian, Joint, Dynamic, and Certified Examples

The executable script examples/advanced_expansions.py runs all four mechanisms with compact deterministic tensors. The full derivations and scale routes are in Bayesian, Joint, Dynamic, and Certified Equilibria. The four mechanisms are grounded in the Bayesian, joint-inference, spatiotemporal, and certification sources [94] through [98].

python examples/advanced_expansions.py

Expected checks include nonzero posterior predictive variance, a finite joint equilibrium residual, a complete implicit trajectory, and interval-certified class margins. These are mechanism checks rather than source-benchmark results.

Replace the Internals

model = SILVAJointInferenceEquilibrium(
    observation_dim=observation_dim,
    state_dim=state_dim,
    optimized_input_dim=latent_dim,
    output_dim=output_dim,
    representation_transition=representation_module,
    input_update=projected_latent_update,
    readout=decoder,
    config=solver_config,
)

The same replacement pattern applies to posterior transitions, known and learned physical dynamics, boundary projectors, and certificate backends.

Complete Worked Study

The short construction above identifies the main API. A complete study must also distinguish the state equation, task objective, numerical residual, gradient path, and scale transfer. In this example, the equilibrium state is one equilibrium state for each posterior transition sample, the condition is the observed input, posterior parameters, sample seed, and optional warm start, and the repeated map is a sampled parameter transition with a separately solved fixed point.

Derivation From Transition to Reported Result

The forward solve is defined by

\[ z^\star = T_\theta(z^\star,x). \]

The task output and task objective are separate from convergence:

\[ \widehat y = R_\phi(z^\star), \qquad \mathcal L_{\mathrm{task}}=\ell(\widehat y,y). \]

For a computed state \(z_K\), the normalized fixed-point residual is

\[ r_K = \frac{\lVert T_\theta(z_K,x)-z_K\rVert_2} {\lVert z_K\rVert_2+\varepsilon}. \]

A small task loss does not imply a small \(r_K\), and a small \(r_K\) does not establish task quality. Both belong in the result. For implicit training, the parameter sensitivity follows

\[ \frac{\mathrm d z^\star}{\mathrm d\theta} = \left(I-\partial_z T_\theta(z^\star,x)\right)^{-1} \partial_\theta T_\theta(z^\star,x). \]

This is why the example checks gradients in addition to forward convergence. The reader-facing evidence for this route is posterior variance, coupled-root residual, trajectory shape, and certified margins. The invariants that must remain true are sample/state shape, reproducible draws, contraction control, and finite predictive moments.

Complete Program

The complete executable source is included here so the example can be studied without reconstructing omitted setup, solver, loss, or gradient steps.

"""Run the Bayesian, joint-inference, dynamic, and certified SILVA families."""

import torch

from silva_networks import (
    SILVABayesianDEQ,
    SILVACertifiedEquilibrium,
    SILVAImplicitSpatiotemporalEquilibrium,
    SILVAJointInferenceEquilibrium,
    SILVAPeriodicDiffusion1D,
    SolverConfig,
)


def main() -> None:
    torch.manual_seed(610)
    config = SolverConfig(max_iter=40, tol=1e-7, backward_mode="unrolled")

    bayesian = SILVABayesianDEQ(3, 6, 2, posterior_samples=3, config=config)
    bayesian_result = bayesian(torch.randn(4, 3), seed=11, return_result=True)
    print("bayesian variance", float(bayesian_result.predictive_variance.mean().detach()))

    joint = SILVAJointInferenceEquilibrium(4, 6, 3, 2, config=config)
    joint_result = joint(torch.randn(4, 4), return_result=True)
    print("joint residual", joint_result.solver_result.residual)

    dynamics = SILVAImplicitSpatiotemporalEquilibrium(
        known_dynamics=SILVAPeriodicDiffusion1D(0.1),
        dt=0.2,
        steps=4,
        config=config,
    )
    dynamic_result = dynamics(torch.randn(3, 24), return_result=True)
    print("trajectory", tuple(dynamic_result.trajectory.shape))

    certified = SILVACertifiedEquilibrium(2, 6, 3, config=config)
    inputs = torch.randn(4, 2)
    logits = certified(inputs)
    certificate = certified.certify(inputs, 0.02, logits.argmax(dim=-1))
    print("certified examples", int(certificate.certified.sum()))


if __name__ == "__main__":
    main()

Run the Complete Example

python examples/advanced_expansions.py

Measured Compact Output

The following output was produced by the executable program in the current repository. Floating-point values may vary slightly across devices and library builds, while shapes, finite values, invariants, and declared tolerances must remain stable.

bayesian variance 0.000405691476771608
joint residual 8.033163112486363e-08
trajectory (3, 5, 24)
certified examples 4

Interpret the Output

Evidence What it answers What would require investigation
Tensor shapes Did every source, state, branch, and readout preserve its declared contract? A changed entity, channel, token, or spatial dimension
Task metric Did the compact task execute and produce finite evidence? Non-finite loss, a missing mask, or a metric computed on the wrong split
Fixed-point residual Did the returned state satisfy the repeated transition to the requested tolerance? A residual plateau, rising trajectory, or convergence flag inconsistent with the value
Iteration or trajectory data How much numerical work was required? Solver effort that grows sharply under a small input or resolution change
Gradient evidence Can the loss reach every trainable component through the selected backward mode? Missing, non-finite, or implausibly large gradients
Domain invariant Did the method retain positivity, feasibility, boundary values, permutation behavior, or another structural requirement? A task metric that looks acceptable while the structural contract fails

The compact output is a mechanism check, not a paper-scale benchmark claim. It shows that data enter the intended construction, the transition executes, the solver returns diagnostics, and differentiation reaches trainable parameters.

Add a Solver and Scale Sweep

The next run should hold model parameters and data fixed while changing one numerical control at a time. A complete experiment record can use this schema:

experiment:
  example: advanced-expansions
  state: one equilibrium state for each posterior transition sample
  condition: the observed input, posterior parameters, sample seed, and optional warm start
  repeated_transition: a sampled parameter transition with a separately solved fixed point
  invariant_checks: sample/state shape, reproducible draws, contraction control, and finite predictive moments
  compact_evidence: posterior variance, coupled-root residual, trajectory shape, and certified margins
  scale_axes: posterior sample count, state width, data size, solver budget, and accelerator count
solver_sweep:
  methods: [picard, anderson, broyden]
  tolerances: [1.0e-4, 1.0e-6, 1.0e-8]
  maximum_iterations: [25, 50, 100]
report:
  - task_metric
  - fixed_point_residual
  - backward_linear_residual
  - iterations
  - wall_time
  - peak_memory
  - gradient_norm

At full scale, move toward the cited uncertainty, joint inference, spatiotemporal, or certification benchmark. Increase only one of posterior sample count, state width, data size, solver budget, and accelerator count at a time. Retain this compact run as a regression test, preserve the source split and preprocessing receipt, archive the resolved configuration and checkpoint, and report convergence failures rather than discarding them.

Where to Go Next

Question Page
Where are the equations? Advanced Equilibrium Expansions
How are source-scale runs configured? Evidence and Source-Scale Experiments
Where are the signatures? Advanced Expansion API