• 沒有找到結果。

Optimum Placement of Segments

The problem of piecewise approximation with variable segment boundaries has received considerable attention in the mathematical literature, especially with the theory of splines [15], [42]. To quote Rice [150]: “The key to the successful use of splines is to have the location of knots as variables.” This section introduces a method for computing the optimum placement of segments for function approxi-mation. We shall use it as a reference in comparing the uniform segment method and our proposed method, as shown in Table 5.2 (Section 5.4). Let f be a contin-uous function on [a, b], and let an integer m ≥ 2 specify the number of contigcontin-uous segments into which [a, b] has been partitioned: a = u0 ≤ u1 ≤ ... ≤ um = b.

Let d be a non-negative integer and let Pi denote the set of functions pi whose polynomials are of degrees less or equal to d. For i = 1, ..., m, define

hi(ui−1, ui) = min

pi∈Pi

ui−1max≤x≤ui

|f (x) − pi(x)|. (5.5)

Let emax = emax(u) = max1≤i≤mhi(ui−1, ui). The segmented minimax approxi-mation problem is that of minimizing emax over all partitions u of [a, b]. If the error norm is a non-decreasing function of the length of the interval of approx-imation, the function to be approximated is continuous and that the goal is to minimize the maximum error norm on each interval, then a balanced error solu-tion is locally optimal. The term “balanced error” means that the error norms on each interval are equal [81]. One class of algorithms to tackle this problem is based on the remainder formula [42] and assumes that the (d + 1)th derivative of f is either of fixed sign or bounded away from zero [140]. However, in many practical cases this assumption does not hold [138]. Often, the (d + 1)th deriva-tive may be zero or very small over most of [a, b] except a few points where it has very large values. This is precisely the case with the non-linear functions we are approximating.

In Lawson paper, an iterative technique for finding the balanced error so-lution [81] is presented. However, his technique has a rather serious defect: if at some intermediate step of the algorithm an interval with zero-error norm (or even much smaller than others) is found, the method fails. This turns out to be a common occurrence in various practical applications [138]. Pavlidis and Maika present a better scheme in their paper [142] which results in a suboptimal balanced error solution. It is based on an iteration of the form

uk+1i = uki + c(eki+1− eki), i = 1, ..., n − 1. (5.6) Here uki is the value of the i-th point and the k-th iteration, eki is the error on (uki−1, uki] and c is an appropriate small positive number. It can be shown that for sufficiently small c the scheme converges to a solution [142]. A reasonable choice for c is the inverse of the change in error norm divided by the size of the motion of a boundary which caucused it. We have implemented this scheme in MATLAB,

where the function to be approximated f , the interval of approximation [a, b], the degree d of the polynomial approximations and the number of segments m are given as inputs. The program outputs the segment boundaries u1..m−1 and the maximum absolute error emax. Our tests show that this scheme requires large numbers of iterations for a reasonable value of m and balance criterion (deviation of errors of the segments), and often fails to converge. In addition, for our purposes we would like to give f , [a, b], d and emax as inputs and obtain m and u1..m−1.

We have developed a novel algorithm to find the optimum boundaries for a given f , [a, b], d, emax and unit in the last place (ulp). The ulp is the least significant bit of the fraction of a number in its standard representation. For instance, if a number has F fractional bits, the ulp of that number would be 2−F. The ulp is required as an input, since the input is quantized to n bits.

The MATLAB code for the algorithm is shown in Figure 5.1. The algorithm is based on binary search and finds the optimum boundaries over [a, b]. We first set x1 = a and x2 = b and find the minimax approximation over the interval [x1, x2].

If the error e of this approximation is larger than emax, we set x2 = (x1 + x2)/2 and obtain the error for [a, x2]. We keep halving the interval of approximation until e ≤ emax. At this point we increment x2 by a small amount and compute the error again. This small amount is either (abs(x2 − prev x2))/2 or the ulp, whichever is smaller (prev x2 is the value of x2 in the previous iteration). When this small amount is the ulp, in the next iterations x2 will keep oscillating between the ideal (un-quantized) boundary. We take the x2 whose error e is just below emax as our boundary, set x1 = x2 and x2 = b, and move on to approximating over [x1, x2]. This is performed until the error over [x1, x2] is less than or equal to emax and x2 has the same value as b. We can see that the boundaries up to the last one are optimum for the given ulp (the last segment is always smaller than its

optimum size, as it can be seen in Figure 5.2 for f2). Although our segments are not optimum in the sense that the errors of the segments are not fully balanced, we can conclude that given the error constraint emax and the ulp, the placement of our segment boundaries is optimum. This is because the maximum error we obtain is less than or equal to emaxand this is not achievable with fewer segments.

