-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ce724c0
commit b494116
Showing
27 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
38 changes: 38 additions & 0 deletions
38
.../baseline/graph_algorithms_baselines/centrality/degree_centrality/CompleteUnweighted.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
[ | ||
{ | ||
"@@top_scores_heap": [ | ||
{ | ||
"Vertex_ID": "A", | ||
"score": 1.2857142857142856 | ||
}, | ||
{ | ||
"Vertex_ID": "B", | ||
"score": 1.2857142857142856 | ||
}, | ||
{ | ||
"Vertex_ID": "C", | ||
"score": 1.2857142857142856 | ||
}, | ||
{ | ||
"Vertex_ID": "D", | ||
"score": 1.2857142857142856 | ||
}, | ||
{ | ||
"Vertex_ID": "E", | ||
"score": 1.2857142857142856 | ||
}, | ||
{ | ||
"Vertex_ID": "F", | ||
"score": 1.2857142857142856 | ||
}, | ||
{ | ||
"Vertex_ID": "G", | ||
"score": 1.2857142857142856 | ||
}, | ||
{ | ||
"Vertex_ID": "H", | ||
"score": 1.2857142857142856 | ||
} | ||
] | ||
} | ||
] |
38 changes: 38 additions & 0 deletions
38
...ta/baseline/graph_algorithms_baselines/centrality/degree_centrality/CompleteWeighted.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
[ | ||
{ | ||
"@@top_scores_heap": [ | ||
{ | ||
"Vertex_ID": "A", | ||
"score": 1.2857142857142856 | ||
}, | ||
{ | ||
"Vertex_ID": "B", | ||
"score": 1.2857142857142856 | ||
}, | ||
{ | ||
"Vertex_ID": "C", | ||
"score": 1.2857142857142856 | ||
}, | ||
{ | ||
"Vertex_ID": "D", | ||
"score": 1.2857142857142856 | ||
}, | ||
{ | ||
"Vertex_ID": "E", | ||
"score": 1.2857142857142856 | ||
}, | ||
{ | ||
"Vertex_ID": "F", | ||
"score": 1.2857142857142856 | ||
}, | ||
{ | ||
"Vertex_ID": "G", | ||
"score": 1.2857142857142856 | ||
}, | ||
{ | ||
"Vertex_ID": "H", | ||
"score": 1.2857142857142856 | ||
} | ||
] | ||
} | ||
] |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import csv | ||
import json | ||
|
||
import networkx as nx | ||
import numpy as np | ||
|
||
baseline_path_root = "baseline/graph_algorithms_baselines" | ||
|
||
|
||
def run_degree_baseline(g: nx.Graph): | ||
res = nx.centrality.degree_centrality(g) | ||
nx.centrality.degree_centrality | ||
|
||
out = [] | ||
for k, v in res.items(): | ||
out.append({"Vertex_ID": k, "score": v}) | ||
|
||
out = [{"@@top_scores_heap": out}] | ||
return out | ||
|
||
|
||
def create_graph(path, edges, weights): | ||
g = nx.Graph() | ||
# include edge weights if they exist | ||
if weights is not None: | ||
g.add_weighted_edges_from(edges) | ||
else: | ||
g.add_edges_from(edges) | ||
return g | ||
|
||
|
||
def create_degree_baseline(): | ||
# input, output | ||
paths = [ | ||
( | ||
"unweighted_edges/complete_edges.csv", | ||
f"{baseline_path_root}/centrality/degree_centrality/CompleteUnweighted.json", | ||
False, | ||
), | ||
( | ||
"weighted_edges/complete_edges.csv", | ||
f"{baseline_path_root}/centrality/degree_centrality/CompleteWeighted.json", | ||
True, | ||
), | ||
] | ||
|
||
for p, o_path, w in paths: | ||
with open(p) as f: | ||
edges = np.array(list(csv.reader(f))) | ||
|
||
g = create_graph(p, edges, w) | ||
|
||
res = run_degree_baseline(g) | ||
with open(o_path, "w") as f: | ||
json.dump(res, f, indent=2) | ||
|
||
|
||
if __name__ == "__main__": | ||
create_degree_baseline() |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters