Let $\mathsf{Stoch}$ denote the Kleisli category of the Giry monad. That is, $\mathsf{Stoch}$ is a category whose objects are measurable spaces and for which a morphism $f\in\mathsf{Stoch}(X,Y)$ is a map sending points in $X$ to probability measures on $Y$; see [nLab: Giry monad](https://ncatlab.org/nlab/show/Giry+monad) for details.


Let $\mathsf{Met}$ denote the symmetric monoidal category of metric spaces $(X,d)$ and *short* maps (functions $f\colon X\to Y$ satisfying $d(x\_1,x\_2)\geq d(fx\_1,fx\_2)$ for all $x\_1,x\_2\in X$).


**Question:** Is there a way to enrich $\mathsf{Stoch}$ in $\mathsf{Met}$?


In other words, I'm looking for a way to endow each hom-set $\mathsf{Stoch}(X,Y)$ with a metric space structure in such a way that the composition operation is short:
$$
d(f\_1,f\_2)+d(g\_1,g\_2) \geq d(g\_1\circ f\_1, g\_2\circ f\_2)
$$


The upshot would be that when working in $\mathsf{Stoch}$, diagrams would not simply either commute or not commute; they would commute up to some distance, and this distance would behave sensibly under "diagram chasing".



Is Stoch enriched in Met?
A way to enrich $\mathsf{Stoch}$ could be as follows.


Let $X$ be a measurable space and let $PX$ be the space of probability measures over $X$. We can equip $PX$ with the [total variational distance](https://en.wikipedia.org/wiki/Total_variation_distance_of_probability_measures), which is given by the following equivalent forms.
$$
d(p,q) \;=\; \sup\_{A\subseteq X} |p(A) - q(A)| \;=\; \sup\_{f:X\to[0,1]} \left| \int\_X f\, dp - \int\_X f\; dq \right| .
$$
Above, and in what follows, the subsets $A\subseteq X$ and the functions $f:X\to\Bbb{R}$ are assumed measurable.


Now first of all let $f:X \to Y$ be a measurable (deterministic) function.
Denote by $f\_\*:PX\to PY$ the [pushforward of measures](https://ncatlab.org/nlab/show/pushforward+measure) (for category theorists, the action of the functor $P$ on the morphisms).
We have
\begin{align\*}
d( f\_\*p, f\_\*q ) \;&=\; \sup\_{B\subseteq Y} |f\_\*p(B) - f\_\*q(B)| \\\
 \;&=\; \sup\_{B\subseteq Y} |p(f^{-1}(B)) - q(f^{-1}(B))| \\\
 \;&\le\; \sup\_{A\subseteq X} |p(A) - q(A)| \\\
 \;&=\; d( p, q ) ,
\end{align\*}
which means that $f\_\*:PX\to PY$ is short for the metric just defined. This will be of use later.


We can equip now the sets $\mathsf{Stoch}(X,Y)$ with the "product" or "$L^\infty$" metric construction induced by the one on $PY$, as follows. We use the following notation, a stochastic map $k:X\to PY$ evaluated at a point $x\in X$ gives the measure $k\_x\in PY$. Now for stochastic maps $k,h:X\to PY$, we set
$$
d(k,h) \;=\; \sup\_{x\in X} d\big( k\_x, h\_y \big) .
$$
This number is bounded by $1$. (Thanks to Martin Hairer for pointing this out, see the comments.)


We now have to prove that the (Kleisli) composition of $\mathsf{Stoch}$ is short. Given $h:X \to PY$ and $l: Y \to PZ$, their [Kleisli composition](https://ncatlab.org/nlab/show/Kleisli+category#in_terms_of_kleisli_morphisms), which we denote by $lh$, is given by the [Chapman-Kolmogorov formula](https://en.wikipedia.org/wiki/Chapman%E2%80%93Kolmogorov_equation). Explicitly, for every measurable $C \subseteq Z$, we have
$$
lh\_x(C) \;=\; \int\_{PZ} q(C) \,d(l\_\*h\_x)(q) \;=\; \int\_{Y} l\_y(C) \,dh\_x(y) .
$$


Now, to see that postcomposition is short, let $h,k:X \to PY$ and $l: Y \to PZ$. We have
\begin{align\*}
d( lh, lk ) \;&=\; \sup\_{x\in X} \sup\_{C\subseteq Z} | lh\_x(C) - lk\_x(C) | \\\
 \;&=\; \sup\_{x\in X} \sup\_{C\subseteq Z} \left| \int\_{PZ} q(C) \,d(l\_\*h\_x)(q) - \int\_{PZ} q(C) \,d(l\_\*k\_x)(q) \right| \\\
 \;&\le\; \sup\_{x\in X} d\big( l\_\*h\_x , l\_\*k\_x \big) \\\
 \;&\le\; \sup\_{x\in X} d( h\_x , k\_x ) \\\
 \;&=\; d( h, k ) .
\end{align\*}
(We used the fact that the evaluation map $PX\to \Bbb{R}$ given by $p\mapsto p(A)$ for a measurable set $A\subseteq X$ is measurable for the $\sigma$-algebra on $PX$ in the construction of the [Giry monad](https://ncatlab.org/nlab/show/Giry+monad).)


To see that precomposition is short, let also $g: W \to PX$. Then
\begin{align\*}
d( hg, kg ) \;&=\; \sup\_{w\in W} \sup\_{B\subseteq Y} | hg\_w(B) - kg\_w(B) | \\\
 \;&=\; \sup\_{w\in W} \sup\_{B\subseteq Y} \left| \int\_{X} h\_x(B) \,dg\_w(x) - \int\_{X} k\_x(B) \,dg\_w(x) \right| \\\
 \;&\le\; \sup\_{w\in W} \int\_{X} \sup\_{B\subseteq Y} | h\_x(B) - k\_x(B) | \,d(g\_w)(x) \\\
 \;&=\; \sup\_{w\in W} \int\_{X} d( h\_x, k\_x ) \,d(g\_w)(x) \\\
 \;&\le\; d( h\_x, k\_x ) .
\end{align\*}


Consider now the set $\mathsf{Stoch}(X,Y)\times\mathsf{Stoch}(Y,Z)$. We can equip it either with the metric
$$
d \big( (h\_1,l\_1), (h\_2,l\_2) \big) \;=\; \max\{ d(h\_1,h\_2), d(l\_1,l\_2) \},
$$
which corresponds to the metric of the [cartesian (categorical) product](https://ncatlab.org/nlab/show/cartesian+product) of $\mathsf{Met}$, or with the metric
$$
d \big( (h\_1,l\_1), (h\_2,l\_2) \big) \;=\; d(h\_1,h\_2) + d(l\_1,l\_2) ,
$$
which is the metric of the [closed monoidal product](https://ncatlab.org/nlab/show/closed+monoidal+category) of $\mathsf{Met}$ as an (i.e. exhibiting a [hom-tensor adjunction](https://en.wikipedia.org/wiki/Tensor-hom_adjunction)).


For either choice, the map $\circ: \mathsf{Stoch}(X,Y)\times\mathsf{Stoch}(Y,Z) \to \mathsf{Stoch}(X,Z)$ given by composition is short.
This gives the desired enrichment.


By the way, if we want talk about diagrams "commuting up to $\varepsilon$", then by definition of the metric, $\varepsilon$ has to be a *uniform* bound. For example, for the diagram
$\require{AMScd}$
\begin{CD}
 A @>f>> B\\
 @V m V V @VV n V\\
 C @>>g> D
\end{CD}
to commute up to $\varepsilon$, in the sense that $d(n\circ f,g\circ m)\lt\varepsilon$, we need that
$$
\sup\_{a\in A} d\big(n(f(a)),g(m(a))\big) \;\lt\;\varepsilon,
$$
where the distance above is the one of $D$. For that to happen, $\varepsilon$ needs to be independent of $a$, which is quite a strong condition in practice (if $A$ is not compact).


