pub struct BoxEmbedding {
pub min: Vec<f32>,
pub max: Vec<f32>,
}Expand description
A box embedding representing an entity in d-dimensional space.
Boxes are axis-aligned hyperrectangles defined by min/max bounds in each dimension. Coreference is modeled as high mutual conditional probability (overlap).
Fields§
§min: Vec<f32>Lower bound in each dimension (d-dimensional vector).
max: Vec<f32>Upper bound in each dimension (d-dimensional vector).
Implementations§
Source§impl BoxEmbedding
impl BoxEmbedding
Sourcepub fn volume(&self) -> f32
pub fn volume(&self) -> f32
Compute the volume of the box.
Volume = product of (max - min) for each dimension.
Sourcepub fn intersection_volume(&self, other: &Self) -> f32
pub fn intersection_volume(&self, other: &Self) -> f32
Compute the intersection volume with another box.
Returns 0.0 if boxes are disjoint.
Sourcepub fn conditional_probability(&self, other: &Self) -> f32
pub fn conditional_probability(&self, other: &Self) -> f32
Compute conditional probability P(self | other).
This is the BERE model’s coreference metric: P(A|B) = Vol(A ∩ B) / Vol(B)
Returns a value in [0.0, 1.0] where:
- 1.0 = self is completely contained in other
- 0.0 = boxes are disjoint
Sourcepub fn coreference_score(&self, other: &Self) -> f32
pub fn coreference_score(&self, other: &Self) -> f32
Compute mutual coreference score.
Coreference requires high mutual conditional probability: score = (P(A|B) + P(B|A)) / 2
This ensures both boxes largely contain each other (high overlap).
Sourcepub fn is_contained_in(&self, other: &Self) -> bool
pub fn is_contained_in(&self, other: &Self) -> bool
Check if this box is contained in another box.
Returns true if self ⊆ other (all dimensions).
Sourcepub fn is_disjoint(&self, other: &Self) -> bool
pub fn is_disjoint(&self, other: &Self) -> bool
Check if boxes are disjoint (no overlap).
Sourcepub fn from_vector(vector: &[f32], radius: f32) -> Self
pub fn from_vector(vector: &[f32], radius: f32) -> Self
Create a box embedding from a vector embedding.
Converts a point embedding to a box by creating a small hypercube
around the point. The box size is controlled by radius.
§Arguments
vector- Vector embedding (point in space)radius- Half-width of the box in each dimension
§Example
let vector = vec![0.5, 0.5, 0.5];
let box_embedding = BoxEmbedding::from_vector(&vector, 0.1);
// Creates box: min=[0.4, 0.4, 0.4], max=[0.6, 0.6, 0.6]Sourcepub fn from_vector_adaptive(vector: &[f32], radius_factor: f32) -> Self
pub fn from_vector_adaptive(vector: &[f32], radius_factor: f32) -> Self
Create a box embedding from a vector with adaptive radius.
Uses a radius proportional to the vector’s magnitude, creating larger boxes for vectors further from the origin.
§Arguments
vector- Vector embeddingradius_factor- Multiplier for adaptive radius (default: 0.1)
Sourcepub fn center(&self) -> Vec<f32>
pub fn center(&self) -> Vec<f32>
Get the center point of the box.
Returns the midpoint in each dimension.
Sourcepub fn intersection(&self, other: &Self) -> Self
pub fn intersection(&self, other: &Self) -> Self
Compute the intersection box with another box.
Returns a new box representing the overlapping region. If boxes are disjoint, returns a zero-volume box.
Sourcepub fn union(&self, other: &Self) -> Self
pub fn union(&self, other: &Self) -> Self
Compute the union box (bounding box containing both).
Sourcepub fn overlap_prob(&self, other: &Self) -> f32
pub fn overlap_prob(&self, other: &Self) -> f32
Compute overlap probability (Jaccard-style).
P(overlap) = Vol(intersection) / Vol(union)
Trait Implementations§
Source§impl Clone for BoxEmbedding
impl Clone for BoxEmbedding
Source§fn clone(&self) -> BoxEmbedding
fn clone(&self) -> BoxEmbedding
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for BoxEmbedding
impl Debug for BoxEmbedding
Source§impl<'de> Deserialize<'de> for BoxEmbedding
impl<'de> Deserialize<'de> for BoxEmbedding
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for BoxEmbedding
impl PartialEq for BoxEmbedding
Source§impl Serialize for BoxEmbedding
impl Serialize for BoxEmbedding
impl StructuralPartialEq for BoxEmbedding
Auto Trait Implementations§
impl Freeze for BoxEmbedding
impl RefUnwindSafe for BoxEmbedding
impl Send for BoxEmbedding
impl Sync for BoxEmbedding
impl Unpin for BoxEmbedding
impl UnsafeUnpin for BoxEmbedding
impl UnwindSafe for BoxEmbedding
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
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>
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