# Error-Bounded Learned Scientific Data Compression with Preservation of Derived Quantities
## Appendix A Implementation Details
2:function\(\mathrm{AETMC}(\mathcal{X},\mathbf{Q}_{T})\)\(\triangleright\) Entire framework
3:\(\mathcal{S},U_{1},\ldots,U_{R}\leftarrow\mathrm{Tucker}(\mathcal{X})\)
4: Train AE with Tucker coefficients
5:\(\mathrm{AE}_{Encoder},\mathrm{AE}_{Decoder}\leftarrow\mathrm{TrainingAE}( \mathcal{S})\)
6:\(\mathcal{S}_{c}\leftarrow\mathrm{AE}_{Encoder}(\mathcal{S})\)
7: Quantize \(\mathcal{S}_{c}\) with \(\mathrm{PQ}\)
8:\(\mathcal{S}_{c},D_{1}\leftarrow\mathrm{PQ}(\mathcal{S}_{c},B_{1})\)\(\triangleright\)\(D_{1}\): dictionary
9:\(\mathcal{S}_{d}\leftarrow\mathrm{PQ}\mathrm{Decoder}(\mathcal{S}_{c},D_{1})\)
10: Reconstruct Tucker coefficients with AE
11:\(\mathcal{S}\leftarrow\mathrm{AE}_{Decoder}(\mathcal{S}_{d})\)
12:\(\mathcal{X}^{0}\leftarrow\mathrm{InverseTucker}\big{(}\mathcal{S},U_{1}, \ldots,U_{R}\big{)}\)
13:\(\mathcal{R}\leftarrow\mathcal{X}-\mathcal{X}^{0}\)\(\triangleright\) Compute residuals Reconstruct residuals \(\mathcal{\tilde{R}}\) by MGARD
14:\(\mathcal{\tilde{R}}_{c}\leftarrow\mathrm{MGARD}_{Decompose}(\mathcal{\tilde{R}})\)\(\triangleright\) Encode residuals
15:\(\mathcal{\tilde{R}}\leftarrow\mathrm{MGARD}_{Recompose}(\mathcal{\tilde{R}}_{c})\)\(\triangleright\) Decode residuals Reconstructed output \(\mathcal{X}^{0}\) by AETM
16:\(\mathcal{X}^{0}\leftarrow\mathcal{X}^{0}+\mathcal{\tilde{R}}\)
17:\(\mathcal{X}^{0}\leftarrow\mathrm{ReLU}(\mathcal{X}^{0})+\epsilon\)\(\triangleright\) Remove non-positive values Constraint satisfaction with \(\mathcal{X}^{0}\)
18:\(\mathcal{\tilde{X}},\mathbf{\Lambda}_{c},D_{2}\leftarrow\mathrm{CS}(\mathcal{X}^{0}, \mathbf{Q}_{T})\)
19:return\(\mathcal{\tilde{X}}\) (Reconstruction), \(\mathcal{S}_{c},\mathcal{\tilde{R}}_{c},\mathbf{\Lambda}_{c}\) (Encoded data), \(\mathrm{AE}_{Decoder}\), \(\mathrm{MGARD}_{Decoder}\), \(\{U_{i}\}_{1}^{R}\), \(D_{1}\), \(D_{2}\) (Fixed cost)
20:end function
21:function\(\mathrm{Tucker}(\mathcal{X})\)\(\triangleright\) Tucker decomposition
22:for\(r=1,\ldots,R\)do
23: Compute \(\mathcal{X}_{(r)}=U_{r}\Sigma_{r}V_{r}^{T}\)
24:endfor
25:\(\mathcal{S}\leftarrow\mathcal{X}\times_{1}U_{1}^{T}\times\cdots\times_{R}U_{ R}^{T}\)
26:return\(\mathcal{S},U_{1},\ldots,U_{R}\triangleright\) Tucker coefficients and bases
27:end function
28:function\(\mathrm{InverseTucker}(\mathcal{S},U_{1},\ldots,U_{R})\)\(\triangleright\) Inverse of Tucker
29:\(\mathcal{X}\leftarrow\mathcal{S}\times_{1}U_{1}\times\cdots\times_{R}U_{R}\)
30:return\(\mathcal{X}\)\(\triangleright\) Project back into original space
31:end function
32:function\(\mathrm{TrainingAE}(\mathcal{S})\)\(\triangleright\) Training Autoencoder
33: Initialize Encoder weight \(W\)
34:Decoder weight \(\gets W^{T}\)
35:for\(p=1,\ldots,Epoch\)do
36:\(\mathcal{\tilde{S}}_{p}\gets W_{p}^{T}W_{p}\mathcal{S}\)
37:\(W_{p}\leftarrow\min\mathrm{MSE}\big{(}\mathcal{S},\mathcal{\tilde{S}}_{p} \big{)}\)
38:endfor
39:return\(W\)
40:endfunction
41:function\(\mathrm{PQ}(\mathcal{\tilde{S}}_{c},B)\)\(\triangleright\) Product Quantizer
42:\(M\leftarrow\) latent feature space of \(\mathcal{\tilde{S}}_{c}\)
43:\(D\gets M\times 2^{B}\) dictionary\(\triangleright\)\(B\): quantization bits
44:for\(m=1,\ldots,M\)do
45: Run K-means clustering of each sub-feature
46:\(C\gets 2^{B}\) centroids of \(\mathcal{\tilde{S}}_{c}^{m}\)
47:\(D_{m}\gets C\)
48:\(\mathcal{S}_{c}^{m}\leftarrow\) indexes to the nearest centroid in \(D_{m}\)
49:endfor
50:return\(\mathcal{S}_{c},D\)
51:endfunction
52:function\(\mathrm{PSO}(\mathcal{\tilde{S}}_{c},D)\)\(\triangleright\) Decoding PQ
53:\(\mathcal{S}_{d}\leftarrow\) entries of the dictionary \(D\) indicated by \(\mathcal{S}_{c}\)
54:return\(\mathcal{S}_{d}\)
55:endfunction
56:function\(\mathrm{CS}(\mathcal{X}^{0},\mathbf{Q}_{T})\)\(\triangleright\) Constraint Satisfaction
57: Initialize \(\mathbf{\Lambda}\leftarrow\mathbf{0}\)
58:for\(n=1,\ldots,N\)do\(\triangleright\) N=16,395
59:\(f^{0}\leftarrow\mathcal{X}_{n}^{0}\)
60:\(\mathbf{\lambda}\leftarrow\mathbf{\Lambda}_{n}\)
61:\(f\gets f^{0}\exp\left(-\mathbf{\lambda}^{T}\mathbf{V}\right)\)
62:\(g(\mathbf{\lambda})\leftarrow\) gradient of \(q(\mathbf{\lambda})\) in Equation (24)
63:\(H(\mathbf{\lambda})\leftarrow\) Hessian of \(q(\mathbf{\Lambda})\)
64:while k do\(\triangleright\) Iterate until converge
65:\(\mathbf{\lambda}_{k+1}\leftarrow\mathbf{\lambda}_{k}-H^{-1}(\mathbf{\lambda}_{k})g(\mathbf{ \lambda}_{k})\)
66:\(f\gets f^{0}\exp\left(-\mathbf{\lambda}_{k+1}^{T}\mathbf{V}\right)\)
67:endwhile
68:\(\mathbf{\Lambda}_{n}\leftarrow\mathbf{\lambda}_{k+1}\)
69:endfor
70:Quantization of \(\mathbf{\Lambda}\)
71:\(\mathbf{\Lambda}^{c},D_{2}\leftarrow\mathrm{PQ}(\mathbf{\Lambda},B_{2})\)\(\triangleright\)\(D_{2}\): dictionary
72:\(\mathbf{\Lambda}^{d}\leftarrow\mathrm{PQ}\mathrm{Decoder}(\mathbf{\Lambda}^{c},D_{2})\)
73:for\(n=1,\ldots,N\)do
74:\(f^{0}\leftarrow\mathcal{X}_{n}^{0}\)
75:\(\mathbf{\lambda}\leftarrow\mathbf{\Lambda}_{n}^{d}\)
76:\(f\gets f^{0}\exp\left(-\mathbf{\lambda}^{T}\mathbf{V}\right)\)
77:\(\mathcal{\tilde{X}}_{n}\gets f\)
78:endfor
79:return\(\mathcal{\tilde{X

## References

* [PERSON] (2017) [PERSON] Computing Just What You Need: Online Data Analysis and Reduction at Extreme Scales.