Skip to content

Commit

Permalink
Merge pull request #21 from ComplexData-MILA/dtdg
Browse files Browse the repository at this point in the history
Merging recent changes
  • Loading branch information
shenyangHuang authored Jan 15, 2024
2 parents 62380f8 + 17e943d commit 197e1c2
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 7 deletions.
9 changes: 5 additions & 4 deletions examples/data_viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@

#! load the datasets
# dataset = tgx.builtin.uci() #built in datasets
# data_name = "uci"

data_name = "tgbl-wiki" #"tgbl-review"
data_name = "tgbn-token" #"tgbl-wiki" #"tgbl-review"
dataset = tgx.tgb_data(data_name) #tgb datasets


time_scale = "daily" #"hourly"
ctdg = tgx.Graph(dataset)
time_scale = "daily"
dtdg = ctdg.discretize(time_scale=time_scale)


Expand All @@ -40,8 +41,8 @@

#! compute statistics
test_ratio = 0.15
tgx.get_reoccurrence(ctdg, test_ratio=test_ratio)
tgx.get_surprise(ctdg, test_ratio=test_ratio)
tgx.get_reoccurrence(dtdg, test_ratio=test_ratio)
tgx.get_surprise(dtdg, test_ratio=test_ratio)

#* these two much faster on dtdgs
tgx.get_avg_node_activity(dtdg)
Expand Down
34 changes: 34 additions & 0 deletions starting_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import tgx
import argparse
import sys

def get_args():
parser = argparse.ArgumentParser('*** discretizing time steps from datasets ***')
parser.add_argument('-d', '--data', type=str, help='Dataset name', default='tgbl-wiki')
parser.add_argument('-t', '--time', type=str, help='time granularity', default='daily')

try:
args = parser.parse_args()
except:
parser.print_help()
sys.exit(0)
return args, sys.argv

args, _ = get_args()


#! load the datasets from tgb or builtin
# dataset = tgx.builtin.uci()

data_name = args.data #"tgbl-coin" #"tgbl-review" #"tgbl-wiki"
dataset = tgx.tgb_data(data_name)



ctdg = tgx.Graph(dataset)
# ctdg.save2csv("ctdg") #! save the graph to csv files

time_scale = args.time #"minutely" #"monthly" #"weekly" #"daily" #"hourly"
dtdg = ctdg.discretize(time_scale=time_scale)
print ("discretize to ", time_scale)

8 changes: 5 additions & 3 deletions tgx/data/tgb.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
'tgbl-flight' : {'discretize' : True, 'time_scale': 'monthly'},
'tgbn-trade' : {'discretize' : False, 'time_scale': None},
'tgbn-genre' : {'discretize' : True, 'time_scale': 'monthly'},
'tgbn-reddit' : {'discretize' : True, 'time_scale': 'monthly'}
'tgbn-reddit' : {'discretize' : True, 'time_scale': 'monthly'},
'tgbn-token' : {'discretize' : True, 'time_scale': 'weekly'}
}

class tgb_data(object):
Expand Down Expand Up @@ -60,9 +61,10 @@ def tgb(self, dname: str,
from tgb.nodeproppred.dataset import NodePropPredDataset
except:
print("First install TGB package using 'pip install py-tgb'")


#TODO not hard code the dataset name anymore
link_pred = ["tgbl-wiki", "tgbl-review", "tgbl-coin", "tgbl-comment", "tgbl-flight"]
node_pred = ["tgbn-trade", "tgbn-genre", "tgbn-reddit"]
node_pred = ["tgbn-trade", "tgbn-genre", "tgbn-reddit", "tgbn-token"]
if dname in link_pred:
data = LinkPropPredDataset(name=dname, root="datasets", preprocess=True)
elif dname in node_pred:
Expand Down

0 comments on commit 197e1c2

Please sign in to comment.