bayesian-pinn
Skill0 starsChanged 3 days agoMITView on GitHub
Posterior uncertainty on neural solutions: BNNODE for ODEs, BayesianPINN for PDEs, prior choice, and reading a credible interval honestly. Use when a neural surrogate must carry an error bar.
In this repository55 other files it gives its agents.
- advanced-optimizationSkill
- bayesian-inferenceSkill
- bayesian-ude-workflowSkill
- catalyst-reactionsSkill
- continuum-mechanics-and-rheologySkill
- control-theorySkill
- creating-julia-appSkill
- debugging-toolkitSkill
- differential-equationsSkill
- differentiationSkill
- equation-discoverySkill
- experiment-trackingSkill
- fem-feaSkill
- julia-graph-neural-networksSkill
- julia-languageSkill
- julia-ml-and-dlSkill
- julia-model-deploymentSkill
- julia-paper-implementationSkill
- julia-pro-helpSkill
- julia-pro-modeSkill
- julia-reinforcement-learningSkill
- modeling-toolkitSkill
- neural-pdeSkill
- nonlinear-dynamicsSkill
- numerical-methods-implementationSkill
- package-development-workflowSkill
- performance-tuningSkill
- physical-learning-systemsSkill
- playbook-debugSkill
- playbook-model-validateSkill
- playbook-package-releaseSkill
- playbook-paper-implementSkill
- playbook-perfSkill
- playbook-test-specSkill
- principle-both-sidesSkill
- principle-breakingSkill
- principle-file-is-truthSkill
- principle-gateSkill
- principle-limitsSkill
- principle-loud-failureSkill
- principle-one-stepSkill
- principle-proof-listSkill
- principle-rebuttalSkill
- principle-runtime-surfaceSkill
- principle-three-boundsSkill
- principle-three-clocksSkill
- scientific-visualizationSkill
- sciml-and-diffeqSkill
- setup-julia-proSkill
- signal-processingSkill
- simulation-and-hpcSkill
- statistical-physicsSkill
- symbolic-mathSkill
- web-development-juliaSkill
- zarr-cloud-arraysSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 95
Shrink the network: Every weight is a dimension of the posterior.
- Distinctive: line 97
Report the multimodality: If modes persist, the honest output is the set of modes with their weights, not the mean across them.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Bayesian PINN — BNNODE & BayesianPINN
NeuralPDE.jl ships its own Bayesian engine built directly on AdvancedHMC and MCMCChains, independent of Turing (no @model block). Two entry points depending on whether the target equation is an ODE or a PDE.
Which posterior
| Question | Use |
| credible intervals on the solution of a known ODE/PDE | BNNODE / BayesianPINN — this page |
| unknown coefficients fitted from data, with uncertainty | BNNODE with param = [prior, ...] — this page |
| point estimate only | ../neural-pde/SKILL.md, which is the cheaper path |
| a known model plus a neural correction, uncertainty on both | ../bayesian-ude-workflow/SKILL.md — Turing @model with an embedded solve |
The distinction that decides it: a PINN posterior is over a function parameterised by a network, so the uncertainty carries the network's own ambiguity; a UDE posterior is over parameters of a known model, so the interval is usually tighter and more interpretable. Reach for BPINN when the solution field itself is the deliverable.
ODEs — BNNODE solver
The high-level interface: pass BNNODE as the algorithm to solve(prob, alg).
using NeuralPDE, Lux, AdvancedHMC, OrdinaryDiffEq
# Out-of-place form is REQUIRED — `du = f(u, p, t)`, not `f!(du, u, p, t)`
function lotka(u, p, t)
[p[1] * u[1] - p[2] * u[1] * u[2],
p[3] * u[1] * u[2] - p[4] * u[2]]
end
prob = ODEProblem(lotka, u0, tspan, p_true)
chain = Chain(Dense(1, 8, tanh), Dense(8, 8, tanh), Dense(8, 2))
alg = BNNODE(
chain;
dataset = [t_obs, u_obs], # for inverse problems / data fitting
draw_samples = 1500,
priorsNNw = (0.0, 2.0), # (mean, std) of Gaussian weight prior — default
phystd = [0.05, 0.05], # std of physics residual likelihood
l2std = [0.05, 0.05], # std of data-fit likelihood
param = [Normal(1.0, 2.0)], # priors on physical parameters (inverse)
Adaptorkwargs = (Integrator = Leapfrog,),
progress = true,
)
sol = solve(prob, alg)The lower-level function ahmc_bayesian_pinn_ode(prob, chain; ...) exposes the same kwargs for callers that want to drive HMC directly without going through the SciML solver interface.
Critical constraint: BPINN ODE solvers only accept the out-of-place form
du = f(u, p, t). The mutating in-place formf!(du, u, p, t)will silently misbehave or error. Convert in-place ODEs before passing them toBNNODE.
PDEs — BayesianPINN discretizer
For full PDE systems (built with @parameters / @variables / Differential — see neural-pde for the symbolic-spec layer), use the BayesianPINN discretizer instead of PhysicsInformedNN:
using NeuralPDE, Lux, AdvancedHMC
discretization = BayesianPINN(
chain,
GridTraining(0.1);
Kernel = HMC(0.05, 4), # step size, leapfrog steps
dataset = [u_obs, t_obs],
)
sol = solve(
pde_system, discretization;
draw_samples = 1500,
priorsNNw = (0.0, 2.0),
)The result of either path (BNNODE or BayesianPINN) is an object whose sol.original field carries the underlying MCMCChains.Chains, fully compatible with mcmc-diagnostics (R-hat, ESS, ArviZ).
Prior choice for NN weights
The weight prior priorsNNw = (μ, σ) directly controls posterior identifiability. Defaults (0.0, 2.0) are fine for small networks; for wider networks, tighten the prior — wide priors on many weights produce multimodal posteriors that NUTS cannot escape.
| Network width | Recommended σ | Rationale |
| ≤ 16 units/layer | 2.0 | Default; data informs the posterior |
| 32–64 units/layer | 1.0 | Reduce neuron-permutation symmetry basin count |
| > 64 units/layer | 0.5 + label-symmetry constraints | Otherwise NUTS almost certainly fails to mix — reach for Pigeons |
When NUTS does not mix
Neural-network weight symmetries (neuron permutation, sign flips) create disjoint posterior basins, and HMC bridges them badly. The signature is chains that individually look healthy — good per-chain ESS, no obvious trend — while R-hat stays above 1.01 across chains. More samples do not fix it: the chains are not in the same mode.
The cheap responses, in order:
- Tighten
priorsNNw(table above). A narrower prior shrinks the permutation basins toward each other. - Shrink the network. Every weight is a dimension of the posterior; a 64-unit net is a 4000-dimensional multimodal target and a 8-unit net may be adequate for a 1-D ODE.
- Temper. Parallel tempering with a Gaussian reference —
Pigeons.jl,n_chainsaround 10,n_rounds10,variational = GaussianReference()— swaps between tempered chains and crosses basins that single-temperature HMC cannot. - Report the multimodality. If modes persist, the honest output is the set of modes with their weights, not the mean across them.
NeuralPDE does not export the log-density as a LogDensityProblems target, so a Pigeons run needs you to reconstruct it from the discretizer's loss (prior term plus physics residual plus data term, up to constants). Before writing that by hand, check whether tightening the prior and shrinking the network removes the need.
Diagnostics
Post-process sol.original, which is a MCMCChains.Chains:
- R-hat < 1.01 on every NN weight and physical parameter, computed across chains — not per chain
- ESS of at least a few hundred per parameter; the tail of the weight distribution is usually where it fails first
- trace plots with no trend and no step: a step means the sampler found a new basin mid-run
- posterior-predictive solves: draw 50–100 samples from the chain, run
solvewith each, and overlay against held-out data — the coverage of that band is the claim, not the band's width
For inverse problems, the physical parameters (p) should have narrow posteriors with bands narrower than the priors — if not, the data is not identifying them. Widen the data set or tighten the prior.
Done when
The chain inside sol.original shows R-hat below 1.01 and an effective sample size in the hundreds per parameter; the ODE was in out-of-place form before it reached BNNODE; priorsNNw was set from the network width rather than left at its default; and posterior predictive coverage was checked on held-out data. When R-hat stayed elevated through the warm start, the posterior came from a tempered parallel run (Pigeons) rather than a longer NUTS chain, and the physical parameters' credible bands are narrower than their priors — the evidence that the data identified them.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

