pub struct ComplEx {
pub entity_re: Vec<Vec<f64>>,
pub entity_im: Vec<Vec<f64>>,
pub relation_re: Vec<Vec<f64>>,
pub relation_im: Vec<Vec<f64>>,
pub dim: usize,
}Expand description
ComplEx knowledge graph embedding model.
Entities and relations are embedded in complex vector space ℂ^d.
Each embedding is stored as two real vectors (real and imaginary parts).
Score: Re( Σ_k h_k · r_k · conj(t_k) )
= Σ_k ( Re(h)·Re(r)·Re(t) + Im(h)·Re(r)·Im(t) + Re(h)·Im(r)·Im(t) - Im(h)·Im(r)·Re(t) )
Fields§
§entity_re: Vec<Vec<f64>>Real part of entity embeddings [n_entities, dim]
entity_im: Vec<Vec<f64>>Imaginary part of entity embeddings [n_entities, dim]
relation_re: Vec<Vec<f64>>Real part of relation embeddings [n_relations, dim]
relation_im: Vec<Vec<f64>>Imaginary part of relation embeddings [n_relations, dim]
dim: usizeEmbedding dimension (complex components per embedding)
Implementations§
Source§impl ComplEx
impl ComplEx
Sourcepub fn new(n_entities: usize, n_relations: usize, dim: usize) -> Result<Self>
pub fn new(n_entities: usize, n_relations: usize, dim: usize) -> Result<Self>
Create a ComplEx model with random initialisation.
Sourcepub fn score(&self, h: usize, r: usize, t: usize) -> Result<f64>
pub fn score(&self, h: usize, r: usize, t: usize) -> Result<f64>
Score triple (h, r, t) using the ComplEx scoring function.
Sourcepub fn link_prediction_score(&self, h: usize, r: usize, t: usize) -> Result<f64>
pub fn link_prediction_score(&self, h: usize, r: usize, t: usize) -> Result<f64>
Link prediction score.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ComplEx
impl RefUnwindSafe for ComplEx
impl Send for ComplEx
impl Sync for ComplEx
impl Unpin for ComplEx
impl UnsafeUnpin for ComplEx
impl UnwindSafe for ComplEx
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