The MCDist Mathematica package

On-the-fly exact computation of bisimilarity distances for Markov Chains

Authors: Giorgio Bacci, Giovanni Bacci, Kim G. Larsen, and Radu Mardare

In this tutorial we present the main features of the MCDist package. This Mathematica package implements an on-the-fly method for computing the bisimilarity pseudometric of Desharnais et al. [1] for Markov Chains. The algorithm implemented in this package is based on the technique recently proposed in [2].

Preliminaries

Markov Chains and Probabilistic Bisimulations

Definition (Markov Chain). A (discrete-time) Markov chain (MC) is a tuple M = (S, Σ, π, ℓ) consisting of a finite nonempty set S of states, a nonempty set A of labels, a transition probability function π : S × S → [0,1] such that, for arbitrary s ∈ S, MC Tutorial_1.gif, and a labelling function ℓ : S → Σ.

From a theoretical point of view, it is irrelevant whether the transition probability function of a given MC has rational values or not, However, for algorithmic purposes, here we assume that for arbitrary s,t ∈ S, π(s,t) ∈ Q ∩ [0,1].

Definition (Probabilistic Bisimulation). Let M = (S, Σ, π, ℓ) be an MC. An equivalence relation R ⊆ S × S is a probabilistic bisimulation if whenever (s,t) ∈ R, ℓ(s) = ℓ(t) and for each R-equivalence class C, MC Tutorial_2.gif.
Two states s,t ∈ S are bisimilar, written s ∼ t, if they are related by some probabilistic bisimulation.

Bisimilarity Pseudometric

The notion of equivalence can be relaxed by means of a pseudometric, which tells us how far apart from each other two elements are and whenever they are at zero distance they are equivalent. Desharnais et al. [1] defined a bisimilarity pseudometric that measures the behavioral similarity of two non-bisimilar MCs. In [3], van Breugel et al. characterized this pseudometric as the least fixed point of a operator on functions in S × S → [0,1].
Consider an MC M = (S, Σ, π, ℓ) and a discount factor λ ∈ (0,1]. The set S × S → [0,1] of [0,1]-valued maps on S × S equipped with the point-wise partial order defined by d ⊆ d’ ⇔ d(s,t) ≤ d’(s,t), for all s,t ∈ S.
We define a fixed point operator MC Tutorial_3.gif, for d : S × S → [0,1] and s,t ∈ S as

MC Tutorial_4.gif

Where MC Tutorial_5.gif denotes the optimal value of a Transportation Problem with marginals π(s,·) and π(t,·) and costs given by d

MC Tutorial_6.gif

MC Tutorial_7.gif is monotonic, thus, by Tarski’s fixed point theorem, its admits a least fixed point. This fixed point is the bisimilarity pseudometric.

Definition (Bisimilarity psudometric). Let M = (S, Σ, π, ℓ) be an MC and λ ∈ (0,1] be a discount factor, then the λ-discounted bisimilarity pseudometric for M, written MC Tutorial_8.gif, is the least fixed point of MC Tutorial_9.gif.

The pseudometric MC Tutorial_10.gif enjoys the property that two states are at distance zero if and only if they are bisimilar.

Getting started

The package can be loaded by setting as current directory that of the MCDist package, then using the commad << (Get) as follows

MC Tutorial_11.gif

Encoding and manipulating Markov Chains

An MC M = (S, Σ, π, ℓ) with MC Tutorial_12.gif is represented by a term of the form MC[tm, lbl] where
- tm is an n × n probability matrix such that tm[[i,j]] = MC Tutorial_13.gif, for all 1 ≤ i,j ≤ n,
- lbl is a list of strings (or integers) such that lbl[[i]] = ℓ(MC Tutorial_14.gif) for all 1 ≤ i ≤ n.
A state MC Tutorial_15.gif is implicitly represented by its index 1 ≤ i ≤ n.

For example we can encode an MC by defining tm and lbl as follows:

MC Tutorial_16.gif

