本文整理汇总了C++中Neighborhood::first方法的典型用法代码示例。如果您正苦于以下问题:C++ Neighborhood::first方法的具体用法?C++ Neighborhood::first怎么用?C++ Neighborhood::first使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Neighborhood
的用法示例。
在下文中一共展示了Neighborhood::first方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ClusterGallery
// Zhu et al. "A Rank-Order Distance based Clustering Algorithm for Face Tagging", CVPR 2011
br::Clusters br::ClusterGallery(const QStringList &simmats, float aggressiveness, const QString &csv)
{
qDebug("Clustering %d simmat(s)", simmats.size());
// Read in gallery parts, keeping top neighbors of each template
Neighborhood neighborhood = getNeighborhood(simmats);
const int cutoff = neighborhood.first().size();
const float threshold = 3*cutoff/4 * aggressiveness/5;
// Initialize clusters
Clusters clusters(neighborhood.size());
for (int i=0; i<neighborhood.size(); i++)
clusters[i].append(i);
bool done = false;
while (!done) {
// nextClusterIds[i] = j means that cluster i is set to merge into cluster j
QVector<int> nextClusterIDs(neighborhood.size());
for (int i=0; i<neighborhood.size(); i++) nextClusterIDs[i] = i;
// For each cluster
for (int clusterID=0; clusterID<neighborhood.size(); clusterID++) {
const Neighbors &neighbors = neighborhood[clusterID];
int nextClusterID = nextClusterIDs[clusterID];
// Check its neighbors
foreach (const Neighbor &neighbor, neighbors) {
int neighborID = neighbor.first;
int nextNeighborID = nextClusterIDs[neighborID];
// Don't bother if they have already merged
if (nextNeighborID == nextClusterID) continue;
// Flag for merge if similar enough
if (normalizedROD(neighborhood, clusterID, neighborID) < threshold) {
if (nextClusterID < nextNeighborID) nextClusterIDs[neighborID] = nextClusterID;
else nextClusterIDs[clusterID] = nextNeighborID;
}
}
}
// Transitive merge
for (int i=0; i<neighborhood.size(); i++) {
int nextClusterID = i;
while (nextClusterID != nextClusterIDs[nextClusterID]) {
assert(nextClusterIDs[nextClusterID] < nextClusterID);
nextClusterID = nextClusterIDs[nextClusterID];
}
nextClusterIDs[i] = nextClusterID;
}
// Construct new clusters
QHash<int, int> clusterIDLUT;
QList<int> allClusterIDs = QSet<int>::fromList(nextClusterIDs.toList()).values();
for (int i=0; i<neighborhood.size(); i++)
clusterIDLUT[i] = allClusterIDs.indexOf(nextClusterIDs[i]);
Clusters newClusters(allClusterIDs.size());
Neighborhood newNeighborhood(allClusterIDs.size());
for (int i=0; i<neighborhood.size(); i++) {
int newID = clusterIDLUT[i];
newClusters[newID].append(clusters[i]);
newNeighborhood[newID].append(neighborhood[i]);
}
// Update indices and trim
for (int i=0; i<newNeighborhood.size(); i++) {
Neighbors &neighbors = newNeighborhood[i];
int size = qMin(neighbors.size(),cutoff);
std::partial_sort(neighbors.begin(), neighbors.begin()+size, neighbors.end(), compareNeighbors);
for (int j=0; j<size; j++)
neighbors[j].first = clusterIDLUT[j];
neighbors = neighbors.mid(0, cutoff);
}
// Update results
done = true; //(newClusters.size() >= clusters.size());
clusters = newClusters;
neighborhood = newNeighborhood;
}