Skip to content

Commit

Permalink
fixing error in edge weight frequency counting for discretize_edges
Browse files Browse the repository at this point in the history
  • Loading branch information
shenyangHuang committed Mar 28, 2024
1 parent b57254b commit f195458
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion py_tgx.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ TGX implementation works with `python >= 3.9` and can be installed as follows.

6. [optional] Install `mkdocs` dependencies to serve the documentation locally.
```
pip install mkdocs-glightbox
pip install mkdocs mkdocs-material mkdocstrings-python mkdocs-glightbox mkdocs-jupyter ipython_genutils
```


Expand Down
10 changes: 6 additions & 4 deletions tgx/utils/graph_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def discretize_edges(edgelist: dict,
"""
unique_ts = list(edgelist.keys())
total_time = unique_ts[-1] - unique_ts[0]

if time_scale is not None:
if isinstance(time_scale, int):
interval_size = total_time // time_scale #integer timestamp of the bin, discounting any bin that has a smaller duration than others
Expand Down Expand Up @@ -73,25 +74,26 @@ def discretize_edges(edgelist: dict,
if (store_unix):
unix_dict = []
start_time = int(unique_ts[0])

for ts, edges_list in edgelist.items():
bin_ts = ceiling_division(ts, interval_size) #will correctly put edges into the last bin

for edge in edges_list:
if bin_ts not in updated_edgelist:
updated_edgelist[bin_ts] = {edge: 1}
#updated_edgelist[bin_ts] = [edge]
else:
if (not freq_weight):
updated_edgelist[bin_ts][edge] = 1
else:
if (edge in updated_edgelist[bin_ts]):
updated_edgelist[bin_ts] += 1
updated_edgelist[bin_ts][edge] += 1
else:
updated_edgelist[bin_ts][edge] = 1
#updated_edgelist[bin_ts].append(edge)

if (store_unix):
unix_ts = start_time + int(ts // interval_size) * interval_size #round to the nearest start time
#! should use bin_ts here
unix_ts = start_time + bin_ts * interval_size
# unix_ts = start_time + int(ts // interval_size) * interval_size #round to the nearest start time
unix_ts = int(unix_ts)
unix_dict.extend([unix_ts] * len(edges_list))

Expand Down

0 comments on commit f195458

Please sign in to comment.