pub struct EmbeddingModel<N: Node> {
pub embeddings: HashMap<N, Embedding>,
pub context_embeddings: HashMap<N, Embedding>,
pub dimensions: usize,
}Expand description
Graph embedding model
Fields§
§embeddings: HashMap<N, Embedding>Node embeddings (input vectors)
context_embeddings: HashMap<N, Embedding>Context embeddings (output vectors) for skip-gram
dimensions: usizeDimensionality of embeddings
Implementations§
Source§impl<N: Node> EmbeddingModel<N>
impl<N: Node> EmbeddingModel<N>
Sourcepub fn get_embedding(&self, node: &N) -> Option<&Embedding>
pub fn get_embedding(&self, node: &N) -> Option<&Embedding>
Get embedding for a node
Sourcepub fn set_embedding(&mut self, node: N, embedding: Embedding) -> Result<()>
pub fn set_embedding(&mut self, node: N, embedding: Embedding) -> Result<()>
Set embedding for a node
Sourcepub fn initialize_random<E, Ix>(
&mut self,
graph: &Graph<N, E, Ix>,
rng: &mut impl Rng,
)
pub fn initialize_random<E, Ix>( &mut self, graph: &Graph<N, E, Ix>, rng: &mut impl Rng, )
Initialize random embeddings for all nodes
Sourcepub fn initialize_random_digraph<E, Ix>(
&mut self,
graph: &DiGraph<N, E, Ix>,
rng: &mut impl Rng,
)
pub fn initialize_random_digraph<E, Ix>( &mut self, graph: &DiGraph<N, E, Ix>, rng: &mut impl Rng, )
Initialize random embeddings for directed graph
Sourcepub fn most_similar(&self, node: &N, k: usize) -> Result<Vec<(N, f64)>>where
N: Clone,
pub fn most_similar(&self, node: &N, k: usize) -> Result<Vec<(N, f64)>>where
N: Clone,
Find k most similar nodes to a given node
Sourcepub fn generate_context_pairs(
walks: &[RandomWalk<N>],
window_size: usize,
) -> Vec<ContextPair<N>>where
N: Clone,
pub fn generate_context_pairs(
walks: &[RandomWalk<N>],
window_size: usize,
) -> Vec<ContextPair<N>>where
N: Clone,
Generate context pairs from random walks
Sourcepub fn train_skip_gram(
&mut self,
pairs: &[ContextPair<N>],
negative_sampler: &NegativeSampler<N>,
learning_rate: f64,
negative_samples: usize,
rng: &mut impl Rng,
) -> Result<()>
pub fn train_skip_gram( &mut self, pairs: &[ContextPair<N>], negative_sampler: &NegativeSampler<N>, learning_rate: f64, negative_samples: usize, rng: &mut impl Rng, ) -> Result<()>
Train skip-gram model on context pairs with negative sampling
Trait Implementations§
Auto Trait Implementations§
impl<N> Freeze for EmbeddingModel<N>
impl<N> RefUnwindSafe for EmbeddingModel<N>where
N: RefUnwindSafe,
impl<N> Send for EmbeddingModel<N>
impl<N> Sync for EmbeddingModel<N>
impl<N> Unpin for EmbeddingModel<N>where
N: Unpin,
impl<N> UnwindSafe for EmbeddingModel<N>where
N: UnwindSafe,
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> 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