---
title: State-Dependent PCFGs (PSDGs)
url: https://www.emergentmind.com/topics/state-dependent-pcfgs-psdgs
type: topic
---

# State-Dependent PCFGs (PSDGs)

State-dependent probabilistic context-free grammars (state-dependent PCFGs, or PSDGs) are extensions of PCFGs that capture stochastic plan-generation under uncertainty by conditioning production probabilities on an evolving hidden state. Such state variables may encode both observable environmental context and unobserved, internal agent variables, enabling rigorous, interpretable modeling of planning behavior in applications such as plan recognition, traffic monitoring, and adversarial air combat. PSDGs marry the tree-structured, modular expressivity of PCFGs with explicit, dynamic world-state, supporting efficient, exact online probabilistic inference not feasible with generic dynamic Bayes nets or vanilla PCFGs [1301.3888].

## 1. Formal Specification of Probabilistic State-Dependent Grammars

A Probabilistic State-Dependent Grammar is defined as a 7-tuple
$$
G = (\Sigma, N, S, Q, P, \pi_0, T)
$$
where:

- $\Sigma$: finite set of terminal symbols,
- $N$: finite set of nonterminal symbols,
- $S \in N$: start symbol,
- $Q$: state-variable domain, which can be factored into external observable and internal latent variables,
- $\pi_0: Q \to [0,1]$: prior distribution over initial state,
- $P$: set of productions $r: X \to \alpha$ ($X \in N,\, \alpha \in (N \cup \Sigma)^+$) each with a state-dependent probability function $p_r: Q \to [0,1]$ such that $\sum_{r: X \to \alpha} p_r(q) = 1$ $\forall X, q$,
- $T: Q \times \Sigma \times Q \to [0,1]$: state-transition kernel encoding the Markovian update rule for $Q$ upon emission of a terminal.

Generative semantics proceed by sampling $Q_0 \sim \pi_0(\cdot)$, then—at each step $t$—expanding the current leftmost nonterminal $X$ in state $q = Q_{t-1}$ via stochastic selection of production $r$ with probability $p_r(q)$. Expansion continues depth-first; terminals emitted increment $t$ and transition the state by $Q_t \sim T(Q_{t-1}, x_t, \cdot)$. The joint probability over derivation $D = (r_1, \dots, r_K)$, emitted string $x_{1:K}$, and state sequence $q_{0:K}$ is
$$
\pi_0(q_0) \cdot \prod_{t=1}^K \big[ p_{r_t}(q_{t-1}) \cdot T(q_{t-1}, x_t, q_t) \big].
$$

## 2. Comparison to Standard PCFGs

Ordinary PCFGs are defined as tuples with fixed, context-independent rule probabilities:
$$
\text{PCFG:}\quad \Pr(r \mid X) = p_r,
$$
whereas
$$
\text{PSDG:}\quad \Pr(r \mid X, q) = p_r(q).
$$
Thus, in PSDGs, production selection is conditioned on the agent's current planning state $q$. This context conditioning is crucial for modeling dynamic behavior, such as varying the likelihood of driving maneuvers based on external (e.g., exit proximity) or internal (e.g., aggressiveness) state. All stochasticity in rule choice becomes explicitly state-dependent, increasing modeling fidelity for sequential decision applications [1301.3888].

## 3. State Dynamics and Observation Model

The state space $Q$ in a PSDG is typically factored:
- $Q^{ext}$: visible variables (e.g., position, velocity, observable traffic features, radar contacts).
- $Q^{int}$: hidden/latent features (e.g., goals, skill, preference, aggressiveness).

State transitions follow a one-step Markov property:
$$
\Pr(Q_t = q' \mid Q_{t-1} = q, x_t = x) = T(q, x, q').
$$
At recognition (inference) time, a subset of $Q_t$ may be partially observed, so plan recognition operates over $R_t \subseteq Q$ consistent with available evidence.

## 4. Efficient Inference and Belief Propagation

Online inference in PSDGs must efficiently update the posterior distribution over stack configuration, current productions, and hidden state. The critical insight is that, conditioned on parse stack level and current state, expansions are independent—enabling scalable belief propagation.

Define hierarchical belief states:
- $B_N^t(\ell, X, q):$ probability nonterminal $X$ is active at stack level $\ell$ with prior state $q$,
- $B_P^t(\ell, r, q):$ probability production $r$ is active at level $\ell$ with prior state $q$,
- $B_L^t(\ell, q):$ probability that production at level $\ell$ terminated at $t$ given prior state $q$.

