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

WIP: Updating timing scripts and heatmaps #61

Closed
Closed
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
Binary file modified timing/heatmap_all_pairs_bellman_ford_path_length_timing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified timing/heatmap_all_pairs_bellman_ford_path_timing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified timing/heatmap_betweenness_centrality_timing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
77 changes: 31 additions & 46 deletions timing/timing_individual_function.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import time
import timeit
import random
import types

import networkx as nx
import pandas as pd
Expand All @@ -7,24 +9,29 @@

import nx_parallel as nxp


def execFunc(func, *args, **kwargs):
c = func(*args, **kwargs)
if isinstance(c, types.GeneratorType):
d = dict(c)
return d


# Code to create README heatmaps for individual function currFun
heatmapDF = pd.DataFrame()
# for bipartite graphs
# n = [50, 100, 200, 400]
# m = [25, 50, 100, 200]
number_of_nodes_list = [200, 400, 800, 1600]
nodes = [75, 150, 300, 600]
weighted = False
pList = [1, 0.8, 0.6, 0.4, 0.2]
currFun = nx.tournament.is_reachable
"""
currFun = nx.all_pairs_bellman_ford_path_length
for p in pList:
for num in range(len(number_of_nodes_list)):
for num in nodes:
# create original and parallel graphs
G = nx.fast_gnp_random_graph(
number_of_nodes_list[num], p, seed=42, directed=True
)

G = nx.fast_gnp_random_graph(num, p, seed=42, directed=True)

"""
# for bipartite.node_redundancy
G = nx.bipartite.random_graph(n[num], m[num], p, seed=42, directed=True)
for i in G.nodes:
Expand All @@ -35,6 +42,7 @@
G.add_edge(i, random.choice([node for node in G.nodes if node != i]))
elif len(l) == 1:
G.add_edge(i, random.choice([node for node in G.nodes if node != i and node not in list(G.neighbors(i))]))
"""

# for weighted graphs
if weighted:
Expand All @@ -45,55 +53,32 @@
H = nxp.ParallelGraph(G)

# time both versions and update heatmapDF
t1 = time.time()
c1 = currFun(H)
if isinstance(c1, types.GeneratorType):
d = dict(c1)
t2 = time.time()
parallelTime = t2 - t1
t1 = time.time()
c2 = currFun(G)
if isinstance(c2, types.GeneratorType):
d = dict(c2)
t2 = time.time()
stdTime = t2 - t1
parallelTime = timeit.timeit(lambda: execFunc(currFun, H), number=1)
stdTime = timeit.timeit(lambda: execFunc(currFun, G), number=1)
timesFaster = stdTime / parallelTime
heatmapDF.at[number_of_nodes_list[num], p] = timesFaster
heatmapDF.at[num, p] = timesFaster
print("Finished " + str(currFun))
"""

# Code to create for row of heatmap specifically for tournaments
for num in number_of_nodes_list:
print(num)
G = nx.tournament.random_tournament(num, seed=42)
H = nxp.ParallelGraph(G)
t1 = time.time()
c = currFun(H, 1, num)
t2 = time.time()
parallelTime = t2 - t1
print(parallelTime)
t1 = time.time()
c = currFun(G, 1, num)
t2 = time.time()
stdTime = t2 - t1
print(stdTime)
timesFaster = stdTime / parallelTime
heatmapDF.at[num, 3] = timesFaster
print("Finished " + str(currFun))
# for p in pList:
# for num in nodes:
# G = nx.tournament.random_tournament(num)
# H = nx_parallel.ParallelDiGraph(G)
# parallelTime = timeit.timeit(lambda: nx.tournament.is_reachable(H, 1, num), number=1)
# stdTime = timeit.timeit(lambda: nx.tournament.is_reachable(G, 1, num), number=1)
# timesFaster = stdTime / parallelTime
# timesFaster = stdTime/parallelTime
# heatmapDF.at[num, 3] = timesFaster

# plotting the heatmap with numbers and a green color scheme
plt.figure(figsize=(20, 4))
hm = sns.heatmap(data=heatmapDF.T, annot=True, cmap="Greens", cbar=True)

# Remove the tick labels on both axes
hm.set_yticklabels(
[
3,
]
)
hm.set_yticklabels(pList)

# Adding x-axis labels
hm.set_xticklabels(number_of_nodes_list)
hm.set_xticklabels(nodes)

# Rotating the x-axis labels for better readability (optional)
plt.xticks(rotation=45)
Expand Down
Loading