ExplainabilityCallback

Struct ExplainabilityCallback 

Source
pub struct ExplainabilityCallback { /* private fields */ }
Expand description

Callback for computing feature attributions during training

Integrates with aprender’s interpret module to provide explainability insights during model evaluation.

§Example

use entrenar::train::{ExplainabilityCallback, ExplainMethod};

let callback = ExplainabilityCallback::new(ExplainMethod::PermutationImportance)
    .with_top_k(5)
    .with_eval_samples(100);

Implementations§

Source§

impl ExplainabilityCallback

Source

pub fn new(method: ExplainMethod) -> Self

Create new explainability callback

§Arguments
  • method - Attribution method to use
Source

pub fn with_top_k(self, k: usize) -> Self

Set number of top features to track

Source

pub fn with_eval_samples(self, n: usize) -> Self

Set number of samples to use for evaluation

Source

pub fn with_feature_names(self, names: Vec<String>) -> Self

Set feature names for interpretability

Source

pub fn method(&self) -> ExplainMethod

Get attribution method

Source

pub fn top_k(&self) -> usize

Get top-k setting

Source

pub fn eval_samples(&self) -> usize

Get eval samples setting

Source

pub fn results(&self) -> &[FeatureImportanceResult]

Get all computed results

Source

pub fn feature_names(&self) -> Option<&[String]>

Get feature names if set

Source

pub fn record_importances( &mut self, epoch: usize, importances: Vec<(usize, f32)>, )

Record feature importances for an epoch

Call this during on_epoch_end with computed importances

Source

pub fn compute_permutation_importance<P>( &self, predict_fn: P, x: &[Vector<f32>], y: &[f32], ) -> Vec<(usize, f32)>
where P: Fn(&Vector<f32>) -> f32,

Compute permutation importance using aprender

§Arguments
  • predict_fn - Model prediction function
  • x - Feature vectors
  • y - Target values
Source

pub fn compute_integrated_gradients<F>( &self, model_fn: F, sample: &Vector<f32>, baseline: &Vector<f32>, ) -> Vec<(usize, f32)>
where F: Fn(&Vector<f32>) -> f32,

Compute integrated gradients using aprender

§Arguments
  • model_fn - Model prediction function
  • sample - Input sample to explain
  • baseline - Baseline input (typically zeros)
Source

pub fn compute_saliency<F>( &self, model_fn: F, sample: &Vector<f32>, ) -> Vec<(usize, f32)>
where F: Fn(&Vector<f32>) -> f32,

Compute saliency map using aprender

§Arguments
  • model_fn - Model prediction function
  • sample - Input sample to explain
Source

pub fn consistent_top_features(&self) -> Vec<(usize, f32)>

Get top features that have been consistently important across epochs

Trait Implementations§

Source§

impl Debug for ExplainabilityCallback

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl TrainerCallback for ExplainabilityCallback

Source§

fn on_epoch_end(&mut self, ctx: &CallbackContext) -> CallbackAction

Called after each epoch
Source§

fn name(&self) -> &'static str

Get callback name for logging
Source§

fn on_train_begin(&mut self, _ctx: &CallbackContext) -> CallbackAction

Called before training starts
Source§

fn on_train_end(&mut self, _ctx: &CallbackContext)

Called after training ends
Source§

fn on_epoch_begin(&mut self, _ctx: &CallbackContext) -> CallbackAction

Called before each epoch
Source§

fn on_step_begin(&mut self, _ctx: &CallbackContext) -> CallbackAction

Called before each training step
Source§

fn on_step_end(&mut self, _ctx: &CallbackContext) -> CallbackAction

Called after each training step
Source§

fn on_validation(&mut self, _ctx: &CallbackContext) -> CallbackAction

Called when validation is performed

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,