- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
警告:相当长的问题,也许太长了。如果是这样,我深表歉意。
我正在开发一个涉及 kd 树的最近邻搜索的程序(在本例中,它是一棵具有 3961 个独立点的 11 维树)。我们才刚刚了解它们,虽然我很好地掌握了这棵树的作用,但当涉及到最近邻搜索时,我感到非常困惑。
我设置了一个二维点数组,每个点都包含质量和位置,如下所示。
struct point{
double quality;
double location;
}
// in main
point **parray;
// later points to an array of [3961][11] points
然后我转换数据使其具有零均值,并针对单位方差重新调整它。我不会发布代码,因为它对我的问题并不重要。之后,我按照如下随机顺序将点构建到树中:
struct Node {
point *key;
Node *left;
Node *right;
Node (point *k) { key = k; left = right = NULL; }
};
Node *kd = NULL;
// Build the data into a kd-tree
random_shuffle(parray, &parray[n]);
for(int val=0; val<n; val++) {
for(int dim=1; dim<D+1; dim++) {
kd = insert(kd, &parray[val][dim], dim);
}
}
非常标准的东西。如果我错误地使用了 random_shuffle(),或者如果我的树的结构有任何固有的错误,请告诉我。它应该打乱 parray 的第一个维度,同时保持每个维度的 11 个维度按顺序保持不变。
现在我开始研究 neighbor() 函数,这就是我感到困惑的地方。
neighbor() 函数(后半部分是伪代码,坦率地说,我不知道从哪里开始):
Node *neighbor (Node *root, point *pn, int d,
Node *best, double bestdist) {
double dist = 0;
// Recursively move down tree, ignore the node we are comparing to
if(!root || root->key == pn) return NULL;
// Dist = SQRT of the SUMS of SQUARED DIFFERENCES of qualities
for(int dim=1; dim<D+1; dim++)
dist += pow(pn[d].quality - root->key->quality, 2);
dist = sqrt(dist);
// If T is better than current best, current best = T
if(!best || dist<bestdist) {
bestdist = dist;
best = root;
}
// If the dist doesn't reach a plane, prune search, walk back up tree
// Else traverse down that tree
// Process root node, return
}
这是 main() 中对 neighbor 的调用,大部分未完成。我不确定 main() 中应该包含什么以及 neighbor() 函数中应该包含什么:
// Nearest neighbor(s) search
double avgdist = 0.0;
// For each neighbor
for(int i=0; i<n; i++) {
// Should this be an array/tree of x best neighbors to keep track of them?
Node *best;
double bestdist = 1000000000;
// Find nearest neighbor(s)?
for(int i=0; i<nbrs; i++) {
neighbor(kd, parray[n], 1, best, &bestdist);
}
// Determine "distance" between the two?
// Add to total dist?
avgdist += bestdist;
}
// Average the total dist
// avgdist /= n;
如您所见,我卡在了最后两段代码中。几天来我一直在为此绞尽脑汁,但我仍然被困住了。它很快就会到期,所以当然感谢任何和所有帮助。提前致谢。
最佳答案
kd-tree 不涉及洗牌。
事实上,您会希望使用排序(或更好的快速选择)来构建树。
首先求解 最近邻 (1NN)。一旦你让这部分开始工作,应该很清楚如何找到 kNN,方法是保留一堆最佳候选对象,并使用第 k 个点进行修剪。
关于c++ - 在 KD 树中寻找最近的邻居,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27308281/
假设您有一个对象列表,每个对象都需要计算距离它最近的对象以进行拍摄。这个对象有一个 x 和一个 y 值。物体也在移动。 kd树还有用吗?我不确定,因为如果物体在移动,你必须继续创建这个 kd 树。 我
我正在查看 KD 树的维基百科页面。例如,我在 python 中实现了用于构建列出的 kd 树的算法。 但是,使用 KD 树进行 KNN 搜索的算法会切换语言并且并不完全清楚。英文解释开始有意义,但它
Kd 算法首先通过划分基元数组(三角形、球体等)来创建根 BSP 节点,以便创建两个新数组(左基元和右基元),用于创建其两个基元子树。 左基元和右基元是通过将给定基元数组划分为两个数组来计算的。通过取
我(尝试)在Processing/Java中实现KD树,并遵循我在数十篇文章和维基百科文章中看到的逻辑,但我一定做错了什么,因为输出如下所示: 而不是这个: 显然有些东西不对劲,因为节点是重复的,而且
我有以下路径数据: id1 p1 p2 0 1 7.935 5.103 1 1 7.93
我正在阅读 C 中的 kd 树实现。这是其中的一些部分。问题出在 findmedian 函数中。我不明白 的实现 *md = start +(end-start)/2; ...... -> 其他不相关
给定一组数据点,kdtree是在它们之上创建的,但是这个 kdtree 是唯一的吗? 最佳答案 这似乎取决于您构建树的方式。维基百科文章提到中点的选择如何影响生成的树是否平衡。如果选择不同的点,那么树
警告:相当长的问题,也许太长了。如果是这样,我深表歉意。 我正在开发一个涉及 kd 树的最近邻搜索的程序(在本例中,它是一棵具有 3961 个独立点的 11 维树)。我们才刚刚了解它们,虽然我很好地掌
我目前正在尝试构建二维(纬度和经度)的 KD 树以查询最近的坐标。我将坐标(ID、纬度、经度)推送到一个 vector 中,并将该 vector 传递到我的 KD-Tree 的构造函数中。 但是当我在
我正在尝试为我的 C++ (DirectX) 项目实现一个 kd-tree 以加速我的碰撞检测。我的实现是一个非常原始的递归函数。第 nth_element 似乎工作正常(如果我将其注释掉,则只有 1
我为两组点构建了 kd 树,以便找到两组点之间最接近的双色配对: kd 树存储为 python 字典,可以在下面的代码中找到,并传递给一个函数('closest'),该函数旨在同时递归地分析两棵树以找
我正在尝试基于递归构建一个二维树。我可以将算法总结如下: > ALGORITHM BuildKDTree(P,depth) > 1. if P contains only one po
我想从平衡的 KD 树中删除一个元素,并且树在不重建整棵树的情况下保持平衡。这有可能在不重建整棵树的情况下平衡树吗?如果是那么怎么办? 最佳答案 对于标准的 k-d 树,您可以删除项目但没有重新平衡,
所以我们有一个无限的 3d 世界,我们需要查询最近的点。然而我们的点有标识符并且一直在移动。支持数据点的 KDtree\Octree 之类的数据结构是什么。连续移动并且在搜索+更新方面不会比 3d 情
你好,有人用 C++ 迭代实现了 Kd-Tree 吗?我试过了,但是当节点数为奇数时它失败了。到目前为止,这是我的代码。我指的是 http://ldots.org/kdtree/#buildingAk
我想扩展一个 kd-tree (2D) 类,以便能够删除节点(点)。这种移除应该在不必重建树的大部分的情况下进行。这些slides中描述的算法,在幻灯片 13 上似乎是我所追求的。但是,我无法理解幻灯
普通的kd-tree是通过递归地将超平面分成两半来构建的。并且用一个查询点做范围搜索,它只会搜索一小串点(对数)而不是所有(线性)。 我想知道 kd 树可以用点积构建吗? 例如,b 是一个 3d 向量
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我刚刚完成了一个 kd-tree 的实现用于进行快速最近邻搜索。除了 Euclidean distance 之外,我有兴趣使用不同的距离指标。 .我对 kd-tree 的理解是,如果度量是非欧几里德的
我使用了 kd-tree algoritham 和 make tree。 但是我发现树不平衡所以我的问题是如果我们使用 kd-tree algoritham 那棵树总是平衡的如果不是那么我们怎样才能使
我是一名优秀的程序员,十分优秀!