After incorporating evidence via the Markov kernel and likelihood of terminal emissions, recurrences for belief update are
$$
\Psi_t(\ell, X, q \to q') = \Pr(e_t=q_t,\, Q_t=q' \mid N_t^\ell = X, Q_{t-1} = q) = \sum_{r: X \to \alpha} p_r(q) \cdot \phi_t(\ell, r, q \to q'),
$$
with $\phi_t$ computed bottom-up over $\alpha$. This enables explanation (filtering) and prediction (one-step ahead) passes with per-step computational cost $O(|R|^2 |P| m d)$, where $|R|$ is size of filtered state, $|P|$ total number of productions, $m$ the longest RHS, and $d$ max stack depth. This approach maintains exactness while remaining tractable for moderate $|Q|$, with practical inference times reported (e.g., 1s per timestep for traffic domains with $|R| \sim 20$, $d=6$, $m \sim 3$, $|P| \sim 37$ on legacy hardware) [1301.3888].

## 5. Empirical Examples in Plan Recognition Domains

### Traffic Monitoring
A traffic-domain PSDG example illustrates state-dependence. Nonterminals: Drive, Pass, Exit; Terminals: {Left, Right, Stay}. The state $q = (lane, exitDistance, aggressiveness)$. Productions include, e.g.,

| Production         | Probability function $p_r(q)$                      |
|--------------------|---------------------------------------------------|
| Drive $\to$ Stay Drive | constant $0.2$                                 |
| Drive $\to$ Left Drive | $0.1$ if exitDistance $>$ 1 km, else $0.01$    |
| Drive $\to$ Pass Drive | $0.3$ if aggressiveness=high, else $0.05$      |
| Drive $\to$ Exit      | soft-threshold(exitDistance)                    |

After observing “Exit” taken and new state $q_1$, only $r_4$: Drive $\to$ Exit is consistent with the trajectory. Inference updates the posterior on production and state accordingly, and predicts next moves via $p_r(q_1)$.

### Air Combat
In the air-combat setting, nonterminals include Engage, Attack, Evade, Disengage. State features: range (close, medium, far), threatLevel (low, high). For example, production
$$
\text{Engage} \to \text{Attack Engage},\quad p_{r_A}(range, threat) =
\begin{cases}
0.8 & \text{if range=close, threat=high} \\
0.3 & \text{if range=medium, threat=low} \\
0 & \text{otherwise}
\end{cases}
$$
Inference proceeds identically, with efficiency increases when all state variables are fully observable.

## 6. Context-Dependency and Relation to Probabilistic Context-Sensitive Grammars

PSDGs instantiate a form of probabilistic context-sensitive dependency by allowing production probabilities to depend on state, including unobservable latent variables and environmental context. Other models—such as probabilistic context-sensitive grammars (PCSGs) [2402.07113]—make the dependence explicit in rule formulation by including left/right neighbor context in production application. In PCSGs, rewriting a nonterminal at position $A$ may depend on neighboring symbols $L, R$, and rule probabilities interpolate between context-free and context-sensitive forms,
$$
P_{\text{PCSG}}(r \mid A, L, R) = (1-q) M^\text{CF}_{A \to BC} + q\, M^\text{CS}_{LAR \to LBCR}
$$
depending on parameter $q$, with $q\to0$ recovering the PCFG and $q>0$ breaking context-free independence, as evidenced by nontrivial pairwise and higher-order mutual information.

PSDGs differ in that their context is an explicit, possibly high-dimensional or latent state variable, and state transitions are tightly coupled to plan (production) execution. Both paradigms extend PCFG expressivity to domains where substructure probability must depend nontrivially on plan or environmental context.

## 7. Significance and Limitations

PSDGs address the key limitation of PCFGs for modeling structured agent or system behavior in partially observed, dynamic environments: namely, the inability of PCFGs to represent context-sensitive plan-generation. By encoding production probabilities as functions of state, PSDGs offer modular, interpretable modeling and allow exact, online inference leveraging state Markovity and stack factorization.

A limitation is the exponential scaling in state and stack depth, though specialized recurrences and state filtering maintain tractability when $|Q|$ is moderate and only subsets of state are observable.

A plausible implication is that, as plan-recognition complexity and context-sensitivity increase, PSDGs or related models with explicit latent or contextual dependence will be crucial for practical, scalable inference in real-world sequential decision domains [1301.3888], [2402.07113].

Source: https://www.emergentmind.com/topics/state-dependent-pcfgs-psdgs