Utility Functions for Link Prediction
- fedgraph.utils_lp.check_data_files_existance(country_codes: list, dataset_dir_path: str) None [source]
Check if the data files exist
- fedgraph.utils_lp.download_LPDataset(file_name: str, dir_path: str) None [source]
Download the data files
- fedgraph.utils_lp.get_data(country_code: str, user_id_mapping: Any | None = None, item_id_mapping: Any | None = None, file_path: Any | None = None) HeteroData [source]
Get the data for the specified country code
- Parameters:
- Returns:
data – The data with nodes and edges extracted and stored
- Return type:
HeteroData
Notes
HeteroData is a data class included in torch.geometric.data that stores the heterogeneous graph data. It has the following attributes: - node_id (torch.Tensor): The node indices. - edge_index (torch.Tensor): The edge indices. - edge_attr (torch.Tensor): The edge attributes. - edge_label_index (torch.Tensor): The edge label indices. - edge_label (torch.Tensor): The edge labels.
- fedgraph.utils_lp.get_data_by_time_step(data: HeteroData, start_time_float_format: float, end_time_float_format: float, constant_edges: int = -1) HeteroData [source]
Get the data within the time range determined by the start and end time.
- Parameters:
data (HeteroData) – The data with nodes and edges extracted and stored
start_time_float_format (float) – The start time in float format
end_time_float_format (float) – The end time in float format
constant_edges (int) – The number of constant edges. If -1, all edges within the time range will be kept, otherwise only the last constant_edges edges will be kept
- Returns:
data_current_time_step – The data at the current time step
- Return type:
HeteroData
- fedgraph.utils_lp.get_data_loaders_per_time_step(data: HeteroData, start_time_float_format: float, end_time_float_format: float, use_buffer: bool = False, buffer_size: int = -1) tuple [source]
Get the data loaders per time step.
- fedgraph.utils_lp.get_global_user_item_mapping(global_file_path: str) tuple [source]
Get the global user and item mapping
- fedgraph.utils_lp.get_start_end_time(online_learning: bool, method: str) tuple [source]
Determine the start and end time for the conditional info, and prediction range
- Parameters:
- Returns:
[0]: The start time [1]: The end time [2]: The prediction days [3]: The start time in float format [4]: The end time in float format
- Return type:
- fedgraph.utils_lp.load_edge_csv(path: str, src_index_col: int, src_mapping: dict, dst_index_col: int, dst_mapping: dict) tuple [source]
Load edge csv file
- Parameters:
- Returns:
[0]: The edge index, which stores the source and destination indices [1]: The edge attribute, which stores the time in float format
- Return type:
(torch.Tensor, torch.Tensor)
- fedgraph.utils_lp.load_node_csv(path: str, index_col: int) dict [source]
Load node csv file and create a mapping of the index to the node
- fedgraph.utils_lp.to_next_day(start_time: datetime, end_time: datetime, method: str) tuple [source]
Move the start and end time to the next day
- Parameters:
start_time (datetime.datetime) – The start time
end_time (datetime.datetime) – The end time
method (str) – The method used
- Returns:
[0]: The start time [1]: The end time [2]: The start time in float format [3]: The end time in float format
- Return type:
- fedgraph.utils_lp.transform_negative_sample(data: HeteroData) HeteroData [source]
Transform the data by adding negative samples. The negative samples reverse the edges in the graph.
- Parameters:
data (HeteroData) – The data with nodes and edges extracted and stored
- Returns:
data – The data with negative samples added
- Return type:
HeteroData