pub struct ModelEnsemble {
pub config: EnsembleConfig,
pub members: Vec<ModelMember>,
}Expand description
Multi-model ensemble aggregator supporting voting, averaging, and stacking.
Fields§
§config: EnsembleConfig§members: Vec<ModelMember>Implementations§
Source§impl ModelEnsemble
impl ModelEnsemble
Sourcepub fn new(config: EnsembleConfig) -> Self
pub fn new(config: EnsembleConfig) -> Self
Create a new ensemble with the given configuration.
Sourcepub fn add_member(&mut self, model_id: String, weight: f64) -> &mut Self
pub fn add_member(&mut self, model_id: String, weight: f64) -> &mut Self
Add a model member. Returns &mut Self for builder-style chaining.
Sourcepub fn enable_member(&mut self, model_id: &str) -> bool
pub fn enable_member(&mut self, model_id: &str) -> bool
Enable the member with the given id. Returns false if not found.
Sourcepub fn disable_member(&mut self, model_id: &str) -> bool
pub fn disable_member(&mut self, model_id: &str) -> bool
Disable the member with the given id. Returns false if not found.
Sourcepub fn record_call(&mut self, model_id: &str, success: bool)
pub fn record_call(&mut self, model_id: &str, success: bool)
Record a call result for a member (updates call_count / error_count).
Sourcepub fn member_stats(&self) -> Vec<&ModelMember>
pub fn member_stats(&self) -> Vec<&ModelMember>
Immutable references to all members.
Sourcepub fn stats(&self) -> EnsembleStats
pub fn stats(&self) -> EnsembleStats
Aggregate statistics over all members.
Sourcepub fn aggregate(
&self,
predictions: &[ModelPrediction],
) -> Result<EnsembleResult, EnsembleError>
pub fn aggregate( &self, predictions: &[ModelPrediction], ) -> Result<EnsembleResult, EnsembleError>
Aggregate a slice of model predictions according to the configured strategy.
Steps:
- Filter out predictions whose
model_idmaps to a disabled member. - Optionally check that every enabled member contributed (
require_all). - Validate the count against
min_models. - Apply the strategy.
Sourcepub fn top_class(outputs: &[f64]) -> usize
pub fn top_class(outputs: &[f64]) -> usize
Return the index of the maximum element (argmax). Ties: lowest index.
Sourcepub fn softmax(logits: &[f64]) -> Vec<f64>
pub fn softmax(logits: &[f64]) -> Vec<f64>
Numerically stable softmax (subtract max before exp).
Sourcepub fn normalize_weights(weights: &[f64]) -> Vec<f64>
pub fn normalize_weights(weights: &[f64]) -> Vec<f64>
Divide each weight by the total sum. If the sum is approximately 0, return a uniform distribution.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ModelEnsemble
impl RefUnwindSafe for ModelEnsemble
impl Send for ModelEnsemble
impl Sync for ModelEnsemble
impl Unpin for ModelEnsemble
impl UnsafeUnpin for ModelEnsemble
impl UnwindSafe for ModelEnsemble
Blanket Implementations§
impl<T> Allocation for T
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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