Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to enable HDBSCAN #208

Merged
merged 40 commits into from
May 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
046f703
Allowing epilogue in knn graph connection function
cjnolet Apr 20, 2021
086b08a
Fixing style
cjnolet Apr 20, 2021
37d2e0d
Adding missing argument
cjnolet Apr 23, 2021
709c040
Fixing typename
cjnolet Apr 23, 2021
b1fbc63
Updates
cjnolet Apr 23, 2021
81b630a
Fixing style
cjnolet Apr 23, 2021
6c52542
Updating to get hdbscan to compile
cjnolet Apr 23, 2021
4be3d24
Some updates
cjnolet Apr 26, 2021
1aaa7d5
changes
cjnolet Apr 29, 2021
dd6e537
agglomerative labeling to accept device arrays directly
cjnolet Apr 30, 2021
e3085cb
Cleaning up inputs to some of the single linkage prims
cjnolet Apr 30, 2021
ec1cca5
removing deprecated rmm policy usage
divyegala May 4, 2021
d32677d
Changes
cjnolet May 5, 2021
43f7cf8
removing deprecated rmm policy usage
divyegala May 4, 2021
e0ef5b3
alpha to weight alteration for precision
divyegala May 10, 2021
d809630
merge
divyegala May 10, 2021
1678c66
resolving errors
divyegala May 10, 2021
8018ea5
merge again
divyegala May 10, 2021
404e5ce
Merge branch 'fea-020-hdbscan' of github.com:cjnolet/raft into fea-02…
divyegala May 10, 2021
5eda4aa
trying alpha for all
divyegala May 11, 2021
030b3a9
double precision weight alteration
divyegala May 12, 2021
635d018
Checking in
cjnolet May 14, 2021
26dff4d
Fixing style
cjnolet May 19, 2021
55f274c
Removing unused epilogue from mst
cjnolet May 19, 2021
eb69413
Removing mst epilogue functor
cjnolet May 19, 2021
9f39d69
Merge branch 'branch-0.20' into fea-020-hdbscan
cjnolet May 19, 2021
dfebf10
Merge branch 'branch-21.06' into fea-020-hdbscan
cjnolet May 19, 2021
50d1cdc
Getting test to build
cjnolet May 20, 2021
c654156
Removing mstepiloguenoop since it's no longer being used
cjnolet May 22, 2021
136529a
another template param for weight alteration
divyegala May 24, 2021
e4b0f91
merge upstream
divyegala May 24, 2021
d7e93d9
renaming confusing variable name
divyegala May 24, 2021
e51d08b
working through merge
divyegala May 26, 2021
beea020
merging mst template PR
divyegala May 26, 2021
86cbf42
removing unnecessary comments
divyegala May 26, 2021
eb92e26
Review feedback
cjnolet May 27, 2021
e337c0d
Merge branch 'branch-21.06' into fea-020-hdbscan
cjnolet May 27, 2021
8b1e344
Update cpp/include/raft/sparse/hierarchy/detail/agglomerative.cuh
cjnolet May 27, 2021
1933520
Fixing bad merge
cjnolet May 27, 2021
1bc3e68
Merge branch 'fea-020-hdbscan' of github.com:cjnolet/raft into fea-02…
cjnolet May 27, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Checking in
  • Loading branch information
