From fee7f513fe699b509475b5fa0c0f802d26d117f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edyta=20Fr=C4=85szczak?= Date: Fri, 5 Jul 2024 10:59:53 +0200 Subject: [PATCH] jupyter and some documentation updates --- README.md | 36 ++++++++++++++++++++++++++++++++++++ src/aa.py | 29 ----------------------------- 2 files changed, 36 insertions(+), 29 deletions(-) delete mode 100644 src/aa.py diff --git a/README.md b/README.md index 67498f8..8bad272 100644 --- a/README.md +++ b/README.md @@ -219,6 +219,42 @@ result, evaluation = source_detector.detect_sources_and_evaluate(G=G, print(evaluation) +``` + +For performing ensemble source detection, use 'EnsembleSourceDetector' class and configure it with 'EnsembleSourceDetectionConfig' object. This approach allows for seamless source detection and result evaluation. + +```python + +import networkx as nx + +from nsdlib.common.models import SourceDetectionConfig, \ + EnsembleSourceDetectionConfig +from nsdlib.source_detection import SourceDetector, EnsembleSourceDetector +from nsdlib.taxonomies import NodeEvaluationAlgorithm, EnsembleVotingType + +G = nx.karate_club_graph() + +config_netsleuth = SourceDetectionConfig( + node_evaluation_algorithm=NodeEvaluationAlgorithm.NETSLEUTH, +) + +config_degree = SourceDetectionConfig( + node_evaluation_algorithm=NodeEvaluationAlgorithm.CENTRALITY_DEGREE, +) + +ensemble_config = EnsembleSourceDetectionConfig( + detection_configs=[config_netsleuth, config_degree], + voting_type=EnsembleVotingType.HARD, + classifier_weights=[0.5, 0.5], +) + +source_detector = EnsembleSourceDetector(ensemble_config) + +result, evaluation = source_detector.detect_sources_and_evaluate(G=G, + IG=G, real_sources=[0,33]) +print(evaluation) + + ``` - by importing and using specific method, each method has appropriate prefix to understand what is the purpose of it: diff --git a/src/aa.py b/src/aa.py deleted file mode 100644 index a7e462b..0000000 --- a/src/aa.py +++ /dev/null @@ -1,29 +0,0 @@ -import networkx as nx - -import nsdlib as nsd -from nsdlib import NodeEvaluationAlgorithm, PropagationReconstructionAlgorithm - -G = nx.karate_club_graph() -IG = G.copy() -IG.remove_nodes_from([10, 15, 20, 33]) -real_sources = [0, 8] - -EIG = nsd.reconstruct_propagation(G, IG, PropagationReconstructionAlgorithm.SBRP) - -outbreaks = nsd.identify_outbreaks(EIG, nsd.OutbreaksDetectionAlgorithm.LEIDEN) -outbreaks_G = nsd.create_subgraphs_based_on_outbreaks(EIG, outbreaks) -detected_sources = [] -for outbreak in outbreaks_G: - nodes_evaluation = nsd.evaluate_nodes( - outbreak, NodeEvaluationAlgorithm.CENTRALITY_AVERAGE_DISTANCE - ) - outbreak_detected_source = max(nodes_evaluation, key=nodes_evaluation.get) - print(f"Outbreak: {outbreak}, Detected Source: {outbreak_detected_source}") - detected_sources.append(outbreak_detected_source) - -evaluation = nsd.compute_source_detection_evaluation( - G=EIG, - real_sources=real_sources, - detected_sources=detected_sources, -) -print(evaluation)