def calculate_fractional_overlap(interest_range, comparison_range):
"""
Calculate how much of the range of interest overlaps with the comparison
range.
"""
if not (interest_range[-1] >= comparison_range[0] \
and comparison_range[-1] >= interest_range[0]):
return 0.0 # No overlap
elif (interest_range[0] >= comparison_range[0] \
and interest_range[-1] <= comparison_range[-1]):
return 1.0 # Total overlap
else:
# Some overlap. Which side?
if interest_range[0] < comparison_range[0]:
# Left hand side
width = interest_range[-1] - comparison_range[0]
else:
# Right hand side
width = comparison_range[-1] - interest_range[0]
return width/np.ptp(interest_range) # Fractional overlap
评论列表
文章目录