Then, the MC can be displayed by means of its undelying graph. Labels are displayed using different colors.

MC Tutorial_17.gif

MC Tutorial_18.gif

Alternatively, one may use the functions MCtm to construct the transition matrix, listing only the values different from zero. Given the list of rules tmRules = { MC Tutorial_19.gif, the probabilty transition matrix induced by the probability transition function π may be constructed by calling MCtm[tmRules, n].

The list of rules may be given explicitly or using patterns. For example, the matrix tm defined above can be constructed as follows

MC Tutorial_20.gif

MC Tutorial_21.gif

MC Tutorial_22.gif

One can check that M is a well-formed MC by calling MCQ[M]

MC Tutorial_23.gif

MC Tutorial_24.gif

Given a sequence of Markov chains MC Tutorial_25.gif, one may construct their disjoint union using the function JoinMC

MC Tutorial_26.gif

MC Tutorial_27.gif

Run the on-the-fly algorithm

Given a MC M = MC[π,ℓ], a discount factor λ ∈ (0,1], and a list of pairs of states Q, the bisimilarity distance between the pairs in Q is computed by calling the function BDistMC as follows

MC Tutorial_28.gif

MC Tutorial_29.gif

The Verbose option may be used to trace the computation steps

MC Tutorial_30.gif

MC Tutorial_31.gif

MC Tutorial_32.gif

MC Tutorial_33.gif

MC Tutorial_34.gif

MC Tutorial_35.gif

MC Tutorial_36.gif

MC Tutorial_37.gif

MC Tutorial_38.gif

MC Tutorial_39.gif

MC Tutorial_40.gif

MC Tutorial_41.gif

MC Tutorial_42.gif

MC Tutorial_43.gif

MC Tutorial_44.gif

MC Tutorial_45.gif

MC Tutorial_46.gif

MC Tutorial_47.gif

MC Tutorial_48.gif

MC Tutorial_49.gif

MC Tutorial_50.gif

For computing the distance between all pair of states one can use as query list the alias All

MC Tutorial_51.gif

MC Tutorial_52.gif

The output is returned as a set of ArrayRules, so that one can easily transform it into a matrix using the function SparseArray

MC Tutorial_53.gif

MC Tutorial_54.gif

Bisimilarity Distance and Bisimilarity Quotient

Due to the fact that MC Tutorial_55.gif(s,t) equals zero if and only if the states s and t are bisimilar, the algorithm for computing MC Tutorial_56.gif can be used to compute the bisimilarity classes and the bisimilarity quotient for an MC.

Let M = (S, Σ, π, ℓ) be a (psedo-randomly generated) Markov chain with 50 states and outer-degree 2

MC Tutorial_57.gif

MC Tutorial_58.gif

The function BisimClassesMC[M] returns the set of bisimilarity classes of M, that is S/∼.

MC Tutorial_59.gif

MC Tutorial_60.gif

so that this can be used to construct an MC M’ bisimilar to M with all the states that are bisimilar in M lumped together. M’ is also known as the bisimilar quotient of M.

MC Tutorial_61.gif

MC Tutorial_62.gif

Examples

Example 1

Here we present an example taken from [2], which shows most of the features of the on-the-fly algorithm.
Consider the following MC:

MC Tutorial_63.gif

MC Tutorial_64.gif

Let us compute the undiscouted distance between the state MC Tutorial_65.gif and MC Tutorial_66.gif, namely MC Tutorial_67.gif

MC Tutorial_68.gif

MC Tutorial_69.gif

MC Tutorial_70.gif

MC Tutorial_71.gif

MC Tutorial_72.gif

MC Tutorial_73.gif

MC Tutorial_74.gif

MC Tutorial_75.gif

MC Tutorial_76.gif

MC Tutorial_77.gif

MC Tutorial_78.gif

MC Tutorial_79.gif

MC Tutorial_80.gif

MC Tutorial_81.gif

MC Tutorial_82.gif

MC Tutorial_83.gif

MC Tutorial_84.gif

MC Tutorial_85.gif

MC Tutorial_86.gif

MC Tutorial_87.gif

MC Tutorial_88.gif

Looking at the execution trace we see that during the computation of d(1,4) an over-approximation for the distance d(3,4) is computed.
This happens because we encountered a coupling that demands d(3,4) for computing an over-approximation of d(1,4).
However, the first improvement of the current coupling makes the computation of d(3,4) no more demanded for d(1,4), so that no further improvement on (3,4) is made.

The following execution trace shows that the exact computation of MC Tutorial_89.gif demands an exact computation of MC Tutorial_90.gif, MC Tutorial_91.gif and MC Tutorial_92.gif

MC Tutorial_93.gif

MC Tutorial_94.gif

MC Tutorial_95.gif

MC Tutorial_96.gif

MC Tutorial_97.gif

MC Tutorial_98.gif

MC Tutorial_99.gif

MC Tutorial_100.gif

MC Tutorial_101.gif

MC Tutorial_102.gif

MC Tutorial_103.gif

MC Tutorial_104.gif

MC Tutorial_105.gif

MC Tutorial_106.gif

MC Tutorial_107.gif

MC Tutorial_108.gif

MC Tutorial_109.gif

MC Tutorial_110.gif

MC Tutorial_111.gif

MC Tutorial_112.gif

MC Tutorial_113.gif

MC Tutorial_114.gif

MC Tutorial_115.gif

MC Tutorial_116.gif

MC Tutorial_117.gif

MC Tutorial_118.gif

MC Tutorial_119.gif

MC Tutorial_120.gif

MC Tutorial_121.gif

MC Tutorial_122.gif

MC Tutorial_123.gif

MC Tutorial_124.gif

MC Tutorial_125.gif

MC Tutorial_126.gif

MC Tutorial_127.gif

MC Tutorial_128.gif

MC Tutorial_129.gif

MC Tutorial_130.gif

MC Tutorial_131.gif

MC Tutorial_132.gif

One would claim that if we ask for the exact computation of d(3,4), d(1,4) and d(2,6) the computation will do the same steps made for d(3,4). However, the exact computation of d(1,4) does not need an exact computation of the remaining pairs.
Thus, considering the pair (1,4) before (3,4) will allow us to reduce the size of the linear equation systems computed for d(3,4).

MC Tutorial_133.gif

MC Tutorial_134.gif

Another way to reduce the exploration of the MC is to give estimates for some distances. Assume we have an over-approximation of the exact value for d(2,6). By using this information, we can further reduce the state space explotation of the MC. This is done using the Estimates option as follows:

MC Tutorial_135.gif

MC Tutorial_136.gif

MC Tutorial_137.gif

MC Tutorial_138.gif

MC Tutorial_139.gif

MC Tutorial_140.gif

MC Tutorial_141.gif

MC Tutorial_142.gif

MC Tutorial_143.gif

MC Tutorial_144.gif

MC Tutorial_145.gif

MC Tutorial_146.gif

MC Tutorial_147.gif

MC Tutorial_148.gif

MC Tutorial_149.gif

MC Tutorial_150.gif

MC Tutorial_151.gif

MC Tutorial_152.gif

MC Tutorial_153.gif

MC Tutorial_154.gif

MC Tutorial_155.gif

MC Tutorial_156.gif

Using the estimate MC Tutorial_157.gif for the distance d(2,6) we had considerably reduced the number of steps for computing a good over-approximation for d(3,4).

The Craps Game

Here we present two different MCs modeling slightly different versions for the “craps game” (these are taken from the book Principles of Model Checking, Examples 10.4 and 10.23). We compare the two MCs by means of the distance beteween their initial states.

MC Tutorial_158.gif

MC Tutorial_159.gif

MC Tutorial_160.gif

MC Tutorial_161.gif

MC Tutorial_162.gif

MC Tutorial_163.gif

MC Tutorial_164.gif

MC Tutorial_165.gif

Spikey Created with Wolfram Mathematica 9.0