SlowGuess/NeurIPS_2023_OCR huggingface dataset:
Stratis Markou*
em626@cam.ac.uk
Jose Miguel Hernandez Lobato
Relative entropy coding (REC) algorithms encode a sample from a target distribution  $Q$  using a proposal distribution  $P$  using as few bits as possible. Unlike entropy coding, REC does not assume discrete distributions or require quantisation. As such, it can be naturally integrated into communication pipelines such as learnt compression and differentially private federated learning. Unfortunately, despite their practical benefits, REC algorithms have not seen widespread application, due to their prohibitively slow runtimes or restrictive assumptions. In this paper, we make progress towards addressing these issues. We introduce Greedy Rejection Coding (GRC), which generalises the rejection based-algorithm of Harsha et al. (2007) to arbitrary probability spaces and partitioning schemes. We first show that GRC terminates almost surely and returns unbiased samples from  $Q$ , after which we focus on two of its variants: GRCS and GRCD. We show that for continuous  $Q$  and  $P$  over  $\mathbb{R}$  with unimodal density ratio  $dQ / dP$ , the expected runtime of GRCS is upper bounded by  $\beta D_{\mathrm{KL}}[Q\| P] + \mathcal{O}(1)$  where  $\beta \approx 4.82$ , and its expected codelength is optimal. This makes GRCS the first REC algorithm with guaranteed optimal runtime for this class of distributions, up to the multiplicative constant  $\beta$ . This significantly improves upon the previous state-of-the-art method, A* coding (Flamich et al., 2022). Under the same assumptions, we experimentally observe and conjecture that the expected runtime and codelength of GRCD are upper bounded by  $D_{\mathrm{KL}}[Q\| P] + \mathcal{O}(1)$ . Finally, we evaluate GRC in a variational autoencoder-based compression pipeline on MNIST, and show that a modified ELBO and an index-compression method can further improve compression efficiency.
1 Introduction and motivation
Over the past decade, the development of excellent deep generative models (DGMs) such as variational autoencoders (VAEs; Vahdat & Kautz, 2020; Child, 2020), normalising flows (Kingma et al., 2016) and diffusion models (Ho et al., 2020) demonstrated great promise in leveraging machine learning (ML) for data compression. Many recent learnt compression approaches have significantly outperformed the best classical hand-crafted CODECs across a range of domains, such as lossless and lossy image or video compression (Zhang et al., 2021; Mentzer et al., 2020, 2022).
Transform coding. Most learnt compression algorithms are transform coding methods: they first map a datum to a latent variable using a learnt transform, and encode it using entropy coding (Balle et al., 2020). Entropy coding assumes discrete variables while the latent variables in DGMs are typically continuous, so most transform coding methods quantize the latent variable prior to entropy coding. Unfortunately, quantization has zero derivative almost everywhere. Thus, state-of-the-art DGMs trained with gradient-based optimisation must resort to some continuous approximation to
Figure 1: An illustration of the relations between the variants of GRC, introduced in this work, and the variants of  $\mathrm{A}^*$  coding. Algorithms in purple are introduced in this work. The algorithms of Harsha et al. (2007) and Li & El Gamal (2018) are equivalent to GRCG and Global  $\mathrm{A}^*$  coding respectively.
quantisation during training and switch to hard quantisation for compression. Previous works have argued that using quantisation within learnt compression is restrictive or otherwise harmful, and that a method which naturally interfaces with continuous latent variables is needed (Havasi et al., 2018; Flamich et al., 2020; Theis & Agustsson, 2021; Flamich et al., 2022).
Relative entropy coding. In this paper, we study an alternative to quantizing and entropy coding the latent representations: we consider randomly perturbing them and encoding the perturbed representations instead. This problem is called relative entropy coding (REC; Havasi et al., 2018; Flamich et al., 2020), and formally, it requires that we encode a random sample from a target  $Q$  (the distribution of the perturbed latent representations) using a coding distribution  $P$  and some publicly available randomness  $S$  (e.g. a publicly shared PRNG seed). Remarkably, there exist algorithms which encode a target sample using only approximately  $D_{\mathrm{KL}}[Q||P]$ -many bits on average and, notably, allow  $Q$  and  $P$  to be continuous (Li & El Gamal, 2018; Flamich et al., 2022; Flamich & Theis, 2023; Flamich, 2023). Thus, we can forgo quantization in our compression pipeline and learn our transforms end-to-end using gradient descent and the reparameterization trick. Moreover, REC has fundamental advantages over quantization in lossy compression with realism constraints (Theis & Agustsson, 2021; Theis et al., 2022) and has a range of other applications, such as differentially private compression for federated learning (Shah et al., 2022; Shahmiri et al., 2023) and compression with Bayesian implicit neural representations (Guo et al., 2023; He et al., 2023).
Limitations of existing REC algorithms. While algorithms for solving REC problems already exist, most of them suffer from limitations that render them impractical. These limitations fall into three categories: 1) prohibitively long runtimes, 2) overly restrictive assumptions, or 3) excessive coding overheads. In this work, we study and make progress towards addressing these limitations.
General-purpose REC algorithms. The minimal assumption made by any REC algorithm on  $Q$  and  $P$  is that  $D_{\mathrm{KL}}[Q\|P] < \infty$ , which ensures that it produces a finite code. However, unfortunately, Agustsson & Theis (2020) showed that without additional assumptions on  $Q$  and  $P$ , the expected runtime of any algorithm that simulates a  $Q$ -distributed sample using  $P$  must scale at least exponentially in  $D_{\mathrm{KL}}[Q\|P]$  in the worst case, which is impractically slow for most practical problems. This result holds even in the approximate sense, i.e., the exponential runtime persists even if the algorithm simulates a  $\tilde{Q}$ -distributed sample with  $||Q - \tilde{Q}||_{TV} < 1/12$ .
Faster algorithms with additional assumptions. On the other hand, there exist algorithms which make additional assumptions in order to achieve faster runtimes. For example, dithered quantization (Ziv 1985; Agustsson & Theis 2020) achieves an expected runtime of  $D_{\mathrm{KL}}[Q \| P]$ , which is optimal since any REC algorithm has an expected runtime of at least  $D_{\mathrm{KL}}[Q \| P]$ . However, it requires both  $Q$  and  $P$  to be uniform distributions, which limits its applicability. Recently, Flamich et al. (2022) introduced  $\mathbf{A}^*$  coding, an algorithm based on  $\mathbf{A}^*$  sampling (Maddison et al. 2014) which, under assumptions satisfied in practice, achieves an expected runtime of  $D_{\infty}[Q \| P]$ . Unfortunately, this runtime is suboptimal and is not always practically fast, since  $D_{\infty}[Q \| P]$  can be arbitrarily large for fixed  $D_{\mathrm{KL}}[Q \| P]$ . Further, as discussed in Flamich et al. (2022) this runtime also comes at a cost of an additional, substantial, overhead in codelength, which limits the applicability of  $\mathbf{A}^*$  coding.
Our contributions. In this work, we address some of these limitations. First, we propose greedy rejection coding (GRC), a REC algorithm based on rejection sampling. Then, inspired by A* coding (Flamich et al., 2022), we develop GRCS and GRCD, two variants of GRC that partition the sample space to dramatically speed up termination. Figure I illustrates the relations between GRC and its variants with existing algorithms. We analyze the correctness and the runtime of these algorithms and, in particular, prove that GRCS has an optimal codelength and order-optimal runtime on a wide class of one-dimensional problems. In more detail, our contributions are
- We introduce Greedy Rejection Coding (GRC), which generalises the algorithm of Harsha et al. (2007) to arbitrary probability spaces and partitioning schemes. We prove that under mild conditions, GRC terminates almost surely and returns an unbiased sample from  $Q$ .
- We introduce GRCS and GRCD, two variants of GRC for continuous distributions over  $\mathbb{R}$ , which adaptively partition the sample space to dramatically improve their convergence, inspired by AS* and AD* coding (Flamich et al., 2022), respectively.
- We prove that whenever  $dQ / dP$  is unimodal, the expected runtime and codelength of GRCS is  $\mathcal{O}(D_{\mathrm{KL}}[Q\| P])$ . This significantly improves upon the  $\mathcal{O}(D_{\infty}[Q\| P])$  runtime of  $\mathrm{AS}^*$  coding, which is always larger than that of GRCS. This runtime is order-optimal, while making far milder assumptions than, for example, dithered quantization.
- We provide clear experimental evidence for and conjecture that whenever  $dQ / dP$  is unimodal, the expected runtime and codelength of GRCD are  $D_{\mathrm{KL}}[Q\| P]$ . This also significantly improves over the  $D_{\infty}[Q\| P]$  empirically observed runtime of  $\mathrm{AD}^*$  coding.
- We implement a compression pipeline with VAEs, using GRC to compress MNIST images. We propose a modified ELBO objective and show that this, together with a practical method for compressing the indices returned by GRC further improve compression efficiency.
Relative entropy coding. First, we define REC algorithms. Definition  $\boxed{1}$  is stricter than the one given by Flamich et al. (2022), as it has a stronger condition on the expected codelength of the algorithm. In this paper, all logarithms are base 2, and all divergences are measured in bits.
Definition 1 (REC algorithm). Let  $(\mathcal{X},\Sigma)$  be a measurable space, let  $\mathcal{R}$  be a set of pairs of distributions  $(Q,P)$  over  $(\mathcal{X},\Sigma)$  such that  $D_{\mathrm{KL}}[Q\| P] < \infty$  and  $\mathcal{P}$  be the set of all distributions  $P$  such that  $(Q,P)\in \mathcal{R}$  for some distribution  $Q$ . Let  $S = (S_{1},S_{2},\ldots)$  be a publicly available sequence of independent and fair coin tosses, with corresponding probability space  $(S,\mathcal{F},\mathbb{P})$  and let  $\mathcal{C} = \{0,1\}^*$  be the set of all finite binary sequences. A REC algorithm is a pair of functions  $\operatorname{enc}:\mathcal{R}\times \mathcal{S}\to \mathcal{C}$  and  $\operatorname{dec}:\mathcal{C}\times \mathcal{P}\times \mathcal{S}\to \mathcal{X}$ , such that for each  $(Q,P)\in \mathcal{R}$  and  $S\sim \mathbb{P}$ , the outputs of the encoder  $C = \operatorname{enc}(Q,P,S)$  and the decoder  $X = \operatorname{dec}(P,C,S)$  satisfy
$$
X \sim Q \quad a n d \quad \mathbb {E} _ {S} [ | C | ] = D _ {\mathrm {K L}} [ Q \| P ] + \mathcal {O} (\log (D _ {\mathrm {K L}} [ Q \| P ] + 1)), \tag {1}
$$
where  $|C|$  is the length of the string  $C$ . We call enc the encoder and dec the decoder.
In practice,  $S$  is implemented with a pseudo-random number generator (PRNG) with a public seed. In the remainder of this section, we discuss relevant REC algorithms, building up to GRC in section 3.
Existing REC algorithms. While there are many REC algorithms already, they suffer from various issues limiting their applicability in practice. Our proposed algorithm, Greedy Rejection Coding (GRC), is based on and generalises Harsha et al. (2007)'s REJ-SAMPLER, by drawing inspiration from  $\mathrm{A}^*$  coding (Flamich et al., 2022). Specifically,  $\mathrm{A}^*$  coding generalises Li & El Gamal (2018)'s Poisson functional representation by introducing a partitioning scheme to speed up the algorithm's termination. In an analogous fashion, GRC generalises Harsha et al. (2007) by also introducing partitioning schemes to speed up termination and achieve optimal runtimes. Here we discuss relevant algorithms, building up to GRC in section 3
REC with rejection sampling. In this work, we generalize the rejection sampler introduced by Harsha et al. (2007). While they presented the algorithm for discrete  $Q$  and  $P$  originally, we generalise it to arbitrary probability spaces in this section and further extend it to arbitrary partitioning schemes (see definition 5) in section 3. The generalisation to arbitrary probability spaces relies on
Figure 2: Example run of Harsha et al. (2007), for a pair of continuous  $Q$  and  $P$  over  $[0,1]$ . The green and red regions correspond to acceptance and rejection regions at each step. Here the algorithm rejects the first two samples and accepts the third one, terminating at the third step.
the Radon-Nikodym derivative  $dQ / dP$ , which is guaranteed to exist since  $Q \ll P$  by definition. When  $Q$  and  $P$  both have densities,  $dQ / dP$  coincides with the density ratio.
At each step, the algorithm draws a sample from  $P$  and performs an accept-reject step, as illustrated in fig. 2 If it rejects the sample, it rules out part of  $Q$  corresponding to the acceptance region, adjusts the proposal to account for the removed mass, and repeats until acceptance. More formally, define  $T_0$  to be the zero-measure on  $\mathcal{X}$ , and recursively for  $d \in \mathbb{N}$ , set:
$$
T _ {d + 1} (S) \stackrel {\text {d e f}} {=} T _ {d} (S) + A _ {d + 1} (S), \quad A _ {d + 1} (S) \stackrel {\text {d e f}} {=} \int_ {S} \alpha_ {d + 1} (x) d P (x), \tag {2}
$$
$$
t _ {d} (x) \stackrel {\text {d e f}} {=} \frac {d T _ {d}}{d P} (x), \quad \alpha_ {d + 1} (x) \stackrel {\text {d e f}} {=} \min  \left\{\frac {d Q}{d P} (x) - t _ {d} (x), (1 - T _ {d} (\mathcal {X})) \right\}, \tag {3}
$$
$$
X _ {d} \sim P, U _ {d} \sim \operatorname {U n i f o r m} (0, 1) \quad \beta_ {d + 1} (x) \stackrel {\text {d e f}} {=} \frac {\alpha_ {d + 1} (x)}{1 - T _ {d} (\mathcal {X})}, \tag {4}
$$
for all  $x \in \mathcal{X}, S \in \Sigma$ . The algorithm terminates at the first occurrence of  $U_d \leq \beta_{d+1}(X_d)$ . The  $T_d$  measure corresponds to the mass that has been ruled off up to and including the  $d^{\text{th}}$  rejection:  $T_1(\mathcal{X}), T_2(\mathcal{X})$  and  $T_3(\mathcal{X})$  are the sums of the blue and green masses in the left, middle and right plots of fig. ② respectively. The  $A_d$  measure corresponds to the acceptance mass at the  $d^{\text{th}}$  step:  $A_1(\mathcal{X}), A_2(\mathcal{X})$  and  $A_3(\mathcal{X})$  are the masses of the green regions in the left, middle and right plots of fig. ② respectively. Lastly,  $t_d, \alpha_d$  are the Radon-Nikodym derivatives i.e., roughly speaking, the densities, of  $T_d, A_d$  with respect to  $P$ , and  $\beta_{d+1}(X_d)$  is the probability of accepting the sample  $X_d$ .
To encode the accepted sample  $X$ , enc outputs the number of rejections  $C$  that occurred before acceptance. To decode  $X$  from  $C$ , dec draws  $C + 1$  samples from  $P$ , using the same PRNG seed as the encoder, and returns the last sample. While this algorithm is elegantly simple and achieves optimal codelengths, Flamich & Theis (2023) showed its expected runtime is  $2^{D_{\infty}[Q]}$ , where  $\bar{D}_{\infty}[Q]$  is  $\sup_{x \in \mathcal{X}} \log(dQ/dP)(x)$  is the Rényi  $\infty$ -divergence. Unfortunately, this runtime is prohibitively slow in most practical cases.
REC with Poisson & Gumbel processes. Li & El Gamal (2018) introduced a REC algorithm based on Poisson processes, referred to as Poisson Functional Representation (PFR). PFR assumes that  $dQ / dP$  is bounded above, and relies on the fact that (Kingman, 1992), if  $T_{n}$  are the ordered arrival times of a homogeneous Poisson process on  $\mathbb{R}^+$  and  $\overline{X}_n\sim P$ , then
$$
N \stackrel {\text {d e f}} {=} \operatorname * {a r g} _ {n \in \mathbb {N}} \left\{T _ {n} \frac {d P}{d Q} \left(X _ {n}\right) \right\} \Rightarrow X _ {N} \sim Q. \tag {5}
$$
Therefore, PFR casts the REC problem into an optimisation, or search, problem, which can be solved in finite time almost surely. The PFR encoder draws pairs of samples  $T_{n}$ ,  $X_{n}$ , until it solves the search problem in eq. (5), and returns  $X = X_{N}$ ,  $C = N - 1$ . The decoder can recover  $X_{N}$  from  $(P,C,S)$ , by drawing  $N$  samples from  $P$ , using the same random seed, and keeping the last sample. While, like the algorithm of Harsha et al. (2007), PFR is elegantly simple and achieves optimal codelengths, its expected runtime is also  $2^{D_{\infty}[Q\|P]}$  (Maddison 2016).
Fast REC requires additional assumptions. These algorithms' slow runtimes are perhaps unsurprising considering Agustsson & Theis's result, which shows under the computational hardness assumption  $\mathrm{RP} \neq \mathrm{NP}$  that without making additional assumptions on  $Q$  and  $P$ , there is no REC
Algorithm 1 [Harsha et al.'s rejection algorithm; equivalent to GRC with a global partition
Require: Target  $Q$  ,proposal  $P$  ,space  $\mathcal{X}$    
1:  $d\gets 0,T_0\gets 0$    
2:   
3: while True do   
4:  $X_{d + 1}\sim P$    
5:  $U_{d + 1}\sim$  Uniform(0,1)   
6:  $\beta_{d + 1}\leftarrow$  AcceptProb  $(Q,P,X_{d + 1},T_d)$    
7: if  $U_{d + 1}\leq \beta_{d + 1}$  then   
8: return  $X_{d + 1},d$    
9: end if   
10:   
11:   
12:   
13:  $T_{d + 1}\gets$  RuledOutMass  $(Q,P,T_d)$    
14:  $d\gets d + 1$    
15: end while
Algorithm 2 GRC with partition process  $Z$ ; differences to Harsha et al.'s algorithm shown in green
Require: Target  $Q$  ,proposal  $P$  ,space  $\mathcal{X}$  ,partition  $Z$    
1:  $d\gets 0,T_0\gets 0$    
2:  $I_0\gets 1,S_1\gets \mathcal{X}$    
3: while True do   
4:  $X_{I_d}\sim P|_{S_d} / P(S_d)$    
5:  $U_{I_d}\sim$  Uniform(0,1)   
6:  $\beta_{I_d}\leftarrow$  AcceptProb  $(Q,P,X_{I_d},T_d)$    
7: if  $U_{I_d}\leq \beta_{d + 1}$  or  $d = D_{\mathrm{max}}$  then   
8: return  $X_{I_d},I_d$    
9: end if   
10:  $p\gets$  PartitionProb  $(Q,P,T_d,Z_{2d},Z_{2d + 1})$    
11:  $b_{d}\sim$  Bernoulli(p)   
12:  $I_{d + 1}\gets 2I_d + b_d$  and  $S_{d + 1}\gets Z_{I_{d + 1}}$    
13:  $T_{d + 1}\gets$  RuledOutMass  $(Q,P,T_d,S_{d + 1})$    
14:  $d\gets d + 1$    
15: end while
algorithm whose expected runtime scales polynomially in  $D_{\mathrm{KL}}[Q \| P]$ . Therefore, in order to achieve faster runtimes, a REC algorithm must make additional assumptions on  $Q$  and  $P$ .
$\mathbf{A}^*$  coding. To this end, Flamich et al. (2022) proposed: (1) a set of appropriate assumptions which are satisfied by many deep latent variable models in practice and (2) a REC algorithm, referred to as  $\mathbf{A}^*$  coding, which leverages these assumptions to achieve a substantial speed-up over existing methods. In particular,  $\mathbf{A}^*$  coding generalizes PFR by introducing a partitioning scheme, which splits the sample space  $\mathcal{X}$  in nested partitioning subsets, to speed up the solution of eq. (5). Drawing inspiration from this, our proposed algorithm generalises eqs. (2) to (4) in an analogous manner (see fig. 1), introducing partitioning processes (definition 2) to speed up the algorithm's termination.
Definition 2 (Partitioning process). A partitioning process is a process  $Z: \mathbb{N}^{+} \to \Sigma$  such that
$$
Z _ {1} = \mathcal {X}, Z _ {2 n} \cap Z _ {2 n + 1} = \emptyset , Z _ {2 n} \cup Z _ {2 n + 1} = Z _ {n}. \tag {6}
$$
In other words, a partitioning process  $Z$  is an infinite binary tree-structured process, where the root node is  $Z_{1} = \mathcal{X}$  and has index 1, and each node  $Z_{n}$  with index  $n$  is partitioned by its two children nodes  $Z_{2n}, Z_{2n+1}$  with indices  $2n$  and  $2n+1$ . We refer to this system of indexing as heap indexing. In section 3 we present specific choices of partitioning processes which dramatically speed up GRC.
Greedy Poisson Rejection Sampling. Contemporary to our work, Flamich (2023) introduces a rejection sampler based on Poisson processes, called Greedy Poisson Rejection Sampling (GPRS), which can be used as a REC algorithm. Similar to GRC and A* coding, GPRS partitions the sample space to speed up the convergence to the accepted sample. Furthermore, a variant of GPRS also achieves order-optimal runtime for one-dimensional distribution pairs with a unimodal density ratio. However, the construction of their method is significantly different from ours, relying entirely on Poisson processes. Moreover, GPRS requires numerically solving a certain ODE, while our method does not, making it potentially more favourable in practice. We believe establishing a closer connection between GPRS and GRC is a promising future research direction.
3 Greedy Rejection Coding
Generalising Harsha et al. (2007). In this section we introduce Greedy Rejection Coding (GRC; definition 5), which generalises the algorithm of Harsha et al. (2007) in two ways. First, GRC can be used with distributions over arbitrary probability spaces. Therefore, it is applicable to arbitrary REC problems, including REC with continuous distributions. Second, similar to  $\mathbf{A}^*$  coding, GRC can be combined with arbitrary partitioning processes, allowing it to achieve optimal runtimes given additional assumptions on the REC problem, and an appropriate choice of partitioning process.
(a) Sample & accept or reject
(b) Partition & sample  $b_{1} \in \{0, 1\}$
(d) Sample & accept or reject
Figure 3: Illustrations of the two variants of GRC considered in this work. (a) to (c) show GRC with the on-sample partitioning process (GRCS). (d) to (f) show GRC with the dyadic partition process (GRCD). GRC interleaves accept-reject steps with partitioning steps. In the former, it draws a sample and either accepts or rejects it. In the latter, it partitions the sample space and randomly chooses one of the partitions, ruling out large parts of the sample space and speeding up termination.
(e) Partition & sample  $b_{1} \in \{0, 1\}$
(c) Sample & accept or reject
(f) Sample & accept or reject
3.1 Algorithm definition
Overview. Before specifying GRC, we summarise its operation with an accompanying illustration. On a high level, GRC interleaves accept-reject steps with partitioning steps, where the latter are determined by a partitioning process. Specifically, consider the example in figs. 3d to 3f, where  $Q$  and  $P$  are distributions over  $\mathcal{X} = [0,1]$ , and  $Z$  is the partitioning process defined by
$$
Z _ {n} = [ L, R ] \Longrightarrow Z _ {2 n} = [ L, M), Z _ {2 n + 1} = [ M, R ], \text {w h e r e} M = (L + R) / 2. \tag {7}
$$
In each step  $d = 1,2,\ldots$ , GRC maintains a heap index  $I_{d}$  of an infinite binary tree, and an active subset  $S_{d} = Z_{I_{d}} \subseteq \mathcal{X}$  of the sample space, initialised as  $I_0 = 1$  and  $S_{1} = Z_{1} = \mathcal{X}$  respectively.
Accept-reject step. In each step, GRC draws a sample from the restriction of  $P$  to  $S_{d}$ , namely  $P|_{S_d} / P(S_d)$ , and either accepts or rejects it. If the sample is accepted, the algorithm terminates. Otherwise, GRC performs a partitioning step as shown in fig. 3d
Partitioning step. In each partitioning step, GRC partitions  $S_{d} = Z_{I_{d}}$  into  $Z_{2I_{d}}$  and  $Z_{2I_{d} + 1}$ , as specified by the partitioning process  $Z$ . It then samples a Bernoulli random variable  $b_{d}$ , whose outcomes have probabilities proportional to the mass of  $Q$  which has not been accounted for, up to and including step  $d$ , within the partitions  $Z_{2I_{d}}$  and  $Z_{2I_{d} + 1}$  respectively. In fig. 3e, these two masses correspond to the purple and orange areas, and the algorithm has sampled  $b_{d} = 1$ . Last, GRC updates the heap index to  $I_{d + 1} = 2I_{d} + b_{d}$  and the active subset to  $S_{d + 1} = Z_{I_{d + 1}}$ . GRC proceeds by interleaving accept-reject and partitioning steps until an acceptance occurs.
Algorithm specification. The aforementioned algorithm can be formalised in terms of probability measures over arbitrary spaces and arbitrary partitioning processes. Above, algorithms 1 and 2 describe Harsha et al.'s rejection sampler and our generalisation of it, respectively. For the sake of keeping the exposition lightweight, we defer the formal measure-theoretic definition of GRC to the appendix (see definition 5 in appendix A.1), and refer to algorithm 2 as a working definition here.