RDKit::INT_VECT HierarchicalClusterPicker::pick(const double *distMat, unsigned int poolSize, unsigned int pickSize) const { PRECONDITION(distMat,"bad distance matrix"); RDKit::VECT_INT_VECT clusters = this->cluster(distMat, poolSize, pickSize); CHECK_INVARIANT(clusters.size() == pickSize, ""); // the last step: find a representative element from each of the // remaining clusters RDKit::INT_VECT picks; for (unsigned int i = 0; i < pickSize; i++) { int pick; double minSumD2 = RDKit::MAX_DOUBLE; for (RDKit::INT_VECT_CI cxi1 = clusters[i].begin(); cxi1 != clusters[i].end(); ++cxi1 ) { int curPick = (*cxi1); double d2sum = 0.0; for (RDKit::INT_VECT_CI cxi2 = clusters[i].begin(); cxi2 != clusters[i].end(); ++cxi2) { if (cxi1 == cxi2) { continue; } double d = getDistFromLTM(distMat, curPick, (*cxi2)); d2sum += (d*d); } if (d2sum < minSumD2) { pick = curPick; minSumD2 = d2sum; } } picks.push_back(pick); } return picks; }