Coverage for src/foapy/characteristics/_descriptive_information.py: 100%
4 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-17 20:45 +0000
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-17 20:45 +0000
1import numpy as np
4def descriptive_information(intervals_grouped, dtype=None):
5 """
6 Calculates descriptive information of intervals (grouped by element of the alphabet).
8 $$D=\\prod_{j=1}^{m}{\\left(\\sum_{i=1}^{n_j}{\\frac{\\Delta_{ij}}{n_j}}\\right)^{\\frac{n_j}{n}}}$$
10 where \\( m \\) is count of groups (alphabet power), \\( n_j \\) is count of intervals in group \\( j \\),
11 \\( \\Delta_{ij} \\) represents an interval at index \\( i \\) in group \\( j \\) and \\( n \\) is total count of intervals across all groups.
13 $$n=\\sum_{j=1}^{m}{n_j} $$
15 Parameters
16 ----------
17 intervals_grouped : array_like
18 An array of intervals grouped by element
19 dtype : dtype, optional
20 The dtype of the output
22 Returns
23 -------
24 : float
25 The descriptive information of the input array of intervals_grouped.
27 Examples
28 --------
30 Calculate the descriptive information of intervals_grouped of a sequence.
32 ``` py linenums="1"
33 import foapy
34 import numpy as np
36 source = np.array(['a', 'b', 'a', 'c', 'a', 'd'])
37 order = foapy.ma.order(source)
38 print(order)
40 #[[0 -- 0 -- 0 --]
41 # [-- 1 -- -- -- --]
42 # [-- -- -- 2 -- --]
43 # [-- -- -- -- -- 3]]
45 intervals_grouped = foapy.ma.intervals(order, foapy.binding.start, foapy.mode.normal)
47 print(intervals_grouped)
48 # [
49 # array([1, 2, 2]),
50 # array([2]),
51 # array([4]),
52 # array([6])
53 # ]
55 # m = 4
56 # n_0 = 3
57 # n_1 = 1
58 # n_2 = 1
59 # n_3 = 1
60 # n = 6
62 result = foapy.characteristics.descriptive_information(intervals_grouped)
63 print(result)
64 # 2.4611112617624173
66 # Improve precision by specifying a dtype.
67 result = foapy.characteristics.descriptive_information(intervals_grouped, dtype=np.longdouble)
68 print(result)
69 # 2.4611112617624174427
70 ```
71 """ # noqa: E501
72 from foapy.characteristics import identifying_information
74 return np.power(
75 2, identifying_information(intervals_grouped, dtype=dtype), dtype=dtype
76 )