Skip to content

Commit

Permalink
gallery and stats update
Browse files Browse the repository at this point in the history
  • Loading branch information
rshirzadkhani committed Nov 9, 2023
1 parent 8cd26cb commit 0b56d0c
Show file tree
Hide file tree
Showing 16 changed files with 140 additions and 132 deletions.
27 changes: 0 additions & 27 deletions docs/gallery/0-degree.md → docs/gallery/0-degree-builtin.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,3 @@

### Contacts
![image](degree/Contacts_ave_degree_per_ts.png){ width="400"}

### tgbl-wiki
![image](degree/tgbl-wiki_ave_degree_per_ts.png){ width="400"}

### tgbl-review
![image](degree/tgbl-review_ave_degree_per_ts.png){ width="400"}

### tgbl-coin
![image](degree/tgbl-coin_ave_degree_per_ts.png){ width="400"}


### tgbl-comment
![image](degree/tgbl-comment_ave_degree_per_ts.png){ width="400"}

### tgbl-flight
![image](degree/tgbl-flight_ave_degree_per_ts.png){ width="400"}

### tgbn-trade
![image](degree/tgbn-trade_ave_degree_per_ts.png){ width="400"}

### tgbn-genre
![image](degree/tgbn-genre_ave_degree_per_ts.png){ width="400"}

### tgbn-reddit
![image](degree/tgbn-reddit_ave_degree_per_ts.png){ width="400"}


31 changes: 31 additions & 0 deletions docs/gallery/0-degree-tgb.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Plot by type

## TEA plots


### tgbl-wiki
![image](degree/tgbl-wiki_ave_degree_per_ts.png){ width="400"}

### tgbl-review
![image](degree/tgbl-review_ave_degree_per_ts.png){ width="400"}

### tgbl-coin
![image](degree/tgbl-coin_ave_degree_per_ts.png){ width="400"}


### tgbl-comment
![image](degree/tgbl-comment_ave_degree_per_ts.png){ width="400"}

### tgbl-flight
![image](degree/tgbl-flight_ave_degree_per_ts.png){ width="400"}

### tgbn-trade
![image](degree/tgbn-trade_ave_degree_per_ts.png){ width="400"}

### tgbn-genre
![image](degree/tgbn-genre_ave_degree_per_ts.png){ width="400"}

### tgbn-reddit
![image](degree/tgbn-reddit_ave_degree_per_ts.png){ width="400"}


Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,3 @@
### Contacts
![image](node_edge/Contacts_node&edge_per_ts.png){ width="400"}

### tgbl-wiki
![image](node_edge/tgbl-wiki_node&edge_per_ts.png){ width="400"}

### tgbl-review
![image](node_edge/tgbl-review_node&edge_per_ts.png){ width="400"}

### tgbl-coin
![image](node_edge/tgbl-coin_node&edge_per_ts.png){ width="400"}


### tgbl-comment
![image](node_edge/tgbl-comment_node&edge_per_ts.png){ width="400"}

### tgbl-flight
![image](node_edge/tgbl-flight_node&edge_per_ts.png){ width="400"}

### tgbn-trade
![image](node_edge/tgbn-trade_node&edge_per_ts.png){ width="400"}

### tgbn-genre
![image](node_edge/tgbn-genre_node&edge_per_ts.png){ width="400"}

### tgbn-reddit
![image](node_edge/tgbn-reddit_node&edge_per_ts.png){ width="400"}


30 changes: 30 additions & 0 deletions docs/gallery/0-node_edge-tgb.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Plot by type

## TEA plots

### tgbl-wiki
![image](node_edge/tgbl-wiki_node&edge_per_ts.png){ width="400"}

### tgbl-review
![image](node_edge/tgbl-review_node&edge_per_ts.png){ width="400"}

### tgbl-coin
![image](node_edge/tgbl-coin_node&edge_per_ts.png){ width="400"}


### tgbl-comment
![image](node_edge/tgbl-comment_node&edge_per_ts.png){ width="400"}

### tgbl-flight
![image](node_edge/tgbl-flight_node&edge_per_ts.png){ width="400"}

### tgbn-trade
![image](node_edge/tgbn-trade_node&edge_per_ts.png){ width="400"}

