design later

Could Mycelium store its beliefs (and perhaps its factors) as the types RxInfer.jl already uses, instead of its own structs that are converted on the way in and out? For beliefs, yes, by wrapping: keep this project’s abstract types and dispatch, store an ExponentialFamily object inside. For factors, no: the two packages mean different things by a factor, and the useful sharing is RxInfer’s approximation code inside a hand-written nonlinear factor. Noted for later; nothing here is built.

Sources: original to this vault (design); the source of ReactiveMP.jl 5.x (src/approximations/: linearization, unscented, Laplace, CVI) and of BayesBase.jl / ExponentialFamily.jl, read October 2026; Bagaev, Podusenko & de Vries, RxInfer: A Julia package for reactive real-time Bayesian inference, JOSS 2023

Bibliography: Bagaev et al. 2023

Theory: RxInfer as a Backend · Belief Algebra · interop

1. Where things stand

Beliefs are this project’s own structs (GaussianBelief, CategoricalBelief, …, in LenticulumCore), with their rules in Mycelium. as_distribution / as_belief convert to and from the BayesBase / ExponentialFamily types RxInfer passes (interop), allocating a new object each way.

The allocation is not the problem: copying an precision is cheap next to anything done with it, and as_distribution could share the arrays instead of copying them. What a shared type would really buy is shared rules: ExponentialFamily already has products, entropies, densities and natural-parameter arithmetic for dozens of families (Gamma, Wishart, Beta, Dirichlet, von Mises, …), which Mycelium would otherwise re-implement one by one.

2. Three ways to hold a belief

own struct (today)use the RxInfer type directlywrap the RxInfer type
exampleGaussianBelief(η, Λ)MvNormalWeightedMeanPrecision is the beliefGaussianBelief{D}(d::D), d an ExponentialFamily object
conversionallocatenoneunwrap / wrap, no copy
own supertype and dispatch (AbstractBelief)yesno: an external type cannot subtype oursyes
families availablethe six we wroteall of ExponentialFamily’sall, one thin wrapper each
our extras (improper messages, labels, TrivialBelief, polarity-aware rules)yesmust be bolted on outside the typeyes, in the wrapper
dependency of the belief layerLinearAlgebraExponentialFamily (heavy)ExponentialFamily (heavy)

Using the types directly loses the one thing the project’s design rests on: a belief type hierarchy it controls (AbstractBelief, isexact, combine rules with polarity in mind). Wrapping keeps it and still gets every rule for free by delegation: combine on two wrapped Gaussians calls BayesBase’s prod; entropy calls entropy; a family with no wrapper yet can use a generic ExpFamBelief{D}.

3. Where the wrapped beliefs would live

Not in LenticulumCore: ExponentialFamily pulls in ForwardDiff, SpecialFunctions, HCubature and more, and the core is meant to be light, like LuxCore. This is the MyceliumCore / Mycelium split discussed earlier (Belief Algebra §6, item 3), now with a reason:

packagecontentdependencies
LenticulumCoreabstract types, the factor interface, today’s light beliefslight
MyceliumCore (new)graphs, schedules, combine for the light beliefslight
Myceliumwrapped ExponentialFamily beliefs, their rules by delegation, the RxInfer bridgesExponentialFamily, BayesBase

Factor packages that only need Gaussians and points keep depending on the light layers.

4. Factors: share the approximations, not the structs

A Lenticulum factor and an RxInfer node are different objects:

Lenticulum factorRxInfer node
isa struct with parameters and state (ps, st), like a Lux layera declaration (@node) plus one rule per interface (@rule)
directionchosen per call by a Polarityone rule per direction, written in advance
learnedyes, by gradients through inferenceparameters by inference over them

A common struct would fit neither. What can be shared is the bridge in both directions, step 3 of RxInfer as a Backend §4 (a learned relation as an RxInfer node), and, the part that matters most, RxInfer’s approximation code inside a hand-written nonlinear factor.

ReactiveMP’s delta nodes already implement, as reusable functions, the Gaussian approximations through a known function (src/approximations/): Linearization (first-order Taylor), Unscented (sigma points), Gauss–Hermite and spherical-radial cubature, Laplace, and CVI. A NonlinearFactor(f; method = Unscented()) in Mycelium could call these for its messages, which gives Lenticulum the factor it lacks (Open Problems in Implicit Diffusion Learning I11) without writing a sigma-point library. The cost is a ReactiveMP dependency (heavier than ExponentialFamily, and its internals change between versions); the fallback is writing linearisation and the unscented transform here, about a hundred lines with DifferentiationInterface.

A hand-written nonlinear factor and a learned one would then sit side by side in one graph: known physics (, a measurement model) next to a learned relation. That is the combination real problems need (the particle and SLAM examples).

5. Risks

  • Load time and weight. ExponentialFamily and ReactiveMP are large; time to first inference grows. Hence the split in §3.
  • Improper messages. This project’s likelihood messages often have a singular precision. ExponentialFamily represents them, but its mean, cov and entropy assume proper distributions; the wrapper must keep this project’s checks.
  • API stability. BayesBase and ExponentialFamily are stable packages; ReactiveMP’s approximation internals are less so. Depend on the former; treat the latter as optional.
  • Automatic differentiation. The implicit adjoints differentiate through beliefs only in a few places, but Zygote or Enzyme through ExponentialFamily types is untested here.
  • Labels and polarity. Categorical labels and polarity-aware rules have no counterpart upstream; they stay in the wrappers.

6. When to do it

The trigger is the first non-Gaussian exponential family Mycelium needs: a Gamma belief for a learned noise precision, a Wishart for a covariance, a Dirichlet for categorical parameters. Writing those by hand would duplicate ExponentialFamily, so at that point wrap instead (§2) and split the package (§3). The nonlinear factor (§4) can come earlier and independently, with ReactiveMP’s approximations as an optional extension and a small built-in linearisation as the default.

Related: RxInfer as a Backend, Belief Algebra, interop, gaussian_belief, Related Julia Projects, Why Julia