Skip to content

Commit 64c7cab

Browse files
changes
1 parent 42246c5 commit 64c7cab

File tree

8 files changed

+139
-40
lines changed

8 files changed

+139
-40
lines changed

experimental/algorithm/LAGraph_IsolateSets.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
GrB_free(&Seed) ; \
1818
GrB_free(&degree) ; \
1919
}
20-
#define DEBUG 0
20+
#define DEBUG 1
2121
#define dbg(x) if (DEBUG) GxB_print(x,5)
2222
typedef GrB_Matrix mat;
2323
typedef GrB_Vector vec ;
@@ -49,7 +49,7 @@ int LAGraph_IsolateSets(
4949
GrB_Vector degree = NULL ; // (float) G->out_degree
5050
GrB_Matrix A ; // G->A, the adjacency matrix
5151
GrB_Index n ; // # of nodes
52-
52+
printf("in Isolate set algorithm");
5353
LG_TRY (LAGraph_CheckGraph (G, msg)) ;
5454
LG_ASSERT(isolate_set != NULL, GrB_NULL_POINTER);
5555
A = G->A;
@@ -101,6 +101,7 @@ int LAGraph_IsolateSets(
101101
dbg(new_members);
102102
GRB_TRY (GrB_assign (iset, new_members, NULL,true,GrB_ALL,n,NULL)) ;
103103
(*isolate_set) = iset;
104+
printf("done iset");
104105
iset = NULL;
105106
LG_FREE_ALL;
106107
return 0;

experimental/algorithm/LAGraph_Louvain.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ int LAGraph_Louvain(
5353
)
5454
{
5555
char MATRIX_TYPE[LAGRAPH_MSG_LEN];
56-
GrB_set (GrB_GLOBAL, false, GxB_BURBLE);
56+
GrB_set (GrB_GLOBAL, true, GxB_BURBLE);
5757
//assignment of monoids, bops, and semis
5858
GrB_Monoid plusmon = GrB_PLUS_MONOID_FP64;
5959
GrB_Monoid maxmon = GrB_MAX_MONOID_FP64;
@@ -103,7 +103,7 @@ int LAGraph_Louvain(
103103
GRB_TRY(GrB_assign (x, NULL, NULL, 1, GrB_ALL, n, NULL)) ;
104104
// GxB_print(i,5);
105105
GRB_TRY(GrB_Matrix_diag(&S,x,0));
106-
// GxB_print(S,5);
106+
GxB_print(S,5);
107107

108108
//var used in for loop
109109
GrB_Index vertices_changed;
@@ -137,6 +137,7 @@ int LAGraph_Louvain(
137137
// GxB_print(t_q,5);
138138

139139
// sr = S(i,:)
140+
140141
GRB_TRY(GrB_Col_extract(sr,NULL,NULL,S,GrB_ALL,1,i,GrB_DESC_T0));
141142
// GxB_print(sr,5);
142143

experimental/algorithm/LAGraph_Louvain2.c

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <stdlib.h>
2424
#include <stdio.h>
2525
#include <time.h>
26+
2627
// #include <iostream>
2728
#undef LG_FREE_ALL
2829
#define LG_FREE_ALL \
@@ -53,7 +54,7 @@
5354
LAGraph_Free ((void *) &dSp, NULL) ; \
5455
LAGraph_Free ((void *) &dSj, NULL) ; \
5556
}
56-
#define DEBUG 1
57+
#define DEBUG 0
5758
#define dbg(x) if (DEBUG) GxB_print(x,5)
5859
// uint64_t seed = 213;
5960
typedef struct tuple_fp64{
@@ -69,13 +70,8 @@ void make_fp64(tuple_fp64 *z,
6970
{
7071
z->k = (int64_t)jx;
7172
z->v = (*x);
72-
size_t tb = (*y)+1;
73-
tb ^= tb << 13;
74-
tb ^= tb >> 7;
75-
tb ^= tb << 17;
76-
tb = (tb ^ (tb >> 27)) * 0x94D049BB133111EB ;
77-
tb = (tb ^ (tb >> 31)) ;
78-
(tb = tb ^ (tb >> 30)) * 0xBF58476D1CE4E5B9 ;
73+
uint64_t seed = (*y + ix + iy + jy);
74+
uint64_t tb = LG_Random64(&seed);
7975
z->tb = tb;
8076
}
8177
void max_fp64(tuple_fp64 *z, const tuple_fp64 *x, const tuple_fp64 *y){
@@ -111,13 +107,8 @@ void max_fp64(tuple_fp64 *z, const tuple_fp64 *x, const tuple_fp64 *y){
111107
"{ \n" \
112108
" z->k = (int64_t)jx; \n" \
113109
" z->v = (*x); \n" \
114-
" size_t tb = (*y)+1; \n"\
115-
" tb ^= tb << 13;\n"\
116-
" tb ^= tb >> 7;\n" \
117-
" tb ^= tb << 17; \n"\
118-
" tb = (tb ^ (tb >> 27)) * 0x94D049BB133111EB ; \n"\
119-
" tb = (tb ^ (tb >> 31)) ;\n"\
120-
" (tb = tb ^ (tb >> 30)) * 0xBF58476D1CE4E5B9 ;\n"\
110+
" uint64_t seed = (*y + ix + iy + jy); \n"\
111+
" uint64_t tb = LG_Random64(&seed);\n"\
121112
" z->tb = tb;\n"\
122113
"}"
123114

@@ -135,7 +126,7 @@ int LAGraph_Louvain2(
135126

136127
char MATRIX_TYPE[LAGRAPH_MSG_LEN];
137128
if (DEBUG)
138-
GrB_set (GrB_GLOBAL, false, GxB_BURBLE);
129+
GrB_set (GrB_GLOBAL, true, GxB_BURBLE);
139130

140131
//assignment of monoids, bops, and semis
141132
GrB_Monoid plusmon = GrB_PLUS_MONOID_FP64;
@@ -184,12 +175,13 @@ int LAGraph_Louvain2(
184175
double o1;
185176
double k_i = 0;
186177
// FIXME: add check to see if S_result is NULL
187-
178+
LG_Random_Init(msg)
188179
LG_ASSERT(S_result != NULL, GrB_NULL_POINTER);
189180

190181
GrB_Matrix A = G->A;
191182
// GxB_print(A,5);
192-
183+
// printf("rand init");
184+
double test = 23;
193185
//index bin op definitions
194186
//------------------------------------------------------------------------------------------------------------------
195187

@@ -207,7 +199,6 @@ int LAGraph_Louvain2(
207199
GRB_TRY(GrB_Semiring_new(&Semiring, Mon, Bop));
208200
//------------------------------------------------------------------------------------------------------------------
209201

210-
GRB_TRY(LAGraph_Random_Init(msg));
211202

212203
GRB_TRY(GrB_Matrix_nrows(&n,A));
213204
GRB_TRY(GrB_Matrix_ncols(&b,A));
@@ -255,8 +246,8 @@ int LAGraph_Louvain2(
255246
bool changed = true;
256247
int max_iter = 20;
257248
int iter =0;
258-
uint64_t seed = (uint64_t)time(NULL);
259-
GRB_TRY(LAGraph_Random_Seed(y_rand,seed,msg));
249+
uint64_t seed = 231;
250+
260251
// GxB_print(y_rand,5);
261252
GRB_TRY(GrB_mxv(z,NULL,NULL,stdmxm,S,k,NULL));
262253
// GxB_print(z,5);
@@ -309,7 +300,9 @@ int LAGraph_Louvain2(
309300
// GxB_print(q1,5);
310301
// printf("Size of q1: %ld\n",q1_size);
311302
// GRB_TRY(GrB_Vector_setElement_UINT64(y_rand,seed,0));
312-
// GRB_TRY (GrB_assign (y_rand, t_q, NULL, seed, GrB_ALL, n, GrB_DESC_S));
303+
seed+=i;
304+
GRB_TRY (GrB_assign (y_rand, t_q, NULL, seed, GrB_ALL, n, GrB_DESC_S));
305+
313306
// GxB_print(q1,5);
314307
GRB_TRY(GrB_mxv(max_q1,NULL,NULL,Semiring,(GrB_Matrix)q1,y_rand,GrB_DESC_T0));
315308
// GxB_print(q1,5);

experimental/algorithm/LAGraph_LouvainMIS.c

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <stdlib.h>
44
#include <stdio.h>
55
#include <time.h>
6-
#define DEBUG 0
6+
#define DEBUG 1
77
#define dbg(x) if (DEBUG) GxB_print(x,5)
88
#undef LG_FREE_ALL
99
#define LG_FREE_ALL\
@@ -23,49 +23,70 @@ int LAGraph_LouvainMIS(
2323
GrB_set (GrB_GLOBAL, true, GxB_BURBLE);
2424
// Shortened monoids, Binary ops, and Semirings
2525
GrB_Monoid plusmon = GrB_PLUS_MONOID_FP64;
26+
GrB_Monoid timesmon = GrB_TIMES_FP64;
2627
GrB_BinaryOp plusf64 = GrB_PLUS_FP64;
2728
GrB_BinaryOp timesf64 = GrB_TIMES_FP64;
2829
GrB_Semiring stdmxm = GrB_PLUS_TIMES_SEMIRING_FP64;
2930

3031
// Declarations
3132
GrB_Vector iset = NULL;
33+
GrB_Vector v = NULL;
3234
GrB_Vector k = NULL;
3335
GrB_Vector x = NULL;
36+
GrB_Vector coef = NULL;
37+
GrB_Vector z = NULL;
3438
GrB_Matrix S = NULL;
3539
GrB_Matrix A = NULL;
3640
GrB_Index n ;
3741

38-
42+
3943
// Initializing
4044
LG_TRY (LAGraph_CheckGraph (G, msg)) ;
4145
LG_ASSERT(S_result != NULL, GrB_NULL_POINTER);
46+
4247
A = G->A;
4348
dbg(A);
4449

4550
//k = [+_j A(:,j)]
46-
GRB_TRY(GrB_Vector_new(&iset,GrB_BOOL,n));
51+
GRB_TRY(GrB_Matrix_nrows(&n,A));
4752
GRB_TRY(GrB_Vector_new(&k, GrB_FP64, n));
53+
GRB_TRY(GrB_Vector_new(&coef,GrB_FP64,n));
54+
GRB_TRY(GrB_Vector_new(&x,GrB_FP64,n));
55+
GRB_TRY(GrB_Vector_new(&z,GrB_FP64,n));
56+
GRB_TRY(GrB_Vector_new(&v,GrB_FP64,n));
57+
58+
4859
double m;
4960
GRB_TRY(GrB_Vector_reduce_FP64(&m,NULL,plusmon,k,NULL));
5061
m*=.5;
51-
62+
printf("%ld",m);
63+
5264
// S <- I
53-
GRB_TRY(GrB_Vector_new(&x,GrB_FP64,n));
5465
GRB_TRY(GrB_assign (x, NULL, NULL, 1, GrB_ALL, n, NULL)) ;
5566
// GxB_print(i,5);
5667
GRB_TRY(GrB_Matrix_diag(&S,x,0));
57-
68+
dbg(S);
5869
// Compute Isolate Set
59-
70+
GRB_TRY(LAGraph_IsolateSets(&iset,G,123,msg));
71+
dbg(iset);
6072

6173
// Compute max change in modularity for each node in the isolate set
74+
GRB_TRY(GrB_mxv(z,NULL,NULL,stdmxm,S,k,NULL));
75+
dbg(z);
76+
GRB_TRY (GrB_Matrix_reduce_Monoid(k, NULL, NULL,plusmon, A, NULL));
77+
dbg(k);
78+
GRB_TRY(GrB_Vector_eWiseMult_BinaryOp(coef,NULL,NULL,timesf64,k,iset,NULL));
79+
80+
dbg(coef);
81+
6282
// Aggregate Graph
6383
// Iterate till no change is detected
64-
double Q;
65-
double gamma = 1;
66-
GRB_TRY(LAGr_Modularity2(&Q,gamma,A,S,msg));
67-
// printf("Iterations: %d\n", iter);
68-
printf("Q:%.15g\n",Q);
84+
85+
// double Q;
86+
// double gamma = 1;
87+
// GRB_TRY(LAGr_Modularity2(&Q,gamma,A,S,msg));
88+
// // printf("Iterations: %d\n", iter);
89+
// printf("Q:%.15g\n",Q);
6990
(*S_result) = S ;
7091
S = NULL;
7192
LG_FREE_ALL;

experimental/algorithm/LaGr_Modularity2.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ int LAGr_Modularity2(
119119
//------------------------------------------------------------------------------
120120
GRB_TRY(GrB_Matrix_new(&BS, GrB_FP64, n, n));
121121
GRB_TRY(GrB_Matrix_new(&S_BS, GrB_FP64, n, n));
122+
// GxB_print(S,5);
122123
GRB_TRY(GrB_mxm(BS, NULL, NULL, stdmxm, B, S, NULL));
124+
// GxB_print(BS,5);
123125
GRB_TRY(GrB_mxm(S_BS,NULL,NULL,stdmxm,S,BS,GrB_DESC_T0));
124126
// GxB_print (S_BS,3);
125127

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#include <stdio.h>
2+
#include <acutest.h>
3+
4+
#include <LAGraphX.h>
5+
#include <LAGraph_test.h>
6+
#include "LG_Xtest.h"
7+
8+
char msg [LAGRAPH_MSG_LEN];
9+
LAGraph_Graph G;
10+
GrB_Matrix A;
11+
#define LEN 512
12+
char filename [LEN+1];
13+
typedef struct
14+
{
15+
const char * matrix_file; //Adjeancy matrix or graph
16+
const double mod;
17+
} matrix_info;
18+
19+
const matrix_info files[] = {
20+
21+
{"comm0.mtx", 0.357142857142857},
22+
// {"res1.mtx", 0.0},
23+
// {"karate2.mtx", .42},
24+
{"",-1}
25+
};
26+
void test_Louvain(void){
27+
LAGraph_Init(msg);
28+
printf("\n");
29+
for(int k = 0;;k++){
30+
if (strlen(files[k].matrix_file) == 0)
31+
break;
32+
snprintf (filename, LEN, LG_DATA_DIR "%s", files[k].matrix_file) ;
33+
FILE *f = fopen (filename, "r") ;
34+
TEST_CHECK (f != NULL) ;
35+
OK (LAGraph_MMRead (&A, f, msg)) ;
36+
OK (LAGraph_New (&G, &A, LAGraph_ADJACENCY_DIRECTED, msg)) ;
37+
TEST_CHECK (A == NULL) ;
38+
39+
// check if the pattern is symmetric - if it isn't make it.
40+
OK (LAGraph_Cached_OutDegree (G, msg)) ;
41+
OK (LAGraph_Cached_IsSymmetricStructure (G, msg)) ;
42+
43+
if (G->is_symmetric_structure == LAGraph_FALSE)
44+
{
45+
printf("This matrix is not symmetric. \n");
46+
// make the adjacency matrix symmetric
47+
OK (LAGraph_Cached_AT (G, msg)) ;
48+
OK (GrB_eWiseAdd (G->A, NULL, NULL, GrB_LOR, G->A, G->AT, NULL)) ;
49+
G->is_symmetric_structure = true ;
50+
// consider the graph as directed
51+
G->kind = LAGraph_ADJACENCY_DIRECTED ;
52+
}
53+
else
54+
{
55+
G->kind = LAGraph_ADJACENCY_UNDIRECTED ;
56+
}
57+
GrB_Matrix S;
58+
double tsimple = LAGraph_WallClockTime ( ) ;
59+
OK(LAGraph_LouvainMIS(&S,G,msg));
60+
tsimple = LAGraph_WallClockTime ( ) - tsimple ;
61+
printf(" time: %f\n",tsimple);
62+
63+
64+
}
65+
}
66+
TEST_LIST = {
67+
{"Louvain", test_Louvain},
68+
{NULL, NULL}
69+
};

experimental/test/test_louvain.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ typedef struct
1919
const matrix_info files[] = {
2020

2121
{"comm0.mtx", 0.357142857142857},
22-
{"res1.mtx", 0.0},
23-
{"karate2.mtx", .42},
22+
// {"res1.mtx", 0.0},
23+
// {"karate2.mtx", .42},
2424
{"",-1}
2525
};
2626
//Store matrix by row

include/LAGraphX.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,6 +1429,18 @@ int LAGraph_IsolateSets(
14291429
uint64_t seed,
14301430
char* msg
14311431
);
1432+
LAGRAPHX_PUBLIC
1433+
int LAGraph_LouvainMIS(
1434+
//output
1435+
GrB_Matrix *S_result,
1436+
//input
1437+
LAGraph_Graph G,
1438+
char* msg
1439+
);
1440+
LAGRAPHX_PUBLIC
1441+
uint64_t LG_Random64 (uint64_t *state);
1442+
1443+
14321444
#if defined ( __cplusplus )
14331445
}
14341446
#endif

0 commit comments

Comments
 (0)