von_mises_fisher_mixture.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:spherecluster 作者: clara-labs 项目源码 文件源码
def _log_likelihood(X, centers, weights, concentrations):
    if len(np.shape(X)) != 2:
        X = X.reshape((1, len(X)))

    n_examples, n_features = np.shape(X)
    n_clusters, _ = centers.shape

    if n_features <= 50:  # works up to about 50 before numrically unstable
        vmf_f = _vmf_log
    else:
        vmf_f = _vmf_log_asymptotic

    f_log = np.zeros((n_clusters, n_examples))
    for cc in range(n_clusters):
        f_log[cc, :] = vmf_f(X, concentrations[cc], centers[cc, :])

    posterior = np.zeros((n_clusters, n_examples))
    weights_log = np.log(weights)
    posterior = np.tile(weights_log.T, (n_examples, 1)).T + f_log
    for ee in range(n_examples):
        posterior[:, ee] = np.exp(
                posterior[:, ee] - logsumexp(posterior[:, ee]))

    return posterior
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号