Calculates average remoteness of intervals.
\[ g = \frac{1}{n} * \sum_{i=1}^{n} \log_2 \Delta_{i} \]
where \( \Delta_{i} \) represents each interval and \( n \)
is the total number of intervals.
Parameters:
Name |
Type |
Description |
Default |
intervals
|
array_like
|
|
required
|
dtype
|
dtype
|
|
None
|
Returns:
Type |
Description |
float
|
The average remoteness of the input array of intervals.
|
Examples:
Calculate the average remoteness of intervals of a sequence.
| import foapy
source = ['a', 'b', 'a', 'c', 'a', 'd']
intervals = foapy.intervals(source, foapy.binding.start, foapy.mode.normal)
result = foapy.characteristics.average_remoteness(intervals)
print(result)
# 1.2641604167868594
# Improve precision by specifying a dtype.
result = foapy.characteristics.average_remoteness(intervals, dtype=np.longdouble)
print(result)
# 1.2641604167868593636
|
Source code in .tox/docs-deploy/lib/python3.11/site-packages/foapy/characteristics/_average_remoteness.py
| def average_remoteness(intervals, dtype=None):
"""
Calculates average remoteness of intervals.
$$ g = \\frac{1}{n} * \\sum_{i=1}^{n} \\log_2 \\Delta_{i} $$
where \\( \\Delta_{i} \\) represents each interval and \\( n \\)
is the total number of intervals.
Parameters
----------
intervals : array_like
An array of intervals
dtype : dtype, optional
The dtype of the output
Returns
-------
: float
The average remoteness of the input array of intervals.
Examples
--------
Calculate the average remoteness of intervals of a sequence.
``` py linenums="1"
import foapy
source = ['a', 'b', 'a', 'c', 'a', 'd']
intervals = foapy.intervals(source, foapy.binding.start, foapy.mode.normal)
result = foapy.characteristics.average_remoteness(intervals)
print(result)
# 1.2641604167868594
# Improve precision by specifying a dtype.
result = foapy.characteristics.average_remoteness(intervals, dtype=np.longdouble)
print(result)
# 1.2641604167868593636
```
""" # noqa: W605
from foapy.characteristics import depth
n = len(intervals)
# Check for an empty list or a list with zeros
if n == 0 or all(x == 0 for x in intervals):
return 0
return depth(intervals, dtype=dtype) / n
|