FedGraph

Getting Started

  • Installation
  • Federated Graph Learning: A Tutorial
  • Set Up the Ray Cluster

API References

  • Data Process
  • Federated Graph Methods
  • GNN Models
  • Server Class
  • Training Function
  • Trainer Class
  • Monitor Class
  • Utility Functions for Graph Classification
  • Utility Functions for Link Prediction
    • check_data_files_existance()
    • convert_time()
    • download_LPDataset()
    • get_data()
    • get_data_by_time_step()
    • get_data_loaders_per_time_step()
    • get_global_user_item_mapping()
    • get_start_end_time()
    • load_edge_csv()
    • load_node_csv()
    • to_next_day()
    • transform_negative_sample()
  • Utility Functions for Node Classification

Additional Information

  • Cite
  • Reference
FedGraph
  • Utility Functions for Link Prediction
  • View page source

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

Parameters:
  • country_codes (list) – The list of country codes

  • dataset_dir_path (str, optional) – The directory path of the dataset

fedgraph.utils_lp.convert_time(time_string: str) → float[source]

Convert time string to float

Parameters:

time_string (str) – The time string to be converted, from which the year, month, day, hour, minute, and second will be extracted

Returns:

The time in float format

Return type:

float

fedgraph.utils_lp.download_LPDataset(file_name: str, dir_path: str) → None[source]

Download the data files

Parameters:
  • dir_path (str) – The directory path

  • file_name (str) – The file name

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:
  • country_code (str) – The country code

  • user_id_mapping (list) – The user id mapping

  • item_id_mapping (list) – The item id mapping

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.

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

  • use_buffer (bool) – Whether to use buffer

  • buffer_size (int) – The buffer size

fedgraph.utils_lp.get_global_user_item_mapping(global_file_path: str) → tuple[source]

Get the global user and item mapping

Parameters:

file_path (str) – The file path of the global data that contains all the user and item ids

Returns:

[0]: The user id mapping [1]: The item id mapping

Return type:

(dict, dict)

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:
  • online_learning (bool) – Whether the learning is online or not

  • method (str) – The method used

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:

(datetime.datetime, datetime.datetime, int, float, float)

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:
  • path (str) – The path to the csv file

  • src_index_col (int) – The source index column

  • src_mapping (dict) – The source mapping

  • dst_index_col (int) – The destination index column

  • dst_mapping (dict) – The destination mapping

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

Parameters:
  • path (str) – The path to the csv file

  • index_col (int) – The index column

Returns:

mapping – The mapping of the index to the node

Return type:

dict

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:

(datetime.datetime, datetime.datetime, float, float)

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

Previous Next

© Copyright 2024 FedGraph Team.

Built with Sphinx using a theme provided by Read the Docs.