The Inferencer and the Optimizer attached two graphs to a factor graph, one over its messages and one over its parameters. This note adds the other two parts of a learning system, a regulariser and a loss, and asks for the exact formulation of all four together.
The answer splits them in two:
- Inside the model: the regulariser (prior factors on parameter and structure variables) and the inferencer (an amortised belief). They are factors and beliefs of one joint distribution, and one free energy scores them all.
- Outside it: the optimiser and the loss. The optimiser is the dynamics that minimises the free energy; the loss is the choice of the objective. Neither is a factor of the joint. Each can be learned only in a nested problem, against a criterion it does not control.
Three conditions make the parts compose: the optimiser’s fixed points are the objective’s stationary points; the inferencer is judged by the same free energy; a learned loss or regulariser is anchored by a normaliser or by held-out data. Without the third, learning the weight of a loss or of a penalty on the training objective drives it to zero (§4, derived).
A design note (2026-11-05, Daniel’s question, written up by Claude). Nothing here is implemented beyond what §7 lists as existing; nothing is measured.
Sources: Cruttwell, Gavranović, Ghani, Wilson & Zanasi, Categorical Foundations of Gradient-Based Learning, ESOP 2022 (Def. 3.14 update lenses, Example 3.16 momentum); MacKay, Bayesian Interpolation, Neural Computation 4(3), 1992 (the evidence for hyperparameters); Mitchell & Beauchamp, Bayesian Variable Selection in Linear Regression, JASA 83(404), 1988 (spike-and-slab); Bissiri, Holmes & Walker, A General Framework for Updating Belief Distributions, JRSS B 78(5), 2016 (loss-based posteriors); Lorraine, Vicol & Duvenaud, Optimizing Millions of Hyperparameters by Implicit Differentiation, AISTATS 2020; Andrychowicz et al., Learning to Learn by Gradient Descent by Gradient Descent, NeurIPS 2016; Myers, Double Categories of Open Dynamical Systems, 2020. The decomposition and the derivations are original to this vault. code:
lib/Mycelium.jl/src/factors.jl(OptimiserFactor,LossFactor,PriorFactor),exposure.jl(expose),em.jl(fit_em),lib/LenticulumCore.jl/src/energy.jl(scalarisations)Bibliography: Cruttwell et al. 2022 · MacKay 1992 · Mitchell & Beauchamp 1988 · Bissiri et al. 2016 · Lorraine et al. 2020 · Andrychowicz et al. 2016 · Myers 2020
Theory (CT-ML wiki): Gradient Based Learning with Parametric Lenses · Parametric Lens · Variational Free Energy · Double Category
1. Four roles
| role | acts on | inside the joint? | in Lenticulum today |
|---|---|---|---|
| model | data , latents | yes: | the base graph |
| regulariser | parameters , structure | yes: | PriorFactor on an exposed parameter (expose); BIC’s penalty in the structure examples |
| inferencer | beliefs over (and ) | yes, as a belief: | the message rules; AmortisedInversion per factor |
| optimiser | the update of | no: a dynamics on the objective | OptimiserFactor (GradientDescent, Momentum, Nesterov), fit_em |
| loss | the objective itself | no: the choice of the objective | LossFactor, the scalarisations (WeightedSum, GradedScalarisation) |
The first three are parts of one probabilistic model, the last two are how and what one minimises. The “loss network” of the question is a learned version of the last row, and a learned optimiser a learned version of the row above it.
2. Inside: one joint, one free energy
With parameters and structure as variables (exposed parameters, L-SPEC-003 Exposed Parameters and Energy Channels), the joint is
and one free energy over a belief scores everything:
Its terms sort into the subgraphs. The model’s factors give , the fit. The regulariser’s factors give , the penalty. A belief over contributes its entropy, which is what makes the penalty a complexity term and not only a shrinkage.
A point for . When is fitted as a point (EM, gradient steps), its belief is a Dirac, whose entropy is for continuous . The working objective is then
MAP learning: the regulariser is an added energy and no longer a complexity term. That is why
structures cannot be compared by alone; the structure examples add BIC’s penalty
(, lib/Lenticulum.jl/examples/structure_clusters.md), the crude Laplace approximation of the missing
entropy.
The regulariser subgraph. It is the factors on , and :
- Priors on parameters: a
PriorFactoron an exposed parameter channel; weight decay is a Gaussian prior. - Gated inclusion of edges (spike-and-slab, Mitchell & Beauchamp 1988): a binary gate per edge with , a prior on the gate and a slab on . This separates whether an edge exists from how large it is, so a rarely used but large edge is not shrunk away the way a magnitude penalty shrinks it. That is the answer to “valuable but rare, or to regularise” in the language of the joint: the gate’s posterior is the edge’s value, and a structure edit is a hard decision on .
- Hyperpriors: as a variable with its own prior. Fitted as a point by the evidence (type-II maximum likelihood, MacKay 1992), ; with the free energy as the bound, .
The inferencer, inside. An amortised belief is one choice of , so training on is the same objective, not a new one, and
is the amortisation gap, measurable whenever the message rules reach the minimiser . When is the exact posterior, the gap is . Because is bounded below by , an inferencer cannot lower it by cheating: it can only approach the evidence. This is what The Inferencer and the Optimizer §4 means by “one objective”.
3. Outside: the optimiser
An optimiser is a map on parameters and its state,
Cruttwell et al.’s update lens (Def. 3.14). It is not a factor of the joint: it says how to move towards a minimum of , not what is.
Condition (O): the fixed points are the stationary points. is a fixed point of
exactly when (with its state at rest). If not, the optimiser minimises something
other than . For Mycelium’s rules this holds, from their definitions in factors.jl:
GradientDescent(η): is fixed iff .Momentum(η, γ): , . Fixed requires (from ) and , so and then .Nesterov(η, γ): the same, with the gradient taken at at rest.
A learned optimiser (Andrychowicz et al. 2016) has parameters of its own. They cannot be trained on ‘s value at the current step, which every leaves unchanged. They are trained on an outer criterion: (or a held-out ) after steps of . Condition (O) is then not automatic. A learned rule can have spurious fixed points or none, and it must be checked (or built in, as “the update is zero when the gradient is”).
4. Outside: the loss, and why a learned one must be anchored
The loss is the scalarisation that turns the graded energies into the number being minimised. The free energy is one choice of : the plain sum of fit, penalty and negative entropy. Others:
- Weighted fit (generalised or tempered Bayes, Bissiri et al. 2016): minimising over gives . The loss need not be a log-likelihood, and says how much to trust it against the prior.
- Risk scalarisations of an energy belief (RQ-007 Risk Scalarisations and Local Decomposition).
- Contrastive losses, which generate negatives and raise their energy: Lenticulum’s
RatioFactor(Why Learned Relations Do Not Collapse).
A loss network is a learned , or a learned . It cannot be trained by minimising the loss it computes. The simplest cases show what happens, exactly:
- The weight of the fit. With , the minimum over of the tempered objective is , , and . The minimum over is at : trust no data.
- The weight of a penalty. For an unnormalised penalty with , the envelope theorem gives : the minimum is at , no regularisation.
- The normalised version does not collapse. As a Gaussian prior, weight decay is . The log-normaliser pushes back; the evidence has an interior optimum (MacKay 1992).
This is LP-022’s collapse one level up (LP-022 Constraint factors are normalised in their residual, not their channels): a learned part that is not normalised can lower the objective by giving up, instead of by fitting. The cures are the same two:
Condition (L): a learned loss or regulariser is anchored. Either it is a normalised density in what it scores (then the evidence may choose its parameters), or its parameters are chosen by an outer criterion it does not control: a held-out free energy or likelihood, or a task metric. A learned that is no density, such as the fit weight , has only the second option.
5. The exact statement: a nested problem
- Inner problem: model, regulariser and inferencer in one objective, solved by the optimiser.
- Outer problem: the optimiser’s , the loss’s , the regulariser’s , judged by : the evidence (for normalised parts) or held-out data (for everything else).
- Hypergradients. At an inner minimum, the implicit function theorem gives (Lorraine et al. 2020)
Lenticulum already differentiates through fixed points this way (the implicit learners’ adjoints, the DEQ factors), so the machinery is the same.
The conditions of composition, in one place:
| condition | if it fails | |
|---|---|---|
| (O) | the optimiser’s fixed points are ‘s stationary points | it minimises something else |
| (I) | the inferencer is trained on the same (the gap ) | it can lower a different objective than the one that is reported |
| (L) | a learned loss or regulariser is normalised, or set by an outer criterion | it gives up: weights go to zero, penalties vanish |
When the inner problem has several minima (switches, mixtures), is a choice of minimum and the hypergradient is local to it. The outer problem then inherits the inner problem’s restarts and beams (as in the structure search).
6. Where structure search sits
Structure is a discrete variable of the joint, so structure search is inference over with integrated out, approximately: the score is plus the complexity term the point lacks (BIC today). Three ways to make it sharper, all from §2 and §5:
- gates instead of edits: a soft belief per candidate edge, inferred with everything else; a structure edit becomes the rounding of a gate;
- a Laplace evidence instead of BIC, using the Hessian the hypergradients need anyway;
- held-out scoring, which also judges structures whose parts are not normalised densities.
And the outer problem’s own structure, a beam of inner solutions, is what
lib/Lenticulum.jl/examples/structure_clusters.jl already runs by hand.
7. What exists, and what would be built
| part | exists | missing |
|---|---|---|
| model, regulariser as factors | PriorFactor, expose (L-SPEC-003 §1) | gates per edge; hyperpriors with an M-step for |
| inferencer | message rules; AmortisedInversion per factor | a graph-wide amortised belief; the gap reported |
| optimiser | OptimiserFactor, three rules satisfying (O); fit_em | a train! that interleaves inference and updates (factors.md §5); a check of (O) for a user’s rule |
| loss | LossFactor, scalarisations | learned scalarisations with (L) enforced: a warning, as for LP-022, when a learned weight’s own objective is used |
| outer problem | restarts, beams, refits in the examples | held-out scores; hypergradients through fit_em and the message fixed point |
The rows are in Feature Backlog (“Learning” and “Structure search and editing”).
Related: Composing Optimisers (the optimiser’s own composition), The Inferencer and the Optimizer, The Two-Part Diagram, Everything is a Factor, Unusual Wirings, L-SPEC-003 Exposed Parameters and Energy Channels, Why Learned Relations Do Not Collapse, Energy-Based Learning, RQ-007 Risk Scalarisations and Local Decomposition, L-SPEC-010 Structure Edits