graphorge.gnn_base_model.data.graph_data.GraphData¶
- class GraphData(n_dim, nodes_coords)[source]¶
Bases:
object
Graph Neural Network graph data.
- _nodes_coords¶
Coordinates of nodes stored as a numpy.ndarray(2d) with shape (n_nodes, n_dim). Coordinates of i-th node are stored in nodes_coords[i, :].
- Type:
numpy.ndarray(2d)
- _node_features_matrix¶
Nodes input features matrix stored as a numpy.ndarray(2d) of shape (n_nodes, n_features).
- Type:
numpy.ndarray(2d)
- _edge_features_matrix¶
Edges input features matrix stored as a numpy.ndarray(2d) of shape (n_edges, n_features).
- Type:
numpy.ndarray(2d)
- _global_features_matrix¶
Global input features matrix stored as a numpy.ndarray(2d) of shape (1, n_features).
- Type:
numpy.ndarray(2d)
- _node_targets_matrix¶
Nodes targets matrix stored as a numpy.ndarray(2d) of shape (n_nodes, n_targets).
- Type:
numpy.ndarray(2d)
- _edge_targets_matrix¶
Edges targets matrix stored as a numpy.ndarray(2d) of shape (n_nodes, n_targets).
- Type:
numpy.ndarray(2d)
- _global_targets_matrix¶
Global targets matrix stored as a numpy.ndarray(2d) of shape (1, n_targets).
- Type:
numpy.ndarray(2d)
- _edges_indexes¶
Edges indexes matrix stored as numpy.ndarray[int](2d) with shape (n_edges, 2), where the i-th edge is stored in edges_indexes[i, :] as (start_node_index, end_node_index).
- Type:
numpy.ndarray(2d)
- set_graph_edges_indexes(self, connect_radius=None, edges_indexes_mesh=None, is_unique=True)[source]¶
Set graph edges indexes.
- plot_graph(self, is_show_plot=False, is_save_plot=False, save_directory=None, plot_name=None, is_overwrite_file=False)[source]¶
Generate plot of graph.
- _get_edges_from_local_radius(nodes_coords, connect_radius)[source]¶
Get edges between nodes that are within a given connectivity radius.
Constructor.
- Parameters:
n_dim (int) – Number of spatial dimensions.
nodes_coords (numpy.ndarray(2d)) – Coordinates of nodes stored as a numpy.ndarray(2d) with shape (n_nodes, n_dim). Coordinates of i-th node are stored in nodes_coords[i, :].
List of Public Methods
Add metadata information.
Extract data from PyG homogeneous graph data object.
Get edges input features matrix.
Get edge targets matrix.
Convert set of mesh connected nodes to edges indexes matrix.
Get global input features matrix.
Get global targets matrix.
Get graph edges indexes.
Get metadata information.
Get graph number of edges.
Get graph number of nodes.
Set nodes input features matrix.
Get node targets matrix.
Get graph node coordinates.
Get PyG homogeneous graph data object.
Get set of undirected unique edges indexes.
Move time dimension axis in temporal data array.
Generate plot of graph.
Set edges input features matrix.
Set edge targets matrix.
Set global input features matrix.
Set global targets matrix.
Set graph edges indexes and number of edges.
Set metadata information.
Set nodes input features matrix.
Set node targets matrix.
Methods
- __init__(n_dim, nodes_coords)[source]¶
Constructor.
- Parameters:
n_dim (int) – Number of spatial dimensions.
nodes_coords (numpy.ndarray(2d)) – Coordinates of nodes stored as a numpy.ndarray(2d) with shape (n_nodes, n_dim). Coordinates of i-th node are stored in nodes_coords[i, :].
- static _check_edges_indexes_matrix(edges_indexes)[source]¶
Check if given edges indexes matrix is valid.
- Parameters:
edges_indexes (numpy.ndarray(2d)) – Edges indexes matrix stored as numpy.ndarray[int](2d) with shape (n_edges, 2), where the i-th edge is stored in edges_indexes[i, :] as (start_node_index, end_node_index).
- static _get_edges_from_local_radius(nodes_coords, connect_radius)[source]¶
Get edges between nodes that are within a given connectivity radius.
- Parameters:
nodes_coords (numpy.ndarray(2d)) – Coordinates of nodes stored as a numpy.ndarray(2d) with shape (n_nodes, n_dim). Coordinates of i-th node are stored in nodes_coords[i, :].
connect_radius (float) – Connectivity radius that sets the maximum distance between two nodes that leads to an edge.
- Returns:
edges_indexes – Edges indexes matrix stored as numpy.ndarray[int](2d) with shape (num_edges, 2), where the i-th edge is stored in edges_indexes[i, :] as (start_node_index, end_node_index).
- Return type:
numpy.ndarray(2d)
- add_metadata(key, value)[source]¶
Add metadata information.
- Parameters:
key (str) – Key of metadata information.
value (Any) – Value of metadata information.
- static extract_data_torch_data_object(pyg_graph, attributes)[source]¶
Extract data from PyG homogeneous graph data object.
- Parameters:
pyg_graph (torch_geometric.data.Data) – PyG data object describing a homogeneous graph.
attributes (tuple) – Attributes to be extracted from PyG data object. Available attributes coincide with the attributes of GraphData.
- Returns:
attributes_data – Extracted attributes data sorted according with provided attributes sequence.
- Return type:
- get_edge_features_matrix()[source]¶
Get edges input features matrix.
- Returns:
edge_features_matrix – Edges input features matrix stored as a numpy.ndarray(2d) of shape (n_edges, n_features).
- Return type:
numpy.ndarray(2d)
- get_edge_targets_matrix()[source]¶
Get edge targets matrix.
- Returns:
edge_targets_matrix – Edges targets matrix stored as a numpy.ndarray(2d) of shape (n_edges, n_targets).
- Return type:
numpy.ndarray(2d)
- static get_edges_indexes_mesh(connected_nodes)[source]¶
Convert set of mesh connected nodes to edges indexes matrix.
It is assumed that nodes are labeled from 1 to n_nodes, such that node 1 and node n_nodes are associated with indexes 0 and n_nodes-1, respectively.
- Parameters:
connected_nodes (tuple[tuple(2)]) – A set containing all pairs of nodes that are connected by any relevant mesh representation (e.g., finite element mesh). Each connection is stored a single time as a tuple(node[int], node[int]) and is independent of the corresponding nodes storage order.
- Returns:
edges_indexes_mesh – Edges stemming from any relevant mesh representation (e.g., finite element mesh) and that should be accounted for. Edges indexes matrix stored as numpy.ndarray[int](2d) with shape (n_edges, 2), where the i-th edge is stored in edges_indexes[i, :] as (start_node_index, end_node_index).
- Return type:
numpy.ndarray(2d), default=None
- get_global_features_matrix()[source]¶
Get global input features matrix.
- Returns:
global_features_matrix – Global input features matrix stored as a numpy.ndarray(2d) of shape (1, n_features).
- Return type:
numpy.ndarray(2d)
- get_global_targets_matrix()[source]¶
Get global targets matrix.
- Returns:
global_targets_matrix – Global targets matrix stored as a numpy.ndarray(2d) of shape (1, n_targets).
- Return type:
numpy.ndarray(2d)
- get_graph_edges_indexes()[source]¶
Get graph edges indexes.
- Returns:
edges_indexes – Edges indexes matrix stored as numpy.ndarray[int](2d) with shape (num_edges, 2), where the i-th edge is stored in edges_indexes[i, :] as (start_node_index, end_node_index).
- Return type:
numpy.ndarray(2d)
- get_metadata()[source]¶
Get metadata information.
- Returns:
metadata – Metadata information stored as a dictionary.
- Return type:
- get_node_features_matrix()[source]¶
Set nodes input features matrix.
- Returns:
node_features_matrix – Nodes input features matrix stored as a numpy.ndarray(2d) of shape (n_nodes, n_features).
- Return type:
numpy.ndarray(2d)
- get_node_targets_matrix()[source]¶
Get node targets matrix.
- Returns:
node_targets_matrix – Nodes targets matrix stored as a numpy.ndarray(2d) of shape (n_nodes, n_targets).
- Return type:
numpy.ndarray(2d)
- get_nodes_coords()[source]¶
Get graph node coordinates.
- Returns:
nodes_coords – Coordinates of nodes stored as a numpy.ndarray(2d) with shape (n_nodes, n_dim). Coordinates of i-th node are stored in nodes_coords[i, :].
- Return type:
numpy.ndarray(2d), default=None
- get_torch_data_object()[source]¶
Get PyG homogeneous graph data object.
- Returns:
pyg_graph – PyG data object describing a homogeneous graph.
- Return type:
- static get_undirected_unique_edges(edges_indexes)[source]¶
Get set of undirected unique edges indexes.
This function processes the given matrix of edges indexes and transforms all edges into undirected edges. In addition, it also removes any duplicated edges.
- Parameters:
edges_indexes (numpy.ndarray(2d)) – Edges indexes matrix stored as numpy.ndarray[int](2d) with shape (n_edges, 2), where the i-th edge is stored in edges_indexes[i, :] as (start_node_index, end_node_index).
- Returns:
edges_indexes – Edges indexes matrix stored as numpy.ndarray[int](2d) with shape (n_edges, 2), where the i-th edge is stored in edges_indexes[i, :] as (start_node_index, end_node_index).
- Return type:
numpy.ndarray(2d)
- static move_time_dimension_axis(array, source_dim, dest_dim)[source]¶
Move time dimension axis in temporal data array.
- plot_graph(is_show_plot=False, is_save_plot=False, save_directory=None, plot_name=None, is_overwrite_file=False)[source]¶
Generate plot of graph.
- Parameters:
is_show_plot (bool, default=False) – Display plot of graph if True.
is_save_plot (bool, default=False) – Save plot of graph. Plot is only saved if save_directory is provided and exists.
save_directory (str, default=None) – Directory where plot of graph is stored.
plot_name (str, default=None) – Filename of graph plot.
is_overwrite_file (bool, default=False) – Overwrite plot of graph if True, otherwise generate generate non-existent file path by extending the original file path with an integer.
- set_edge_features_matrix(edge_features_matrix)[source]¶
Set edges input features matrix.
- Parameters:
edge_features_matrix (numpy.ndarray(2d)) – Edges input features matrix stored as a numpy.ndarray(2d) of shape (n_edges, n_features).
- set_edge_targets_matrix(edge_targets_matrix)[source]¶
Set edge targets matrix.
- Parameters:
edge_targets_matrix (numpy.ndarray(2d)) – Edges targets matrix stored as a numpy.ndarray(2d) of shape (n_edges, n_targets).
- set_global_features_matrix(global_features_matrix)[source]¶
Set global input features matrix.
- Parameters:
global_features_matrix (numpy.ndarray(2d)) – Global input features matrix stored as a numpy.ndarray(2d) of shape (1, n_features).
- set_global_targets_matrix(global_targets_matrix)[source]¶
Set global targets matrix.
- Parameters:
global_targets_matrix (numpy.ndarray(2d)) – Global targets matrix stored as a numpy.ndarray(2d) of shape (1, n_targets).
- set_graph_edges_indexes(connect_radius=None, edges_indexes_mesh=None, is_unique=True)[source]¶
Set graph edges indexes and number of edges.
Sets existing edges input features and targets matrices to None.
- Parameters:
connect_radius (float, default=None) – Connectivity radius that sets the maximum distance between two nodes that leads to an edge. If None, then no edges are generated from distance-based search.
edges_indexes_mesh (numpy.ndarray(2d), default=None) – Edges stemming from any relevant mesh representation (e.g., finite element mesh) and that should be accounted for. Edges indexes matrix stored as numpy.ndarray[int](2d) with shape (n_edges, 2), where the i-th edge is stored in edges_indexes[i, :] as (start_node_index, end_node_index).
is_unique (bool, default=True) – Remove any existent duplicated edges if True. Resulting unique edges are sorted by ascending order of the corresponding indexes, according to ‘numpy.unique’ output. If False, edges are kept unmodified.
- set_metadata(metadata)[source]¶
Set metadata information.
- Parameters:
metadata (dict) – Any metadata information stored as a dictionary.
Note
Metadata information is useful to store any additional information that is not related to the graph data itself but that is relevant for further processing or analysis, e,g., sample id, time step, etc.
metadata is a dictionary that won’t be moved to the GPU when using
.to(device)
. Avoid retrieving information from it inside your a model.
- set_node_features_matrix(node_features_matrix)[source]¶
Set nodes input features matrix.
- Parameters:
node_features_matrix ({numpy.ndarray(2d), None}) – Nodes input features matrix stored as a numpy.ndarray(2d) of shape (n_nodes, n_features).
- set_node_targets_matrix(node_targets_matrix)[source]¶
Set node targets matrix.
- Parameters:
node_targets_matrix (numpy.ndarray(2d)) – Nodes targets matrix stored as a numpy.ndarray(2d) of shape (n_nodes, n_targets).