The results of our segmentation can be used for various other applications [138]

including pattern recognition [37], [141], data compression, non-linear filtering and picture processing [140].

In the ideal case, one would use these optimum boundaries to approximate the functions. However, from a hardware implementation point of view, this is can be impractical. The circuit to find the right segment for a given input could be complex, hence large and slow. Nevertheless, the optimum segments give us an indication of how well a given segmentation scheme matches the optimum segmentation. Moreover, they provide information on the non-linearities of a function. Figure 5.2 shows the optimum boundaries for the four functions in Section 5.1 for 16-bit operands and second order approximations. We observe that f1 needs more segments in the regions near 0 and 1, f2 requires more segments near 0 and f3 requires more segments in the two regions in the lower and upper half of the interval.

In Figure 5.3 and Figure 5.4, we observe how the optimum number of segments change for first and second order approximations as the bit width increases. We can see that they have an exponential behavior. The interesting observation is that for all four functions, the optimum segment numbers vary by a factor of around 4 per bit for first order and 1.6 per bit for second order approximations.

Therefore as the bitwidths get larger, the memory savings of using second order approximations get larger (Figure 5.5).

Figure 5.5 compares the ratio of the number of optimum segments required by first and second order approximations for 8, 12, 16, 20 and 24-bit approximations to the four functions. We can see that savings of second order approximations get larger as the bit width increases. However one should note that, whereas first order approximations involve one multiply and one add, second order approxima-tions involve two multiplies and two adds. Therefore, there is a tradeoff between the look-up table size and the circuit complexity. For low latency and low accu-racy applications, first order approximations may be appropriate. Second order approximations may be suitable for applications that require small look-up tables and high accuracies.

% Inputs: a, b, d, f, e_max, ulp

% Output: u()

x1 = a; x2 = b; m = 1; done = 0; check_x2 = 0; prev_x2 = a;

oscillating = 0; done = 0;

while (~done)

e = minimax(f,d,x1,x2,ulp);

if (e <= e_max) if (x2 == b)

u(i) = x2;

done = 1;

else

if (oscillating) u(m) = x2;

prev_x2 = x2;

x1 = x2;

x2 = b;

m = m+1;

oscillating = 0;

else

change_x2 = abs(x2-prev_x2)/2;

prev_x2 = x2;

if (change_x2 > ulp) x2 = x2 + change_x2;

else

x2 = x2 + ulp;

end end end else

change_x2 = abs(x2-prev_x2)/2;

prev_x2 = x2;

if (change_x2 > ulp) x2 = x2 - change_x2;

else

x2 = x2 - ulp;

if (check_x2 == x2) oscillating = 1;

else

check_x2 = x2;

end end end end

Figure 5.1: MATLAB code for finding the optimum boundaries.

0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 0

0.5 1 1.5 2 2.5 3

x f 1(x)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

−0.35

−0.3

−0.25

−0.2

−0.15

−0.1

−0.05

x f 2(x)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

0.2 0.4 0.6 0.8 1 1.2

x f 3(x)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

0.2 0.4 0.6 0.8 1

x f 4(x)

Figure 5.2: Optimum locations of the segments for the four functions in Sec-tion 5.1 for 16-bit operands and second order approximaSec-tion.

8 10 12 14 16 18 20 22 24 0

1000 2000 3000 4000 5000 6000

Operand Bit Width

Number of Optimum Segments

f1 f2 f3 f4

Figure 5.3: Numbers of optimum segments for first order approximations to the functions for various operand bitwidths.

8 10 12 14 16 18 20 22 24

0 50 100 150 200 250 300 350 400

Operand Bit Width

Number of Optimum Segments

f1 f2 f3 f4

Figure 5.4: Numbers of optimum segments for second order approximations to the functions for various operand bitwidths.

8 10 12 14 16 18 20 22 24 0

5 10 15 20 25

Operand Bit Width

First Order / Second Order

f1

f2

f3

f4

Figure 5.5: Ratio of the number of optimum segments required for first and second order approximations to the functions.

相關文件