# On the Optimal Calculation of the Rice Coding Parameter
## 5 Multi-Parameter Rice Coding
### Two Simple Heuristics for Constrained IoT Devices  
Based on the analysis of the solution to the problem of finding the optimal Rice coding using the partitioning process as described above, in this subsection, we present two parameterized heuristics of reduced complexity in terms of both memory and CPU usage. The idea behind the design of these parameterized heuristics is to define--in a single iteration through samples--output sub-sequences based on their similarity in terms of the number of bits needed for their encoding, following the concept of the basis presented in Section 5.1. To do this, we assume that we are given an input parameter, say \(\Delta\), bounded by \(0\leq\Delta\leq(L_{\max}-L_{\min})\), which we name the spread factor. Output sub-sequences are going to be built in such a way that the difference in the bit-length of the raw values--i.e., \(L(n_{i})\)--of each output sub-sequence will not be larger than the parameter \(\Delta\). As a result, if \(\Delta\) equals \((L_{\max}-L_{\min})\), the output of these heuristics will be a single sub-sequence comprising all elements. On the other hand, if \(\Delta\) is equal to zero, the output of these heuristics will be the set of all the sub-sequences found in the basis (as explained in Section 5.1). Our first proposed heuristic for this problem sets the encoding parameter of each sub-sequence as the optimal value as calculated by Algorithm 1. Our second proposed heuristic for this problem sets the encoding parameter of each sub-sequence to its respective value of \(\lfloor S\rfloor\), as explained in Section 3.2. The pseudo-code of the second heuristic can be observed in Algorithm 4. The function \(\mathrm{RiceEncode}(\mathbf{n},i,j,r)\) does only the encoding (no parameter calculation) of the sub-sequence of \(\mathbf{n}\) starting from the \(i\)-th element to the \(j\)-th element using Rice parameter \(r\). Since each element in \(\mathbf{n}\) is passed through only once and all other calculations are done within the loop itself--between Lines 6 and 20--the running complexity of the second heuristic is \(O(n)\). The pseudo-code for the first heuristic is very similar, with the difference that the estimation \(s\) and its associated summation \(\hat{s}\) are not implemented and, hence, not passed to the function \(\mathrm{RiceEncode}\). In such a case, the function \(\mathrm{RiceEncode}\) should find the optimal parameter for the given sub-sequence using Algorithm 1, before encoding the set of samples. Each element must be passed twice: first by the loop function presented in Algorithm 4 and later for determining the optimal parameter (Algorithm 1) for the sub-sequence. The running complexity of the first heuristic is, therefore, \(O(N+N\cdot L_{\max})=O(N\cdot L_{\max})\), i.e., it is defined by the complexity of finding the optimal parameter of a sub-sequence. Figure 9: The directed acyclic bipartite graph for the previously provided example sequence, with weights (\(w\)) as given in Table 4. When \(\epsilon=0\), the shortest path has a total cost of \(57\). This shortest path is marked using continuous lines as arcs between the vertices. Only the weight of the vertices for this shortest path and those equal to \(\epsilon\) are shown. When \(\epsilon=8\), the shortest path solution corresponds to the path \(v_{\alpha}\to u_{1}\to v_{10}\to u_{\omega}\) (not shown) with cost \(64+\epsilon=72\).