Skip to content

Commit

Permalink
Optimize Remove Isolated Node Process
Browse files Browse the repository at this point in the history
  • Loading branch information
devbruce committed Mar 7, 2019
1 parent b8f1cea commit 5791832
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
6 changes: 6 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,9 @@
- Change urls

- Stabilization & Optimization

<br>

## v1.32

- Stabilization & Optimization
11 changes: 7 additions & 4 deletions app/viz/core/sna.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,18 @@ def gen_gexf_and_pass_partition_data(
)
sub_graph = sub_data.get('sub_graph')
tf_sum_dict_sorted = sub_data.get('tf_sum_dict_sorted')
isolated_nodes = sub_data.get('isolated_nodes')

# ------ Set Attributes for gexf file ------ #
# Add Node Weight
scaled_weight_list = []
for s in tf_sum_dict_sorted[:node_num]:
if s[1] == -1: continue # If Node Weight == -1 (It means that this node is a isolated node), then do nothing
for node_freq in tf_sum_dict_sorted[:node_num]:
# node_freq[0] is node, node_freq[1] is node's frequency
if node_freq[0] in isolated_nodes:
continue
else:
scaled_weight = (s[1] * (70 ** 2) / tf_sum_dict_sorted[0][1])**(1/2)
scaled_weight_list.append((s[0], scaled_weight))
scaled_weight = (node_freq[1] * (70 ** 2) / tf_sum_dict_sorted[0][1])**(1/2)
scaled_weight_list.append((node_freq[0], scaled_weight))

scaled_weight_dict = dict(scaled_weight_list)

Expand Down
21 changes: 5 additions & 16 deletions app/viz/core/sna_sub.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,11 @@ def get_sub_data(graph, node_num, edge_remove_threshold, remove_isolated_node, m

# Get Top Frequency Nodes to make sub_graph
tf_sum_dict_sorted = sorted(tf_sum_dict.items(), key=lambda x: x[1], reverse=True)
sub_nodes = [node_freq[0] for node_freq in tf_sum_dict_sorted[:node_num]]

# -- Process : Remove Isolated Node -- #
isolated_nodes = list()
if remove_isolated_node:
# Make Remove Isolated Nodes List
isolated_nodes = list()
sub_nodes = [i[0] for i in tf_sum_dict_sorted[:node_num]]
for node in sub_nodes:
have_edge = False
for related_node in graph[node]: # graph[node] returns {'to_node': {'weight: n }, . . . }
Expand All @@ -141,23 +140,12 @@ def get_sub_data(graph, node_num, edge_remove_threshold, remove_isolated_node, m
if not have_edge:
isolated_nodes.append(node)

# Make temp_dict for setting isolated node weight -1
temp_dict = OrderedDict(tf_sum_dict_sorted)

# Set Isolated nodes' weight -1
# Remove isolated node from sub node list
for node in isolated_nodes:
temp_dict[node] = -1
tf_sum_dict_sorted = list(temp_dict.items())
sub_nodes.remove(node)
# ------------------------------------- #

# Make Sub Graph
sub_nodes = list()
for node_data in tf_sum_dict_sorted[:node_num]: # Set the Number of Nodes
if node_data[1] == -1: # If Node Weight == -1 (It means that this node is a isolated node)
continue
else:
sub_nodes.append(node_data[0])

sub_graph = graph.subgraph(sub_nodes)

# Exception Handling : If No Edges or No Nodes
Expand All @@ -168,6 +156,7 @@ def get_sub_data(graph, node_num, edge_remove_threshold, remove_isolated_node, m
'sub_graph': sub_graph,
'tf_sum_dict': tf_sum_dict,
'tf_sum_dict_sorted': tf_sum_dict_sorted,
'isolated_nodes': isolated_nodes,
}
return result

Expand Down

0 comments on commit 5791832

Please sign in to comment.