Observation models¶
How a hidden state produces a sensor reading. FixedSensor is a constant linear sensor; CallableSensor lets the observation noise R(x) vary with the state — the reason an agent has anything to gain from seeking information. Under a fixed sensor and fixed dynamics noise the epistemic term is identical for every policy 1; a state-dependent R(x) is the minimal departure that makes it move with the action again 2. Both satisfy the ObservationModel protocol.
ObservationModel ¶
Bases: Protocol
How a hidden state produces an observation, as a local linear-Gaussian map.
The EFE core never assumes a fixed sensor matrix; it asks the observation
model to linearize itself about a state, getting back the local
(C, R) (the observation Jacobian and the noise covariance there). For a
fixed sensor these are constant; for a state-dependent sensor they vary.
Both methods take their arguments by position, so an implementation may name them as it likes.
is_fixed
property
¶
True when (C, R) are constant in the state.
This is the fixed-sensor fast path. With fixed dynamics noise as well,
EFE's epistemic term is constant there and EFE collapses to LQR. False
for a state-dependent sensor.
linearize ¶
gaussianize ¶
gaussianize(
mean: ArrayLike, cov: Float64[Array, "n n"]
) -> tuple[
Float64[Array, m],
Float64[Array, "m m"],
Float64[Array, "m m"],
]
Sensor's EFE ingredients (o⁺, S, R) about the belief (mean, cov).
The EFE kernel calls this, not linearize: each sensor owns its own
moment-matching, so the fixed/linear path stays a bare matvec and a
sensor with a nonlinear mean could do second order without reopening it.
Returns the predicted-observation mean o⁺, its covariance S (feeds
the pragmatic term), and the conditional observation noise R at mean
(feeds the epistemic ½(ln det S − ln det R)) — all computed in one pass.
Source code in src/cpomdp/observation.py
FixedSensor
dataclass
¶
A sensor whose (C, R) never change with state.
linearize returns the same stored matrices for every state: a fixed
linear sensor is its own linear approximation everywhere. With fixed process
noise as well, this is the regime where EFE's epistemic term is constant and EFE
collapses to LQR (DECISIONS.md ADR-003). A state-dependent Q(x) moves the
epistemic term even here (ADR-006).
Attributes:
| Name | Type | Description |
|---|---|---|
observation_matrix |
Float64[Array, 'm n']
|
the observation matrix |
observation_noise |
Float64[Array, 'm m']
|
the observation-noise covariance |
Source code in src/cpomdp/observation.py
linearize ¶
Return the stored (C, R) unchanged, the same for every state.
gaussianize ¶
gaussianize(
mean: ArrayLike, cov: Float64[Array, "n n"]
) -> tuple[
Float64[Array, m],
Float64[Array, "m m"],
Float64[Array, "m m"],
]
Exact linear ingredients (C·μ, C·Σ·Cᵀ + R, R) about (mean, cov).
Source code in src/cpomdp/observation.py
tree_flatten ¶
tree_unflatten
classmethod
¶
Rebuild without re-validating — leaves may be tracers.
Source code in src/cpomdp/observation.py
CallableSensor
dataclass
¶
CallableSensor(
observation_matrix: ArrayLike,
noise_fn: Callable[
[Float64[Array, n], PyTree], Float64[Array, "m m"]
],
noise_params: PyTree,
)
A sensor with state-dependent observation noise R(x) and constant C.
The observation map stays linear (constant C); the noise covariance varies
with the state via noise_fn(state, noise_params) -> R. This breaks the ADR-003
fixed-sensor collapse: with R depending on the predicted state μ⁺ (and
so on the action), the epistemic term is no longer action-invariant — the agent
can act to reach states where the sensor is sharper. Mean-exact,
covariance-plug-in: o⁺ = C·μ⁺ is exact, while R(μ⁺) is a plug-in that
drops the ½tr(H_R Σ⁺) Jensen term — a deliberate first-order choice.
noise_fn must return a positive-definite R(x) at every reachable state
— it is a covariance the epistemic term inverts. A non-PD R(x) has no real
½ln det, so the EFE epistemic term becomes NaN there (surfaced at action
selection, not silently wrong); this is the runtime analogue of the
construction-time positive-definite check on a fixed observation_noise.
noise_params is a pytree leaf (so EFE is grad-able w.r.t. it — sensor
learning); noise_fn is static aux (a callable cannot be a traced leaf).
Pass a module-level noise_fn and keep all tunables in noise_params: a
closure/lambda is hashable only by identity and would defeat jit caching.
CallableDynamicsNoise takes the same two
arguments for Q(x).
Source code in src/cpomdp/observation.py
linearize ¶
Local (C, R(state)): constant C, state-dependent noise.
Source code in src/cpomdp/observation.py
gaussianize ¶
gaussianize(
mean: ArrayLike, cov: Float64[Array, "n n"]
) -> tuple[
Float64[Array, m],
Float64[Array, "m m"],
Float64[Array, "m m"],
]
Linear ingredients (C·μ, C·Σ·Cᵀ + R(μ), R(μ)) about (mean, cov).
Mean-exact, with R plugged in at μ, the mean.
Source code in src/cpomdp/observation.py
tree_flatten ¶
Traced children (observation_matrix, noise_params); aux noise_fn.
tree_unflatten
classmethod
¶
Rebuild without re-validating — leaves may be tracers.
Source code in src/cpomdp/observation.py
-
Magnus T. Koudahl, Wouter M. Kouw, and Bert de Vries. On epistemics in expected free energy for linear Gaussian state space models. Entropy, 23(12):1565, 2021. URL: https://doi.org/10.3390/e23121565, doi:10.3390/e23121565. ↩
-
Daniel Corva. State-dependent observation noise reintroduces epistemic value in linear-Gaussian active inference. arXiv preprint arXiv:2607.20306, 2026. URL: https://arxiv.org/abs/2607.20306, arXiv:2607.20306, doi:10.48550/arXiv.2607.20306. ↩