本文整理汇总了C++中CoverTree::kNearestNeighbors方法的典型用法代码示例。如果您正苦于以下问题:C++ CoverTree::kNearestNeighbors方法的具体用法?C++ CoverTree::kNearestNeighbors怎么用?C++ CoverTree::kNearestNeighbors使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CoverTree
的用法示例。
在下文中一共展示了CoverTree::kNearestNeighbors方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
SGMatrix<int32_t> CKernelLocallyLinearEmbedding::get_neighborhood_matrix(SGMatrix<float64_t> kernel_matrix, int32_t k)
{
int32_t i;
int32_t N = kernel_matrix.num_cols;
int32_t* neighborhood_matrix = SG_MALLOC(int32_t, N*k);
float64_t max_dist=0.0;
for (i=0; i<N; i++)
max_dist = CMath::max(max_dist,kernel_matrix[i*N+i]);
std::vector<KLLE_COVERTREE_POINT> vectors;
vectors.reserve(N);
for (i=0; i<N; i++)
vectors.push_back(KLLE_COVERTREE_POINT(i,kernel_matrix));
CoverTree<KLLE_COVERTREE_POINT>* coverTree = new CoverTree<KLLE_COVERTREE_POINT>(2.0*max_dist,vectors);
for (i=0; i<N; i++)
{
std::vector<KLLE_COVERTREE_POINT> neighbors =
coverTree->kNearestNeighbors(vectors[i],k+1);
ASSERT(neighbors.size()>=unsigned(k+1));
for (std::size_t m=1; m<unsigned(k+1); m++)
neighborhood_matrix[i*k+m-1] = neighbors[m].point_index;
}
delete coverTree;
return SGMatrix<int32_t>(neighborhood_matrix,k,N);
}
示例2:
SGMatrix<int32_t> CLocallyLinearEmbedding::get_neighborhood_matrix(SGMatrix<float64_t> distance_matrix, int32_t k)
{
int32_t i;
int32_t N = distance_matrix.num_rows;
int32_t* neighborhood_matrix = SG_MALLOC(int32_t, N*k);
float64_t max_dist = SGVector<float64_t>::max(distance_matrix.matrix,N*N);
CoverTree<LLE_COVERTREE_POINT>* coverTree = new CoverTree<LLE_COVERTREE_POINT>(max_dist);
for (i=0; i<N; i++)
coverTree->insert(LLE_COVERTREE_POINT(i,distance_matrix));
for (i=0; i<N; i++)
{
std::vector<LLE_COVERTREE_POINT> neighbors =
coverTree->kNearestNeighbors(LLE_COVERTREE_POINT(i,distance_matrix),k+1);
for (std::size_t m=1; m<unsigned(k+1); m++)
neighborhood_matrix[i*k+m-1] = neighbors[m].point_index;
}
delete coverTree;
return SGMatrix<int32_t>(neighborhood_matrix,k,N);
}
示例3:
SGMatrix<int32_t> CStochasticProximityEmbedding::get_neighborhood_matrix(CDistance* distance, int32_t k, int32_t N, float64_t max_dist)
{
int32_t i;
int32_t* neighborhood_matrix = SG_MALLOC(int32_t, N*k);
CoverTree<SPE_COVERTREE_POINT>* coverTree = new CoverTree<SPE_COVERTREE_POINT>(max_dist);
for (i=0; i<N; i++)
coverTree->insert(SPE_COVERTREE_POINT(i, distance));
for (i=0; i<N; i++)
{
std::vector<SPE_COVERTREE_POINT> neighbors =
coverTree->kNearestNeighbors(SPE_COVERTREE_POINT(i, distance), k+1);
for (std::size_t m=1; m<unsigned(k+1); m++)
neighborhood_matrix[i*k+m-1] = neighbors[m].m_point_index;
}
delete coverTree;
return SGMatrix<int32_t>(neighborhood_matrix,k,N);
}