Today I want to share a rabbit hole I went down where I made an (in my view) interesting mistake when learning about bisimulation metrics. (*1)


Bisimulation Metrics

Bisimulation metrics can be viewed as a measure of behavioral equivalence/similarities between states in Markov chains. As a starter, consider a Markov chain over state space X\mathcal{X} with a reward function R:XR.R: \mathcal{X} \to \mathbb{R}. Roughly speaking, if two states xAx_A and xBx_B admit similar rewards (*2)—the rewards are the “behavior” of the states that actually matter—we are willing to say the states are similar, even if xAx_A and xBx_B themselves “look” very different (e.g., xAx_A and xBx_B are real vectors that are far away from each other in Euclidean distance).

Of course things are not that easy: these states will transition to random next-states xAx_A' and xBx_B', who will produce their own rewards R(xA)R(x_A') and R(xB)R(x_B'). So when we say xAx_A and xBx_B are behaviorally similar, we want to make sure not only they share similar immediate rewards R(xA)R(xB)R(x_A) \approx R(x_B), but they also transition to distributions of states that admit similar rewards, i.e., R(xA)R(x_A') and R(xB)R(x_B') are similar distributed, and xAx_A' and xBx_B' further transition to states whose reward similarities need to be accounted for… and so on and so forth. (*3)

The bisimulation metric captures the above intuition mathematically. In fact, it allows you to measure state similarity even between different chains. Consider two Markov chains defined over state spaces X\mathcal{X} and Y\mathcal{Y}, respectively, with transition kernels PXP_X and PYP_Y. (If you want to measure state similarity in a single chain PXP_X, just invoke the definition with Y=X\mathcal{Y}=\mathcal{X} and PX=PYP_X = P_Y.) Let RXR_X and RYR_Y be the reward functions. Then, the bisimulation metric d(,):X×YR0d(\cdot,\cdot): \mathcal{X}\times\mathcal{Y} \to \mathbb{R}_{\ge 0} measures the distance between a state xXx \in \mathcal{X} and yYy\in \mathcal{Y} as:

d(x,y)=(1γ)RX(x)RY(y)+γinfpΠ(PX(x),PY(y))E(x,y)p[d(x,y)],(1)d(x,y) = (1-\gamma) |R_X(x) - R_Y(y)| + \gamma \inf_{p \in \Pi(P_X(\cdot|x), P_Y(\cdot|y))} \mathbb{E}_{(x', y') \sim p}[d(x',y')], \quad (1)

where Π(μ,ν)\Pi(\mu, \nu) is a coupling between two distributions as often seen in the definition of Wasserstein’s distance, i.e., for μΔ(X)\mu\in\Delta(\mathcal{X}) and νΔ(Y)\nu\in\Delta(\mathcal{Y}), pΠ(μ,ν)p \in \Pi(\mu, \nu) is any joint distribution whose XX marginal matches μ\mu and whose YY marginal matches ν\nu.


Trajectory Coupling

A remarkable observation, made here and here, is that Eq.(1) is the Bellman optimality equation of an “augmented MDP” with state space X×Y\mathcal{X}\times\mathcal{Y}. (*4) Viewed this way, d(.,.)d(.,.) is the VV^\star in this augmented MDP, the LHS is simply VV^\star at state (x,y)(x,y), and (1γ)RX(x)RY(y)(1-\gamma) \vert R_X(x) - R_Y(y)\vert on the RHS is the immediate reward. infp\inf_p is minimizing over actions (so we are doing cost minimization instead of reward maximization), and the transition distribution over the next (x,y)(x',y') is given by the action pp itself.

