def estimate_mode(acc):
""" Estimate the mode of a set of float values between 0 and 1.
:param acc: Data.
:returns: The mode of the sample
:rtype: float
"""
# Taken from sloika.
if len(acc) > 1:
da = gaussian_kde(acc)
optimization_result = minimize_scalar(lambda x: -da(x), bounds=(0, 1), method='Bounded')
if optimization_result.success:
try:
mode = optimization_result.x[0]
except IndexError:
mode = optimization_result.x
else:
sys.stderr.write("Mode computation failed")
mode = 0
else:
mode = acc[0]
return mode
评论列表
文章目录