pub struct KnowledgeDistillation<S = Untrained> { /* private fields */ }Expand description
Knowledge Distillation for Multi-Task Learning
Implements knowledge distillation where a smaller student network learns from a larger teacher network for improved efficiency and performance.
§Examples
use sklears_multioutput::transfer_learning::KnowledgeDistillation;
// Use SciRS2-Core for arrays and random number generation (SciRS2 Policy)
use scirs2_core::ndarray::array;
let X = array![[1.0, 2.0], [2.0, 3.0], [3.0, 1.0]];
let y = array![[1.0, 0.0], [0.0, 1.0], [1.0, 1.0]];
let distillation = KnowledgeDistillation::new()
.temperature(3.0)
.alpha(0.7)
.learning_rate(0.01);Implementations§
Source§impl KnowledgeDistillation<Untrained>
impl KnowledgeDistillation<Untrained>
Sourcepub fn temperature(self, temp: Float) -> Self
pub fn temperature(self, temp: Float) -> Self
Set the temperature for softening teacher predictions
Sourcepub fn alpha(self, alpha: Float) -> Self
pub fn alpha(self, alpha: Float) -> Self
Set the alpha parameter for balancing hard and soft targets
Sourcepub fn learning_rate(self, lr: Float) -> Self
pub fn learning_rate(self, lr: Float) -> Self
Set the learning rate
Sourcepub fn random_state(self, seed: Option<u64>) -> Self
pub fn random_state(self, seed: Option<u64>) -> Self
Set the random state for reproducibility
Sourcepub fn fit(
&self,
X: &ArrayView2<'_, Float>,
y: &ArrayView2<'_, Float>,
teacher_predictions: &ArrayView2<'_, Float>,
) -> SklResult<KnowledgeDistillation<KnowledgeDistillationTrained>>
pub fn fit( &self, X: &ArrayView2<'_, Float>, y: &ArrayView2<'_, Float>, teacher_predictions: &ArrayView2<'_, Float>, ) -> SklResult<KnowledgeDistillation<KnowledgeDistillationTrained>>
Fit the knowledge distillation model
Source§impl KnowledgeDistillation<KnowledgeDistillationTrained>
impl KnowledgeDistillation<KnowledgeDistillationTrained>
Sourcepub fn predict(&self, X: &ArrayView2<'_, Float>) -> SklResult<Array2<Float>>
pub fn predict(&self, X: &ArrayView2<'_, Float>) -> SklResult<Array2<Float>>
Predict using the student network
Sourcepub fn student_weights(&self) -> &Array2<Float>
pub fn student_weights(&self) -> &Array2<Float>
Get the student weights
Sourcepub fn teacher_weights(&self) -> &Array2<Float>
pub fn teacher_weights(&self) -> &Array2<Float>
Get the teacher weights
Trait Implementations§
Source§impl<S: Clone> Clone for KnowledgeDistillation<S>
impl<S: Clone> Clone for KnowledgeDistillation<S>
Source§fn clone(&self) -> KnowledgeDistillation<S>
fn clone(&self) -> KnowledgeDistillation<S>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<S: Debug> Debug for KnowledgeDistillation<S>
impl<S: Debug> Debug for KnowledgeDistillation<S>
Source§impl Default for KnowledgeDistillation<Untrained>
impl Default for KnowledgeDistillation<Untrained>
Source§impl Estimator for KnowledgeDistillation<Untrained>
impl Estimator for KnowledgeDistillation<Untrained>
Source§type Error = SklearsError
type Error = SklearsError
Error type for the estimator
Source§fn validate_config(&self) -> Result<(), SklearsError>
fn validate_config(&self) -> Result<(), SklearsError>
Validate estimator configuration with detailed error context
Source§fn check_compatibility(
&self,
n_samples: usize,
n_features: usize,
) -> Result<(), SklearsError>
fn check_compatibility( &self, n_samples: usize, n_features: usize, ) -> Result<(), SklearsError>
Check if estimator is compatible with given data dimensions
Source§fn metadata(&self) -> EstimatorMetadata
fn metadata(&self) -> EstimatorMetadata
Get estimator metadata
Source§impl Estimator for KnowledgeDistillation<KnowledgeDistillationTrained>
impl Estimator for KnowledgeDistillation<KnowledgeDistillationTrained>
Source§type Error = SklearsError
type Error = SklearsError
Error type for the estimator
Source§fn validate_config(&self) -> Result<(), SklearsError>
fn validate_config(&self) -> Result<(), SklearsError>
Validate estimator configuration with detailed error context
Source§fn check_compatibility(
&self,
n_samples: usize,
n_features: usize,
) -> Result<(), SklearsError>
fn check_compatibility( &self, n_samples: usize, n_features: usize, ) -> Result<(), SklearsError>
Check if estimator is compatible with given data dimensions
Source§fn metadata(&self) -> EstimatorMetadata
fn metadata(&self) -> EstimatorMetadata
Get estimator metadata
Auto Trait Implementations§
impl<S> Freeze for KnowledgeDistillation<S>where
S: Freeze,
impl<S> RefUnwindSafe for KnowledgeDistillation<S>where
S: RefUnwindSafe,
impl<S> Send for KnowledgeDistillation<S>where
S: Send,
impl<S> Sync for KnowledgeDistillation<S>where
S: Sync,
impl<S> Unpin for KnowledgeDistillation<S>where
S: Unpin,
impl<S> UnwindSafe for KnowledgeDistillation<S>where
S: UnwindSafe,
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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 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>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> StableApi for Twhere
T: Estimator,
impl<T> StableApi for Twhere
T: Estimator,
Source§const STABLE_SINCE: &'static str = "0.1.0"
const STABLE_SINCE: &'static str = "0.1.0"
API version this type was stabilized in
Source§const HAS_EXPERIMENTAL_FEATURES: bool = false
const HAS_EXPERIMENTAL_FEATURES: bool = false
Whether this API has any experimental features