pub struct GCNConv { /* private fields */ }Expand description
Graph Convolutional Network layer (Kipf & Welling, 2017).
Implements the propagation rule: H^(l+1) = σ(D̃^(-1/2) Ã D̃^(-1/2) H^(l) W^(l))
Where:
- Ã = A + I (adjacency with self-loops)
- D̃ = degree matrix of Ã
- W = learnable weight matrix
- σ = activation function (
ReLUby default)
§Example
use aprender::nn::gnn::{GCNConv, AdjacencyMatrix};
use aprender::autograd::Tensor;
let gcn = GCNConv::new(64, 32);
let x = Tensor::new(&vec![0.1; 3 * 64], &[3, 64]);
let adj = AdjacencyMatrix::from_edge_index(&[[0, 1], [1, 2]], 3).add_self_loops();
let out = gcn.forward(&x, &adj);
assert_eq!(out.shape(), &[3, 32]);Implementations§
Source§impl GCNConv
impl GCNConv
Sourcepub fn new(in_features: usize, out_features: usize) -> Self
pub fn new(in_features: usize, out_features: usize) -> Self
Create a new GCN layer.
§Arguments
in_features- Input feature dimension per nodeout_features- Output feature dimension per node
Sourcepub fn without_bias(self) -> Self
pub fn without_bias(self) -> Self
Disable bias.
Sourcepub fn without_self_loops(self) -> Self
pub fn without_self_loops(self) -> Self
Disable automatic self-loop addition.
Sourcepub fn without_normalize(self) -> Self
pub fn without_normalize(self) -> Self
Disable normalization.
Sourcepub fn in_features(&self) -> usize
pub fn in_features(&self) -> usize
Get input feature dimension.
Sourcepub fn out_features(&self) -> usize
pub fn out_features(&self) -> usize
Get output feature dimension.
Sourcepub fn forward(&self, x: &Tensor, adj: &AdjacencyMatrix) -> Tensor
pub fn forward(&self, x: &Tensor, adj: &AdjacencyMatrix) -> Tensor
Trait Implementations§
Auto Trait Implementations§
impl Freeze for GCNConv
impl !RefUnwindSafe for GCNConv
impl Send for GCNConv
impl Sync for GCNConv
impl Unpin for GCNConv
impl UnsafeUnpin for GCNConv
impl !UnwindSafe for GCNConv
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more