搞不清主控律算法

2024-03-28 10:21:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在matlab中为“majorclust”算法编写自己的代码。我有文档对有它们的余弦相似性。当我在网上搜索时,我遇到了这个网站。在

http://muse-amuse.in/~baali/MajorClustPost.html

在本网站的示例(用Python编写)中,集群部分如下所示:

t = False
indices = np.arange(num_of_samples)
while not t:
  t = True
  for index in np.arange(num_of_samples):
    # aggregating edge weights 
    new_index = np.argmax(np.bincount(indices, 
    weights=cosine_distances[index]))
if indices[new_index] != indices[index]:
  indices[index] = indices[new_index]
  t = False

当我检查样品时,我有点困惑。当我们考虑for循环时:

^{pr2}$

第一个索引为“0”。最大相似度用“1”检索。所以新的_索引必须是1,索引“0”将被“1”替换。在

在下一次迭代中,索引将为“1”,其最大权重将来自“0”,该值与上一次迭代的索引相同。因此,在这个点之后循环必须终止。在

该算法基于论文(见第4页):

http://www.uni-weimar.de/medien/webis/publications/papers/stein_2002c.pdf

文中指出指标必须随机选取。但在这个例子中 我看不出任何随机的选择。在

我错过了什么?在


Tags: ofin算法falsehttpnewforindex
1条回答
网友
1楼 · 发布于 2024-03-28 10:21:59

是的,如果你洗牌索引,你可以做同样的使用

from random import shuffle
shuffled_indices = np.arange(num_of_samples)
shuffle(shuffled_indices)
for index in shuffled_indices:
    # aggregating edge weights 
    new_index = np.argmax(np.bincount(indices,weights=cosine_distances[index]))
    if indices[new_index] != indices[index]:
        indices[index] = indices[new_index]
        t = False

很抱歉这么晚才回复。在

相关问题 更多 >