pub struct AdaptiveBandwidthRBFSampler<State = Untrained> {
pub n_components: usize,
pub strategy: BandwidthSelectionStrategy,
pub objective_function: ObjectiveFunction,
pub gamma_range: (Float, Float),
pub n_gamma_candidates: usize,
pub cv_folds: usize,
pub random_state: Option<u64>,
pub tolerance: Float,
pub max_iterations: usize,
/* private fields */
}Expand description
Adaptive bandwidth RBF sampler with automatic gamma selection
This sampler automatically selects the optimal bandwidth parameter (gamma) for RBF kernel approximation based on data characteristics. Multiple strategies are available for bandwidth selection, from simple heuristics to sophisticated optimization methods.
§Mathematical Background
The RBF kernel with adaptive bandwidth is: K(x,y) = exp(-γ*||x-y||²) where γ is automatically selected to optimize a given objective function.
Common bandwidth selection strategies:
- Median heuristic: γ = 1/(2*median²) where median is the median pairwise distance
- Scott’s rule: γ = n^(-1/(d+4)) for n samples and d dimensions
- Cross-validation: γ = argmin CV_error(γ)
§Examples
use sklears_kernel_approximation::{AdaptiveBandwidthRBFSampler, BandwidthSelectionStrategy};
use sklears_core::traits::{Transform, Fit, Untrained}
use scirs2_core::ndarray::array;
let x = array![[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];
let sampler = AdaptiveBandwidthRBFSampler::new(100)
.strategy(BandwidthSelectionStrategy::MedianHeuristic);
let fitted = sampler.fit(&x, &()).unwrap();
let features = fitted.transform(&x).unwrap();
let optimal_gamma = fitted.selected_gamma();AdaptiveBandwidthRBFSampler
Fields§
§n_components: usizeNumber of random features
strategy: BandwidthSelectionStrategyBandwidth selection strategy
objective_function: ObjectiveFunctionObjective function for optimization
gamma_range: (Float, Float)Search range for gamma (min, max)
n_gamma_candidates: usizeNumber of gamma candidates for grid search
cv_folds: usizeCross-validation folds
random_state: Option<u64>Random seed for reproducibility
tolerance: FloatTolerance for optimization convergence
max_iterations: usizeMaximum iterations for optimization
Implementations§
Source§impl AdaptiveBandwidthRBFSampler<Untrained>
impl AdaptiveBandwidthRBFSampler<Untrained>
Sourcepub fn new(n_components: usize) -> Self
pub fn new(n_components: usize) -> Self
Create a new adaptive bandwidth RBF sampler
§Arguments
n_components- Number of random features to generate
Sourcepub fn strategy(self, strategy: BandwidthSelectionStrategy) -> Self
pub fn strategy(self, strategy: BandwidthSelectionStrategy) -> Self
Set the bandwidth selection strategy
Sourcepub fn objective_function(self, objective: ObjectiveFunction) -> Self
pub fn objective_function(self, objective: ObjectiveFunction) -> Self
Set the objective function for bandwidth optimization
Sourcepub fn gamma_range(self, min: Float, max: Float) -> Self
pub fn gamma_range(self, min: Float, max: Float) -> Self
Set the search range for gamma values
Sourcepub fn n_gamma_candidates(self, n: usize) -> Self
pub fn n_gamma_candidates(self, n: usize) -> Self
Set the number of gamma candidates for grid search
Sourcepub fn random_state(self, seed: u64) -> Self
pub fn random_state(self, seed: u64) -> Self
Set the random state for reproducibility
Sourcepub fn max_iterations(self, max_iter: usize) -> Self
pub fn max_iterations(self, max_iter: usize) -> Self
Set maximum optimization iterations
Source§impl AdaptiveBandwidthRBFSampler<Trained>
impl AdaptiveBandwidthRBFSampler<Trained>
Sourcepub fn selected_gamma(&self) -> Result<Float>
pub fn selected_gamma(&self) -> Result<Float>
Get the selected gamma value
Trait Implementations§
Source§impl<State: Clone> Clone for AdaptiveBandwidthRBFSampler<State>
impl<State: Clone> Clone for AdaptiveBandwidthRBFSampler<State>
Source§fn clone(&self) -> AdaptiveBandwidthRBFSampler<State>
fn clone(&self) -> AdaptiveBandwidthRBFSampler<State>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<State: Debug> Debug for AdaptiveBandwidthRBFSampler<State>
impl<State: Debug> Debug for AdaptiveBandwidthRBFSampler<State>
Source§impl Fit<ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>, ()> for AdaptiveBandwidthRBFSampler<Untrained>
impl Fit<ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>, ()> for AdaptiveBandwidthRBFSampler<Untrained>
Source§type Fitted = AdaptiveBandwidthRBFSampler<Trained>
type Fitted = AdaptiveBandwidthRBFSampler<Trained>
Source§fn fit(self, x: &Array2<Float>, _y: &()) -> Result<Self::Fitted>
fn fit(self, x: &Array2<Float>, _y: &()) -> Result<Self::Fitted>
Source§fn fit_with_validation(
self,
x: &X,
y: &Y,
_x_val: Option<&X>,
_y_val: Option<&Y>,
) -> Result<(Self::Fitted, FitMetrics), SklearsError>where
Self: Sized,
fn fit_with_validation(
self,
x: &X,
y: &Y,
_x_val: Option<&X>,
_y_val: Option<&Y>,
) -> Result<(Self::Fitted, FitMetrics), SklearsError>where
Self: Sized,
Auto Trait Implementations§
impl<State> Freeze for AdaptiveBandwidthRBFSampler<State>
impl<State> RefUnwindSafe for AdaptiveBandwidthRBFSampler<State>where
State: RefUnwindSafe,
impl<State> Send for AdaptiveBandwidthRBFSampler<State>where
State: Send,
impl<State> Sync for AdaptiveBandwidthRBFSampler<State>where
State: Sync,
impl<State> Unpin for AdaptiveBandwidthRBFSampler<State>where
State: Unpin,
impl<State> UnwindSafe for AdaptiveBandwidthRBFSampler<State>where
State: 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
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>
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