def analytical_value_d_hellinger(distr1, distr2, par1, par2):
""" Analytical value of Hellinger distance for the given distributions.
Parameters
----------
distr1, distr2 : str-s
Names of the distributions.
par1, par2 : dictionary-s
Parameters of the distributions. If distr1 = distr2 =
'normal': par1["mean"], par1["cov"] and par2["mean"],
par2["cov"] are the means and the covariance matrices.
Returns
-------
d : float
Analytical value of the Hellinger distance.
"""
if distr1 == 'normal' and distr2 == 'normal':
# covariance matrices, expectations:
c1, m1 = par1['cov'], par1['mean']
c2, m2 = par2['cov'], par2['mean']
# "https://en.wikipedia.org/wiki/Hellinger_distance": Examples:
diffm = m1 - m2
avgc = (c1 + c2) / 2
inv_avgc = inv(avgc)
d = 1 - det(c1)**(1/4) * det(c2)**(1/4) / sqrt(det(avgc)) * \
exp(-dot(diffm, dot(inv_avgc, diffm))/8) # D^2
d = sqrt(d)
else:
raise Exception('Distribution=?')
return d
x_analytical_values.py 文件源码
python
阅读 19
收藏 0
点赞 0
评论 0
评论列表
文章目录