# Error-Bounded Learned Scientific Data Compression with Preservation of Derived Quantities
## 3 The Compression Framework
### Preservation of the Derived Quantities
#### 3.2.1 Constraint Satisfaction
\begin{array}{rcl}n^{c}(x,t)&=&\int f(x,\mathbf{v},t)\text{vol}(x,\mathbf{v})dv_{ \perp}dv_{\parallel},\end{array}  \tag{12}\]\[u_{\parallel}^{c}(x,t) = \frac{\int f(x,v,t)\text{vol}(x,v)v_{\parallel}(v)dv_{\perp}dv_{ \parallel}}{n^{c}(x,t)}, \tag{13}\] \[T_{\perp}^{c}(x,t) = \frac{1}{2}\frac{\int f(x,v,t)\text{vol}(x,v)mv_{\perp}^{2}(v)dv_{ \perp}dv_{\parallel}}{n^{c}(x,t)},\] (14) \[R_{\parallel}^{c}(x,t) = \frac{1}{2}\frac{\int f(x,v,t)\text{vol}(x,v)mv_{\parallel}^{2}(v )dv_{\perp}dv_{\parallel}}{n^{c}(x,t)}, \tag{15}\]  
where the superscript \(c\) indicates the true (correct) value. Now, we perform constrained optimization. We rewrite the constraints in discrete form since XGC dataset is discretized. We consider a 2D velocity histogram \(f\) at a mesh node \(x\) from a single timestep for notational brevity. The discretized constraints are  
\[n^{c} = \sum_{i,j}f_{ij}\text{vol}_{ij}, \tag{16}\] \[u_{\parallel}^{c}n^{c} = \sum_{i,j}f_{ij}\text{vol}_{ij}v_{j}^{\parallel},\] (17) \[T_{\perp}^{c}n^{c} = \frac{1}{2}m\sum_{i,j}f_{ij}\text{vol}_{ij}\left(v_{i}^{\perp} \right)^{2},\] (18) \[R_{\parallel}^{c}n^{c} = \frac{1}{2}m\sum_{i,j}f_{ij}\text{vol}_{ij}\left(v_{j}^{\parallel }\right)^{2}, \tag{19}\]  
where \(v_{j}^{\parallel}\) and \(v_{j}^{\perp}\) indicate parallel velocity \(v_{\parallel}(v)\) and perpendicular velocity \(v_{\perp}(v)\) respectively. For the objective function in Equation (7), we choose the _Bregman divergence_ for the \(x\log x\) entropy function [38; 39] since all the velocity histogram values are positive and the range of histograms is fairly large (\(10^{6}\)\(\sim\)\(10^{17}\)). Any suitable convex error measure can be used. Since the PD error is optimized in the AE and residual post-processing, we want to obtain the updated reconstruction with constraint satisfaction while minimizing the changes in the PD reconstruction. Let the reconstructed histogram of AETM or any compressor be \(f^{0}\). We use Rectified Linear Units [40] (ReLU) with a small positive value to remove non-positive values, as a compressor might produce some non-positive values due to the large range of histograms. \[f_{ij}^{0}= \begin{cases}f_{ij}^{0}+\epsilon&\text{if }f_{ij}^{0}>0,\\ \epsilon&\text{otherwise},\end{cases}  \tag{20}\]  
where \(\epsilon\) is a very small positive value compared to the histograms, so it does not affect overall compression accuracy. Let the updated reconstruction with constraint satisfaction be \(f\). The Lagrangian for the XGC application is  
\[\mathcal{L}(f,\mathbf{\lambda})=\sum_{i,j}\left(f_{ij}\log\frac{f_{ ij}}{f_{ij}^{0}}-f_{ij}+f_{ij}^{0}\right)+\lambda_{1}\left(\sum_{i,j}f_{ij}V_{ ij}^{1}-n^{c}\right)+\lambda_{2}\left(\sum_{i,j}f_{ij}V_{ij}^{2}-u_{\parallel}^{c}n^{ c}\right)\\ +\lambda_{3}\left(\sum_{i,j}f_{ij}V_{ij}^{3}-T_{\perp}^{c}n^{c} \right)+\lambda_{4}\left(\sum_{i,j}f_{ij}V_{ij}^{4}-R_{\parallel}^{c}n^{c} \right), \tag{21}\]  
where \(\mathbf{\lambda}=[\lambda_{1},\ldots,\lambda_{4}]\), \(V_{ij}^{1}=\text{vol}_{ij}\), \(V_{ij}^{2}=\text{vol}_{ij}v_{j}^{\parallel}\), \(V_{ij}^{3}=\frac{1}{2}m\text{vol}_{ij}\left(v_{i}^{\perp}\right)^{2}\), and \(V_{ij}^{4}=\frac{1}{2}m\text{vol}_{ij}\left(v_{j}^{\parallel}\right)^{2}\). Since the objective function is convex, we set the gradient of \(\mathcal{L}(f,\mathbf{\lambda})\) with regard to \(f\) to zero to find the minimum:  
\[\frac{\partial\mathcal{L}(f,\mathbf{\lambda})}{\partial f_{ij}}=\log\frac{f_{ij}} {f_{ij}^{0}}+\lambda_{1}V_{ij}^{1}+\lambda_{2}V_{ij}^{2}+\lambda_{3}V_{ij}^{3 }+\lambda_{4}V_{ij}^{4}=0, \tag{22}\]from which we obtain  
\[f_{ij}=f_{ij}^{0}\exp\big{(}-K_{ij}\big{)}, \tag{23}\]  
where \(K_{ij}=\lambda_{1}\mathrm{V}_{ij}^{1}+\lambda_{2}\mathrm{V}_{ij}^{2}+\lambda_{3} \mathrm{V}_{ij}^{3}+\lambda_{4}\mathrm{V}_{ij}^{4}\). Using the fact that \(\mathbf{f}^{T}\
abla_{f}\mathcal{L}(\mathbf{f},\mathbf{\lambda})=0\) at the minimum, we obtain the dual \(q(\mathbf{\lambda})\) of Equation (21)  
\[