From d719acf985d3a619c1e0311524689968ca3c0846 Mon Sep 17 00:00:00 2001 From: Mohammad Amin Date: Wed, 17 Apr 2024 17:05:17 +0330 Subject: [PATCH 1/2] fix: missing interaction count filter! --- setup.py | 2 +- .../utils/compute_interaction_per_acc.py | 34 ++++++++++++------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/setup.py b/setup.py index e23d073..f223dda 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setup( name="tc-core-analyzer-lib", - version="1.2.0", + version="1.3.0", author="Mohammad Amin Dadgar, TogetherCrew", maintainer="Mohammad Amin Dadgar", maintainer_email="dadgaramin96@gmail.com", diff --git a/tc_core_analyzer_lib/utils/compute_interaction_per_acc.py b/tc_core_analyzer_lib/utils/compute_interaction_per_acc.py index a86bbdc..791c134 100644 --- a/tc_core_analyzer_lib/utils/compute_interaction_per_acc.py +++ b/tc_core_analyzer_lib/utils/compute_interaction_per_acc.py @@ -96,26 +96,17 @@ def thr_int( # # # THRESHOLDED CONNECTIONS # # # - # make copy of graph for thresholding - thresh_graph = copy.deepcopy(graph) - - # remove edges below threshold from copy - thresh_graph.remove_edges_from( - [ - (n1, n2) - for n1, n2, w in thresh_graph.edges(data="weight") - if w < EDGE_STR_THR - ] - ) - # preparing matrix with no `action` and just interactions # actions were self-intereaction and are on diagonal matrix_interaction = copy.deepcopy(matrix) matrix_interaction[np.diag_indices_from(matrix_interaction)] = 0 graph_interaction = make_graph(matrix_interaction) + # filtering the `at least interaction count` from the graph + graph_interaction_thresh = remove_edges_below_threshold(graph_interaction, EDGE_STR_THR) + # get unweighted node degree value for each node from interaction network - all_degrees_thresh = np.array([val for (_, val) in graph_interaction.degree()]) + all_degrees_thresh = np.array([val for (_, val) in graph_interaction_thresh.degree()]) # compare total unweighted node degree after thresholding to threshold thr_uw_thr_deg = np.where(all_degrees_thresh > UW_THR_DEG_THR)[0] @@ -123,6 +114,23 @@ def thr_int( return (thr_ind, thr_uw_deg, thr_uw_thr_deg, graph) +def remove_edges_below_threshold( + graph: DiGraph, EDGE_STR_THR: int, weight_name: str = "weight" + ) -> DiGraph: + """ + remove the edges that has a weight below the threshold + """ + graph_copy = copy.deepcopy(graph) + graph_copy.remove_edges_from( + [ + (n1, n2) + for n1, n2, w in graph_copy.edges(data=weight_name) + if w < EDGE_STR_THR + ] + ) + return graph_copy + + def get_analysis_vector( int_mat: dict[str, np.ndarray], activites: list[str], From 2da21dafcb53cf3f5f6fb7fe2ae38ae62391645c Mon Sep 17 00:00:00 2001 From: Mohammad Amin Date: Wed, 17 Apr 2024 17:08:55 +0330 Subject: [PATCH 2/2] fix: linter issue! --- .../utils/compute_interaction_per_acc.py | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/tc_core_analyzer_lib/utils/compute_interaction_per_acc.py b/tc_core_analyzer_lib/utils/compute_interaction_per_acc.py index 791c134..b125a69 100644 --- a/tc_core_analyzer_lib/utils/compute_interaction_per_acc.py +++ b/tc_core_analyzer_lib/utils/compute_interaction_per_acc.py @@ -103,10 +103,14 @@ def thr_int( graph_interaction = make_graph(matrix_interaction) # filtering the `at least interaction count` from the graph - graph_interaction_thresh = remove_edges_below_threshold(graph_interaction, EDGE_STR_THR) + graph_interaction_thresh = remove_edges_below_threshold( + graph_interaction, EDGE_STR_THR + ) # get unweighted node degree value for each node from interaction network - all_degrees_thresh = np.array([val for (_, val) in graph_interaction_thresh.degree()]) + all_degrees_thresh = np.array( + [val for (_, val) in graph_interaction_thresh.degree()] + ) # compare total unweighted node degree after thresholding to threshold thr_uw_thr_deg = np.where(all_degrees_thresh > UW_THR_DEG_THR)[0] @@ -115,18 +119,18 @@ def thr_int( def remove_edges_below_threshold( - graph: DiGraph, EDGE_STR_THR: int, weight_name: str = "weight" - ) -> DiGraph: + graph: DiGraph, EDGE_STR_THR: int, weight_name: str = "weight" +) -> DiGraph: """ remove the edges that has a weight below the threshold """ graph_copy = copy.deepcopy(graph) graph_copy.remove_edges_from( - [ - (n1, n2) - for n1, n2, w in graph_copy.edges(data=weight_name) - if w < EDGE_STR_THR - ] + [ + (n1, n2) + for n1, n2, w in graph_copy.edges(data=weight_name) + if w < EDGE_STR_THR + ] ) return graph_copy