我最近一直在阅读关于各种hierarchical clustering algorithms,如single-linkage clustering和group average clustering。一般来说,这些算法不会很好地扩展。大多数分层聚类算法的初始实现是O(N^3)
,但单连接聚类可以在O(N^2)
时间内实现。群平均聚类算法的复杂性
还声称可以在O(N^2 logN)
时间内实现组平均聚类。这是我的问题。
我根本看不出这是怎么可能的。
解释后解释,如:
http://nlp.stanford.edu/IR-book/html/htmledition/time-complexity-of-hac-1.html
http://nlp.stanford.edu/IR-book/completelink.html#averagesection
https://en.wikipedia.org/wiki/UPGMA#Time_complexity
...声称该组平均聚类可以O(N^2 logN)
时间通过使用优先级队列来完成。但是当我读到实际的解释或伪代码时,我总觉得它并不比O(N^3)
好。
本质上,算法如下:
For an input sequence of size N:
Create a distance matrix of NxN #(this is O(N^2) time)
For each row in the distance matrix:
Create a priority queue (binary heap) of all distances in the row
Then:
For i in 0 to N-1:
Find the min element among all N priority queues # O(N)
Let k = the row index of the min element
For each element e in the kth row:
Merge the min element with it's nearest neighbor
Update the corresponding values in the distance matrix
Update the corresponding value in priority_queue[e]
因此这是最后一步,对我而言,似乎使这是一个O(N^3)
算法。如果没有在O(N)
时间内扫描队列,就无法“更新”优先队列中的任意值 - 假设优先队列是二进制堆。 (一个二进制堆让你可以连续访问最小元素和插入/删除,但不能简单地按值查找元素,优于O(N)
时间)。因为我们会扫描每个行元素的优先级队列,所以我们得到了(O(N^3))
。
优先级队列由距离值分类 - 但所讨论的算法要求在其对应于k
,在最小元件的距离矩阵的行索引的优先级队列中删除的元素。再次,没有O(N)
扫描,无法在队列中找到此元素。
所以,我认为我可能是错误的,因为其他人都说不是。有人可以解释这个算法怎么样,不知何故不是O(N^3)
,但实际上,O(N^2 logN)
?
你知道0.5 * n^2还在O(n^2)吗? **节省一半的矩阵不会减少渐近复杂度**。而你错认“互惠”。你用它的方式,你说d(x,y)= 1/d(y,x)但距离是对称的而不是互易的? –
这意味着找到互补(更好的词)优先级队列条目是O(1)。全局最小值表示两次,两者都必须在其优先级队列中的第一个条目。 –
以上方法使用(出于一个很好的原因)每个条目有一个优先级队列,因为否则每次都需要丢弃O(n)个条目。 –