### tgbn-genre
![image](node_edge/tgbn-genre_node&edge_per_ts.png){ width="400"}

### tgbn-reddit
![image](node_edge/tgbn-reddit_node&edge_per_ts.png){ width="400"}


Binary file modified docs/gallery/0-tet-tgb.md
Binary file not shown.
Binary file added docs/gallery/degree/reddit_ave_degree_per_ts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/gallery/node_edge/reddit_nodes_per_ts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 7 additions & 7 deletions examples/test_package2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
data_path = '/network/scratch/r/razieh.shirzadkhani/'
Plot_path = "./docs/gallery/node_edge"

dataset = tgx.builtin.uci(root = data_path)
dataset = tgx.builtin.reddit(root = data_path)
G = tgx.Graph(dataset)
G.discretize(intervals=2)
G.count_freq()
tgx.TEA(G, filepath = Plot_path, network_name=dataset.name)
tgx.TET(G, filepath = Plot_path, network_name=dataset.name)
tgx.degree_over_time(G, filepath= Plot_path, network_name=dataset.name)
tgx.nodes_over_time(G, filepath= Plot_path, network_name=dataset.name)
new_G = G.discretize(intervals=dataset.intervals)
# new_G.count_freq()
# tgx.TEA(G, filepath = Plot_path, network_name=dataset.name)
# tgx.TET(G, filepath = Plot_path, network_name=dataset.name)
# tgx.degree_over_time(new_G, filepath= Plot_path, network_name=dataset.name)
tgx.nodes_and_edges_over_time(new_G, filepath= Plot_path, network_name=dataset.name)
18 changes: 6 additions & 12 deletions examples/test_paths.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import tgx
from tgx.io.read_files import read_edgelist
from tgx.classes import data_loader
from tgx.io.read import read_edgelist
from tgx.data import builtin

data_path = '/network/scratch/r/razieh.shirzadkhani/'


dataset = data_loader.data.uci(root=data_path)
dataset = builtin.data.uci(root=data_path)
data = read_edgelist(data=dataset, discretize=dataset.discretize, intervals=dataset.intervals)



#! external csv
from tgx.io.read import read_csv
data = read_csv ()
data = read_csv (.....)


#! for built in dataset
Expand All @@ -28,7 +28,7 @@
#! visualization

from tgx.viz.TEA import TEA
from tgx.utils.graph_stat import nodes_and_edges_per_ts
from tgx.utils.stat import nodes_and_edges_per_ts


TEA(data)
Expand All @@ -52,13 +52,7 @@
G = read_csv(fname)
G.discretize(options)

dataset = builtin.uci()
data = read_csv(dataset)
G = tgx.Graph(data)
G.discretize()


TEA(G.disc_G) #create the temp dictionary here by going through the edges
TEA(G) #create the temp dictionary here by going through the edges
TET(G) #check if the temp dict is created, if not, create it
nodes_over_time(G)

Expand Down
8 changes: 6 additions & 2 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ nav:
- TET Plots:
- Builtin: gallery/0-tet-builtin.md
- TGB: gallery/0-tet-tgb.md
- Average degree over time: gallery/0-degree.md
- Node and Edge over time: gallery/0-node_edge.md
- Average degree over time:
- Builtin: gallery/0-degree-builtin.md
- TGB: gallery/0-degree-tgb.md
- Node and Edge over time:
- Builtin: gallery/0-node_edge-builtin.md
- TGB: gallery/0-node_edge-tgb.md
- Plots by dataset:
- Builtin:
- Reddit: gallery/reddit.md
Expand Down
Binary file modified tgx/classes/__pycache__/graph.cpython-39.pyc
Binary file not shown.
50 changes: 38 additions & 12 deletions tgx/classes/graph.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# import networkx as nx
from typing import Optional
from tgx.utils.graph_utils import edgelist_discritizer, frequency_count
from typing import Optional, Union
from tgx.utils.graph_utils import edgelist_discritizer, frequency_count, subsampling
from tgx.io.read import read_csv
import copy

