Задача решается достаточно просто:
SOURCE: Array ( [0] => 13.1 [1] => 3 [2] => 4 [3] => 8 [4] => 17.9 [5] => 19 [6] => 23.1 [7] => 28 [8] => 33 )
------------
SORTED: Array ( [0] => 3 [1] => 4 [2] => 8 [3] => 13.1 [4] => 17.9 [5] => 19 [6] => 23.1 [7] => 28 [8] => 33 )
DISTANCE: Array ( [0] => 1 [1] => 4 [2] => 5.1 [3] => 4.8 [4] => 1.1 [5] => 4.1 [6] => 4.9 [7] => 5 )
AVERAGE DISTANCE:3.75
CLUSTERS:
Array
(
[-] => Array
(
[data] => Array
(
[0] => 1
[1] => 1.1
)
[max] => 1.1
[min] => 1
)
[+] => Array
(
[data] => Array
(
[0] => 4
[1] => 5.1
[2] => 4.8
[3] => 4.1
[4] => 4.9
[5] => 5
)
[max] => 5.1
[min] => 4
)
)
AVERAGE PERIOD POSITIVE [+]: 4.65
AVERAGE PERIOD NEGATIVE [-]: 1.05
RANGE [+]: [4.55; 5.1]
3: 0, 1, 5, 10.1, 14.9, 16, 20.1, 25, 30, => 1
4: 1, 0, 4, 9.1, 13.9, 15, 19.1, 24, 29, => 0
8: 5, 4, 0, 5.1, 9.9, 11, 15.1, 20, 25, => 2
13.1: 10.1, 9.1, 5.1, 0, 4.8, 5.9, 10, 14.9, 19.9, => 2
17.9: 14.9, 13.9, 9.9, 4.8, 0, 1.1, 5.2, 10.1, 15.1, => 1
19: 16, 15, 11, 5.9, 1.1, 0, 4.1, 9, 14, => 0
23.1: 20.1, 19.1, 15.1, 10, 5.2, 4.1, 0, 4.9, 9.9, => 1
28: 25, 24, 20, 14.9, 10.1, 9, 4.9, 0, 5, => 2
33: 30, 29, 25, 19.9, 15.1, 14, 9.9, 5, 0, => 1
------------
CHAINS:
Array
(
[0] => 1
[1] => 0
[2] => 2
[3] => 2
[4] => 1
[5] => 0
[6] => 1
[7] => 2
[8] => 1
)
------------
RESULT:
Array
(
[0] => 3
[1] => 8
[2] => 13.1
[3] => 17.9
[4] => 23.1
[5] => 28
[6] => 33
)
DISTANCE RESULT: Array ( [0] => 5 [1] => 5.1 [2] => 4.8 [3] => 5.2 [4] => 4.9 [5] => 5 )
PERIOD (average): 5