cjnolet committed May 14, 2021
commit 635d018f687c82f571b7c511e7632400046fec6a
40 changes: 21 additions & 19 deletions cpp/include/raft/sparse/hierarchy/detail/mst.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ void merge_msts(raft::Graph_COO<value_idx, value_idx, value_t> &coo1,
* @param[inout] color the color labels array returned from the mst invocation
* @return updated MST edge list
*/
template <typename value_idx, typename value_t, typename mst_epilogue_f>
template <typename value_idx, typename value_t, typename mst_epilogue_f, typename red_op>
void connect_knn_graph(const raft::handle_t &handle, const value_t *X,
raft::Graph_COO<value_idx, value_idx, value_t> &msf,
size_t m, size_t n, value_idx *color,
mst_epilogue_f mst_epilogue_func,
mst_epilogue_f mst_epilogue_func, red_op reduction_op,
raft::distance::DistanceType metric =
raft::distance::DistanceType::L2SqrtExpanded) {
auto d_alloc = handle.get_device_allocator();
Expand All @@ -86,7 +86,7 @@ void connect_knn_graph(const raft::handle_t &handle, const value_t *X,
raft::sparse::COO<value_t, value_idx> connected_edges(d_alloc, stream);

raft::linkage::connect_components<value_idx, value_t>(handle, connected_edges,
X, color, m, n);
X, color, m, n, reduction_op);

mst_epilogue_func(handle, connected_edges.rows(), connected_edges.cols(),
connected_edges.vals(), connected_edges.nnz);
Expand All @@ -96,6 +96,9 @@ void connect_knn_graph(const raft::handle_t &handle, const value_t *X,
connected_edges.nnz, indptr2.data(),
m + 1, d_alloc, stream);

raft::print_device_vector("new_rows", connected_edges.rows(), connected_edges.nnz, std::cout);
raft::print_device_vector("new_cols", connected_edges.cols(), connected_edges.nnz, std::cout);
raft::print_device_vector("new_dists", connected_edges.vals(), connected_edges.nnz, std::cout);
// On the second call, we hand the MST the original colors
// and the new set of edges and let it restart the optimization process
auto new_mst = raft::mst::mst<value_idx, value_idx, value_t>(
Expand Down Expand Up @@ -129,39 +132,38 @@ void connect_knn_graph(const raft::handle_t &handle, const value_t *X,
* @param[in] max_iter maximum iterations to run knn graph connection. This
* argument is really just a safeguard against the potential for infinite loops.
*/
template <typename value_idx, typename value_t, typename mst_epilogue_f>
template <typename value_idx, typename value_t, typename mst_epilogue_f, typename red_op>
void build_sorted_mst(const raft::handle_t &handle, const value_t *X,
const value_idx *indptr, const value_idx *indices,
const value_t *pw_dists, size_t m, size_t n,
value_idx *mst_src, value_idx *mst_dst,
value_t *mst_weight, size_t nnz,
mst_epilogue_f epilogue_func,
value_t *mst_weight, value_idx *color, size_t nnz,
mst_epilogue_f epilogue_func, red_op reduction_op,
raft::distance::DistanceType metric =
raft::distance::DistanceType::L2SqrtExpanded,
int max_iter = 10) {
auto d_alloc = handle.get_device_allocator();
auto stream = handle.get_stream();

rmm::device_uvector<value_idx> color(m, stream);

// We want to have MST initialize colors on first call.
auto mst_coo = raft::mst::mst<value_idx, value_idx, value_t>(
handle, indptr, indices, pw_dists, (value_idx)m, nnz, color.data(), stream,
handle, indptr, indices, pw_dists, (value_idx)m, nnz, color, stream,
false, true);


int iters = 1;
int n_components =
linkage::get_n_components(color.data(), m, d_alloc, stream);
linkage::get_n_components(color, m, d_alloc, stream);

while (n_components > 1 && iters < max_iter) {
printf("Didn't converge. trying again\n");
connect_knn_graph<value_idx, value_t>(handle, X, mst_coo, m, n,
color.data(), epilogue_func);
color, epilogue_func, reduction_op);

iters++;

n_components = linkage::get_n_components(color.data(), m, d_alloc, stream);
n_components = linkage::get_n_components(color, m, d_alloc, stream);
}

/**
Expand All @@ -184,14 +186,14 @@ void build_sorted_mst(const raft::handle_t &handle, const value_t *X,
" or increase 'max_iter'",
max_iter);

if (mst_coo.n_edges != m - 1) {
raft::print_device_vector("mst_src", mst_coo.src.data(), mst_coo.n_edges,
std::cout);
raft::print_device_vector("mst_dst", mst_coo.dst.data(), mst_coo.n_edges,
std::cout);
raft::print_device_vector("mst_weight", mst_coo.weights.data(),
mst_coo.n_edges, std::cout);
}
// if (mst_coo.n_edges != m - 1) {
// raft::print_device_vector("mst_src", mst_coo.src.data(), mst_coo.n_edges,
// std::cout);
// raft::print_device_vector("mst_dst", mst_coo.dst.data(), mst_coo.n_edges,
// std::cout);
// raft::print_device_vector("mst_weight", mst_coo.weights.data(),
// mst_coo.n_edges, std::cout);
// }

RAFT_EXPECTS(mst_coo.n_edges == m - 1,
"n_edges should be %d but was %d. This"
Expand Down
6 changes: 4 additions & 2 deletions cpp/include/raft/sparse/hierarchy/single_linkage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,12 @@ void single_linkage(const raft::handle_t &handle, const value_t *X, size_t m,
/**
* 2. Construct MST, sorted by weights
*/
rmm::device_uvector<value_idx> color(m, stream);
raft::linkage::FixConnectivitiesRedOp<value_idx, value_t> op(color.data(), m);
detail::build_sorted_mst<value_idx, value_t>(
handle, X, indptr.data(), indices.data(), pw_dists.data(), m, n,
mst_rows.data(), mst_cols.data(), mst_data.data(), indices.size(),
MSTEpilogueNoOp<value_idx, value_t>(), metric);
mst_rows.data(), mst_cols.data(), mst_data.data(), color.data(), indices.size(),
MSTEpilogueNoOp<value_idx, value_t>(), op, metric);

pw_dists.release();

Expand Down
12 changes: 6 additions & 6 deletions cpp/include/raft/sparse/selection/connect_components.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -200,23 +200,22 @@ struct LookupColorOp {
* @param[in] d_alloc device allocator to use
* @param[in] stream cuda stream for which to order cuda operations
*/
template <typename value_idx, typename value_t>
template <typename value_idx, typename value_t, typename red_op>
void perform_1nn(cub::KeyValuePair<value_idx, value_t> *kvp,
value_idx *nn_colors, value_idx *colors, const value_t *X,
size_t n_rows, size_t n_cols,
std::shared_ptr<raft::mr::device::allocator> d_alloc,
cudaStream_t stream) {
cudaStream_t stream, red_op reduction_op) {
rmm::device_uvector<int> workspace(n_rows, stream);
rmm::device_uvector<value_t> x_norm(n_rows, stream);

raft::linalg::rowNorm(x_norm.data(), X, n_cols, n_rows, raft::linalg::L2Norm,
true, stream);

FixConnectivitiesRedOp<value_idx, value_t> red_op(colors, n_rows);
raft::distance::fusedL2NN<value_t, cub::KeyValuePair<value_idx, value_t>,
value_idx>(kvp, X, X, x_norm.data(), x_norm.data(),
n_rows, n_rows, n_cols, workspace.data(),
red_op, red_op, true, true, stream);
reduction_op, reduction_op, true, true, stream);

LookupColorOp<value_idx, value_t> extract_colors_op(colors);
thrust::transform(thrust::cuda::par.on(stream), kvp, kvp + n_rows, nn_colors,
Expand Down Expand Up @@ -318,11 +317,12 @@ void min_components_by_color(raft::sparse::COO<value_t, value_idx> &coo,
* @param[in] n_rows number of rows in X
* @param[in] n_cols number of cols in X
*/
template <typename value_idx, typename value_t>
template <typename value_idx, typename value_t, typename red_op>
void connect_components(const raft::handle_t &handle,
raft::sparse::COO<value_t, value_idx> &out,
const value_t *X, const value_idx *orig_colors,
size_t n_rows, size_t n_cols,
red_op reduction_op,
raft::distance::DistanceType metric =
raft::distance::DistanceType::L2SqrtExpanded) {
auto d_alloc = handle.get_device_allocator();
Expand Down Expand Up @@ -352,7 +352,7 @@ void connect_components(const raft::handle_t &handle,
rmm::device_uvector<value_idx> src_indices(n_rows, stream);

perform_1nn(temp_inds_dists.data(), nn_colors.data(), colors.data(), X,
n_rows, n_cols, d_alloc, stream);
n_rows, n_cols, d_alloc, stream, reduction_op);

/**
* Sort data points by color (neighbors are not sorted)
Expand Down