find the average value:
in our example:
(7 + 11 + 9 + 14 + 12 + 17)/6 = 11.667
find the total length:
(11-7) + (14-9) + (17-12) = 4 + 5 + 5 = 14;
find the new min / max;
14/2 = 7 11.667 - 7 = 4.667 11.667 + 7 = 18.667
you can combine them
4.667 ~ 5 18.667 ~ 19
start with mines by creating partitions with intervals
(5, (11-7)+5) = (5,9) (9, (14-9)+9) = (9,14) (14, (17-12)+14) = (14,19)
Note:
this method will not match the original elements as much as possible, but will keep them as close to the original as possible, given their relative values โโ(keeping the center)
EDIT:
if you want to keep the average values โโof all intervals as close as possible to the original, you can implement a mathematical solution.
our input problems:
a 1 = (a 1,1 , a 1,2 ), ..., a nsub> = (a <sub> n, 1sub>, and <sub> n, 2sub>)
define:
ai 1 = a 1,2 -a 1,1 // define the intervals
b 1 = (d, d + ai 1 )
b n = (d + sum (ai 1 .. ai n-1 )), d + sum (ai 1 .. ai n ))
bi 1 = b 1,2 -b 1,1 // set the intervals
we need to find "d", for example:
s = sum (abs ((a 1,1 + a 1,2 ) / 2 - (b 1,1 + b 1,2 ) / 2))
min (s) is what we want
in our example:
a 1 = (7.11), ai 1 = 4, A avg1 = 9
a 2 = (9.14), ai 2 = 5, A avg2 = 11.5
a 3 = (12.7), ai 3 = 5, A avg3 = 14.5
b 1 = (d, d + 4) B avg1 = d + 2
b 2 = (d + 4, d + 9) B avg2 = d + 6.5
b 3 = (d + 9, d + 14) B avg3 = d + 11.5
s = abs (9- (d + 2)) + abs (11.5- (d + 6.5)) + abs (14.5- (d + 11.5)) = abs (7-d) + abs (5-d) + abs (3-d)
Now calculate the derivative to find the min / max OR iterations over d to get the result. in our case, you will need to iterate from 3 to 7
which should do the trick