def _log_vMF_matrix(points,means,K,n_jobs=1):
"""
This method computes the log of the density of probability of a von Mises Fischer law. Each line
corresponds to a point from points.
:param points: an array of points (n_points,dim)
:param means: an array of k points which are the means of the clusters (n_components,dim)
:param cov: an array of k arrays which are the covariance matrices (n_components,dim,dim)
:return: an array containing the log of density of probability of a von Mises Fischer law (n_points,n_components)
"""
n_points,dim = points.shape
n_components,_ = means.shape
dim = float(dim)
log_prob = K * np.dot(points,means.T)
# Regularisation to avoid infinte terms
bessel_term = iv(dim*0.5-1,K)
idx = np.where(bessel_term==np.inf)[0]
bessel_term[idx] = np.finfo(K.dtype).max
log_C = -.5 * dim * np.log(2*np.pi) - np.log(bessel_term) + (dim/2-1) * np.log(K)
return log_C + log_prob
评论列表
文章目录