# Denoising Diffusion Models on Model-Based Latent Space
## 3 Proposed Method
### Latent-Space Encoding
#### 3.1.1 Vector Quantization  
Vector quantization [17; 18] is a popular technique in the domain of data compression and signal processing. Its fundamental idea is the approximation of the entire data space \(X\) with a finite subset of representative vectors \(\mathcal{C}\). This process not only reduces the cardinality of the space but also enables a concise and efficient representation by assigning a codeword \(c_{i}\) to each element \(x\in X\) of the subset. Conveniently, each entry \(c_{i}\) can be uniquely represented by its index \(i\in\mathcal{I}\), with \(\mathcal{I}:=\{1,\ldots,|\mathcal{C}|\}\).  
Formally, this procedure is described by a quantizer defined by an encoder function \(E(x)\) and a decoder function \(D(i)\)  
\[q\colon X \longrightarrow\mathcal{C} \tag{7}\] \[x \longmapsto c=q(x)=D(E(x)) \tag{8}\]  
The encoder function, \(E\colon X\longrightarrow\mathcal{I}\), maps each element of the space into its compact code representation \(E(x)=i\in\mathcal{I}\). On the other hand, the decoder function \(D\colon\mathcal{I}\longrightarrow\mathcal{C}\) maps the index \(i\in\mathcal{I}\) back to the representative vector \(c_{i}\). The representative vector \(c_{i}\) is chosen by definition in order to minimize the distortion with respect to \(x\); hence, the encoder can be defined as  
\[E(x)=i\Longleftrightarrow\|x-c_{i}\|_{2}^{2}=\min_{c}\|x-c\|_{2}^{2} \tag{9}\]  
From Equation (9), the lossy nature of VQ is clear, since the encoding process implies an approximation error \(e\), or \(c_{i}=x+e\). For convenience, \(\mathcal{C}\) is referred to as the _codebook_, and its elements \(c_{i}\) as _codewords_, with \(i\) being the _code_ associated to \(x\). For the scope of  
Figure 1: Image compression scheme.  
this work, we focus on fixed-rate quantizers, where each code is represented with the same number of bits; hence, the number of bits required to approximate \(x\) with \(i\) using a codebook \(\mathcal{C}\) is \(b_{\mathcal{C}}=log_{2}(|\mathcal{C}|)\), defined as _bitrate_ of \(q\). When \(x\in\mathbb{R}^{n}\) with \(n>>b_{\mathcal{C}}\), it makes VQ a very powerful compressor.  
Defining an optimal quantizer is not straightforward, as it depends on the desired tradeoff between reconstruction error and compression rate, which is strictly dependent on \(|\mathcal{C}|\). In the simple case where \(X\) is defined as a finite subset of \(\mathbb{R}^{n}\) and \(|\mathcal{C}|\) is fixed beforehand, recalling Equation (9), the formulation for the error introduced by encoding \(X\) with \(q\) simplifies to  
\[MSE(q)=\sum_{x\in X}\|x-q(x)\|_{2}^{2}=\sum_{x\in X}\|x-D(E(x))\|_{2}^{2} \tag{10}\]  
From this definition, the choice of the optimal quantizer for \(X\) reduces to defining the set of vectors \(c_{i}\), which minimizes Equation (10), which are those provided by the k-means algorithm. K-means directly minimizes the MSE by iteratively updating centroids to minimize the sum of squared distances between data points and their assigned centroids. In Section 4.1, we detail the process of defining the optimal quantizer for the problem of image compression, where \(X\) is defined as a set of representative image patches.