And my down-the-rabbit-hole journey starts here: what does it look like to rollout Monte-Carlo trajectories in the MDP described by Eq.(1), under some policy for choosing pΠ(PX(x),PY(y))p \in \Pi(P_X(\cdot\mid x), P_Y(\cdot\mid y))? Well, we start with some (x,y)(x,y) as initial state, i.e., (X0,Y0)=(x,y)(X_0,Y_0)=(x,y). In each step tt, a policy chooses a pp to draw (Xt,Yt)(X_t, Y_t) in a way that respects the transition laws of PXP_X and PYP_Y, i.e., P(XtXt1)=PX(XtXt1)P(X_t \mid X_{t-1}) = P_X(X_t \mid X_{t-1}), and similarly for YY. So at the end of the day, this defines a joint distribution qq over

X0,X1,X2,,Y0,Y1,Y2,X_0, X_1, X_2, \ldots, Y_0, Y_1, Y_2, \ldots

where the marginal of qq over X0,X1,X2,X_0, X_1, X_2, \ldots is clearly identically distributed as a trajectory drawn from PXP_X (let’s denote the distribution of trajectories starting from xx as P{Xt}xP_{\{X_t\}}^{x}), and similarly for YY. Thus, we have

qΠ(P{Xt}x,P{Yt}y).q \in \Pi(P_{\{X_t\}}^{x}, P_{\{Y_t\}}^{y}).

Moreover, the random return along this trajectory is

t0γtRX(Xt)RY(Yt).(2)\sum_{t\ge 0} \gamma^t |R_X(X_t) - R_Y(Y_t)|. \quad \quad (2)

Seeing this, a guess immediately came to my mind: if a policy for choosing pp defines a coupling between XX and YY trajectories, perhaps the optimal policy in Eq.(1) simply induces the optimal coupling between P{Xt}xP_{\{X_t\}}^{x} and P{Yt}yP_{\{Y_t\}}^{y} for minimizing Eq.(2)? If this is true, we will have a remarkable consequence that, d(x,y)d(x,y) is the Wasserstein distance between P{Xt}xP_{\{X_t\}}^{x} and P{Yt}yP_{\{Y_t\}}^{y}, where the base metric is Eq.(2), i.e.,

d(x,y)=minqΠ(P{Xt}x,P{Yt}y)E{Xt},{Yt}q[t0γtRX(Xt)RY(Yt)].(3)d(x,y) = \min_{q \in \Pi(P_{\{X_t\}}^{x}, P_{\{Y_t\}}^{y})} \mathbb{E}_{\{X_t\}, \{Y_t\} \sim q}[\sum_{t\ge 0} \gamma^t |R_X(X_t) - R_Y(Y_t)|]. \quad (3)

Believing my intuition was correct, I started to sketch a proof based on the following claims (my mistake is hidden somewhere; see if you can spot it before I reveal the answer!):

Claim 1: A policy for choosing pp in the augmented MDP defines a coupling between P{Xt}xP_{\{X_t\}}^{x} and P{Yt}yP_{\{Y_t\}}^{y}.

Justification: Evident from the description above.

Claim 2: Conversely, any coupling between P{Xt}xP_{\{X_t\}}^{x} and P{Yt}yP_{\{Y_t\}}^{y} is a history-dependent policy in the augmented MDP.

Justification: The joint distribution qq between {Xt}\{X_t\} and {Yt}\{Y_t\} specified by the coupling can always be written as the product of q(Xt+1,Yt+1X1:t,Y1:t)q(X_{t+1}, Y_{t+1} \mid X_{1:t}, Y_{1:t}), which maps history of the augmented MDP to a distribution over next Xt+1,Yt+1X_{t+1}, Y_{t+1}. Since the coupling respects the marginals of P{Xt}xP_{\{X_t\}}^{x} and P{Yt}yP_{\{Y_t\}}^{y}, it also respects PX(Xt+1Xt)P_X(X_{t+1} \mid X_{t}) and PY(Yt+1Yt)P_Y(Y_{t+1} \mid Y_{t}), which is consistent with the “pΠ(PX(x),PY(y))p \in \Pi(P_X(\cdot\mid x), P_Y(\cdot\mid y))” specification in Eq.(1).

Claim 3: Among all history-dependent policies, the optimal one is Markov, i.e., the form of policy considered in Eq.(1).

