Coverage for src/foapy/characteristics/ma/_uniformity.py: 100%

4 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-05-17 20:45 +0000

1import numpy as np 

2 

3 

4def uniformity(intervals, dtype=None): 

5 """ 

6 Calculates uniformity of the intervals grouped by congeneric sequence. 

7 

8 $$ 

9 \\left[ u_j \\right]_{1 \\le j \\le m} = 

10 \\left[ 

11 \\log_2 { \\left(\\frac{1}{n_j} * \\sum_{i=1}^{n_j} \\Delta_{ij} \\right) } - 

12 \\frac{1}{n_j} * \\sum_{i=1}^{n_j} \\log_2 \\Delta_{ij} 

13 \\right]_{1 \\le j \\le m} 

14 $$ 

15 

16 where \\( \\Delta_{ij} \\) represents $i$-th interval of $j$-th 

17 congeneric intervals array, \\( n_j \\) is the total 

18 number of intervals in $j$-th congeneric intervals array 

19 and $m$ is number of congeneric intervals arrays. 

20 

21 Parameters 

22 ---------- 

23 intervals : array_like 

24 An array of congeneric intervals array 

25 dtype : dtype, optional 

26 The dtype of the output 

27 

28 Returns 

29 ------- 

30 : array 

31 An array of the uniformity of congeneric intervals. 

32 

33 Examples 

34 -------- 

35 

36 Calculate the uniformity of a sequence. 

37 

38 ``` py linenums="1" 

39 import foapy 

40 import numpy as np 

41 

42 source = np.array(['a', 'b', 'a', 'c', 'a', 'd']) 

43 order = foapy.ma.order(source) 

44 intervals = foapy.ma.intervals(order, foapy.binding.start, foapy.mode.normal) 

45 result = foapy.characteristics.ma.uniformity(intervals) 

46 print(result) 

47 # [0.07029893 0. 0. 0. ] 

48 ``` 

49 

50 Calculate the uniformity of congeneric intervals of a sequence. 

51 

52 ``` py linenums="1" 

53 import foapy 

54 

55 X = [] 

56 X.append([1, 1, 4, 4]) 

57 X.append([3, 1, 3]) 

58 X.append([5, 3, 1]) 

59 

60 result = foapy.characteristics.ma.uniformity(X) 

61 print(result) 

62 # [0.32192809 0.16575075 0.28266564] 

63 ``` 

64 """ # noqa: W605 

65 

66 from foapy.characteristics.ma import average_remoteness, identifying_information 

67 

68 return np.subtract( 

69 identifying_information(intervals, dtype=dtype), 

70 average_remoteness(intervals, dtype=dtype), 

71 dtype=dtype, 

72 )