Class GraphData<T>
- Namespace
- AiDotNet.Data.Structures
- Assembly
- AiDotNet.dll
Represents a single graph with nodes, edges, features, and optional labels.
public class GraphData<T>
Type Parameters
TThe numeric type used for calculations, typically float or double.
- Inheritance
-
GraphData<T>
- Inherited Members
Remarks
GraphData encapsulates all information about a graph structure including: - Node features (attributes for each node) - Edge indices (connections between nodes) - Edge features (optional attributes for edges) - Adjacency matrix (graph structure in matrix form) - Labels (for supervised learning tasks)
For Beginners: Think of a graph as a social network: - **Nodes**: People in the network - **Edges**: Friendships or connections between people - **Node Features**: Each person's attributes (age, interests, etc.) - **Edge Features**: Relationship attributes (how long they've been friends, interaction frequency) - **Labels**: What we want to predict (e.g., will this person like a product?)
This class packages all this information together for graph neural network training.
Properties
AdjacencyMatrix
Adjacency matrix of shape [num_nodes, num_nodes] or [batch_size, num_nodes, num_nodes].
public Tensor<T>? AdjacencyMatrix { get; set; }
Property Value
- Tensor<T>
Remarks
Square matrix where A[i,j] = 1 if edge exists from node i to j, 0 otherwise. Can be weighted for graphs with edge weights.
EdgeFeatures
Optional edge feature matrix of shape [num_edges, num_edge_features].
public Tensor<T>? EdgeFeatures { get; set; }
Property Value
- Tensor<T>
Remarks
Each row contains features for one edge. In molecular graphs, this could be bond type, bond length, stereochemistry, etc.
EdgeIndex
Edge index tensor of shape [2, num_edges] or [num_edges, 2]. Format: [source_nodes; target_nodes] or [[src, tgt], [src, tgt], ...].
public Tensor<T> EdgeIndex { get; set; }
Property Value
- Tensor<T>
Remarks
Stores graph connectivity in COO (Coordinate) format. Each edge is represented by a (source, target) pair of node indices.
For Beginners: If node 0 connects to node 1, and node 1 connects to node 2: EdgeIndex = [[0, 1], [1, 2]] or transposed as [[0, 1], [1, 2]] This is a compact way to store which nodes are connected.
GraphLabel
Graph-level label for graph-level tasks (e.g., graph classification). Shape: [1] or [num_classes].
public Tensor<T>? GraphLabel { get; set; }
Property Value
- Tensor<T>
Metadata
Metadata for heterogeneous graphs (optional).
public Dictionary<string, object>? Metadata { get; set; }
Property Value
NodeFeatures
Node feature matrix of shape [num_nodes, num_features].
public Tensor<T> NodeFeatures { get; set; }
Property Value
- Tensor<T>
Remarks
Each row represents one node's feature vector. For example, in a molecular graph, features might include atom type, charge, hybridization, etc.
NodeLabels
Node labels for node-level tasks (e.g., node classification). Shape: [num_nodes] or [num_nodes, num_classes].
public Tensor<T>? NodeLabels { get; set; }
Property Value
- Tensor<T>
NumEdgeFeatures
Number of edge features (0 if no edge features).
public int NumEdgeFeatures { get; }
Property Value
NumEdges
Number of edges in the graph. Handles both [2, num_edges] and [num_edges, 2] EdgeIndex formats.
public int NumEdges { get; }
Property Value
NumNodeFeatures
Number of node features.
public int NumNodeFeatures { get; }
Property Value
NumNodes
Number of nodes in the graph.
public int NumNodes { get; }
Property Value
TestMask
Mask indicating which nodes are in the test set.
public Tensor<T>? TestMask { get; set; }
Property Value
- Tensor<T>
TrainMask
Mask indicating which nodes are in the training set.
public Tensor<T>? TrainMask { get; set; }
Property Value
- Tensor<T>
ValMask
Mask indicating which nodes are in the validation set.
public Tensor<T>? ValMask { get; set; }
Property Value
- Tensor<T>