## 2 State-of-the-Art PWL Method
### ML-PLAC Segmentor and Quantizer  
The segmentation method of ML-PLAC is similar to that of the method in [21; 25], except that quantization is added to the process, which is called SQ method [28], and the whole process of segmentation is shown in Figure 3. Compared to PLAC, ML-PLAC has more segments, but the computational burden is greatly reduced. Therefore, the performance of the hardware circuit is greatly improved and the area is smaller meanwhile. ML-PLAC searches for the minimum number of segments with the specified fractional bits of the input/output, intermediate data and slope, while ensuring that the error is less than predefined MAE (MAE\({}_{\text{def}}\)). Using SQ method to replace the separated segmentation and quantization operations, the original function can be approximated better by piecewise linear function. The segmentation steps of ML-PLAC based on software are briefly described below:  
1. Predefine MAE, kw, iw, qw and initial i, j as 0 and 1, respectively, for the first segment;
2. Use the bisection method to find the segment width that meets the conditions. When the endpoint of a segment is found, the in-segment loop is complete. Then the value of i plus 1, sp and ep are initialized as start and end point indexes for undivided zones to start a new segment. Before each new segment, the left and right pointers of the bisection window coincide with sp and ep, respectively;
3. Suppose that the independent variable of ith segment is [x(spi), x(epi)]; ki and bi are slope and y-intercept of the linear function, calculated as: \[\mathrm{k_{i}}=\frac{\mathrm{f(x(ep_{i}))-f(x(sp_{i}))}}{\mathrm{x(ep_{i})-x( sp_{i})}}\] (8) and \[\mathrm{b_{i}}=\mathrm{f(x(ep_{i}))-k_{i}\times x(ep_{i})}\] (9)  
\(\mathrm{k_{i}}\) is quantified as kqi which is related to kw, expressed by:  
\[\mathrm{kq_{i}}=\frac{\mathrm{round}\big{(}\mathrm{k_{i}\times 2^{kw}}\big{)}}{2^{kw}} \tag{10}\]  
Then take mq to represent the result of (x \(\times\) kqi). SAA operations are used to replace multiplication, in which the data are truncated according to the fractional bit width of the intermediate data qw. The linear function is expressed by (1), expressed as:  
\[\mathrm{h(x)}=\mathrm{mq}+\mathrm{b_{i}} \tag{11}\]  
So, the error is:  
\[\mathrm{Err}=\mathrm{f(x(sp:ep))-h(x(sp:ep))} \tag{12}\]  
Figure 3: The process of segmentation in ML-PLAC. The intercept is corrected by Err to minimize the MAE, optimized to be:  
\[\text{b}_{\text{i}}^{\prime}=\text{b}_{\text{i}}+\frac{\text{max}(\text{Err})+ \text{min}(\text{Err})}{2} \tag{13}\]  
And \(\text{b}_{\text{i}}\)' is quantified as \(\text{b}\text{q}_{\text{i}}\), expressed by:  
\[\text{b}\text{q}_{\text{i}}=\frac{\text{round}\Big{(}\text{b}_{\text{i}}^{ \prime}\times 2^{\text{max}(\text{iw},\ \text{q}\text{w})}\Big{)}}{2^{\text{max}(\text{iw},\ \text{q}\text{w})}} \tag{14}\]  
Therefore, the optimized linear function and MAE are, respectively, calculated by:  
\[\text{h}(\text{x})^{\prime}=\text{mq}+\ \text{b}\text{q}_{\text{i}} \tag{15}\]  
and  
\[\mathrm{k_{i}}=\frac{\mathrm{f(x(ep_{i}))-f(x(sp_{i}))}}{\mathrm{x(ep_{i})-x( sp_{i})}}\]0  
4. This step executes according to the value of MAE calculated by Equation (16) and the predefined \(\text{MAE}_{\text{def}}\). **Condition a:** If MAE meets the requirement of the predefined \(\text{MAE}_{\text{def}}\), then conform whether the width of current segment reaches the width of the bisection window pointer (\(\text{ep}==\text{rp}\) or \(\text{ep}==\text{rp}-1\)). If is reached, the information of the segment including start pointer, end pointer, slope and y-intercept are determined and stored. After that, back to step 2 and start the new segment. Otherwise, the width of current segment can be enlarged. Then the left pointer of the bisection window shifts to the end pointer and end the pointer shifts right to the middle of the new bisection window. **Condition b:** If MAE does not meet the predefined \(\text{MAE}_{\text{def}}\), it means the width of the segment is too large and needs to be reduced.