Skip to content

Instantly share code, notes, and snippets.

@whoishu
Forked from jdeng/cluster
Created July 3, 2014 12:02
Show Gist options
  • Save whoishu/34b61d5bdbb4180a35da to your computer and use it in GitHub Desktop.
Save whoishu/34b61d5bdbb4180a35da to your computer and use it in GitHub Desktop.
auto dist = [n, &dists](size_t i, size_t j) { return dists[i * n + j]; } // dists is pre-calculated n x n distances matrix
auto index = seq(n); //[0,...,n-1]
std::vector<size_t> rho(n);
for (size_t i=0; i<n; ++i) {
rho[i] = std::count_if(index.begin(), index.end(), [&](size_t j) { return dist(i,j) < dist_cutoff; });
}
std::vector<D> delta(n);
for (size_t i=0; i<n; ++i) {
auto it = std::min_element_if(index.begin(), index.end(), [&](size_t j, size_t k) { return dist(i,j) < dist(i,k); }, [&](size_t j) { return rho[j] > rho[i]; });
if (it == index.end())
it = std::max_element(index.begin(), index.end(), [&](size_t j, size_t k) { return dist(i,j) < dist(i,k); });
delta[i] = dist(i, *it);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment