Types¶
hyperbench.types
¶
EdgeIndex
¶
A wrapper for edge index representation of a graph.
Edge index is a tensor of shape (2, num_edges) where the first row contains source node indices
and the second row contains destination node indices for each edge.
Examples:
This represents a graph with edges (0, 1), (1, 0), and (2, 3). The number of nodes in this graph is 4 (nodes 0, 1, 2, and 3) and the number of edges is 3.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_index
|
Tensor
|
A tensor of shape |
required |
edge_weights
|
Tensor | None
|
Optional tensor of shape |
None
|
Source code in hyperbench/types/graph.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 | |
item
property
¶
Return the edge index tensor.
edge_weights
property
¶
Return the edge weight tensor, if present.
max_node_id
property
¶
Return the maximum node ID in the edge index.
num_edges
property
¶
Return the number of edges in the graph.
num_nodes
property
¶
Return the number of nodes in the graph.
add_selfloops(num_nodes=None, with_duplicate_removal=True)
¶
Add self-loops to each node in the edge index.
Examples:
>>> edge_index = [[0, 1, 2],
... [1, 0, 3]]
>>> edge_index_with_selfloops = [[0, 1, 2, 0, 1, 2, 3],
... [1, 0, 3, 0, 1, 2, 3]]
When num_nodes is higher than the number of nodes in edge_index,
self-loops are added for all nodes from 0 to num_nodes - 1,
including nodes not present in the original edges:
>>> edge_index = [[0, 1, 2],
... [1, 0, 3]]
>>> num_nodes = 6
>>> edge_index_with_selfloops = [[0, 1, 2, 0, 1, 2, 3, 4, 5],
... [1, 0, 3, 0, 1, 2, 3, 4, 5]]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_nodes
|
int | None
|
Total number of nodes. When provided, self-loops are added for nodes |
None
|
with_duplicate_removal
|
bool
|
Whether to remove duplicate edges after adding self-loops. Defaults to |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
This |
EdgeIndex
|
class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input edge index has no edges (i.e., |
Source code in hyperbench/types/graph.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | |
get_sparse_adjacency_matrix(num_nodes=None, use_edge_weights=False)
¶
Compute the sparse adjacency matrix from a graph edge index. To get the normalized adjacency matrix, add self-loops to the edge_index.
Examples:
>>> edge_index = [[0, 1, 2],
... [1, 0, 3]]
>>> num_nodes = 4
>>> adj_values = [1, 1, 1]
>>> adj_indices = [[0, 1, 2],
... [1, 0, 3]]
>>> 0 1 2 3
... adj_matrix = [[0, 1, 0, 0], 0
... [1, 0, 0, 0], 1
... [0, 0, 0, 1], 2
... [0, 0, 1, 0]] 3
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_nodes
|
int | None
|
The number of nodes in the graph.
If |
None
|
use_edge_weights
|
bool
|
Whether to use edge weights if they are present.
If |
False
|
Returns:
| Type | Description |
|---|---|
Tensor
|
The sparse adjacency matrix of shape |
Source code in hyperbench/types/graph.py
get_sparse_identity_matrix(num_nodes=None)
¶
Compute the sparse identity matrix I of shape (num_nodes, num_nodes).
Examples:
>>> num_nodes = 3
>>> identity_indices = [[0, 1, 2],
... [0, 1, 2]]
>>> values = [1, 1, 1]
>>> I = [[1, 0, 0],
... [0, 1, 0],
... [0, 0, 1]]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_nodes
|
int | None
|
The number of nodes in the graph.
If |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
The sparse identity matrix I of shape |
Source code in hyperbench/types/graph.py
get_sparse_normalized_degree_matrix(num_nodes=None, use_edge_weights=False)
¶
Compute the sparse normalized degree matrix D^-½ from a graph edge index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_nodes
|
int | None
|
The number of nodes in the graph.
If |
None
|
use_edge_weights
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
Tensor
|
The sparse normalized degree matrix D^-½ of shape |
Source code in hyperbench/types/graph.py
get_sparse_normalized_laplacian(num_nodes=None)
¶
Compute the sparse symmetric normalized Laplacian matrix: L = I - D^{-½} A D^{-½}.
Unlike get_sparse_normalized_gcn_laplacian, this method does not add self-loops
and computes the standard Laplacian (not the GCN propagation matrix).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_nodes
|
int | None
|
The number of nodes in the graph. If |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
The sparse symmetric normalized Laplacian matrix of shape |
Source code in hyperbench/types/graph.py
get_sparse_normalized_gcn_laplacian(num_nodes=None, use_edge_weights=False)
¶
Compute the sparse Laplacian matrix from a graph edge index.
The GCN Laplacian is defined as: L_GCN = D_hat^-½ * A_hat * D_hat^-½, where A_hat = A + I (adjacency with self-loops) and D_hat is the degree matrix of A_hat.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_nodes
|
int | None
|
The number of nodes in the graph. If |
None
|
use_edge_weights
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
Tensor
|
The sparse symmetrically normalized Laplacian matrix of shape |
Source code in hyperbench/types/graph.py
remove_selfloops()
¶
Remove self-loops from the edge index.
Source code in hyperbench/types/graph.py
remove_duplicate_edges(num_nodes=None)
¶
Remove duplicate edges from the edge index. Keeps the tensor contiguous in memory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_nodes
|
int | None
|
The number of nodes in the graph. If |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
This |
EdgeIndex
|
class: |
Source code in hyperbench/types/graph.py
to_undirected(with_selfloops=False, num_nodes=None)
¶
Convert the edge index to an undirected edge index by adding reverse edges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
with_selfloops
|
bool
|
Whether to add self-loops to each node. Defaults to |
False
|
num_nodes
|
int | None
|
Total number of nodes. Propagated to |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
This |
EdgeIndex
|
class: |
Source code in hyperbench/types/graph.py
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 | |
Graph
¶
A simple graph data structure using edge list representation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edges
|
list[list[int]]
|
A list of edges, where each edge is represented as a list of two integers (source_node, destination_node). |
required |
edge_weights
|
list[float] | None
|
Optional list of edge weights corresponding to each edge in |
None
|
Source code in hyperbench/types/graph.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
edge_weights
property
¶
Return the edge weights, if present.
edge_weights_tensor
property
¶
Return the edge weights as a tensor, if present.
num_nodes
property
¶
Return the number of nodes in the graph.
num_edges
property
¶
Return the number of edges in the graph.
remove_selfloops()
¶
Remove self-loops from the graph.
Returns:
| Type | Description |
|---|---|
Graph
|
List of edges without self-loops. |
Source code in hyperbench/types/graph.py
to_edge_index()
¶
Convert the graph to edge index representation.
Returns:
| Name | Type | Description |
|---|---|---|
edge_index |
Tensor
|
Tensor of shape (2, |E|) representing edges. |
Source code in hyperbench/types/graph.py
smoothing_with_laplacian_matrix(x, laplacian_matrix, drop_rate=0.0)
staticmethod
¶
Return the feature matrix smoothed with a Laplacian matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Node feature matrix. Size |
required |
laplacian_matrix
|
Tensor
|
The Laplacian matrix. Size |
required |
drop_rate
|
float
|
Randomly dropout the connections in the Laplacian with probability |
0.0
|
Returns:
| Type | Description |
|---|---|
Tensor
|
The smoothed feature matrix. Size |
Source code in hyperbench/types/graph.py
HIFHypergraph
¶
A hypergraph data structure that supports directed/undirected hyperedges with incidence-based representation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network_type
|
Literal['asc', 'directed', 'undirected'] | None
|
The type of hypergraph, which can be "asc" (or "directed") for directed hyperedges, or "undirected" for undirected hyperedges. |
None
|
metadata
|
dict[str, Any] | None
|
Optional dictionary of metadata about the hypergraph. |
None
|
incidences
|
list[dict[str, Any]] | None
|
A list of incidences, where each incidence is a dictionary with keys "node" and "edge" representing the relationship between a node and a hyperedge. |
None
|
nodes
|
list[dict[str, Any]] | None
|
A list of node dictionaries, where each dictionary contains information about a node (e.g., id, features). |
None
|
hyperedges
|
list[dict[str, Any]] | None
|
A list of edge dictionaries, where each dictionary contains information about a hyperedge (e.g., id, features). |
None
|
Source code in hyperbench/types/hypergraph.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
num_nodes
property
¶
Return the number of nodes in the hypergraph.
num_hyperedges
property
¶
Return the number of hyperedges in the hypergraph.
from_hif(data)
classmethod
¶
Create a Hypergraph from a HIF (Hypergraph Interchange Format).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict[str, Any]
|
Dictionary with keys: network-type, metadata, incidences, nodes, hyperedges |
required |
Returns:
| Type | Description |
|---|---|
HIFHypergraph
|
Hypergraph instance |
Source code in hyperbench/types/hypergraph.py
stats()
¶
Compute statistics for the HIFhypergraph.
The fields returned in the dictionary include:
- num_nodes: The number of nodes in the hypergraph.
- num_hyperedges: The number of hyperedges in the hypergraph.
- avg_degree_node_raw: The average degree of nodes, calculated as the mean number of hyperedges each node belongs to.
- avg_degree_node: The floored node average degree.
- avg_degree_hyperedge_raw: The average size of hyperedges, calculated as the mean number of nodes each hyperedge contains.
- avg_degree_hyperedge: The floored hyperedge average size.
- node_degree_max: The maximum degree of any node in the hypergraph.
- hyperedge_degree_max: The maximum size of any hyperedge in the hypergraph.
- node_degree_median: The median degree of nodes in the hypergraph.
- hyperedge_degree_median: The median size of hyperedges in the hypergraph.
- distribution_node_degree: A list where the value at index i represents the count of nodes with degree i.
- distribution_hyperedge_size: A list where the value at index i represents the count of hyperedges with size i.
- distribution_node_degree_hist: A dictionary where the keys are node degrees and the values are the count of nodes with that degree.
- distribution_hyperedge_size_hist: A dictionary where the keys are hyperedge sizes and the values are the count of hyperedges with that size.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dictionary containing various statistics about the hypergraph. |
Source code in hyperbench/types/hypergraph.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
Hypergraph
¶
A simple hypergraph data structure using edge list representation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hyperedges
|
list[list[int]]
|
A list of hyperedges, where each hyperedge is represented as a list of node IDs. |
required |
Source code in hyperbench/types/hypergraph.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 | |
num_nodes
property
¶
Return the number of nodes in the hypergraph.
num_hyperedges
property
¶
Return the number of hyperedges in the hypergraph.
neighbors_of(node)
¶
Return the set of nodes that share at least one hyperedge with node.
A node u is a neighbor of v if there exists a hyperedge e such that both u and v are in e. The node itself is excluded from the result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
int
|
The node ID to find neighbors for. |
required |
Returns:
| Type | Description |
|---|---|
Neighborhood
|
A set of neighbor node IDs (excluding the node itself). |
Source code in hyperbench/types/hypergraph.py
neighbors_of_all()
¶
Build a mapping from every node to its neighbors.
This precomputes neighbors_of for all nodes at once, which is
more efficient when scoring many candidate hyperedges.
Returns:
| Type | Description |
|---|---|
dict[int, Neighborhood]
|
A dictionary mapping each node ID to its set of neighbors. |
Source code in hyperbench/types/hypergraph.py
stats()
¶
Return basic statistics about the hypergraph.
Source code in hyperbench/types/hypergraph.py
from_hyperedge_index(hyperedge_index)
classmethod
¶
Create a Hypergraph from a hyperedge index representation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hyperedge_index
|
Tensor
|
Tensor of shape (2, |E|) representing hyperedges, where each column is (node, hyperedge). |
required |
Returns:
| Type | Description |
|---|---|
Hypergraph
|
Hypergraph instance |
Source code in hyperbench/types/hypergraph.py
smoothing_with_matrix(x, matrix, drop_rate=0.0)
staticmethod
¶
Return the feature matrix smoothed with a smoothing matrix.
Computes M @ X where M is the smoothing matrix and X is the node feature matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Node feature matrix. Size |
required |
matrix
|
Tensor
|
The smoothing matrix. Size |
required |
drop_rate
|
float
|
Randomly dropout the connections in the smoothing matrix with probability |
0.0
|
Returns:
| Type | Description |
|---|---|
Tensor
|
The smoothed feature matrix. Size |
Source code in hyperbench/types/hypergraph.py
HyperedgeIndex
¶
A wrapper for hyperedge index representation.
Hyperedge index is a tensor of shape (2, num_incidences) that encodes the relationships between nodes and hyperedges.
Each column in the tensor represents an incidence between a node and a hyperedge, with the first row containing node indices
and the second row containing corresponding hyperedge indices.
Examples:
This represents two hyperedges: - Hyperedge 0 connects nodes 0, 1, and 2. - Hyperedge 1 connects node 0.
The number of nodes in this hypergraph is 3 (nodes 0, 1, and 2). The number of hyperedges is 2 (hyperedges 0 and 1).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hyperedge_index
|
Tensor
|
A tensor of shape |
required |
Source code in hyperbench/types/hypergraph.py
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 | |
all_node_ids
property
¶
Return the tensor of all node IDs in the hyperedge index.
all_hyperedge_ids
property
¶
Return the tensor of all hyperedge IDs in the hyperedge index.
item
property
¶
Return the hyperedge index tensor.
node_ids
property
¶
Return the sorted unique node IDs from the hyperedge index.
hyperedge_ids
property
¶
Return the sorted unique hyperedge IDs from the hyperedge index.
num_hyperedges
property
¶
Return the number of hyperedges in the hypergraph.
num_nodes
property
¶
Return the number of nodes in the hypergraph.
num_incidences
property
¶
Return the number of incidences in the hypergraph, which is the number of columns in the hyperedge index.
nodes_in(hyperedge_id)
¶
Return the list of node IDs that belong to the given hyperedge.
num_nodes_if_isolated_exist(num_nodes)
¶
Return the number of nodes in the hypergraph, accounting for isolated nodes that may not appear in the hyperedge index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_nodes
|
int
|
The total number of nodes in the hypergraph, including isolated nodes. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The number of nodes in the hypergraph, which is the maximum of the number of unique nodes in the hyperedge index and the provided |
Source code in hyperbench/types/hypergraph.py
get_sparse_incidence_matrix(num_nodes=None, num_hyperedges=None)
¶
Compute the sparse incidence matrix H of shape (num_nodes, num_hyperedges).
Each entry H[v, e] = 1 if node v belongs to hyperedge e, and 0 otherwise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_nodes
|
int | None
|
Total number of nodes. If |
None
|
num_hyperedges
|
int | None
|
Total number of hyperedges. If |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
The sparse incidence matrix H of shape |
Source code in hyperbench/types/hypergraph.py
get_sparse_normalized_node_degree_matrix(incidence_matrix, power, num_nodes=None)
¶
Compute a sparse diagonal node degree matrix from row-sums of the incidence matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
incidence_matrix
|
Tensor
|
The sparse incidence matrix H of shape |
required |
power
|
float
|
Exponent applied to node degrees before placing them on the diagonal. |
required |
num_nodes
|
int | None
|
Total number of nodes. If |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
The sparse diagonal matrix of shape |
Source code in hyperbench/types/hypergraph.py
get_sparse_rownormalized_node_degree_matrix(incidence_matrix, num_nodes=None)
¶
Compute the sparse normalized node degree matrix D_n^-1.
The node degree d_n[i] is the number of hyperedges containing node i
(i.e., the row-sum of the incidence matrix H).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
incidence_matrix
|
Tensor
|
The sparse incidence matrix H of shape |
required |
num_nodes
|
int | None
|
Total number of nodes. If |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
The sparse diagonal matrix D_n^-1 of shape |
Source code in hyperbench/types/hypergraph.py
get_sparse_symnormalized_node_degree_matrix(incidence_matrix, num_nodes=None)
¶
Compute the sparse normalized node degree matrix D_n^-½.
The node degree d_n[i] is the number of hyperedges containing node i
(i.e., the row-sum of the incidence matrix H).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
incidence_matrix
|
Tensor
|
The sparse incidence matrix H of shape |
required |
num_nodes
|
int | None
|
Total number of nodes. If |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
The sparse diagonal matrix D_n^-½ of shape |
Source code in hyperbench/types/hypergraph.py
get_sparse_normalized_hyperedge_degree_matrix(incidence_matrix, num_hyperedges=None)
¶
Compute the sparse normalized hyperedge degree matrix D_e^-1.
The hyperedge degree d_e[j] is the number of nodes in hyperedge j
(i.e., the column-sum of the incidence matrix H).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
incidence_matrix
|
Tensor
|
The sparse incidence matrix H of shape |
required |
num_hyperedges
|
int | None
|
Total number of hyperedges. If |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
The sparse diagonal matrix D_e^-1 of shape |
Source code in hyperbench/types/hypergraph.py
get_sparse_hgnn_smoothing_matrix(num_nodes=None, num_hyperedges=None)
¶
Compute the sparse HGNN Laplacian matrix for hypergraph spectral convolution.
Implements: L_HGNN = D_n^{-1/2} H D_e^{-1} H^T D_n^{-1/2}
where
- H is the incidence matrix of shape
(num_nodes, num_hyperedges) - D_n^-½ is the normalized node degree matrix
- D_e^-1 is the inverse hyperedge degree matrix (with W = I)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_nodes
|
int | None
|
Total number of nodes. If |
None
|
num_hyperedges
|
int | None
|
Total number of hyperedges. If |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
The sparse HGNN Laplacian matrix of shape |
Source code in hyperbench/types/hypergraph.py
get_sparse_hgnnp_smoothing_matrix(num_nodes=None, num_hyperedges=None)
¶
Compute the sparse HGNN+ smoothing matrix for hypergraph mean aggregation.
Implements: M_HGNN+ = D_v^{-1} H D_e^{-1} H^T
This matrix is row-stochastic for non-isolated nodes and corresponds to
the two-stage mean aggregation used by HGNN+:
1. D_e^{-1} H^T X: mean over nodes in each hyperedge.
2. D_v^{-1} H (...): mean over hyperedges incident to each node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_nodes
|
int | None
|
Total number of nodes. If |
None
|
num_hyperedges
|
int | None
|
Total number of hyperedges. If |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
The sparse HGNN+ smoothing matrix of shape |
Source code in hyperbench/types/hypergraph.py
reduce(strategy, **kwargs)
¶
Reduce the hypergraph to a graph represented by edge index using the specified strategy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
strategy
|
Literal['clique_expansion']
|
The reduction strategy to use. Defaults to |
required |
**kwargs
|
Additional keyword arguments for specific strategies. |
{}
|
Returns:
| Type | Description |
|---|---|
Tensor
|
The edge index of the reduced graph. Size |
Source code in hyperbench/types/hypergraph.py
reduce_to_edge_index_on_clique_expansion()
¶
Construct a graph from a hypergraph via clique expansion using H @ H^T, where H is the incidence matrix of the hypergraph.
In clique expansion, each hyperedge is replaced by a clique connecting all its member nodes.
For each hyperedge, all pairs of member nodes become edges in the resulting graph.
This is computed efficiently using the incidence matrix: A = H @ H^T, where H is
the sparse incidence matrix of shape [num_nodes, num_hyperedges] and A is the adjacency matrix of the clique-expanded graph.
Returns:
| Type | Description |
|---|---|
Tensor
|
The edge index of the clique-expanded graph. Size |
Source code in hyperbench/types/hypergraph.py
reduce_to_edge_index_on_random_direction(x, with_mediators=False, remove_selfloops=True, return_weights=False)
¶
Construct a graph from a hypergraph with methods proposed in HyperGCN: A New Method of Training Graph Convolutional Networks on Hypergraphs <https://arxiv.org/pdf/1809.02589.pdf>_ paper.
Reference implementation: source <https://deephypergraph.readthedocs.io/en/latest/_modules/dhg/structure/graphs/graph.html#Graph.from_hypergraph_hypergcn>_.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Node feature matrix. Size |
required |
with_mediators
|
bool
|
Whether to use mediator to transform the hyperedges to edges in the graph. Defaults to |
False
|
remove_selfloops
|
bool
|
Whether to remove self-loops. Defaults to |
True
|
return_weights
|
bool
|
Whether to return the DHG-style reduced-edge weights alongside the edge index. Defaults to |
False
|
Returns:
| Type | Description |
|---|---|
Tensor
|
A tuple |
Tensor | None
|
|
tuple[Tensor, Tensor | None]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If any hyperedge contains fewer than 2 nodes. |
Source code in hyperbench/types/hypergraph.py
remove_duplicate_edges()
¶
Remove duplicate edges from the hyperedge index. Keeps the tensor contiguous in memory.
Source code in hyperbench/types/hypergraph.py
remove_hyperedges_with_fewer_than_k_nodes(k)
¶
Remove hyperedges that contain fewer than k nodes.
Example
hyperedge_index = [[0, 1, 2, 3, 5, 4], ... [0, 0, 1, 1, 2, 1]], shape (2, |E| = 6)
k = 3 unique_hyperedge_ids: [0, 1, 2] ... # inverse -> idx_to_hyperedge_id, counts -> num_nodes_per_hyperedge ... inverse = [0, 0, 1, 1, 2, 1] # (index into unique_hyperedge_ids per column) ... counts = [2, 3, 1]
counts[inverse] is equivalent to:¶
... # for i, inv in enumerate(inverse): keep_mask[i] = counts[inv] counts[inverse] = [2, 2, 3, 3, 1, 3] keep_mask = [F, F, T, T, F, T]
after filtering hyperedges with fewer than k=3 nodes:¶
hyperedge_index = [[2, 3, 4], ... [1, 1, 1]], shape (2, |E'| = 3)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
int
|
The minimum number of nodes a hyperedge must contain to be kept. |
required |
Returns:
| Type | Description |
|---|---|
HyperedgeIndex
|
A new :class: |
Source code in hyperbench/types/hypergraph.py
to_0based(node_ids_to_rebase=None, hyperedge_ids_to_rebase=None)
¶
Convert hyperedge index to the 0-based format by rebasing node IDs to the range [0, num_nodes-1] and hyperedge IDs [0, num_hyperedges-1].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_ids_to_rebase
|
Tensor | None
|
Tensor of shape |
None
|
hyperedge_ids_to_rebase
|
Tensor | None
|
Tensor of shape |
None
|
Returns:
| Type | Description |
|---|---|
HyperedgeIndex
|
A new :class: |
Source code in hyperbench/types/hypergraph.py
HData
¶
Container for hypergraph data.
Examples:
>>> x = torch.randn(10, 16) # 10 nodes with 16 features each
>>> hyperedge_index = torch.tensor([[0, 0, 1, 1, 1], # node IDs
... [0, 1, 2, 3, 4]]) # hyperedge IDs
>>> data = HData(x=x, hyperedge_index=hyperedge_index)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Node feature matrix of shape |
required |
hyperedge_index
|
Tensor
|
Hyperedge connectivity in COO format of shape |
required |
hyperedge_weights
|
Tensor | None
|
Optional tensor of shape |
None
|
hyperedge_attr
|
Tensor | None
|
Hyperedge feature matrix of shape |
None
|
num_nodes
|
int | None
|
Number of nodes in the hypergraph.
If |
None
|
num_hyperedges
|
int | None
|
Number of hyperedges in the hypergraph.
If |
None
|
y
|
Tensor | None
|
Labels for hyperedges, of shape |
None
|
global_node_ids
|
Tensor | None
|
Optional stable node IDs of shape |
None
|
Source code in hyperbench/types/hdata.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 | |
cat_same_node_space(hdatas, x=None)
classmethod
¶
Concatenate :class:HData instances that share the same node space, meaning nodes with the same ID in different instances are the same node.
This is useful when combining positive and negative hyperedges that reference the same set of nodes.
Notes
xis derived from the instance with the largest number of nodes, if not provided explicitly. If there are conflicting features for the same node ID across instances, the features from the instance with the largest number of nodes will be used.hyperedge_indexis the concatenation of all input hyperedge indices.hyperedge_weightsis the concatenation of all input hyperedge weights, if present. If some instances have hyperedge weights and others do not, the resultinghyperedge_weightswill be set toNone.hyperedge_attris the concatenation of all input hyperedge attributes, if present. If some instances have hyperedge attributes and others do not, the resultinghyperedge_attrwill be set toNone.yis the concatenation of all input labels.
Examples:
>>> x = torch.randn(5, 8)
>>> pos = HData(x=x, hyperedge_index=torch.tensor([[0, 1, 2, 3, 4], [0, 0, 1, 2, 2]]))
>>> neg = HData(x=x, hyperedge_index=torch.tensor([[0, 2], [3, 3]]))
>>> new = HData.cat_same_node_space([pos, neg])
>>> new.num_nodes # 5 — nodes [0, 1, 2, 3, 4]
>>> new.num_hyperedges # 4 — hyperedges [0, 1, 2, 3]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hdatas
|
Sequence[HData]
|
One or more :class: |
required |
x
|
Tensor | None
|
Optional node feature matrix to use for the resulting :class: |
None
|
Returns:
| Type | Description |
|---|---|
HData
|
A new :class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the node counts do not match across inputs. |
Source code in hyperbench/types/hdata.py
add_negative_samples(negative_sampler, seed=None)
¶
Return a new :class:HData with sampled negative hyperedges added.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
negative_sampler
|
NegativeSampler
|
Sampler used to generate negative hyperedges from this instance. |
required |
seed
|
int | None
|
Optional random seed used for both negative sampling and the final shuffle. |
None
|
Returns:
| Type | Description |
|---|---|
HData
|
A new :class: |
Source code in hyperbench/types/hdata.py
from_hyperedge_index(hyperedge_index)
classmethod
¶
Build an :class:HData from a given hyperedge index, with empty node features and hyperedge attributes.
- Node features are initialized as an empty tensor of shape
[0, 0]. - Hyperedge attributes are set to
None. - Hyperedge weights are set to
None. - The number of nodes and hyperedges are inferred from the hyperedge index.
Examples:
>>> hyperedge_index = [[0, 0, 1, 2, 3, 4],
... [0, 0, 0, 1, 2, 2]]
>>> num_nodes = 5
>>> num_hyperedges = 3
>>> x = [] # Empty node features with shape [0, 0]
>>> hyperedge_attr = None
>>> hyperedge_weights = None
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hyperedge_index
|
Tensor
|
Tensor of shape |
required |
Returns:
| Name | Type | Description |
|---|---|---|
An |
HData
|
class: |
Source code in hyperbench/types/hdata.py
split(hdata, split_hyperedge_ids, node_space_setting='transductive')
classmethod
¶
Build an :class:HData for a single split from the given hyperedge IDs.
Examples:
Transductive split (default) preserving the full node space:
>>> split_hdata = HData.split(hdata, torch.tensor([1]), node_space_setting="transductive")
>>> split_hdata.x.shape[0] == hdata.x.shape[0]
>>> split_hdata.hyperedge_index
... # node IDs stay in the original row space, hyperedge IDs are rebased
Inductive split:
>>> split_hdata = HData.split(hdata, torch.tensor([1]), node_space_setting="inductive")
>>> split_hdata.x.shape[0] # only nodes incident to hyperedge 1
... 2
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hdata
|
HData
|
The original :class: |
required |
split_hyperedge_ids
|
Tensor
|
Tensor of hyperedge IDs to include in this split. |
required |
node_space_setting
|
NodeSpaceSetting
|
Whether to preserve the full node space in the splits.
|
'transductive'
|
Returns:
| Type | Description |
|---|---|
HData
|
The splitted instance with remapped node and hyperedge IDs. |
Source code in hyperbench/types/hdata.py
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 | |
enrich_node_features(enricher, enrichment_mode=None)
¶
Enrich node features using the provided node feature enricher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
enricher
|
NodeEnricher
|
An instance of NodeEnricher to generate structural node features from hypergraph topology. |
required |
enrichment_mode
|
EnrichmentMode | None
|
How to combine generated features with existing |
None
|
Source code in hyperbench/types/hdata.py
enrich_node_features_from(hdata_with_features, node_space_setting='transductive', fill_value=None)
¶
Copy node features from another :class:HData by aligning features by global_node_ids.
Examples:
Transductive enrichment (default) expecting the same node space in both source and target:
Inductive with a scalar fill value:
>>> target = target.enrich_node_features_from(
... source,
... node_space_setting="inductive",
... fill_value=0.0,
... )
Inductive with a feature vector fill value:
>>> target = target.enrich_node_features_from(
... source,
... node_space_setting="inductive",
... fill_value=[0.0, 1.0, 0.0],
... )
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hdata_with_features
|
HData
|
Source :class: |
required |
node_space_setting
|
NodeSpaceSetting
|
The setting for the node space, determining how nodes are handled.
If |
'transductive'
|
fill_value
|
NodeSpaceFiller | None
|
Scalar or vector used to fill missing node features when |
None
|
Returns:
| Type | Description |
|---|---|
HData
|
A new :class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If either instance lacks |
Source code in hyperbench/types/hdata.py
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 | |
enrich_hyperedge_weights(enricher, enrichment_mode=None)
¶
Enrich hyperedge weights using the provided hyperedge weight enricher.
Args:
enricher: An instance of HyperedgeEnricher to generate hyperedge weights from hypergraph topology.
enrichment_mode: How to combine generated weights with existing hdata.hyperedge_weights.
concatenate appends new weights to the existing 1D tensor.
replace substitutes hdata.hyperedge_weights entirely.
Source code in hyperbench/types/hdata.py
enrich_hyperedge_attr(enricher, enrichment_mode=None)
¶
Enrich hyperedge features using the provided hyperedge feature enricher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
enricher
|
HyperedgeEnricher
|
An instance of HyperedgeEnricher to generate structural hyperedge features from hypergraph topology. |
required |
enrichment_mode
|
EnrichmentMode | None
|
How to combine generated features with existing |
None
|
Source code in hyperbench/types/hdata.py
get_device_if_all_consistent()
¶
Check that all tensors are on the same device and return that device. If there are no tensors or if they are on different devices, return CPU.
Returns:
| Type | Description |
|---|---|
device
|
The common device if all tensors are on the same device, otherwise CPU. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If tensors are on different devices. |
Source code in hyperbench/types/hdata.py
shuffle(seed=None)
¶
Return a new :class:HData instance with hyperedge IDs randomly reassigned.
Each hyperedge keeps its original set of nodes, but is assigned a new ID via a random permutation.
y and hyperedge_attr are reordered to match, so that y[new_id] still corresponds to the correct hyperedge.
Same for hyperedge_attr[new_id] if hyperedge attributes are present.
Examples:
>>> hyperedge_index = torch.tensor([[0, 1, 2, 3], [0, 0, 1, 1]])
>>> y = torch.tensor([1, 0])
>>> hdata = HData(x=x, hyperedge_index=hyperedge_index, y=y)
>>> shuffled_hdata = hdata.shuffle(seed=42)
>>> shuffled_hdata.hyperedge_index # hyperedges may be reassigned
... # e.g.,
... [[0, 1, 2, 3],
... [1, 1, 0, 0]]
>>> shuffled_hdata.y # labels are permuted to match new hyperedge IDs, e.g., [0, 1]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seed
|
int | None
|
Optional random seed for reproducibility. If |
None
|
Returns:
| Type | Description |
|---|---|
HData
|
A new :class: |
Source code in hyperbench/types/hdata.py
clone()
¶
Return a deep copy of this :class:HData.
Returns:
| Type | Description |
|---|---|
HData
|
A new :class: |
Source code in hyperbench/types/hdata.py
to(device, non_blocking=False)
¶
Move all tensors to the specified device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
device | str
|
The target device (e.g., 'cpu', 'cuda:0'). |
required |
non_blocking
|
bool
|
If |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
The |
HData
|
class: |
Source code in hyperbench/types/hdata.py
with_y_to(value)
¶
Return a copy of this instance with a y attribute set to the given value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
The value to set for all entries in the y attribute. |
required |
Returns:
| Type | Description |
|---|---|
HData
|
A new :class: |
Source code in hyperbench/types/hdata.py
with_y_ones()
¶
with_y_zeros()
¶
stats()
¶
Compute statistics for the hypergraph data.
The fields returned in the dictionary include:
- shape_x: The shape of the node feature matrix x.
- shape_hyperedge_weights: The shape of the hyperedge weights tensor, or None if hyperedge weights are not present.
- shape_hyperedge_attr: The shape of the hyperedge attribute matrix, or None if hyperedge attributes are not present.
- num_nodes: The number of nodes in the hypergraph.
- num_hyperedges: The number of hyperedges in the hypergraph.
- avg_degree_node_raw: The average degree of nodes, calculated as the mean number of hyperedges each node belongs to.
- avg_degree_node: The floored node average degree.
- avg_degree_hyperedge_raw: The average size of hyperedges, calculated as the mean number of nodes each hyperedge contains.
- avg_degree_hyperedge: The floored hyperedge average size.
- node_degree_max: The maximum degree of any node in the hypergraph.
- hyperedge_degree_max: The maximum size of any hyperedge in the hypergraph.
- node_degree_median: The median degree of nodes in the hypergraph.
- hyperedge_degree_median: The median size of hyperedges in the hypergraph.
- distribution_node_degree: A list where the value at index i represents the count of nodes with degree i.
- distribution_hyperedge_size: A list where the value at index i represents the count of hyperedges with size i.
- distribution_node_degree_hist: A dictionary where the keys are node degrees and the values are the count of nodes with that degree.
- distribution_hyperedge_size_hist: A dictionary where the keys are hyperedge sizes and the values are the count of hyperedges with that size.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dictionary containing various statistics about the hypergraph. |
Source code in hyperbench/types/hdata.py
790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 | |
ModelConfig
¶
A class representing the configuration of a model for training.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the model. |
required |
version
|
str
|
The version of the model. |
'default'
|
model
|
LightningModule
|
a LightningModule instance. |
required |
is_trainable
|
bool
|
Whether the model is trainable. |
True
|
trainer
|
Trainer | None
|
a Trainer instance. |
None
|
train_dataloader
|
DataLoader | None
|
Optional per-model train dataloader. When set, |
None
|
val_dataloader
|
DataLoader | None
|
Optional per-model validation dataloader. When set, |
None
|
test_dataloader
|
DataLoader | None
|
Optional per-model test dataloader. When set, |
None
|