|
1 | 1 | Build Structure |
2 | 2 | =================================== |
3 | 3 | Correlation structures are the core of **DHG**. In this section, we introduce the basic construction methods of different structures |
4 | | -and some structure transformation functions of them like: *reducing the high-order structrue to the low-order structure* |
5 | | -and *promoting the low-order structure to the high-order structure.* |
| 4 | +and some structure transformation functions of them like: |
| 5 | + |
| 6 | +- Reducing the high-order structrue to the low-order structure |
| 7 | +- Promoting the low-order structure to the high-order structure |
6 | 8 |
|
7 | 9 | Low-Order Structures |
8 | 10 | ----------------------- |
9 | 11 |
|
| 12 | +Currently, DHG's low-order structures include simple graph, directed graph, and bipartite graph. |
| 13 | +In the future, we will add more low-order structures. |
| 14 | + |
| 15 | +.. _build_graph: |
| 16 | + |
10 | 17 | Build Simple Graph |
11 | 18 | +++++++++++++++++++++++ |
12 | 19 |
|
@@ -232,6 +239,7 @@ a method to reduce the hyperedges in the hypergraph to the edges in the simple g |
232 | 239 | [0.3333, 0.3333, 0.3333, 0.0000, 0.3333], |
233 | 240 | [0.0000, 0.0000, 0.0000, 0.3333, 0.0000]]) |
234 | 241 |
|
| 242 | +.. _build_directed_graph: |
235 | 243 |
|
236 | 244 | Build Directed Graph |
237 | 245 | +++++++++++++++++++++++ |
@@ -316,6 +324,7 @@ Reduced from High-Order Structures |
316 | 324 |
|
317 | 325 | Welcome to contribute! |
318 | 326 |
|
| 327 | +.. _build_bipartite_graph: |
319 | 328 |
|
320 | 329 | Build Bipartite Graph |
321 | 330 | +++++++++++++++++++++++ |
@@ -433,17 +442,122 @@ We first define a simple hypergraph as: |
433 | 442 | [0., 1., 1., 0., 0.], |
434 | 443 | [1., 0., 0., 1., 1.]]) |
435 | 444 |
|
| 445 | +
|
436 | 446 | High-Order Structures |
437 | 447 | ----------------------- |
438 | | -Comming soon |
| 448 | + |
| 449 | +Currently, DHG's high-order structures include simple hypergraph. |
| 450 | +In the future, we will add more high-order structures like directed hypergraph. |
| 451 | + |
| 452 | +.. _build_hypergraph: |
439 | 453 |
|
440 | 454 | Build Simple Hypergraph |
441 | 455 | ++++++++++++++++++++++++++ |
442 | | -Comming soon |
| 456 | +A `simple hypergraph <https://en.wikipedia.org/wiki/Hypergraph>`_ is a hypergraph with no direction information in each hyperedge. |
| 457 | +Each hyperedge in a hypergraph can connect more than two vertices, which can be indicated with a sub-set of total vertices. |
| 458 | +Simple hypergraph can be constructed by the following methods: |
| 459 | + |
| 460 | +- Hyperedge list (**default**) :py:class:`dhg.Hypergraph` |
| 461 | +- Features with k-Nearest Neighbors :py:meth:`dhg.Hypergraph.from_feature_kNN` |
| 462 | +- Promoted from the low-order structures |
| 463 | + |
| 464 | + - Simple Graph :py:meth:`dhg.Hypergraph.from_graph` |
| 465 | + - k-Hop Neighbors of vertices in a simple graph :py:meth:`dhg.Hypergraph.from_graph_kHop` |
| 466 | + - Bipartite Graph :py:meth:`dhg.Hypergraph.from_bigraph` |
| 467 | + |
443 | 468 |
|
444 | 469 | Common Methods |
445 | 470 | ^^^^^^^^^^^^^^^^^^^ |
446 | | -Comming soon |
| 471 | + |
| 472 | +**Construct a simple hypergraph from edge list with** :py:class:`dhg.Hypergraph` |
| 473 | + |
| 474 | +.. code-block:: python |
| 475 | +
|
| 476 | + >>> hg = dhg.Hypergraph(5, [(0, 1, 2), (2, 3), (0, 4)]) |
| 477 | + >>> hg |
| 478 | + Simple Hypergraph(num_v=5, num_e=3) |
| 479 | + >>> hg.e |
| 480 | + ([(0, 1, 2), (2, 3), (0, 4)], [1.0, 1.0, 1.0]) |
| 481 | + >>> # print the incidence matrix of the simple hypergraph |
| 482 | + >>> hg.H.to_dense() |
| 483 | + tensor([[1., 0., 1.], |
| 484 | + [1., 0., 0.], |
| 485 | + [1., 1., 0.], |
| 486 | + [0., 1., 0.], |
| 487 | + [0., 0., 1.]]) |
| 488 | +
|
| 489 | +.. important:: |
| 490 | + |
| 491 | + Each hyperedge in the hypergraph is an unordered set of vertices, which means that ``(0, 1, 2)``, ``(0, 2, 1)``, and ``(2, 1, 0)`` are all the same hyperedge. |
| 492 | + |
| 493 | +.. code-block:: python |
| 494 | +
|
| 495 | + >>> hg = dhg.Hypergraph(5, [(0, 2, 1), (2, 3), (0, 4)]) |
| 496 | + >>> hg.e |
| 497 | + ([(0, 1, 2), (2, 3), (0, 4)], [1.0, 1.0, 1.0]) |
| 498 | + >>> hg.H.to_dense() |
| 499 | + tensor([[1., 0., 1.], |
| 500 | + [1., 0., 0.], |
| 501 | + [1., 1., 0.], |
| 502 | + [0., 1., 0.], |
| 503 | + [0., 0., 1.]]) |
| 504 | + >>> hg = dhg.Hypergraph(5, [(1, 0, 2), (2, 3), (0, 4)]) |
| 505 | + >>> hg.e |
| 506 | + ([(0, 1, 2), (2, 3), (0, 4)], [1.0, 1.0, 1.0]) |
| 507 | + >>> hg.H.to_dense() |
| 508 | + tensor([[1., 0., 1.], |
| 509 | + [1., 0., 0.], |
| 510 | + [1., 1., 0.], |
| 511 | + [0., 1., 0.], |
| 512 | + [0., 0., 1.]]) |
| 513 | +
|
| 514 | +.. note:: |
| 515 | + |
| 516 | + If the added hyperedges have duplicate hyperedges, those duplicate hyperedges will be automatically merged with specified ``merge_op``. |
| 517 | + |
| 518 | +.. code-block:: python |
| 519 | +
|
| 520 | + >>> hg = dhg.Hypergraph(5, [(0, 1, 2), (2, 3), (2, 3), (0, 4)], merge_op="mean") |
| 521 | + >>> hg.e |
| 522 | + ([(0, 1, 2), (2, 3), (0, 4)], [1.0, 1.0, 1.0]) |
| 523 | + >>> hg = dhg.Hypergraph(5, [(0, 1, 2), (2, 3), (2, 3), (0, 4)], merge_op="sum") |
| 524 | + >>> hg.e |
| 525 | + ([(0, 1, 2), (2, 3), (0, 4)], [1.0, 2.0, 1.0]) |
| 526 | + >>> hg.add_hyperedges([(0, 2, 1), (0, 4)], merge_op="mean") |
| 527 | + >>> hg.e |
| 528 | + ([(0, 1, 2), (2, 3), (0, 4)], [1.0, 2.0, 1.0]) |
| 529 | + >>> hg.add_hyperedges([(0, 2, 1), (0, 4)], merge_op="sum") |
| 530 | + >>> hg.e |
| 531 | + ([(0, 1, 2), (2, 3), (0, 4)], [2.0, 2.0, 2.0]) |
| 532 | +
|
| 533 | +You can find the weight of the last hyperedge is ``1.0`` and ``2.0``, if you set the ``merge_op`` to ``mean`` and ``sum``, respectively. |
| 534 | + |
| 535 | + |
| 536 | +**Construct a simple hypergraph from feature k-Nearest Neighbors with** :py:meth:`dhg.Hypergraph.from_feature_kNN` |
| 537 | + |
| 538 | +.. code-block:: python |
| 539 | +
|
| 540 | + >>> X = torch.tensor(([[0.6460, 0.0247], |
| 541 | + [0.9853, 0.2172], |
| 542 | + [0.7791, 0.4780], |
| 543 | + [0.0092, 0.4685], |
| 544 | + [0.9049, 0.6371]])) |
| 545 | + >>> hg = dhg.Hypergraph.from_feature_kNN(X, k=2) |
| 546 | + >>> hg |
| 547 | + Simple Hypergraph(num_v=5, num_e=3) |
| 548 | + >>> hg.e |
| 549 | + ([(0, 1, 2), (1, 2, 4), (0, 2, 3)], [1.0, 1.0, 1.0]) |
| 550 | + >>> hg.H.to_dense() |
| 551 | + tensor([[1., 0., 1.], |
| 552 | + [1., 1., 0.], |
| 553 | + [1., 1., 1.], |
| 554 | + [0., 0., 1.], |
| 555 | + [0., 1., 0.]]) |
| 556 | +
|
| 557 | +.. note:: |
| 558 | + |
| 559 | + Those duplicated hyperedges are merged with ``mean`` operation. |
| 560 | + |
447 | 561 |
|
448 | 562 | Prometed from Low-Order Structures |
449 | 563 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
|
0 commit comments