Justification: Basic property of an infinite-horizon discounted MDP.

Combining the claims, it follows that the optimal policy implied in Eq.(1) minimizes Eq.(2) over all trajectory couplings.


Weird Implications

For a few weeks(!) I believed my reasoning was correct and was pretty excited about Eq.(3), as it implies an embarrassingly simple way (compared to what’s known in the literature) to estimate d(,)d(\cdot, \cdot): roll out multiple trajectories from xx and yy, resp., and simply calculate the empirical Wasserstein according to Eq.(2) as the base metric! “There is an elegant paper to write,” I said to myself, “only if I could make sense of a few confusing implications…

Implication 1: The rate of estimating Wasserstein’s suffers a curse of dimensionality, i.e., if the base metric is a standard distance (say 1\ell_1 or 2\ell_2) in Rd\mathcal{R}^{\mathsf{d}}, typically you’d expect a poor rate of n1/dn^{-1/{\mathsf{d}}}. Now let’s look at Eq.(2): if we assume all trajectories end in HH steps (or perform the standard truncation), Eq.(2) is an 1\ell_1 distance in RH\mathbb{R}^H, resulting in n1/Hn^{-1/H} rate.

Now what’s really peculiar is this: if the process only has terminal rewards, i.e., R(Xt)=RY(Yt)=0R(X_t)=R_Y(Y_t) = 0 unless t=Ht=H, then Eq.(2) is 1\ell_1 in R\mathbb{R}, improving the estimation rate to 1/n1/n! This is super weird and strongly counterintuitive, as terminal rewards alone as an assumption almost never makes a problem fundamentally easier in RL.

Implication 2: In the hierarchy of state abstractions, model-irrelevance (which is closely related to bisimulation metrics (*3)) is at the finest level. Value-irrelevance (such as QπQ^\pi- or QQ^\star-irrelevance) is a significantly coarser notion, allowing the aggregation of states with similar expected values. Looking at Eq.(3), however, it is clearly closer to the value-irrelevance notion of abstraction than model-irrelevance. In fact, it is like a distributional variant of the former, and they coincide when the Markov chain is deterministic and there are only terminal rewards. This is also counterintuitive as we have not made any significant assumptions that should collapse the abstraction hierarchy.


Understanding the Mistake

The more I thought about the weirdness, the more I believed Eq.(3) is wrong. Eventually, I was able to come up with a simple counterexample:

counterexample

This is a finite-horizon example and I only consider d(,)d(\cdot, \cdot) across states at the same “level”, and it can be easily converted to the discounted setting. Basically we have two chains that both produce a Bernoulli-distributed terminal reward, but their bifurcations occur at different time steps. If we calculate d(A,B)d(A,B) according to Eq.(3), clearly we have d(A,B)=0d(A,B)=0. However, if we perform dynamic programming according to Eq.(1), we see that d(C,D)>0d(C, D)>0 and d(C,E)>0d(C, E) >0, so it must follow that d(A,B)>0d(A,B)>0.

So what went wrong? (Last chance to make your own guess before the answer is revealed!)

Let’s examine the optimal trajectory coupling in Eq.(3), which is obviously

q({Xt}=ACF,{Yt}=BDH)=q({Xt}=ACG,{Yt}=BEI)=0.5.q(\{X_t\} = ACF, \{Y_t\} = BDH) = q(\{X_t\} = ACG, \{Y_t\} = BEI) = 0.5.

Now, the conditionals like q(FC)=0.5q(F\mid C) = 0.5 are consistent with the transition rule of each chain. However, when you do the dynamic programming step in Eq.(1) by hand, you realize that what you need is not q(FC)=0.5q(F \mid C) = 0.5, but q(FC,D)=q(FC,E)=0.5q(F\mid C, D) = q(F\mid C, E) = 0.5! So among my claims, Claim 2 is incorrect: not any trajectory coupling can be realized by a valid policy in the augmented MDP. This is because an arbitrary trajectory coupling qq only satisfies:

