- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一个包含约 200,000 个点的二维数组,并希望“抖动”这些点,使任何点与其最近邻点之间的距离 >= 某个最小值。
在从头开始编写这个算法之前,我想问:是否有任何规范的方法或常用的算法来实现这个行为?我认为在着手解决这个问题之前先回顾一下这些算法是有意义的。
如果其他人可以就此问题提出任何建议,我们将不胜感激。
最佳答案
我最终使用了一种名为 "Lloyd iteration" 的技术解决这个问题。该算法背后的想法非常简单;要在一组点上运行 Lloyd 迭代,我们:
This gist有一些示例代码(带有可视化效果):
from lloyd import Field
from scipy.spatial import voronoi_plot_2d
import matplotlib.pyplot as plt
import numpy as np
import umap, os
def plot(vor, name, e=0.3):
'''Plot the Voronoi map of 2D numpy array X'''
plot = voronoi_plot_2d(vor, show_vertices=False, line_colors='y', line_alpha=0.5, point_size=5)
plot.set_figheight(14)
plot.set_figwidth(20)
plt.axis([field.bb[0]-e, field.bb[1]+e, field.bb[2]-e, field.bb[3]+e])
if not os.path.exists('plots'): os.makedirs('plots')
if len(str(name)) < 2: name = '0' + str(name)
plot.savefig( 'plots/' + str(name) + '.png' )
# get 1000 observations in two dimensions and plot their Voronoi map
np.random.seed(1144392507)
X = np.random.rand(1000, 4)
X = umap.UMAP().fit_transform(X)
# run 20 iterations of Lloyd's algorithm
field = Field(X)
for i in range(20):
print(' * running iteration', i)
plot(field.voronoi, i)
field.relax()
结果是点的移动就像它们在下面的 gif 中一样:
注意:上面的 gif 显示了无约束的 Lloyd 迭代,其中输出域可能非常大。对于在 Python 中构造约束 Lloyd 迭代的一些讨论和代码,我写了一点 blog post .
关于Python:确保每个成对距离 >= 某个最小距离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51214496/
我有 X 个值通过 CSV 传递到表中 - 因此我将 99315,99316,99223 并将它们拆分到单列临时表中 - CSV 中的每个值都放入一行。 我需要做的是获得成对的值的每个排列 -所以 -
我已经看到了几个关于如何生成数组中元素的所有可能组合的类似问题。但是我很难弄清楚如何编写一个只输出对组合的算法。任何建议将不胜感激! 从以下数组开始(有 N 个元素): var array = ["a
基本上我想做这样的查询: SELECT * FROM `table` WHERE (`c1`,`c2`) in (('a','b'),('c','d')) 我尝试了一些方法,但找不到任何关于如何实现的
我声明了一个 vector 对: vector > args; 然后我想像这样将一对插入 vector : args.push_back((1,-1)); 它告诉我逗号的左边操作数没有作用。我哪里出
我正在用给定的对填充 vector 的邻接列表: vector> adj[1000]; 我正在对列表进行深度优先搜索,但遇到了一些奇怪的行为。第一个 print 语句打印一些值,这意味着我在 adj[
这个问题Mysql Select some random rows and plus one specific row非常接近我想要的,只是我不知道如何将 ORDER BY 应用于我的情况。 当有人接
我在字符串向量中有大量文本(大约 700.000 个字符串)。我正在尝试替换语料库中的特定单词/短语。也就是说,我有一个包含 app 40.000 个短语的向量和一个相应的替换向量。 我正在寻找解决问
我正在寻找一种方法来找到第 2 组(对)的集群。 有没有一种简单的方法可以做到这一点? 想象一下,我有某种数据想要匹配 x和 y , 喜欢 library(cluster) set.seed(1) d
我必须正确编码 5 个 XML 保留字符(& "和 '),如下所示: "&", "&" "", ">" "\"", """ "\'", "'" 我可以一一做,
我正在处理我的作品集。我在正文中有图像我希望图像应该只使用 css/css3/Jquery 对 Angular 线而不是通过 photoshop 编辑我已经尝试对正文使用变换旋转。 但我没有得到结果。
我带着类似的问题又回来了。是否有可以返回其特定合作伙伴的数据类型?例如: ExampleType test = new ExampleType(); test.put("hello","hi"); 如
我正在对我的数据运行事后 Tukey HSD,该数据有 10 个因子级别。该表很大,我希望在成对的表中向读者展示 p 值,将 45 行表留给附录。 这是一个示例数据集: set.seed(42) x
我正在对我的数据运行事后 Tukey HSD,该数据有 10 个因子级别。该表很大,我希望在成对的表中向读者展示 p 值,将 45 行表留给附录。 这是一个示例数据集: set.seed(42) x
我想根据 std::pair 的 std::vector 找到 std::lower_bound second 元素与 lambda。 std::vector > vec; vec.resize(5
得到这个简单的python代码,和re.compile实例一样匹配。我注意到,即使我使用的是完全相同的值,它也会创建两个实例,并相应地重复它们。 我想知道是否有人可以说出这种行为的原因, 为什么要创建
首先,我是 C++ 的新手,所以我可能不得不深入研究伪代码和/或 Python 来解释我正在尝试做的事情... 我正在尝试为动画的每一帧存储多个 Sprite 的 X 和 Y 坐标对。我设想这类似于以
test1和test2在内存中的布局是否相同? std::vector > test1; std::vector test2; 其中 mystruct 定义为: struct mystru
我有这个代码: std::vector> vec; vec.emplace_back("a", 1); //success vec.emplace(vec.end(), "b", 2); //comp
跟进 this question ,我正在尝试制作箱线图和成对比较以再次显示显着性水平(仅针对重要的成对),但这次我有超过 2 个组要比较和更复杂的方面。 我将在此处使用 iris 数据集进行说明。检
我有一个 vector 对,如下所示。第一对值未排序,第二对值已排序(从零开始)。我可能想通过实现 std::vector 和 std::pair 来存储数据。当我有第一对值(未排序)时,找到相应的第
我是一名优秀的程序员,十分优秀!