- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
为了使聚类成为一项更可行的任务,我想从数组中删除项目,如果它们有另一个项目在 n 维欧几里德空间中的某个阈值内。此截断的输入数据是像素级特征向量数组。我的第一个想法是计算所有项目之间的成对欧氏距离矩阵,然后对它们进行操作:
indices = list(range(len(X)))
dist_matrix = euclidean_distances(X,X)
index = 0
while True:
deletion = np.where(dist_matrix[index]<=threshold)[0]
indices = [i for i in indices if i==index or i not in deletion]
try:
index = indices[indices.index(index) + 1]
except IndexError:
break
dictionary = []
for index in indices:
dictionary.append(X[index])
但是,当使用 sklearn.metrics.pairwise.euclidean_distances 创建距离矩阵时,这会导致我的大型数据集出现内存错误。执行此操作的有效、内存保守的方式是什么?我已经意识到这个距离矩阵的计算是导致聚类算法出现问题的原因,所以我希望能够通过截断输入数组来避免计算这么大的距离矩阵。
最佳答案
根据维度数 n、点数 N、每个维度中问题的大小 L 以及您可接受的分隔距离 d,一种选择是将您的空间划分为维度 d 的框并最多保留每个网格框中的一个点。内存需求将从 O(N^2) 变为 O((L/d)^n),运行时间将从 O(N^2) 变为 O(N + (L/d)^n),因此如果 L/d 和 n 不太大,它可能会更有效。
或者,使用以下算法可能是实用的
for each point p in points
for each point q in points
if p <> q and p.dist(q) < Dmin
q.delete
这应该是 O(N^2) 的运行时间和 O(0) 的额外内存。
关于python - 如果向量在欧几里德空间中距离太近,则使用快速/内存保护方式从数组中删除向量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39130072/
在我们的服务出现一些预期的增长之后,突然间一些更新花费了非常长的时间,这些过去非常快,直到表达到大约 2MM 记录,现在它们每个需要大约 40-60 秒。 update table1 set fiel
我在服务中实现了一个传感器事件监听器,只要采样周期和最大报告延迟低于 1 秒,该监听器就可以正常工作,但一旦我将采样周期增加到超过 1 秒,传感器就根本不会更新。 我希望采样周期为 10 秒(可能是
我使用 Tkinter GUI 来启动测量和分析过程,基本上只需单击一个按钮即可开始。由于这些测量可能需要一段时间,我尝试添加一个进度条,即这个: http://tkinter.unpythonic.
我正在尝试使用套接字发送数据包,但出现错误。 invalid conversion from ‘omnetpp::cPacket*’ to ‘inet::Packet*’ [-fpermissive]
我刚刚发现 String#split 有以下奇怪的行为: "a\tb c\nd".split => ["a", "b", "c", "d"] "a\tb c\nd".split(' ') => ["a
您好,我正在尝试 ClojureScript,我正在使用 Klipse作为我的 REPL 差不多。这可能不是它的预期用途,但因为我没有做任何太复杂的事情,所以现在没问题。 我遇到的一个问题是尝试设置计
根据下面的数据,ClockKit 会生成一次 future 的 CLKComplicationTimelineEntry 项,但对于过去的时间点,会进行 24 次调用!这是为什么? 更多详情: 我注意
我有一个 MySQL 表,这个表有一个名为 datetime_utc 的 DATETIME 列。如您所料,它是 UTC 日期和时间。在我的 Bookshelf 模型中,我定义了一个虚拟 getter,
大家好,我是二哥呀! 昨天,一位球友问我能不能给他解释一下 @SpringBootApplication 注解是什么意思,还有 Spring Boot 的运行原理,于是我就带着他扒拉了一下这个注解的源
我是一名优秀的程序员,十分优秀!