-
Notifications
You must be signed in to change notification settings - Fork 86
Leiden and Louvain Sequential Algorithms #417
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
Draft
GomezGab
wants to merge
13
commits into
v1.3.x
Choose a base branch
from
gg/leiden
base: v1.3.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
39c6f7e
Improve performance for calculating modularity metric
GomezGab 7522000
[WIP] Leiden implementation with GraphBLAS
GomezGab 124c836
[WIP] Break up Leiden phases into helper functions
GomezGab d052ed7
Leiden initial tests passing
GomezGab 7314b99
bug fixes for Leiden
GomezGab 621f5ba
more bug fixes
GomezGab 20b48f7
improve preformance by bypassing costly ops
GomezGab 733623b
Change ModularityMatrix, update tests, and update leiden
GomezGab 2ec46f3
Allow splitting in Leiden Phase 1
GomezGab f81b402
work around 10.3.0 crash
GomezGab 80efae4
[wip] louvain
swilly22 00b6a9e
[WIP] Louvain
GomezGab a630bcb
use more graphblas functions for louvain
GomezGab File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -27,101 +27,92 @@ | |||||||
|
|
||||||||
| // Current Test File: experimental/test/test_modularity.c | ||||||||
|
|
||||||||
| #include "GraphBLAS.h" | ||||||||
| #include "LG_internal.h" | ||||||||
| #include <LAGraphX.h> | ||||||||
| #include <stdio.h> | ||||||||
|
|
||||||||
| #define LG_FREE_MOD \ | ||||||||
| { \ | ||||||||
| GrB_free(&k); \ | ||||||||
| GrB_free(&kk_); \ | ||||||||
| GrB_free(&B); \ | ||||||||
| GrB_free(&BS); \ | ||||||||
| GrB_free(&S_BS); \ | ||||||||
| GrB_free(&Diag); \ | ||||||||
|
|
||||||||
| #undef LG_FREE_WORK | ||||||||
| #define LG_FREE_WORK \ | ||||||||
| { \ | ||||||||
| GrB_free (&k); \ | ||||||||
| GrB_free (&B); \ | ||||||||
| GrB_free (&S_t); \ | ||||||||
| } | ||||||||
| #undef LG_FREE_ALL | ||||||||
| #define LG_FREE_ALL \ | ||||||||
| { \ | ||||||||
| LG_FREE_MOD; \ | ||||||||
| } | ||||||||
| #define DEBUG 0 | ||||||||
| #if DEBUG | ||||||||
| #define check() printf("here") | ||||||||
| #define dbg(x) \ | ||||||||
| if (DEBUG) \ | ||||||||
| GxB_print(x, 5) | ||||||||
| #define err(x, info) \ | ||||||||
| if (!(info == GrB_SUCCESS || info == GrB_NO_VALUE)) \ | ||||||||
| { \ | ||||||||
| char **err; \ | ||||||||
| GrB_error(err, x); \ | ||||||||
| printf("\ninfo: %d error: %s\n", info, err); \ | ||||||||
| LG_FREE_WORK; \ | ||||||||
| } | ||||||||
| #else | ||||||||
| #define check() | ||||||||
| #define dbg(x) | ||||||||
| #define err(x, info) | ||||||||
| #endif | ||||||||
|
|
||||||||
| int LAGr_AdjModularity( | ||||||||
| int LAGr_AdjModularity ( | ||||||||
| double *Q, | ||||||||
| double gamma, | ||||||||
| GrB_Matrix A, | ||||||||
| GrB_Matrix S, | ||||||||
| const GrB_Matrix A, | ||||||||
| const GrB_Matrix S, | ||||||||
| char *msg) | ||||||||
| { | ||||||||
| #if LG_SUITESPARSE_GRAPHBLAS_V10_2 | ||||||||
| LG_CLEAR_MSG; | ||||||||
| char MATRIX_TYPE[LAGRAPH_MSG_LEN]; | ||||||||
|
|
||||||||
| // GrB_set(GrB_GLOBAL, false, GxB_BURBLE); | ||||||||
|
|
||||||||
| GrB_Index n; | ||||||||
| GrB_Matrix k = NULL; | ||||||||
| GrB_Matrix kk_ = NULL; | ||||||||
| GrB_Index nrows, ncols, nrows_s, ncols_s; | ||||||||
| GrB_Vector k = NULL, com_deg = NULL; | ||||||||
| GrB_Matrix B = NULL; | ||||||||
| GrB_Matrix BS = NULL; | ||||||||
| GrB_Matrix S_BS = NULL; | ||||||||
| GrB_Matrix Diag = NULL; | ||||||||
| GrB_Matrix mask = NULL; | ||||||||
| GrB_Matrix S_t = NULL; | ||||||||
|
|
||||||||
| GRB_TRY(GrB_Matrix_nrows(&n, A)); | ||||||||
| LG_ASSERT (A != NULL, GrB_NULL_POINTER) ; | ||||||||
| LG_ASSERT (S != NULL, GrB_NULL_POINTER) ; | ||||||||
|
|
||||||||
| GRB_TRY(GrB_Matrix_new(&B, GrB_FP64, n, n)); | ||||||||
| GRB_TRY(GrB_Matrix_new(&k, GrB_FP64, n, 1)); | ||||||||
| GRB_TRY(GrB_Matrix_new(&kk_, GrB_FP64, n, n)); | ||||||||
| GRB_TRY(GrB_Matrix_new(&BS, GrB_FP64, n, n)); | ||||||||
| GRB_TRY(GrB_Matrix_new(&S_BS, GrB_FP64, n, n)); | ||||||||
| GRB_TRY(GrB_Matrix_new(&Diag, GrB_FP64, n, n)); | ||||||||
| GxB_print(A, 2); | ||||||||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove print statements |
||||||||
| GRB_TRY (GrB_Matrix_nrows (&nrows, A)); | ||||||||
| GRB_TRY (GrB_Matrix_ncols (&ncols, A)); | ||||||||
| GRB_TRY (GrB_Matrix_nrows (&nrows_s, S)); | ||||||||
| GRB_TRY (GrB_Matrix_ncols (&ncols_s, S)); | ||||||||
|
|
||||||||
| LG_ASSERT (nrows == ncols, GrB_DIMENSION_MISMATCH) ; | ||||||||
| LG_ASSERT (ncols == nrows_s, GrB_DIMENSION_MISMATCH) ; | ||||||||
|
|
||||||||
| GRB_TRY (GrB_Matrix_new (&B, GrB_FP64, nrows, ncols)); | ||||||||
| GRB_TRY (GrB_Matrix_new (&S_t, GrB_BOOL, ncols_s, nrows_s)); | ||||||||
| GRB_TRY (GrB_Vector_new (&k, GrB_FP64, ncols)); | ||||||||
| GRB_TRY (GrB_Vector_new (&com_deg, GrB_FP64, ncols_s)); | ||||||||
|
|
||||||||
| double m = 0.0; | ||||||||
| double Q_ = 0.0; | ||||||||
|
|
||||||||
| GRB_TRY(GrB_Matrix_reduce_Monoid((GrB_Vector)k, NULL, NULL, GrB_PLUS_MONOID_FP64, A, NULL)); | ||||||||
| GRB_TRY (GrB_reduce (k, NULL, NULL, GrB_PLUS_MONOID_FP64, A, NULL)); | ||||||||
| GRB_TRY (GrB_reduce (&m, NULL, GrB_PLUS_MONOID_FP64, k, NULL)); | ||||||||
|
|
||||||||
| GRB_TRY(GrB_Matrix_reduce_FP64(&m, GrB_PLUS_FP64, GrB_PLUS_MONOID_FP64, A, NULL)); | ||||||||
| m /= 2.0; | ||||||||
| if (m == 0.0) | ||||||||
| { | ||||||||
| *Q = 0.0; | ||||||||
| LG_FREE_ALL; | ||||||||
| LG_FREE_WORK; | ||||||||
| return GrB_SUCCESS; | ||||||||
| } | ||||||||
| GRB_TRY(GrB_mxm(kk_, NULL, NULL, GrB_PLUS_TIMES_SEMIRING_FP64, k, k, GrB_DESC_T1)); | ||||||||
| double inv_m = -gamma / (2.0 * m); | ||||||||
| GRB_TRY(GrB_Matrix_apply_BinaryOp2nd_FP64(kk_, NULL, NULL, GrB_TIMES_FP64, kk_, inv_m, GrB_DESC_R)); | ||||||||
| GRB_TRY(GrB_eWiseAdd(B, NULL, NULL, GrB_PLUS_FP64, A, kk_, NULL)); | ||||||||
| GRB_TRY(GrB_mxm(BS, NULL, NULL, GrB_PLUS_TIMES_SEMIRING_FP64, B, S, NULL)); | ||||||||
| GRB_TRY(GrB_mxm(S_BS, NULL, NULL, GrB_PLUS_TIMES_SEMIRING_FP64, S, BS, GrB_DESC_T0)); | ||||||||
| // sum degrees per community | ||||||||
| GRB_TRY (GrB_transpose (S_t, NULL, NULL, S, NULL)) ; | ||||||||
| GRB_TRY (GrB_mxv (com_deg, NULL, NULL, GxB_PLUS_SECOND_FP64, S_t, k, NULL)) ; | ||||||||
| // square | ||||||||
| GRB_TRY (GrB_apply (com_deg, NULL, NULL, GxB_POW_FP64, com_deg, 2.0, NULL)) ; | ||||||||
|
|
||||||||
| // sum all of the products | ||||||||
| // this computed \sum_{i,j} (k_{i}k_{j}\delta(\sigma_i\sigma_j)) | ||||||||
|
Comment on lines
+99
to
+100
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| GRB_TRY (GrB_reduce (&Q_, NULL, GrB_PLUS_MONOID_FP64, com_deg, NULL)) ; | ||||||||
| Q_ *= inv_m; | ||||||||
| GRB_TRY (GrB_free (&com_deg)) ; | ||||||||
|
|
||||||||
| // Count the number of edges per node in the cluster originating at a node | ||||||||
| // in the cluster | ||||||||
| GRB_TRY (GrB_mxm (B, S, NULL, GxB_PLUS_FIRST_FP64, A, S_t, GrB_DESC_ST1)); | ||||||||
|
|
||||||||
| GRB_TRY(GrB_select(Diag, NULL, NULL, GrB_DIAG, S_BS, 0, NULL)); | ||||||||
| // sum the intra-cluster edges per node for all nodes | ||||||||
| GRB_TRY (GrB_reduce (&Q_, GrB_PLUS_FP64, GrB_PLUS_MONOID_FP64, B, NULL)) ; | ||||||||
|
|
||||||||
| GRB_TRY(GrB_Matrix_reduce_FP64(&Q_, NULL, GrB_PLUS_MONOID_FP64, Diag, NULL)); | ||||||||
| Q_ *= -inv_m; | ||||||||
| *Q = Q_; | ||||||||
|
|
||||||||
| LG_FREE_ALL; | ||||||||
| LG_FREE_WORK; | ||||||||
| return (GrB_SUCCESS); | ||||||||
| #else | ||||||||
| return (GrB_NOT_IMPLEMENTED); | ||||||||
|
|
||||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add comments to for GraphBLAS objects