C++ 聚类与点关联
我正在使用DBScan算法对一组点进行聚类。我有一组点的ID,还有一组簇,每个簇都有一组点。 我想在集群和点ID之间建立关联 例如,我有一组ID{1,2,3,4},现在如果我有两个簇,两个簇有两个点,那么第一个簇的这两个点应该有ID 1,2,第二个簇的ID为3,4。另外,如果我有4个簇,每个簇有一个点,那么这些点的ID应该是1、2、3和4。此外,如果我有两个簇,但一个簇有3个点,另一个簇有一个点,那么第一个簇的点的ID应该是1,2,3,第二个簇的点的ID应该是4 我试图编写代码,但我在计算公式以实现该场景时停了下来C++ 聚类与点关联,c++,algorithm,computer-vision,C++,Algorithm,Computer Vision,我正在使用DBScan算法对一组点进行聚类。我有一组点的ID,还有一组簇,每个簇都有一组点。 我想在集群和点ID之间建立关联 例如,我有一组ID{1,2,3,4},现在如果我有两个簇,两个簇有两个点,那么第一个簇的这两个点应该有ID 1,2,第二个簇的ID为3,4。另外,如果我有4个簇,每个簇有一个点,那么这些点的ID应该是1、2、3和4。此外,如果我有两个簇,但一个簇有3个点,另一个簇有一个点,那么第一个簇的点的ID应该是1,2,3,第二个簇的点的ID应该是4 我试图编写代码,但我在计算公式以
std::vector<int>_IDs;
// for each cluster
for( int j = 0; j<clusters.size();j++ )
{
// for each point in that cluster
for ( int i=0; i < clusters[j].m_Points.size(); i++)
{
// assign its ID from the _IDs array based and save it in Clusters Vector
clusters[j].m_IDs.push_back(_IDs[j+ i*clusters[j].m_Points.size()]);
}
}
std::vector\u id;
//对于每个集群
对于(int j=0;j,我会这样写:
std::vector<int>_IDs; // those come in from wherever
std::vector<int>::const_iterator id = _IDs.begin();
// for each cluster
for( int j = 0; j<clusters.size(); ++j )
{
// for each point in that cluster
for ( int i=0; i < clusters[j].m_Points.size(); i++)
{
// some external logic should take care that there are enough ids
// for all points in clusters. sanity check it here.
assert(id != _IDs.end());
// assign its ID from the _IDs array based and save it in Clusters Vector
clusters[j].m_IDs.push_back(*id);
++id;
}
}
std::vector_IDs;//它们来自任何地方
std::vector::const_迭代器id=_id.begin();
//对于每个集群
对于(int j=0;j