pub struct EnsembleEmbedder { /* private fields */ }Implementations§
Source§impl EnsembleEmbedder
impl EnsembleEmbedder
Sourcepub fn new(
models: Vec<Box<dyn Fn(&str) -> Vec<f64> + Send + Sync>>,
config: EnsembleConfig,
) -> Result<Self>
pub fn new( models: Vec<Box<dyn Fn(&str) -> Vec<f64> + Send + Sync>>, config: EnsembleConfig, ) -> Result<Self>
Sourcepub fn num_models(&self) -> usize
pub fn num_models(&self) -> usize
Return the number of models in the ensemble.
Sourcepub fn set_weights(&mut self, weights: Vec<f64>) -> Result<()>
pub fn set_weights(&mut self, weights: Vec<f64>) -> Result<()>
Set per-model weights for WeightedAverage.
Weights are automatically normalised to sum to 1.
§Errors
Returns an error if the weight vector length does not match the model count, or if any weight is negative or not finite, or if the sum is zero.
Sourcepub fn embed(&self, key: &str) -> Result<Vec<f64>>
pub fn embed(&self, key: &str) -> Result<Vec<f64>>
Produce an ensemble embedding for the given entity key.
§Errors
- Dimensionality mismatch between model output and
config.output_dim. Stackingstrategy called beforeEnsembleEmbedder::fit_stacking.
Sourcepub fn fit_stacking(
&mut self,
validation_pairs: &[(&str, Vec<f64>)],
) -> Result<()>
pub fn fit_stacking( &mut self, validation_pairs: &[(&str, Vec<f64>)], ) -> Result<()>
Train the stacking meta-learner on a validation set.
validation_pairs is a slice of (key, target_embedding) pairs where
target_embedding is the ground-truth embedding (e.g. from a stronger
reference model or link-prediction evaluation).
§Errors
Returns an error if the validation set is empty, or if any target embedding has the wrong dimensionality.
Sourcepub fn eval_cosine(
&self,
reference: &impl Fn(&str) -> Vec<f64>,
validation_keys: &[&str],
) -> Result<f64>
pub fn eval_cosine( &self, reference: &impl Fn(&str) -> Vec<f64>, validation_keys: &[&str], ) -> Result<f64>
Compute the average cosine similarity between ensemble output and a reference model on the given validation keys. Useful for tuning weights.
Sourcepub fn derive_weights(
&mut self,
reference: &impl Fn(&str) -> Vec<f64>,
validation_keys: &[&str],
) -> Result<()>
pub fn derive_weights( &mut self, reference: &impl Fn(&str) -> Vec<f64>, validation_keys: &[&str], ) -> Result<()>
Derive performance-based weights from cosine similarity scores on a validation set.
Each model’s weight is proportional to its mean cosine similarity to a reference embedding. Models with zero weight (similarity ≤ 0) are assigned a small ε = 1e-6 to keep them in the ensemble.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for EnsembleEmbedder
impl !RefUnwindSafe for EnsembleEmbedder
impl Send for EnsembleEmbedder
impl Sync for EnsembleEmbedder
impl Unpin for EnsembleEmbedder
impl UnsafeUnpin for EnsembleEmbedder
impl !UnwindSafe for EnsembleEmbedder
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> 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<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.