pub struct GnnLayer {
pub in_dim: usize,
pub out_dim: usize,
pub w_self: Vec<f64>,
pub w_neigh: Vec<f64>,
pub bias: Vec<f64>,
pub activation: ExtActivation,
}Expand description
A single graph neural network layer implementing the sum-aggregation message passing update:
h_i^(l+1) = σ(W_self * h_i^(l) + W_neigh * Σ_{j ∈ N(i)} h_j^(l) + b)
All nodes share the same weight matrices.
Fields§
§in_dim: usizeInput feature dimension.
out_dim: usizeOutput feature dimension.
w_self: Vec<f64>Self-loop weight matrix W_self [out_dim × in_dim].
w_neigh: Vec<f64>Neighbour aggregation weight matrix W_neigh [out_dim × in_dim].
bias: Vec<f64>Bias vector [out_dim].
activation: ExtActivationActivation function.
Implementations§
Source§impl GnnLayer
impl GnnLayer
Sourcepub fn new(in_dim: usize, out_dim: usize, activation: ExtActivation) -> Self
pub fn new(in_dim: usize, out_dim: usize, activation: ExtActivation) -> Self
Create a new GNN layer with zero-initialised weights.
Sourcepub fn forward(
&self,
node_feats: &[f64],
n_nodes: usize,
adj: &[Vec<usize>],
) -> Vec<f64>
pub fn forward( &self, node_feats: &[f64], n_nodes: usize, adj: &[Vec<usize>], ) -> Vec<f64>
Forward pass.
node_feats–[n_nodes × in_dim]flat row-major node feature matrix.adj– adjacency list:adj[i]contains the neighbour indices of nodei.
Returns [n_nodes × out_dim] flat row-major.
Sourcepub fn num_params(&self) -> usize
pub fn num_params(&self) -> usize
Total number of trainable parameters.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for GnnLayer
impl RefUnwindSafe for GnnLayer
impl Send for GnnLayer
impl Sync for GnnLayer
impl Unpin for GnnLayer
impl UnsafeUnpin for GnnLayer
impl UnwindSafe for GnnLayer
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