pub struct TypeDistribution { /* private fields */ }Expand description
Distribution over entity types.
Unlike a single EntityType prediction, this captures uncertainty by assigning probability mass to multiple types.
§Invariants
- Probabilities are in [0, 1]
- Probabilities may not sum to 1 (unnormalized is allowed)
- Empty distributions are valid (no prediction)
Implementations§
Source§impl TypeDistribution
impl TypeDistribution
Sourcepub fn new(probs: Vec<(EntityType, f64)>) -> Self
pub fn new(probs: Vec<(EntityType, f64)>) -> Self
Create a new type distribution.
Probabilities are clamped to [0, 1] but NOT normalized. This allows representing “I’m 30% sure it’s PERSON, 20% ORG, and 50% nothing”.
Sourcepub fn uniform(types: &[EntityType]) -> Self
pub fn uniform(types: &[EntityType]) -> Self
Create a uniform distribution over types.
Sourcepub fn point_mass(entity_type: EntityType, confidence: f64) -> Self
pub fn point_mass(entity_type: EntityType, confidence: f64) -> Self
Create a distribution with all mass on one type.
Sourcepub fn argmax(&self) -> Option<(&EntityType, f64)>
pub fn argmax(&self) -> Option<(&EntityType, f64)>
Get the most likely type and its probability.
Sourcepub fn prob(&self, entity_type: &EntityType) -> f64
pub fn prob(&self, entity_type: &EntityType) -> f64
Get probability for a specific type.
Sourcepub fn entropy(&self) -> f64
pub fn entropy(&self) -> f64
Get entropy of the distribution (higher = more uncertain).
Returns 0 for point mass, log(n) for uniform over n types.
Sourcepub fn margin(&self) -> f64
pub fn margin(&self) -> f64
Get margin between top two predictions (higher = more confident).
Returns 1.0 if only one type, 0.0 if tied.
Sourcepub fn is_confident(&self, threshold: f64) -> bool
pub fn is_confident(&self, threshold: f64) -> bool
Check if the top prediction exceeds a confidence threshold.
Sourcepub fn to_map(&self) -> HashMap<EntityType, f64>
pub fn to_map(&self) -> HashMap<EntityType, f64>
Convert to a HashMap for easier iteration.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&EntityType, f64)>
pub fn iter(&self) -> impl Iterator<Item = (&EntityType, f64)>
Iterate over (type, probability) pairs.
Trait Implementations§
Source§impl Clone for TypeDistribution
impl Clone for TypeDistribution
Source§fn clone(&self) -> TypeDistribution
fn clone(&self) -> TypeDistribution
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TypeDistribution
impl Debug for TypeDistribution
Source§impl Default for TypeDistribution
impl Default for TypeDistribution
Source§fn default() -> TypeDistribution
fn default() -> TypeDistribution
Source§impl<'de> Deserialize<'de> for TypeDistribution
impl<'de> Deserialize<'de> for TypeDistribution
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 Display for TypeDistribution
impl Display for TypeDistribution
Source§impl PartialEq for TypeDistribution
impl PartialEq for TypeDistribution
Source§impl Serialize for TypeDistribution
impl Serialize for TypeDistribution
impl StructuralPartialEq for TypeDistribution
Auto Trait Implementations§
impl Freeze for TypeDistribution
impl RefUnwindSafe for TypeDistribution
impl Send for TypeDistribution
impl Sync for TypeDistribution
impl Unpin for TypeDistribution
impl UnsafeUnpin for TypeDistribution
impl UnwindSafe for TypeDistribution
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read moreSource§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.