From 0c13206aa292c5286cb28d1cd3271028de27f469 Mon Sep 17 00:00:00 2001 From: Mohammad Amin Date: Tue, 5 Mar 2024 18:32:38 +0330 Subject: [PATCH] update: interaction and actions compute method! --- .../utils/compute_interaction_per_acc.py | 39 ++++++++----------- 1 file changed, 17 insertions(+), 22 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 2c72c52..15b1aca 100644 --- a/tc_core_analyzer_lib/utils/compute_interaction_per_acc.py +++ b/tc_core_analyzer_lib/utils/compute_interaction_per_acc.py @@ -1,9 +1,10 @@ +import copy + import numpy as np import numpy.typing as npt from networkx import DiGraph from .generate_graph import make_graph -from .activity import DiscordActivity def thr_int( @@ -58,18 +59,8 @@ def thr_int( graph : networkx.DiGraph the network graph of active members """ - - ignore_axis_0_activities: list[str] - ignore_axis_1_activities: list[str] - - if "ignore_axis_0_activities" not in kwargs: - ignore_axis_0_activities = [] - else: - ignore_axis_0_activities = kwargs["ignore_axis_0_activities"] - if "ignore_axis_1_activities" not in kwargs: - ignore_axis_1_activities = [] - else: - ignore_axis_1_activities = kwargs["ignore_axis_1_activities"] + ignore_axis_0_activities: list[str] = kwargs.get("ignore_axis_0_activities", []) + ignore_axis_1_activities: list[str] = kwargs.get("ignore_axis_1_activities", []) # int_analysis is for all actions and interactions int_analysis = get_analysis_vector( @@ -83,16 +74,11 @@ def thr_int( # all the activities has the same interaction matrix # with the same shape matrix = np.zeros_like(int_mat[activities[0]]) - interaction_matrix = np.zeros_like(int_mat[activities[0]]) for activity in activities: - if activity in [DiscordActivity.Reaction, DiscordActivity.Mention, DiscordActivity.Reaction]: - interaction_matrix += int_mat[activity] - # matrix for action and interactions matrix += int_mat[activity] - interaction_graph = make_graph(interaction_matrix) graph = make_graph(matrix) # # # TOTAL INTERACTIONS # # # @@ -110,17 +96,26 @@ def thr_int( # # # THRESHOLDED CONNECTIONS # # # + # make copy of graph for thresholding + thresh_graph = copy.deepcopy(graph) + # remove edges below threshold from copy - interaction_graph.remove_edges_from( + thresh_graph.remove_edges_from( [ (n1, n2) - for n1, n2, w in interaction_graph.edges(data="weight") + for n1, n2, w in thresh_graph.edges(data="weight") if w < EDGE_STR_THR ] ) - # get unweighted node degree value for each node from thresholded network - all_degrees_thresh = np.array([val for (_, val) in interaction_graph.degree()]) + # 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) + + # get unweighted node degree value for each node from interaction network + all_degrees_thresh = np.array([val for (_, val) in graph_interaction.degree()]) # compare total unweighted node degree after thresholding to threshold thr_uw_thr_deg = np.where(all_degrees_thresh > UW_THR_DEG_THR)[0]