pub struct EdgeEncoding {
pub edge_embed: Array2<f64>,
pub projection: Array1<f64>,
pub max_edge_types: usize,
pub hidden_dim: usize,
}Expand description
Edge encoding along shortest paths between node pairs.
For each pair (i, j), takes the edges along the shortest path from i to j
and averages the learnable edge embeddings. This provides additional structural
information to the attention mechanism.
Fields§
§edge_embed: Array2<f64>Learnable edge embedding: [max_edge_types, hidden_dim]
projection: Array1<f64>Projection from hidden_dim to scalar bias
max_edge_types: usizeMaximum number of edge types
Hidden dimension for edge embedding
Implementations§
Source§impl EdgeEncoding
impl EdgeEncoding
Sourcepub fn new(max_edge_types: usize, hidden_dim: usize) -> Self
pub fn new(max_edge_types: usize, hidden_dim: usize) -> Self
Create a new edge encoding module.
§Arguments
max_edge_types- Maximum number of distinct edge feature typeshidden_dim- Dimension for edge embeddings
Sourcepub fn forward(&self, adj: &CsrMatrix, spd: &Array2<usize>) -> Array2<f64>
pub fn forward(&self, adj: &CsrMatrix, spd: &Array2<usize>) -> Array2<f64>
Compute edge bias matrix.
For simplicity, uses edge weights discretized to integer types. Each edge on the shortest path contributes its embedding, which is averaged and projected to a scalar.
§Arguments
adj- Adjacency matrix with edge weightsspd- Shortest path distance matrix fromSpatialEncoding::compute_spd_matrix
§Returns
Edge bias matrix [n, n]
Trait Implementations§
Source§impl Clone for EdgeEncoding
impl Clone for EdgeEncoding
Source§fn clone(&self) -> EdgeEncoding
fn clone(&self) -> EdgeEncoding
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for EdgeEncoding
impl RefUnwindSafe for EdgeEncoding
impl Send for EdgeEncoding
impl Sync for EdgeEncoding
impl Unpin for EdgeEncoding
impl UnsafeUnpin for EdgeEncoding
impl UnwindSafe for EdgeEncoding
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