Return the largest eigenvalue of the normalized symmetric Laplacian of a graph. If the graph is batched from multiple graphs, return the list of the largest eigenvalue for each graph instead. Parameters ---------- g : DGLGraph The input graph, it must be a bi-directed h
(g)
| 1424 | |
| 1425 | |
| 1426 | def laplacian_lambda_max(g): |
| 1427 | """Return the largest eigenvalue of the normalized symmetric Laplacian of a graph. |
| 1428 | |
| 1429 | If the graph is batched from multiple graphs, return the list of the largest eigenvalue |
| 1430 | for each graph instead. |
| 1431 | |
| 1432 | Parameters |
| 1433 | ---------- |
| 1434 | g : DGLGraph |
| 1435 | The input graph, it must be a bi-directed homogeneous graph, i.e., every edge |
| 1436 | should have an accompanied reverse edge in the graph. |
| 1437 | The graph can be batched from multiple graphs. |
| 1438 | |
| 1439 | Returns |
| 1440 | ------- |
| 1441 | list[float] |
| 1442 | A list where the i-th item indicates the largest eigenvalue |
| 1443 | of i-th graph in :attr:`g`. |
| 1444 | |
| 1445 | In the case where the function takes a single graph, it will return a list |
| 1446 | consisting of a single element. |
| 1447 | |
| 1448 | Examples |
| 1449 | -------- |
| 1450 | >>> import dgl |
| 1451 | >>> g = dgl.graph(([0, 1, 2, 3, 4, 0, 1, 2, 3, 4], [1, 2, 3, 4, 0, 4, 0, 1, 2, 3])) |
| 1452 | >>> dgl.laplacian_lambda_max(g) |
| 1453 | [1.809016994374948] |
| 1454 | """ |
| 1455 | g_arr = batch.unbatch(g) |
| 1456 | rst = [] |
| 1457 | for g_i in g_arr: |
| 1458 | n = g_i.num_nodes() |
| 1459 | adj = g_i.adj_external( |
| 1460 | transpose=True, scipy_fmt=g_i.formats()["created"][0] |
| 1461 | ).astype(float) |
| 1462 | norm = sparse.diags( |
| 1463 | F.asnumpy(g_i.in_degrees()).clip(1) ** -0.5, dtype=float |
| 1464 | ) |
| 1465 | laplacian = sparse.eye(n) - norm * adj * norm |
| 1466 | rst.append( |
| 1467 | scipy.sparse.linalg.eigs( |
| 1468 | laplacian, 1, which="LM", return_eigenvectors=False |
| 1469 | )[0].real |
| 1470 | ) |
| 1471 | return rst |
| 1472 | |
| 1473 | |
| 1474 | def metapath_reachable_graph(g, metapath): |
nothing calls this directly
no test coverage detected