dhg.utils
Logging
Download
- dhg.utils.download_file(url, file_path)[source]
Download a file from a url.
- Parameters
url (
str) – the url of the filefile_path (
str) – the path to the file
Structure Helpers
- dhg.utils.remap_edge_list(e_list, bipartite_graph=False, ret_map=False)[source]
Remap the vertex markers to numbers of an ordered and continuous range.
Note
This function can support both low-order structures and high-order structures.
- Parameters
e_list (
List[tuple]) – Edge list of low-order structures or high-order structures.bipartite_graph (
bool) – Whether the structure is bipartite graph. Defaults toFalse.ret_map (
bool) – Whether to return the map dictionary of raw marker to new index. Defaults toFalse.
- dhg.utils.remap_edge_lists(*e_lists, bipartite_graph=False, ret_map=False)[source]
Remap the vertex markers to numbers of an ordered and continuous range for given multiple edge lists.
Note
This function can support both low-order structures and high-order structures.
- Parameters
e_lists (
List[List[tuple]]) – The list of edge list of low-order structures or high-order structures.bipartite_graph (
bool) – Whether the structure is bipartite graph. Defaults toFalse.ret_map (
bool) – Whether to return the map dictionary of raw marker to new index. Defaults toFalse.
- dhg.utils.remap_adj_list(adj_list, bipartite_graph=False, ret_map=False)[source]
Remap the vertex markers to numbers of an ordered and continuous range.
Note
This function can only support low-order structures like graph, directed graph, and bipartite graph.
- Parameters
adj_list (
List[List[int]]) – Adjacency list of low-order structures.bipartite_graph (
bool) – Whether the structure is bipartite graph. Defaults toFalse.ret_map (
bool) – Whether to return the map dictionary of raw marker to new index. Defaults toFalse.
- dhg.utils.remap_adj_lists(*adj_lists, bipartite_graph=False, ret_map=False)[source]
Remap the vertex markers to numbers of an ordered and continuous range for given multiple adjacency lists.
Note
This function can only support low-order structures like graph, directed graph, and bipartite graph.
- Parameters
adj_lists (
List[List[List[int]]]) – The list of adjacency list of low-order structures.bipartite_graph (
bool) – Whether the structure is bipartite graph. Defaults toFalse.ret_map (
bool) – Whether to return the map dictionary of raw marker to new index. Defaults toFalse.
- dhg.utils.edge_list_to_adj_list(e_list)[source]
Convert edge list to adjacency list for low-order structures.
Note
Adjacency list can only represent low-order structures like graph, directed graph, and bipartite graph.
- Parameters
e_list (
List[Tuple[int, int]]) – Edge list.
Dataset Wrapers
- class dhg.utils.UserItemDataset(*args, **kwargs)[source]
Bases:
torch.utils.data.DatasetThe dataset class of user-item bipartite graph for recommendation task.
- Parameters
num_users (
int) – The number of users.num_items (
int) – The number of items.user_item_list (
List[Tuple[int, int]]) – The list of user-item pairs.train_user_item_list (
List[Tuple[int, int]], optional) – The list of user-item pairs for training. This is only needed for testing to mask those seen items in training. Defaults toNone.strict_link (
bool) – Whether to iterate through all interactions in the dataset. If set toFalse, in training phase the dataset will keep randomly sampling interactions until meeting the same number of original interactions. Defaults toTrue.phase (
str) – The phase of the dataset can be either"train"or"test". Defaults to"train".
- __getitem__(index)[source]
Return the item at the index. If the phase is
"train", return the (User-PositiveItem-NegativeItem) triplet. If the phase is"test", return all true positive items for each user.- Parameters
index (
int) – The index of the item.
- __len__()[source]
Return the length of the dataset. If the phase is
"train", return the number of interactions. If the phase is"test", return the number of users.