Skip to main content

GraphMae

Struct GraphMae 

Source
pub struct GraphMae { /* private fields */ }
Expand description

Graph Masked Autoencoder.

Maintains:

  • A learnable mask token of shape [feature_dim] used to replace masked node features.
  • An encoder weight matrix [feature_dim × encoder_dim].
  • A decoder weight matrix [encoder_dim × feature_dim].

Implementations§

Source§

impl GraphMae

Source

pub fn new(feature_dim: usize, config: GraphMaeConfig, seed: u64) -> Self

Construct a new GraphMAE.

§Arguments
  • feature_dim – dimension of each node’s input features
  • config – MAE hyper-parameters
  • seed – RNG seed for reproducible initialisation
Source

pub fn mask_features( &self, features: &Array2<f64>, seed: u64, ) -> (Array2<f64>, Vec<usize>)

Apply random feature masking.

Selects a random subset of nodes (fraction ≈ config.mask_rate) and replaces their feature vectors with the learnable mask token.

§Arguments
  • features – node feature matrix [n_nodes × feature_dim]
  • seed – RNG seed (different from the model seed so each call can produce a different mask)
§Returns

(masked_features, mask_indices) where mask_indices contains the row indices of the masked nodes (sorted ascending).

Source

pub fn encode(&self, features: &Array2<f64>) -> Array2<f64>

Encode node features: Z = ReLU(X @ W_enc)

§Arguments
  • features – (possibly masked) node features [n_nodes × feature_dim]
§Returns

Latent representations [n_nodes × encoder_dim]

Source

pub fn decode(&self, encoded: &Array2<f64>) -> Array2<f64>

Decode latent representations: X̂ = Z @ W_dec

§Arguments
  • encoded – latent representations [n_nodes × encoder_dim]
§Returns

Reconstructed features [n_nodes × feature_dim]

Source

pub fn sce_loss( &self, original: &Array2<f64>, reconstructed: &Array2<f64>, mask_indices: &[usize], gamma: f64, ) -> f64

Scaled Cosine Error (SCE) reconstruction loss on masked nodes.

L = (1/|M|) Σ_{i∈M} (1 - cosine_sim(reconstructed_i, original_i))^γ

If mask_indices is empty, returns 0.0.

§Arguments
  • original – original node features [n_nodes × feature_dim]
  • reconstructed – decoder output [n_nodes × feature_dim]
  • mask_indices – indices of masked nodes
  • gamma – exponent ≥ 1 (typical: 2 or 3)
Source

pub fn forward(&self, features: &Array2<f64>, seed: u64) -> (Array2<f64>, f64)

Full GraphMAE forward pass.

  1. Mask features randomly.
  2. Encode masked features.
  3. Decode back to feature space.
  4. Compute SCE loss over masked nodes (γ = 2).
§Arguments
  • features – original node feature matrix [n_nodes × feature_dim]
  • seed – RNG seed for the masking step
§Returns

(reconstructed_features, sce_loss)

Source

pub fn mask_token(&self) -> &Array1<f64>

The learnable mask token vector [feature_dim].

Source

pub fn feature_dim(&self) -> usize

Input / output feature dimension.

Source

pub fn encoder_dim(&self) -> usize

Encoder output dimension.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V