Comparison analysis¶
Comparison provides classes for comparing Graph objects to find the
commonalities (sigma) and differences (delta).
Comparison methods¶
- sigma_graphto calculate the commonalities (i.e. sum) of a set of graphs with comparable node names.
- delta_graphto calculate the differences and overlap between two graphs with comparable node names.
dataclass
  
¶
EdgeDescriptor(
    source: str,
    target: str,
    kind: str,
    labels: FrozenSet[str],
    weights: FrozenSet[Tuple[str, float]],
)
              Bases: EdgeDescriptorLike
Describe a node based on its source name, target name, kind, labels, and weights.
    
              Bases: ABC
A class that takes an edge and describes it by returning a fixed (hashable) output.
Hashable means that the description can be used to determine uniqueness by set operations.
abstractmethod
      classmethod
  
¶
from_edge(edge: Edge) -> EdgeDescriptor
dataclass
  
¶
    
    
              Bases: ABC
A class that takes a node and describes it by returning a fixed (hashable) output.
Hashable means that the description can be used to determine uniqueness by set operations.
abstractmethod
      classmethod
  
¶
from_node(node: Node) -> NodeDescriptorLike
abstractmethod
  
¶
    Create a node from a descriptor in a graph and return it for convenience.
    
              Bases: StrEnum
Aggregation mode for sigma analysis, absolute counted occurrences or an average per graph.
    
              Bases: StrEnum
How to tag nodes as unique to one of the given inputs or common.
    Add observed edges in item to the accumulator in-place.
Based on node names.
Metadata for existing nodes is added using
add_meta method.
Source code in src/ragraph/analysis/comparison/_sigma.py
              
    Add a graph to an accumulator graph. Occurrences are counted under the 'count_prefix'.
Source code in src/ragraph/analysis/comparison/_sigma.py
              
    Add metadata of another item to the accumulator in-place. Annotations are updated and the last observed value for any key is kept. Occurrence value is tracked under the 'count_prefix'.
Source code in src/ragraph/analysis/comparison/_sigma.py
              
    Add observed nodes in item to the accumulator in-place and keep track of an occurrence count.
Based on node names.
Metadata for existing nodes is added using
add_meta method.
Source code in src/ragraph/analysis/comparison/_sigma.py
              
delta_graph(
    graph_a: Graph,
    graph_b: Graph,
    delta_a: str = "delta_a",
    delta_b: str = "delta_b",
    common: str = "common",
    tag_mode: TagMode = KIND,
    node_descriptor: Type[
        NodeDescriptorLike
    ] = NodeDescriptor,
    edge_descriptor: Type[
        EdgeDescriptorLike
    ] = EdgeDescriptor,
) -> Graph
Get the delta graph between two graphs.
Parameters:
| Name | Type | Description | Default | 
|---|---|---|---|
| graph_a | Graph | First graph to compare. | required | 
| graph_b | Graph | Second graph to compare. | required | 
| delta_a | str | Name for nodes and edges unique to the first graph. | 'delta_a' | 
| delta_b | str | Name for nodes and edges unique to the second graph. | 'delta_b' | 
| common | str | Name for the common nodes and edges occurring in both graphs. | 'common' | 
Note
Graphs are compared on leaf node level and compared by name only.
Please provide appropriate input as such and look to
get_graph_slice for example on how to obtain a
subgraph to your liking.
Source code in src/ragraph/analysis/comparison/_delta.py
              
    Increment the occurrence and label counts as weights in the accumulator with an item.
Source code in src/ragraph/analysis/comparison/_sigma.py
              
    Initialize an accumulator instance with the info from the first item.
Source code in src/ragraph/analysis/comparison/_sigma.py
              
sigma_graph(
    graphs: Iterable[Graph],
    count_prefix: str = "sigma",
    mode: SigmaMode = ABSOLUTE,
) -> Graph
Get the sigma (summed) graph based on the leaf nodes and the edges in multiple graphs.
Parameters:
| Name | Type | Description | Default | 
|---|---|---|---|
| graphs | Iterable[Graph] | Graphs to sum and count edge occurrences in. | required | 
| mode | SigmaMode | Whether to count absolute occurrence values or an average per graph. | ABSOLUTE | 
| count_prefix | str | Which weight key (prefix) to store the occurrence values under. Also used as a prefix for label counts that are stored as weights using as well. | 'sigma' | 
Note
Summations are done over (leaf) node names. Edges in an input graph are aggregated first
using the add_meta method
before being aggregated into the resulting graph.
Source code in src/ragraph/analysis/comparison/_sigma.py
              
    Tag an item using a given tagging mode.
