pub struct SAGEConv { /* private fields */ }Expand description
GraphSAGE convolutional layer (Hamilton et al., 2017).
Implements the aggregation rule:
h_v^(l+1) = σ(W · CONCAT(h_v^(l), AGG({h_u^(l) : u ∈ N(v)})))
Where AGG can be mean, max, sum, or LSTM aggregation.
§Example
use aprender::nn::gnn::{SAGEConv, AdjacencyMatrix, SAGEAggregation};
use aprender::autograd::Tensor;
let sage = SAGEConv::new(64, 32).with_aggregation(SAGEAggregation::Mean);
let x = Tensor::new(&vec![0.1; 5 * 64], &[5, 64]);
let adj = AdjacencyMatrix::from_edge_index(&[[0, 1], [1, 2], [2, 3], [3, 4]], 5);
let out = sage.forward(&x, &adj);
assert_eq!(out.shape(), &[5, 32]);Implementations§
Source§impl SAGEConv
impl SAGEConv
Sourcepub fn new(in_features: usize, out_features: usize) -> SAGEConv
pub fn new(in_features: usize, out_features: usize) -> SAGEConv
Create a new GraphSAGE layer.
§Arguments
in_features- Input feature dimension per nodeout_features- Output feature dimension per node
Sourcepub fn with_aggregation(self, agg: SAGEAggregation) -> SAGEConv
pub fn with_aggregation(self, agg: SAGEAggregation) -> SAGEConv
Set aggregation method.
Sourcepub fn with_normalize(self) -> SAGEConv
pub fn with_normalize(self) -> SAGEConv
Enable L2 normalization of output.
Sourcepub fn without_root(self) -> SAGEConv
pub fn without_root(self) -> SAGEConv
Disable root weight (self features).
Sourcepub fn without_bias(self) -> SAGEConv
pub fn without_bias(self) -> SAGEConv
Disable bias.
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 aggregation(&self) -> SAGEAggregation
pub fn aggregation(&self) -> SAGEAggregation
Get aggregation method.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for SAGEConv
impl !UnwindSafe for SAGEConv
impl Freeze for SAGEConv
impl Send for SAGEConv
impl Sync for SAGEConv
impl Unpin for SAGEConv
impl UnsafeUnpin for SAGEConv
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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