Skip to content

Commit

Permalink
update: interaction and actions compute method!
Browse files Browse the repository at this point in the history
  • Loading branch information
amindadgar committed Mar 5, 2024
1 parent 3a916a7 commit 0c13206
Showing 1 changed file with 17 additions and 22 deletions.
39 changes: 17 additions & 22 deletions tc_core_analyzer_lib/utils/compute_interaction_per_acc.py
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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 # # #
Expand All @@ -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]
Expand Down

0 comments on commit 0c13206

Please sign in to comment.