graph_interdependence
Bases: interdependence
A graph-based interdependence function.
This class computes the interdependence matrix using a graph structure, allowing relationships to be modeled based on nodes and edges in the graph.
Notes
Based on the graph structure, we define the graph interdependence function as:
\[ \begin{equation}\label{equ:graph_interdependence_function} \xi(\mathbf{x} | G) = \mathbf{A} \in R^{m \times m'}, \end{equation} \]
where the output dimension \(m' = m\) by default.
Attributes:
Name | Type | Description |
---|---|---|
graph |
graph
|
The graph structure representing the interdependence. |
node_id_index_map |
dict
|
Mapping of node IDs to their indices in the matrix. |
node_index_id_map |
dict
|
Mapping of matrix indices back to their corresponding node IDs. |
normalization |
bool
|
Whether to normalize the interdependence matrix. |
normalization_mode |
str
|
The mode of normalization ('row', 'column', etc.). |
self_dependence |
bool
|
Whether nodes are self-dependent. |
Methods:
Name | Description |
---|---|
__init__ |
Initializes the graph-based interdependence function. |
get_node_index_id_map |
Retrieves the mapping from indices to node IDs. |
get_node_id_index_map |
Retrieves the mapping from node IDs to indices. |
calculate_A |
Computes the interdependence matrix using the graph structure. |
Source code in tinybig/interdependence/topological_interdependence.py
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 |
|
__init__(b, m, interdependence_type='instance', name='graph_interdependence', graph=None, nodes=None, links=None, directed=True, normalization=False, normalization_mode='row', self_dependence=False, require_data=False, require_parameters=False, device='cpu', *args, **kwargs)
Initializes the graph-based interdependence function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
b
|
int
|
Number of rows in the input tensor. |
required |
m
|
int
|
Number of columns in the input tensor. |
required |
interdependence_type
|
str
|
Type of interdependence ('instance', 'attribute', etc.). Defaults to 'instance'. |
'instance'
|
name
|
str
|
Name of the interdependence function. Defaults to 'graph_interdependence'. |
'graph_interdependence'
|
graph
|
graph
|
Predefined graph structure. Defaults to None. |
None
|
nodes
|
list
|
List of nodes in the graph. Required if |
None
|
links
|
list
|
List of links (edges) in the graph. Required if |
None
|
directed
|
bool
|
Whether the graph is directed. Defaults to True. |
True
|
normalization
|
bool
|
Whether to normalize the interdependence matrix. Defaults to False. |
False
|
normalization_mode
|
str
|
The mode of normalization ('row', 'column', etc.). Defaults to 'row'. |
'row'
|
self_dependence
|
bool
|
Whether nodes are self-dependent. Defaults to False. |
False
|
require_data
|
bool
|
Whether the interdependence function requires data. Defaults to False. |
False
|
require_parameters
|
bool
|
Whether the interdependence function requires parameters. Defaults to False. |
False
|
device
|
str
|
Device for computation ('cpu', 'cuda'). Defaults to 'cpu'. |
'cpu'
|
*args
|
tuple
|
Additional positional arguments for the parent class. |
()
|
**kwargs
|
dict
|
Additional keyword arguments for the parent class. |
{}
|
Raises:
Type | Description |
---|---|
ValueError
|
If neither |
Source code in tinybig/interdependence/topological_interdependence.py
calculate_A(x=None, w=None, device='cpu', *args, **kwargs)
Computes the interdependence matrix using the graph structure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
Input tensor of shape |
None
|
w
|
Parameter
|
Parameter tensor. Defaults to None. |
None
|
device
|
str
|
Device for computation ('cpu', 'cuda'). Defaults to 'cpu'. |
'cpu'
|
*args
|
tuple
|
Additional positional arguments. |
()
|
**kwargs
|
dict
|
Additional keyword arguments. |
{}
|
Returns:
Type | Description |
---|---|
Tensor
|
The computed interdependence matrix. |
Raises:
Type | Description |
---|---|
AssertionError
|
If the computed matrix shape is invalid. |
Source code in tinybig/interdependence/topological_interdependence.py
get_node_id_index_map()
Retrieves the mapping from node IDs to indices.
Returns:
Type | Description |
---|---|
dict
|
A dictionary mapping node IDs to matrix indices. |
Warnings
If the mapping has not been assigned, a warning will be raised.
Source code in tinybig/interdependence/topological_interdependence.py
get_node_index_id_map()
Retrieves the mapping from indices to node IDs.
Returns:
Type | Description |
---|---|
dict
|
A dictionary mapping matrix indices to node IDs. |
Warnings
If the mapping has not been assigned, a warning will be raised.