Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pyrca/analyzers/epsilon_diagnosis.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2023 salesforce.com, inc.
# Copyright (c) 2026 salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause#
Expand Down Expand Up @@ -87,7 +87,7 @@ def find_root_causes(self, abnormal_df: pd.DataFrame, **kwargs):
self.correlations[colname] = np.square(
np.cov(self.normal_df[colname].values, abnormal_df[colname].values)[0, 1]
) / (np.var(self.normal_df[colname].values) * np.var(abnormal_df[colname].values))
if self.correlations[colname] > self.statistics[colname]:
if self.correlations[colname] < self.statistics[colname]:
root_cause_nodes.append((colname, self.correlations[colname]))
root_cause_nodes = sorted(root_cause_nodes, key=lambda r: r[1], reverse=True)[: self.config.root_cause_top_k]
root_cause_nodes = sorted(root_cause_nodes, key=lambda r: r[1], reverse=False)[: self.config.root_cause_top_k]
return RCAResults(root_cause_nodes=root_cause_nodes)
8 changes: 6 additions & 2 deletions tests/analyzers/test_epsilon_diagnosis.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2023 salesforce.com, inc.
# Copyright (c) 2026 salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause#
Expand Down Expand Up @@ -31,10 +31,14 @@ def setUp(self) -> None:
self.abnormal_data = pd.DataFrame(self.abnormal_data, columns=columns)

def test(self):
np.random.seed(42)
model = EpsilonDiagnosis(config=EpsilonDiagnosisConfig(alpha=0.01))
model.train(self.normal_data)
results = model.find_root_causes(self.abnormal_data).to_list()
print(results)
# Columns with low correlation (a, b, d, e) should be identified as root causes
# Column c has high correlation (0.9) so should NOT be a root cause
root_causes = [r["root_cause"] for r in results]
self.assertNotIn("c", root_causes, "High correlation column 'c' should not be a root cause")


if __name__ == "__main__":
Expand Down