diff --git a/docs/api_references.md b/docs/api_references.md deleted file mode 100644 index 25b6bac..0000000 --- a/docs/api_references.md +++ /dev/null @@ -1,10 +0,0 @@ -# TGX - -::: tgx.classes.graph -::: tgx.classes.data_loader -::: tgx.io.read_files -::: tgx.utils.graph_stat -::: tgx.utils.graph_utils -::: tgx.utils.plotting_utils -::: tgx.viz.TEA -::: tgx.viz.TET \ No newline at end of file diff --git a/docs/gallery/degree.md b/docs/gallery/0-degree.md similarity index 91% rename from docs/gallery/degree.md rename to docs/gallery/0-degree.md index 2eb3315..d18e9d7 100644 --- a/docs/gallery/degree.md +++ b/docs/gallery/0-degree.md @@ -13,14 +13,14 @@ ![image](degree/lastfm_ave_degree_per_ts.png){ width="400"} ### Enron -![image](degree/enron_node&edge_per_ts.png){ width="400"} +![image](degree/enron_ave_degree_per_ts.png){ width="400"} ### Social Evo ![image](degree/SocialEvo_ave_degree_per_ts.png){ width="400"} ### UCI - ![UCI](degree/CanParluci_ave_degree_per_ts.png){ width="400"} + ![UCI](degree/uci_ave_degree_per_ts.png){ width="400"} ### Flights ![image](degree/Flights_ave_degree_per_ts.png){ width="400"} diff --git a/docs/gallery/node_edge.md b/docs/gallery/0-node_edge.md similarity index 95% rename from docs/gallery/node_edge.md rename to docs/gallery/0-node_edge.md index d05e806..6a64f72 100644 --- a/docs/gallery/node_edge.md +++ b/docs/gallery/0-node_edge.md @@ -20,7 +20,7 @@ ### UCI - ![UCI](node_edge/CanParluci_node&edge_per_ts.png){ width="400"} + ![UCI](node_edge/uci_node&edge_per_ts.png){ width="400"} ### Flights ![image](node_edge/Flights_node&edge_per_ts.png){ width="400"} diff --git a/docs/gallery/tea.md b/docs/gallery/0-tea-builtin.md similarity index 56% rename from docs/gallery/tea.md rename to docs/gallery/0-tea-builtin.md index f8e17a7..9d68897 100644 --- a/docs/gallery/tea.md +++ b/docs/gallery/0-tea-builtin.md @@ -37,29 +37,6 @@ ### Contacts ![image](TEA/Contacts.png){ width="400"} -### tgbl-wiki -![image](TEA/tgbl-wiki.png){ width="400"} -### tgbl-review -![image](TEA/tgbl-review.png){ width="400"} - -### tgbl-coin -![image](TEA/tgbl-coin.png){ width="400"} - - -### tgbl-comment -![image](TEA/tgbl-comment.png){ width="400"} - -### tgbl-flight -![image](TEA/tgbl-flight.png){ width="400"} - -### tgbn-trade -![image](TEA/tgbn-trade.png){ width="400"} - -### tgbn-genre -![image](TEA/tgbn-genre.png){ width="400"} - -### tgbn-reddit -![image](TEA/tgbn-reddit.png){ width="400"} diff --git a/docs/gallery/0-tea-tgb.md b/docs/gallery/0-tea-tgb.md new file mode 100644 index 0000000..9655c12 --- /dev/null +++ b/docs/gallery/0-tea-tgb.md @@ -0,0 +1,30 @@ +# Plot by type + + + +### tgbl-wiki +![image](TEA/tgbl-wiki.png){ width="400"} + +### tgbl-review +![image](TEA/tgbl-review.png){ width="400"} + +### tgbl-coin +![image](TEA/tgbl-coin.png){ width="400"} + + +### tgbl-comment +![image](TEA/tgbl-comment.png){ width="400"} + +### tgbl-flight +![image](TEA/tgbl-flight.png){ width="400"} + +### tgbn-trade +![image](TEA/tgbn-trade.png){ width="400"} + +### tgbn-genre +![image](TEA/tgbn-genre.png){ width="400"} + +### tgbn-reddit +![image](TEA/tgbn-reddit.png){ width="400"} + + diff --git a/docs/gallery/tet.md b/docs/gallery/0-tet-builtin.md similarity index 55% rename from docs/gallery/tet.md rename to docs/gallery/0-tet-builtin.md index b4576b0..86b5bbf 100644 --- a/docs/gallery/tet.md +++ b/docs/gallery/0-tet-builtin.md @@ -34,26 +34,3 @@ ![image](TET/Contacts.png){ width="400"} -### tgbl-wiki -![image](TET/tgbl-wiki.png){ width="400"} - -### tgbl-review -![image](TET/tgbl-review.png){ width="400"} - -### tgbl-coin -![image](TET/tgbl-coin.png){ width="400"} - -### tgbl-comment -![image](TET/tgbl-comment.png){ width="400"} - -### tgbl-flight -![image](TET/tgbl-flight.png){ width="400"} - -### tgbn-trade -![image](TET/tgbn-trade.png){ width="400"} - -### tgbn-genre -![image](TET/tgbn-genre.png){ width="400"} - -### tgbn-reddit -![image](TET/tgbn-reddit.png){ width="400"} diff --git a/docs/gallery/0-tet-tgb.md b/docs/gallery/0-tet-tgb.md new file mode 100644 index 0000000..ffb90ed --- /dev/null +++ b/docs/gallery/0-tet-tgb.md @@ -0,0 +1,27 @@ +## TET Plots + + + +### tgbl-wiki +![image](TET/tgbl-wiki.png){ width="400"} + +### tgbl-review +![image](TET/tgbl-review.png){ width="400"} + +### tgbl-coin +![image](TET/tgbl-coin.png){ width="400"} + +### tgbl-comment +![image](TET/tgbl-comment.png){ width="400"} + +### tgbl-flight +![image](TET/tgbl-flight.png){ width="400"} + +### tgbn-trade +![image](TET/tgbn-trade.png){ width="400"} + +### tgbn-genre +![image](TET/tgbn-genre.png){ width="400"} + +### tgbn-reddit +![image](TET/tgbn-reddit.png){ width="400"} diff --git a/docs/gallery/canparl.md b/docs/gallery/canparl.md new file mode 100644 index 0000000..73a8434 --- /dev/null +++ b/docs/gallery/canparl.md @@ -0,0 +1,10 @@ + +## Can. Parl. +#### TEA Plot +![Canadian Parliment](TEA/CanParl.png){ width="400"} +#### TET Plot +![Canadian Parliment](TET/CanParl.png){ width="400"} +#### Average degree over time +![Canadian Parliment](degree/CanParl_ave_degree_per_ts.png){ width="400"} +#### Node and Edge over time +![Canadian Parliment](node_edge/CanParl_node&edge_per_ts.png){ width="400"} \ No newline at end of file diff --git a/docs/gallery/contact.md b/docs/gallery/contact.md new file mode 100644 index 0000000..a259192 --- /dev/null +++ b/docs/gallery/contact.md @@ -0,0 +1,13 @@ +## Contacts +#### TEA Plot +![image](TEA/Contacts.png){ width="400"} +#### TET Plot +![image](TET/Contacts.png){ width="400"} + + +#### Average degree over time +![image](degree/Contacts_ave_degree_per_ts.png){ width="400"} + + +#### Node and Edge over time +![image](node_edge/Contacts_node&edge_per_ts.png){ width="400"} diff --git a/docs/gallery/enron.md b/docs/gallery/enron.md new file mode 100644 index 0000000..c1479c1 --- /dev/null +++ b/docs/gallery/enron.md @@ -0,0 +1,12 @@ +## Enron +#### TEA Plot +![image](TEA/Enron.png){ width="400"} +### TET Plot +![image](TET/Enron.png){ width="400"} + +#### Average degree over time +![image](degree/enron_ave_degree_per_ts.png){ width="400"} + + +#### Node and Edge over time +![image](node_edge/enron_node&edge_per_ts.png){ width="400"} diff --git a/docs/gallery/flight.md b/docs/gallery/flight.md new file mode 100644 index 0000000..48ec78d --- /dev/null +++ b/docs/gallery/flight.md @@ -0,0 +1,13 @@ +## Flights +#### TEA Plot +![image](TEA/Flights.png){ width="400"} +#### TET Plot +![image](TET/Flights.png){ width="400"} + +#### Average degree over time +![image](degree/Flights_ave_degree_per_ts.png){ width="400"} + + + +#### Node and Edge over time +![image](node_edge/Flights_node&edge_per_ts.png){ width="400"} diff --git a/docs/gallery/lastfm.md b/docs/gallery/lastfm.md new file mode 100644 index 0000000..4daf106 --- /dev/null +++ b/docs/gallery/lastfm.md @@ -0,0 +1,12 @@ + +## LastFM +#### TEA Plot +![image](TEA/LastFM.png){ width="400"} +#### TET Plot +![image](TEA/LastFM.png){ width="400"} +#### Average degree over time +![image](degree/lastfm_ave_degree_per_ts.png){ width="400"} + + +#### Node and Edge over time +![image](node_edge/lastfm_node&edge_per_ts.png){ width="400"} diff --git a/docs/gallery/mooc.md b/docs/gallery/mooc.md new file mode 100644 index 0000000..1bfe222 --- /dev/null +++ b/docs/gallery/mooc.md @@ -0,0 +1,12 @@ + +## MOOC +#### TEA Plot +![image](TEA/MOOC.png){ width="400"} +#### TET Plot +![image](TET/MOOC.png){ width="400"} + +#### Average degree over time +![image](degree/mooc_ave_degree_per_ts.png){ width="400"} + +#### Node and Edge over time +![image](node_edge/mooc_node&edge_per_ts.png){ width="400"} \ No newline at end of file diff --git a/docs/gallery/reddit.md b/docs/gallery/reddit.md new file mode 100644 index 0000000..6e04c2b --- /dev/null +++ b/docs/gallery/reddit.md @@ -0,0 +1,13 @@ +## Reddit +#### TEA Plot +![image](TEA/Reddit.png){ width="400"} + + +#### TET Plot +![image](TET/Reddit.png){ width="400"} + +#### Average degree over time +![image](degree/reddit_ave_degree_per_ts.png){ width="400"} + +#### Node and Edge over time +![image](node_edge/reddit_node&edge_per_ts.png){ width="400"} \ No newline at end of file diff --git a/docs/gallery/socialevo.md b/docs/gallery/socialevo.md new file mode 100644 index 0000000..8f7ba6d --- /dev/null +++ b/docs/gallery/socialevo.md @@ -0,0 +1,12 @@ +## Social Evo +#### TEA Plot +![image](TEA/SocialEvo.png){ width="400"} +#### TET Plot +![image](TET/SocialEvo.png){ width="400"} + +#### Average degree over time + ![image](degree/SocialEvo_ave_degree_per_ts.png){ width="400"} + + +#### Node and Edge over time + ![image](node_edge/SocialEvo_node&edge_per_ts.png){ width="400"} diff --git a/docs/gallery/tgbl-coin.md b/docs/gallery/tgbl-coin.md new file mode 100644 index 0000000..44b612f --- /dev/null +++ b/docs/gallery/tgbl-coin.md @@ -0,0 +1,12 @@ +## tgbl-coin +#### TEA Plot +![image](TEA/tgbl-coin.png){ width="400"} +#### TET Plot +![image](TET/tgbl-coin.png){ width="400"} + +#### Average degree over time +![image](degree/tgbl-coin_ave_degree_per_ts.png){ width="400"} + + +#### Node and Edge over time +![image](node_edge/tgbl-coin_node&edge_per_ts.png){ width="400"} diff --git a/docs/gallery/tgbl-comment.md b/docs/gallery/tgbl-comment.md new file mode 100644 index 0000000..cdcb2e4 --- /dev/null +++ b/docs/gallery/tgbl-comment.md @@ -0,0 +1,12 @@ +## tgbl-comment +#### TEA Plot +![image](TEA/tgbl-comment.png){ width="400"} +#### TET Plot +![image](TET/tgbl-comment.png){ width="400"} + +#### Average degree over time +![image](degree/tgbl-comment_ave_degree_per_ts.png){ width="400"} + + +#### Node and Edge over time +![image](node_edge/tgbl-comment_node&edge_per_ts.png){ width="400"} diff --git a/docs/gallery/tgbl-flight.md b/docs/gallery/tgbl-flight.md new file mode 100644 index 0000000..7ece363 --- /dev/null +++ b/docs/gallery/tgbl-flight.md @@ -0,0 +1,12 @@ +## tgbl-flight +#### TEA Plot +![image](TEA/tgbl-flight.png){ width="400"} +#### TET Plot +![image](TET/tgbl-flight.png){ width="400"} + +#### Average degree over time +![image](degree/tgbl-flight_ave_degree_per_ts.png){ width="400"} + + +#### Node and Edge over time +![image](node_edge/tgbl-flight_node&edge_per_ts.png){ width="400"} diff --git a/docs/gallery/tgbl-review.md b/docs/gallery/tgbl-review.md new file mode 100644 index 0000000..d0e7b08 --- /dev/null +++ b/docs/gallery/tgbl-review.md @@ -0,0 +1,13 @@ + +## tgbl-review +#### TEA Plot +![image](TEA/tgbl-review.png){ width="400"} +#### TET Plot +![image](TET/tgbl-review.png){ width="400"} + +#### Average degree over time +![image](degree/tgbl-review_ave_degree_per_ts.png){ width="400"} + + +#### Node and Edge over time +![image](node_edge/tgbl-review_node&edge_per_ts.png){ width="400"} diff --git a/docs/gallery/tgbl-wiki.md b/docs/gallery/tgbl-wiki.md new file mode 100644 index 0000000..b3ca8cd --- /dev/null +++ b/docs/gallery/tgbl-wiki.md @@ -0,0 +1,14 @@ +## tgbl-wiki +#### TEA Plot +![image](TEA/tgbl-wiki.png){ width="400"} +#### TET Plot +![image](TET/tgbl-wiki.png){ width="400"} + + + +#### Average degree over time +![image](degree/tgbl-wiki_ave_degree_per_ts.png){ width="400"} + + +#### Node and Edge over time +![image](node_edge/tgbl-wiki_node&edge_per_ts.png){ width="400"} diff --git a/docs/gallery/tgbn-genre.md b/docs/gallery/tgbn-genre.md new file mode 100644 index 0000000..a6525f3 --- /dev/null +++ b/docs/gallery/tgbn-genre.md @@ -0,0 +1,12 @@ +## tgbn-genre +#### TEA Plot +![image](TEA/tgbn-genre.png){ width="400"} +#### TET Plot +![image](TET/tgbn-genre.png){ width="400"} + +#### Average degree over time +![image](degree/tgbn-genre_ave_degree_per_ts.png){ width="400"} + + +#### Node and Edge over time +![image](node_edge/tgbn-genre_node&edge_per_ts.png){ width="400"} diff --git a/docs/gallery/tgbn-reddit.md b/docs/gallery/tgbn-reddit.md new file mode 100644 index 0000000..3bd99ef --- /dev/null +++ b/docs/gallery/tgbn-reddit.md @@ -0,0 +1,12 @@ +## tgbn-reddit +#### TEA Plot +![image](TEA/tgbn-reddit.png){ width="400"} +#### TET Plot +![image](TET/tgbn-reddit.png){ width="400"} + +#### Average degree over time +![image](degree/tgbn-reddit_ave_degree_per_ts.png){ width="400"} + + +#### Node and Edge over time +![image](node_edge/tgbn-reddit_node&edge_per_ts.png){ width="400"} diff --git a/docs/gallery/tgbn-trade.md b/docs/gallery/tgbn-trade.md new file mode 100644 index 0000000..f7c49d0 --- /dev/null +++ b/docs/gallery/tgbn-trade.md @@ -0,0 +1,12 @@ +## tgbn-trade +#### TEA Plot +![image](TEA/tgbn-trade.png){ width="400"} +#### TET Plot +![image](TET/tgbn-trade.png){ width="400"} + +#### Average degree over time +![image](degree/tgbn-trade_ave_degree_per_ts.png){ width="400"} + + +#### Node and Edge over time +![image](node_edge/tgbn-trade_node&edge_per_ts.png){ width="400"} diff --git a/docs/gallery/uci.md b/docs/gallery/uci.md new file mode 100644 index 0000000..f4c20df --- /dev/null +++ b/docs/gallery/uci.md @@ -0,0 +1,12 @@ +## UCI +#### TEA Plot +![UCI](TEA/UCI.png){ width="400"} +#### TET Plot +![UCI](TET/UCI.png){ width="400"} + +#### Average degree over time + ![UCI](degree/uci_ave_degree_per_ts.png){ width="400"} + + +#### Node and Edge over time + ![UCI](node_edge/uci_node&edge_per_ts.png){ width="400"} diff --git a/docs/gallery/unvote.md b/docs/gallery/unvote.md new file mode 100644 index 0000000..f828196 --- /dev/null +++ b/docs/gallery/unvote.md @@ -0,0 +1,12 @@ +## UN Vote +#### TEA Plot +![image](TEA/UNVote.png){ width="400"} +#### TET Plot +![image](TET/UNVote.png){ width="400"} + +#### Average degree over time +![image](degree/UNvote_ave_degree_per_ts.png){ width="400"} + + +#### Node and Edge over time +![image](node_edge/UNvote_node&edge_per_ts.png){ width="400"} diff --git a/docs/gallery/uslegis.md b/docs/gallery/uslegis.md new file mode 100644 index 0000000..75f61e5 --- /dev/null +++ b/docs/gallery/uslegis.md @@ -0,0 +1,13 @@ + + +## US Legis +#### TEA Plot +![image](TEA/USLegis.png){ width="400"} +#### TET Plot +![image](TET/USLegis.png){ width="400"} +#### Average degree over time +![image](degree/USLegis_ave_degree_per_ts.png){ width="400"} + + +#### Node and Edge over time +![image](node_edge/USLegis_node&edge_per_ts.png){ width="400"} diff --git a/examples/test_package1.py b/examples/test_package1.py index 861239a..9d7079c 100644 --- a/examples/test_package1.py +++ b/examples/test_package1.py @@ -1,7 +1,5 @@ -from tgx.data.tgb import tgb_data from tgx.data.builtin import builtin -from tgx.io.read import read_csv -from tgx.classes.graph import * +from tgx.classes.graph import Graph from tgx.viz.TEA import TEA from tgx.viz.TET import TET from tgx.utils.stat import degree_over_time, nodes_over_time diff --git a/examples/test_package2.py b/examples/test_package2.py index 1b8904f..71f6e47 100644 --- a/examples/test_package2.py +++ b/examples/test_package2.py @@ -2,11 +2,11 @@ data_path = '/network/scratch/r/razieh.shirzadkhani/' -Plot_path = "./examples" +Plot_path = "./docs/gallery/node_edge" dataset = tgx.builtin.uci(root = data_path) G = tgx.Graph(dataset) -G.discretize(intervals=dataset.intervals) +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) diff --git a/mkdocs.yml b/mkdocs.yml index 3c9b355..598e52b 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -4,7 +4,7 @@ nav: - Home: index.md - API: - ReadWrite: - - Read Data: io.md + - Read Data: io/io.md - Utils: - Graph stats: utils/graph_stats.md - Graph Utils: utils/graph_utils.md @@ -14,16 +14,46 @@ nav: - TET Plot: viz/vis_tet.md - Classes: - Graph: classes/graph.md - - Datasets: classes/datasets.md + - Data: + - Builtin: data/builtin.md + - TGB: data/tgb.md - Tutorials: - Load data: tutorials/data_loader.ipynb + - Features: tutorials/Features.ipynb - Generate TEA and TET plots: tutorials/TEA&TET.ipynb - Gallery: - Plots by type: - - TEA Plots: gallery/tea.md - - TET Plots: gallery/tet.md - - Plots by dataset: gallery/dataset.md + - TEA Plots: + - Builtin: gallery/0-tea-builtin.md + - TGB: gallery/0-tea-tgb.md + - 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 + - Plots by dataset: + - Builtin: + - Reddit: gallery/reddit.md + - MOOC: gallery/mooc.md + - LastFM: gallery/lastfm.md + - Enron: gallery/enron.md + - Social Evo: gallery/socialevo.md + - UCI: gallery/uci.md + - Flights: gallery/flight.md + - Can Parl: gallery/canparl.md + - US Legis: gallery/uslegis.md + - UN Vote: gallery/unvote.md + - Contacts: gallery/contact.md + - TGB: + - tgbl-wiki: gallery/tgbl-wiki.md + - tgbl-review: gallery/tgbl-review.md + - tgbl-coin: gallery/tgbl-coin.md + - tgbl-comment: gallery/tgbl-comment.md + - tgbl-flight: gallery/tgbl-flight.md + - tgbn-trade: gallery/tgbn-trade.md + - tgbn-genre: gallery/tgbn-genre.md + - tgbn-reddit: gallery/tgbn-reddit.md theme: diff --git a/py_tgx.egg-info/PKG-INFO b/py_tgx.egg-info/PKG-INFO index 893781f..6a0c724 100644 --- a/py_tgx.egg-info/PKG-INFO +++ b/py_tgx.egg-info/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: py-tgx -Version: 0.1.7 +Version: 0.1.9 Summary: Temporal graph Home-page: https://github.com/fpour/tgx Author: Razieh Shirzadkhani diff --git a/py_tgx.egg-info/SOURCES.txt b/py_tgx.egg-info/SOURCES.txt index 6312fac..d77fbb5 100644 --- a/py_tgx.egg-info/SOURCES.txt +++ b/py_tgx.egg-info/SOURCES.txt @@ -15,6 +15,7 @@ setup.py ./tgx/data/tgb.py ./tgx/io/__init__.py ./tgx/io/read.py +./tgx/io/write.py ./tgx/utils/__init__.py ./tgx/utils/graph_utils.py ./tgx/utils/plotting_utils.py diff --git a/setup.cfg b/setup.cfg index 22ecfbd..f076b05 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = py-tgx -version = 0.1.7 +version = 0.1.9 author = ["Razieh Shirzadkhani ", "shenyang Huang ", "Elahe Kooshafar", "Farimah Poursafaei"] author_email = razieh.shirzadkhani@gmail.com description = Temporal Graph Analysis project repo diff --git a/setup.py b/setup.py index ac2e633..4321251 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ def readme(): setup( name="py-tgx", - version="0.1.7", + version="0.1.9", description="Temporal graph", long_description=readme(), long_description_content_type="text/markdown", diff --git a/tgx/__init__.py b/tgx/__init__.py index cee51a4..3e370d9 100644 --- a/tgx/__init__.py +++ b/tgx/__init__.py @@ -9,7 +9,6 @@ from tgx.viz.TEA import TEA from tgx.viz.TET import TET - from tgx.utils.stat import * from tgx.utils.graph_utils import * diff --git a/tgx/classes/__pycache__/graph.cpython-39.pyc b/tgx/classes/__pycache__/graph.cpython-39.pyc index d7b1d63..c504264 100644 Binary files a/tgx/classes/__pycache__/graph.cpython-39.pyc and b/tgx/classes/__pycache__/graph.cpython-39.pyc differ diff --git a/tgx/classes/graph.py b/tgx/classes/graph.py index 1a13d5e..b48e75b 100644 --- a/tgx/classes/graph.py +++ b/tgx/classes/graph.py @@ -1,4 +1,4 @@ -import networkx as nx +# import networkx as nx from typing import Optional from tgx.utils.graph_utils import edgelist_discritizer, frequency_count from tgx.io.read import read_csv @@ -41,16 +41,23 @@ def count_freq(self): self.freq_data = frequency_count(self.data) return self - def number_of_nodes(self, edgelist: Optional[dict] = None) -> int: + def number_of_edges(self) -> int: r""" Calculate total number of nodes present in an edgelist - Parameters: - edgelist: dictionary in the form of {t: {(u, v), freq}} """ - if self.edgelist is None: - return [] - elif edgelist is None: - edgelist = self.edgelist + edgelist = self.data + a = 0 + for _, edges in edgelist.items(): + a += len(edges) + + return #len(edges_list.keys()) + + def number_of_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(): @@ -75,32 +82,32 @@ def nodes_list(self) -> list: self.node_list = list(node_list.keys()) return list(node_list.keys()) - def _generate_graph(self, - edgelist: Optional[dict] = None - ) -> list: - r''' - Generate a list of graph snapshots. Each snapshot is a - Networkx graph object. - Parameters: - edgelist: a dictionary containing in the form of {t: {(u, v), freq}} - Returns: - G_times: a list of networkx graphs - ''' - if self.edgelist is None: - return [] - elif edgelist is None: - edgelist = self.edgelist - G_times = [] - G = nx.Graph() - cur_t = 0 - for ts, edge_data in edgelist.items(): - for (u,v), n in edge_data.items(): - if (ts != cur_t): - G_times.append(G) - G = nx.Graph() - cur_t = ts - G.add_edge(u, v, freq=n) - G_times.append(G) - return G_times + # def _generate_graph(self, + # edgelist: Optional[dict] = None + # ) -> list: + # r''' + # Generate a list of graph snapshots. Each snapshot is a + # Networkx graph object. + # Parameters: + # edgelist: a dictionary containing in the form of {t: {(u, v), freq}} + # Returns: + # G_times: a list of networkx graphs + # ''' + # if self.edgelist is None: + # return [] + # elif edgelist is None: + # edgelist = self.edgelist + # G_times = [] + # G = nx.Graph() + # cur_t = 0 + # for ts, edge_data in edgelist.items(): + # for (u,v), n in edge_data.items(): + # if (ts != cur_t): + # G_times.append(G) + # G = nx.Graph() + # cur_t = ts + # G.add_edge(u, v, freq=n) + # G_times.append(G) + # return G_times \ No newline at end of file diff --git a/tgx/data/tgb.py b/tgx/data/tgb.py index b2f907b..1b1c1c5 100644 --- a/tgx/data/tgb.py +++ b/tgx/data/tgb.py @@ -41,16 +41,16 @@ def tgb(self, dname: str, edge_idxs: bool = False): """ Load datasets from "tgb" package. To load these datasets you need to install tgb package. - Args: + Parameters: dname: str, name of the dataset from the list: ["tgbl-wiki", "tgbl-review", "tgbl-coin", "tgbl-comment", "tgbl-flight","tgbn-trade", "tgbn-genre", "tgbn-reddit"] - edge_feat: - weight: - edge_label: - edge_idx: + edge_feat: list of edge features + w: edge weights + edge_label: edge labels + edge_idxs: edge indexes """ try: diff --git a/tgx/io/read.py b/tgx/io/read.py index e92823f..bed4e58 100644 --- a/tgx/io/read.py +++ b/tgx/io/read.py @@ -26,8 +26,6 @@ def read_csv(fname: Union[str, object] = None, fname: directory of a dataset in .csv format or data object created from loading dgb/tgb datasets header: whether first line of data file is header index: whether the first column is row indices - discretize: whether to discretize the data - intervals: to discretize data based on "daily", "weekly", "monthly" or "yearly" or give the number of intervals t_col: column indext for timestamps (0 or 2) ts_sorted: if data are sorted based on timestamp max_intervals: maximum number of intervals to discretize data diff --git a/tgx/utils/stat.py b/tgx/utils/stat.py index 3aa6f64..1ce4564 100644 --- a/tgx/utils/stat.py +++ b/tgx/utils/stat.py @@ -18,8 +18,7 @@ "degree_density"] -def degree_over_time(graph: list, - total_nodes: int, +def degree_over_time(graph: list, network_name: str, filepath: str = None) -> None: r''' @@ -28,7 +27,7 @@ def degree_over_time(graph: list, graph: a list containing graph snapshots total_nodes: number of nodes that appear through all the snapshots network_name: name of the graph to be used in the output file name - plot_path: path to save the output figure + filepath: path to save the output figure ''' print("Plotting average degree per timestamp") ave_degree = _calculate_average_degree_per_ts(graph, total_nodes) @@ -37,7 +36,7 @@ def degree_over_time(graph: list, filename = f"{network_name}_ave_degree_per_ts" else: filename = "ave_degree_per_ts" - plot_for_snapshots(ave_degree, filename, "Average degree", plot_path = plot_path) + plot_for_snapshots(ave_degree, filename, "Average degree", plot_path = filepath) print("Plotting Done!") return @@ -61,13 +60,14 @@ def nodes_over_time(graph: list, filename = f"{network_name}_nodes_per_ts" else: filename = "nodes_per_ts" - plot_for_snapshots(active_nodes, filename, "Number of nodes", plot_path = plot_path) + plot_for_snapshots(active_nodes, filename, "Number of nodes", plot_path = filepath) print("Plotting Done!") return -def edges_per_ts(graph: list, +def edges_over_time(graph: list, plot_path: str = None, - network_name: str = None) -> None: + network_name: str = None, + filepath: str = None) -> None: r''' Plot number of edges per timestamp. Parameters: @@ -81,13 +81,13 @@ def edges_per_ts(graph: list, filename = f"{network_name}_edges_per_ts" else: filename = "_edges_per_ts" - plot_for_snapshots(active_edges, plot_path, filename, "Number of edges") + plot_for_snapshots(active_edges, plot_path, filename, "Number of edges", plot_path = filepath) print("Plotting Done!") return -def nodes_and_edges_per_ts(graph: list, +def nodes_and_edges_over_time(graph: list, network_name: str , - plot_path: str = None): + filepath: str = None): r""" Plot number of nodes per timestamp and number of edges per timestamp in one fiugre. Parameters: @@ -95,12 +95,12 @@ def nodes_and_edges_per_ts(graph: list, network_name: name of the graph to be used in the output file name filepath: path to save the output figure """ - edges = _calculate_edge_per_ts(graph) - nodes = _calculate_node_per_ts(graph) + edges = _calculate_edge_per_ts(graph.data) + nodes = _calculate_node_per_ts(graph.data) ts = list(range(0, len(graph))) - return plot_nodes_edges_per_ts(edges, nodes, ts, network_name = network_name, plot_path = plot_path) + return plot_nodes_edges_per_ts(edges, nodes, ts, network_name = network_name, plot_path = filepath) @@ -236,12 +236,12 @@ def merge(x, y, parent): parent[root_x] = root_y -def size_connected_components(graph): +def size_connected_components(graph) -> list: """ Calculate the sizes of connected components per timestamp. Returns: - - list: A list containing the sizes of connected components in each timestamp. + component_sizes: A list containing the sizes of connected components in each timestamp. """ component_sizes = [] diff --git a/tgx/viz/__init__.py b/tgx/viz/__init__.py index e69de29..8814ee3 100644 --- a/tgx/viz/__init__.py +++ b/tgx/viz/__init__.py @@ -0,0 +1 @@ +# from tgx.viz import TEA \ No newline at end of file