nip.graph_isomorphism.environment.AdjacencyMatrixSpec#
- class nip.graph_isomorphism.environment.AdjacencyMatrixSpec(max_num_nodes: int, shape: Size | None = None, device: device | str | int | None = None, dtype: str | dtype = torch.int32)[source]#
A specification of the space of adjacency matrices.
This represents a space of adjacency matrices with a fixed number of nodes, for use in an RL environment.
- Parameters:
max_num_nodes (int) – The maximum number of nodes in the graph.
shape (torch.Size, optional) – The shape of the adjacency matrix. If None, the shape will be (max_num_nodes, max_num_nodes).
device (torch.device, optional) – The device on which the adjacency matrix spec should be stored.
dtype (torch.dtype, optional) – The dtype of the adjacency matrix spec.
Methods Summary
__init__
(max_num_nodes[, shape, device, dtype])_project
(val)Project a value to the space of valid adjacency matrices.
clone
()Create a copy of the adjacency matrix spec.
is_in
(val)Check if a value is a valid adjacency matrix.
rand
([shape])Generate a random 1/2 Erdos-Renyi adjacency matrix.
to
(dest)Move the adjacency matrix spec to a new device or dtype.
Attributes
SPEC_HANDLED_FUNCTIONS
device
domain
dtype
ndim
shape
space
Methods
- __init__(max_num_nodes: int, shape: Size | None = None, device: device | str | int | None = None, dtype: str | dtype = torch.int32)[source]#
- _project(val: Tensor) Tensor [source]#
Project a value to the space of valid adjacency matrices.
Symmetrizes the matrix, sets the diagonal to zero and rounds the values to 0 or 1.
- Parameters:
val (torch.Tensor) – The value to project.
- Returns:
projected_val (torch.Tensor) – The projected value.
- clone() AdjacencyMatrixSpec [source]#
Create a copy of the adjacency matrix spec.
- is_in(val: Tensor) bool [source]#
Check if a value is a valid adjacency matrix.
- Parameters:
val (torch.Tensor) – The value to check.
- Returns:
is_in (bool) – Whether the value is a valid adjacency matrix.
- rand(shape: list[int] | Size | None = None) Tensor [source]#
Generate a random 1/2 Erdos-Renyi adjacency matrix.
- Parameters:
shape (list[int] | torch.Size, optional) – The batch shape of the adjacency matrix. If None, the batch shape will be ().
- Returns:
adjacency (torch.Tensor) – A random adjacency matrix.
- to(dest: dtype | device | str | int) TensorSpec [source]#
Move the adjacency matrix spec to a new device or dtype.
- Parameters:
dest (torch.dtype | torch.device | str | int) – The destination device or dtype.
- Returns:
adjacency_matrix_spec (AdjacencyMatrixSpec) – The adjacency matrix spec on the new device or dtype.