rllm.transforms.graph_transforms.GDC

class rllm.transforms.graph_transforms.GDC(self_loop_weight: float = 1.0, normalize_in: str = 'sym', normalize_out: str = 'col', diffusion: Dict[str, Any] = {'alpha': 0.15, 'method': 'ppr'}, sparsification: Dict[str, Any] = {'avg_degree': 64, 'method': 'threshold'})[source]

Bases: EdgeTransform

Processes the graph via Graph Diffusion Convolution (GDC) from the “Diffusion Improves Graph Learning” paper (functional name: gdc).

Parameters:
  • self_loop_weight (float, optional) – Weight of the added self-loop. Set to None to add no self-loops. (default: 1)

  • normalize_in (str, optional) – Normalization scheme of transition matrix on input graph. Possible values: "sym", "col", and "row". (default: "sym")

  • normalize_out (str, optional) – Normalization scheme of transition matrix on output graph. Possible values: "sym", "col", "row", and None. (default: "col")

  • diffusion_kwargs (dict, optional) – Dictionary containing the parameters for diffusion. Possible values: "ppr", "heat") Each diffusion method requires different additional parameters. (default: dict(method='ppr', alpha=0.15))

  • sparsification_kwargs (dict, optional) – Dictionary containing the parameters for sparsification.Possible values: "threshold", "topk") Each sparsification method requires different additional parameters. (default: dict(method='threshold', avg_degree=64))

diffusion_matrix(adj: Tensor, method: str, **kwargs) Tensor[source]

Get the diffusion of the given sparse graph.

Parameters:
  • adj (Tensor) – The adjacency matrix.

  • num_nodes (int) – Number of nodes.

  • method (str) –

    Diffusion method:

    1. "ppr": Use personalized PageRank as diffusion. Additionally expects the parameter:

      • alpha (float) - Return probability in PPR. default:obj:[0.05, 0.2].

    2. "heat": Use heat kernel diffusion. Additionally expects the parameter:

      • t (float) - Time of diffusion. default:obj:[2, 10].

get_transition_matrix(adj: Tensor, normalize: str) Tensor[source]

Get the transition matrix of the given sparse matrix.

Parameters:
  • adj (Tensor) – The adjacency matrix.

  • normalize (str) –

    The normalization scheme is adopted:

    1. "sym": Symmetric normalization

    2. "col": Column-wise normalization

    3. "row": Row-wise normalization

    4. None: No normalization.

sparsify_matrix(mx: Tensor, method: str, **kwargs) Tensor[source]

Sparsifies the given sparse graph.

Parameters:
  • adj (Tensor) – The adjacency matrix.

  • num_nodes (int) – Number of nodes.

  • method (str) –

    Method of sparsification:

    1. "threshold": Remove all edges with weights smaller than eps. Additionally expects two parameters:

      • eps (float) - Threshold to bound edges at.

      • avg_degree (int) - If eps is not given, it can optionally be calculated by calculating the value of avg_degree.

    2. "topk": Keep top-k edges on the given dim. Additionally expects two parameters:

      • k (int) - The number of edges to keep.

      • dim (int) - The dim along which to take the top.