Skip to content

foapy.characteristics.descriptive_information

descriptive_information(intervals_grouped, dtype=None)

Calculates descriptive information of intervals (grouped by element of the alphabet).

\[D=\prod_{j=1}^{m}{\left(\sum_{i=1}^{n_j}{\frac{\Delta_{ij}}{n_j}}\right)^{\frac{n_j}{n}}}\]

where \( m \) is count of groups (alphabet power), \( n_j \) is count of intervals in group \( j \), \( \Delta_{ij} \) represents an interval at index \( i \) in group \( j \) and \( n \) is total count of intervals across all groups.

\[n=\sum_{j=1}^{m}{n_j} \]

Parameters:

Name Type Description Default

intervals_grouped

array_like

An array of intervals grouped by element

required

dtype

dtype

The dtype of the output

None

Returns:

Type Description
float

The descriptive information of the input array of intervals_grouped.

Examples:

Calculate the descriptive information of intervals_grouped of a sequence.

import foapy
import numpy as np

source = np.array(['a', 'b', 'a', 'c', 'a', 'd'])
order = foapy.ma.order(source)
print(order)

#[[0 -- 0 -- 0 --]
# [-- 1 -- -- -- --]
# [-- -- -- 2 -- --]
# [-- -- -- -- -- 3]]

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

print(intervals_grouped)
# [
#    array([1, 2, 2]),
#    array([2]),
#    array([4]),
#    array([6])
# ]

# m = 4
# n_0 = 3
# n_1 = 1
# n_2 = 1
# n_3 = 1
# n = 6

result = foapy.characteristics.descriptive_information(intervals_grouped)
print(result)
# 2.4611112617624173

# Improve precision by specifying a dtype.
result = foapy.characteristics.descriptive_information(intervals_grouped, dtype=np.longdouble)
print(result)
# 2.4611112617624174427
Source code in .tox/docs-deploy/lib/python3.11/site-packages/foapy/characteristics/_descriptive_information.py
def descriptive_information(intervals_grouped, dtype=None):
    """
    Calculates descriptive information of intervals (grouped by element of the alphabet).

    $$D=\\prod_{j=1}^{m}{\\left(\\sum_{i=1}^{n_j}{\\frac{\\Delta_{ij}}{n_j}}\\right)^{\\frac{n_j}{n}}}$$

    where \\( m \\) is count of groups (alphabet power), \\( n_j \\) is count of intervals in group \\( j \\),
    \\( \\Delta_{ij} \\) represents an interval at index \\( i \\) in group \\( j \\) and \\( n \\) is total count of intervals across all groups.

    $$n=\\sum_{j=1}^{m}{n_j} $$

    Parameters
    ----------
    intervals_grouped : array_like
        An array of intervals grouped by element
    dtype : dtype, optional
        The dtype of the output

    Returns
    -------
    : float
        The descriptive information of the input array of intervals_grouped.

    Examples
    --------

    Calculate the descriptive information of intervals_grouped of a sequence.

    ``` py linenums="1"
    import foapy
    import numpy as np

    source = np.array(['a', 'b', 'a', 'c', 'a', 'd'])
    order = foapy.ma.order(source)
    print(order)

    #[[0 -- 0 -- 0 --]
    # [-- 1 -- -- -- --]
    # [-- -- -- 2 -- --]
    # [-- -- -- -- -- 3]]

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

    print(intervals_grouped)
    # [
    #    array([1, 2, 2]),
    #    array([2]),
    #    array([4]),
    #    array([6])
    # ]

    # m = 4
    # n_0 = 3
    # n_1 = 1
    # n_2 = 1
    # n_3 = 1
    # n = 6

    result = foapy.characteristics.descriptive_information(intervals_grouped)
    print(result)
    # 2.4611112617624173

    # Improve precision by specifying a dtype.
    result = foapy.characteristics.descriptive_information(intervals_grouped, dtype=np.longdouble)
    print(result)
    # 2.4611112617624174427
    ```
    """  # noqa: E501
    from foapy.characteristics import identifying_information

    return np.power(
        2, identifying_information(intervals_grouped, dtype=dtype), dtype=dtype
    )