Finite generative model and posterior-form variational free energy
Definitionfep_generative_modelThe mission's model layer: a finite generative model for active inference, the laws it predicts, and the posterior-form variational free energy.
Over finite types , a generative model consists of five fields:
- an initial state law over ;
- a policy-conditioned transition kernel ;
- a state-to-outcome likelihood kernel ;
- a preference law over outcomes;
- a policy prior .
Under a policy the model predicts the state law (marginalizing the initial law through the transition) and the outcome law . At an outcome with positive predicted mass , the exact Bayesian posterior state law is the finite Bayes rule . The outcome surprisal is (a total function; positivity enters the theorems as an explicit hypothesis, not inside the definition). A recognition density is any finite law over states, and the posterior-form variational free energy of at is
Formalization Note — transcribed verbatim from the proved module FepSketches.active_inference of the fep_lean formalization (fields, prediction, posterior, surprisal, and the free-energy functional; rollout/planning and expected-free-energy constructs of that module are out of this mission's scope and are planned for a follow-up mission); the file compiles sorry-free.
import Definitions.Def_fep_finite_information
/-!
# Finite generative model and posterior-form variational free energy
Transcribed from the proved module `FepSketches.active_inference` of the
fep_lean formalization (Active Inference Institute). One policy-conditioned
carrier owns prediction, observation, posterior state, preferences, and the
posterior-form variational free energy. The epistemic sign is fixed by
definition; the theorems of this mission derive the surprisal bound, its
exactness at the Bayesian posterior, its uniqueness characterization, and the
evidence lower bound.
-/
namespace FreeEnergyPrinciple
open Finset
open scoped BigOperators
variable {Policy State Outcome : Type*}
[Fintype Policy] [Fintype State] [Fintype Outcome]
/-- Finite policy-conditioned generative model for active inference. -/
structure GenerativeModel (Policy State Outcome : Type*)
[Fintype Policy] [Fintype State] [Fintype Outcome] where
initialState : FiniteLaw State
transition : Policy → FiniteKernel State State
likelihood : FiniteKernel State Outcome
preferences : FiniteLaw Outcome
policyPrior : FiniteLaw Policy
/-- State prediction under a candidate policy. -/
def predictedState (model : GenerativeModel Policy State Outcome)
(policy : Policy) : FiniteLaw State :=
(model.transition policy).predictive model.initialState
/-- Predicted outcome marginal under a policy. -/
def predictedOutcome (model : GenerativeModel Policy State Outcome)
(policy : Policy) : FiniteLaw Outcome :=
model.likelihood.predictive (predictedState model policy)
/-- Exact posterior state law after a positive-mass outcome. -/
noncomputable def posteriorState
(model : GenerativeModel Policy State Outcome) (policy : Policy)
(outcome : Outcome) (h : 0 < predictedOutcome model policy outcome) :
FiniteLaw State :=
model.likelihood.posterior (predictedState model policy) outcome h
/-- Surprisal of one outcome under a policy. Positivity is required by the
downstream posterior/VFE theorems rather than hidden in this total function. -/
noncomputable def outcomeSurprisal
(model : GenerativeModel Policy State Outcome) (policy : Policy)
(outcome : Outcome) : ℝ :=
-Real.log (predictedOutcome model policy outcome)
/-- Posterior-form variational free energy:
`F[Q,o,π] = KL(Q || P(s|o,π)) - log P(o|π)`. -/
noncomputable def variationalFreeEnergy
(model : GenerativeModel Policy State Outcome) (policy : Policy)
(outcome : Outcome) (h : 0 < predictedOutcome model policy outcome)
(recognition : FiniteLaw State) : ℝ :=
finiteKL recognition (posteriorState model policy outcome h) +
outcomeSurprisal model policy outcome
end FreeEnergyPrinciple
Read-back
What the Lean code literally says, in plain math · glm-flash-latest
Read-back: GenerativeModel, predictedState, predictedOutcome, posteriorState, outcomeSurprisal, variationalFreeEnergy
Structure GenerativeModel. For types , , that are all finite, a generative model is a record consisting of five pieces of data:
- an initial state law , i.e. a probability distribution over states;
- a transition assignment , giving for each policy a finite transition kernel over states, ;
- a likelihood kernel , mapping each state to a distribution over outcomes;
- a preference law , a distribution over outcomes;
- a policy prior , a distribution over policies.
Here denotes a probability law on the finite type and a finite transition kernel from to ; the structures used (FiniteLaw, FiniteKernel, finiteKL, and the predictive/posterior operations) are imported from a definitions module and their internal meaning is not restated in this file.
Definition predictedState. Given a model, a policy , the predicted state law is the predictive (pushforward) distribution obtained by applying the transition kernel to the initial state law . This is total: it is defined for every policy, with no positivity or support condition.
Definition predictedOutcome. Given a model and a policy , the predicted outcome law is the predictive distribution obtained by applying the likelihood kernel to the predicted state law under . Again total, defined for every policy.
Definition posteriorState. Given a model, a policy , an outcome , and the explicit hypothesis that the predicted outcome mass (as defined by predictedOutcome) is strictly positive, the posterior state law is the Bayesian posterior obtained by conditioning the predicted state law under on the outcome via the likelihood kernel's posterior operation. The definition is partial in the sense that it is only stated when ; for outcomes of zero predicted mass, this declaration provides no value.
Definition outcomeSurprisal. For a model, a policy , and an outcome , the surprisal is
the negative natural logarithm of the predicted outcome mass. This is a total function of : when the value is -valued behavior of -valued log is not guarded here — as written, the definition computes using the total real logarithm, so at zero-mass outcomes the value is whatever Real.log 0 evaluates to (it does not throw an error or return a special value), and no positivity assumption is baked into this definition. It is noncomputable.
Definition variationalFreeEnergy. Given a model, a policy , an outcome , the positivity hypothesis , and an arbitrary "recognition" state law , the posterior-form variational free energy is
that is, the finite KL divergence from the supplied recognition law to the posterior state law (as defined above, which requires the same positivity hypothesis), plus the surprisal of under . Note precisely what is quantified: is universally quantified and arbitrary — the definition imposes no constraint tying to the model, so degenerate choices of are included. The KL divergence used is the finiteKL operation on finite laws; as imported, it is applied to an arbitrary pair of state laws with no hypothesis guarding against non-absolute-continuity, so the value at pairs where is not absolutely continuous with respect to the posterior is whatever finiteKL returns by its own convention (this file states none). The definition is noncomputable.
No theorem in this file asserts anything about these definitions; the declarations above are definitions only, and the positivity hypothesis appears in posteriorState and variationalFreeEnergy but not in predictedState, predictedOutcome, or outcomeSurprisal.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.