You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: notebooks/08_triangle_counting.ipynb
+46-10Lines changed: 46 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -93,7 +93,7 @@
93
93
},
94
94
{
95
95
"cell_type": "code",
96
-
"execution_count": 30,
96
+
"execution_count": 4,
97
97
"metadata": {},
98
98
"outputs": [
99
99
{
@@ -133,7 +133,9 @@
133
133
{
134
134
"cell_type": "code",
135
135
"execution_count": 6,
136
-
"metadata": {},
136
+
"metadata": {
137
+
"scrolled": true
138
+
},
137
139
"outputs": [
138
140
{
139
141
"name": "stdout",
@@ -154,13 +156,47 @@
154
156
"cell_type": "markdown",
155
157
"metadata": {},
156
158
"source": [
157
-
"## Per-Node Triangle Count"
159
+
"## More efficient Sandia Method"
160
+
]
161
+
},
162
+
{
163
+
"cell_type": "markdown",
164
+
"metadata": {},
165
+
"source": [
166
+
"The above triangle counting scheme works, but is not maximally efficient. First, it considers the entire symmetric graph, which involves counting both forward and backward edges, second it does an `ewise_mult` after the matrix multiply, requiring two operations instead of one. The \"sandia\" method considers only the lower triangluar half of the matrix, counting half as many edges, and combines the ewise_mult operation into the matrix multiplication by using A as its own mask:"
158
167
]
159
168
},
160
169
{
161
170
"cell_type": "code",
162
171
"execution_count": 7,
163
172
"metadata": {},
173
+
"outputs": [
174
+
{
175
+
"name": "stdout",
176
+
"output_type": "stream",
177
+
"text": [
178
+
"Total triangles: 45\n"
179
+
]
180
+
}
181
+
],
182
+
"source": [
183
+
"L = A.select('tril').new()\n",
184
+
"L(L.S) << L.mxm(L)\n",
185
+
"total = L.reduce_scalar(binary.plus).get()\n",
186
+
"print(f\"Total triangles: {num_triangles}\")"
187
+
]
188
+
},
189
+
{
190
+
"cell_type": "markdown",
191
+
"metadata": {},
192
+
"source": [
193
+
"## Per-Node Triangle Count"
194
+
]
195
+
},
196
+
{
197
+
"cell_type": "code",
198
+
"execution_count": 8,
199
+
"metadata": {},
164
200
"outputs": [
165
201
{
166
202
"name": "stdout",
@@ -179,7 +215,7 @@
179
215
},
180
216
{
181
217
"cell_type": "code",
182
-
"execution_count": 8,
218
+
"execution_count": 9,
183
219
"metadata": {},
184
220
"outputs": [
185
221
{
@@ -221,7 +257,7 @@
221
257
},
222
258
{
223
259
"cell_type": "code",
224
-
"execution_count": 9,
260
+
"execution_count": 10,
225
261
"metadata": {},
226
262
"outputs": [
227
263
{
@@ -271,7 +307,7 @@
271
307
},
272
308
{
273
309
"cell_type": "code",
274
-
"execution_count": 50,
310
+
"execution_count": 11,
275
311
"metadata": {},
276
312
"outputs": [
277
313
{
@@ -297,7 +333,7 @@
297
333
" - A @ y = sum of ALL neighbors' triangle counts\n",
298
334
" - T1 @ y = sum of TRIANGLE neighbors' triangle counts\n",
299
335
" \n",
300
-
" The 3 vs 2 weighting means non-triangle neighbors count MORE than triangle neighbors.\n",
336
+
" The 3 vs 2 weighting means non-triangle neighbors count more than triangle neighbors.\n",
0 commit comments