q(Xt+1Xt)=PX(Xt+1Xt),q(X_{t+1} \mid X_t) = P_X(X_{t+1} \mid X_t),

but for the qq to be valid in the augmented MDP (i.e., it can be induced as the trajectory distribution of some policy), we must have:

q(Xt+1Xt,Yt=y)=PX(Xt+1Xt), y.q(X_{t+1} \mid X_t, Y_t = y) = P_X(X_{t+1} \mid X_t), ~ \forall y.

In fact, the latter condition is discussed in Sec 2.1 of Calo et al., but without going through all of this I won’t be able to tell why conditioning on YtY_t is necessary. If I have to find an excuse for myself, I’d say that pΠ(PX(x),PY(y))p \in \Pi(P_X(\cdot\mid x), P_Y(\cdot\mid y)) in Eq.(1) is quite deceptive—it makes you feel that only PX(x)P_X(\cdot\mid x) needs to be respected, while the dependence on yy is secretly hidden on the LHS of the equation.

To conclude, the valid trajectory distributions in the augmented MDP is generally a small subset of all possible trajectory couplings Π(P{Xt}x,P{Yt}y)\Pi(P_{\{X_t\}}^x, P_{\{Y_t\}}^y). I want to develop more intuitions about this subset, and for now I only have some vague ideas like it looks “nested” as transition mass from (x,y)(x,y) cannot be coupled with that from a different pair of states (if this means anything). (*5) In any case, the weird implications that bothered me are all wrong, so I can finally make peace with myself. Phew.


Footnote Remarks

(*1) This was inspired by a conversation with Necmiye Ozay and her student Alperen Tercan at L4DC.

(*2) More generally, you don’t need to have a reward, but just some way to measure the “instantaneous” similarity between states.

(*3) This is also the intuition I use for bisimulation abstractions, a highly related topic that is very close to my heart and I teach in my RL courses (I might be one of the very few who does that). The difference and connection between bisimulation abstraction and metric is a topic for another day, but very briefly: for the former, you need to first specify an abstraction, then you can calculate the violation of the bisimulation criteria. Bisimulation metrics are more straightforward and generally tighter as a result: you directly compute d(,)d(\cdot, \cdot) from Eq.(1), and can decide how to aggregate states based off it.

(*4) One can extend bisimulation metrics to MDPs, where we need max over aAa\in\mathcal{A} on the RHS of Eq.(1). The corresponding “augmented MDP” will actually become a two-player zero-sum game, where the two players take actions in turns (like Chess or Go): the max player chooses an action aa, and the min player chooses pp afterwards. The max player here plays a (what I call) “synchronized” policy X×YA\mathcal{X}\times\mathcal{Y}\to\mathcal{A}, that is, choose an action for a (x,y)(x,y) pair that is supposedly “coupled” (in the sense they are drawn from a coupling created by the min player). In contrast, when we aggregate states according to bisimulation metrics (see (*3)), we may end up learning a policy that takes different actions for similar states; if you loosely think of these states as “coupled”, then the policy is not “synchronized” which can cause issues. In this sense, on-policy bisimulation metrics, which is basically bisimulation metrics for chains induced by an arbitrary fixed policy, is not necessarily “less pessimistic” than the maxa\max_a version, as two states close in the latter can have large distance in the former if the policy takes different actions in them.

(*5) I guess what I am looking for is some way to encode the subset in a clean(?) way. For example, a general trajectory coupling qq in Eq.(3) only needs to satisfy q({Xt})=P{Xt}x({Xt})q(\{X_t\}) = P_{\{X_t\}}^x(\{X_t\}) and similarly for YY, which provides some “trajectory-level” understanding (that is, if it were right) compared to the very “local” form of the transition coupling in Eq.(1). Now, Calo et al. has something really close (their Eq.(6-8)), which is an exact characterization of the valid occupancies in the augmented MDP. (So this entire blogpost is really just me learning their paper in my own way!) Still, I’d be curious to know if there is a way to characterize the valid distributions at the trajectory level.