|
20 | 20 | class StructureEvaluator: |
21 | 21 | """Evaluates structural robustness of the graph.""" |
22 | 22 |
|
23 | | - # Thresholds for structural metrics |
24 | | - NOISE_RATIO_THRESHOLD = 0.15 |
25 | | - LARGEST_CC_RATIO_THRESHOLD = 0.90 |
26 | | - AVG_DEGREE_MIN = 2 |
27 | | - AVG_DEGREE_MAX = 5 |
28 | | - POWERLAW_R2_THRESHOLD = 0.75 |
29 | | - |
30 | | - def __init__(self, graph_storage: BaseGraphStorage): |
| 23 | + def __init__( |
| 24 | + self, |
| 25 | + graph_storage: BaseGraphStorage, |
| 26 | + noise_ratio_threshold: float = 0.15, |
| 27 | + largest_cc_ratio_threshold: float = 0.90, |
| 28 | + avg_degree_min: float = 2.0, |
| 29 | + avg_degree_max: float = 5.0, |
| 30 | + powerlaw_r2_threshold: float = 0.75, |
| 31 | + ): |
31 | 32 | self.graph_storage = graph_storage |
| 33 | + self.noise_ratio_threshold = noise_ratio_threshold |
| 34 | + self.largest_cc_ratio_threshold = largest_cc_ratio_threshold |
| 35 | + self.avg_degree_min = avg_degree_min |
| 36 | + self.avg_degree_max = avg_degree_max |
| 37 | + self.powerlaw_r2_threshold = powerlaw_r2_threshold |
32 | 38 |
|
33 | 39 | def evaluate(self) -> Dict[str, Any]: |
34 | 40 | if nx is None: |
@@ -73,27 +79,26 @@ def evaluate(self) -> Dict[str, Any]: |
73 | 79 | # Power law distribution R² |
74 | 80 | powerlaw_r2 = self._calculate_powerlaw_r2(G) |
75 | 81 |
|
76 | | - # Check thresholds |
77 | 82 | thresholds = { |
78 | 83 | "noise_ratio": { |
79 | 84 | "value": noise_ratio, |
80 | | - "threshold": self.NOISE_RATIO_THRESHOLD, |
81 | | - "pass": noise_ratio < self.NOISE_RATIO_THRESHOLD, |
| 85 | + "threshold": self.noise_ratio_threshold, |
| 86 | + "pass": noise_ratio < self.noise_ratio_threshold, |
82 | 87 | }, |
83 | 88 | "largest_cc_ratio": { |
84 | 89 | "value": largest_cc_ratio, |
85 | | - "threshold": self.LARGEST_CC_RATIO_THRESHOLD, |
86 | | - "pass": largest_cc_ratio > self.LARGEST_CC_RATIO_THRESHOLD, |
| 90 | + "threshold": self.largest_cc_ratio_threshold, |
| 91 | + "pass": largest_cc_ratio > self.largest_cc_ratio_threshold, |
87 | 92 | }, |
88 | 93 | "avg_degree": { |
89 | 94 | "value": avg_degree, |
90 | | - "threshold": (self.AVG_DEGREE_MIN, self.AVG_DEGREE_MAX), |
91 | | - "pass": self.AVG_DEGREE_MIN <= avg_degree <= self.AVG_DEGREE_MAX, |
| 95 | + "threshold": (self.avg_degree_min, self.avg_degree_max), |
| 96 | + "pass": self.avg_degree_min <= avg_degree <= self.avg_degree_max, |
92 | 97 | }, |
93 | 98 | "powerlaw_r2": { |
94 | 99 | "value": powerlaw_r2, |
95 | | - "threshold": self.POWERLAW_R2_THRESHOLD, |
96 | | - "pass": powerlaw_r2 > self.POWERLAW_R2_THRESHOLD if powerlaw_r2 is not None else False, |
| 100 | + "threshold": self.powerlaw_r2_threshold, |
| 101 | + "pass": powerlaw_r2 > self.powerlaw_r2_threshold if powerlaw_r2 is not None else False, |
97 | 102 | }, |
98 | 103 | } |
99 | 104 |
|
|
0 commit comments