gnn

package
v1.24.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Experimental — this package is not yet wired into the main framework.

Package gnn implements Graph Neural Network layers for node-level representation learning on graph-structured data.

The package provides two architectures:

  • GCN (Graph Convolutional Network): spectral-based convolution using symmetric normalized adjacency, as described by Kipf & Welling (2017). Each layer computes H' = sigma(D_tilde^{-1/2} A_tilde D_tilde^{-1/2} H W) where A_tilde = A + I adds self-loops.

  • GAT (Graph Attention Network): attention-based message passing as described by Velickovic et al. (2018). Attention coefficients alpha_{ij} = softmax_j(LeakyReLU(a^T [Wh_i || Wh_j])) are computed over each node's neighborhood, with multi-head attention support.

Both models support multi-layer stacking, dropout regularization, and training via gradient descent with cross-entropy loss.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GAT

type GAT struct {
	// contains filtered or unexported fields
}

GAT is a multi-head Graph Attention Network.

func NewGAT

func NewGAT(config GATConfig) *GAT

NewGAT creates a GAT with Xavier-initialized weights.

func (*GAT) AttentionMask

func (g *GAT) AttentionMask(adjacency, features [][]float64) ([][]float64, error)

AttentionMask returns the learned attention coefficients for each head. Returns [n_nodes][n_nodes] averaged over all heads. Coefficients are zero for non-neighbors and sum to 1 over each node's neighborhood.

func (*GAT) Forward

func (g *GAT) Forward(adjacency, features [][]float64) ([][]float64, error)

Forward performs a forward pass through the GAT. adjacency is [n_nodes][n_nodes] and features is [n_nodes][input_dim]. Returns node embeddings of shape [n_nodes][output_dim].

func (*GAT) Train

func (g *GAT) Train(adjacency, features [][]float64, labels []int, config TrainConfig) error

Train trains the GAT using gradient descent with cross-entropy loss.

type GATConfig

type GATConfig struct {
	InputDim     int
	HiddenDim    int
	OutputDim    int
	NHeads       int
	DropoutRate  float64
	LearningRate float64
}

GATConfig configures a Graph Attention Network.

type GCN

type GCN struct {
	// contains filtered or unexported fields
}

GCN is a multi-layer Graph Convolutional Network.

func NewGCN

func NewGCN(config GCNConfig) *GCN

NewGCN creates a GCN with Xavier-initialized weights.

func (*GCN) Forward

func (g *GCN) Forward(adjacency, features [][]float64) ([][]float64, error)

Forward performs a forward pass through the GCN. adjacency is [n_nodes][n_nodes] and features is [n_nodes][input_dim]. Returns node embeddings of shape [n_nodes][output_dim].

func (*GCN) Train

func (g *GCN) Train(adjacency, features [][]float64, labels []int, config TrainConfig) error

Train trains the GCN using gradient descent with cross-entropy loss.

type GCNConfig

type GCNConfig struct {
	InputDim     int
	HiddenDims   []int
	OutputDim    int
	DropoutRate  float64
	LearningRate float64
}

GCNConfig configures a Graph Convolutional Network.

type TrainConfig

type TrainConfig struct {
	Epochs int
}

TrainConfig configures a training run.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL