Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: missing interaction count filter! #21

Merged
merged 2 commits into from
Apr 18, 2024
Merged
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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="[email protected]",
Expand Down
38 changes: 25 additions & 13 deletions tc_core_analyzer_lib/utils/compute_interaction_per_acc.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,33 +96,45 @@ 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]

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],
Expand Down
Loading