pub struct ActiveLearningSampler { /* private fields */ }Expand description
Active learning sampler that prioritizes uncertain or informative samples
This sampler selects samples based on uncertainty estimates or other information-theoretic criteria to maximize learning efficiency with minimal labeling effort.
§Examples
use torsh_data::sampler::{ActiveLearningSampler, AcquisitionStrategy, Sampler};
let mut sampler = ActiveLearningSampler::new(
1000,
AcquisitionStrategy::UncertaintySampling,
10
).with_generator(42);
// Update with uncertainty scores from model
let uncertainties = vec![0.5; 1000]; // Mock uncertainties
sampler.update_uncertainties(uncertainties);
// Get samples to label
let indices: Vec<usize> = sampler.iter().collect();
assert_eq!(indices.len(), 10);
// Add labeled samples
sampler.add_labeled_samples(&indices);Implementations§
Source§impl ActiveLearningSampler
impl ActiveLearningSampler
Sourcepub fn new(
dataset_size: usize,
acquisition_strategy: AcquisitionStrategy,
budget_per_round: usize,
) -> Self
pub fn new( dataset_size: usize, acquisition_strategy: AcquisitionStrategy, budget_per_round: usize, ) -> Self
Create a new active learning sampler
§Arguments
dataset_size- Total size of the datasetacquisition_strategy- Strategy for selecting samplesbudget_per_round- Number of samples to select per round
§Examples
use torsh_data::sampler::{ActiveLearningSampler, AcquisitionStrategy};
let sampler = ActiveLearningSampler::new(
1000,
AcquisitionStrategy::UncertaintySampling,
20
);Sourcepub fn with_initial_labeled(
dataset_size: usize,
acquisition_strategy: AcquisitionStrategy,
budget_per_round: usize,
initial_labeled: &[usize],
) -> Self
pub fn with_initial_labeled( dataset_size: usize, acquisition_strategy: AcquisitionStrategy, budget_per_round: usize, initial_labeled: &[usize], ) -> Self
Create an active learning sampler with initial labeled samples
§Arguments
dataset_size- Total size of the datasetacquisition_strategy- Strategy for selecting samplesbudget_per_round- Number of samples to select per roundinitial_labeled- Initially labeled sample indices
Sourcepub fn update_uncertainties(&mut self, uncertainties: Vec<f64>)
pub fn update_uncertainties(&mut self, uncertainties: Vec<f64>)
Sourcepub fn add_labeled_samples(&mut self, indices: &[usize])
pub fn add_labeled_samples(&mut self, indices: &[usize])
Sourcepub fn remove_labeled_samples(&mut self, indices: &[usize])
pub fn remove_labeled_samples(&mut self, indices: &[usize])
Remove samples from labeled set (useful for experimental scenarios)
§Arguments
indices- Indices to remove from labeled set
Sourcepub fn with_generator(self, seed: u64) -> Self
pub fn with_generator(self, seed: u64) -> Self
Sourcepub fn current_round(&self) -> usize
pub fn current_round(&self) -> usize
Get the current round number
Sourcepub fn budget_per_round(&self) -> usize
pub fn budget_per_round(&self) -> usize
Get the budget per round
Sourcepub fn strategy(&self) -> &AcquisitionStrategy
pub fn strategy(&self) -> &AcquisitionStrategy
Get the acquisition strategy
Sourcepub fn num_labeled(&self) -> usize
pub fn num_labeled(&self) -> usize
Get the number of labeled samples
Sourcepub fn num_unlabeled(&self) -> usize
pub fn num_unlabeled(&self) -> usize
Get the number of unlabeled samples
Sourcepub fn labeled_indices(&self) -> Vec<usize>
pub fn labeled_indices(&self) -> Vec<usize>
Get the labeled sample indices
Sourcepub fn get_unlabeled_indices(&self) -> Vec<usize>
pub fn get_unlabeled_indices(&self) -> Vec<usize>
Get unlabeled sample indices
Sourcepub fn is_labeled(&self, index: usize) -> bool
pub fn is_labeled(&self, index: usize) -> bool
Check if a sample is labeled
Sourcepub fn set_strategy(&mut self, strategy: AcquisitionStrategy)
pub fn set_strategy(&mut self, strategy: AcquisitionStrategy)
Sourcepub fn set_budget(&mut self, budget: usize)
pub fn set_budget(&mut self, budget: usize)
Sourcepub fn active_learning_stats(&self) -> ActiveLearningStats
pub fn active_learning_stats(&self) -> ActiveLearningStats
Get statistics about the current active learning state
Trait Implementations§
Source§impl Clone for ActiveLearningSampler
impl Clone for ActiveLearningSampler
Source§fn clone(&self) -> ActiveLearningSampler
fn clone(&self) -> ActiveLearningSampler
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 Sampler for ActiveLearningSampler
impl Sampler for ActiveLearningSampler
Source§type Iter = SamplerIterator
type Iter = SamplerIterator
Iterator type returned by the sampler
Source§fn into_batch_sampler(
self,
batch_size: usize,
drop_last: bool,
) -> BatchingSampler<Self>where
Self: Sized,
fn into_batch_sampler(
self,
batch_size: usize,
drop_last: bool,
) -> BatchingSampler<Self>where
Self: Sized,
Convert this sampler into a batch sampler
Source§fn into_distributed(
self,
num_replicas: usize,
rank: usize,
) -> DistributedWrapper<Self>where
Self: Sized,
fn into_distributed(
self,
num_replicas: usize,
rank: usize,
) -> DistributedWrapper<Self>where
Self: Sized,
Create a distributed version of this sampler
Auto Trait Implementations§
impl Freeze for ActiveLearningSampler
impl RefUnwindSafe for ActiveLearningSampler
impl Send for ActiveLearningSampler
impl Sync for ActiveLearningSampler
impl Unpin for ActiveLearningSampler
impl UnwindSafe for ActiveLearningSampler
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<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>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
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
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.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>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
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
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.