Coverage for src/abcd_graph/callbacks/property_collector.py: 100%
48 statements
« prev ^ index » next coverage.py v7.5.3, created at 2024-12-04 21:31 +0100
« prev ^ index » next coverage.py v7.5.3, created at 2024-12-04 21:31 +0100
1# Copyright (c) 2024 Jordan Barrett & Aleksander Wojnarowicz
2#
3# Permission is hereby granted, free of charge, to any person obtaining a copy
4# of this software and associated documentation files (the "Software"), to deal
5# in the Software without restriction, including without limitation the rights
6# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7# copies of the Software, and to permit persons to whom the Software is
8# furnished to do so, subject to the following conditions:
9#
10# The above copyright notice and this permission notice shall be included in all
11# copies or substantial portions of the Software.
12#
13# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19# SOFTWARE.
21from typing import Optional
23import numpy as np
24from numpy.typing import NDArray
26from abcd_graph.callbacks.abstract import (
27 ABCDCallback,
28 BuildContext,
29)
30from abcd_graph.exporter import GraphExporter
31from abcd_graph.graph.core.abcd_objects import (
32 Community,
33 GraphImpl,
34)
37class PropertyCollector(ABCDCallback):
38 def __init__(self) -> None:
39 self._graph: Optional[GraphImpl] = None
41 self._communities: list[Community] = []
43 self._degree_sequence: dict[int, int] = {}
45 self._xi_matrix: Optional[NDArray[np.float64]] = None
47 self._expected_degree_cdf: dict[int, float] = {}
49 self._actual_degree_cdf: dict[int, float] = {}
51 self._expected_community_cdf: dict[int, float] = {}
53 self._actual_community_cdf: dict[int, float] = {}
55 def after_build(self, graph: GraphImpl, context: BuildContext, exporter: GraphExporter) -> None:
56 self._graph = graph
58 @property
59 def degree_sequence(self) -> dict[int, int]:
60 if not self._degree_sequence:
61 self._degree_sequence = self._graph.degree_sequence # type: ignore[union-attr]
63 return self._degree_sequence
65 @property
66 def xi_matrix(self) -> NDArray[np.float64]:
67 if self._xi_matrix is None:
68 self._xi_matrix = self._graph.xi_matrix # type: ignore[union-attr]
69 return self._xi_matrix
71 @property
72 def expected_degree_cdf(self) -> dict[int, float]:
73 if not self._expected_degree_cdf:
74 self._expected_degree_cdf = self._graph.expected_degree_cdf # type: ignore[union-attr]
76 return self._expected_degree_cdf
78 @property
79 def actual_degree_cdf(self) -> dict[int, float]:
80 if not self._actual_degree_cdf:
81 self._actual_degree_cdf = self._graph.actual_degree_cdf # type: ignore[union-attr]
83 return self._actual_degree_cdf
85 @property
86 def expected_community_cdf(self) -> dict[int, float]:
87 if not self._expected_community_cdf:
88 self._expected_community_cdf = self._graph.expected_community_cdf # type: ignore[union-attr]
90 return self._expected_community_cdf
92 @property
93 def actual_community_cdf(self) -> dict[int, float]:
94 if not self._actual_community_cdf:
95 self._actual_community_cdf = self._graph.actual_community_cdf # type: ignore[union-attr]
97 return self._actual_community_cdf