Documentation

Linglib.Core.Agent.BToM

Bayesian Theory of Mind (BToM) @cite{baker-jara-ettinger-saxe-tenenbaum-2017} #

@cite{clark-1996} @cite{houlihan-kleiman-weiner-hewitt-tenenbaum-saxe-2023} @cite{kratzer-2006} @cite{ying-zhi-xuan-wong-mansinghka-tenenbaum-2025}

Domain-general cognitive architecture for action explanation: how observers explain agents' behavior by jointly inferring mental states, shared states, and environmental constraints.

BToM is not specific to language — it applies equally to physical action understanding, game-theoretic reasoning, emotion attribution, and communication. Linguistic specialization (RSA) is established via the RSA-BToM bridge.

Latent Variable Ontology #

Latent variables in the generative model fall into three ontological categories:

The Generative Model #

An agent's action is generated by the causal chain:

World → Percept → Belief
                    ↓
              Belief × Desire × Shared × Medium → Plan → Action
                                                          ↓
                                    Shared × Action × World → Shared'

The observer sees an action and jointly infers the latent variables across all three categories via Bayesian inversion:

P(p, b, d, s, m, w | a) ∝ P(a | b, d, s, m) · P(b | p) · P(p | w) · P(d | w) · P(s) · P(m) · P(w)

Note that P(d | w) is world-conditioned: in many domains, the prior distribution over desires depends on the world state. In RSA, this corresponds to latentPrior(w, l) — the distribution over speaker latent states may depend on the true world (e.g., observation probability in @cite{goodman-stuhlmuller-2013}).

Causal Structure #

The perception chain W → P → B is one specific causal architecture — it decomposes world-to-belief inference into observation then updating. Other architectures are possible (direct world-to-belief, joint perception-belief formation, belief from memory + percept). The current structure follows @cite{baker-jara-ettinger-saxe-tenenbaum-2017} and is sufficient for RSA grounding, where the chain collapses to identity (perfect perception and knowledge).

Limitations #

This is a first-order model: the observer inverts a single agent's generative model. It does not represent recursive mentalizing ("I think that you think that I think..."). Extending to recursive BToM would require nesting: the agent's planModel would itself contain a BToM inference step over the observer's mental states. This is conceptually straightforward but computationally expensive and not needed for single-utterance RSA models.

Extensibility #

The model is designed for domain-specific extension without modification:

Ontological classification of latent variables in BToM.

Different theoretical positions classify the same variable differently. For example, in the RSA-BToM bridge, an RSA model's Interp parameter might be classified as mental (speaker's intended meaning) or medium (structural ambiguity in the grammar), depending on one's theory of scope ambiguity.

  • mental : LatentCategory

    Individual mental states, private to a single agent's mind. Decomposes into Belief, Desire, and Percept.

  • shared : LatentCategory

    Intersubjective states maintained between agents. Common ground, discourse referents, QUD stacks, precedents. Not reducible to individual mental states.

  • medium : LatentCategory

    Non-mental environmental constraints on action. Language structure, conventions, channel properties, affordances.