class Graph(object):
def __init__(self,
Expand Down Expand Up @@ -29,43 +30,68 @@ def __init__(self,
self.freq_data = None


def discretize(self, intervals):
# self.discretized = True
def discretize(self, intervals: Union[str, int]) -> object:
new_G = copy.deepcopy(self)
disc_G = edgelist_discritizer(self.data,
time_interval = intervals)
self.continueos_G = self.data
self.data = disc_G
return self.data
new_G.data = disc_G
return new_G

def count_freq(self):
self.freq_data = frequency_count(self.data)
return self

def subsampling(self,
node_list: Optional[list] = [],
random_selection: Optional[bool] = True,
N: Optional[int] = None) -> object:
new_G = copy.deepcopy(self)
new_G.data = subsampling(new_G, node_list = node_list, random_selection=random_selection, N=N)
return new_G

def number_of_edges(self) -> int:
r"""
Calculate total number of nodes present in an edgelist
"""
edgelist = self.data
a = 0
e_num = 0
for _, edges in edgelist.items():
a += len(edges)
e_num += len(edges)

return #len(edges_list.keys())
return e_num

def number_of_nodes(self) -> int:
def total_nodes(self) -> int:
r"""
Calculate total number of nodes present in an edgelist
"""

edgelist = self.data
node_list = {}
for _, edge_data in edgelist.items():
for (u,v), _ in edge_data.items():
for edge in edge_data:
(u, v) = edge
if u not in node_list:
node_list[u] = 1
if v not in node_list:
node_list[v] = 1
return len(node_list.keys())

def node_per_ts(self):
active_nodes = {}
for ts in range(len(self.data)):
edgelist_t = self.data[ts]
active_nodes.append(self._count_node(edgelist_t))
return active_nodes

def edgelist_node_count(self, edge_data: list):
node_list = {}
for edge in edge_data:
(u, v) = edge
if u not in node_list:
node_list[u] = 1
if v not in node_list:
node_list[v] = 1
return len(node_list.keys())

def nodes_list(self) -> list:
r"""
Expand Down
Binary file modified tgx/utils/__pycache__/graph_utils.cpython-39.pyc
Binary file not shown.
28 changes: 1 addition & 27 deletions tgx/utils/graph_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,36 +52,16 @@ def edgelist_discritizer(edgelist,
print(f'Discretizing data to {num_intervals} timestamps...')
if num_intervals == 0:
print("Warning! Only one timestamp exist in the data.")

updated_edgelist = {}
new_ts = {}
curr_t = 0
for ts, edges_list in edgelist.items():
bin_ts = int(ts / interval_size)
if bin_ts >= num_intervals:
bin_ts -= 1

# if bin_ts not in new_ts:
# new_ts[bin_ts] = curr_t
# curr_t += 1

for edge in edges_list:
# if new_ts[bin_ts] not in updated_edgelist:
# updated_edgelist[new_ts[bin_ts]] = {}

# for (u,v) in edge_data.items():
# if (u, v) not in freq_count_dict[new_ts[bin_ts]]:
# freq_count_dict[new_ts[bin_ts]][(u, v)] = n
# else:
# freq_count_dict[new_ts[bin_ts]][(u, v)] += n
if bin_ts not in updated_edgelist:
updated_edgelist[bin_ts] = []
# updated_edgelist[curr_t] = edges_list
# edges_list = []
# curr_t = bin_ts
updated_edgelist[bin_ts].append(edge)

# updated_edgelist[curr_t] = edges_list
print("Discretization Done..!")
return updated_edgelist

Expand All @@ -108,26 +88,20 @@ def subsampling(graph: Union[object, dict],
nodes = node_list(graph)
else:
edgelist = graph.edgelist
nodes = graph.nodes()
# print(nodes[10])

nodes = graph.nodes()

if random_selection:
node_list = list(np.random.choice(nodes, size = N, replace = False))
# print(node_list)

new_edgelist = {}
for t, edge_data in edgelist.items():
# print("t",t)
for (u,v), f in edge_data.items():
# print(u)
if u in node_list or v in node_list:
if t not in new_edgelist:
new_edgelist[t] = {}
new_edgelist[t][(u, v)] = f
else:
new_edgelist[t][(u, v)] = f
# print(new_edgelist)
return new_edgelist

def frequency_count(edgelist: dict):
Expand Down
Loading

0 comments on commit 0b56d0c

Please sign in to comment.