Source code in src/ragraph/analysis/comparison/utils.py
              
    Delta analysis¶
delta_graph(
    graph_a: Graph,
    graph_b: Graph,
    delta_a: str = "delta_a",
    delta_b: str = "delta_b",
    common: str = "common",
    tag_mode: TagMode = KIND,
    node_descriptor: Type[
        NodeDescriptorLike
    ] = NodeDescriptor,
    edge_descriptor: Type[
        EdgeDescriptorLike
    ] = EdgeDescriptor,
) -> Graph
Get the delta graph between two graphs.
Parameters:
| Name | Type | Description | Default | 
|---|---|---|---|
| graph_a | Graph | First graph to compare. | required | 
| graph_b | Graph | Second graph to compare. | required | 
| delta_a | str | Name for nodes and edges unique to the first graph. | 'delta_a' | 
| delta_b | str | Name for nodes and edges unique to the second graph. | 'delta_b' | 
| common | str | Name for the common nodes and edges occurring in both graphs. | 'common' | 
Note
Graphs are compared on leaf node level and compared by name only.
Please provide appropriate input as such and look to
get_graph_slice for example on how to obtain a
subgraph to your liking.
Source code in src/ragraph/analysis/comparison/_delta.py
              
    Sigma analysis¶
    
              Bases: StrEnum
Aggregation mode for sigma analysis, absolute counted occurrences or an average per graph.
    Add observed edges in item to the accumulator in-place.
Based on node names.
Metadata for existing nodes is added using
add_meta method.
Source code in src/ragraph/analysis/comparison/_sigma.py
              
    Add a graph to an accumulator graph. Occurrences are counted under the 'count_prefix'.
Source code in src/ragraph/analysis/comparison/_sigma.py
              
    Add metadata of another item to the accumulator in-place. Annotations are updated and the last observed value for any key is kept. Occurrence value is tracked under the 'count_prefix'.
Source code in src/ragraph/analysis/comparison/_sigma.py
              
    Add observed nodes in item to the accumulator in-place and keep track of an occurrence count.
Based on node names.
Metadata for existing nodes is added using
add_meta method.
Source code in src/ragraph/analysis/comparison/_sigma.py
              
    Increment the occurrence and label counts as weights in the accumulator with an item.
Source code in src/ragraph/analysis/comparison/_sigma.py
              
    Initialize an accumulator instance with the info from the first item.
Source code in src/ragraph/analysis/comparison/_sigma.py
              
sigma_graph(
    graphs: Iterable[Graph],
    count_prefix: str = "sigma",
    mode: SigmaMode = ABSOLUTE,
) -> Graph
Get the sigma (summed) graph based on the leaf nodes and the edges in multiple graphs.
Parameters:
| Name | Type | Description | Default | 
|---|---|---|---|
| graphs | Iterable[Graph] | Graphs to sum and count edge occurrences in. | required | 
| mode | SigmaMode | Whether to count absolute occurrence values or an average per graph. | ABSOLUTE | 
| count_prefix | str | Which weight key (prefix) to store the occurrence values under. Also used as a prefix for label counts that are stored as weights using as well. | 'sigma' | 
Note
Summations are done over (leaf) node names. Edges in an input graph are aggregated first
using the add_meta method
before being aggregated into the resulting graph.
Source code in src/ragraph/analysis/comparison/_sigma.py
              
    Comparison analysis utilities¶
dataclass
  
¶
EdgeDescriptor(
    source: str,
    target: str,
    kind: str,
    labels: FrozenSet[str],
    weights: FrozenSet[Tuple[str, float]],
)
              Bases: EdgeDescriptorLike
Describe a node based on its source name, target name, kind, labels, and weights.
    
              Bases: ABC
A class that takes an edge and describes it by returning a fixed (hashable) output.
Hashable means that the description can be used to determine uniqueness by set operations.
abstractmethod
      classmethod
  
¶
from_edge(edge: Edge) -> EdgeDescriptor
dataclass
  
¶
    
    
              Bases: ABC
A class that takes a node and describes it by returning a fixed (hashable) output.
Hashable means that the description can be used to determine uniqueness by set operations.
abstractmethod
      classmethod
  
¶
from_node(node: Node) -> NodeDescriptorLike
abstractmethod
  
¶
    Create a node from a descriptor in a graph and return it for convenience.
    
              Bases: StrEnum
How to tag nodes as unique to one of the given inputs or common.
    Tag an item using a given tagging mode.