Instances For
    Equations
    • One or more equations did not get rendered due to their size.
    Instances For

      Temporal dynamics of a latent factor.

      Orthogonal to LatentCategory: a belief can be episodic (specific to one observation), dispositional (stable trait), or dynamic (evolving over time). This distinction matters for multi-observation models where factors may be shared across inference steps or updated between them.

      DynamicsExample (mental)Example (shared)
      episodicthis-utterance belief/goalcurrent QUD
      dispositionalpersonality, stable preferencecultural norms
      dynamicaccumulating evidenceevolving common ground
      • episodic : FactorDynamics

        Varies per observation. Fresh inference target at each step. Most RSA latent variables are episodic: the speaker's goal, intended interpretation, or lexicon for this specific utterance.

      • dispositional : FactorDynamics

        Stable trait of the agent or environment. Shared across observations. E.g., the speaker's general politeness preference, a language's conventionalized scale structure.

      • dynamic : FactorDynamics

        Evolves over observations via an update function. E.g., the listener's accumulating evidence about speaker knowledge, or common ground that grows through discourse.

      Instances For
        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          structure Core.BToM.BToMModel (F : Type u_1) [CommSemiring F] (Action : Type u_2) (Percept : Type u_3) (Belief : Type u_4) (Desire : Type u_5) (Shared : Type u_6) (Medium : Type u_7) (World : Type u_8) :
          Type (max (max (max (max (max (max (max u_1 u_2) u_3) u_4) u_5) u_6) u_7) u_8)

          A BToM generative model for action explanation.

          The observer explains an agent's action by inverting a generative model with six latent variable types organized into three ontological categories:

          Mental (private to the agent):

          • Percept: what the agent observes (generated from world state)
          • Belief: the agent's epistemic state (generated from percepts)
          • Desire: the agent's goals

          Shared (intersubjective):

          • Shared: common ground, mutual beliefs, established conventions

          Medium (environmental constraints):

          • Medium: structure of the communication channel, conventions

          The generative model's causal structure:

          W → perceptModel → P → beliefModel → B
          B × D × S × M → planModel → A
          S × A × W → sharedUpdate → S'
          

          For domains that don't use all components, set unused types to Unit with constant-1 scoring functions.

          The model is parameterized by a score type F (typically for exact computation or for mathematical proofs).

          • perceptModel : WorldPerceptF

            How percepts arise from the world: P(p | w). For agents with perfect perception, use a point mass [p = w].

          • beliefModel : PerceptBeliefF

            How beliefs arise from percepts: P(b | p). For agents with perfect inference, use a point mass [b = p].

          • planModel : BeliefDesireSharedMediumActionF

            Rational action given all latent states: P(a | b, d, s, m). This is the agent's planning/decision function — the forward model that the observer inverts.

          • worldPrior : WorldF

            Prior over world states: P(w).

          • desirePrior : WorldDesireF

            Prior over desires: P(d | w). World-conditioned: the distribution over agent goals may depend on the world state. For world-independent priors, use fun _ => prior.

          • sharedPrior : SharedF

            Prior over shared states: P(s). For single-observation models with fixed shared state, use a point mass.

          • mediumPrior : MediumF

            Prior over medium constraints: P(m).

          • sharedUpdate : SharedActionWorldShared

            How shared state evolves after an action in a world. For single-observation models, this is the identity. For discourse models, this encodes common-ground update, QUD push/pop, presupposition accommodation, and precedent formation. The World parameter allows updates to depend on what actually happened (e.g., whether a presupposition was in fact true).

          Instances For
            def Core.BToM.BToMModel.jointScore {F : Type u_1} [CommSemiring F] {A : Type u_2} {P : Type u_3} {B : Type u_4} {D : Type u_5} {S : Type u_6} {M : Type u_7} {W : Type u_8} (model : BToMModel F A P B D S M W) (a : A) (p : P) (b : B) (d : D) (s : S) (m : M) (w : W) :
            F

            The observer's unnormalized joint score over all latent variables given an observed action:

            joint(a, p, b, d, s, m, w) =
              planModel(b,d,s,m,a) · beliefModel(p,b) · perceptModel(w,p) ·
              worldPrior(w) · desirePrior(w,d) · sharedPrior(s) · mediumPrior(m)
            

            This is the full generative model probability (unnormalized). All marginal posteriors are sums over subsets of this joint.

            Equations
            • One or more equations did not get rendered due to their size.
            Instances For
              def Core.BToM.BToMModel.worldMarginal {F : Type u_9} [CommSemiring F] {A : Type u_10} {P : Type u_11} {B : Type u_12} {D : Type u_13} {S : Type u_14} {M : Type u_15} {W : Type u_16} [Fintype P] [Fintype B] [Fintype D] [Fintype S] [Fintype M] (model : BToMModel F A P B D S M W) (a : A) (w : W) :
              F

              World marginal: P(w | a) ∝ Σ_{p,b,d,s,m} joint(a, p, b, d, s, m, w).

              This is the primary inference target: given an observed action, what is the state of the world?

              Equations
              Instances For
                theorem Core.BToM.BToMModel.worldMarginal_eq {F : Type u_9} [CommSemiring F] {A : Type u_10} {P : Type u_11} {B : Type u_12} {D : Type u_13} {S : Type u_14} {M : Type u_15} {W : Type u_16} [Fintype P] [Fintype B] [Fintype D] [Fintype S] [Fintype M] (model : BToMModel F A P B D S M W) (a : A) (w : W) :
                model.worldMarginal a w = model.worldPrior w * p : P, b : B, d : D, s : S, m : M, model.planModel b d s m a * model.beliefModel p b * model.perceptModel w p * model.desirePrior w d * model.sharedPrior s * model.mediumPrior m

                The world prior factors out of the world marginal:

                P(w | a) ∝ P(w) · Σ_{p,b,d,s,m} P(a|b,d,s,m) · P(b|p) · P(p|w) · P(d|w) · P(s) · P(m)

                def Core.BToM.BToMModel.beliefMarginal {F : Type u_9} [CommSemiring F] {A : Type u_10} {P : Type u_11} {B : Type u_12} {D : Type u_13} {S : Type u_14} {M : Type u_15} {W : Type u_16} [Fintype P] [Fintype D] [Fintype S] [Fintype M] [Fintype W] (model : BToMModel F A P B D S M W) (a : A) (b : B) :
                F

                Belief marginal: P(b | a) ∝ Σ_{p,d,s,m,w} joint(a, p, b, d, s, m, w).

                Equations
                Instances For
                  def Core.BToM.BToMModel.desireMarginal {F : Type u_9} [CommSemiring F] {A : Type u_10} {P : Type u_11} {B : Type u_12} {D : Type u_13} {S : Type u_14} {M : Type u_15} {W : Type u_16} [Fintype P] [Fintype B] [Fintype S] [Fintype M] [Fintype W] (model : BToMModel F A P B D S M W) (a : A) (d : D) :
                  F

                  Desire marginal: P(d | a) ∝ Σ_{p,b,s,m,w} joint(a, p, b, d, s, m, w).

                  Equations
                  Instances For
                    def Core.BToM.BToMModel.perceptMarginal {F : Type u_9} [CommSemiring F] {A : Type u_10} {P : Type u_11} {B : Type u_12} {D : Type u_13} {S : Type u_14} {M : Type u_15} {W : Type u_16} [Fintype B] [Fintype D] [Fintype S] [Fintype M] [Fintype W] (model : BToMModel F A P B D S M W) (a : A) (p : P) :
                    F

                    Percept marginal: P(p | a) ∝ Σ_{b,d,s,m,w} joint(a, p, b, d, s, m, w).

                    Equations
                    Instances For
                      def Core.BToM.BToMModel.sharedMarginal {F : Type u_9} [CommSemiring F] {A : Type u_10} {P : Type u_11} {B : Type u_12} {D : Type u_13} {S : Type u_14} {M : Type u_15} {W : Type u_16} [Fintype P] [Fintype B] [Fintype D] [Fintype M] [Fintype W] (model : BToMModel F A P B D S M W) (a : A) (s : S) :
                      F

                      Shared-state marginal: P(s | a) ∝ Σ_{p,b,d,m,w} joint(a, p, b, d, s, m, w).

                      Equations
                      Instances For
                        def Core.BToM.BToMModel.mediumMarginal {F : Type u_9} [CommSemiring F] {A : Type u_10} {P : Type u_11} {B : Type u_12} {D : Type u_13} {S : Type u_14} {M : Type u_15} {W : Type u_16} [Fintype P] [Fintype B] [Fintype D] [Fintype S] [Fintype W] (model : BToMModel F A P B D S M W) (a : A) (m : M) :
                        F

                        Medium marginal: P(m | a) ∝ Σ_{p,b,d,s,w} joint(a, p, b, d, s, m, w).

                        Equations
                        Instances For
                          def Core.BToM.BToMModel.beliefExpectation {F : Type u_9} [CommSemiring F] {A : Type u_10} {P : Type u_11} {B : Type u_12} {D : Type u_13} {S : Type u_14} {M : Type u_15} {W : Type u_16} [Fintype P] [Fintype B] [Fintype D] [Fintype S] [Fintype M] [Fintype W] (model : BToMModel F A P B D S M W) (f : BF) (a : A) :
                          F

                          Belief-weighted expectation: given a scoring function on belief states, compute the belief-marginal weighted sum.

                          This is the general form of LaBToM's Pr(Agent, φ) computation: instantiate f b = if φ(b) then 1 else 0 to get the unnormalized Pr_obs(Agent, φ | a) from BToM belief marginals.

                          More generally, any quantity that depends on the agent's belief state (credence, expected utility, prediction error) can be computed as a belief expectation.

                          Equations
                          Instances For

                            Connection to Content Individuals #

                            BToM's Belief and Desire types correspond to content individuals — see Core.ContentIndividual for the ontological sort. A BToMModel can be instantiated with ContentIndividual W as the Belief type, making the observer's posterior a distribution over content individuals.